webpack 5.77.0 → 5.78.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 (66) hide show
  1. package/bin/webpack.js +0 -0
  2. package/lib/APIPlugin.js +25 -18
  3. package/lib/CompatibilityPlugin.js +53 -52
  4. package/lib/ConstPlugin.js +22 -15
  5. package/lib/ContextModule.js +3 -2
  6. package/lib/DefinePlugin.js +44 -36
  7. package/lib/DelegatedModule.js +2 -1
  8. package/lib/DllModule.js +2 -1
  9. package/lib/ErrorHelpers.js +61 -22
  10. package/lib/ExportsInfoApiPlugin.js +16 -9
  11. package/lib/ExternalModule.js +2 -1
  12. package/lib/FlagAllModulesAsUsedPlugin.js +22 -27
  13. package/lib/FlagDependencyExportsPlugin.js +336 -348
  14. package/lib/FlagDependencyUsagePlugin.js +6 -8
  15. package/lib/FlagEntryExportAsUsedPlugin.js +22 -23
  16. package/lib/HotModuleReplacementPlugin.js +50 -45
  17. package/lib/JavascriptMetaInfoPlugin.js +16 -9
  18. package/lib/ModuleTypeConstants.js +50 -0
  19. package/lib/NodeStuffPlugin.js +35 -31
  20. package/lib/NormalModule.js +2 -1
  21. package/lib/NormalModuleFactory.js +7 -1
  22. package/lib/ProvidePlugin.js +17 -10
  23. package/lib/RawModule.js +2 -1
  24. package/lib/RequireJsStuffPlugin.js +15 -15
  25. package/lib/UseStrictPlugin.js +15 -8
  26. package/lib/WebpackIsIncludedPlugin.js +16 -9
  27. package/lib/config/defaults.js +16 -8
  28. package/lib/config/normalization.js +4 -0
  29. package/lib/container/ContainerEntryModule.js +2 -1
  30. package/lib/css/CssParser.js +22 -2
  31. package/lib/debug/ProfilingPlugin.js +20 -12
  32. package/lib/dependencies/AMDPlugin.js +26 -20
  33. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -4
  34. package/lib/dependencies/CommonJsPlugin.js +29 -25
  35. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
  36. package/lib/dependencies/HarmonyModulesPlugin.js +11 -5
  37. package/lib/dependencies/ImportMetaContextPlugin.js +11 -5
  38. package/lib/dependencies/ImportMetaPlugin.js +26 -20
  39. package/lib/dependencies/ImportPlugin.js +14 -7
  40. package/lib/dependencies/RequireContextPlugin.js +12 -6
  41. package/lib/dependencies/RequireEnsurePlugin.js +13 -7
  42. package/lib/dependencies/RequireIncludePlugin.js +11 -5
  43. package/lib/dependencies/SystemPlugin.js +21 -15
  44. package/lib/dependencies/URLPlugin.js +15 -9
  45. package/lib/dependencies/WorkerPlugin.js +14 -8
  46. package/lib/javascript/JavascriptModulesPlugin.js +157 -164
  47. package/lib/json/JsonModulesPlugin.js +13 -5
  48. package/lib/library/AmdLibraryPlugin.js +22 -6
  49. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
  50. package/lib/node/ReadFileCompileWasmPlugin.js +2 -1
  51. package/lib/optimize/ConcatenatedModule.js +2 -1
  52. package/lib/optimize/InnerGraphPlugin.js +47 -46
  53. package/lib/optimize/SideEffectsFlagPlugin.js +43 -43
  54. package/lib/sharing/ConsumeSharedPlugin.js +4 -0
  55. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +9 -6
  56. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +42 -43
  57. package/lib/web/FetchCompileAsyncWasmPlugin.js +2 -1
  58. package/lib/web/FetchCompileWasmPlugin.js +40 -40
  59. package/package.json +1 -1
  60. package/schemas/WebpackOptions.check.js +1 -1
  61. package/schemas/WebpackOptions.json +18 -0
  62. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  63. package/schemas/plugins/container/ContainerPlugin.json +8 -0
  64. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  65. package/schemas/plugins/container/ModuleFederationPlugin.json +8 -0
  66. package/types.d.ts +10 -0
@@ -7,6 +7,7 @@
7
7
 
8
8
  const { OriginalSource, RawSource } = require("webpack-sources");
9
9
  const Module = require("./Module");
10
+ const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
10
11
  const RuntimeGlobals = require("./RuntimeGlobals");
11
12
  const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
12
13
  const StaticExportsDependency = require("./dependencies/StaticExportsDependency");
@@ -40,7 +41,7 @@ const RUNTIME_REQUIREMENTS = new Set([
40
41
 
41
42
  class DelegatedModule extends Module {
42
43
  constructor(sourceRequest, data, type, userRequest, originalRequest) {
43
- super("javascript/dynamic", null);
44
+ super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
44
45
 
45
46
  // Info from Factory
46
47
  this.sourceRequest = sourceRequest;
package/lib/DllModule.js CHANGED
@@ -7,6 +7,7 @@
7
7
 
8
8
  const { RawSource } = require("webpack-sources");
9
9
  const Module = require("./Module");
10
+ const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
10
11
  const RuntimeGlobals = require("./RuntimeGlobals");
11
12
  const makeSerializable = require("./util/makeSerializable");
12
13
 
@@ -35,7 +36,7 @@ const RUNTIME_REQUIREMENTS = new Set([
35
36
 
36
37
  class DllModule extends Module {
37
38
  constructor(context, dependencies, name) {
38
- super("javascript/dynamic", context);
39
+ super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, context);
39
40
 
40
41
  // Info from Factory
41
42
  this.dependencies = dependencies;
@@ -9,36 +9,57 @@ const loaderFlag = "LOADER_EXECUTION";
9
9
 
10
10
  const webpackOptionsFlag = "WEBPACK_OPTIONS";
11
11
 
12
- exports.cutOffByFlag = (stack, flag) => {
13
- stack = stack.split("\n");
14
- for (let i = 0; i < stack.length; i++) {
15
- if (stack[i].includes(flag)) {
16
- stack.length = i;
12
+ /**
13
+ * @param {string} stack stack trace
14
+ * @param {string} flag flag to cut off
15
+ * @returns {string} stack trace without the specified flag included
16
+ */
17
+ const cutOffByFlag = (stack, flag) => {
18
+ const errorStack = stack.split("\n");
19
+ for (let i = 0; i < errorStack.length; i++) {
20
+ if (errorStack[i].includes(flag)) {
21
+ errorStack.length = i;
17
22
  }
18
23
  }
19
- return stack.join("\n");
24
+ return errorStack.join("\n");
20
25
  };
21
26
 
22
- exports.cutOffLoaderExecution = stack =>
23
- exports.cutOffByFlag(stack, loaderFlag);
27
+ /**
28
+ * @param {string} stack stack trace
29
+ * @returns {string} stack trace without the loader execution flag included
30
+ */
31
+ const cutOffLoaderExecution = stack => cutOffByFlag(stack, loaderFlag);
24
32
 
25
- exports.cutOffWebpackOptions = stack =>
26
- exports.cutOffByFlag(stack, webpackOptionsFlag);
33
+ /**
34
+ * @param {string} stack stack trace
35
+ * @returns {string} stack trace without the webpack options flag included
36
+ */
37
+ const cutOffWebpackOptions = stack => cutOffByFlag(stack, webpackOptionsFlag);
27
38
 
28
- exports.cutOffMultilineMessage = (stack, message) => {
29
- stack = stack.split("\n");
30
- message = message.split("\n");
39
+ /**
40
+ * @param {string} stack stack trace
41
+ * @param {string} message error message
42
+ * @returns {string} stack trace without the message included
43
+ */
44
+ const cutOffMultilineMessage = (stack, message) => {
45
+ const stackSplitByLines = stack.split("\n");
46
+ const messageSplitByLines = message.split("\n");
31
47
 
32
48
  const result = [];
33
49
 
34
- stack.forEach((line, idx) => {
35
- if (!line.includes(message[idx])) result.push(line);
50
+ stackSplitByLines.forEach((line, idx) => {
51
+ if (!line.includes(messageSplitByLines[idx])) result.push(line);
36
52
  });
37
53
 
38
54
  return result.join("\n");
39
55
  };
40
56
 
41
- exports.cutOffMessage = (stack, message) => {
57
+ /**
58
+ * @param {string} stack stack trace
59
+ * @param {string} message error message
60
+ * @returns {string} stack trace without the message included
61
+ */
62
+ const cutOffMessage = (stack, message) => {
42
63
  const nextLine = stack.indexOf("\n");
43
64
  if (nextLine === -1) {
44
65
  return stack === message ? "" : stack;
@@ -48,14 +69,32 @@ exports.cutOffMessage = (stack, message) => {
48
69
  }
49
70
  };
50
71
 
51
- exports.cleanUp = (stack, message) => {
52
- stack = exports.cutOffLoaderExecution(stack);
53
- stack = exports.cutOffMessage(stack, message);
72
+ /**
73
+ * @param {string} stack stack trace
74
+ * @param {string} message error message
75
+ * @returns {string} stack trace without the loader execution flag and message included
76
+ */
77
+ const cleanUp = (stack, message) => {
78
+ stack = cutOffLoaderExecution(stack);
79
+ stack = cutOffMessage(stack, message);
54
80
  return stack;
55
81
  };
56
82
 
57
- exports.cleanUpWebpackOptions = (stack, message) => {
58
- stack = exports.cutOffWebpackOptions(stack);
59
- stack = exports.cutOffMultilineMessage(stack, message);
83
+ /**
84
+ * @param {string} stack stack trace
85
+ * @param {string} message error message
86
+ * @returns {string} stack trace without the webpack options flag and message included
87
+ */
88
+ const cleanUpWebpackOptions = (stack, message) => {
89
+ stack = cutOffWebpackOptions(stack);
90
+ stack = cutOffMultilineMessage(stack, message);
60
91
  return stack;
61
92
  };
93
+
94
+ exports.cutOffByFlag = cutOffByFlag;
95
+ exports.cutOffLoaderExecution = cutOffLoaderExecution;
96
+ exports.cutOffWebpackOptions = cutOffWebpackOptions;
97
+ exports.cutOffMultilineMessage = cutOffMultilineMessage;
98
+ exports.cutOffMessage = cutOffMessage;
99
+ exports.cleanUp = cleanUp;
100
+ exports.cleanUpWebpackOptions = cleanUpWebpackOptions;
@@ -5,12 +5,19 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const {
9
+ JAVASCRIPT_MODULE_TYPE_AUTO,
10
+ JAVASCRIPT_MODULE_TYPE_DYNAMIC,
11
+ JAVASCRIPT_MODULE_TYPE_ESM
12
+ } = require("./ModuleTypeConstants");
8
13
  const ConstDependency = require("./dependencies/ConstDependency");
9
14
  const ExportsInfoDependency = require("./dependencies/ExportsInfoDependency");
10
15
 
11
16
  /** @typedef {import("./Compiler")} Compiler */
12
17
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
13
18
 
19
+ const PLUGIN_NAME = "ExportsInfoApiPlugin";
20
+
14
21
  class ExportsInfoApiPlugin {
15
22
  /**
16
23
  * Apply the plugin
@@ -19,7 +26,7 @@ class ExportsInfoApiPlugin {
19
26
  */
20
27
  apply(compiler) {
21
28
  compiler.hooks.compilation.tap(
22
- "ExportsInfoApiPlugin",
29
+ PLUGIN_NAME,
23
30
  (compilation, { normalModuleFactory }) => {
24
31
  compilation.dependencyTemplates.set(
25
32
  ExportsInfoDependency,
@@ -32,7 +39,7 @@ class ExportsInfoApiPlugin {
32
39
  const handler = parser => {
33
40
  parser.hooks.expressionMemberChain
34
41
  .for("__webpack_exports_info__")
35
- .tap("ExportsInfoApiPlugin", (expr, members) => {
42
+ .tap(PLUGIN_NAME, (expr, members) => {
36
43
  const dep =
37
44
  members.length >= 2
38
45
  ? new ExportsInfoDependency(
@@ -47,7 +54,7 @@ class ExportsInfoApiPlugin {
47
54
  });
48
55
  parser.hooks.expression
49
56
  .for("__webpack_exports_info__")
50
- .tap("ExportsInfoApiPlugin", expr => {
57
+ .tap(PLUGIN_NAME, expr => {
51
58
  const dep = new ConstDependency("true", expr.range);
52
59
  dep.loc = expr.loc;
53
60
  parser.state.module.addPresentationalDependency(dep);
@@ -55,14 +62,14 @@ class ExportsInfoApiPlugin {
55
62
  });
56
63
  };
57
64
  normalModuleFactory.hooks.parser
58
- .for("javascript/auto")
59
- .tap("ExportsInfoApiPlugin", handler);
65
+ .for(JAVASCRIPT_MODULE_TYPE_AUTO)
66
+ .tap(PLUGIN_NAME, handler);
60
67
  normalModuleFactory.hooks.parser
61
- .for("javascript/dynamic")
62
- .tap("ExportsInfoApiPlugin", handler);
68
+ .for(JAVASCRIPT_MODULE_TYPE_DYNAMIC)
69
+ .tap(PLUGIN_NAME, handler);
63
70
  normalModuleFactory.hooks.parser
64
- .for("javascript/esm")
65
- .tap("ExportsInfoApiPlugin", handler);
71
+ .for(JAVASCRIPT_MODULE_TYPE_ESM)
72
+ .tap(PLUGIN_NAME, handler);
66
73
  }
67
74
  );
68
75
  }
@@ -10,6 +10,7 @@ const ConcatenationScope = require("./ConcatenationScope");
10
10
  const { UsageState } = require("./ExportsInfo");
11
11
  const InitFragment = require("./InitFragment");
12
12
  const Module = require("./Module");
13
+ const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("./ModuleTypeConstants");
13
14
  const RuntimeGlobals = require("./RuntimeGlobals");
14
15
  const Template = require("./Template");
15
16
  const StaticExportsDependency = require("./dependencies/StaticExportsDependency");
@@ -378,7 +379,7 @@ const getSourceForDefaultCase = (optional, request, runtimeTemplate) => {
378
379
 
379
380
  class ExternalModule extends Module {
380
381
  constructor(request, type, userRequest) {
381
- super("javascript/dynamic", null);
382
+ super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
382
383
 
383
384
  // Info from Factory
384
385
  /** @type {string | string[] | Record<string, string | string[]>} */
@@ -10,6 +10,7 @@ const { getEntryRuntime, mergeRuntimeOwned } = require("./util/runtime");
10
10
  /** @typedef {import("./Compiler")} Compiler */
11
11
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
12
12
 
13
+ const PLUGIN_NAME = "FlagAllModulesAsUsedPlugin";
13
14
  class FlagAllModulesAsUsedPlugin {
14
15
  constructor(explanation) {
15
16
  this.explanation = explanation;
@@ -21,34 +22,28 @@ class FlagAllModulesAsUsedPlugin {
21
22
  * @returns {void}
22
23
  */
23
24
  apply(compiler) {
24
- compiler.hooks.compilation.tap(
25
- "FlagAllModulesAsUsedPlugin",
26
- compilation => {
27
- const moduleGraph = compilation.moduleGraph;
28
- compilation.hooks.optimizeDependencies.tap(
29
- "FlagAllModulesAsUsedPlugin",
30
- modules => {
31
- /** @type {RuntimeSpec} */
32
- let runtime = undefined;
33
- for (const [name, { options }] of compilation.entries) {
34
- runtime = mergeRuntimeOwned(
35
- runtime,
36
- getEntryRuntime(compilation, name, options)
37
- );
38
- }
39
- for (const module of modules) {
40
- const exportsInfo = moduleGraph.getExportsInfo(module);
41
- exportsInfo.setUsedInUnknownWay(runtime);
42
- moduleGraph.addExtraReason(module, this.explanation);
43
- if (module.factoryMeta === undefined) {
44
- module.factoryMeta = {};
45
- }
46
- module.factoryMeta.sideEffectFree = false;
47
- }
25
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
26
+ const moduleGraph = compilation.moduleGraph;
27
+ compilation.hooks.optimizeDependencies.tap(PLUGIN_NAME, modules => {
28
+ /** @type {RuntimeSpec} */
29
+ let runtime = undefined;
30
+ for (const [name, { options }] of compilation.entries) {
31
+ runtime = mergeRuntimeOwned(
32
+ runtime,
33
+ getEntryRuntime(compilation, name, options)
34
+ );
35
+ }
36
+ for (const module of modules) {
37
+ const exportsInfo = moduleGraph.getExportsInfo(module);
38
+ exportsInfo.setUsedInUnknownWay(runtime);
39
+ moduleGraph.addExtraReason(module, this.explanation);
40
+ if (module.factoryMeta === undefined) {
41
+ module.factoryMeta = {};
48
42
  }
49
- );
50
- }
51
- );
43
+ module.factoryMeta.sideEffectFree = false;
44
+ }
45
+ });
46
+ });
52
47
  }
53
48
  }
54
49