1
1
const NormalModule = require ( 'webpack/lib/NormalModule' ) ;
2
2
const Module = require ( 'webpack/lib/Module' ) ;
3
3
4
+ const nodeObjectHash = require ( 'node-object-hash' ) ;
5
+
4
6
const logMessages = require ( './util/log-messages' ) ;
5
7
const {
6
8
relateNormalPath,
@@ -11,6 +13,44 @@ const {
11
13
const pluginCompat = require ( './util/plugin-compat' ) ;
12
14
const serial = require ( './util/serial' ) ;
13
15
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
+
14
54
const serialNormalModule4 = serial . serial ( 'NormalModule' , {
15
55
constructor : serial . constructed ( NormalModule , {
16
56
data : serial . pipe (
@@ -124,6 +164,8 @@ const serialNormalModule4 = serial.serial('NormalModule', {
124
164
_buildHash : serial . identity ,
125
165
hash : serial . identity ,
126
166
_lastSuccessfulBuildMeta : serial . identity ,
167
+
168
+ __hardSource_resolved : serialResolvedMap ,
127
169
} ) ,
128
170
129
171
dependencyBlock : serial . dependencyBlock ,
@@ -159,6 +201,9 @@ const needRebuild4 = function() {
159
201
}
160
202
const fileHashes = this . __hardSourceFileMd5s ;
161
203
const cachedHashes = this . __hardSourceCachedMd5s ;
204
+ const resolvedLast = this . __hardSource_resolved ;
205
+ const missingCache = this . __hardSource_missingCache ;
206
+
162
207
for ( const file of this . buildInfo . fileDependencies ) {
163
208
if ( ! cachedHashes [ file ] || fileHashes [ file ] !== cachedHashes [ file ] ) {
164
209
this . cacheItem . invalid = true ;
@@ -173,7 +218,33 @@ const needRebuild4 = function() {
173
218
return true ;
174
219
}
175
220
}
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 ;
177
248
} ;
178
249
179
250
const serialNormalModule3 = serial . serial ( 'NormalModule' , {
@@ -275,6 +346,8 @@ const serialNormalModule3 = serial.serial('NormalModule', {
275
346
warnings : serial . moduleWarning ,
276
347
errors : serial . moduleError ,
277
348
_source : serial . source ,
349
+
350
+ __hardSource_resolved : serialResolvedMap ,
278
351
} ) ,
279
352
280
353
hash : {
@@ -320,6 +393,9 @@ const needRebuild3 = function() {
320
393
}
321
394
const fileHashes = this . __hardSourceFileMd5s ;
322
395
const cachedHashes = this . __hardSourceCachedMd5s ;
396
+ const resolvedLast = this . __hardSource_resolved ;
397
+ const missingCache = this . __hardSource_missingCache ;
398
+
323
399
for ( const file of this . fileDependencies ) {
324
400
if ( ! cachedHashes [ file ] || fileHashes [ file ] !== cachedHashes [ file ] ) {
325
401
this . cacheItem . invalid = true ;
@@ -334,7 +410,34 @@ const needRebuild3 = function() {
334
410
return true ;
335
411
}
336
412
}
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 ;
338
441
} ;
339
442
340
443
const cacheable = module =>
@@ -498,6 +601,7 @@ class TransformNormalModulePlugin {
498
601
m . cacheItem = frozen ;
499
602
m . __hardSourceFileMd5s = compilation . __hardSourceFileMd5s ;
500
603
m . __hardSourceCachedMd5s = compilation . __hardSourceCachedMd5s ;
604
+ m . __hardSource_missingCache = compiler . __hardSource_missingCache ;
501
605
m . needRebuild = needRebuild ;
502
606
503
607
// Unbuild if there is no cache. The module will be rebuilt. Not
0 commit comments