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/lib/Compiler.js CHANGED
@@ -42,6 +42,7 @@ const { isSourceEqual } = require("./util/source");
42
42
  /** @typedef {import("./Chunk")} Chunk */
43
43
  /** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
44
44
  /** @typedef {import("./Module")} Module */
45
+ /** @typedef {import("./util/WeakTupleMap")} WeakTupleMap */
45
46
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
46
47
  /** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
47
48
  /** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
@@ -247,6 +248,9 @@ class Compiler {
247
248
 
248
249
  this.cache = new Cache();
249
250
 
251
+ /** @type {WeakMap<Module, { hash: string, memCache: WeakTupleMap }> | undefined} */
252
+ this.moduleMemCaches = undefined;
253
+
250
254
  this.compilerPath = "";
251
255
 
252
256
  /** @type {boolean} */
@@ -276,7 +280,11 @@ class Compiler {
276
280
  * @returns {CacheFacade} the cache facade instance
277
281
  */
278
282
  getCache(name) {
279
- return new CacheFacade(this.cache, `${this.compilerPath}${name}`);
283
+ return new CacheFacade(
284
+ this.cache,
285
+ `${this.compilerPath}${name}`,
286
+ this.options.output.hashFunction
287
+ );
280
288
  }
281
289
 
282
290
  /**
@@ -1027,9 +1035,9 @@ ${other}`);
1027
1035
  return !!this.parentCompilation;
1028
1036
  }
1029
1037
 
1030
- createCompilation() {
1038
+ createCompilation(params) {
1031
1039
  this._cleanupLastCompilation();
1032
- return (this._lastCompilation = new Compilation(this));
1040
+ return (this._lastCompilation = new Compilation(this, params));
1033
1041
  }
1034
1042
 
1035
1043
  /**
@@ -1037,7 +1045,7 @@ ${other}`);
1037
1045
  * @returns {Compilation} the created compilation
1038
1046
  */
1039
1047
  newCompilation(params) {
1040
- const compilation = this.createCompilation();
1048
+ const compilation = this.createCompilation(params);
1041
1049
  compilation.name = this.name;
1042
1050
  compilation.records = this.records;
1043
1051
  this.hooks.thisCompilation.call(compilation, params);
package/lib/Dependency.js CHANGED
@@ -78,6 +78,8 @@ const memoize = require("./util/memoize");
78
78
  * @property {boolean=} canMangle when false, referenced export can not be mangled, defaults to true
79
79
  */
80
80
 
81
+ const TRANSITIVE = Symbol("transitive");
82
+
81
83
  const getIgnoredModule = memoize(() => {
82
84
  const RawModule = require("./RawModule");
83
85
  return new RawModule("/* (ignored) */", `ignored`, `(ignored)`);
@@ -175,6 +177,13 @@ class Dependency {
175
177
  return null;
176
178
  }
177
179
 
180
+ /**
181
+ * @returns {boolean | TRANSITIVE} true, when changes to the referenced module could affect the referencing module; TRANSITIVE, when changes to the referenced module could affect referencing modules of the referencing module
182
+ */
183
+ couldAffectReferencingModule() {
184
+ return TRANSITIVE;
185
+ }
186
+
178
187
  /**
179
188
  * Returns the referenced module and export
180
189
  * @deprecated
@@ -322,4 +331,6 @@ Object.defineProperty(Dependency.prototype, "disconnect", {
322
331
  }
323
332
  });
324
333
 
334
+ Dependency.TRANSITIVE = TRANSITIVE;
335
+
325
336
  module.exports = Dependency;
@@ -9,14 +9,20 @@ const createHash = require("./util/createHash");
9
9
 
10
10
  /** @typedef {import("./Dependency")} Dependency */
11
11
  /** @typedef {import("./DependencyTemplate")} DependencyTemplate */
12
+ /** @typedef {typeof import("./util/Hash")} Hash */
13
+
12
14
  /** @typedef {new (...args: any[]) => Dependency} DependencyConstructor */
13
15
 
14
16
  class DependencyTemplates {
15
- constructor() {
17
+ /**
18
+ * @param {string | Hash} hashFunction the hash function to use
19
+ */
20
+ constructor(hashFunction = "md4") {
16
21
  /** @type {Map<Function, DependencyTemplate>} */
17
22
  this._map = new Map();
18
23
  /** @type {string} */
19
24
  this._hash = "31d6cfe0d16ae931b73c59d7e0c089c0";
25
+ this._hashFunction = hashFunction;
20
26
  }
21
27
 
22
28
  /**
@@ -41,7 +47,7 @@ class DependencyTemplates {
41
47
  * @returns {void}
42
48
  */
43
49
  updateHash(part) {
44
- const hash = createHash("md4");
50
+ const hash = createHash(this._hashFunction);
45
51
  hash.update(this._hash);
46
52
  hash.update(part);
47
53
  this._hash = /** @type {string} */ (hash.digest("hex"));
@@ -61,7 +61,8 @@ class EvalDevToolModulePlugin {
61
61
  },
62
62
  {
63
63
  requestShortener: runtimeTemplate.requestShortener,
64
- chunkGraph
64
+ chunkGraph,
65
+ hashFunction: compilation.outputOptions.hashFunction
65
66
  }
66
67
  );
67
68
  const footer =
@@ -138,7 +138,8 @@ class EvalSourceMapDevToolPlugin {
138
138
  },
139
139
  {
140
140
  requestShortener: runtimeTemplate.requestShortener,
141
- chunkGraph
141
+ chunkGraph,
142
+ hashFunction: compilation.outputOptions.hashFunction
142
143
  }
143
144
  );
144
145
  });
@@ -38,6 +38,7 @@ const { register } = require("./util/serialization");
38
38
  /** @typedef {import("./WebpackError")} WebpackError */
39
39
  /** @typedef {import("./javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
40
40
  /** @typedef {import("./util/Hash")} Hash */
41
+ /** @typedef {typeof import("./util/Hash")} HashConstructor */
41
42
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
42
43
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
43
44
 
@@ -160,11 +161,16 @@ const getSourceForImportExternal = (moduleAndSpecifiers, runtimeTemplate) => {
160
161
  };
161
162
 
162
163
  class ModuleExternalInitFragment extends InitFragment {
163
- constructor(request, ident) {
164
+ /**
165
+ * @param {string} request import source
166
+ * @param {string=} ident recomputed ident
167
+ * @param {string | HashConstructor=} hashFunction the hash function to use
168
+ */
169
+ constructor(request, ident, hashFunction = "md4") {
164
170
  if (ident === undefined) {
165
171
  ident = Template.toIdentifier(request);
166
172
  if (ident !== request) {
167
- ident += `_${createHash("md4")
173
+ ident += `_${createHash(hashFunction)
168
174
  .update(request)
169
175
  .digest("hex")
170
176
  .slice(0, 8)}`;
@@ -230,21 +236,25 @@ const generateModuleRemapping = (input, exportsInfo, runtime) => {
230
236
  };
231
237
 
232
238
  /**
233
- * @param {string|number} id the module id
234
239
  * @param {string|string[]} moduleAndSpecifiers the module request
235
240
  * @param {ExportsInfo} exportsInfo exports info of this module
236
241
  * @param {RuntimeSpec} runtime the runtime
242
+ * @param {string | HashConstructor=} hashFunction the hash function to use
237
243
  * @returns {SourceData} the generated source
238
244
  */
239
245
  const getSourceForModuleExternal = (
240
- id,
241
246
  moduleAndSpecifiers,
242
247
  exportsInfo,
243
- runtime
248
+ runtime,
249
+ hashFunction
244
250
  ) => {
245
251
  if (!Array.isArray(moduleAndSpecifiers))
246
252
  moduleAndSpecifiers = [moduleAndSpecifiers];
247
- const initFragment = new ModuleExternalInitFragment(moduleAndSpecifiers[0]);
253
+ const initFragment = new ModuleExternalInitFragment(
254
+ moduleAndSpecifiers[0],
255
+ undefined,
256
+ hashFunction
257
+ );
248
258
  const baseAccess = `${initFragment.getNamespaceIdentifier()}${propertyAccess(
249
259
  moduleAndSpecifiers,
250
260
  1
@@ -566,12 +576,11 @@ class ExternalModule extends Module {
566
576
  "The target environment doesn't support EcmaScriptModule syntax so it's not possible to use external type 'module'"
567
577
  );
568
578
  }
569
- const id = chunkGraph.getModuleId(this);
570
579
  return getSourceForModuleExternal(
571
- id !== null ? id : this.identifier(),
572
580
  request,
573
581
  moduleGraph.getExportsInfo(this),
574
- runtime
582
+ runtime,
583
+ runtimeTemplate.outputOptions.hashFunction
575
584
  );
576
585
  }
577
586
  case "var":