webpack 5.37.0 → 5.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (139) hide show
  1. package/README.md +5 -8
  2. package/bin/webpack.js +20 -5
  3. package/lib/AsyncDependencyToInitialChunkError.js +0 -2
  4. package/lib/CacheFacade.js +3 -3
  5. package/lib/CaseSensitiveModulesWarning.js +0 -2
  6. package/lib/Chunk.js +8 -5
  7. package/lib/ChunkRenderError.js +0 -2
  8. package/lib/CodeGenerationError.js +0 -2
  9. package/lib/CommentCompilationWarning.js +0 -2
  10. package/lib/Compilation.js +43 -55
  11. package/lib/Compiler.js +7 -4
  12. package/lib/ConcatenationScope.js +2 -1
  13. package/lib/ConcurrentCompilationError.js +0 -2
  14. package/lib/ContextModule.js +5 -4
  15. package/lib/ContextModuleFactory.js +3 -1
  16. package/lib/ContextReplacementPlugin.js +4 -3
  17. package/lib/DefinePlugin.js +16 -12
  18. package/lib/DllReferencePlugin.js +0 -2
  19. package/lib/EntryPlugin.js +3 -3
  20. package/lib/EvalSourceMapDevToolPlugin.js +3 -1
  21. package/lib/ExportsInfo.js +20 -13
  22. package/lib/FileSystemInfo.js +24 -30
  23. package/lib/FlagDependencyExportsPlugin.js +8 -7
  24. package/lib/FlagDependencyUsagePlugin.js +2 -4
  25. package/lib/HarmonyLinkingError.js +0 -2
  26. package/lib/HookWebpackError.js +0 -1
  27. package/lib/HotModuleReplacementPlugin.js +27 -32
  28. package/lib/InvalidDependenciesModuleWarning.js +0 -2
  29. package/lib/JavascriptMetaInfoPlugin.js +2 -1
  30. package/lib/MainTemplate.js +2 -3
  31. package/lib/ModuleBuildError.js +0 -2
  32. package/lib/ModuleDependencyError.js +0 -2
  33. package/lib/ModuleDependencyWarning.js +0 -2
  34. package/lib/ModuleError.js +0 -2
  35. package/lib/ModuleFilenameHelpers.js +4 -2
  36. package/lib/ModuleGraphConnection.js +6 -2
  37. package/lib/ModuleInfoHeaderPlugin.js +2 -3
  38. package/lib/ModuleNotFoundError.js +0 -2
  39. package/lib/ModuleParseError.js +0 -2
  40. package/lib/ModuleRestoreError.js +0 -2
  41. package/lib/ModuleStoreError.js +0 -2
  42. package/lib/ModuleWarning.js +0 -2
  43. package/lib/MultiCompiler.js +31 -27
  44. package/lib/NoModeWarning.js +0 -2
  45. package/lib/NormalModule.js +26 -8
  46. package/lib/NormalModuleFactory.js +2 -0
  47. package/lib/RecordIdsPlugin.js +5 -4
  48. package/lib/ResolverFactory.js +10 -7
  49. package/lib/SourceMapDevToolPlugin.js +13 -14
  50. package/lib/Template.js +4 -2
  51. package/lib/UnsupportedFeatureWarning.js +0 -2
  52. package/lib/WarnDeprecatedOptionPlugin.js +0 -2
  53. package/lib/Watching.js +91 -47
  54. package/lib/WebpackError.js +0 -2
  55. package/lib/asset/AssetGenerator.js +46 -29
  56. package/lib/asset/AssetModulesPlugin.js +1 -1
  57. package/lib/buildChunkGraph.js +21 -21
  58. package/lib/cache/PackFileCacheStrategy.js +12 -9
  59. package/lib/config/defaults.js +21 -10
  60. package/lib/config/normalization.js +8 -7
  61. package/lib/config/target.js +7 -2
  62. package/lib/debug/ProfilingPlugin.js +4 -3
  63. package/lib/dependencies/AMDRequireDependency.js +3 -3
  64. package/lib/dependencies/CommonJsExportRequireDependency.js +2 -3
  65. package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -1
  66. package/lib/dependencies/CommonJsImportsParserPlugin.js +2 -4
  67. package/lib/dependencies/CommonJsPlugin.js +8 -7
  68. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
  69. package/lib/dependencies/ContextDependencyHelpers.js +10 -8
  70. package/lib/dependencies/ContextElementDependency.js +6 -1
  71. package/lib/dependencies/CriticalDependencyWarning.js +0 -2
  72. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +11 -13
  73. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +2 -4
  74. package/lib/dependencies/HarmonyImportSpecifierDependency.js +4 -11
  75. package/lib/dependencies/ImportDependency.js +3 -3
  76. package/lib/dependencies/ImportParserPlugin.js +3 -4
  77. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +2 -3
  78. package/lib/dependencies/RequireEnsureDependency.js +3 -3
  79. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +0 -2
  80. package/lib/dependencies/SystemPlugin.js +0 -2
  81. package/lib/dependencies/WorkerDependency.js +6 -6
  82. package/lib/dependencies/WorkerPlugin.js +18 -19
  83. package/lib/errors/BuildCycleError.js +0 -1
  84. package/lib/hmr/LazyCompilationPlugin.js +9 -5
  85. package/lib/ids/HashedModuleIdsPlugin.js +3 -3
  86. package/lib/ids/OccurrenceModuleIdsPlugin.js +2 -3
  87. package/lib/index.js +5 -3
  88. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -6
  89. package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -3
  90. package/lib/javascript/JavascriptGenerator.js +3 -1
  91. package/lib/javascript/JavascriptModulesPlugin.js +15 -23
  92. package/lib/javascript/JavascriptParser.js +10 -8
  93. package/lib/library/AssignLibraryPlugin.js +4 -2
  94. package/lib/node/NodeEnvironmentPlugin.js +1 -0
  95. package/lib/node/NodeWatchFileSystem.js +19 -4
  96. package/lib/optimize/AggressiveSplittingPlugin.js +5 -4
  97. package/lib/optimize/ConcatenatedModule.js +31 -27
  98. package/lib/optimize/FlagIncludedChunksPlugin.js +4 -6
  99. package/lib/optimize/InnerGraph.js +9 -11
  100. package/lib/optimize/InnerGraphPlugin.js +3 -1
  101. package/lib/optimize/ModuleConcatenationPlugin.js +7 -10
  102. package/lib/optimize/RealContentHashPlugin.js +14 -16
  103. package/lib/optimize/SideEffectsFlagPlugin.js +6 -5
  104. package/lib/optimize/SplitChunksPlugin.js +13 -15
  105. package/lib/performance/AssetsOverSizeLimitWarning.js +0 -2
  106. package/lib/performance/EntrypointsOverSizeLimitWarning.js +0 -2
  107. package/lib/performance/NoAsyncChunksWarning.js +0 -2
  108. package/lib/runtime/EnsureChunkRuntimeModule.js +9 -8
  109. package/lib/runtime/LoadScriptRuntimeModule.js +2 -3
  110. package/lib/runtime/OnChunksLoadedRuntimeModule.js +38 -37
  111. package/lib/schemes/DataUriPlugin.js +21 -2
  112. package/lib/serialization/BinaryMiddleware.js +5 -3
  113. package/lib/serialization/FileMiddleware.js +3 -1
  114. package/lib/serialization/ObjectMiddleware.js +11 -7
  115. package/lib/stats/DefaultStatsFactoryPlugin.js +7 -7
  116. package/lib/stats/DefaultStatsPrinterPlugin.js +11 -9
  117. package/lib/stats/StatsFactory.js +2 -1
  118. package/lib/stats/StatsPrinter.js +3 -3
  119. package/lib/util/LazyBucketSortedSet.js +3 -3
  120. package/lib/util/cleverMerge.js +3 -1
  121. package/lib/util/comparators.js +13 -13
  122. package/lib/util/createHash.js +5 -4
  123. package/lib/util/identifier.js +2 -1
  124. package/lib/util/serialization.js +108 -59
  125. package/lib/validateSchema.js +5 -3
  126. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +4 -4
  127. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +0 -2
  128. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +5 -4
  129. package/lib/wasm-sync/WebAssemblyGenerator.js +89 -83
  130. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +0 -2
  131. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -1
  132. package/lib/wasm-sync/WebAssemblyParser.js +6 -5
  133. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -4
  134. package/lib/webpack.js +11 -7
  135. package/package.json +9 -6
  136. package/schemas/WebpackOptions.check.js +1 -1
  137. package/schemas/WebpackOptions.json +76 -60
  138. package/types.d.ts +112 -262
  139. package/lib/util/DataURI.js +0 -32
@@ -164,8 +164,6 @@ class NonErrorEmittedError extends WebpackError {
164
164
 
165
165
  this.name = "NonErrorEmittedError";
166
166
  this.message = "(Emitted value instead of an instance of Error) " + error;
167
-
168
- Error.captureStackTrace(this, this.constructor);
169
167
  }
170
168
  }
171
169
 
@@ -219,6 +217,7 @@ class NormalModule extends Module {
219
217
  * @param {string} options.rawRequest request without resolving
220
218
  * @param {LoaderItem[]} options.loaders list of loaders
221
219
  * @param {string} options.resource path + query of the real resource
220
+ * @param {Record<string, any>=} options.resourceResolveData resource resolve data
222
221
  * @param {string | undefined} options.matchResource path + query of the matched resource (virtual)
223
222
  * @param {Parser} options.parser the parser used
224
223
  * @param {object} options.parserOptions the options of the parser used
@@ -234,6 +233,7 @@ class NormalModule extends Module {
234
233
  rawRequest,
235
234
  loaders,
236
235
  resource,
236
+ resourceResolveData,
237
237
  matchResource,
238
238
  parser,
239
239
  parserOptions,
@@ -260,6 +260,7 @@ class NormalModule extends Module {
260
260
  this.generatorOptions = generatorOptions;
261
261
  /** @type {string} */
262
262
  this.resource = resource;
263
+ this.resourceResolveData = resourceResolveData;
263
264
  /** @type {string | undefined} */
264
265
  this.matchResource = matchResource;
265
266
  /** @type {LoaderItem[]} */
@@ -276,6 +277,8 @@ class NormalModule extends Module {
276
277
  this._source = null;
277
278
  /** @private @type {Map<string, number> | undefined} **/
278
279
  this._sourceSizes = undefined;
280
+ /** @private @type {Set<string>} */
281
+ this._sourceTypes = undefined;
279
282
 
280
283
  // Cache
281
284
  this._lastSuccessfulBuildMeta = {};
@@ -347,12 +350,19 @@ class NormalModule extends Module {
347
350
  this.resource = m.resource;
348
351
  this.matchResource = m.matchResource;
349
352
  this.loaders = m.loaders;
353
+ this._sourceTypes = m._sourceTypes;
354
+ this._sourceSizes = m._sourceSizes;
350
355
  }
351
356
 
352
357
  /**
353
358
  * Assuming this module is in the cache. Remove internal references to allow freeing some memory.
354
359
  */
355
360
  cleanupForCache() {
361
+ // Make sure to cache types and sizes before cleanup
362
+ if (this._sourceTypes === undefined) this.getSourceTypes();
363
+ for (const type of this._sourceTypes) {
364
+ this.size(type);
365
+ }
356
366
  super.cleanupForCache();
357
367
  this.parser = undefined;
358
368
  this.parserOptions = undefined;
@@ -390,6 +400,7 @@ class NormalModule extends Module {
390
400
  this.type,
391
401
  this.generatorOptions
392
402
  );
403
+ // we assume the generator behaves identically and keep cached sourceTypes/Sizes
393
404
  }
394
405
 
395
406
  /**
@@ -765,7 +776,11 @@ class NormalModule extends Module {
765
776
  },
766
777
  (err, result) => {
767
778
  // Cleanup loaderContext to avoid leaking memory in ICs
768
- loaderContext._compilation = loaderContext._compiler = loaderContext._module = loaderContext.fs = undefined;
779
+ loaderContext._compilation =
780
+ loaderContext._compiler =
781
+ loaderContext._module =
782
+ loaderContext.fs =
783
+ undefined;
769
784
 
770
785
  if (!result) {
771
786
  return processResult(
@@ -869,6 +884,7 @@ class NormalModule extends Module {
869
884
  this._forceBuild = false;
870
885
  this._source = null;
871
886
  if (this._sourceSizes !== undefined) this._sourceSizes.clear();
887
+ this._sourceTypes = undefined;
872
888
  this._ast = null;
873
889
  this.error = null;
874
890
  this.clearWarningsAndErrors();
@@ -887,7 +903,7 @@ class NormalModule extends Module {
887
903
  assetsInfo: undefined
888
904
  };
889
905
 
890
- const startTime = Date.now();
906
+ const startTime = compilation.compiler.fsStartTime || Date.now();
891
907
 
892
908
  return this.doBuild(options, compilation, resolver, fs, err => {
893
909
  // if we have an error mark module as failed and exit
@@ -958,7 +974,8 @@ class NormalModule extends Module {
958
974
  checkDependencies(this.buildInfo.missingDependencies);
959
975
  checkDependencies(this.buildInfo.contextDependencies);
960
976
  if (nonAbsoluteDependencies !== undefined) {
961
- const InvalidDependenciesModuleWarning = getInvalidDependenciesModuleWarning();
977
+ const InvalidDependenciesModuleWarning =
978
+ getInvalidDependenciesModuleWarning();
962
979
  this.addWarning(
963
980
  new InvalidDependenciesModuleWarning(this, nonAbsoluteDependencies)
964
981
  );
@@ -1070,7 +1087,10 @@ class NormalModule extends Module {
1070
1087
  * @returns {Set<string>} types available (do not mutate)
1071
1088
  */
1072
1089
  getSourceTypes() {
1073
- return this.generator.getTypes(this);
1090
+ if (this._sourceTypes === undefined) {
1091
+ this._sourceTypes = this.generator.getTypes(this);
1092
+ }
1093
+ return this._sourceTypes;
1074
1094
  }
1075
1095
 
1076
1096
  /**
@@ -1259,7 +1279,6 @@ class NormalModule extends Module {
1259
1279
  const { write } = context;
1260
1280
  // deserialize
1261
1281
  write(this._source);
1262
- write(this._sourceSizes);
1263
1282
  write(this.error);
1264
1283
  write(this._lastSuccessfulBuildMeta);
1265
1284
  write(this._forceBuild);
@@ -1291,7 +1310,6 @@ class NormalModule extends Module {
1291
1310
  deserialize(context) {
1292
1311
  const { read } = context;
1293
1312
  this._source = read();
1294
- this._sourceSizes = read();
1295
1313
  this.error = read();
1296
1314
  this._lastSuccessfulBuildMeta = read();
1297
1315
  this._forceBuild = read();
@@ -168,6 +168,7 @@ const unsafeCacheData = new WeakMap();
168
168
 
169
169
  const ruleSetCompiler = new RuleSetCompiler([
170
170
  new BasicMatcherRulePlugin("test", "resource"),
171
+ new BasicMatcherRulePlugin("scheme"),
171
172
  new BasicMatcherRulePlugin("mimetype"),
172
173
  new BasicMatcherRulePlugin("dependency"),
173
174
  new BasicMatcherRulePlugin("include", "resource"),
@@ -443,6 +444,7 @@ class NormalModuleFactory extends ModuleFactory {
443
444
  realResource: resourceData.path,
444
445
  resourceQuery: resourceDataForRules.query,
445
446
  resourceFragment: resourceDataForRules.fragment,
447
+ scheme,
446
448
  mimetype: matchResourceData ? "" : resourceData.data.mimetype || "",
447
449
  dependency: dependencyType,
448
450
  descriptionData: matchResourceData
@@ -48,10 +48,11 @@ class RecordIdsPlugin {
48
48
  apply(compiler) {
49
49
  const portableIds = this.options.portableIds;
50
50
 
51
- const makePathsRelative = identifierUtils.makePathsRelative.bindContextCache(
52
- compiler.context,
53
- compiler.root
54
- );
51
+ const makePathsRelative =
52
+ identifierUtils.makePathsRelative.bindContextCache(
53
+ compiler.context,
54
+ compiler.root
55
+ );
55
56
 
56
57
  /**
57
58
  * @param {Module} module the module
@@ -42,9 +42,9 @@ const convertToResolveOptions = resolveOptionsWithDepType => {
42
42
  ...remaining,
43
43
  plugins:
44
44
  plugins &&
45
- /** @type {ResolvePluginInstance[]} */ (plugins.filter(
46
- item => item !== "..."
47
- ))
45
+ /** @type {ResolvePluginInstance[]} */ (
46
+ plugins.filter(item => item !== "...")
47
+ )
48
48
  };
49
49
 
50
50
  if (!partialOptions.fileSystem) {
@@ -53,7 +53,10 @@ const convertToResolveOptions = resolveOptionsWithDepType => {
53
53
  );
54
54
  }
55
55
  // These weird types validate that we checked all non-optional properties
56
- const options = /** @type {Partial<ResolveOptions> & Pick<ResolveOptions, "fileSystem">} */ (partialOptions);
56
+ const options =
57
+ /** @type {Partial<ResolveOptions> & Pick<ResolveOptions, "fileSystem">} */ (
58
+ partialOptions
59
+ );
57
60
 
58
61
  return removeOperations(
59
62
  resolveByProperty(options, "byDependency", dependencyType)
@@ -124,9 +127,9 @@ module.exports = class ResolverFactory {
124
127
  const resolveOptions = convertToResolveOptions(
125
128
  this.hooks.resolveOptions.for(type).call(resolveOptionsWithDepType)
126
129
  );
127
- const resolver = /** @type {ResolverWithOptions} */ (Factory.createResolver(
128
- resolveOptions
129
- ));
130
+ const resolver = /** @type {ResolverWithOptions} */ (
131
+ Factory.createResolver(resolveOptions)
132
+ );
130
133
  if (!resolver) {
131
134
  throw new Error("No resolver created");
132
135
  }
@@ -430,19 +430,20 @@ class SourceMapDevToolPlugin {
430
430
  currentSourceMappingURLComment !== false &&
431
431
  /\.css($|\?)/i.test(file)
432
432
  ) {
433
- currentSourceMappingURLComment = currentSourceMappingURLComment.replace(
434
- /^\n\/\/(.*)$/,
435
- "\n/*$1*/"
436
- );
433
+ currentSourceMappingURLComment =
434
+ currentSourceMappingURLComment.replace(
435
+ /^\n\/\/(.*)$/,
436
+ "\n/*$1*/"
437
+ );
437
438
  }
438
439
  const sourceMapString = JSON.stringify(sourceMap);
439
440
  if (sourceMapFilename) {
440
441
  let filename = file;
441
442
  const sourceMapContentHash =
442
443
  usesContentHash &&
443
- /** @type {string} */ (createHash("md4")
444
- .update(sourceMapString)
445
- .digest("hex"));
444
+ /** @type {string} */ (
445
+ createHash("md4").update(sourceMapString).digest("hex")
446
+ );
446
447
  const pathParams = {
447
448
  chunk,
448
449
  filename: options.fileContext
@@ -454,13 +455,11 @@ class SourceMapDevToolPlugin {
454
455
  : filename,
455
456
  contentHash: sourceMapContentHash
456
457
  };
457
- const {
458
- path: sourceMapFile,
459
- info: sourceMapInfo
460
- } = compilation.getPathWithInfo(
461
- sourceMapFilename,
462
- pathParams
463
- );
458
+ const { path: sourceMapFile, info: sourceMapInfo } =
459
+ compilation.getPathWithInfo(
460
+ sourceMapFilename,
461
+ pathParams
462
+ );
464
463
  const sourceMapUrl = options.publicPath
465
464
  ? options.publicPath + sourceMapFile
466
465
  : relative(
package/lib/Template.js CHANGED
@@ -413,5 +413,7 @@ class Template {
413
413
  }
414
414
 
415
415
  module.exports = Template;
416
- module.exports.NUMBER_OF_IDENTIFIER_START_CHARS = NUMBER_OF_IDENTIFIER_START_CHARS;
417
- module.exports.NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS = NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS;
416
+ module.exports.NUMBER_OF_IDENTIFIER_START_CHARS =
417
+ NUMBER_OF_IDENTIFIER_START_CHARS;
418
+ module.exports.NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS =
419
+ NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS;
@@ -21,8 +21,6 @@ class UnsupportedFeatureWarning extends WebpackError {
21
21
  this.name = "UnsupportedFeatureWarning";
22
22
  this.loc = loc;
23
23
  this.hideStack = true;
24
-
25
- Error.captureStackTrace(this, this.constructor);
26
24
  }
27
25
  }
28
26
 
@@ -48,8 +48,6 @@ class DeprecatedOptionWarning extends WebpackError {
48
48
  "configuration\n" +
49
49
  `The value '${value}' for option '${option}' is deprecated. ` +
50
50
  `Use '${suggestion}' instead.`;
51
-
52
- Error.captureStackTrace(this, this.constructor);
53
51
  }
54
52
  }
55
53
 
package/lib/Watching.js CHANGED
@@ -57,16 +57,70 @@ class Watching {
57
57
  this._needRecords = true;
58
58
  this.watcher = undefined;
59
59
  this.pausedWatcher = undefined;
60
+ /** @type {Set<string>} */
61
+ this._collectedChangedFiles = undefined;
62
+ /** @type {Set<string>} */
63
+ this._collectedRemovedFiles = undefined;
60
64
  this._done = this._done.bind(this);
61
65
  process.nextTick(() => {
62
66
  if (this._initial) this._invalidate();
63
67
  });
64
68
  }
65
69
 
66
- _go() {
70
+ _mergeWithCollected(changedFiles, removedFiles) {
71
+ if (!changedFiles) return;
72
+ if (!this._collectedChangedFiles) {
73
+ this._collectedChangedFiles = new Set(changedFiles);
74
+ this._collectedRemovedFiles = new Set(removedFiles);
75
+ } else {
76
+ for (const file of changedFiles) {
77
+ this._collectedChangedFiles.add(file);
78
+ this._collectedRemovedFiles.delete(file);
79
+ }
80
+ for (const file of removedFiles) {
81
+ this._collectedChangedFiles.delete(file);
82
+ this._collectedRemovedFiles.add(file);
83
+ }
84
+ }
85
+ }
86
+
87
+ _go(fileTimeInfoEntries, contextTimeInfoEntries, changedFiles, removedFiles) {
67
88
  this._initial = false;
68
89
  this.startTime = Date.now();
69
90
  this.running = true;
91
+ if (this.watcher) {
92
+ this.pausedWatcher = this.watcher;
93
+ this.lastWatcherStartTime = Date.now();
94
+ this.watcher.pause();
95
+ this.watcher = null;
96
+ } else if (!this.lastWatcherStartTime) {
97
+ this.lastWatcherStartTime = Date.now();
98
+ }
99
+ this.compiler.fsStartTime = Date.now();
100
+ this._mergeWithCollected(
101
+ changedFiles ||
102
+ (this.pausedWatcher &&
103
+ this.pausedWatcher.getAggregatedChanges &&
104
+ this.pausedWatcher.getAggregatedChanges()),
105
+ (this.compiler.removedFiles =
106
+ removedFiles ||
107
+ (this.pausedWatcher &&
108
+ this.pausedWatcher.getAggregatedRemovals &&
109
+ this.pausedWatcher.getAggregatedRemovals()))
110
+ );
111
+
112
+ this.compiler.modifiedFiles = this._collectedChangedFiles;
113
+ this._collectedChangedFiles = undefined;
114
+ this.compiler.removedFiles = this._collectedRemovedFiles;
115
+ this._collectedRemovedFiles = undefined;
116
+
117
+ this.compiler.fileTimestamps =
118
+ fileTimeInfoEntries ||
119
+ (this.pausedWatcher && this.pausedWatcher.getFileTimeInfoEntries());
120
+ this.compiler.contextTimestamps =
121
+ contextTimeInfoEntries ||
122
+ (this.pausedWatcher && this.pausedWatcher.getContextTimeInfoEntries());
123
+
70
124
  const run = () => {
71
125
  if (this.compiler.idle) {
72
126
  return this.compiler.cache.endIdle(err => {
@@ -159,13 +213,16 @@ class Watching {
159
213
 
160
214
  let stats = null;
161
215
 
162
- const handleError = err => {
216
+ const handleError = (err, cbs) => {
163
217
  this.compiler.hooks.failed.call(err);
164
218
  this.compiler.cache.beginIdle();
165
219
  this.compiler.idle = true;
166
220
  this.handler(err, stats);
167
- for (const cb of this.callbacks) cb();
168
- this.callbacks.length = 0;
221
+ if (!cbs) {
222
+ cbs = this.callbacks;
223
+ this.callbacks = [];
224
+ }
225
+ for (const cb of cbs) cb(err);
169
226
  };
170
227
 
171
228
  if (
@@ -197,17 +254,19 @@ class Watching {
197
254
  }
198
255
  if (err) return handleError(err);
199
256
 
257
+ const cbs = this.callbacks;
258
+ this.callbacks = [];
200
259
  logger.time("done hook");
201
260
  this.compiler.hooks.done.callAsync(stats, err => {
202
261
  logger.timeEnd("done hook");
203
- if (err) return handleError(err);
262
+ if (err) return handleError(err, cbs);
204
263
  this.handler(null, stats);
205
264
  logger.time("storeBuildDependencies");
206
265
  this.compiler.cache.storeBuildDependencies(
207
266
  compilation.buildDependencies,
208
267
  err => {
209
268
  logger.timeEnd("storeBuildDependencies");
210
- if (err) return handleError(err);
269
+ if (err) return handleError(err, cbs);
211
270
  logger.time("beginIdle");
212
271
  this.compiler.cache.beginIdle();
213
272
  this.compiler.idle = true;
@@ -221,8 +280,7 @@ class Watching {
221
280
  );
222
281
  }
223
282
  });
224
- for (const cb of this.callbacks) cb();
225
- this.callbacks.length = 0;
283
+ for (const cb of cbs) cb(null);
226
284
  this.compiler.hooks.afterDone.call(stats);
227
285
  }
228
286
  );
@@ -241,7 +299,7 @@ class Watching {
241
299
  files,
242
300
  dirs,
243
301
  missing,
244
- this.startTime,
302
+ this.lastWatcherStartTime,
245
303
  this.watchOptions,
246
304
  (
247
305
  err,
@@ -250,25 +308,20 @@ class Watching {
250
308
  changedFiles,
251
309
  removedFiles
252
310
  ) => {
253
- this.pausedWatcher = this.watcher;
254
- this.watcher = null;
255
311
  if (err) {
256
312
  this.compiler.modifiedFiles = undefined;
257
313
  this.compiler.removedFiles = undefined;
258
314
  this.compiler.fileTimestamps = undefined;
259
315
  this.compiler.contextTimestamps = undefined;
316
+ this.compiler.fsStartTime = undefined;
260
317
  return this.handler(err);
261
318
  }
262
- this.compiler.fileTimestamps = fileTimeInfoEntries;
263
- this.compiler.contextTimestamps = contextTimeInfoEntries;
264
- this.compiler.removedFiles = removedFiles;
265
- this.compiler.modifiedFiles = changedFiles;
266
- if (this.watcher) {
267
- this.pausedWatcher = this.watcher;
268
- this.watcher.pause();
269
- this.watcher = null;
270
- }
271
- this._invalidate();
319
+ this._invalidate(
320
+ fileTimeInfoEntries,
321
+ contextTimeInfoEntries,
322
+ changedFiles,
323
+ removedFiles
324
+ );
272
325
  this._onChange();
273
326
  },
274
327
  (fileName, changeTime) => {
@@ -293,33 +346,31 @@ class Watching {
293
346
  this._invalidReported = true;
294
347
  this.compiler.hooks.invalid.call(null, Date.now());
295
348
  }
349
+ this._onChange();
296
350
  this._invalidate();
297
351
  }
298
352
 
299
- _invalidate() {
300
- if (this.suspended) return;
301
- if (this._isBlocked()) {
302
- this.blocked = true;
353
+ _invalidate(
354
+ fileTimeInfoEntries,
355
+ contextTimeInfoEntries,
356
+ changedFiles,
357
+ removedFiles
358
+ ) {
359
+ if (this.suspended || (this._isBlocked() && (this.blocked = true))) {
360
+ this._mergeWithCollected(changedFiles, removedFiles);
303
361
  return;
304
362
  }
305
- if (this.watcher) {
306
- this.compiler.modifiedFiles =
307
- this.watcher.getAggregatedChanges &&
308
- this.watcher.getAggregatedChanges();
309
- this.compiler.removedFiles =
310
- this.watcher.getAggregatedRemovals &&
311
- this.watcher.getAggregatedRemovals();
312
- this.compiler.fileTimestamps = this.watcher.getFileTimeInfoEntries();
313
- this.compiler.contextTimestamps = this.watcher.getContextTimeInfoEntries();
314
- this.pausedWatcher = this.watcher;
315
- this.watcher.pause();
316
- this.watcher = null;
317
- }
318
363
 
319
364
  if (this.running) {
365
+ this._mergeWithCollected(changedFiles, removedFiles);
320
366
  this.invalid = true;
321
367
  } else {
322
- this._go();
368
+ this._go(
369
+ fileTimeInfoEntries,
370
+ contextTimeInfoEntries,
371
+ changedFiles,
372
+ removedFiles
373
+ );
323
374
  }
324
375
  }
325
376
 
@@ -334,14 +385,6 @@ class Watching {
334
385
  }
335
386
  }
336
387
 
337
- _checkUnblocked() {
338
- if (this.blocked && !this._isBlocked()) {
339
- this.blocked = false;
340
- this._needWatcherInfo = true;
341
- this._invalidate();
342
- }
343
- }
344
-
345
388
  /**
346
389
  * @param {Callback<void>} callback signals when the watcher is closed
347
390
  * @returns {void}
@@ -362,6 +405,7 @@ class Watching {
362
405
  this.compiler.removedFiles = undefined;
363
406
  this.compiler.fileTimestamps = undefined;
364
407
  this.compiler.contextTimestamps = undefined;
408
+ this.compiler.fsStartTime = undefined;
365
409
  const shutdown = () => {
366
410
  this.compiler.cache.shutdown(err => {
367
411
  this.compiler.hooks.watchClose.call();
@@ -31,8 +31,6 @@ class WebpackError extends Error {
31
31
  this.chunk = undefined;
32
32
  /** @type {string} */
33
33
  this.file = undefined;
34
-
35
- Error.captureStackTrace(this, this.constructor);
36
34
  }
37
35
 
38
36
  [inspect]() {
@@ -120,12 +120,33 @@ class AssetGenerator extends Generator {
120
120
  }
121
121
  );
122
122
  } else {
123
- const encoding = this.dataUrlOptions.encoding;
124
- const ext = path.extname(module.nameForCondition());
125
- const mimeType =
126
- this.dataUrlOptions.mimetype || mimeTypes.lookup(ext);
127
-
128
- if (!mimeType) {
123
+ /** @type {string | false | undefined} */
124
+ let encoding = this.dataUrlOptions.encoding;
125
+ if (encoding === undefined) {
126
+ if (
127
+ module.resourceResolveData &&
128
+ module.resourceResolveData.encoding !== undefined
129
+ ) {
130
+ encoding = module.resourceResolveData.encoding;
131
+ }
132
+ }
133
+ if (encoding === undefined) {
134
+ encoding = "base64";
135
+ }
136
+ let ext;
137
+ let mimeType = this.dataUrlOptions.mimetype;
138
+ if (mimeType === undefined) {
139
+ ext = path.extname(module.nameForCondition());
140
+ if (
141
+ module.resourceResolveData &&
142
+ module.resourceResolveData.mimetype !== undefined
143
+ ) {
144
+ mimeType = module.resourceResolveData.mimetype;
145
+ } else if (ext) {
146
+ mimeType = mimeTypes.lookup(ext);
147
+ }
148
+ }
149
+ if (typeof mimeType !== "string") {
129
150
  throw new Error(
130
151
  "DataUrl can't be generated automatically, " +
131
152
  `because there is no mimetype for "${ext}" in mimetype database. ` +
@@ -170,9 +191,9 @@ class AssetGenerator extends Generator {
170
191
  hash.update(runtimeTemplate.outputOptions.hashSalt);
171
192
  }
172
193
  hash.update(originalSource.buffer());
173
- const fullHash = /** @type {string} */ (hash.digest(
174
- runtimeTemplate.outputOptions.hashDigest
175
- ));
194
+ const fullHash = /** @type {string} */ (
195
+ hash.digest(runtimeTemplate.outputOptions.hashDigest)
196
+ );
176
197
  const contentHash = fullHash.slice(
177
198
  0,
178
199
  runtimeTemplate.outputOptions.hashDigestLength
@@ -183,26 +204,9 @@ class AssetGenerator extends Generator {
183
204
  module.matchResource || module.resource,
184
205
  runtimeTemplate.compilation.compiler.root
185
206
  ).replace(/^\.\//, "");
186
- let {
187
- path: filename,
188
- info: assetInfo
189
- } = runtimeTemplate.compilation.getAssetPathWithInfo(
190
- assetModuleFilename,
191
- {
192
- module,
193
- runtime,
194
- filename: sourceFilename,
195
- chunkGraph,
196
- contentHash
197
- }
198
- );
199
- let publicPath;
200
- if (this.publicPath) {
201
- const {
202
- path,
203
- info
204
- } = runtimeTemplate.compilation.getAssetPathWithInfo(
205
- this.publicPath,
207
+ let { path: filename, info: assetInfo } =
208
+ runtimeTemplate.compilation.getAssetPathWithInfo(
209
+ assetModuleFilename,
206
210
  {
207
211
  module,
208
212
  runtime,
@@ -211,6 +215,19 @@ class AssetGenerator extends Generator {
211
215
  contentHash
212
216
  }
213
217
  );
218
+ let publicPath;
219
+ if (this.publicPath) {
220
+ const { path, info } =
221
+ runtimeTemplate.compilation.getAssetPathWithInfo(
222
+ this.publicPath,
223
+ {
224
+ module,
225
+ runtime,
226
+ filename: sourceFilename,
227
+ chunkGraph,
228
+ contentHash
229
+ }
230
+ );
214
231
  publicPath = JSON.stringify(path);
215
232
  assetInfo = mergeAssetInfo(assetInfo, info);
216
233
  } else {
@@ -129,7 +129,7 @@ class AssetModulesPlugin {
129
129
  dataUrl = generatorOptions.dataUrl;
130
130
  if (!dataUrl || typeof dataUrl === "object") {
131
131
  dataUrl = {
132
- encoding: "base64",
132
+ encoding: undefined,
133
133
  mimetype: undefined,
134
134
  ...dataUrl
135
135
  };