webpack 5.90.1 → 5.90.3

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 (37) hide show
  1. package/lib/Compilation.js +1 -1
  2. package/lib/ContextModule.js +2 -1
  3. package/lib/CssModule.js +0 -3
  4. package/lib/DelegatedModule.js +2 -1
  5. package/lib/DllModule.js +2 -1
  6. package/lib/ExternalModule.js +2 -1
  7. package/lib/Module.js +24 -3
  8. package/lib/MultiCompiler.js +36 -10
  9. package/lib/NormalModule.js +236 -85
  10. package/lib/NormalModuleFactory.js +162 -31
  11. package/lib/RawModule.js +2 -1
  12. package/lib/ResolverFactory.js +2 -0
  13. package/lib/RuntimeModule.js +2 -1
  14. package/lib/Stats.js +2 -2
  15. package/lib/asset/RawDataUrlModule.js +2 -1
  16. package/lib/buildChunkGraph.js +156 -348
  17. package/lib/container/ContainerEntryModule.js +2 -1
  18. package/lib/container/FallbackModule.js +2 -1
  19. package/lib/container/RemoteModule.js +2 -1
  20. package/lib/css/CssLoadingRuntimeModule.js +1 -1
  21. package/lib/dependencies/ExportsInfoDependency.js +6 -12
  22. package/lib/dependencies/HarmonyImportSpecifierDependency.js +15 -5
  23. package/lib/dependencies/ImportParserPlugin.js +1 -0
  24. package/lib/dependencies/WorkerDependency.js +1 -1
  25. package/lib/dependencies/WorkerPlugin.js +4 -4
  26. package/lib/hmr/HotModuleReplacement.runtime.js +1 -1
  27. package/lib/hmr/LazyCompilationPlugin.js +2 -1
  28. package/lib/optimize/ConcatenatedModule.js +2 -1
  29. package/lib/runtime/AutoPublicPathRuntimeModule.js +1 -1
  30. package/lib/sharing/ConsumeSharedModule.js +2 -1
  31. package/lib/sharing/ProvideSharedModule.js +2 -1
  32. package/lib/util/memoize.js +2 -0
  33. package/lib/util/numberHash.js +4 -15
  34. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -1
  35. package/lib/webpack.js +5 -3
  36. package/package.json +2 -2
  37. package/types.d.ts +122 -78
@@ -23,6 +23,7 @@ const ContainerExposedDependency = require("./ContainerExposedDependency");
23
23
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
24
24
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
25
25
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
26
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
26
27
  /** @typedef {import("../RequestShortener")} RequestShortener */
27
28
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
28
29
  /** @typedef {import("../WebpackError")} WebpackError */
@@ -54,7 +55,7 @@ class ContainerEntryModule extends Module {
54
55
  }
55
56
 
56
57
  /**
57
- * @returns {Set<string>} types available (do not mutate)
58
+ * @returns {SourceTypes} types available (do not mutate)
58
59
  */
59
60
  getSourceTypes() {
60
61
  return SOURCE_TYPES;
@@ -22,6 +22,7 @@ const FallbackItemDependency = require("./FallbackItemDependency");
22
22
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
23
23
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
24
24
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
25
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
25
26
  /** @typedef {import("../RequestShortener")} RequestShortener */
26
27
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
27
28
  /** @typedef {import("../WebpackError")} WebpackError */
@@ -116,7 +117,7 @@ class FallbackModule extends Module {
116
117
  }
117
118
 
118
119
  /**
119
- * @returns {Set<string>} types available (do not mutate)
120
+ * @returns {SourceTypes} types available (do not mutate)
120
121
  */
121
122
  getSourceTypes() {
122
123
  return TYPES;
@@ -21,6 +21,7 @@ const RemoteToExternalDependency = require("./RemoteToExternalDependency");
21
21
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
22
22
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
23
23
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
24
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
24
25
  /** @typedef {import("../RequestShortener")} RequestShortener */
25
26
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
26
27
  /** @typedef {import("../WebpackError")} WebpackError */
@@ -119,7 +120,7 @@ class RemoteModule extends Module {
119
120
  }
120
121
 
121
122
  /**
122
- * @returns {Set<string>} types available (do not mutate)
123
+ * @returns {SourceTypes} types available (do not mutate)
123
124
  */
124
125
  getSourceTypes() {
125
126
  return TYPES;
@@ -226,7 +226,7 @@ class CssLoadingRuntimeModule extends RuntimeModule {
226
226
  `module.exports = exports;`
227
227
  )}).bind(null, exports); ${
228
228
  withHmr ? "moduleIds.push(token); " : ""
229
- }token = ""; exports = {}; exportsWithId.length = 0; }`,
229
+ }token = ""; exports = {}; exportsWithId.length = 0; exportsWithDashes.length = 0; }`,
230
230
  `else if(cc == ${cc("\\")}) { token += data[++i] }`,
231
231
  `else { token += data[i]; }`
232
232
  ]),
@@ -25,7 +25,7 @@ const NullDependency = require("./NullDependency");
25
25
  /**
26
26
  * @param {ModuleGraph} moduleGraph the module graph
27
27
  * @param {Module} module the module
28
- * @param {string | null} exportName name of the export if any
28
+ * @param {string[] | null} exportName name of the export if any
29
29
  * @param {string | null} property name of the requested property
30
30
  * @param {RuntimeSpec} runtime for which runtime
31
31
  * @returns {any} value of the property
@@ -51,23 +51,19 @@ const getProperty = (moduleGraph, module, exportName, property, runtime) => {
51
51
  switch (property) {
52
52
  case "canMangle": {
53
53
  const exportsInfo = moduleGraph.getExportsInfo(module);
54
- const exportInfo = exportsInfo.getExportInfo(
55
- /** @type {string} */ (exportName)
56
- );
54
+ const exportInfo = exportsInfo.getExportInfo(exportName[0]);
57
55
  if (exportInfo) return exportInfo.canMangle;
58
56
  return exportsInfo.otherExportsInfo.canMangle;
59
57
  }
60
58
  case "used":
61
59
  return (
62
- moduleGraph
63
- .getExportsInfo(module)
64
- .getUsed(/** @type {string} */ (exportName), runtime) !==
60
+ moduleGraph.getExportsInfo(module).getUsed(exportName, runtime) !==
65
61
  UsageState.Unused
66
62
  );
67
63
  case "useInfo": {
68
64
  const state = moduleGraph
69
65
  .getExportsInfo(module)
70
- .getUsed(/** @type {string} */ (exportName), runtime);
66
+ .getUsed(exportName, runtime);
71
67
  switch (state) {
72
68
  case UsageState.Used:
73
69
  case UsageState.OnlyPropertiesUsed:
@@ -83,9 +79,7 @@ const getProperty = (moduleGraph, module, exportName, property, runtime) => {
83
79
  }
84
80
  }
85
81
  case "provideInfo":
86
- return moduleGraph
87
- .getExportsInfo(module)
88
- .isExportProvided(/** @type {string} */ (exportName));
82
+ return moduleGraph.getExportsInfo(module).isExportProvided(exportName);
89
83
  }
90
84
  return undefined;
91
85
  };
@@ -93,7 +87,7 @@ const getProperty = (moduleGraph, module, exportName, property, runtime) => {
93
87
  class ExportsInfoDependency extends NullDependency {
94
88
  /**
95
89
  * @param {Range} range range
96
- * @param {TODO} exportName export name
90
+ * @param {string[] | null} exportName export name
97
91
  * @param {string | null} property property
98
92
  */
99
93
  constructor(range, exportName, property) {
@@ -143,7 +143,8 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
143
143
  */
144
144
  getReferencedExports(moduleGraph, runtime) {
145
145
  let ids = this.getIds(moduleGraph);
146
- if (ids.length === 0) return this._getReferencedExportsInDestructuring();
146
+ if (ids.length === 0)
147
+ return this._getReferencedExportsInDestructuring(moduleGraph);
147
148
  let namespaceObjectAsContext = this.namespaceObjectAsContext;
148
149
  if (ids[0] === "default") {
149
150
  const selfModule = moduleGraph.getParentModule(this);
@@ -160,7 +161,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
160
161
  case "default-only":
161
162
  case "default-with-named":
162
163
  if (ids.length === 1)
163
- return this._getReferencedExportsInDestructuring();
164
+ return this._getReferencedExportsInDestructuring(moduleGraph);
164
165
  ids = ids.slice(1);
165
166
  namespaceObjectAsContext = true;
166
167
  break;
@@ -178,21 +179,30 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
178
179
  ids = ids.slice(0, -1);
179
180
  }
180
181
 
181
- return this._getReferencedExportsInDestructuring(ids);
182
+ return this._getReferencedExportsInDestructuring(moduleGraph, ids);
182
183
  }
183
184
 
184
185
  /**
186
+ * @param {ModuleGraph} moduleGraph module graph
185
187
  * @param {string[]=} ids ids
186
188
  * @returns {(string[] | ReferencedExport)[]} referenced exports
187
189
  */
188
- _getReferencedExportsInDestructuring(ids) {
190
+ _getReferencedExportsInDestructuring(moduleGraph, ids) {
189
191
  if (this.referencedPropertiesInDestructuring) {
190
192
  /** @type {ReferencedExport[]} */
191
193
  const refs = [];
194
+ const importedModule = moduleGraph.getModule(this);
195
+ const canMangle =
196
+ Array.isArray(ids) &&
197
+ ids.length > 0 &&
198
+ !moduleGraph
199
+ .getExportsInfo(importedModule)
200
+ .getExportInfo(ids[0])
201
+ .isReexport();
192
202
  for (const key of this.referencedPropertiesInDestructuring) {
193
203
  refs.push({
194
204
  name: ids ? ids.concat([key]) : [key],
195
- canMangle: false
205
+ canMangle
196
206
  });
197
207
  }
198
208
  return refs;
@@ -287,6 +287,7 @@ class ImportParserPlugin {
287
287
  exports
288
288
  );
289
289
  dep.loc = /** @type {DependencyLocation} */ (expr.loc);
290
+ dep.optional = !!parser.scope.inTry;
290
291
  depBlock.addDependency(dep);
291
292
  parser.state.current.addBlock(depBlock);
292
293
  }
@@ -29,7 +29,7 @@ class WorkerDependency extends ModuleDependency {
29
29
  * @param {string} request request
30
30
  * @param {Range} range range
31
31
  * @param {Object} workerDependencyOptions options
32
- * @param {string} workerDependencyOptions.publicPath public path for the worker
32
+ * @param {string=} workerDependencyOptions.publicPath public path for the worker
33
33
  */
34
34
  constructor(request, range, workerDependencyOptions) {
35
35
  super(request);
@@ -71,10 +71,10 @@ const PLUGIN_NAME = "WorkerPlugin";
71
71
 
72
72
  class WorkerPlugin {
73
73
  /**
74
- * @param {ChunkLoading} chunkLoading chunk loading
75
- * @param {WasmLoading} wasmLoading wasm loading
76
- * @param {OutputModule} module output module
77
- * @param {WorkerPublicPath} workerPublicPath worker public path
74
+ * @param {ChunkLoading=} chunkLoading chunk loading
75
+ * @param {WasmLoading=} wasmLoading wasm loading
76
+ * @param {OutputModule=} module output module
77
+ * @param {WorkerPublicPath=} workerPublicPath worker public path
78
78
  */
79
79
  constructor(chunkLoading, wasmLoading, module, workerPublicPath) {
80
80
  this._chunkLoading = chunkLoading;
@@ -215,7 +215,7 @@ module.exports = function () {
215
215
  for (var i = 0; i < registeredStatusHandlers.length; i++)
216
216
  results[i] = registeredStatusHandlers[i].call(null, newStatus);
217
217
 
218
- return Promise.all(results);
218
+ return Promise.all(results).then(function () {});
219
219
  }
220
220
 
221
221
  function unblock() {
@@ -27,6 +27,7 @@ const { registerNotSerializable } = require("../util/serialization");
27
27
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
28
28
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
29
29
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
30
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
30
31
  /** @typedef {import("../ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
31
32
  /** @typedef {import("../ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
32
33
  /** @typedef {import("../RequestShortener")} RequestShortener */
@@ -190,7 +191,7 @@ class LazyCompilationProxyModule extends Module {
190
191
  }
191
192
 
192
193
  /**
193
- * @returns {Set<string>} types available (do not mutate)
194
+ * @returns {SourceTypes} types available (do not mutate)
194
195
  */
195
196
  getSourceTypes() {
196
197
  return TYPES;
@@ -52,6 +52,7 @@ const {
52
52
  /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */
53
53
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
54
54
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
55
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
55
56
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
56
57
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
57
58
  /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
@@ -710,7 +711,7 @@ class ConcatenatedModule extends Module {
710
711
  }
711
712
 
712
713
  /**
713
- * @returns {Set<string>} types available (do not mutate)
714
+ * @returns {SourceTypes} types available (do not mutate)
714
715
  */
715
716
  getSourceTypes() {
716
717
  return TYPES;
@@ -56,7 +56,7 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
56
56
  "if(scripts.length) {",
57
57
  Template.indent([
58
58
  "var i = scripts.length - 1;",
59
- "while (i > -1 && !scriptUrl) scriptUrl = scripts[i--].src;"
59
+ "while (i > -1 && (!scriptUrl || !/^http(s?):/.test(scriptUrl))) scriptUrl = scripts[i--].src;"
60
60
  ]),
61
61
  "}"
62
62
  ]),
@@ -25,6 +25,7 @@ const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependen
25
25
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
26
26
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
27
27
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
28
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
28
29
  /** @typedef {import("../RequestShortener")} RequestShortener */
29
30
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
30
31
  /** @typedef {import("../WebpackError")} WebpackError */
@@ -147,7 +148,7 @@ class ConsumeSharedModule extends Module {
147
148
  }
148
149
 
149
150
  /**
150
- * @returns {Set<string>} types available (do not mutate)
151
+ * @returns {SourceTypes} types available (do not mutate)
151
152
  */
152
153
  getSourceTypes() {
153
154
  return TYPES;
@@ -21,6 +21,7 @@ const ProvideForSharedDependency = require("./ProvideForSharedDependency");
21
21
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
22
22
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
23
23
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
24
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
24
25
  /** @typedef {import("../RequestShortener")} RequestShortener */
25
26
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
26
27
  /** @typedef {import("../WebpackError")} WebpackError */
@@ -120,7 +121,7 @@ class ProvideSharedModule extends Module {
120
121
  }
121
122
 
122
123
  /**
123
- * @returns {Set<string>} types available (do not mutate)
124
+ * @returns {SourceTypes} types available (do not mutate)
124
125
  */
125
126
  getSourceTypes() {
126
127
  return TYPES;
@@ -23,6 +23,8 @@ const memoize = fn => {
23
23
  cache = true;
24
24
  // Allow to clean up memory for fn
25
25
  // and all dependent resources
26
+ // eslint-disable-next-line no-warning-comments
27
+ // @ts-ignore
26
28
  fn = undefined;
27
29
  return /** @type {T} */ (result);
28
30
  }
@@ -47,14 +47,9 @@ const FNV_PRIME_64 = BigInt("0x100000001B3");
47
47
  function fnv1a32(str) {
48
48
  let hash = FNV_OFFSET_32;
49
49
  for (let i = 0, len = str.length; i < len; i++) {
50
- let code = str.charCodeAt(i);
51
- if (code > 0xff) {
52
- hash ^= code & 0xff;
53
- hash = (hash * FNV_PRIME_32) | 0;
54
- code >>= 8;
55
- }
56
- hash ^= code;
57
- hash = (hash * FNV_PRIME_32) | 0;
50
+ hash ^= str.charCodeAt(i);
51
+ // Use Math.imul to do c-style 32-bit multiplication and keep only the 32 least significant bits
52
+ hash = Math.imul(hash, FNV_PRIME_32);
58
53
  }
59
54
  // Force the result to be positive
60
55
  return hash & MASK_31;
@@ -69,13 +64,7 @@ function fnv1a32(str) {
69
64
  function fnv1a64(str) {
70
65
  let hash = FNV_OFFSET_64;
71
66
  for (let i = 0, len = str.length; i < len; i++) {
72
- let code = str.charCodeAt(i);
73
- if (code > 0xff) {
74
- hash ^= BigInt(code & 0xff);
75
- hash = BigInt.asUintN(64, hash * FNV_PRIME_64);
76
- code >>= 8;
77
- }
78
- hash ^= BigInt(code);
67
+ hash ^= BigInt(str.charCodeAt(i));
79
68
  hash = BigInt.asUintN(64, hash * FNV_PRIME_64);
80
69
  }
81
70
  return hash;
@@ -19,6 +19,7 @@ const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDe
19
19
  /** @typedef {import("../Dependency")} Dependency */
20
20
  /** @typedef {import("../DependencyTemplates")} DependencyTemplates */
21
21
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
22
+ /** @typedef {import("../Module")} Module */
22
23
  /** @typedef {import("../NormalModule")} NormalModule */
23
24
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
24
25
 
@@ -127,7 +128,7 @@ class WebAssemblyJavascriptGenerator extends Generator {
127
128
  const defineStatement = Template.asString([
128
129
  `${exportProp} = ${runtimeTemplate.exportFromImport({
129
130
  moduleGraph,
130
- module: moduleGraph.getModule(dep),
131
+ module: /** @type {Module} */ (moduleGraph.getModule(dep)),
131
132
  request: dep.request,
132
133
  importVar: importData.importVar,
133
134
  originModule: module,
package/lib/webpack.js CHANGED
@@ -20,6 +20,7 @@ const NodeEnvironmentPlugin = require("./node/NodeEnvironmentPlugin");
20
20
  const memoize = require("./util/memoize");
21
21
 
22
22
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptions} WebpackOptions */
23
+ /** @typedef {import("../declarations/WebpackOptions").WebpackPluginFunction} WebpackPluginFunction */
23
24
  /** @typedef {import("./Compiler").WatchOptions} WatchOptions */
24
25
  /** @typedef {import("./MultiCompiler").MultiCompilerOptions} MultiCompilerOptions */
25
26
  /** @typedef {import("./MultiStats")} MultiStats */
@@ -30,7 +31,7 @@ const getValidateSchema = memoize(() => require("./validateSchema"));
30
31
  /**
31
32
  * @template T
32
33
  * @callback Callback
33
- * @param {Error=} err
34
+ * @param {(Error | null)=} err
34
35
  * @param {T=} stats
35
36
  * @returns {void}
36
37
  */
@@ -71,7 +72,8 @@ const createCompiler = rawOptions => {
71
72
  if (Array.isArray(options.plugins)) {
72
73
  for (const plugin of options.plugins) {
73
74
  if (typeof plugin === "function") {
74
- plugin.call(compiler, compiler);
75
+ /** @type {WebpackPluginFunction} */
76
+ (plugin).call(compiler, compiler);
75
77
  } else if (plugin) {
76
78
  plugin.apply(compiler);
77
79
  }
@@ -160,7 +162,7 @@ const webpack = /** @type {WebpackFunctionSingle & WebpackFunctionMulti} */ (
160
162
  }
161
163
  return compiler;
162
164
  } catch (err) {
163
- process.nextTick(() => callback(err));
165
+ process.nextTick(() => callback(/** @type {Error} */ (err)));
164
166
  return null;
165
167
  }
166
168
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack",
3
- "version": "5.90.1",
3
+ "version": "5.90.3",
4
4
  "author": "Tobias Koppers @sokra",
5
5
  "description": "Packs ECMAScript/CommonJs/AMD modules for the browser. Allows you to split your codebase into multiple bundles, which can be loaded on demand. Supports loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
6
6
  "license": "MIT",
@@ -57,7 +57,7 @@
57
57
  "eslint": "^8.48.0",
58
58
  "eslint-config-prettier": "^9.1.0",
59
59
  "eslint-plugin-jest": "^27.6.3",
60
- "eslint-plugin-jsdoc": "^43.0.5",
60
+ "eslint-plugin-jsdoc": "^48.1.0",
61
61
  "eslint-plugin-n": "^16.6.2",
62
62
  "eslint-plugin-prettier": "^5.1.3",
63
63
  "file-loader": "^6.0.0",