webpack 5.52.0 → 5.55.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 (71) hide show
  1. package/bin/webpack.js +0 -0
  2. package/lib/AsyncDependenciesBlock.js +9 -2
  3. package/lib/CacheFacade.js +10 -3
  4. package/lib/ChunkGraph.js +19 -8
  5. package/lib/CodeGenerationResults.js +7 -2
  6. package/lib/Compilation.js +549 -144
  7. package/lib/Compiler.js +12 -4
  8. package/lib/Dependency.js +11 -0
  9. package/lib/DependencyTemplates.js +8 -2
  10. package/lib/EvalDevToolModulePlugin.js +2 -1
  11. package/lib/EvalSourceMapDevToolPlugin.js +2 -1
  12. package/lib/ExternalModule.js +18 -9
  13. package/lib/FileSystemInfo.js +101 -170
  14. package/lib/FlagDependencyExportsPlugin.js +25 -16
  15. package/lib/JavascriptMetaInfoPlugin.js +6 -1
  16. package/lib/ModuleFactory.js +1 -0
  17. package/lib/ModuleFilenameHelpers.js +21 -7
  18. package/lib/ModuleGraph.js +90 -21
  19. package/lib/NodeStuffInWebError.js +34 -0
  20. package/lib/NodeStuffPlugin.js +59 -16
  21. package/lib/NormalModuleFactory.js +8 -43
  22. package/lib/SourceMapDevToolPlugin.js +7 -3
  23. package/lib/WebpackOptionsApply.js +19 -1
  24. package/lib/cache/PackFileCacheStrategy.js +183 -53
  25. package/lib/cache/getLazyHashedEtag.js +35 -8
  26. package/lib/config/defaults.js +32 -12
  27. package/lib/dependencies/CachedConstDependency.js +4 -3
  28. package/lib/dependencies/CommonJsExportRequireDependency.js +19 -9
  29. package/lib/dependencies/CommonJsFullRequireDependency.js +11 -9
  30. package/lib/dependencies/ConstDependency.js +12 -4
  31. package/lib/dependencies/ContextDependency.js +8 -0
  32. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +179 -163
  33. package/lib/dependencies/HarmonyImportDependency.js +4 -1
  34. package/lib/dependencies/JsonExportsDependency.js +7 -1
  35. package/lib/dependencies/ModuleDecoratorDependency.js +5 -2
  36. package/lib/dependencies/ModuleDependency.js +8 -0
  37. package/lib/dependencies/NullDependency.js +8 -4
  38. package/lib/dependencies/ProvidedDependency.js +6 -2
  39. package/lib/dependencies/PureExpressionDependency.js +5 -1
  40. package/lib/dependencies/RuntimeRequirementsDependency.js +5 -1
  41. package/lib/dependencies/WebAssemblyExportImportedDependency.js +9 -0
  42. package/lib/ids/IdHelpers.js +21 -8
  43. package/lib/ids/NamedChunkIdsPlugin.js +3 -0
  44. package/lib/ids/NamedModuleIdsPlugin.js +3 -1
  45. package/lib/index.js +6 -0
  46. package/lib/javascript/BasicEvaluatedExpression.js +3 -0
  47. package/lib/javascript/JavascriptParser.js +22 -4
  48. package/lib/javascript/JavascriptParserHelpers.js +0 -2
  49. package/lib/node/NodeTargetPlugin.js +1 -0
  50. package/lib/optimize/ConcatenatedModule.js +25 -4
  51. package/lib/optimize/InnerGraph.js +22 -2
  52. package/lib/optimize/ModuleConcatenationPlugin.js +2 -1
  53. package/lib/runtime/RelativeUrlRuntimeModule.js +1 -1
  54. package/lib/schemes/HttpUriPlugin.js +1 -2
  55. package/lib/serialization/BinaryMiddleware.js +11 -2
  56. package/lib/serialization/FileMiddleware.js +24 -7
  57. package/lib/serialization/ObjectMiddleware.js +23 -12
  58. package/lib/util/WeakTupleMap.js +95 -92
  59. package/lib/util/createHash.js +10 -0
  60. package/lib/util/hash/BatchedHash.js +65 -0
  61. package/lib/util/hash/xxhash64.js +154 -0
  62. package/lib/util/internalSerializables.js +1 -0
  63. package/lib/util/serialization.js +10 -6
  64. package/package.json +11 -7
  65. package/schemas/WebpackOptions.check.js +1 -1
  66. package/schemas/WebpackOptions.json +19 -3
  67. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  68. package/schemas/plugins/HashedModuleIdsPlugin.json +20 -2
  69. package/schemas/plugins/IgnorePlugin.check.js +1 -1
  70. package/schemas/plugins/IgnorePlugin.json +4 -2
  71. package/types.d.ts +211 -25
package/bin/webpack.js CHANGED
File without changes
@@ -35,6 +35,7 @@ class AsyncDependenciesBlock extends DependenciesBlock {
35
35
  this.request = request;
36
36
  /** @type {DependenciesBlock} */
37
37
  this.parent = undefined;
38
+ this._stringifiedGroupOptions = undefined;
38
39
  }
39
40
 
40
41
  /**
@@ -49,7 +50,10 @@ class AsyncDependenciesBlock extends DependenciesBlock {
49
50
  * @returns {void}
50
51
  */
51
52
  set chunkName(value) {
52
- this.groupOptions.name = value;
53
+ if (this.groupOptions.name !== value) {
54
+ this.groupOptions.name = value;
55
+ this._stringifiedGroupOptions = undefined;
56
+ }
53
57
  }
54
58
 
55
59
  /**
@@ -59,7 +63,10 @@ class AsyncDependenciesBlock extends DependenciesBlock {
59
63
  */
60
64
  updateHash(hash, context) {
61
65
  const { chunkGraph } = context;
62
- hash.update(JSON.stringify(this.groupOptions));
66
+ if (this._stringifiedGroupOptions === undefined) {
67
+ this._stringifiedGroupOptions = JSON.stringify(this.groupOptions);
68
+ }
69
+ hash.update(this._stringifiedGroupOptions);
63
70
  const chunkGroup = chunkGraph.getBlockChunkGroup(this);
64
71
  hash.update(chunkGroup ? chunkGroup.id : "");
65
72
  super.updateHash(hash, context);
@@ -13,6 +13,7 @@ const mergeEtags = require("./cache/mergeEtags");
13
13
  /** @typedef {import("./Cache").Etag} Etag */
14
14
  /** @typedef {import("./WebpackError")} WebpackError */
15
15
  /** @typedef {import("./cache/getLazyHashedEtag").HashableObject} HashableObject */
16
+ /** @typedef {typeof import("./util/Hash")} HashConstructor */
16
17
 
17
18
  /**
18
19
  * @template T
@@ -198,10 +199,12 @@ class CacheFacade {
198
199
  /**
199
200
  * @param {Cache} cache the root cache
200
201
  * @param {string} name the child cache name
202
+ * @param {string | HashConstructor} hashFunction the hash function to use
201
203
  */
202
- constructor(cache, name) {
204
+ constructor(cache, name, hashFunction) {
203
205
  this._cache = cache;
204
206
  this._name = name;
207
+ this._hashFunction = hashFunction;
205
208
  }
206
209
 
207
210
  /**
@@ -209,7 +212,11 @@ class CacheFacade {
209
212
  * @returns {CacheFacade} child cache
210
213
  */
211
214
  getChildCache(name) {
212
- return new CacheFacade(this._cache, `${this._name}|${name}`);
215
+ return new CacheFacade(
216
+ this._cache,
217
+ `${this._name}|${name}`,
218
+ this._hashFunction
219
+ );
213
220
  }
214
221
 
215
222
  /**
@@ -230,7 +237,7 @@ class CacheFacade {
230
237
  * @returns {Etag} an etag that is lazy hashed
231
238
  */
232
239
  getLazyHashedEtag(obj) {
233
- return getLazyHashedEtag(obj);
240
+ return getLazyHashedEtag(obj, this._hashFunction);
234
241
  }
235
242
 
236
243
  /**
package/lib/ChunkGraph.js CHANGED
@@ -34,6 +34,7 @@ const {
34
34
  /** @typedef {import("./Module")} Module */
35
35
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
36
36
  /** @typedef {import("./RuntimeModule")} RuntimeModule */
37
+ /** @typedef {typeof import("./util/Hash")} Hash */
37
38
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
38
39
 
39
40
  /** @type {ReadonlySet<string>} */
@@ -217,8 +218,9 @@ class ChunkGraphChunk {
217
218
  class ChunkGraph {
218
219
  /**
219
220
  * @param {ModuleGraph} moduleGraph the module graph
221
+ * @param {string | Hash} hashFunction the hash function to use
220
222
  */
221
- constructor(moduleGraph) {
223
+ constructor(moduleGraph, hashFunction = "md4") {
222
224
  /** @private @type {WeakMap<Module, ChunkGraphModule>} */
223
225
  this._modules = new WeakMap();
224
226
  /** @private @type {WeakMap<Chunk, ChunkGraphChunk>} */
@@ -230,6 +232,8 @@ class ChunkGraph {
230
232
  /** @type {ModuleGraph} */
231
233
  this.moduleGraph = moduleGraph;
232
234
 
235
+ this._hashFunction = hashFunction;
236
+
233
237
  this._getGraphRoots = this._getGraphRoots.bind(this);
234
238
 
235
239
  // Caching
@@ -1372,22 +1376,29 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1372
1376
  /**
1373
1377
  * @param {Module} module the module
1374
1378
  * @param {RuntimeSpec} runtime the runtime
1375
- * @param {Set<string>} items runtime requirements to be added (ownership of this Set is given to ChunkGraph)
1379
+ * @param {Set<string>} items runtime requirements to be added (ownership of this Set is given to ChunkGraph when transferOwnership not false)
1380
+ * @param {boolean} transferOwnership true: transfer ownership of the items object, false: items is immutable and shared and won't be modified
1376
1381
  * @returns {void}
1377
1382
  */
1378
- addModuleRuntimeRequirements(module, runtime, items) {
1383
+ addModuleRuntimeRequirements(
1384
+ module,
1385
+ runtime,
1386
+ items,
1387
+ transferOwnership = true
1388
+ ) {
1379
1389
  const cgm = this._getChunkGraphModule(module);
1380
1390
  const runtimeRequirementsMap = cgm.runtimeRequirements;
1381
1391
  if (runtimeRequirementsMap === undefined) {
1382
1392
  const map = new RuntimeSpecMap();
1383
- map.set(runtime, items);
1393
+ // TODO avoid cloning item and track ownership instead
1394
+ map.set(runtime, transferOwnership ? items : new Set(items));
1384
1395
  cgm.runtimeRequirements = map;
1385
1396
  return;
1386
1397
  }
1387
1398
  runtimeRequirementsMap.update(runtime, runtimeRequirements => {
1388
1399
  if (runtimeRequirements === undefined) {
1389
- return items;
1390
- } else if (runtimeRequirements.size >= items.size) {
1400
+ return transferOwnership ? items : new Set(items);
1401
+ } else if (!transferOwnership || runtimeRequirements.size >= items.size) {
1391
1402
  for (const item of items) runtimeRequirements.add(item);
1392
1403
  return runtimeRequirements;
1393
1404
  } else {
@@ -1487,7 +1498,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1487
1498
  cgm.graphHashes = new RuntimeSpecMap();
1488
1499
  }
1489
1500
  const graphHash = cgm.graphHashes.provide(runtime, () => {
1490
- const hash = createHash("md4");
1501
+ const hash = createHash(this._hashFunction);
1491
1502
  hash.update(`${cgm.id}`);
1492
1503
  hash.update(`${this.moduleGraph.isAsync(module)}`);
1493
1504
  this.moduleGraph.getExportsInfo(module).updateHash(hash, runtime);
@@ -1575,7 +1586,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1575
1586
  connectedModules.size > 1
1576
1587
  ? Array.from(connectedModules).sort(([a], [b]) => (a < b ? -1 : 1))
1577
1588
  : connectedModules;
1578
- const hash = createHash("md4");
1589
+ const hash = createHash(this._hashFunction);
1579
1590
  const addModuleToHash = module => {
1580
1591
  hash.update(
1581
1592
  this._getModuleGraphHashBigInt(
@@ -13,12 +13,17 @@ const { runtimeToString, RuntimeSpecMap } = require("./util/runtime");
13
13
  /** @typedef {import("webpack-sources").Source} Source */
14
14
  /** @typedef {import("./Module")} Module */
15
15
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
16
+ /** @typedef {typeof import("./util/Hash")} Hash */
16
17
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
17
18
 
18
19
  class CodeGenerationResults {
19
- constructor() {
20
+ /**
21
+ * @param {string | Hash} hashFunction the hash function to use
22
+ */
23
+ constructor(hashFunction = "md4") {
20
24
  /** @type {Map<Module, RuntimeSpecMap<CodeGenerationResult>>} */
21
25
  this.map = new Map();
26
+ this._hashFunction = hashFunction;
22
27
  }
23
28
 
24
29
  /**
@@ -124,7 +129,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
124
129
  getHash(module, runtime) {
125
130
  const info = this.get(module, runtime);
126
131
  if (info.hash !== undefined) return info.hash;
127
- const hash = createHash("md4");
132
+ const hash = createHash(this._hashFunction);
128
133
  for (const [type, source] of info.sources) {
129
134
  hash.update(type);
130
135
  source.updateHash(hash);