webpack 5.89.0 → 5.90.1

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 (167) hide show
  1. package/README.md +3 -0
  2. package/bin/webpack.js +1 -3
  3. package/hot/log.js +0 -2
  4. package/lib/APIPlugin.js +17 -13
  5. package/lib/ChunkGraph.js +1 -1
  6. package/lib/CleanPlugin.js +12 -12
  7. package/lib/Compilation.js +26 -17
  8. package/lib/Compiler.js +13 -0
  9. package/lib/ConcatenationScope.js +2 -2
  10. package/lib/ConditionalInitFragment.js +3 -3
  11. package/lib/ContextModule.js +4 -4
  12. package/lib/ContextModuleFactory.js +1 -1
  13. package/lib/DefinePlugin.js +47 -26
  14. package/lib/DependencyTemplate.js +3 -1
  15. package/lib/EnvironmentNotSupportAsyncWarning.js +52 -0
  16. package/lib/EvalDevToolModulePlugin.js +1 -1
  17. package/lib/EvalSourceMapDevToolPlugin.js +2 -2
  18. package/lib/ExportsInfoApiPlugin.js +2 -2
  19. package/lib/ExternalModule.js +47 -12
  20. package/lib/ExternalModuleFactoryPlugin.js +1 -1
  21. package/lib/FileSystemInfo.js +20 -3
  22. package/lib/FlagDependencyExportsPlugin.js +1 -1
  23. package/lib/Generator.js +1 -0
  24. package/lib/HotModuleReplacementPlugin.js +3 -3
  25. package/lib/InitFragment.js +7 -7
  26. package/lib/LibManifestPlugin.js +4 -1
  27. package/lib/Module.js +2 -1
  28. package/lib/ModuleFilenameHelpers.js +1 -1
  29. package/lib/ModuleInfoHeaderPlugin.js +1 -1
  30. package/lib/MultiStats.js +2 -2
  31. package/lib/NodeStuffPlugin.js +48 -0
  32. package/lib/NormalModule.js +13 -11
  33. package/lib/NormalModuleFactory.js +7 -7
  34. package/lib/RuntimeTemplate.js +15 -11
  35. package/lib/SourceMapDevToolPlugin.js +2 -2
  36. package/lib/Stats.js +4 -0
  37. package/lib/WebpackOptionsApply.js +4 -3
  38. package/lib/asset/AssetModulesPlugin.js +2 -3
  39. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  40. package/lib/buildChunkGraph.js +53 -0
  41. package/lib/cache/AddManagedPathsPlugin.js +6 -1
  42. package/lib/cache/IdleFileCachePlugin.js +12 -5
  43. package/lib/cache/PackFileCacheStrategy.js +3 -3
  44. package/lib/cache/ResolverCachePlugin.js +2 -2
  45. package/lib/config/browserslistTargetHandler.js +35 -14
  46. package/lib/config/defaults.js +88 -52
  47. package/lib/config/normalization.js +17 -18
  48. package/lib/config/target.js +5 -0
  49. package/lib/container/ContainerReferencePlugin.js +1 -1
  50. package/lib/css/CssExportsGenerator.js +14 -1
  51. package/lib/css/CssGenerator.js +14 -1
  52. package/lib/css/CssLoadingRuntimeModule.js +23 -23
  53. package/lib/css/CssModulesPlugin.js +68 -32
  54. package/lib/css/CssParser.js +8 -3
  55. package/lib/debug/ProfilingPlugin.js +2 -2
  56. package/lib/dependencies/AMDDefineDependency.js +4 -4
  57. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +126 -34
  58. package/lib/dependencies/AMDPlugin.js +11 -4
  59. package/lib/dependencies/AMDRequireArrayDependency.js +13 -1
  60. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +159 -43
  61. package/lib/dependencies/AMDRequireDependency.js +2 -2
  62. package/lib/dependencies/AMDRequireItemDependency.js +1 -1
  63. package/lib/dependencies/CachedConstDependency.js +8 -1
  64. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
  65. package/lib/dependencies/ContextElementDependency.js +1 -1
  66. package/lib/dependencies/ExternalModuleDependency.js +107 -0
  67. package/lib/dependencies/ExternalModuleInitFragment.js +131 -0
  68. package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
  69. package/lib/dependencies/HarmonyDetectionParserPlugin.js +7 -1
  70. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +18 -18
  71. package/lib/dependencies/HarmonyExportInitFragment.js +6 -6
  72. package/lib/dependencies/HarmonyImportDependency.js +4 -4
  73. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +6 -6
  74. package/lib/dependencies/ImportDependency.js +26 -6
  75. package/lib/dependencies/JsonExportsDependency.js +1 -1
  76. package/lib/dependencies/LoaderPlugin.js +2 -1
  77. package/lib/dependencies/LocalModuleDependency.js +1 -1
  78. package/lib/dependencies/PureExpressionDependency.js +12 -4
  79. package/lib/dependencies/RequireIncludeDependency.js +1 -1
  80. package/lib/dependencies/WebpackIsIncludedDependency.js +1 -1
  81. package/lib/dependencies/WorkerPlugin.js +10 -3
  82. package/lib/dependencies/getFunctionExpression.js +2 -2
  83. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +6 -6
  84. package/lib/hmr/HotModuleReplacement.runtime.js +3 -5
  85. package/lib/hmr/lazyCompilationBackend.js +4 -4
  86. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  87. package/lib/index.js +4 -0
  88. package/lib/javascript/JavascriptGenerator.js +16 -1
  89. package/lib/javascript/JavascriptModulesPlugin.js +33 -33
  90. package/lib/javascript/JavascriptParser.js +220 -74
  91. package/lib/json/JsonGenerator.js +1 -1
  92. package/lib/library/AmdLibraryPlugin.js +5 -1
  93. package/lib/library/AssignLibraryPlugin.js +1 -1
  94. package/lib/library/SystemLibraryPlugin.js +1 -1
  95. package/lib/library/UmdLibraryPlugin.js +39 -39
  96. package/lib/logging/createConsoleLogger.js +1 -19
  97. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +8 -8
  98. package/lib/node/RequireChunkLoadingRuntimeModule.js +8 -8
  99. package/lib/node/nodeConsole.js +1 -5
  100. package/lib/optimize/ConcatenatedModule.js +7 -7
  101. package/lib/optimize/InnerGraphPlugin.js +9 -1
  102. package/lib/optimize/MangleExportsPlugin.js +5 -1
  103. package/lib/optimize/ModuleConcatenationPlugin.js +2 -2
  104. package/lib/optimize/RemoveParentModulesPlugin.js +123 -47
  105. package/lib/optimize/SideEffectsFlagPlugin.js +15 -3
  106. package/lib/optimize/SplitChunksPlugin.js +16 -16
  107. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +2 -2
  108. package/lib/rules/RuleSetCompiler.js +1 -1
  109. package/lib/runtime/AutoPublicPathRuntimeModule.js +2 -2
  110. package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -4
  111. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -4
  112. package/lib/runtime/LoadScriptRuntimeModule.js +2 -2
  113. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +23 -22
  114. package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -2
  115. package/lib/schemes/HttpUriPlugin.js +1 -1
  116. package/lib/serialization/FileMiddleware.js +4 -4
  117. package/lib/serialization/ObjectMiddleware.js +4 -4
  118. package/lib/sharing/ConsumeSharedPlugin.js +5 -5
  119. package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -4
  120. package/lib/sharing/ProvideSharedModule.js +2 -2
  121. package/lib/sharing/SharePlugin.js +2 -2
  122. package/lib/sharing/ShareRuntimeModule.js +1 -1
  123. package/lib/sharing/utils.js +24 -28
  124. package/lib/stats/DefaultStatsFactoryPlugin.js +10 -10
  125. package/lib/stats/DefaultStatsPresetPlugin.js +3 -7
  126. package/lib/stats/DefaultStatsPrinterPlugin.js +34 -31
  127. package/lib/util/chainedImports.js +7 -6
  128. package/lib/util/cleverMerge.js +4 -4
  129. package/lib/util/comparators.js +59 -23
  130. package/lib/util/hash/xxhash64.js +2 -2
  131. package/lib/util/identifier.js +2 -2
  132. package/lib/util/internalSerializables.js +6 -0
  133. package/lib/util/numberHash.js +64 -52
  134. package/lib/util/runtime.js +18 -1
  135. package/lib/util/semver.js +19 -24
  136. package/lib/util/smartGrouping.js +1 -1
  137. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +53 -28
  138. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -2
  139. package/lib/wasm-async/AsyncWebAssemblyParser.js +6 -0
  140. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  141. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -2
  142. package/lib/web/JsonpChunkLoadingRuntimeModule.js +13 -13
  143. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -6
  144. package/package.json +25 -80
  145. package/schemas/WebpackOptions.check.js +1 -1
  146. package/schemas/WebpackOptions.json +140 -32
  147. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +7 -0
  148. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +6 -0
  149. package/schemas/plugins/css/CssAutoGeneratorOptions.json +3 -0
  150. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +7 -0
  151. package/schemas/plugins/css/CssAutoParserOptions.check.js +6 -0
  152. package/schemas/plugins/css/CssAutoParserOptions.json +3 -0
  153. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  154. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +7 -0
  155. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +6 -0
  156. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +3 -0
  157. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +7 -0
  158. package/schemas/plugins/css/CssGlobalParserOptions.check.js +6 -0
  159. package/schemas/plugins/css/CssGlobalParserOptions.json +3 -0
  160. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
  161. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
  162. package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
  163. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
  164. package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
  165. package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
  166. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  167. package/types.d.ts +273 -94
package/README.md CHANGED
@@ -38,6 +38,9 @@
38
38
  <a href="https://twitter.com/Webpack">
39
39
  <img src="https://img.shields.io/twitter/follow/Webpack?style=social">
40
40
  </a>
41
+ <a href="https://discord.gg/Tt5cKVwx">
42
+ <img src="https://img.shields.io/discord/1180618526436888586?label=discord&logo=discord&logoColor=white&style=flat">
43
+ </a>
41
44
  <h1>webpack</h1>
42
45
  <p>
43
46
  Webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.
package/bin/webpack.js CHANGED
@@ -76,11 +76,10 @@ const isInstalled = packageName => {
76
76
  const runCli = cli => {
77
77
  const path = require("path");
78
78
  const pkgPath = require.resolve(`${cli.package}/package.json`);
79
- // eslint-disable-next-line node/no-missing-require
80
79
  const pkg = require(pkgPath);
81
80
 
82
81
  if (pkg.type === "module" || /\.mjs/i.test(pkg.bin[cli.binName])) {
83
- // eslint-disable-next-line node/no-unsupported-features/es-syntax
82
+ // eslint-disable-next-line n/no-unsupported-features/es-syntax
84
83
  import(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName])).catch(
85
84
  error => {
86
85
  console.error(error);
@@ -88,7 +87,6 @@ const runCli = cli => {
88
87
  }
89
88
  );
90
89
  } else {
91
- // eslint-disable-next-line node/no-missing-require
92
90
  require(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName]));
93
91
  }
94
92
  };
package/hot/log.js CHANGED
@@ -45,11 +45,9 @@ module.exports = function (level, msg) {
45
45
  }
46
46
  };
47
47
 
48
- /* eslint-disable node/no-unsupported-features/node-builtins */
49
48
  var group = console.group || dummy;
50
49
  var groupCollapsed = console.groupCollapsed || dummy;
51
50
  var groupEnd = console.groupEnd || dummy;
52
- /* eslint-enable node/no-unsupported-features/node-builtins */
53
51
 
54
52
  module.exports.group = logGroup(group);
55
53
 
package/lib/APIPlugin.js CHANGED
@@ -24,10 +24,12 @@ const ChunkNameRuntimeModule = require("./runtime/ChunkNameRuntimeModule");
24
24
  const GetFullHashRuntimeModule = require("./runtime/GetFullHashRuntimeModule");
25
25
 
26
26
  /** @typedef {import("./Compiler")} Compiler */
27
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
27
28
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
29
+ /** @typedef {import("./javascript/JavascriptParser").Range} Range */
28
30
 
29
31
  /**
30
- * @param {boolean} module true if ES module
32
+ * @param {boolean | undefined} module true if ES module
31
33
  * @param {string} importMetaName `import.meta` name
32
34
  * @returns {Record<string, {expr: string, req: string[] | null, type?: string, assign: boolean}>} replacements
33
35
  */
@@ -150,7 +152,9 @@ class APIPlugin {
150
152
  compiler.hooks.compilation.tap(
151
153
  PLUGIN_NAME,
152
154
  (compilation, { normalModuleFactory }) => {
153
- const { importMetaName } = compilation.outputOptions;
155
+ const importMetaName = /** @type {string} */ (
156
+ compilation.outputOptions.importMetaName
157
+ );
154
158
  const REPLACEMENTS = getReplacements(
155
159
  this.options.module,
156
160
  importMetaName
@@ -166,7 +170,7 @@ class APIPlugin {
166
170
  .tap(PLUGIN_NAME, chunk => {
167
171
  compilation.addRuntimeModule(
168
172
  chunk,
169
- new ChunkNameRuntimeModule(chunk.name)
173
+ new ChunkNameRuntimeModule(/** @type {string} */ (chunk.name))
170
174
  );
171
175
  return true;
172
176
  });
@@ -218,7 +222,7 @@ class APIPlugin {
218
222
  if (info.assign === false) {
219
223
  parser.hooks.assign.for(key).tap(PLUGIN_NAME, expr => {
220
224
  const err = new WebpackError(`${key} must not be assigned`);
221
- err.loc = expr.loc;
225
+ err.loc = /** @type {DependencyLocation} */ (expr.loc);
222
226
  throw err;
223
227
  });
224
228
  }
@@ -234,9 +238,9 @@ class APIPlugin {
234
238
  .tap(PLUGIN_NAME, expr => {
235
239
  const dep = new ConstDependency(
236
240
  JSON.stringify(parser.state.module.layer),
237
- expr.range
241
+ /** @type {Range} */ (expr.range)
238
242
  );
239
- dep.loc = expr.loc;
243
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
240
244
  parser.state.module.addPresentationalDependency(dep);
241
245
  return true;
242
246
  });
@@ -247,8 +251,8 @@ class APIPlugin {
247
251
  ? new BasicEvaluatedExpression().setNull()
248
252
  : new BasicEvaluatedExpression().setString(
249
253
  parser.state.module.layer
250
- )
251
- ).setRange(expr.range)
254
+ )
255
+ ).setRange(/** @type {Range} */ (expr.range))
252
256
  );
253
257
  parser.hooks.evaluateTypeof
254
258
  .for("__webpack_layer__")
@@ -257,7 +261,7 @@ class APIPlugin {
257
261
  .setString(
258
262
  parser.state.module.layer === null ? "object" : "string"
259
263
  )
260
- .setRange(expr.range)
264
+ .setRange(/** @type {Range} */ (expr.range))
261
265
  );
262
266
 
263
267
  parser.hooks.expression
@@ -267,10 +271,10 @@ class APIPlugin {
267
271
  "__webpack_module__.id";
268
272
  const dep = new ConstDependency(
269
273
  parser.state.module.moduleArgument + ".id",
270
- expr.range,
274
+ /** @type {Range} */ (expr.range),
271
275
  [RuntimeGlobals.moduleId]
272
276
  );
273
- dep.loc = expr.loc;
277
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
274
278
  parser.state.module.addPresentationalDependency(dep);
275
279
  return true;
276
280
  });
@@ -282,10 +286,10 @@ class APIPlugin {
282
286
  "__webpack_module__";
283
287
  const dep = new ConstDependency(
284
288
  parser.state.module.moduleArgument,
285
- expr.range,
289
+ /** @type {Range} */ (expr.range),
286
290
  [RuntimeGlobals.module]
287
291
  );
288
- dep.loc = expr.loc;
292
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
289
293
  parser.state.module.addPresentationalDependency(dep);
290
294
  return true;
291
295
  });
package/lib/ChunkGraph.js CHANGED
@@ -1539,7 +1539,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1539
1539
  return withConnections
1540
1540
  ? BigInt(
1541
1541
  `0x${this._getModuleGraphHashWithConnections(cgm, module, runtime)}`
1542
- )
1542
+ )
1543
1543
  : this._getModuleGraphHashBigInt(cgm, module, runtime);
1544
1544
  }
1545
1545
 
@@ -328,18 +328,18 @@ class CleanPlugin {
328
328
  typeof keep === "function"
329
329
  ? keep
330
330
  : typeof keep === "string"
331
- ? /**
332
- * @param {string} path path
333
- * @returns {boolean} true, if the path should be kept
334
- */
335
- path => path.startsWith(keep)
336
- : typeof keep === "object" && keep.test
337
- ? /**
338
- * @param {string} path path
339
- * @returns {boolean} true, if the path should be kept
340
- */
341
- path => keep.test(path)
342
- : () => false;
331
+ ? /**
332
+ * @param {string} path path
333
+ * @returns {boolean} true, if the path should be kept
334
+ */
335
+ path => path.startsWith(keep)
336
+ : typeof keep === "object" && keep.test
337
+ ? /**
338
+ * @param {string} path path
339
+ * @returns {boolean} true, if the path should be kept
340
+ */
341
+ path => keep.test(path)
342
+ : () => false;
343
343
 
344
344
  // We assume that no external modification happens while the compiler is active
345
345
  // So we can store the old assets and only diff to them to avoid fs access on
@@ -885,6 +885,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
885
885
  this.resolverFactory = compiler.resolverFactory;
886
886
  this.inputFileSystem = compiler.inputFileSystem;
887
887
  this.fileSystemInfo = new FileSystemInfo(this.inputFileSystem, {
888
+ unmanagedPaths: compiler.unmanagedPaths,
888
889
  managedPaths: compiler.managedPaths,
889
890
  immutablePaths: compiler.immutablePaths,
890
891
  logger: this.getLogger("webpack.FileSystemInfo"),
@@ -1086,7 +1087,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1086
1087
  }
1087
1088
 
1088
1089
  /**
1089
- * @param {StatsOptions | string} optionsOrPreset stats option value
1090
+ * @param {StatsOptions | string | undefined} optionsOrPreset stats option value
1090
1091
  * @param {CreateStatsOptionsContext} context context
1091
1092
  * @returns {NormalizedStatsOptions} normalized options
1092
1093
  */
@@ -1177,9 +1178,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1177
1178
  };
1178
1179
  if (this.hooks.log.call(name, logEntry) === undefined) {
1179
1180
  if (logEntry.type === LogType.profileEnd) {
1180
- // eslint-disable-next-line node/no-unsupported-features/node-builtins
1181
1181
  if (typeof console.profileEnd === "function") {
1182
- // eslint-disable-next-line node/no-unsupported-features/node-builtins
1183
1182
  console.profileEnd(`[${name}] ${logEntry.args[0]}`);
1184
1183
  }
1185
1184
  }
@@ -1192,9 +1191,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1192
1191
  }
1193
1192
  logEntries.push(logEntry);
1194
1193
  if (logEntry.type === LogType.profile) {
1195
- // eslint-disable-next-line node/no-unsupported-features/node-builtins
1196
1194
  if (typeof console.profile === "function") {
1197
- // eslint-disable-next-line node/no-unsupported-features/node-builtins
1198
1195
  console.profile(`[${name}] ${logEntry.args[0]}`);
1199
1196
  }
1200
1197
  }
@@ -1725,6 +1722,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1725
1722
  originModule,
1726
1723
  module,
1727
1724
  true,
1725
+ false,
1728
1726
  callback
1729
1727
  );
1730
1728
  }
@@ -1744,6 +1742,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1744
1742
  * @property {string=} context
1745
1743
  * @property {boolean=} recursive recurse into dependencies of the created module
1746
1744
  * @property {boolean=} connectOrigin connect the resolved module with the origin module
1745
+ * @property {boolean=} checkCycle check the cycle dependencies of the created module
1747
1746
  */
1748
1747
 
1749
1748
  /**
@@ -1759,7 +1758,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1759
1758
  contextInfo,
1760
1759
  context,
1761
1760
  recursive = true,
1762
- connectOrigin = recursive
1761
+ connectOrigin = recursive,
1762
+ checkCycle = !recursive
1763
1763
  },
1764
1764
  callback
1765
1765
  ) {
@@ -1880,6 +1880,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1880
1880
  originModule,
1881
1881
  module,
1882
1882
  recursive,
1883
+ checkCycle,
1883
1884
  callback
1884
1885
  );
1885
1886
  });
@@ -1887,10 +1888,16 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1887
1888
  );
1888
1889
  }
1889
1890
 
1890
- _handleModuleBuildAndDependencies(originModule, module, recursive, callback) {
1891
+ _handleModuleBuildAndDependencies(
1892
+ originModule,
1893
+ module,
1894
+ recursive,
1895
+ checkCycle,
1896
+ callback
1897
+ ) {
1891
1898
  // Check for cycles when build is trigger inside another build
1892
1899
  let creatingModuleDuringBuildSet = undefined;
1893
- if (!recursive && this.buildQueue.isProcessing(originModule)) {
1900
+ if (checkCycle && this.buildQueue.isProcessing(originModule)) {
1894
1901
  // Track build dependency
1895
1902
  creatingModuleDuringBuildSet =
1896
1903
  this.creatingModuleDuringBuild.get(originModule);
@@ -1988,8 +1995,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1988
1995
  context: context
1989
1996
  ? context
1990
1997
  : originModule
1991
- ? originModule.context
1992
- : this.compiler.context,
1998
+ ? originModule.context
1999
+ : this.compiler.context,
1993
2000
  dependencies: dependencies
1994
2001
  },
1995
2002
  (err, result) => {
@@ -2668,9 +2675,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2668
2675
  loaders
2669
2676
  ? `${
2670
2677
  modules.length
2671
- } x ${moduleType} with ${this.requestShortener.shorten(
2678
+ } x ${moduleType} with ${this.requestShortener.shorten(
2672
2679
  loaders
2673
- )}`
2680
+ )}`
2674
2681
  : `${modules.length} x ${moduleType}`
2675
2682
  }`
2676
2683
  );
@@ -3078,7 +3085,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3078
3085
  `BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
3079
3086
  Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
3080
3087
  Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.`
3081
- )
3088
+ )
3082
3089
  : Object.freeze(this.assets);
3083
3090
 
3084
3091
  this.summarizeDependencies();
@@ -3341,6 +3348,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3341
3348
  dependencyTemplates,
3342
3349
  runtimeTemplate,
3343
3350
  runtime,
3351
+ runtimes,
3344
3352
  codeGenerationResults: results,
3345
3353
  compilation: this
3346
3354
  });
@@ -4584,8 +4592,8 @@ This prevents using hashes of each other and should be avoided.`);
4584
4592
  (typeof file === "string"
4585
4593
  ? file
4586
4594
  : typeof filenameTemplate === "string"
4587
- ? filenameTemplate
4588
- : "");
4595
+ ? filenameTemplate
4596
+ : "");
4589
4597
 
4590
4598
  this.errors.push(new ChunkRenderError(chunk, filename, err));
4591
4599
  inTry = false;
@@ -4607,7 +4615,7 @@ This prevents using hashes of each other and should be avoided.`);
4607
4615
  ? {
4608
4616
  ...pathAndInfo.info,
4609
4617
  ...fileManifest.info
4610
- }
4618
+ }
4611
4619
  : pathAndInfo.info;
4612
4620
  }
4613
4621
 
@@ -4927,7 +4935,8 @@ This prevents using hashes of each other and should be avoided.`);
4927
4935
  hashFunction,
4928
4936
  runtimeTemplate,
4929
4937
  hashDigest,
4930
- hashDigestLength
4938
+ hashDigestLength,
4939
+ errors
4931
4940
  );
4932
4941
  }
4933
4942
 
package/lib/Compiler.js CHANGED
@@ -228,6 +228,8 @@ class Compiler {
228
228
  /** @type {Set<string | RegExp>} */
229
229
  this.managedPaths = new Set();
230
230
  /** @type {Set<string | RegExp>} */
231
+ this.unmanagedPaths = new Set();
232
+ /** @type {Set<string | RegExp>} */
231
233
  this.immutablePaths = new Set();
232
234
 
233
235
  /** @type {ReadonlySet<string> | undefined} */
@@ -381,6 +383,17 @@ class Compiler {
381
383
  // e.g. move compilation specific info from Modules into ModuleGraph
382
384
  _cleanupLastCompilation() {
383
385
  if (this._lastCompilation !== undefined) {
386
+ for (const childCompilation of this._lastCompilation.children) {
387
+ for (const module of childCompilation.modules) {
388
+ ChunkGraph.clearChunkGraphForModule(module);
389
+ ModuleGraph.clearModuleGraphForModule(module);
390
+ module.cleanupForCache();
391
+ }
392
+ for (const chunk of childCompilation.chunks) {
393
+ ChunkGraph.clearChunkGraphForChunk(chunk);
394
+ }
395
+ }
396
+
384
397
  for (const module of this._lastCompilation.modules) {
385
398
  ChunkGraph.clearChunkGraphForModule(module);
386
399
  ModuleGraph.clearModuleGraphForModule(module);
@@ -114,8 +114,8 @@ class ConcatenationScope {
114
114
  const asiSafeFlag = asiSafe
115
115
  ? "_asiSafe1"
116
116
  : asiSafe === false
117
- ? "_asiSafe0"
118
- : "";
117
+ ? "_asiSafe0"
118
+ : "";
119
119
  const exportData = ids
120
120
  ? Buffer.from(JSON.stringify(ids), "utf-8").toString("hex")
121
121
  : "ns";
@@ -62,8 +62,8 @@ class ConditionalInitFragment extends InitFragment {
62
62
  }
63
63
 
64
64
  /**
65
- * @param {Context} context context
66
- * @returns {string|Source} the source code that will be included as initialization code
65
+ * @param {GenerateContext} context context
66
+ * @returns {string | Source} the source code that will be included as initialization code
67
67
  */
68
68
  getContent(context) {
69
69
  if (this.runtimeCondition === false || !this.content) return "";
@@ -79,7 +79,7 @@ class ConditionalInitFragment extends InitFragment {
79
79
  }
80
80
 
81
81
  /**
82
- * @param {Context} context context
82
+ * @param {GenerateContext} context context
83
83
  * @returns {string|Source=} the source code that will be included at the end of the module
84
84
  */
85
85
  getEndContent(context) {
@@ -509,8 +509,8 @@ class ContextModule extends Module {
509
509
  this.context
510
510
  ? [this.context]
511
511
  : typeof this.options.resource === "string"
512
- ? [this.options.resource]
513
- : /** @type {string[]} */ (this.options.resource),
512
+ ? [this.options.resource]
513
+ : /** @type {string[]} */ (this.options.resource),
514
514
  null,
515
515
  SNAPSHOT_OPTIONS,
516
516
  (err, snapshot) => {
@@ -947,8 +947,8 @@ module.exports = webpackAsyncContext;`;
947
947
  const requestPrefix = hasNoChunk
948
948
  ? "Promise.resolve()"
949
949
  : hasMultipleOrNoChunks
950
- ? `Promise.all(ids.slice(${chunksStartPosition}).map(${RuntimeGlobals.ensureChunk}))`
951
- : `${RuntimeGlobals.ensureChunk}(ids[${chunksStartPosition}])`;
950
+ ? `Promise.all(ids.slice(${chunksStartPosition}).map(${RuntimeGlobals.ensureChunk}))`
951
+ : `${RuntimeGlobals.ensureChunk}(ids[${chunksStartPosition}])`;
952
952
  const returnModuleObject = this.getReturnModuleObjectSource(
953
953
  fakeMap,
954
954
  true,
@@ -160,7 +160,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
160
160
  resolveOptions || EMPTY_RESOLVE_OPTIONS,
161
161
  "dependencyType",
162
162
  dependencies[0].category
163
- )
163
+ )
164
164
  : resolveOptions
165
165
  );
166
166
  const loaderResolver = this.resolverFactory.get("loader");
@@ -23,9 +23,11 @@ const createHash = require("./util/createHash");
23
23
 
24
24
  /** @typedef {import("estree").Expression} Expression */
25
25
  /** @typedef {import("./Compiler")} Compiler */
26
+ /** @typedef {import("./Module").BuildInfo} BuildInfo */
26
27
  /** @typedef {import("./NormalModule")} NormalModule */
27
28
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
28
29
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
30
+ /** @typedef {import("./javascript/JavascriptParser").Range} Range */
29
31
  /** @typedef {import("./logging/Logger").Logger} Logger */
30
32
 
31
33
  /** @typedef {null|undefined|RegExp|Function|string|number|boolean|bigint|undefined} CodeValuePrimitive */
@@ -66,7 +68,7 @@ class RuntimeValue {
66
68
  * @returns {CodeValuePrimitive} code
67
69
  */
68
70
  exec(parser, valueCacheVersions, key) {
69
- const buildInfo = parser.state.module.buildInfo;
71
+ const buildInfo = /** @type {BuildInfo} */ (parser.state.module.buildInfo);
70
72
  if (this.options === true) {
71
73
  buildInfo.cacheable = false;
72
74
  } else {
@@ -136,19 +138,21 @@ const stringifyObj = (
136
138
  let code;
137
139
  let arr = Array.isArray(obj);
138
140
  if (arr) {
139
- code = `[${obj
140
- .map(code =>
141
- toCode(
142
- code,
143
- parser,
144
- valueCacheVersions,
145
- key,
146
- runtimeTemplate,
147
- logger,
148
- null
141
+ code = `[${
142
+ /** @type {any[]} */ (obj)
143
+ .map(code =>
144
+ toCode(
145
+ code,
146
+ parser,
147
+ valueCacheVersions,
148
+ key,
149
+ runtimeTemplate,
150
+ logger,
151
+ null
152
+ )
149
153
  )
150
- )
151
- .join(",")}]`;
154
+ .join(",")
155
+ }]`;
152
156
  } else {
153
157
  let keys = Object.keys(obj);
154
158
  if (objKeys) {
@@ -157,7 +161,7 @@ const stringifyObj = (
157
161
  }
158
162
  code = `{${keys
159
163
  .map(key => {
160
- const code = obj[key];
164
+ const code = /** @type {{[k: string]: any}} */ (obj)[key];
161
165
  return (
162
166
  JSON.stringify(key) +
163
167
  ":" +
@@ -263,6 +267,10 @@ const toCode = (
263
267
  return strCode;
264
268
  };
265
269
 
270
+ /**
271
+ * @param {CodeValue} code code
272
+ * @returns {string | undefined} result
273
+ */
266
274
  const toCacheVersion = code => {
267
275
  if (code === null) {
268
276
  return "null";
@@ -285,7 +293,7 @@ const toCacheVersion = code => {
285
293
  if (typeof code === "object") {
286
294
  const items = Object.keys(code).map(key => ({
287
295
  key,
288
- value: toCacheVersion(code[key])
296
+ value: toCacheVersion(/** @type {Record<string, any>} */ (code)[key])
289
297
  }));
290
298
  if (items.some(({ value }) => value === undefined)) return undefined;
291
299
  return `{${items.map(({ key, value }) => `${key}: ${value}`).join(", ")}}`;
@@ -353,14 +361,21 @@ class DefinePlugin {
353
361
  const handler = parser => {
354
362
  const mainValue = compilation.valueCacheVersions.get(VALUE_DEP_MAIN);
355
363
  parser.hooks.program.tap(PLUGIN_NAME, () => {
356
- const { buildInfo } = parser.state.module;
364
+ const buildInfo = /** @type {BuildInfo} */ (
365
+ parser.state.module.buildInfo
366
+ );
357
367
  if (!buildInfo.valueDependencies)
358
368
  buildInfo.valueDependencies = new Map();
359
369
  buildInfo.valueDependencies.set(VALUE_DEP_MAIN, mainValue);
360
370
  });
361
371
 
372
+ /**
373
+ * @param {string} key key
374
+ */
362
375
  const addValueDependency = key => {
363
- const { buildInfo } = parser.state.module;
376
+ const buildInfo = /** @type {BuildInfo} */ (
377
+ parser.state.module.buildInfo
378
+ );
364
379
  buildInfo.valueDependencies.set(
365
380
  VALUE_DEP_PREFIX + key,
366
381
  compilation.valueCacheVersions.get(VALUE_DEP_PREFIX + key)
@@ -376,7 +391,7 @@ class DefinePlugin {
376
391
 
377
392
  /**
378
393
  * Walk definitions
379
- * @param {Object} definitions Definitions map
394
+ * @param {Record<string, CodeValue>} definitions Definitions map
380
395
  * @param {string} prefix Prefix string
381
396
  * @returns {void}
382
397
  */
@@ -389,7 +404,10 @@ class DefinePlugin {
389
404
  !(code instanceof RuntimeValue) &&
390
405
  !(code instanceof RegExp)
391
406
  ) {
392
- walkDefinitions(code, prefix + key + ".");
407
+ walkDefinitions(
408
+ /** @type {Record<string, CodeValue>} */ (code),
409
+ prefix + key + "."
410
+ );
393
411
  applyObjectDefine(prefix + key, code);
394
412
  return;
395
413
  }
@@ -458,7 +476,7 @@ class DefinePlugin {
458
476
  )
459
477
  );
460
478
  recurse = false;
461
- res.setRange(expr.range);
479
+ res.setRange(/** @type {Range} */ (expr.range));
462
480
  return res;
463
481
  });
464
482
  parser.hooks.expression.for(key).tap(PLUGIN_NAME, expr => {
@@ -470,7 +488,7 @@ class DefinePlugin {
470
488
  originalKey,
471
489
  runtimeTemplate,
472
490
  logger,
473
- !parser.isAsiPosition(expr.range[0]),
491
+ !parser.isAsiPosition(/** @type {Range} */ (expr.range)[0]),
474
492
  parser.destructuringAssignmentPropertiesFor(expr)
475
493
  );
476
494
 
@@ -517,7 +535,7 @@ class DefinePlugin {
517
535
  : "typeof (" + codeCode + ")";
518
536
  const res = parser.evaluate(typeofCode);
519
537
  recurseTypeof = false;
520
- res.setRange(expr.range);
538
+ res.setRange(/** @type {Range} */ (expr.range));
521
539
  return res;
522
540
  });
523
541
  parser.hooks.typeof.for(key).tap(PLUGIN_NAME, expr => {
@@ -559,7 +577,7 @@ class DefinePlugin {
559
577
  return new BasicEvaluatedExpression()
560
578
  .setTruthy()
561
579
  .setSideEffects(false)
562
- .setRange(expr.range);
580
+ .setRange(/** @type {Range} */ (expr.range));
563
581
  });
564
582
  parser.hooks.evaluateTypeof
565
583
  .for(key)
@@ -576,7 +594,7 @@ class DefinePlugin {
576
594
  key,
577
595
  runtimeTemplate,
578
596
  logger,
579
- !parser.isAsiPosition(expr.range[0]),
597
+ !parser.isAsiPosition(/** @type {Range} */ (expr.range)[0]),
580
598
  parser.destructuringAssignmentPropertiesFor(expr)
581
599
  );
582
600
 
@@ -622,7 +640,7 @@ class DefinePlugin {
622
640
 
623
641
  /**
624
642
  * Walk definitions
625
- * @param {Object} definitions Definitions map
643
+ * @param {Record<string, CodeValue>} definitions Definitions map
626
644
  * @param {string} prefix Prefix string
627
645
  * @returns {void}
628
646
  */
@@ -649,7 +667,10 @@ class DefinePlugin {
649
667
  !(code instanceof RuntimeValue) &&
650
668
  !(code instanceof RegExp)
651
669
  ) {
652
- walkDefinitionsForValues(code, prefix + key + ".");
670
+ walkDefinitionsForValues(
671
+ /** @type {Record<string, CodeValue>} */ (code),
672
+ prefix + key + "."
673
+ );
653
674
  }
654
675
  });
655
676
  };
@@ -26,10 +26,12 @@
26
26
  * @property {ChunkGraph} chunkGraph the chunk graph
27
27
  * @property {Set<string>} runtimeRequirements the requirements for runtime
28
28
  * @property {Module} module current module
29
- * @property {RuntimeSpec} runtime current runtimes, for which code is generated
29
+ * @property {RuntimeSpec} runtime current runtime, for which code is generated
30
+ * @property {RuntimeSpec[]} [runtimes] current runtimes, for which code is generated
30
31
  * @property {InitFragment<GenerateContext>[]} initFragments mutable array of init fragments for the current module
31
32
  * @property {ConcatenationScope=} concatenationScope when in a concatenated module, information about other concatenated modules
32
33
  * @property {CodeGenerationResults} codeGenerationResults the code generation results
34
+ * @property {InitFragment<GenerateContext>[]} chunkInitFragments chunkInitFragments
33
35
  */
34
36
 
35
37
  /**