webpack 5.62.0 → 5.64.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.

@@ -2424,9 +2424,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2424
2424
  let statNew = 0;
2425
2425
  /**
2426
2426
  * @param {Module} module module
2427
- * @returns {{ modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[] }} references
2427
+ * @returns {{ id: string | number, modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[] }} references
2428
2428
  */
2429
2429
  const computeReferences = module => {
2430
+ const id = chunkGraph.getModuleId(module);
2430
2431
  /** @type {Map<Module, string | number | undefined>} */
2431
2432
  let modules = undefined;
2432
2433
  /** @type {(string | number)[] | undefined} */
@@ -2454,16 +2455,18 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2454
2455
  queue.push.apply(queue, block.blocks);
2455
2456
  }
2456
2457
  }
2457
- return { modules, blocks };
2458
+ return { id, modules, blocks };
2458
2459
  };
2459
2460
  /**
2460
2461
  * @param {Module} module module
2461
2462
  * @param {Object} references references
2463
+ * @param {string | number} references.id id
2462
2464
  * @param {Map<Module, string | number>=} references.modules modules
2463
2465
  * @param {(string | number)[]=} references.blocks blocks
2464
2466
  * @returns {boolean} ok?
2465
2467
  */
2466
- const compareReferences = (module, { modules, blocks }) => {
2468
+ const compareReferences = (module, { id, modules, blocks }) => {
2469
+ if (id !== chunkGraph.getModuleId(module)) return false;
2467
2470
  if (modules !== undefined) {
2468
2471
  for (const [module, id] of modules) {
2469
2472
  if (chunkGraph.getModuleId(module) !== id) return false;
@@ -2489,7 +2492,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2489
2492
  };
2490
2493
 
2491
2494
  for (const [module, memCache] of moduleMemCaches) {
2492
- /** @type {{ references: { modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[]}, memCache: WeakTupleMap<any[], any> }} */
2495
+ /** @type {{ references: { id: string | number, modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[]}, memCache: WeakTupleMap<any[], any> }} */
2493
2496
  const cache = memCache.get(key);
2494
2497
  if (cache === undefined) {
2495
2498
  const memCache2 = new WeakTupleMap();
@@ -64,6 +64,7 @@ class EntryOptionPlugin {
64
64
  dependOn: desc.dependOn,
65
65
  publicPath: desc.publicPath,
66
66
  chunkLoading: desc.chunkLoading,
67
+ asyncChunks: desc.asyncChunks,
67
68
  wasmLoading: desc.wasmLoading,
68
69
  library: desc.library
69
70
  };
@@ -692,6 +692,11 @@ class SnapshotOptimization {
692
692
  }
693
693
  }
694
694
 
695
+ const parseString = str => {
696
+ if (str[0] === "'") str = `"${str.slice(1, -1).replace(/"/g, '\\"')}"`;
697
+ return JSON.parse(str);
698
+ };
699
+
695
700
  /* istanbul ignore next */
696
701
  /**
697
702
  * @param {number} mtime mtime
@@ -1657,17 +1662,13 @@ class FileSystemInfo {
1657
1662
  let dependency;
1658
1663
  if (imp.d === -1) {
1659
1664
  // import ... from "..."
1660
- dependency = JSON.parse(
1665
+ dependency = parseString(
1661
1666
  source.substring(imp.s - 1, imp.e + 1)
1662
1667
  );
1663
1668
  } else if (imp.d > -1) {
1664
1669
  // import()
1665
1670
  let expr = source.substring(imp.s, imp.e).trim();
1666
- if (expr[0] === "'")
1667
- expr = `"${expr
1668
- .slice(1, -1)
1669
- .replace(/"/g, '\\"')}"`;
1670
- dependency = JSON.parse(expr);
1671
+ dependency = parseString(expr);
1671
1672
  } else {
1672
1673
  // e.g. import.meta
1673
1674
  continue;
@@ -218,7 +218,15 @@ class RuntimePlugin {
218
218
  compilation.hooks.runtimeRequirementInTree
219
219
  .for(RuntimeGlobals.systemContext)
220
220
  .tap("RuntimePlugin", chunk => {
221
- if (compilation.outputOptions.library.type === "system") {
221
+ const { outputOptions } = compilation;
222
+ const { library: globalLibrary } = outputOptions;
223
+ const entryOptions = chunk.getEntryOptions();
224
+ const libraryType =
225
+ entryOptions && entryOptions.library !== undefined
226
+ ? entryOptions.library.type
227
+ : globalLibrary.type;
228
+
229
+ if (libraryType === "system") {
222
230
  compilation.addRuntimeModule(
223
231
  chunk,
224
232
  new SystemContextRuntimeModule()
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { groupBy } = require("./util/ArrayHelpers");
8
9
  const createSchemaValidation = require("./util/create-schema-validation");
9
10
 
10
11
  /** @typedef {import("../declarations/plugins/WatchIgnorePlugin").WatchIgnorePluginOptions} WatchIgnorePluginOptions */
@@ -40,14 +41,12 @@ class IgnoringWatchFileSystem {
40
41
  p instanceof RegExp ? p.test(path) : path.indexOf(p) === 0
41
42
  );
42
43
 
43
- const notIgnored = path => !ignored(path);
44
-
45
- const ignoredFiles = files.filter(ignored);
46
- const ignoredDirs = dirs.filter(ignored);
44
+ const [ignoredFiles, notIgnoredFiles] = groupBy(files, ignored);
45
+ const [ignoredDirs, notIgnoredDirs] = groupBy(dirs, ignored);
47
46
 
48
47
  const watcher = this.wfs.watch(
49
- files.filter(notIgnored),
50
- dirs.filter(notIgnored),
48
+ notIgnoredFiles,
49
+ notIgnoredDirs,
51
50
  missing,
52
51
  startTime,
53
52
  options,
@@ -50,6 +50,8 @@ const { getEntryRuntime, mergeRuntime } = require("./util/runtime");
50
50
  * @property {Set<ChunkGroupInfo>} availableChildren set of chunk groups which depend on the this chunk group as availableSource
51
51
  * @property {number} preOrderIndex next pre order index
52
52
  * @property {number} postOrderIndex next post order index
53
+ * @property {boolean} chunkLoading has a chunk loading mechanism
54
+ * @property {boolean} asyncChunks create async chunks
53
55
  */
54
56
 
55
57
  /**
@@ -304,7 +306,15 @@ const visitModules = (
304
306
  availableSources: undefined,
305
307
  availableChildren: undefined,
306
308
  preOrderIndex: 0,
307
- postOrderIndex: 0
309
+ postOrderIndex: 0,
310
+ chunkLoading:
311
+ chunkGroup.options.chunkLoading !== undefined
312
+ ? chunkGroup.options.chunkLoading !== false
313
+ : compilation.outputOptions.chunkLoading !== false,
314
+ asyncChunks:
315
+ chunkGroup.options.asyncChunks !== undefined
316
+ ? chunkGroup.options.asyncChunks
317
+ : compilation.outputOptions.asyncChunks !== false
308
318
  };
309
319
  chunkGroup.index = nextChunkGroupIndex++;
310
320
  if (chunkGroup.getNumberOfParents() > 0) {
@@ -418,7 +428,15 @@ const visitModules = (
418
428
  availableSources: undefined,
419
429
  availableChildren: undefined,
420
430
  preOrderIndex: 0,
421
- postOrderIndex: 0
431
+ postOrderIndex: 0,
432
+ chunkLoading:
433
+ entryOptions.chunkLoading !== undefined
434
+ ? entryOptions.chunkLoading !== false
435
+ : chunkGroupInfo.chunkLoading,
436
+ asyncChunks:
437
+ entryOptions.asyncChunks !== undefined
438
+ ? entryOptions.asyncChunks
439
+ : chunkGroupInfo.asyncChunks
422
440
  };
423
441
  chunkGroupInfoMap.set(entrypoint, cgi);
424
442
 
@@ -442,8 +460,18 @@ const visitModules = (
442
460
  chunkGroup: entrypoint,
443
461
  chunkGroupInfo: cgi
444
462
  });
463
+ } else if (!chunkGroupInfo.asyncChunks || !chunkGroupInfo.chunkLoading) {
464
+ // Just queue the block into the current chunk group
465
+ queue.push({
466
+ action: PROCESS_BLOCK,
467
+ block: b,
468
+ module: module,
469
+ chunk,
470
+ chunkGroup,
471
+ chunkGroupInfo
472
+ });
445
473
  } else {
446
- cgi = namedChunkGroups.get(chunkName);
474
+ cgi = chunkName && namedChunkGroups.get(chunkName);
447
475
  if (!cgi) {
448
476
  c = compilation.addChunkInGroup(
449
477
  b.groupOptions || b.chunkName,
@@ -464,7 +492,9 @@ const visitModules = (
464
492
  availableSources: undefined,
465
493
  availableChildren: undefined,
466
494
  preOrderIndex: 0,
467
- postOrderIndex: 0
495
+ postOrderIndex: 0,
496
+ chunkLoading: chunkGroupInfo.chunkLoading,
497
+ asyncChunks: chunkGroupInfo.asyncChunks
468
498
  };
469
499
  allCreatedChunkGroups.add(c);
470
500
  chunkGroupInfoMap.set(c, cgi);
@@ -518,7 +548,7 @@ const visitModules = (
518
548
  chunkGroup: c,
519
549
  chunkGroupInfo: cgi
520
550
  });
521
- } else {
551
+ } else if (entrypoint !== undefined) {
522
552
  chunkGroupInfo.chunkGroup.addAsyncEntrypoint(entrypoint);
523
553
  }
524
554
  };
@@ -183,7 +183,8 @@ const applyWebpackOptionsDefaults = options => {
183
183
  applyModuleDefaults(options.module, {
184
184
  cache,
185
185
  syncWebAssembly: options.experiments.syncWebAssembly,
186
- asyncWebAssembly: options.experiments.asyncWebAssembly
186
+ asyncWebAssembly: options.experiments.asyncWebAssembly,
187
+ futureDefaults
187
188
  });
188
189
 
189
190
  applyOutputDefaults(options.output, {
@@ -428,9 +429,14 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
428
429
 
429
430
  /**
430
431
  * @param {JavascriptParserOptions} parserOptions parser options
432
+ * @param {Object} options options
433
+ * @param {boolean} options.futureDefaults is future defaults enabled
431
434
  * @returns {void}
432
435
  */
433
- const applyJavascriptParserOptionsDefaults = parserOptions => {
436
+ const applyJavascriptParserOptionsDefaults = (
437
+ parserOptions,
438
+ { futureDefaults }
439
+ ) => {
434
440
  D(parserOptions, "unknownContextRequest", ".");
435
441
  D(parserOptions, "unknownContextRegExp", false);
436
442
  D(parserOptions, "unknownContextRecursive", true);
@@ -443,6 +449,7 @@ const applyJavascriptParserOptionsDefaults = parserOptions => {
443
449
  D(parserOptions, "wrappedContextRecursive", true);
444
450
  D(parserOptions, "wrappedContextCritical", false);
445
451
  D(parserOptions, "strictThisContextOnImports", false);
452
+ if (futureDefaults) D(parserOptions, "exportsPresence", "error");
446
453
  };
447
454
 
448
455
  /**
@@ -451,11 +458,12 @@ const applyJavascriptParserOptionsDefaults = parserOptions => {
451
458
  * @param {boolean} options.cache is caching enabled
452
459
  * @param {boolean} options.syncWebAssembly is syncWebAssembly enabled
453
460
  * @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled
461
+ * @param {boolean} options.futureDefaults is future defaults enabled
454
462
  * @returns {void}
455
463
  */
456
464
  const applyModuleDefaults = (
457
465
  module,
458
- { cache, syncWebAssembly, asyncWebAssembly }
466
+ { cache, syncWebAssembly, asyncWebAssembly, futureDefaults }
459
467
  ) => {
460
468
  if (cache) {
461
469
  D(module, "unsafeCache", module => {
@@ -473,7 +481,9 @@ const applyModuleDefaults = (
473
481
  }
474
482
 
475
483
  F(module.parser, "javascript", () => ({}));
476
- applyJavascriptParserOptionsDefaults(module.parser.javascript);
484
+ applyJavascriptParserOptionsDefaults(module.parser.javascript, {
485
+ futureDefaults
486
+ });
477
487
 
478
488
  A(module, "defaultRules", () => {
479
489
  const esm = {
@@ -734,6 +744,7 @@ const applyOutputDefaults = (
734
744
  "Chunk format can't be selected by default when no target is specified"
735
745
  );
736
746
  });
747
+ D(output, "asyncChunks", true);
737
748
  F(output, "chunkLoading", () => {
738
749
  if (tp) {
739
750
  switch (output.chunkFormat) {
@@ -229,6 +229,7 @@ const getNormalizedWebpackOptions = config => {
229
229
  wrappedContextRegExp: module.wrappedContextRegExp,
230
230
  wrappedContextRecursive: module.wrappedContextRecursive,
231
231
  wrappedContextCritical: module.wrappedContextCritical,
232
+ // TODO webpack 6 remove
232
233
  strictExportPresence: module.strictExportPresence,
233
234
  strictThisContextOnImports: module.strictThisContextOnImports,
234
235
  ...parserOptions
@@ -289,6 +290,7 @@ const getNormalizedWebpackOptions = config => {
289
290
  /** @type {OutputNormalized} */
290
291
  const result = {
291
292
  assetModuleFilename: output.assetModuleFilename,
293
+ asyncChunks: output.asyncChunks,
292
294
  charset: output.charset,
293
295
  chunkFilename: output.chunkFilename,
294
296
  chunkFormat: output.chunkFormat,
@@ -483,6 +485,7 @@ const getNormalizedEntryStatic = entry => {
483
485
  runtime: value.runtime,
484
486
  publicPath: value.publicPath,
485
487
  chunkLoading: value.chunkLoading,
488
+ asyncChunks: value.asyncChunks,
486
489
  wasmLoading: value.wasmLoading,
487
490
  dependOn:
488
491
  value.dependOn &&
@@ -203,15 +203,17 @@ class ProfilingPlugin {
203
203
 
204
204
  // Compiler Hooks
205
205
  Object.keys(compiler.hooks).forEach(hookName => {
206
- compiler.hooks[hookName].intercept(
207
- makeInterceptorFor("Compiler", tracer)(hookName)
208
- );
206
+ const hook = compiler.hooks[hookName];
207
+ if (hook) {
208
+ hook.intercept(makeInterceptorFor("Compiler", tracer)(hookName));
209
+ }
209
210
  });
210
211
 
211
212
  Object.keys(compiler.resolverFactory.hooks).forEach(hookName => {
212
- compiler.resolverFactory.hooks[hookName].intercept(
213
- makeInterceptorFor("Resolver", tracer)(hookName)
214
- );
213
+ const hook = compiler.resolverFactory.hooks[hookName];
214
+ if (hook) {
215
+ hook.intercept(makeInterceptorFor("Resolver", tracer)(hookName));
216
+ }
215
217
  });
216
218
 
217
219
  compiler.hooks.compilation.tap(
@@ -303,7 +305,7 @@ const interceptAllHooksFor = (instance, tracer, logLabel) => {
303
305
  if (Reflect.has(instance, "hooks")) {
304
306
  Object.keys(instance.hooks).forEach(hookName => {
305
307
  const hook = instance.hooks[hookName];
306
- if (!hook._fakeHook) {
308
+ if (hook && !hook._fakeHook) {
307
309
  hook.intercept(makeInterceptorFor(logLabel, tracer)(hookName));
308
310
  }
309
311
  });
@@ -121,7 +121,7 @@ CommonJsFullRequireDependency.Template = class CommonJsFullRequireDependencyTemp
121
121
  requireExpr =
122
122
  dep.asiSafe === true
123
123
  ? `(${requireExpr}${access})`
124
- : `${requireExpr}${access})`;
124
+ : `${requireExpr}${access}`;
125
125
  }
126
126
  }
127
127
  source.replace(dep.range[0], dep.range[1] - 1, requireExpr);
@@ -23,10 +23,10 @@ const { HarmonyStarExportsList } = HarmonyExportImportedSpecifierDependency;
23
23
  module.exports = class HarmonyExportDependencyParserPlugin {
24
24
  constructor(options) {
25
25
  this.exportPresenceMode =
26
- options.reexportExportPresence !== undefined
27
- ? ExportPresenceModes.fromUserOption(options.reexportExportPresence)
28
- : options.exportPresence !== undefined
29
- ? ExportPresenceModes.fromUserOption(options.exportPresence)
26
+ options.reexportExportsPresence !== undefined
27
+ ? ExportPresenceModes.fromUserOption(options.reexportExportsPresence)
28
+ : options.exportsPresence !== undefined
29
+ ? ExportPresenceModes.fromUserOption(options.exportsPresence)
30
30
  : options.strictExportPresence
31
31
  ? ExportPresenceModes.ERROR
32
32
  : ExportPresenceModes.AUTO;
@@ -755,8 +755,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
755
755
  * @returns {WebpackError[]} warnings
756
756
  */
757
757
  getWarnings(moduleGraph) {
758
- const exportPresence = this._getEffectiveExportPresenceLevel(moduleGraph);
759
- if (exportPresence === ExportPresenceModes.WARN) {
758
+ const exportsPresence = this._getEffectiveExportPresenceLevel(moduleGraph);
759
+ if (exportsPresence === ExportPresenceModes.WARN) {
760
760
  return this._getErrors(moduleGraph);
761
761
  }
762
762
  return null;
@@ -768,8 +768,8 @@ class HarmonyExportImportedSpecifierDependency extends HarmonyImportDependency {
768
768
  * @returns {WebpackError[]} errors
769
769
  */
770
770
  getErrors(moduleGraph) {
771
- const exportPresence = this._getEffectiveExportPresenceLevel(moduleGraph);
772
- if (exportPresence === ExportPresenceModes.ERROR) {
771
+ const exportsPresence = this._getEffectiveExportPresenceLevel(moduleGraph);
772
+ if (exportsPresence === ExportPresenceModes.ERROR) {
773
773
  return this._getErrors(moduleGraph);
774
774
  }
775
775
  return null;
@@ -38,6 +38,8 @@ const ExportPresenceModes = {
38
38
  return ExportPresenceModes.ERROR;
39
39
  case "warn":
40
40
  return ExportPresenceModes.WARN;
41
+ case "auto":
42
+ return ExportPresenceModes.AUTO;
41
43
  case false:
42
44
  return ExportPresenceModes.NONE;
43
45
  default:
@@ -67,10 +67,10 @@ module.exports = class HarmonyImportDependencyParserPlugin {
67
67
  */
68
68
  constructor(options) {
69
69
  this.exportPresenceMode =
70
- options.importExportPresence !== undefined
71
- ? ExportPresenceModes.fromUserOption(options.importExportPresence)
72
- : options.exportPresence !== undefined
73
- ? ExportPresenceModes.fromUserOption(options.exportPresence)
70
+ options.importExportsPresence !== undefined
71
+ ? ExportPresenceModes.fromUserOption(options.importExportsPresence)
72
+ : options.exportsPresence !== undefined
73
+ ? ExportPresenceModes.fromUserOption(options.exportsPresence)
74
74
  : options.strictExportPresence
75
75
  ? ExportPresenceModes.ERROR
76
76
  : ExportPresenceModes.AUTO;
@@ -173,8 +173,8 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
173
173
  * @returns {WebpackError[]} warnings
174
174
  */
175
175
  getWarnings(moduleGraph) {
176
- const exportPresence = this._getEffectiveExportPresenceLevel(moduleGraph);
177
- if (exportPresence === ExportPresenceModes.WARN) {
176
+ const exportsPresence = this._getEffectiveExportPresenceLevel(moduleGraph);
177
+ if (exportsPresence === ExportPresenceModes.WARN) {
178
178
  return this._getErrors(moduleGraph);
179
179
  }
180
180
  return null;
@@ -186,8 +186,8 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
186
186
  * @returns {WebpackError[]} errors
187
187
  */
188
188
  getErrors(moduleGraph) {
189
- const exportPresence = this._getEffectiveExportPresenceLevel(moduleGraph);
190
- if (exportPresence === ExportPresenceModes.ERROR) {
189
+ const exportsPresence = this._getEffectiveExportPresenceLevel(moduleGraph);
190
+ if (exportsPresence === ExportPresenceModes.ERROR) {
191
191
  return this._getErrors(moduleGraph);
192
192
  }
193
193
  return null;
@@ -1160,7 +1160,7 @@ const AVAILABLE_FORMATS = {
1160
1160
  },
1161
1161
  { regExp: /(\(module has no exports\))/g, format: red },
1162
1162
  { regExp: /\(possible exports: (.+)\)/g, format: green },
1163
- { regExp: /\s*(.+ doesn't exist)/g, format: red },
1163
+ { regExp: /\s*([^\s].* doesn't exist)/g, format: red },
1164
1164
  { regExp: /('\w+' option has not been set)/g, format: red },
1165
1165
  {
1166
1166
  regExp: /(Emitted value instead of an instance of Error)/g,
@@ -12,3 +12,19 @@ exports.equals = (a, b) => {
12
12
  }
13
13
  return true;
14
14
  };
15
+
16
+ /**
17
+ *
18
+ * @param {Array} arr Array of values to be partitioned
19
+ * @param {(value: any) => boolean} fn Partition function which partitions based on truthiness of result.
20
+ * @returns {[Array, Array]} returns the values of `arr` partitioned into two new arrays based on fn predicate.
21
+ */
22
+ exports.groupBy = (arr = [], fn) => {
23
+ return arr.reduce(
24
+ (groups, value) => {
25
+ groups[fn(value) ? 0 : 1].push(value);
26
+ return groups;
27
+ },
28
+ [[], []]
29
+ );
30
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.62.0",
3
+ "version": "5.64.0",
4
4
  "author": "Tobias Koppers @sokra",
5
5
  "description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
6
6
  "license": "MIT",