11const NormalModule = require ( 'webpack/lib/NormalModule' ) ;
22const Module = require ( 'webpack/lib/Module' ) ;
33
4+ const nodeObjectHash = require ( 'node-object-hash' ) ;
5+
46const logMessages = require ( './util/log-messages' ) ;
57const {
68 relateNormalPath,
@@ -11,6 +13,44 @@ const {
1113const pluginCompat = require ( './util/plugin-compat' ) ;
1214const serial = require ( './util/serial' ) ;
1315
16+ const serialResolveRequest = serial . created ( {
17+ context : serial . path ,
18+ request : serial . request ,
19+ } ) ;
20+
21+ const serialResolved = serial . created ( {
22+ // context: serial.path,
23+ // request: serial.request,
24+ // userRequest: serial.request,
25+ // rawRequest: serial.request,
26+ resource : serial . request ,
27+ resolveOptions : serial . identity ,
28+ // loaders: serial.loaders,
29+ } ) ;
30+
31+ const serialResolvedMap = {
32+ freeze ( arg , module , extra ) {
33+ const resolved = [ ] ;
34+ for ( const key in arg ) {
35+ const thawedKey = JSON . parse ( key ) ;
36+ resolved . push ( [
37+ serialResolveRequest . freeze ( thawedKey , thawedKey , extra ) ,
38+ serialResolved . freeze ( arg [ key ] , arg [ key ] , extra ) ,
39+ ] ) ;
40+ }
41+ return resolved ;
42+ } ,
43+ thaw ( arg , frozen , extra ) {
44+ const resolved = { } ;
45+ for ( const item of arg ) {
46+ const key = serialResolveRequest . thaw ( item [ 0 ] , item [ 0 ] , extra ) ;
47+ const value = serialResolved . thaw ( item [ 1 ] , item [ 1 ] , extra ) ;
48+ resolved [ JSON . stringify ( key ) ] = value ;
49+ }
50+ return resolved ;
51+ } ,
52+ } ;
53+
1454const serialNormalModule4 = serial . serial ( 'NormalModule' , {
1555 constructor : serial . constructed ( NormalModule , {
1656 data : serial . pipe (
@@ -124,6 +164,8 @@ const serialNormalModule4 = serial.serial('NormalModule', {
124164 _buildHash : serial . identity ,
125165 hash : serial . identity ,
126166 _lastSuccessfulBuildMeta : serial . identity ,
167+
168+ __hardSource_resolved : serialResolvedMap ,
127169 } ) ,
128170
129171 dependencyBlock : serial . dependencyBlock ,
@@ -159,6 +201,9 @@ const needRebuild4 = function() {
159201 }
160202 const fileHashes = this . __hardSourceFileMd5s ;
161203 const cachedHashes = this . __hardSourceCachedMd5s ;
204+ const resolvedLast = this . __hardSource_resolved ;
205+ const missingCache = this . __hardSource_missingCache ;
206+
162207 for ( const file of this . buildInfo . fileDependencies ) {
163208 if ( ! cachedHashes [ file ] || fileHashes [ file ] !== cachedHashes [ file ] ) {
164209 this . cacheItem . invalid = true ;
@@ -173,7 +218,33 @@ const needRebuild4 = function() {
173218 return true ;
174219 }
175220 }
176- return false ;
221+
222+ let resolvedNeedRebuild = false ;
223+ for ( const _resolveKey in resolvedLast ) {
224+ const resolveKey = JSON . parse ( _resolveKey ) ;
225+ const resolved = resolvedLast [ _resolveKey ] ;
226+ let normalId = 'normal' ;
227+ if ( resolved . resolveOptions ) {
228+ normalId = `normal-${ new nodeObjectHash ( { sort : false } ) . hash (
229+ resolved . resolveOptions ,
230+ ) } `;
231+ }
232+ const resolvedMissing =
233+ missingCache [ normalId ] &&
234+ missingCache [ normalId ] [
235+ JSON . stringify ( [ resolveKey . context , resolved . resource . split ( '?' ) [ 0 ] ] )
236+ ] ;
237+ if ( ! resolvedMissing || resolvedMissing . invalid ) {
238+ resolved . invalid = true ;
239+ resolved . invalidReason = `resolved normal invalid${
240+ resolvedMissing
241+ ? ` ${ resolvedMissing . invalidReason } `
242+ : ': resolve entry not in cache'
243+ } `;
244+ resolvedNeedRebuild = true ;
245+ }
246+ }
247+ return resolvedNeedRebuild ;
177248} ;
178249
179250const serialNormalModule3 = serial . serial ( 'NormalModule' , {
@@ -275,6 +346,8 @@ const serialNormalModule3 = serial.serial('NormalModule', {
275346 warnings : serial . moduleWarning ,
276347 errors : serial . moduleError ,
277348 _source : serial . source ,
349+
350+ __hardSource_resolved : serialResolvedMap ,
278351 } ) ,
279352
280353 hash : {
@@ -320,6 +393,9 @@ const needRebuild3 = function() {
320393 }
321394 const fileHashes = this . __hardSourceFileMd5s ;
322395 const cachedHashes = this . __hardSourceCachedMd5s ;
396+ const resolvedLast = this . __hardSource_resolved ;
397+ const missingCache = this . __hardSource_missingCache ;
398+
323399 for ( const file of this . fileDependencies ) {
324400 if ( ! cachedHashes [ file ] || fileHashes [ file ] !== cachedHashes [ file ] ) {
325401 this . cacheItem . invalid = true ;
@@ -334,7 +410,34 @@ const needRebuild3 = function() {
334410 return true ;
335411 }
336412 }
337- return false ;
413+
414+ let resolvedNeedRebuild = false ;
415+ for ( const _resolveKey in resolvedLast ) {
416+ const resolveKey = JSON . parse ( _resolveKey ) ;
417+ const resolved = resolvedLast [ _resolveKey ] ;
418+ let normalId = 'normal' ;
419+ if ( resolved . resolveOptions ) {
420+ normalId = `normal-${ new nodeObjectHash ( { sort : false } ) . hash (
421+ resolved . resolveOptions ,
422+ ) } `;
423+ }
424+ const resolvedMissing =
425+ missingCache [ normalId ] &&
426+ missingCache [ normalId ] [
427+ JSON . stringify ( [ resolveKey . context , resolved . resource . split ( '?' ) [ 0 ] ] )
428+ ] ;
429+ if ( ! resolvedMissing || resolvedMissing . invalid ) {
430+ resolved . invalid = true ;
431+ resolved . invalidReason = `resolved normal invalid${
432+ resolvedMissing
433+ ? ` ${ resolvedMissing . invalidReason } `
434+ : ': resolve entry not in cache'
435+ } `;
436+ resolvedNeedRebuild = true ;
437+ }
438+ }
439+
440+ return resolvedNeedRebuild ;
338441} ;
339442
340443const cacheable = module =>
@@ -498,6 +601,7 @@ class TransformNormalModulePlugin {
498601 m . cacheItem = frozen ;
499602 m . __hardSourceFileMd5s = compilation . __hardSourceFileMd5s ;
500603 m . __hardSourceCachedMd5s = compilation . __hardSourceCachedMd5s ;
604+ m . __hardSource_missingCache = compiler . __hardSource_missingCache ;
501605 m . needRebuild = needRebuild ;
502606
503607 // Unbuild if there is no cache. The module will be rebuilt. Not
0 commit comments