@@ -22,6 +22,7 @@ const ModuleParseError = require("./ModuleParseError");
22
22
const ModuleBuildError = require ( "./ModuleBuildError" ) ;
23
23
const ModuleError = require ( "./ModuleError" ) ;
24
24
const ModuleWarning = require ( "./ModuleWarning" ) ;
25
+ const createHash = require ( "./util/createHash" ) ;
25
26
26
27
const asString = buf => {
27
28
if ( Buffer . isBuffer ( buf ) ) {
@@ -89,6 +90,7 @@ class NormalModule extends Module {
89
90
// Info from Build
90
91
this . error = null ;
91
92
this . _source = null ;
93
+ this . _buildHash = "" ;
92
94
this . buildTimestamp = undefined ;
93
95
this . _cachedSource = undefined ;
94
96
this . _cachedSourceHash = undefined ;
@@ -327,11 +329,23 @@ class NormalModule extends Module {
327
329
return false ;
328
330
}
329
331
332
+ _initBuildHash ( compilation ) {
333
+ const hash = createHash ( compilation . outputOptions . hashFunction ) ;
334
+ if ( this . _source ) {
335
+ hash . update ( "source" ) ;
336
+ this . _source . updateHash ( hash ) ;
337
+ }
338
+ hash . update ( "meta" ) ;
339
+ hash . update ( JSON . stringify ( this . buildMeta ) ) ;
340
+ this . _buildHash = hash . digest ( "hex" ) ;
341
+ }
342
+
330
343
build ( options , compilation , resolver , fs , callback ) {
331
344
this . buildTimestamp = Date . now ( ) ;
332
345
this . built = true ;
333
346
this . _source = null ;
334
347
this . _ast = null ;
348
+ this . _buildHash = "" ;
335
349
this . error = null ;
336
350
this . errors . length = 0 ;
337
351
this . warnings . length = 0 ;
@@ -349,25 +363,29 @@ class NormalModule extends Module {
349
363
// if we have an error mark module as failed and exit
350
364
if ( err ) {
351
365
this . markModuleAsErrored ( err ) ;
366
+ this . _initBuildHash ( compilation ) ;
352
367
return callback ( ) ;
353
368
}
354
369
355
370
// check if this module should !not! be parsed.
356
371
// if so, exit here;
357
372
const noParseRule = options . module && options . module . noParse ;
358
373
if ( this . shouldPreventParsing ( noParseRule , this . request ) ) {
374
+ this . _initBuildHash ( compilation ) ;
359
375
return callback ( ) ;
360
376
}
361
377
362
378
const handleParseError = e => {
363
379
const source = this . _source . source ( ) ;
364
380
const error = new ModuleParseError ( this , source , e ) ;
365
381
this . markModuleAsErrored ( error ) ;
382
+ this . _initBuildHash ( compilation ) ;
366
383
return callback ( ) ;
367
384
} ;
368
385
369
386
const handleParseResult = result => {
370
387
this . _lastSuccessfulBuildMeta = this . buildMeta ;
388
+ this . _initBuildHash ( compilation ) ;
371
389
return callback ( ) ;
372
390
} ;
373
391
@@ -454,23 +472,8 @@ class NormalModule extends Module {
454
472
return this . _source ? this . _source . size ( ) : - 1 ;
455
473
}
456
474
457
- updateHashWithSource ( hash ) {
458
- if ( ! this . _source ) {
459
- hash . update ( "null" ) ;
460
- return ;
461
- }
462
- hash . update ( "source" ) ;
463
- this . _source . updateHash ( hash ) ;
464
- }
465
-
466
- updateHashWithMeta ( hash ) {
467
- hash . update ( "meta" ) ;
468
- hash . update ( JSON . stringify ( this . buildMeta ) ) ;
469
- }
470
-
471
475
updateHash ( hash ) {
472
- this . updateHashWithSource ( hash ) ;
473
- this . updateHashWithMeta ( hash ) ;
476
+ hash . update ( this . _buildHash ) ;
474
477
super . updateHash ( hash ) ;
475
478
}
476
479
}
0 commit comments