webpack 5.102.1 → 5.103.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.
Files changed (118) hide show
  1. package/README.md +121 -134
  2. package/lib/CompatibilityPlugin.js +25 -2
  3. package/lib/Compilation.js +25 -2
  4. package/lib/ConcatenationScope.js +0 -15
  5. package/lib/CssModule.js +6 -1
  6. package/lib/DefinePlugin.js +11 -11
  7. package/lib/Dependency.js +8 -1
  8. package/lib/DependencyTemplate.js +1 -0
  9. package/lib/DotenvPlugin.js +457 -0
  10. package/lib/EnvironmentPlugin.js +19 -16
  11. package/lib/EvalSourceMapDevToolPlugin.js +16 -0
  12. package/lib/ExportsInfo.js +6 -2
  13. package/lib/ExternalModule.js +20 -28
  14. package/lib/ExternalModuleFactoryPlugin.js +10 -8
  15. package/lib/ExternalsPlugin.js +2 -1
  16. package/lib/ManifestPlugin.js +235 -0
  17. package/lib/Module.js +3 -0
  18. package/lib/ModuleGraph.js +2 -1
  19. package/lib/ModuleSourceTypesConstants.js +0 -6
  20. package/lib/MultiCompiler.js +1 -1
  21. package/lib/NodeStuffPlugin.js +419 -121
  22. package/lib/NormalModule.js +17 -16
  23. package/lib/RuntimeGlobals.js +22 -4
  24. package/lib/RuntimePlugin.js +27 -6
  25. package/lib/RuntimeTemplate.js +115 -56
  26. package/lib/SourceMapDevToolPlugin.js +20 -0
  27. package/lib/WebpackOptionsApply.js +33 -9
  28. package/lib/asset/AssetBytesGenerator.js +1 -1
  29. package/lib/asset/AssetGenerator.js +1 -2
  30. package/lib/asset/AssetSourceGenerator.js +1 -1
  31. package/lib/config/browserslistTargetHandler.js +5 -0
  32. package/lib/config/defaults.js +98 -18
  33. package/lib/config/normalization.js +2 -1
  34. package/lib/config/target.js +6 -0
  35. package/lib/css/CssGenerator.js +283 -57
  36. package/lib/css/CssLoadingRuntimeModule.js +2 -0
  37. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
  38. package/lib/css/CssModulesPlugin.js +84 -34
  39. package/lib/css/CssParser.js +1174 -667
  40. package/lib/css/walkCssTokens.js +97 -0
  41. package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
  42. package/lib/dependencies/CommonJsPlugin.js +12 -0
  43. package/lib/dependencies/CssIcssExportDependency.js +247 -8
  44. package/lib/dependencies/CssIcssFromIdentifierDependency.js +124 -0
  45. package/lib/dependencies/CssIcssGlobalIdentifierDependency.js +48 -0
  46. package/lib/dependencies/CssIcssImportDependency.js +60 -54
  47. package/lib/dependencies/CssIcssLocalIdentifierDependency.js +61 -0
  48. package/lib/dependencies/{CssSelfLocalIdentifierDependency.js → CssIcssSelfLocalIdentifierDependency.js} +88 -10
  49. package/lib/dependencies/CssIcssSymbolDependency.js +31 -29
  50. package/lib/dependencies/CssImportDependency.js +15 -5
  51. package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
  52. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +95 -0
  53. package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
  54. package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
  55. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
  56. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +32 -21
  57. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +12 -8
  58. package/lib/dependencies/HarmonyImportDependency.js +23 -27
  59. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
  60. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
  61. package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
  62. package/lib/dependencies/ImportDependency.js +8 -2
  63. package/lib/dependencies/ImportEagerDependency.js +6 -3
  64. package/lib/dependencies/ImportMetaPlugin.js +97 -9
  65. package/lib/dependencies/ImportParserPlugin.js +19 -21
  66. package/lib/dependencies/ImportPhase.js +121 -0
  67. package/lib/dependencies/ImportWeakDependency.js +6 -3
  68. package/lib/dependencies/ModuleDependency.js +5 -1
  69. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
  70. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
  71. package/lib/hmr/LazyCompilationPlugin.js +1 -0
  72. package/lib/ids/IdHelpers.js +4 -1
  73. package/lib/index.js +6 -0
  74. package/lib/javascript/ChunkHelpers.js +16 -5
  75. package/lib/javascript/JavascriptGenerator.js +101 -101
  76. package/lib/javascript/JavascriptModulesPlugin.js +23 -13
  77. package/lib/javascript/JavascriptParser.js +142 -38
  78. package/lib/json/JsonParser.js +7 -1
  79. package/lib/library/ModuleLibraryPlugin.js +0 -10
  80. package/lib/library/SystemLibraryPlugin.js +4 -0
  81. package/lib/library/UmdLibraryPlugin.js +1 -1
  82. package/lib/node/NodeTargetPlugin.js +9 -1
  83. package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
  84. package/lib/optimize/ConcatenatedModule.js +161 -135
  85. package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
  86. package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
  87. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
  88. package/lib/util/comparators.js +4 -3
  89. package/lib/util/internalSerializables.js +4 -4
  90. package/lib/util/jsonParseEvenBetterErrors.js +10 -0
  91. package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
  92. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +8 -5
  93. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +8 -4
  94. package/lib/web/FetchCompileWasmPlugin.js +0 -2
  95. package/lib/webpack.js +85 -82
  96. package/module.d.ts +5 -0
  97. package/package.json +16 -14
  98. package/schemas/WebpackOptions.check.js +1 -1
  99. package/schemas/WebpackOptions.json +109 -27
  100. package/schemas/plugins/ManifestPlugin.check.d.ts +7 -0
  101. package/schemas/plugins/ManifestPlugin.check.js +6 -0
  102. package/schemas/plugins/ManifestPlugin.json +98 -0
  103. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  104. package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
  105. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  106. package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
  107. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  108. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  109. package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
  110. package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
  111. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  112. package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
  113. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  114. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  115. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  116. package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
  117. package/types.d.ts +560 -293
  118. package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
@@ -8,8 +8,12 @@ const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const Template = require("../Template");
9
9
  const HelperRuntimeModule = require("./HelperRuntimeModule");
10
10
 
11
+ /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
12
+ /** @typedef {import("../Module").ExportsType} ExportsType */
13
+ /** @typedef {import("../ChunkGraph").ModuleId} ModuleId */
14
+
11
15
  /**
12
- * @param {import("../Module").ExportsType} exportsType exports type
16
+ * @param {ExportsType} exportsType exports type
13
17
  * @returns {string} mode
14
18
  */
15
19
  function getMakeDeferredNamespaceModeFromExportsType(exportsType) {
@@ -19,61 +23,81 @@ function getMakeDeferredNamespaceModeFromExportsType(exportsType) {
19
23
  if (exportsType === "dynamic") return `/* ${exportsType} */ 3`;
20
24
  return "";
21
25
  }
26
+
22
27
  /**
23
- * @param {import("../ModuleTemplate").RuntimeTemplate} _runtimeTemplate runtimeTemplate
24
- * @param {import("../Module").ExportsType} exportsType exportsType
25
28
  * @param {string} moduleId moduleId
26
- * @param {(import("../ChunkGraph").ModuleId | null)[]} asyncDepsIds asyncDepsIds
27
- * @returns {string} function
29
+ * @param {ExportsType} exportsType exportsType
30
+ * @param {(ModuleId | null)[]} asyncDepsIds asyncDepsIds
31
+ * @param {RuntimeRequirements} runtimeRequirements runtime requirements
32
+ * @returns {string} call make optimized deferred namespace object
28
33
  */
29
34
  function getOptimizedDeferredModule(
30
- _runtimeTemplate,
31
- exportsType,
32
35
  moduleId,
33
- asyncDepsIds
36
+ exportsType,
37
+ asyncDepsIds,
38
+ runtimeRequirements
34
39
  ) {
35
- const isAsync = asyncDepsIds && asyncDepsIds.length;
36
- const init = `${RuntimeGlobals.require}(${moduleId})${
37
- isAsync ? `[${RuntimeGlobals.asyncModuleExportSymbol}]` : ""
38
- }`;
39
- const props = [
40
- `/* ${exportsType} */ get a() {`,
41
- // if exportsType is "namespace" we can generate the most optimized code,
42
- // on the second access, we can avoid trigger the getter.
43
- // we can also do this if exportsType is "dynamic" and there is a "__esModule" property on it.
44
- exportsType === "namespace" || exportsType === "dynamic"
45
- ? Template.indent([
46
- `var exports = ${init};`,
47
- `${
48
- exportsType === "dynamic" ? "if (exports.__esModule) " : ""
49
- }Object.defineProperty(this, "a", { value: exports });`,
50
- "return exports;"
51
- ])
52
- : Template.indent([`return ${init};`]),
53
- isAsync ? "}," : "}",
54
- isAsync
55
- ? `[${
56
- RuntimeGlobals.makeDeferredNamespaceObjectSymbol
57
- }]: ${JSON.stringify(asyncDepsIds.filter((x) => x !== null))}`
40
+ runtimeRequirements.add(RuntimeGlobals.makeOptimizedDeferredNamespaceObject);
41
+ const mode = getMakeDeferredNamespaceModeFromExportsType(exportsType);
42
+ return `${RuntimeGlobals.makeOptimizedDeferredNamespaceObject}(${moduleId}, ${mode}${
43
+ asyncDepsIds.length > 0
44
+ ? `, ${JSON.stringify(asyncDepsIds.filter((x) => x !== null))}`
58
45
  : ""
59
- ];
60
- return Template.asString(["{", Template.indent(props), "}"]);
46
+ })`;
61
47
  }
62
48
 
63
- const strictModuleCache = [
64
- "if (cachedModule && cachedModule.error === undefined) {",
65
- Template.indent([
66
- "var exports = cachedModule.exports;",
67
- "if (mode == 0) return exports;",
68
- `if (mode == 1) return ${RuntimeGlobals.createFakeNamespaceObject}(exports);`,
69
- `if (mode == 2) return ${RuntimeGlobals.createFakeNamespaceObject}(exports, 2);`,
70
- `if (mode == 3) return ${RuntimeGlobals.createFakeNamespaceObject}(exports, 6);` // 2 | 4
71
- ]),
72
- "}"
73
- ];
74
- const nonStrictModuleCache = [
75
- "// optimization not applied when output.strictModuleErrorHandling is off"
76
- ];
49
+ class MakeOptimizedDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
50
+ /**
51
+ * @param {boolean} hasAsyncRuntime if async module is used.
52
+ */
53
+ constructor(hasAsyncRuntime) {
54
+ super("make optimized deferred namespace object");
55
+ this.hasAsyncRuntime = hasAsyncRuntime;
56
+ }
57
+
58
+ /**
59
+ * @returns {string | null} runtime code
60
+ */
61
+ generate() {
62
+ if (!this.compilation) return null;
63
+ const fn = RuntimeGlobals.makeOptimizedDeferredNamespaceObject;
64
+ const hasAsync = this.hasAsyncRuntime;
65
+ return Template.asString([
66
+ // Note: must be a function (not arrow), because this is used in body!
67
+ `${fn} = function(moduleId, mode${hasAsync ? ", asyncDeps" : ""}) {`,
68
+ Template.indent([
69
+ "// mode: 0 => namespace (esm)",
70
+ "// mode: 1 => default-only (esm strict cjs)",
71
+ "// mode: 2 => default-with-named (esm-cjs compat)",
72
+ "// mode: 3 => dynamic (if exports has __esModule, then esm, otherwise default-with-named)",
73
+ "var r = this;",
74
+ hasAsync ? "var isAsync = asyncDeps && asyncDeps.length;" : "",
75
+ "var obj = {",
76
+ Template.indent([
77
+ "get a() {",
78
+ Template.indent([
79
+ "var exports = r(moduleId);",
80
+ hasAsync
81
+ ? `if(isAsync) exports = exports[${RuntimeGlobals.asyncModuleExportSymbol}];`
82
+ : "",
83
+ // if exportsType is "namespace" we can generate the most optimized code,
84
+ // on the second access, we can avoid trigger the getter.
85
+ // we can also do this if exportsType is "dynamic" and there is a "__esModule" property on it.
86
+ 'if(mode == 0 || (mode == 3 && exports.__esModule)) Object.defineProperty(this, "a", { value: exports });',
87
+ "return exports;"
88
+ ]),
89
+ "}"
90
+ ]),
91
+ "};",
92
+ hasAsync
93
+ ? `if(isAsync) obj[${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol}] = asyncDeps;`
94
+ : "",
95
+ "return obj;"
96
+ ]),
97
+ "};"
98
+ ]);
99
+ }
100
+ }
77
101
 
78
102
  class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
79
103
  /**
@@ -92,8 +116,6 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
92
116
  const { runtimeTemplate } = this.compilation;
93
117
  const fn = RuntimeGlobals.makeDeferredNamespaceObject;
94
118
  const hasAsync = this.hasAsyncRuntime;
95
- const strictError =
96
- this.compilation.options.output.strictModuleErrorHandling;
97
119
  const init = runtimeTemplate.supportsOptionalChaining()
98
120
  ? "init?.();"
99
121
  : "if (init) init();";
@@ -104,7 +126,18 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
104
126
  "// mode: 3 => dynamic (if exports has __esModule, then esm, otherwise default-with-named)",
105
127
  "",
106
128
  "var cachedModule = __webpack_module_cache__[moduleId];",
107
- ...(strictError ? strictModuleCache : nonStrictModuleCache),
129
+ "if (cachedModule && cachedModule.error === undefined) {",
130
+ Template.indent([
131
+ "var exports = cachedModule.exports;",
132
+ hasAsync
133
+ ? `if (${RuntimeGlobals.asyncModuleExportSymbol} in exports) exports = exports[${RuntimeGlobals.asyncModuleExportSymbol}];`
134
+ : "",
135
+ "if (mode == 0) return exports;",
136
+ `if (mode == 1) return ${RuntimeGlobals.createFakeNamespaceObject}(exports);`,
137
+ `if (mode == 2) return ${RuntimeGlobals.createFakeNamespaceObject}(exports, 2);`,
138
+ `if (mode == 3) return ${RuntimeGlobals.createFakeNamespaceObject}(exports, 6);` // 2 | 4
139
+ ]),
140
+ "}",
108
141
  "",
109
142
  `var init = ${runtimeTemplate.basicFunction("", [
110
143
  `ns = ${RuntimeGlobals.require}(moduleId);`,
@@ -137,9 +170,7 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
137
170
  "}"
138
171
  ])};`,
139
172
  "",
140
- `var ns = ${
141
- strictError ? "" : "cachedModule && cachedModule.exports || "
142
- }__webpack_module_deferred_exports__[moduleId] || (__webpack_module_deferred_exports__[moduleId] = { __proto__: null });`,
173
+ "var ns = __webpack_module_deferred_exports__[moduleId] || (__webpack_module_deferred_exports__[moduleId] = { __proto__: null });",
143
174
  "var handler = {",
144
175
  Template.indent([
145
176
  "__proto__: null,",
@@ -161,7 +192,7 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
161
192
  'case "__esModule":',
162
193
  "case Symbol.toStringTag:",
163
194
  hasAsync
164
- ? `case ${RuntimeGlobals.makeDeferredNamespaceObjectSymbol}:`
195
+ ? `case ${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol}:`
165
196
  : "",
166
197
  Template.indent("return true;"),
167
198
  'case "then":',
@@ -208,7 +239,10 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
208
239
  }
209
240
  }
210
241
 
211
- module.exports = MakeDeferredNamespaceObjectRuntimeModule;
242
+ module.exports.MakeDeferredNamespaceObjectRuntimeModule =
243
+ MakeDeferredNamespaceObjectRuntimeModule;
244
+ module.exports.MakeOptimizedDeferredNamespaceObjectRuntimeModule =
245
+ MakeOptimizedDeferredNamespaceObjectRuntimeModule;
212
246
  module.exports.getMakeDeferredNamespaceModeFromExportsType =
213
247
  getMakeDeferredNamespaceModeFromExportsType;
214
248
  module.exports.getOptimizedDeferredModule = getOptimizedDeferredModule;
@@ -19,6 +19,7 @@ const { compareRuntime } = require("./runtime");
19
19
  /** @typedef {import("../dependencies/HarmonyImportSpecifierDependency")} HarmonyImportSpecifierDependency */
20
20
  /** @typedef {import("../Module")} Module */
21
21
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
22
+ /** @typedef {import("../dependencies/ModuleDependency")} ModuleDependency */
22
23
 
23
24
  /**
24
25
  * @typedef {object} DependencySourceOrder
@@ -524,9 +525,9 @@ const sortWithSourceOrder = (dependencies, dependencySourceOrderMap) => {
524
525
  );
525
526
  return main;
526
527
  }
527
- return /** @type { HarmonyImportSideEffectDependency | HarmonyImportSpecifierDependency} */ (
528
- dep
529
- ).sourceOrder;
528
+ return /** @type {number} */ (
529
+ /** @type {ModuleDependency} */ (dep).sourceOrder
530
+ );
530
531
  };
531
532
 
532
533
  /**
@@ -73,10 +73,10 @@ module.exports = {
73
73
  require("../dependencies/CriticalDependencyWarning"),
74
74
  "dependencies/CssImportDependency": () =>
75
75
  require("../dependencies/CssImportDependency"),
76
- "dependencies/CssLocalIdentifierDependency": () =>
77
- require("../dependencies/CssLocalIdentifierDependency"),
78
- "dependencies/CssSelfLocalIdentifierDependency": () =>
79
- require("../dependencies/CssSelfLocalIdentifierDependency"),
76
+ "dependencies/CssIcssLocalIdentifierDependency": () =>
77
+ require("../dependencies/CssIcssLocalIdentifierDependency"),
78
+ "dependencies/CssIcssSelfLocalIdentifierDependency": () =>
79
+ require("../dependencies/CssIcssSelfLocalIdentifierDependency"),
80
80
  "dependencies/CssIcssImportDependency": () =>
81
81
  require("../dependencies/CssIcssImportDependency"),
82
82
  "dependencies/CssIcssExportDependency": () =>
@@ -0,0 +1,10 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Alexander Akait @alexander-akait
4
+ */
5
+
6
+ "use strict";
7
+
8
+ //#region runtime code: json-parse-even-better-errors, parseJsonError
9
+ module.exports = "test";
10
+ //#endregion
@@ -77,7 +77,6 @@ class EnableWasmLoadingPlugin {
77
77
  switch (type) {
78
78
  case "fetch": {
79
79
  if (compiler.options.experiments.syncWebAssembly) {
80
- // TODO webpack 6 remove FetchCompileWasmPlugin
81
80
  const FetchCompileWasmPlugin = require("../web/FetchCompileWasmPlugin");
82
81
 
83
82
  new FetchCompileWasmPlugin({
@@ -95,7 +94,6 @@ class EnableWasmLoadingPlugin {
95
94
  }
96
95
  case "async-node": {
97
96
  if (compiler.options.experiments.syncWebAssembly) {
98
- // TODO webpack 6 remove ReadFileCompileWasmPlugin
99
97
  const ReadFileCompileWasmPlugin = require("../node/ReadFileCompileWasmPlugin");
100
98
 
101
99
  new ReadFileCompileWasmPlugin({
@@ -119,9 +117,17 @@ class EnableWasmLoadingPlugin {
119
117
  break;
120
118
  }
121
119
  case "universal": {
122
- const UniversalCompileAsyncWasmPlugin = require("../wasm-async/UniversalCompileAsyncWasmPlugin");
120
+ if (compiler.options.experiments.syncWebAssembly) {
121
+ throw new Error(
122
+ "Universal wasm loading type is only supported by asynchronous web assembly."
123
+ );
124
+ }
123
125
 
124
- new UniversalCompileAsyncWasmPlugin().apply(compiler);
126
+ if (compiler.options.experiments.asyncWebAssembly) {
127
+ const UniversalCompileAsyncWasmPlugin = require("../wasm-async/UniversalCompileAsyncWasmPlugin");
128
+
129
+ new UniversalCompileAsyncWasmPlugin().apply(compiler);
130
+ }
125
131
  break;
126
132
  }
127
133
  default:
@@ -20,7 +20,7 @@ const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDe
20
20
  /** @typedef {import("../NormalModule")} NormalModule */
21
21
 
22
22
  /**
23
- * @typedef {{ request: string, importVar: string }} ImportObjRequestItem
23
+ * @typedef {{ request: string, importVar: string, dependency: WebAssemblyImportDependency }} ImportObjRequestItem
24
24
  */
25
25
 
26
26
  class AsyncWebAssemblyJavascriptGenerator extends Generator {
@@ -70,7 +70,8 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
70
70
  if (!depModules.has(module)) {
71
71
  depModules.set(module, {
72
72
  request: dep.request,
73
- importVar: `WEBPACK_IMPORTED_MODULE_${depModules.size}`
73
+ importVar: `WEBPACK_IMPORTED_MODULE_${depModules.size}`,
74
+ dependency: dep
74
75
  });
75
76
  }
76
77
  let list = wasmDepsByRequest.get(dep.request);
@@ -87,7 +88,7 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
87
88
 
88
89
  const importStatements = Array.from(
89
90
  depModules,
90
- ([importedModule, { request, importVar }]) => {
91
+ ([importedModule, { request, importVar, dependency }]) => {
91
92
  if (moduleGraph.isAsync(importedModule)) {
92
93
  promises.push(importVar);
93
94
  }
@@ -99,7 +100,8 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
99
100
  request,
100
101
  originModule: module,
101
102
  importVar,
102
- runtimeRequirements
103
+ runtimeRequirements,
104
+ dependency
103
105
  });
104
106
  }
105
107
  );
@@ -132,7 +134,8 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
132
134
  importVar,
133
135
  initFragments,
134
136
  runtime,
135
- runtimeRequirements
137
+ runtimeRequirements,
138
+ dependency: dep
136
139
  })}`;
137
140
  });
138
141
  return Template.asString([
@@ -71,6 +71,7 @@ class WebAssemblyJavascriptGenerator extends Generator {
71
71
  importedModules.set(
72
72
  moduleGraph.getModule(dep),
73
73
  (importData = {
74
+ dependency: moduleDep,
74
75
  importVar: `m${index}`,
75
76
  index,
76
77
  request: (moduleDep && moduleDep.userRequest) || undefined,
@@ -106,7 +107,8 @@ class WebAssemblyJavascriptGenerator extends Generator {
106
107
  defaultInterop: true,
107
108
  initFragments,
108
109
  runtime,
109
- runtimeRequirements
110
+ runtimeRequirements,
111
+ dependency: dep
110
112
  })
111
113
  );
112
114
  }
@@ -138,7 +140,8 @@ class WebAssemblyJavascriptGenerator extends Generator {
138
140
  defaultInterop: true,
139
141
  initFragments,
140
142
  runtime,
141
- runtimeRequirements
143
+ runtimeRequirements,
144
+ dependency: dep
142
145
  })};`,
143
146
  `if(WebAssembly.Global) ${exportProp} = ` +
144
147
  `new WebAssembly.Global({ value: ${JSON.stringify(
@@ -154,7 +157,7 @@ class WebAssemblyJavascriptGenerator extends Generator {
154
157
  const importsCode = Template.asString(
155
158
  Array.from(
156
159
  importedModules,
157
- ([module, { importVar, request, reexports }]) => {
160
+ ([module, { importVar, request, reexports, dependency }]) => {
158
161
  const importStatement = runtimeTemplate.importStatement({
159
162
  module,
160
163
  moduleGraph,
@@ -162,7 +165,8 @@ class WebAssemblyJavascriptGenerator extends Generator {
162
165
  request,
163
166
  importVar,
164
167
  originModule: module,
165
- runtimeRequirements
168
+ runtimeRequirements,
169
+ dependency
166
170
  });
167
171
  return importStatement[0] + importStatement[1] + reexports.join("\n");
168
172
  }
@@ -17,8 +17,6 @@ const WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRunt
17
17
  * @property {boolean=} mangleImports mangle imports
18
18
  */
19
19
 
20
- // TODO webpack 6 remove
21
-
22
20
  const PLUGIN_NAME = "FetchCompileWasmPlugin";
23
21
 
24
22
  class FetchCompileWasmPlugin {
package/lib/webpack.js CHANGED
@@ -106,107 +106,110 @@ const createCompiler = (rawOptions, compilerIndex) => {
106
106
  };
107
107
 
108
108
  /**
109
- * @callback WebpackFunctionSingle
109
+ * @template T
110
+ * @param {T[] | T} options options
111
+ * @returns {T[]} array of options
112
+ */
113
+ const asArray = (options) =>
114
+ Array.isArray(options) ? [...options] : [options];
115
+
116
+ /**
117
+ * @overload
110
118
  * @param {WebpackOptions} options options object
111
- * @param {Callback<Stats>=} callback callback
119
+ * @param {Callback<Stats>} callback callback
112
120
  * @returns {Compiler | null} the compiler object
113
121
  */
114
-
115
122
  /**
116
- * @callback WebpackFunctionMulti
123
+ * @overload
124
+ * @param {WebpackOptions} options options object
125
+ * @returns {Compiler} the compiler object
126
+ */
127
+ /**
128
+ * @overload
117
129
  * @param {MultiWebpackOptions} options options objects
118
- * @param {Callback<MultiStats>=} callback callback
130
+ * @param {Callback<MultiStats>} callback callback
119
131
  * @returns {MultiCompiler | null} the multi compiler object
120
132
  */
121
-
122
133
  /**
123
- * @template T
124
- * @param {T[] | T} options options
125
- * @returns {T[]} array of options
134
+ * @overload
135
+ * @param {MultiWebpackOptions} options options objects
136
+ * @returns {MultiCompiler} the multi compiler object
126
137
  */
127
- const asArray = (options) =>
128
- Array.isArray(options) ? [...options] : [options];
129
-
130
138
  /**
131
- * @callback WebpackCallback
132
139
  * @param {WebpackOptions | MultiWebpackOptions} options options
133
140
  * @param {Callback<Stats> & Callback<MultiStats>=} callback callback
134
141
  * @returns {Compiler | MultiCompiler | null} Compiler or MultiCompiler
135
142
  */
136
-
137
- const webpack = /** @type {WebpackFunctionSingle & WebpackFunctionMulti} */ (
138
- /** @type {WebpackCallback} */
139
- (options, callback) => {
140
- const create = () => {
141
- if (
142
- !asArray(/** @type {WebpackOptions} */ (options)).every(
143
- webpackOptionsSchemaCheck
144
- )
145
- ) {
146
- getValidateSchema()(webpackOptionsSchema, options);
147
- util.deprecate(
148
- () => {},
149
- "webpack bug: Pre-compiled schema reports error while real schema is happy. This has performance drawbacks.",
150
- "DEP_WEBPACK_PRE_COMPILED_SCHEMA_INVALID"
151
- )();
152
- }
153
- /** @type {MultiCompiler|Compiler} */
154
- let compiler;
155
- /** @type {boolean | undefined} */
156
- let watch = false;
157
- /** @type {WatchOptions | WatchOptions[]} */
158
- let watchOptions;
159
- if (Array.isArray(options)) {
160
- /** @type {MultiCompiler} */
161
- compiler = createMultiCompiler(
162
- options,
163
- /** @type {MultiCompilerOptions} */
164
- (options)
165
- );
166
- watch = options.some((options) => options.watch);
167
- watchOptions = options.map((options) => options.watchOptions || {});
168
- } else {
169
- const webpackOptions = /** @type {WebpackOptions} */ (options);
170
- /** @type {Compiler} */
171
- compiler = createCompiler(webpackOptions);
172
- watch = webpackOptions.watch;
173
- watchOptions = webpackOptions.watchOptions || {};
174
- }
175
- return { compiler, watch, watchOptions };
176
- };
177
- if (callback) {
178
- try {
179
- const { compiler, watch, watchOptions } = create();
180
- if (watch) {
181
- compiler.watch(watchOptions, callback);
182
- } else {
183
- compiler.run((err, stats) => {
184
- compiler.close((err2) => {
185
- callback(
186
- err || err2,
187
- /** @type {options extends WebpackOptions ? Stats : MultiStats} */
188
- (stats)
189
- );
190
- });
191
- });
192
- }
193
- return compiler;
194
- } catch (err) {
195
- process.nextTick(() => callback(/** @type {Error} */ (err)));
196
- return null;
197
- }
143
+ const webpack = (options, callback) => {
144
+ const create = () => {
145
+ if (
146
+ !asArray(/** @type {WebpackOptions} */ (options)).every(
147
+ webpackOptionsSchemaCheck
148
+ )
149
+ ) {
150
+ getValidateSchema()(webpackOptionsSchema, options);
151
+ util.deprecate(
152
+ () => {},
153
+ "webpack bug: Pre-compiled schema reports error while real schema is happy. This has performance drawbacks.",
154
+ "DEP_WEBPACK_PRE_COMPILED_SCHEMA_INVALID"
155
+ )();
156
+ }
157
+ /** @type {MultiCompiler|Compiler} */
158
+ let compiler;
159
+ /** @type {boolean | undefined} */
160
+ let watch = false;
161
+ /** @type {WatchOptions | WatchOptions[]} */
162
+ let watchOptions;
163
+ if (Array.isArray(options)) {
164
+ /** @type {MultiCompiler} */
165
+ compiler = createMultiCompiler(
166
+ options,
167
+ /** @type {MultiCompilerOptions} */
168
+ (options)
169
+ );
170
+ watch = options.some((options) => options.watch);
171
+ watchOptions = options.map((options) => options.watchOptions || {});
198
172
  } else {
199
- const { compiler, watch } = create();
173
+ const webpackOptions = /** @type {WebpackOptions} */ (options);
174
+ /** @type {Compiler} */
175
+ compiler = createCompiler(webpackOptions);
176
+ watch = webpackOptions.watch;
177
+ watchOptions = webpackOptions.watchOptions || {};
178
+ }
179
+ return { compiler, watch, watchOptions };
180
+ };
181
+ if (callback) {
182
+ try {
183
+ const { compiler, watch, watchOptions } = create();
200
184
  if (watch) {
201
- util.deprecate(
202
- () => {},
203
- "A 'callback' argument needs to be provided to the 'webpack(options, callback)' function when the 'watch' option is set. There is no way to handle the 'watch' option without a callback.",
204
- "DEP_WEBPACK_WATCH_WITHOUT_CALLBACK"
205
- )();
185
+ compiler.watch(watchOptions, callback);
186
+ } else {
187
+ compiler.run((err, stats) => {
188
+ compiler.close((err2) => {
189
+ callback(
190
+ err || err2,
191
+ /** @type {options extends WebpackOptions ? Stats : MultiStats} */
192
+ (stats)
193
+ );
194
+ });
195
+ });
206
196
  }
207
197
  return compiler;
198
+ } catch (err) {
199
+ process.nextTick(() => callback(/** @type {Error} */ (err)));
200
+ return null;
208
201
  }
202
+ } else {
203
+ const { compiler, watch } = create();
204
+ if (watch) {
205
+ util.deprecate(
206
+ () => {},
207
+ "A 'callback' argument needs to be provided to the 'webpack(options, callback)' function when the 'watch' option is set. There is no way to handle the 'watch' option without a callback.",
208
+ "DEP_WEBPACK_WATCH_WITHOUT_CALLBACK"
209
+ )();
210
+ }
211
+ return compiler;
209
212
  }
210
- );
213
+ };
211
214
 
212
215
  module.exports = webpack;
package/module.d.ts CHANGED
@@ -161,10 +161,15 @@ declare namespace webpack {
161
161
  }
162
162
  }
163
163
 
164
+ interface ImportMetaEnv {
165
+ [key: string]: string | boolean | undefined;
166
+ }
167
+
164
168
  interface ImportMeta {
165
169
  url: string;
166
170
  webpack: number;
167
171
  webpackHot: webpack.Hot;
172
+ env: ImportMetaEnv;
168
173
  webpackContext: (
169
174
  request: string,
170
175
  options?: {