11import type { Tree } from '@nx/devkit' ;
2- import { astCache } from '../ast-cache' ;
32import { treeReadCache } from '../tree-cache' ;
43
54/**
@@ -10,8 +9,12 @@ export interface IndexExports {
109 reexports : Set < string > ; // re-exported modules (file paths without extension)
1110}
1211
12+ interface CachedIndexExports extends IndexExports {
13+ content : string ; // content snapshot used to build this cache entry
14+ }
15+
1316// Internal cache keyed by normalized index file path
14- const indexExportsCache = new Map < string , IndexExports > ( ) ;
17+ const indexExportsCache = new Map < string , CachedIndexExports > ( ) ;
1518
1619/** Clears all cached index export data. */
1720export function clearIndexExportsCache ( ) : void {
@@ -28,11 +31,11 @@ export function invalidateIndexExportsCacheEntry(indexPath: string): void {
2831 * Lightweight regex based extraction – sufficient for current export patterns.
2932 */
3033export function getIndexExports ( tree : Tree , indexPath : string ) : IndexExports {
31- const cached = indexExportsCache . get ( indexPath ) ;
32- if ( cached ) return cached ;
33-
3434 const content = treeReadCache . read ( tree , indexPath , 'utf-8' ) || '' ;
3535
36+ const cached = indexExportsCache . get ( indexPath ) ;
37+ if ( cached && cached . content === content ) return cached ;
38+
3639 const exports = new Set < string > ( ) ;
3740 const reexports = new Set < string > ( ) ;
3841
@@ -51,10 +54,12 @@ export function getIndexExports(tree: Tree, indexPath: string): IndexExports {
5154 // Capture exported local files: export * from './lib/file'; we store path without extension for comparison ease.
5255 for ( const spec of reexports ) {
5356 const withoutExt = spec . replace ( / \. ( t s | t s x | j s | j s x ) $ / i, '' ) ;
54- exports . add ( withoutExt ) ;
57+ // Ensure stored paths are normalized to start with './'
58+ const normalized = withoutExt . startsWith ( './' ) || withoutExt . startsWith ( '../' ) ? withoutExt : `./${ withoutExt } ` ;
59+ exports . add ( normalized ) ;
5560 }
5661
57- const result : IndexExports = { exports, reexports } ;
62+ const result : CachedIndexExports = { exports, reexports, content } ;
5863 indexExportsCache . set ( indexPath , result ) ;
5964 return result ;
6065}
0 commit comments