webpack 5.99.5 → 5.99.7

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.
Files changed (169) hide show
  1. package/README.md +1 -1
  2. package/lib/APIPlugin.js +2 -2
  3. package/lib/AutomaticPrefetchPlugin.js +21 -22
  4. package/lib/BannerPlugin.js +31 -35
  5. package/lib/Cache.js +1 -1
  6. package/lib/Chunk.js +12 -9
  7. package/lib/CleanPlugin.js +5 -3
  8. package/lib/Compilation.js +45 -35
  9. package/lib/Compiler.js +6 -4
  10. package/lib/ContextExclusionPlugin.js +4 -2
  11. package/lib/ContextModule.js +2 -1
  12. package/lib/ContextReplacementPlugin.js +5 -3
  13. package/lib/DelegatedPlugin.js +4 -2
  14. package/lib/DllEntryPlugin.js +4 -2
  15. package/lib/DllPlugin.js +5 -3
  16. package/lib/DllReferencePlugin.js +56 -60
  17. package/lib/DynamicEntryPlugin.js +4 -2
  18. package/lib/EntryOptionPlugin.js +3 -1
  19. package/lib/EntryPlugin.js +4 -2
  20. package/lib/EnvironmentPlugin.js +4 -2
  21. package/lib/EvalDevToolModulePlugin.js +9 -7
  22. package/lib/EvalSourceMapDevToolPlugin.js +137 -138
  23. package/lib/ExternalsPlugin.js +3 -1
  24. package/lib/FlagDependencyExportsPlugin.js +2 -1
  25. package/lib/HotModuleReplacementPlugin.js +3 -3
  26. package/lib/IgnorePlugin.js +6 -4
  27. package/lib/IgnoreWarningsPlugin.js +4 -2
  28. package/lib/LibManifestPlugin.js +3 -4
  29. package/lib/LoaderOptionsPlugin.js +4 -2
  30. package/lib/LoaderTargetPlugin.js +4 -2
  31. package/lib/Module.js +29 -14
  32. package/lib/ModuleFilenameHelpers.js +1 -1
  33. package/lib/ModuleGraph.js +15 -10
  34. package/lib/ModuleInfoHeaderPlugin.js +11 -12
  35. package/lib/MultiCompiler.js +5 -3
  36. package/lib/NoEmitOnErrorsPlugin.js +5 -3
  37. package/lib/NormalModule.js +6 -2
  38. package/lib/NormalModuleReplacementPlugin.js +33 -36
  39. package/lib/PlatformPlugin.js +3 -1
  40. package/lib/PrefetchPlugin.js +5 -3
  41. package/lib/ProgressPlugin.js +23 -26
  42. package/lib/RecordIdsPlugin.js +73 -103
  43. package/lib/RuntimePlugin.js +34 -32
  44. package/lib/SourceMapDevToolPlugin.js +8 -6
  45. package/lib/Template.js +1 -1
  46. package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
  47. package/lib/WarnNoModeSetPlugin.js +3 -1
  48. package/lib/WatchIgnorePlugin.js +3 -1
  49. package/lib/WebpackError.js +11 -3
  50. package/lib/WebpackOptionsApply.js +22 -5
  51. package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
  52. package/lib/buildChunkGraph.js +7 -2
  53. package/lib/cache/IdleFileCachePlugin.js +12 -13
  54. package/lib/cache/MemoryCachePlugin.js +2 -1
  55. package/lib/cache/MemoryWithGcCachePlugin.js +10 -7
  56. package/lib/cache/PackFileCacheStrategy.js +13 -21
  57. package/lib/cache/ResolverCachePlugin.js +22 -22
  58. package/lib/cli.js +8 -4
  59. package/lib/config/defaults.js +2 -2
  60. package/lib/config/normalization.js +9 -3
  61. package/lib/config/target.js +6 -6
  62. package/lib/container/ContainerReferencePlugin.js +24 -26
  63. package/lib/container/ModuleFederationPlugin.js +2 -1
  64. package/lib/css/CssGenerator.js +1 -1
  65. package/lib/css/CssModulesPlugin.js +6 -4
  66. package/lib/css/CssParser.js +1 -1
  67. package/lib/debug/ProfilingPlugin.js +1 -1
  68. package/lib/dependencies/ContextDependencyHelpers.js +1 -1
  69. package/lib/dependencies/CssIcssImportDependency.js +3 -2
  70. package/lib/dependencies/HarmonyDetectionParserPlugin.js +9 -15
  71. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  72. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
  73. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -1
  74. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
  75. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
  76. package/lib/dependencies/JsonExportsDependency.js +1 -1
  77. package/lib/dependencies/LoaderPlugin.js +5 -3
  78. package/lib/dependencies/LocalModulesHelpers.js +1 -1
  79. package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
  80. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
  81. package/lib/dependencies/RequireResolveDependency.js +1 -1
  82. package/lib/dependencies/WorkerPlugin.js +2 -2
  83. package/lib/esm/ModuleChunkLoadingPlugin.js +76 -57
  84. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +11 -9
  85. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  86. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -1
  87. package/lib/hmr/LazyCompilationPlugin.js +17 -18
  88. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
  89. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  90. package/lib/ids/DeterministicModuleIdsPlugin.js +48 -49
  91. package/lib/ids/HashedModuleIdsPlugin.js +4 -2
  92. package/lib/ids/NamedChunkIdsPlugin.js +6 -4
  93. package/lib/ids/NamedModuleIdsPlugin.js +6 -4
  94. package/lib/ids/NaturalChunkIdsPlugin.js +4 -2
  95. package/lib/ids/NaturalModuleIdsPlugin.js +4 -2
  96. package/lib/ids/OccurrenceChunkIdsPlugin.js +4 -2
  97. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -2
  98. package/lib/index.js +1 -1
  99. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  100. package/lib/javascript/JavascriptParser.js +670 -688
  101. package/lib/library/EnableLibraryPlugin.js +15 -2
  102. package/lib/library/ModuleLibraryPlugin.js +66 -43
  103. package/lib/logging/createConsoleLogger.js +0 -1
  104. package/lib/node/CommonJsChunkLoadingPlugin.js +71 -75
  105. package/lib/node/NodeEnvironmentPlugin.js +3 -1
  106. package/lib/node/NodeTemplatePlugin.js +2 -2
  107. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
  108. package/lib/node/ReadFileCompileWasmPlugin.js +3 -3
  109. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  110. package/lib/optimize/AggressiveSplittingPlugin.js +224 -232
  111. package/lib/optimize/ConcatenatedModule.js +12 -15
  112. package/lib/optimize/FlagIncludedChunksPlugin.js +92 -97
  113. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  114. package/lib/optimize/MangleExportsPlugin.js +15 -16
  115. package/lib/optimize/MinChunkSizePlugin.js +4 -2
  116. package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
  117. package/lib/optimize/RealContentHashPlugin.js +4 -2
  118. package/lib/optimize/RemoveEmptyChunksPlugin.js +5 -3
  119. package/lib/optimize/RemoveParentModulesPlugin.js +4 -2
  120. package/lib/optimize/RuntimeChunkPlugin.js +17 -18
  121. package/lib/optimize/SplitChunksPlugin.js +9 -6
  122. package/lib/performance/SizeLimitsPlugin.js +3 -1
  123. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
  124. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
  125. package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
  126. package/lib/schemes/DataUriPlugin.js +5 -3
  127. package/lib/schemes/FileUriPlugin.js +5 -3
  128. package/lib/schemes/HttpUriPlugin.js +32 -39
  129. package/lib/serialization/AggregateErrorSerializer.js +42 -0
  130. package/lib/serialization/BinaryMiddleware.js +22 -38
  131. package/lib/serialization/ErrorObjectSerializer.js +7 -2
  132. package/lib/serialization/FileMiddleware.js +29 -33
  133. package/lib/serialization/ObjectMiddleware.js +42 -30
  134. package/lib/serialization/Serializer.js +29 -18
  135. package/lib/serialization/SerializerMiddleware.js +105 -72
  136. package/lib/serialization/SingleItemMiddleware.js +4 -5
  137. package/lib/sharing/ProvideSharedPlugin.js +6 -4
  138. package/lib/stats/DefaultStatsFactoryPlugin.js +128 -57
  139. package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
  140. package/lib/stats/DefaultStatsPrinterPlugin.js +486 -334
  141. package/lib/stats/StatsFactory.js +47 -10
  142. package/lib/stats/StatsPrinter.js +52 -31
  143. package/lib/util/ArrayQueue.js +1 -1
  144. package/lib/util/AsyncQueue.js +1 -1
  145. package/lib/util/TupleQueue.js +9 -7
  146. package/lib/util/TupleSet.js +37 -18
  147. package/lib/util/WeakTupleMap.js +50 -37
  148. package/lib/util/cleverMerge.js +2 -2
  149. package/lib/util/comparators.js +1 -1
  150. package/lib/util/concatenate.js +4 -2
  151. package/lib/util/createHash.js +1 -1
  152. package/lib/util/fs.js +1 -1
  153. package/lib/util/makeSerializable.js +1 -1
  154. package/lib/util/runtime.js +1 -0
  155. package/lib/util/serialization.js +50 -42
  156. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  157. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -1
  158. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  159. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
  160. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -1
  161. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  162. package/lib/web/FetchCompileWasmPlugin.js +2 -2
  163. package/lib/web/JsonpChunkLoadingPlugin.js +73 -74
  164. package/lib/webpack.js +1 -1
  165. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
  166. package/package.json +4 -3
  167. package/schemas/WebpackOptions.check.js +1 -1
  168. package/schemas/WebpackOptions.json +24 -2
  169. package/types.d.ts +273 -128
@@ -12,6 +12,8 @@ const ModuleChunkLoadingRuntimeModule = require("./ModuleChunkLoadingRuntimeModu
12
12
  /** @typedef {import("../Chunk")} Chunk */
13
13
  /** @typedef {import("../Compiler")} Compiler */
14
14
 
15
+ const PLUGIN_NAME = "ModuleChunkLoadingPlugin";
16
+
15
17
  class ModuleChunkLoadingPlugin {
16
18
  /**
17
19
  * Apply the plugin
@@ -19,68 +21,85 @@ class ModuleChunkLoadingPlugin {
19
21
  * @returns {void}
20
22
  */
21
23
  apply(compiler) {
22
- compiler.hooks.thisCompilation.tap(
23
- "ModuleChunkLoadingPlugin",
24
- compilation => {
25
- const globalChunkLoading = compilation.outputOptions.chunkLoading;
26
- /**
27
- * @param {Chunk} chunk chunk to check
28
- * @returns {boolean} true, when the plugin is enabled for the chunk
29
- */
30
- const isEnabledForChunk = chunk => {
31
- const options = chunk.getEntryOptions();
32
- const chunkLoading =
33
- options && options.chunkLoading !== undefined
34
- ? options.chunkLoading
35
- : globalChunkLoading;
36
- return chunkLoading === "import";
37
- };
38
- const onceForChunkSet = new WeakSet();
39
- /**
40
- * @param {Chunk} chunk chunk to check
41
- * @param {Set<string>} set runtime requirements
42
- */
43
- const handler = (chunk, set) => {
44
- if (onceForChunkSet.has(chunk)) return;
45
- onceForChunkSet.add(chunk);
24
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
25
+ const globalChunkLoading = compilation.outputOptions.chunkLoading;
26
+ /**
27
+ * @param {Chunk} chunk chunk to check
28
+ * @returns {boolean} true, when the plugin is enabled for the chunk
29
+ */
30
+ const isEnabledForChunk = chunk => {
31
+ const options = chunk.getEntryOptions();
32
+ const chunkLoading =
33
+ options && options.chunkLoading !== undefined
34
+ ? options.chunkLoading
35
+ : globalChunkLoading;
36
+ return chunkLoading === "import";
37
+ };
38
+ const onceForChunkSet = new WeakSet();
39
+ /**
40
+ * @param {Chunk} chunk chunk to check
41
+ * @param {Set<string>} set runtime requirements
42
+ */
43
+ const handler = (chunk, set) => {
44
+ if (onceForChunkSet.has(chunk)) return;
45
+ onceForChunkSet.add(chunk);
46
+ if (!isEnabledForChunk(chunk)) return;
47
+ set.add(RuntimeGlobals.moduleFactoriesAddOnly);
48
+ set.add(RuntimeGlobals.hasOwnProperty);
49
+ compilation.addRuntimeModule(
50
+ chunk,
51
+ new ModuleChunkLoadingRuntimeModule(set)
52
+ );
53
+ };
54
+ compilation.hooks.runtimeRequirementInTree
55
+ .for(RuntimeGlobals.ensureChunkHandlers)
56
+ .tap(PLUGIN_NAME, handler);
57
+ compilation.hooks.runtimeRequirementInTree
58
+ .for(RuntimeGlobals.baseURI)
59
+ .tap(PLUGIN_NAME, handler);
60
+ compilation.hooks.runtimeRequirementInTree
61
+ .for(RuntimeGlobals.externalInstallChunk)
62
+ .tap(PLUGIN_NAME, handler);
63
+ compilation.hooks.runtimeRequirementInTree
64
+ .for(RuntimeGlobals.onChunksLoaded)
65
+ .tap(PLUGIN_NAME, handler);
66
+ compilation.hooks.runtimeRequirementInTree
67
+ .for(RuntimeGlobals.externalInstallChunk)
68
+ .tap(PLUGIN_NAME, (chunk, set) => {
46
69
  if (!isEnabledForChunk(chunk)) return;
47
- set.add(RuntimeGlobals.moduleFactoriesAddOnly);
48
- set.add(RuntimeGlobals.hasOwnProperty);
49
70
  compilation.addRuntimeModule(
50
71
  chunk,
51
- new ModuleChunkLoadingRuntimeModule(set)
72
+ new ExportWebpackRequireRuntimeModule()
52
73
  );
53
- };
54
- compilation.hooks.runtimeRequirementInTree
55
- .for(RuntimeGlobals.ensureChunkHandlers)
56
- .tap("ModuleChunkLoadingPlugin", handler);
57
- compilation.hooks.runtimeRequirementInTree
58
- .for(RuntimeGlobals.baseURI)
59
- .tap("ModuleChunkLoadingPlugin", handler);
60
- compilation.hooks.runtimeRequirementInTree
61
- .for(RuntimeGlobals.externalInstallChunk)
62
- .tap("ModuleChunkLoadingPlugin", handler);
63
- compilation.hooks.runtimeRequirementInTree
64
- .for(RuntimeGlobals.onChunksLoaded)
65
- .tap("ModuleChunkLoadingPlugin", handler);
66
- compilation.hooks.runtimeRequirementInTree
67
- .for(RuntimeGlobals.externalInstallChunk)
68
- .tap("ModuleChunkLoadingPlugin", (chunk, set) => {
69
- if (!isEnabledForChunk(chunk)) return;
70
- compilation.addRuntimeModule(
71
- chunk,
72
- new ExportWebpackRequireRuntimeModule()
73
- );
74
- });
74
+ });
75
+
76
+ // We need public path only when we prefetch/preload chunk or public path is not `auto`
77
+ compilation.hooks.runtimeRequirementInTree
78
+ .for(RuntimeGlobals.prefetchChunkHandlers)
79
+ .tap(PLUGIN_NAME, (chunk, set) => {
80
+ if (!isEnabledForChunk(chunk)) return;
81
+ set.add(RuntimeGlobals.publicPath);
82
+ });
83
+
84
+ compilation.hooks.runtimeRequirementInTree
85
+ .for(RuntimeGlobals.preloadChunkHandlers)
86
+ .tap(PLUGIN_NAME, (chunk, set) => {
87
+ if (!isEnabledForChunk(chunk)) return;
88
+ set.add(RuntimeGlobals.publicPath);
89
+ });
90
+
91
+ compilation.hooks.runtimeRequirementInTree
92
+ .for(RuntimeGlobals.ensureChunkHandlers)
93
+ .tap(PLUGIN_NAME, (chunk, set) => {
94
+ if (!isEnabledForChunk(chunk)) return;
95
+
96
+ if (compilation.outputOptions.publicPath !== "auto") {
97
+ set.add(RuntimeGlobals.publicPath);
98
+ }
75
99
 
76
- compilation.hooks.runtimeRequirementInTree
77
- .for(RuntimeGlobals.ensureChunkHandlers)
78
- .tap("ModuleChunkLoadingPlugin", (chunk, set) => {
79
- if (!isEnabledForChunk(chunk)) return;
80
- set.add(RuntimeGlobals.getChunkScriptFilename);
81
- });
82
- }
83
- );
100
+ set.add(RuntimeGlobals.getChunkScriptFilename);
101
+ });
102
+ });
84
103
  }
85
104
  }
86
105
 
@@ -214,9 +214,11 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
214
214
  : `if(${hasJsMatcher("chunkId")}) {`,
215
215
  Template.indent([
216
216
  "// setup Promise in chunk cache",
217
- `var promise = ${importFunctionName}(${JSON.stringify(
218
- rootOutputDir
219
- )} + ${
217
+ `var promise = ${importFunctionName}(${
218
+ compilation.outputOptions.publicPath === "auto"
219
+ ? ""
220
+ : `${RuntimeGlobals.publicPath} + `
221
+ }${JSON.stringify(rootOutputDir)} + ${
220
222
  RuntimeGlobals.getChunkScriptFilename
221
223
  }(chunkId)).then(installChunk, ${runtimeTemplate.basicFunction(
222
224
  "e",
@@ -248,6 +250,9 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
248
250
  ? `${
249
251
  RuntimeGlobals.prefetchChunkHandlers
250
252
  }.j = ${runtimeTemplate.basicFunction("chunkId", [
253
+ isNeutralPlatform
254
+ ? "if (typeof document === 'undefined') return;"
255
+ : "",
251
256
  `if((!${
252
257
  RuntimeGlobals.hasOwnProperty
253
258
  }(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
@@ -255,9 +260,6 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
255
260
  }) {`,
256
261
  Template.indent([
257
262
  "installedChunks[chunkId] = null;",
258
- isNeutralPlatform
259
- ? "if (typeof document === 'undefined') return;"
260
- : "",
261
263
  linkPrefetch.call(
262
264
  Template.asString([
263
265
  "var link = document.createElement('link');",
@@ -288,6 +290,9 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
288
290
  ? `${
289
291
  RuntimeGlobals.preloadChunkHandlers
290
292
  }.j = ${runtimeTemplate.basicFunction("chunkId", [
293
+ isNeutralPlatform
294
+ ? "if (typeof document === 'undefined') return;"
295
+ : "",
291
296
  `if((!${
292
297
  RuntimeGlobals.hasOwnProperty
293
298
  }(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
@@ -295,9 +300,6 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
295
300
  }) {`,
296
301
  Template.indent([
297
302
  "installedChunks[chunkId] = null;",
298
- isNeutralPlatform
299
- ? "if (typeof document === 'undefined') return;"
300
- : "",
301
303
  linkPreload.call(
302
304
  Template.asString([
303
305
  "var link = document.createElement('link');",
@@ -69,7 +69,6 @@ module.exports = function () {
69
69
  me.children.push(request);
70
70
  }
71
71
  } else {
72
- // eslint-disable-next-line no-console
73
72
  console.warn(
74
73
  "[HMR] unexpected require(" +
75
74
  request +
@@ -109,7 +109,6 @@ module.exports = function () {
109
109
  var appliedUpdate = {};
110
110
 
111
111
  var warnUnexpectedRequire = function warnUnexpectedRequire(module) {
112
- // eslint-disable-next-line no-console
113
112
  console.warn(
114
113
  "[HMR] unexpected require(" + module.id + ") to disposed module"
115
114
  );
@@ -353,6 +353,8 @@ class LazyCompilationDependencyFactory extends ModuleFactory {
353
353
  * @property {(RegExp | string | ((module: Module) => boolean))=} test additional filter for lazy compiled entrypoint modules
354
354
  */
355
355
 
356
+ const PLUGIN_NAME = "LazyCompilationPlugin";
357
+
356
358
  class LazyCompilationPlugin {
357
359
  /**
358
360
  * @param {Options} options options
@@ -372,28 +374,25 @@ class LazyCompilationPlugin {
372
374
  apply(compiler) {
373
375
  /** @type {BackendApi} */
374
376
  let backend;
375
- compiler.hooks.beforeCompile.tapAsync(
376
- "LazyCompilationPlugin",
377
- (params, callback) => {
378
- if (backend !== undefined) return callback();
379
- const promise = this.backend(compiler, (err, result) => {
380
- if (err) return callback(err);
381
- backend = /** @type {BackendApi} */ (result);
377
+ compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, (params, callback) => {
378
+ if (backend !== undefined) return callback();
379
+ const promise = this.backend(compiler, (err, result) => {
380
+ if (err) return callback(err);
381
+ backend = /** @type {BackendApi} */ (result);
382
+ callback();
383
+ });
384
+ if (promise && promise.then) {
385
+ promise.then(b => {
386
+ backend = b;
382
387
  callback();
383
- });
384
- if (promise && promise.then) {
385
- promise.then(b => {
386
- backend = b;
387
- callback();
388
- }, callback);
389
- }
388
+ }, callback);
390
389
  }
391
- );
390
+ });
392
391
  compiler.hooks.thisCompilation.tap(
393
- "LazyCompilationPlugin",
392
+ PLUGIN_NAME,
394
393
  (compilation, { normalModuleFactory }) => {
395
394
  normalModuleFactory.hooks.module.tap(
396
- "LazyCompilationPlugin",
395
+ PLUGIN_NAME,
397
396
  (module, createData, resolveData) => {
398
397
  if (
399
398
  resolveData.dependencies.every(dep =>
@@ -454,7 +453,7 @@ class LazyCompilationPlugin {
454
453
  );
455
454
  }
456
455
  );
457
- compiler.hooks.shutdown.tapAsync("LazyCompilationPlugin", callback => {
456
+ compiler.hooks.shutdown.tapAsync(PLUGIN_NAME, callback => {
458
457
  backend.dispose(callback);
459
458
  });
460
459
  }
@@ -21,6 +21,8 @@ const {
21
21
  * @property {number=} end end id
22
22
  */
23
23
 
24
+ const PLUGIN_NAME = "ChunkModuleIdRangePlugin";
25
+
24
26
  class ChunkModuleIdRangePlugin {
25
27
  /**
26
28
  * @param {ChunkModuleIdRangePluginOptions} options options object
@@ -36,9 +38,9 @@ class ChunkModuleIdRangePlugin {
36
38
  */
37
39
  apply(compiler) {
38
40
  const options = this.options;
39
- compiler.hooks.compilation.tap("ChunkModuleIdRangePlugin", compilation => {
41
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
40
42
  const moduleGraph = compilation.moduleGraph;
41
- compilation.hooks.moduleIds.tap("ChunkModuleIdRangePlugin", modules => {
43
+ compilation.hooks.moduleIds.tap(PLUGIN_NAME, modules => {
42
44
  const chunkGraph = compilation.chunkGraph;
43
45
  const chunk = find(
44
46
  compilation.chunks,
@@ -46,7 +48,7 @@ class ChunkModuleIdRangePlugin {
46
48
  );
47
49
  if (!chunk) {
48
50
  throw new Error(
49
- `ChunkModuleIdRangePlugin: Chunk with name '${options.name}"' was not found`
51
+ `${PLUGIN_NAME}: Chunk with name '${options.name}"' was not found`
50
52
  );
51
53
  }
52
54
 
@@ -63,9 +65,7 @@ class ChunkModuleIdRangePlugin {
63
65
  cmpFn = compareModulesByPostOrderIndexOrIdentifier(moduleGraph);
64
66
  break;
65
67
  default:
66
- throw new Error(
67
- "ChunkModuleIdRangePlugin: unexpected value of order"
68
- );
68
+ throw new Error(`${PLUGIN_NAME}: unexpected value of order`);
69
69
  }
70
70
  chunkModules = chunkGraph.getOrderedChunkModules(chunk, cmpFn);
71
71
  } else {
@@ -23,7 +23,7 @@ const {
23
23
 
24
24
  class DeterministicChunkIdsPlugin {
25
25
  /**
26
- * @param {DeterministicChunkIdsPluginOptions} [options] options
26
+ * @param {DeterministicChunkIdsPluginOptions=} options options
27
27
  */
28
28
  constructor(options = {}) {
29
29
  this.options = options;
@@ -27,9 +27,11 @@ const {
27
27
  * @property {boolean=} failOnConflict throw an error when id conflicts occur (instead of rehashing)
28
28
  */
29
29
 
30
+ const PLUGIN_NAME = "DeterministicModuleIdsPlugin";
31
+
30
32
  class DeterministicModuleIdsPlugin {
31
33
  /**
32
- * @param {DeterministicModuleIdsPluginOptions} [options] options
34
+ * @param {DeterministicModuleIdsPluginOptions=} options options
33
35
  */
34
36
  constructor(options = {}) {
35
37
  this.options = options;
@@ -41,56 +43,53 @@ class DeterministicModuleIdsPlugin {
41
43
  * @returns {void}
42
44
  */
43
45
  apply(compiler) {
44
- compiler.hooks.compilation.tap(
45
- "DeterministicModuleIdsPlugin",
46
- compilation => {
47
- compilation.hooks.moduleIds.tap("DeterministicModuleIdsPlugin", () => {
48
- const chunkGraph = compilation.chunkGraph;
49
- const context = this.options.context
50
- ? this.options.context
51
- : compiler.context;
52
- const maxLength = this.options.maxLength || 3;
53
- const failOnConflict = this.options.failOnConflict || false;
54
- const fixedLength = this.options.fixedLength || false;
55
- const salt = this.options.salt || 0;
56
- let conflicts = 0;
46
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
47
+ compilation.hooks.moduleIds.tap(PLUGIN_NAME, () => {
48
+ const chunkGraph = compilation.chunkGraph;
49
+ const context = this.options.context
50
+ ? this.options.context
51
+ : compiler.context;
52
+ const maxLength = this.options.maxLength || 3;
53
+ const failOnConflict = this.options.failOnConflict || false;
54
+ const fixedLength = this.options.fixedLength || false;
55
+ const salt = this.options.salt || 0;
56
+ let conflicts = 0;
57
57
 
58
- const [usedIds, modules] = getUsedModuleIdsAndModules(
59
- compilation,
60
- this.options.test
61
- );
62
- assignDeterministicIds(
63
- modules,
64
- module => getFullModuleName(module, context, compiler.root),
65
- failOnConflict
66
- ? () => 0
67
- : compareModulesByPreOrderIndexOrIdentifier(
68
- compilation.moduleGraph
69
- ),
70
- (module, id) => {
71
- const size = usedIds.size;
72
- usedIds.add(`${id}`);
73
- if (size === usedIds.size) {
74
- conflicts++;
75
- return false;
76
- }
77
- chunkGraph.setModuleId(module, id);
78
- return true;
79
- },
80
- [10 ** maxLength],
81
- fixedLength ? 0 : 10,
82
- usedIds.size,
83
- salt
58
+ const [usedIds, modules] = getUsedModuleIdsAndModules(
59
+ compilation,
60
+ this.options.test
61
+ );
62
+ assignDeterministicIds(
63
+ modules,
64
+ module => getFullModuleName(module, context, compiler.root),
65
+ failOnConflict
66
+ ? () => 0
67
+ : compareModulesByPreOrderIndexOrIdentifier(
68
+ compilation.moduleGraph
69
+ ),
70
+ (module, id) => {
71
+ const size = usedIds.size;
72
+ usedIds.add(`${id}`);
73
+ if (size === usedIds.size) {
74
+ conflicts++;
75
+ return false;
76
+ }
77
+ chunkGraph.setModuleId(module, id);
78
+ return true;
79
+ },
80
+ [10 ** maxLength],
81
+ fixedLength ? 0 : 10,
82
+ usedIds.size,
83
+ salt
84
+ );
85
+ if (failOnConflict && conflicts)
86
+ throw new Error(
87
+ `Assigning deterministic module ids has lead to ${conflicts} conflict${
88
+ conflicts > 1 ? "s" : ""
89
+ }.\nIncrease the 'maxLength' to increase the id space and make conflicts less likely (recommended when there are many conflicts or application is expected to grow), or add an 'salt' number to try another hash starting value in the same id space (recommended when there is only a single conflict).`
84
90
  );
85
- if (failOnConflict && conflicts)
86
- throw new Error(
87
- `Assigning deterministic module ids has lead to ${conflicts} conflict${
88
- conflicts > 1 ? "s" : ""
89
- }.\nIncrease the 'maxLength' to increase the id space and make conflicts less likely (recommended when there are many conflicts or application is expected to grow), or add an 'salt' number to try another hash starting value in the same id space (recommended when there is only a single conflict).`
90
- );
91
- });
92
- }
93
- );
91
+ });
92
+ });
94
93
  }
95
94
  }
96
95
 
@@ -28,6 +28,8 @@ const validate = createSchemaValidation(
28
28
  }
29
29
  );
30
30
 
31
+ const PLUGIN_NAME = "HashedModuleIdsPlugin";
32
+
31
33
  class HashedModuleIdsPlugin {
32
34
  /**
33
35
  * @param {HashedModuleIdsPluginOptions=} options options object
@@ -52,8 +54,8 @@ class HashedModuleIdsPlugin {
52
54
  */
53
55
  apply(compiler) {
54
56
  const options = this.options;
55
- compiler.hooks.compilation.tap("HashedModuleIdsPlugin", compilation => {
56
- compilation.hooks.moduleIds.tap("HashedModuleIdsPlugin", () => {
57
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
58
+ compilation.hooks.moduleIds.tap(PLUGIN_NAME, () => {
57
59
  const chunkGraph = compilation.chunkGraph;
58
60
  const context = this.options.context
59
61
  ? this.options.context
@@ -21,10 +21,12 @@ const {
21
21
 
22
22
  /**
23
23
  * @typedef {object} NamedChunkIdsPluginOptions
24
- * @property {string} [context] context
25
- * @property {string} [delimiter] delimiter
24
+ * @property {string=} context context
25
+ * @property {string=} delimiter delimiter
26
26
  */
27
27
 
28
+ const PLUGIN_NAME = "NamedChunkIdsPlugin";
29
+
28
30
  class NamedChunkIdsPlugin {
29
31
  /**
30
32
  * @param {NamedChunkIdsPluginOptions=} options options
@@ -40,11 +42,11 @@ class NamedChunkIdsPlugin {
40
42
  * @returns {void}
41
43
  */
42
44
  apply(compiler) {
43
- compiler.hooks.compilation.tap("NamedChunkIdsPlugin", compilation => {
45
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
44
46
  const hashFunction =
45
47
  /** @type {NonNullable<Output["hashFunction"]>} */
46
48
  (compilation.outputOptions.hashFunction);
47
- compilation.hooks.chunkIds.tap("NamedChunkIdsPlugin", chunks => {
49
+ compilation.hooks.chunkIds.tap(PLUGIN_NAME, chunks => {
48
50
  const chunkGraph = compilation.chunkGraph;
49
51
  const context = this.context ? this.context : compiler.context;
50
52
  const delimiter = this.delimiter;
@@ -20,12 +20,14 @@ const {
20
20
 
21
21
  /**
22
22
  * @typedef {object} NamedModuleIdsPluginOptions
23
- * @property {string} [context] context
23
+ * @property {string=} context context
24
24
  */
25
25
 
26
+ const PLUGIN_NAME = "NamedModuleIdsPlugin";
27
+
26
28
  class NamedModuleIdsPlugin {
27
29
  /**
28
- * @param {NamedModuleIdsPluginOptions} [options] options
30
+ * @param {NamedModuleIdsPluginOptions=} options options
29
31
  */
30
32
  constructor(options = {}) {
31
33
  this.options = options;
@@ -38,11 +40,11 @@ class NamedModuleIdsPlugin {
38
40
  */
39
41
  apply(compiler) {
40
42
  const { root } = compiler;
41
- compiler.hooks.compilation.tap("NamedModuleIdsPlugin", compilation => {
43
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
42
44
  const hashFunction =
43
45
  /** @type {NonNullable<Output["hashFunction"]>} */
44
46
  (compilation.outputOptions.hashFunction);
45
- compilation.hooks.moduleIds.tap("NamedModuleIdsPlugin", () => {
47
+ compilation.hooks.moduleIds.tap(PLUGIN_NAME, () => {
46
48
  const chunkGraph = compilation.chunkGraph;
47
49
  const context = this.options.context
48
50
  ? this.options.context
@@ -12,6 +12,8 @@ const { assignAscendingChunkIds } = require("./IdHelpers");
12
12
  /** @typedef {import("../Compiler")} Compiler */
13
13
  /** @typedef {import("../Module")} Module */
14
14
 
15
+ const PLUGIN_NAME = "NaturalChunkIdsPlugin";
16
+
15
17
  class NaturalChunkIdsPlugin {
16
18
  /**
17
19
  * Apply the plugin
@@ -19,8 +21,8 @@ class NaturalChunkIdsPlugin {
19
21
  * @returns {void}
20
22
  */
21
23
  apply(compiler) {
22
- compiler.hooks.compilation.tap("NaturalChunkIdsPlugin", compilation => {
23
- compilation.hooks.chunkIds.tap("NaturalChunkIdsPlugin", chunks => {
24
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
25
+ compilation.hooks.chunkIds.tap(PLUGIN_NAME, chunks => {
24
26
  const chunkGraph = compilation.chunkGraph;
25
27
  const compareNatural = compareChunksNatural(chunkGraph);
26
28
  const chunksInNaturalOrder = Array.from(chunks).sort(compareNatural);
@@ -16,6 +16,8 @@ const {
16
16
  /** @typedef {import("../Compiler")} Compiler */
17
17
  /** @typedef {import("../Module")} Module */
18
18
 
19
+ const PLUGIN_NAME = "NaturalModuleIdsPlugin";
20
+
19
21
  class NaturalModuleIdsPlugin {
20
22
  /**
21
23
  * Apply the plugin
@@ -23,8 +25,8 @@ class NaturalModuleIdsPlugin {
23
25
  * @returns {void}
24
26
  */
25
27
  apply(compiler) {
26
- compiler.hooks.compilation.tap("NaturalModuleIdsPlugin", compilation => {
27
- compilation.hooks.moduleIds.tap("NaturalModuleIdsPlugin", modules => {
28
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
29
+ compilation.hooks.moduleIds.tap(PLUGIN_NAME, modules => {
28
30
  const [usedIds, modulesInNaturalOrder] =
29
31
  getUsedModuleIdsAndModules(compilation);
30
32
  modulesInNaturalOrder.sort(
@@ -23,6 +23,8 @@ const validate = createSchemaValidation(
23
23
  }
24
24
  );
25
25
 
26
+ const PLUGIN_NAME = "OccurrenceChunkIdsPlugin";
27
+
26
28
  class OccurrenceChunkIdsPlugin {
27
29
  /**
28
30
  * @param {OccurrenceChunkIdsPluginOptions=} options options object
@@ -39,8 +41,8 @@ class OccurrenceChunkIdsPlugin {
39
41
  */
40
42
  apply(compiler) {
41
43
  const prioritiseInitial = this.options.prioritiseInitial;
42
- compiler.hooks.compilation.tap("OccurrenceChunkIdsPlugin", compilation => {
43
- compilation.hooks.chunkIds.tap("OccurrenceChunkIdsPlugin", chunks => {
44
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
45
+ compilation.hooks.chunkIds.tap(PLUGIN_NAME, chunks => {
44
46
  const chunkGraph = compilation.chunkGraph;
45
47
 
46
48
  /** @type {Map<Chunk, number>} */
@@ -28,6 +28,8 @@ const validate = createSchemaValidation(
28
28
  }
29
29
  );
30
30
 
31
+ const PLUGIN_NAME = "OccurrenceModuleIdsPlugin";
32
+
31
33
  class OccurrenceModuleIdsPlugin {
32
34
  /**
33
35
  * @param {OccurrenceModuleIdsPluginOptions=} options options object
@@ -44,10 +46,10 @@ class OccurrenceModuleIdsPlugin {
44
46
  */
45
47
  apply(compiler) {
46
48
  const prioritiseInitial = this.options.prioritiseInitial;
47
- compiler.hooks.compilation.tap("OccurrenceModuleIdsPlugin", compilation => {
49
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
48
50
  const moduleGraph = compilation.moduleGraph;
49
51
 
50
- compilation.hooks.moduleIds.tap("OccurrenceModuleIdsPlugin", () => {
52
+ compilation.hooks.moduleIds.tap(PLUGIN_NAME, () => {
51
53
  const chunkGraph = compilation.chunkGraph;
52
54
 
53
55
  const [usedIds, modulesInOccurrenceOrder] =
package/lib/index.js CHANGED
@@ -70,7 +70,7 @@ const memoize = require("./util/memoize");
70
70
  */
71
71
  const lazyFunction = factory => {
72
72
  const fac = memoize(factory);
73
- const f = /** @type {any} */ (
73
+ const f = /** @type {unknown} */ (
74
74
  /**
75
75
  * @param {...EXPECTED_ANY} args args
76
76
  * @returns {T} result
@@ -179,7 +179,7 @@ class BasicEvaluatedExpression {
179
179
 
180
180
  /**
181
181
  * Gets the compile-time value of the expression
182
- * @returns {any} the javascript value
182
+ * @returns {undefined | null | string | number | boolean | RegExp | EXPECTED_ANY[] | bigint} the javascript value
183
183
  */
184
184
  asCompileTimeValue() {
185
185
  switch (this.type) {
@@ -524,7 +524,7 @@ class BasicEvaluatedExpression {
524
524
 
525
525
  /**
526
526
  * Set's the range for the expression.
527
- * @param {[number, number]} range range to set
527
+ * @param {Range} range range to set
528
528
  * @returns {this} this
529
529
  */
530
530
  setRange(range) {