@@ -45,6 +45,54 @@ const getLazyRequestsHash = (module, lazyBarrelController, hashFunction) => {
4545 return /** @type {string } */ ( hash . digest ( "hex" ) ) ;
4646} ;
4747
48+ /**
49+ * DefinePlugin (and similar) can change provided exports without changing the
50+ * source hash; fold valueDependencies into the provided-exports cache key.
51+ * @param {Module } module the module
52+ * @param {HashFunction } hashFunction hash function for long keys
53+ * @returns {string } key fragment, or "" when absent
54+ */
55+ const getValueDependenciesHash = ( module , hashFunction ) => {
56+ const valueDependencies =
57+ /** @type {BuildInfo | undefined } */
58+ ( module . buildInfo ) &&
59+ /** @type {BuildInfo } */
60+ ( module . buildInfo ) . valueDependencies ;
61+ if ( ! valueDependencies || valueDependencies . size === 0 ) return "" ;
62+ const parts = [ ] ;
63+ for ( const key of [ ...valueDependencies . keys ( ) ] . sort ( ) ) {
64+ const value = valueDependencies . get ( key ) ;
65+ parts . push (
66+ `${ key } =${
67+ typeof value === "string"
68+ ? value
69+ : value === undefined
70+ ? ""
71+ : `[${ [ ...value ] . sort ( ) . join ( "," ) } ]`
72+ } `
73+ ) ;
74+ }
75+ const joined = parts . join ( "|" ) ;
76+ if ( joined . length < 100 ) return joined ;
77+ const hash = createHash ( hashFunction ) ;
78+ hash . update ( joined ) ;
79+ return /** @type {string } */ ( hash . digest ( "hex" ) ) ;
80+ } ;
81+
82+ /**
83+ * @param {Module } module the module
84+ * @param {LazyBarrelController } lazyBarrelController the compilation's lazy barrel controller
85+ * @param {HashFunction } hashFunction hash function for long keys
86+ * @returns {string } etag for provided-exports mem/persistent cache
87+ */
88+ const getProvidedExportsEtag = ( module , lazyBarrelController , hashFunction ) => {
89+ const lazy = getLazyRequestsHash ( module , lazyBarrelController , hashFunction ) ;
90+ const valueDeps = getValueDependenciesHash ( module , hashFunction ) ;
91+ if ( ! lazy ) return valueDeps ;
92+ if ( ! valueDeps ) return lazy ;
93+ return `${ lazy } |${ valueDeps } ` ;
94+ } ;
95+
4896class FlagDependencyExportsPlugin {
4997 /**
5098 * Applies the plugin by registering its hooks on the compiler.
@@ -107,7 +155,7 @@ class FlagDependencyExportsPlugin {
107155 const memCache = moduleMemCaches && moduleMemCaches . get ( module ) ;
108156 /** @type {MemCacheEntry | undefined } */
109157 const memCacheEntry = memCache && memCache . get ( this ) ;
110- const hash = getLazyRequestsHash (
158+ const etag = getProvidedExportsEtag (
111159 module ,
112160 lazyBarrelController ,
113161 hashFunction
@@ -116,7 +164,7 @@ class FlagDependencyExportsPlugin {
116164 // detection cannot invalidate the mem cache when the un-lazied
117165 // connections are unsafe-cached (they are skipped when comparing
118166 // references)
119- if ( memCacheEntry !== undefined && memCacheEntry . etag === hash ) {
167+ if ( memCacheEntry !== undefined && memCacheEntry . etag === etag ) {
120168 statRestoredFromMemCache ++ ;
121169 exportsInfo . restoreProvided ( memCacheEntry . data ) ;
122170 return callback ( ) ;
@@ -126,7 +174,7 @@ class FlagDependencyExportsPlugin {
126174 ) ;
127175 cache . get (
128176 module . identifier ( ) ,
129- hash ? `${ buildHash } |${ hash } ` : buildHash ,
177+ etag ? `${ buildHash } |${ etag } ` : buildHash ,
130178 ( err , result ) => {
131179 if ( err ) return callback ( err ) ;
132180
@@ -349,12 +397,13 @@ class FlagDependencyExportsPlugin {
349397 changed = true ;
350398 }
351399
352- if (
353- inlined !== undefined &&
354- exportInfo . canInlineProvide === undefined
355- ) {
356- exportInfo . canInlineProvide = inlined ;
357- changed = true ;
400+ if ( inlined !== undefined ) {
401+ const prev = exportInfo . canInlineProvide ;
402+ // Watch rebuilds keep ExportInfo; refresh when the constant changes
403+ if ( prev === undefined || ! prev . equals ( inlined ) ) {
404+ exportInfo . canInlineProvide = inlined ;
405+ changed = true ;
406+ }
358407 }
359408
360409 if ( terminalBinding && ! exportInfo . terminalBinding ) {
@@ -511,15 +560,15 @@ class FlagDependencyExportsPlugin {
511560 . getRestoreProvidedData ( ) ;
512561 const memCache =
513562 moduleMemCaches && moduleMemCaches . get ( module ) ;
514- const hash = getLazyRequestsHash (
563+ const etag = getProvidedExportsEtag (
515564 module ,
516565 lazyBarrelController ,
517566 hashFunction
518567 ) ;
519568 if ( memCache ) {
520569 /** @type {MemCacheEntry } */
521570 const entry = {
522- etag : hash ,
571+ etag,
523572 data : cachedData
524573 } ;
525574 memCache . set ( this , entry ) ;
@@ -529,7 +578,7 @@ class FlagDependencyExportsPlugin {
529578 ) ;
530579 cache . store (
531580 module . identifier ( ) ,
532- hash ? `${ buildHash } |${ hash } ` : buildHash ,
581+ etag ? `${ buildHash } |${ etag } ` : buildHash ,
533582 cachedData ,
534583 callback
535584 ) ;
0 commit comments