@@ -15,13 +15,15 @@ type BundleKind =
1515
1616type BundleCacheRestoreParams = {
1717 kind : BundleKind ;
18+ namespace ?: string ;
1819 name : string ;
1920 /** Optional hash of non-file context (e.g., env variables) to include in cache validation. */
2021 contextHash ?: string ;
2122} ;
2223
2324type BundleCacheSaveParams = {
2425 kind : BundleKind ;
26+ namespace ?: string ;
2527 name : string ;
2628 sourceFile : string ;
2729 content : string ;
@@ -41,8 +43,8 @@ type BundleCache = {
4143 save ( params : BundleCacheSaveParams ) : void ;
4244} ;
4345
44- function buildCacheKey ( kind : string , name : string ) : string {
45- return `${ kind } :${ name } ` ;
46+ function buildCacheKey ( kind : string , name : string , namespace ?: string ) : string {
47+ return namespace ? ` ${ kind } : ${ namespace } : ${ name } ` : `${ kind } :${ name } ` ;
4648}
4749
4850function combineHash ( fileHash : string , contextHash ?: string ) : string {
@@ -90,6 +92,7 @@ function computeBundlerContextHash(params: ComputeBundlerContextHashParams): str
9092type WithCacheParams = {
9193 cache : BundleCache | undefined ;
9294 kind : BundleKind ;
95+ namespace ?: string ;
9396 name : string ;
9497 sourceFile : string ;
9598 contextHash : string | undefined ;
@@ -104,13 +107,13 @@ type WithCacheParams = {
104107 * @returns The bundled code string
105108 */
106109async function withCache ( params : WithCacheParams ) : Promise < string > {
107- const { cache, kind, name, sourceFile, contextHash, build } = params ;
110+ const { cache, kind, namespace , name, sourceFile, contextHash, build } = params ;
108111
109112 if ( ! cache ) {
110113 return await build ( [ ] ) ;
111114 }
112115
113- const content = cache . tryRestore ( { kind, name, contextHash } ) ;
116+ const content = cache . tryRestore ( { kind, namespace , name, contextHash } ) ;
114117 if ( content !== undefined ) {
115118 logger . debug ( ` ${ styles . dim ( "cached" ) } : ${ name } ` ) ;
116119 return content ;
@@ -119,7 +122,15 @@ async function withCache(params: WithCacheParams): Promise<string> {
119122 const { plugin, getResult } = createDepCollectorPlugin ( ) ;
120123 const code = await build ( [ plugin ] ) ;
121124
122- cache . save ( { kind, name, sourceFile, content : code , dependencyPaths : getResult ( ) , contextHash } ) ;
125+ cache . save ( {
126+ kind,
127+ namespace,
128+ name,
129+ sourceFile,
130+ content : code ,
131+ dependencyPaths : getResult ( ) ,
132+ contextHash,
133+ } ) ;
123134
124135 return code ;
125136}
@@ -131,7 +142,7 @@ async function withCache(params: WithCacheParams): Promise<string> {
131142 */
132143function createBundleCache ( store : CacheStore ) : BundleCache {
133144 function tryRestore ( params : BundleCacheRestoreParams ) : string | undefined {
134- const cacheKey = buildCacheKey ( params . kind , params . name ) ;
145+ const cacheKey = buildCacheKey ( params . kind , params . name , params . namespace ) ;
135146 const entry = store . getEntry ( cacheKey ) ;
136147
137148 if ( ! entry ) {
@@ -155,8 +166,8 @@ function createBundleCache(store: CacheStore): BundleCache {
155166 }
156167
157168 function save ( params : BundleCacheSaveParams ) : void {
158- const { kind, name, sourceFile, content, dependencyPaths, contextHash } = params ;
159- const cacheKey = buildCacheKey ( kind , name ) ;
169+ const { kind, namespace , name, sourceFile, content, dependencyPaths, contextHash } = params ;
170+ const cacheKey = buildCacheKey ( kind , name , namespace ) ;
160171 // Always include sourceFile in dependency paths so that changes to the
161172 // source file itself are detected even when dep-collector only finds
162173 // node_modules imports (which are filtered out).
0 commit comments