webpack 5.99.5 → 5.99.7

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 (169) hide show
  1. package/README.md +1 -1
  2. package/lib/APIPlugin.js +2 -2
  3. package/lib/AutomaticPrefetchPlugin.js +21 -22
  4. package/lib/BannerPlugin.js +31 -35
  5. package/lib/Cache.js +1 -1
  6. package/lib/Chunk.js +12 -9
  7. package/lib/CleanPlugin.js +5 -3
  8. package/lib/Compilation.js +45 -35
  9. package/lib/Compiler.js +6 -4
  10. package/lib/ContextExclusionPlugin.js +4 -2
  11. package/lib/ContextModule.js +2 -1
  12. package/lib/ContextReplacementPlugin.js +5 -3
  13. package/lib/DelegatedPlugin.js +4 -2
  14. package/lib/DllEntryPlugin.js +4 -2
  15. package/lib/DllPlugin.js +5 -3
  16. package/lib/DllReferencePlugin.js +56 -60
  17. package/lib/DynamicEntryPlugin.js +4 -2
  18. package/lib/EntryOptionPlugin.js +3 -1
  19. package/lib/EntryPlugin.js +4 -2
  20. package/lib/EnvironmentPlugin.js +4 -2
  21. package/lib/EvalDevToolModulePlugin.js +9 -7
  22. package/lib/EvalSourceMapDevToolPlugin.js +137 -138
  23. package/lib/ExternalsPlugin.js +3 -1
  24. package/lib/FlagDependencyExportsPlugin.js +2 -1
  25. package/lib/HotModuleReplacementPlugin.js +3 -3
  26. package/lib/IgnorePlugin.js +6 -4
  27. package/lib/IgnoreWarningsPlugin.js +4 -2
  28. package/lib/LibManifestPlugin.js +3 -4
  29. package/lib/LoaderOptionsPlugin.js +4 -2
  30. package/lib/LoaderTargetPlugin.js +4 -2
  31. package/lib/Module.js +29 -14
  32. package/lib/ModuleFilenameHelpers.js +1 -1
  33. package/lib/ModuleGraph.js +15 -10
  34. package/lib/ModuleInfoHeaderPlugin.js +11 -12
  35. package/lib/MultiCompiler.js +5 -3
  36. package/lib/NoEmitOnErrorsPlugin.js +5 -3
  37. package/lib/NormalModule.js +6 -2
  38. package/lib/NormalModuleReplacementPlugin.js +33 -36
  39. package/lib/PlatformPlugin.js +3 -1
  40. package/lib/PrefetchPlugin.js +5 -3
  41. package/lib/ProgressPlugin.js +23 -26
  42. package/lib/RecordIdsPlugin.js +73 -103
  43. package/lib/RuntimePlugin.js +34 -32
  44. package/lib/SourceMapDevToolPlugin.js +8 -6
  45. package/lib/Template.js +1 -1
  46. package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
  47. package/lib/WarnNoModeSetPlugin.js +3 -1
  48. package/lib/WatchIgnorePlugin.js +3 -1
  49. package/lib/WebpackError.js +11 -3
  50. package/lib/WebpackOptionsApply.js +22 -5
  51. package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
  52. package/lib/buildChunkGraph.js +7 -2
  53. package/lib/cache/IdleFileCachePlugin.js +12 -13
  54. package/lib/cache/MemoryCachePlugin.js +2 -1
  55. package/lib/cache/MemoryWithGcCachePlugin.js +10 -7
  56. package/lib/cache/PackFileCacheStrategy.js +13 -21
  57. package/lib/cache/ResolverCachePlugin.js +22 -22
  58. package/lib/cli.js +8 -4
  59. package/lib/config/defaults.js +2 -2
  60. package/lib/config/normalization.js +9 -3
  61. package/lib/config/target.js +6 -6
  62. package/lib/container/ContainerReferencePlugin.js +24 -26
  63. package/lib/container/ModuleFederationPlugin.js +2 -1
  64. package/lib/css/CssGenerator.js +1 -1
  65. package/lib/css/CssModulesPlugin.js +6 -4
  66. package/lib/css/CssParser.js +1 -1
  67. package/lib/debug/ProfilingPlugin.js +1 -1
  68. package/lib/dependencies/ContextDependencyHelpers.js +1 -1
  69. package/lib/dependencies/CssIcssImportDependency.js +3 -2
  70. package/lib/dependencies/HarmonyDetectionParserPlugin.js +9 -15
  71. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  72. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
  73. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -1
  74. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
  75. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
  76. package/lib/dependencies/JsonExportsDependency.js +1 -1
  77. package/lib/dependencies/LoaderPlugin.js +5 -3
  78. package/lib/dependencies/LocalModulesHelpers.js +1 -1
  79. package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
  80. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
  81. package/lib/dependencies/RequireResolveDependency.js +1 -1
  82. package/lib/dependencies/WorkerPlugin.js +2 -2
  83. package/lib/esm/ModuleChunkLoadingPlugin.js +76 -57
  84. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +11 -9
  85. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  86. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -1
  87. package/lib/hmr/LazyCompilationPlugin.js +17 -18
  88. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
  89. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  90. package/lib/ids/DeterministicModuleIdsPlugin.js +48 -49
  91. package/lib/ids/HashedModuleIdsPlugin.js +4 -2
  92. package/lib/ids/NamedChunkIdsPlugin.js +6 -4
  93. package/lib/ids/NamedModuleIdsPlugin.js +6 -4
  94. package/lib/ids/NaturalChunkIdsPlugin.js +4 -2
  95. package/lib/ids/NaturalModuleIdsPlugin.js +4 -2
  96. package/lib/ids/OccurrenceChunkIdsPlugin.js +4 -2
  97. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -2
  98. package/lib/index.js +1 -1
  99. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  100. package/lib/javascript/JavascriptParser.js +670 -688
  101. package/lib/library/EnableLibraryPlugin.js +15 -2
  102. package/lib/library/ModuleLibraryPlugin.js +66 -43
  103. package/lib/logging/createConsoleLogger.js +0 -1
  104. package/lib/node/CommonJsChunkLoadingPlugin.js +71 -75
  105. package/lib/node/NodeEnvironmentPlugin.js +3 -1
  106. package/lib/node/NodeTemplatePlugin.js +2 -2
  107. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
  108. package/lib/node/ReadFileCompileWasmPlugin.js +3 -3
  109. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  110. package/lib/optimize/AggressiveSplittingPlugin.js +224 -232
  111. package/lib/optimize/ConcatenatedModule.js +12 -15
  112. package/lib/optimize/FlagIncludedChunksPlugin.js +92 -97
  113. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  114. package/lib/optimize/MangleExportsPlugin.js +15 -16
  115. package/lib/optimize/MinChunkSizePlugin.js +4 -2
  116. package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
  117. package/lib/optimize/RealContentHashPlugin.js +4 -2
  118. package/lib/optimize/RemoveEmptyChunksPlugin.js +5 -3
  119. package/lib/optimize/RemoveParentModulesPlugin.js +4 -2
  120. package/lib/optimize/RuntimeChunkPlugin.js +17 -18
  121. package/lib/optimize/SplitChunksPlugin.js +9 -6
  122. package/lib/performance/SizeLimitsPlugin.js +3 -1
  123. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
  124. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
  125. package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
  126. package/lib/schemes/DataUriPlugin.js +5 -3
  127. package/lib/schemes/FileUriPlugin.js +5 -3
  128. package/lib/schemes/HttpUriPlugin.js +32 -39
  129. package/lib/serialization/AggregateErrorSerializer.js +42 -0
  130. package/lib/serialization/BinaryMiddleware.js +22 -38
  131. package/lib/serialization/ErrorObjectSerializer.js +7 -2
  132. package/lib/serialization/FileMiddleware.js +29 -33
  133. package/lib/serialization/ObjectMiddleware.js +42 -30
  134. package/lib/serialization/Serializer.js +29 -18
  135. package/lib/serialization/SerializerMiddleware.js +105 -72
  136. package/lib/serialization/SingleItemMiddleware.js +4 -5
  137. package/lib/sharing/ProvideSharedPlugin.js +6 -4
  138. package/lib/stats/DefaultStatsFactoryPlugin.js +128 -57
  139. package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
  140. package/lib/stats/DefaultStatsPrinterPlugin.js +486 -334
  141. package/lib/stats/StatsFactory.js +47 -10
  142. package/lib/stats/StatsPrinter.js +52 -31
  143. package/lib/util/ArrayQueue.js +1 -1
  144. package/lib/util/AsyncQueue.js +1 -1
  145. package/lib/util/TupleQueue.js +9 -7
  146. package/lib/util/TupleSet.js +37 -18
  147. package/lib/util/WeakTupleMap.js +50 -37
  148. package/lib/util/cleverMerge.js +2 -2
  149. package/lib/util/comparators.js +1 -1
  150. package/lib/util/concatenate.js +4 -2
  151. package/lib/util/createHash.js +1 -1
  152. package/lib/util/fs.js +1 -1
  153. package/lib/util/makeSerializable.js +1 -1
  154. package/lib/util/runtime.js +1 -0
  155. package/lib/util/serialization.js +50 -42
  156. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  157. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -1
  158. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  159. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
  160. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -1
  161. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  162. package/lib/web/FetchCompileWasmPlugin.js +2 -2
  163. package/lib/web/JsonpChunkLoadingPlugin.js +73 -74
  164. package/lib/webpack.js +1 -1
  165. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
  166. package/package.json +4 -3
  167. package/schemas/WebpackOptions.check.js +1 -1
  168. package/schemas/WebpackOptions.json +24 -2
  169. package/types.d.ts +273 -128
@@ -12,6 +12,11 @@
12
12
  /** @type {WeakMap<Compiler, Set<LibraryType>>} */
13
13
  const enabledTypes = new WeakMap();
14
14
 
15
+ /**
16
+ * @typedef {object} EnableLibraryPluginOptions
17
+ * @property {() => void=} additionalApply function that runs when applying the current plugin.
18
+ */
19
+
15
20
  /**
16
21
  * @param {Compiler} compiler the compiler instance
17
22
  * @returns {Set<LibraryType>} enabled types
@@ -28,9 +33,13 @@ const getEnabledTypes = compiler => {
28
33
  class EnableLibraryPlugin {
29
34
  /**
30
35
  * @param {LibraryType} type library type that should be available
36
+ * @param {EnableLibraryPluginOptions} options options of EnableLibraryPlugin
31
37
  */
32
- constructor(type) {
38
+ constructor(type, options = {}) {
39
+ /** @type {LibraryType} */
33
40
  this.type = type;
41
+ /** @type {EnableLibraryPluginOptions} */
42
+ this.options = options;
34
43
  }
35
44
 
36
45
  /**
@@ -67,13 +76,17 @@ class EnableLibraryPlugin {
67
76
  * @returns {void}
68
77
  */
69
78
  apply(compiler) {
70
- const { type } = this;
79
+ const { type, options } = this;
71
80
 
72
81
  // Only enable once
73
82
  const enabled = getEnabledTypes(compiler);
74
83
  if (enabled.has(type)) return;
75
84
  enabled.add(type);
76
85
 
86
+ if (typeof options.additionalApply === "function") {
87
+ options.additionalApply();
88
+ }
89
+
77
90
  if (typeof type === "string") {
78
91
  const enableExportProperty = () => {
79
92
  const ExportPropertyTemplatePlugin = require("./ExportPropertyLibraryPlugin");
@@ -39,6 +39,8 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
39
39
  * @property {string | string[]=} export
40
40
  */
41
41
 
42
+ const PLUGIN_NAME = "ModuleLibraryPlugin";
43
+
42
44
  /**
43
45
  * @typedef {ModuleLibraryPluginParsed} T
44
46
  * @extends {AbstractLibraryPlugin<ModuleLibraryPluginParsed>}
@@ -62,34 +64,31 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
62
64
  apply(compiler) {
63
65
  super.apply(compiler);
64
66
 
65
- compiler.hooks.compilation.tap("ModernModuleLibraryPlugin", compilation => {
67
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
66
68
  const { exportsDefinitions } =
67
69
  ConcatenatedModule.getCompilationHooks(compilation);
68
- exportsDefinitions.tap(
69
- "ModernModuleLibraryPlugin",
70
- (definitions, module) => {
71
- // If we have connections not all modules were concatenated, so we need the wrapper
72
- const connections =
73
- compilation.moduleGraph.getIncomingConnections(module);
74
-
75
- for (const connection of connections) {
76
- if (connection.originModule) {
77
- return false;
78
- }
70
+ exportsDefinitions.tap(PLUGIN_NAME, (definitions, module) => {
71
+ // If we have connections not all modules were concatenated, so we need the wrapper
72
+ const connections =
73
+ compilation.moduleGraph.getIncomingConnections(module);
74
+
75
+ for (const connection of connections) {
76
+ if (connection.originModule) {
77
+ return false;
79
78
  }
79
+ }
80
80
 
81
- // Runtime and splitting chunks now requires the wrapper too
82
- for (const chunk of compilation.chunkGraph.getModuleChunksIterable(
83
- module
84
- )) {
85
- if (!chunk.hasRuntime()) {
86
- return false;
87
- }
81
+ // Runtime and splitting chunks now requires the wrapper too
82
+ for (const chunk of compilation.chunkGraph.getModuleChunksIterable(
83
+ module
84
+ )) {
85
+ if (!chunk.hasRuntime()) {
86
+ return false;
88
87
  }
89
-
90
- return true;
91
88
  }
92
- );
89
+
90
+ return true;
91
+ });
93
92
  });
94
93
  }
95
94
 
@@ -121,11 +120,11 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
121
120
  renderStartup(
122
121
  source,
123
122
  module,
124
- { moduleGraph, chunk },
123
+ { moduleGraph, chunk, codeGenerationResults },
125
124
  { options, compilation }
126
125
  ) {
127
126
  const result = new ConcatSource(source);
128
- const exportsInfos = options.export
127
+ const exportsInfo = options.export
129
128
  ? [
130
129
  moduleGraph.getExportInfo(
131
130
  module,
@@ -136,7 +135,9 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
136
135
  const definitions =
137
136
  /** @type {BuildMeta} */
138
137
  (module.buildMeta).exportsFinalName || {};
138
+ /** @type {string[]} */
139
139
  const shortHandedExports = [];
140
+ /** @type {[string, string][]} */
140
141
  const exports = [];
141
142
  const isAsync = moduleGraph.isAsync(module);
142
143
 
@@ -146,7 +147,11 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
146
147
  );
147
148
  }
148
149
 
149
- for (const exportInfo of exportsInfos) {
150
+ const varType = compilation.outputOptions.environment.const
151
+ ? "const"
152
+ : "var";
153
+
154
+ for (const exportInfo of exportsInfo) {
150
155
  if (!exportInfo.provided) continue;
151
156
 
152
157
  let shouldContinue = false;
@@ -159,6 +164,7 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
159
164
  for (const reexportInfo of exp.orderedExports) {
160
165
  if (
161
166
  reexportInfo.provided === false &&
167
+ reexportInfo.name !== "default" &&
162
168
  reexportInfo.name === /** @type {string[]} */ (reexport.export)[0]
163
169
  ) {
164
170
  shouldContinue = true;
@@ -168,32 +174,51 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
168
174
 
169
175
  if (shouldContinue) continue;
170
176
 
171
- const webpackExportsProperty = exportInfo.getUsedName(
172
- exportInfo.name,
173
- chunk.runtime
174
- );
175
- const definition =
176
- definitions[/** @type {string} */ (webpackExportsProperty)];
177
+ const originalName = exportInfo.name;
178
+ const usedName =
179
+ /** @type {string} */
180
+ (exportInfo.getUsedName(originalName, chunk.runtime));
181
+ /** @type {string | undefined} */
182
+ const definition = definitions[usedName];
177
183
  const finalName =
178
184
  definition ||
179
- `${RuntimeGlobals.exports}${Template.toIdentifier(exportInfo.name)}`;
185
+ `${RuntimeGlobals.exports}${Template.toIdentifier(originalName)}`;
180
186
 
181
187
  if (!definition) {
182
188
  result.add(
183
- `var ${finalName} = ${RuntimeGlobals.exports}${propertyAccess([
184
- /** @type {string} */
185
- (exportInfo.getUsedName(exportInfo.name, chunk.runtime))
186
- ])}\n`
189
+ `${varType} ${finalName} = ${RuntimeGlobals.exports}${propertyAccess([
190
+ usedName
191
+ ])};\n`
187
192
  );
188
193
  }
189
194
 
190
- if (finalName && (finalName.includes(".") || finalName.includes("["))) {
191
- exports.push([exportInfo.name, finalName]);
195
+ if (
196
+ finalName &&
197
+ (finalName.includes(".") ||
198
+ finalName.includes("[") ||
199
+ finalName.includes("("))
200
+ ) {
201
+ if (exportInfo.isReexport()) {
202
+ const { data } = codeGenerationResults.get(module, chunk.runtime);
203
+ const topLevelDeclarations =
204
+ (data && data.get("topLevelDeclarations")) ||
205
+ (module.buildInfo && module.buildInfo.topLevelDeclarations);
206
+
207
+ if (topLevelDeclarations && topLevelDeclarations.has(originalName)) {
208
+ const name = `${RuntimeGlobals.exports}${Template.toIdentifier(originalName)}`;
209
+ result.add(`${varType} ${name} = ${finalName};\n`);
210
+ shortHandedExports.push(`${name} as ${originalName}`);
211
+ } else {
212
+ exports.push([originalName, finalName]);
213
+ }
214
+ } else {
215
+ exports.push([originalName, finalName]);
216
+ }
192
217
  } else {
193
218
  shortHandedExports.push(
194
- definition && finalName === exportInfo.name
219
+ definition && finalName === originalName
195
220
  ? finalName
196
- : `${finalName} as ${exportInfo.name}`
221
+ : `${finalName} as ${originalName}`
197
222
  );
198
223
  }
199
224
  }
@@ -203,9 +228,7 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
203
228
  }
204
229
 
205
230
  for (const [exportName, final] of exports) {
206
- result.add(
207
- `export ${compilation.outputOptions.environment.const ? "const" : "var"} ${exportName} = ${final};\n`
208
- );
231
+ result.add(`export ${varType} ${exportName} = ${final};\n`);
209
232
  }
210
233
 
211
234
  return result;
@@ -89,7 +89,6 @@ module.exports = ({ level = "info", debug = false, console }) => {
89
89
  .concat(debug)
90
90
  .map(filterToFunction)
91
91
  );
92
- /** @type {number} */
93
92
  const loglevel = LogLevel[`${level}`] || 0;
94
93
 
95
94
  /**
@@ -13,12 +13,14 @@ const StartupChunkDependenciesPlugin = require("../runtime/StartupChunkDependenc
13
13
 
14
14
  /**
15
15
  * @typedef {object} CommonJsChunkLoadingPluginOptions
16
- * @property {boolean} [asyncChunkLoading] enable async chunk loading
16
+ * @property {boolean=} asyncChunkLoading enable async chunk loading
17
17
  */
18
18
 
19
+ const PLUGIN_NAME = "CommonJsChunkLoadingPlugin";
20
+
19
21
  class CommonJsChunkLoadingPlugin {
20
22
  /**
21
- * @param {CommonJsChunkLoadingPluginOptions} [options] options
23
+ * @param {CommonJsChunkLoadingPluginOptions=} options options
22
24
  */
23
25
  constructor(options = {}) {
24
26
  this._asyncChunkLoading = options.asyncChunkLoading;
@@ -40,81 +42,75 @@ class CommonJsChunkLoadingPlugin {
40
42
  chunkLoading: chunkLoadingValue,
41
43
  asyncChunkLoading: this._asyncChunkLoading
42
44
  }).apply(compiler);
43
- compiler.hooks.thisCompilation.tap(
44
- "CommonJsChunkLoadingPlugin",
45
- compilation => {
46
- const globalChunkLoading = compilation.outputOptions.chunkLoading;
47
- /**
48
- * @param {Chunk} chunk chunk
49
- * @returns {boolean} true, if wasm loading is enabled for the chunk
50
- */
51
- const isEnabledForChunk = chunk => {
52
- const options = chunk.getEntryOptions();
53
- const chunkLoading =
54
- options && options.chunkLoading !== undefined
55
- ? options.chunkLoading
56
- : globalChunkLoading;
57
- return chunkLoading === chunkLoadingValue;
58
- };
59
- const onceForChunkSet = new WeakSet();
60
- /**
61
- * @param {Chunk} chunk chunk
62
- * @param {Set<string>} set runtime requirements
63
- */
64
- const handler = (chunk, set) => {
65
- if (onceForChunkSet.has(chunk)) return;
66
- onceForChunkSet.add(chunk);
67
- if (!isEnabledForChunk(chunk)) return;
68
- set.add(RuntimeGlobals.moduleFactoriesAddOnly);
69
- set.add(RuntimeGlobals.hasOwnProperty);
70
- compilation.addRuntimeModule(
71
- chunk,
72
- new ChunkLoadingRuntimeModule(set)
73
- );
74
- };
45
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
46
+ const globalChunkLoading = compilation.outputOptions.chunkLoading;
47
+ /**
48
+ * @param {Chunk} chunk chunk
49
+ * @returns {boolean} true, if wasm loading is enabled for the chunk
50
+ */
51
+ const isEnabledForChunk = chunk => {
52
+ const options = chunk.getEntryOptions();
53
+ const chunkLoading =
54
+ options && options.chunkLoading !== undefined
55
+ ? options.chunkLoading
56
+ : globalChunkLoading;
57
+ return chunkLoading === chunkLoadingValue;
58
+ };
59
+ const onceForChunkSet = new WeakSet();
60
+ /**
61
+ * @param {Chunk} chunk chunk
62
+ * @param {Set<string>} set runtime requirements
63
+ */
64
+ const handler = (chunk, set) => {
65
+ if (onceForChunkSet.has(chunk)) return;
66
+ onceForChunkSet.add(chunk);
67
+ if (!isEnabledForChunk(chunk)) return;
68
+ set.add(RuntimeGlobals.moduleFactoriesAddOnly);
69
+ set.add(RuntimeGlobals.hasOwnProperty);
70
+ compilation.addRuntimeModule(chunk, new ChunkLoadingRuntimeModule(set));
71
+ };
75
72
 
76
- compilation.hooks.runtimeRequirementInTree
77
- .for(RuntimeGlobals.ensureChunkHandlers)
78
- .tap("CommonJsChunkLoadingPlugin", handler);
79
- compilation.hooks.runtimeRequirementInTree
80
- .for(RuntimeGlobals.hmrDownloadUpdateHandlers)
81
- .tap("CommonJsChunkLoadingPlugin", handler);
82
- compilation.hooks.runtimeRequirementInTree
83
- .for(RuntimeGlobals.hmrDownloadManifest)
84
- .tap("CommonJsChunkLoadingPlugin", handler);
85
- compilation.hooks.runtimeRequirementInTree
86
- .for(RuntimeGlobals.baseURI)
87
- .tap("CommonJsChunkLoadingPlugin", handler);
88
- compilation.hooks.runtimeRequirementInTree
89
- .for(RuntimeGlobals.externalInstallChunk)
90
- .tap("CommonJsChunkLoadingPlugin", handler);
91
- compilation.hooks.runtimeRequirementInTree
92
- .for(RuntimeGlobals.onChunksLoaded)
93
- .tap("CommonJsChunkLoadingPlugin", handler);
73
+ compilation.hooks.runtimeRequirementInTree
74
+ .for(RuntimeGlobals.ensureChunkHandlers)
75
+ .tap(PLUGIN_NAME, handler);
76
+ compilation.hooks.runtimeRequirementInTree
77
+ .for(RuntimeGlobals.hmrDownloadUpdateHandlers)
78
+ .tap(PLUGIN_NAME, handler);
79
+ compilation.hooks.runtimeRequirementInTree
80
+ .for(RuntimeGlobals.hmrDownloadManifest)
81
+ .tap(PLUGIN_NAME, handler);
82
+ compilation.hooks.runtimeRequirementInTree
83
+ .for(RuntimeGlobals.baseURI)
84
+ .tap(PLUGIN_NAME, handler);
85
+ compilation.hooks.runtimeRequirementInTree
86
+ .for(RuntimeGlobals.externalInstallChunk)
87
+ .tap(PLUGIN_NAME, handler);
88
+ compilation.hooks.runtimeRequirementInTree
89
+ .for(RuntimeGlobals.onChunksLoaded)
90
+ .tap(PLUGIN_NAME, handler);
94
91
 
95
- compilation.hooks.runtimeRequirementInTree
96
- .for(RuntimeGlobals.ensureChunkHandlers)
97
- .tap("CommonJsChunkLoadingPlugin", (chunk, set) => {
98
- if (!isEnabledForChunk(chunk)) return;
99
- set.add(RuntimeGlobals.getChunkScriptFilename);
100
- });
101
- compilation.hooks.runtimeRequirementInTree
102
- .for(RuntimeGlobals.hmrDownloadUpdateHandlers)
103
- .tap("CommonJsChunkLoadingPlugin", (chunk, set) => {
104
- if (!isEnabledForChunk(chunk)) return;
105
- set.add(RuntimeGlobals.getChunkUpdateScriptFilename);
106
- set.add(RuntimeGlobals.moduleCache);
107
- set.add(RuntimeGlobals.hmrModuleData);
108
- set.add(RuntimeGlobals.moduleFactoriesAddOnly);
109
- });
110
- compilation.hooks.runtimeRequirementInTree
111
- .for(RuntimeGlobals.hmrDownloadManifest)
112
- .tap("CommonJsChunkLoadingPlugin", (chunk, set) => {
113
- if (!isEnabledForChunk(chunk)) return;
114
- set.add(RuntimeGlobals.getUpdateManifestFilename);
115
- });
116
- }
117
- );
92
+ compilation.hooks.runtimeRequirementInTree
93
+ .for(RuntimeGlobals.ensureChunkHandlers)
94
+ .tap(PLUGIN_NAME, (chunk, set) => {
95
+ if (!isEnabledForChunk(chunk)) return;
96
+ set.add(RuntimeGlobals.getChunkScriptFilename);
97
+ });
98
+ compilation.hooks.runtimeRequirementInTree
99
+ .for(RuntimeGlobals.hmrDownloadUpdateHandlers)
100
+ .tap(PLUGIN_NAME, (chunk, set) => {
101
+ if (!isEnabledForChunk(chunk)) return;
102
+ set.add(RuntimeGlobals.getChunkUpdateScriptFilename);
103
+ set.add(RuntimeGlobals.moduleCache);
104
+ set.add(RuntimeGlobals.hmrModuleData);
105
+ set.add(RuntimeGlobals.moduleFactoriesAddOnly);
106
+ });
107
+ compilation.hooks.runtimeRequirementInTree
108
+ .for(RuntimeGlobals.hmrDownloadManifest)
109
+ .tap(PLUGIN_NAME, (chunk, set) => {
110
+ if (!isEnabledForChunk(chunk)) return;
111
+ set.add(RuntimeGlobals.getUpdateManifestFilename);
112
+ });
113
+ });
118
114
  }
119
115
  }
120
116
 
@@ -20,6 +20,8 @@ const nodeConsole = require("./nodeConsole");
20
20
  * @property {InfrastructureLogging} infrastructureLogging infrastructure logging options
21
21
  */
22
22
 
23
+ const PLUGIN_NAME = "NodeEnvironmentPlugin";
24
+
23
25
  class NodeEnvironmentPlugin {
24
26
  /**
25
27
  * @param {NodeEnvironmentPluginOptions} options options
@@ -55,7 +57,7 @@ class NodeEnvironmentPlugin {
55
57
  compiler.outputFileSystem = fs;
56
58
  compiler.intermediateFileSystem = fs;
57
59
  compiler.watchFileSystem = new NodeWatchFileSystem(inputFileSystem);
58
- compiler.hooks.beforeRun.tap("NodeEnvironmentPlugin", compiler => {
60
+ compiler.hooks.beforeRun.tap(PLUGIN_NAME, compiler => {
59
61
  if (
60
62
  compiler.inputFileSystem === inputFileSystem &&
61
63
  inputFileSystem.purge
@@ -12,12 +12,12 @@ const EnableChunkLoadingPlugin = require("../javascript/EnableChunkLoadingPlugin
12
12
 
13
13
  /**
14
14
  * @typedef {object} NodeTemplatePluginOptions
15
- * @property {boolean} [asyncChunkLoading] enable async chunk loading
15
+ * @property {boolean=} asyncChunkLoading enable async chunk loading
16
16
  */
17
17
 
18
18
  class NodeTemplatePlugin {
19
19
  /**
20
- * @param {NodeTemplatePluginOptions} [options] options object
20
+ * @param {NodeTemplatePluginOptions=} options options object
21
21
  */
22
22
  constructor(options = {}) {
23
23
  this._options = options;
@@ -15,14 +15,14 @@ const AsyncWasmLoadingRuntimeModule = require("../wasm-async/AsyncWasmLoadingRun
15
15
 
16
16
  /**
17
17
  * @typedef {object} ReadFileCompileAsyncWasmPluginOptions
18
- * @property {boolean} [import] use import?
18
+ * @property {boolean=} import use import?
19
19
  */
20
20
 
21
21
  const PLUGIN_NAME = "ReadFileCompileAsyncWasmPlugin";
22
22
 
23
23
  class ReadFileCompileAsyncWasmPlugin {
24
24
  /**
25
- * @param {ReadFileCompileAsyncWasmPluginOptions} [options] options object
25
+ * @param {ReadFileCompileAsyncWasmPluginOptions=} options options object
26
26
  */
27
27
  constructor({ import: useImport = false } = {}) {
28
28
  this._import = useImport;
@@ -15,8 +15,8 @@ const WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRunt
15
15
 
16
16
  /**
17
17
  * @typedef {object} ReadFileCompileWasmPluginOptions
18
- * @property {boolean} [mangleImports] mangle imports
19
- * @property {boolean} [import] use import?
18
+ * @property {boolean=} mangleImports mangle imports
19
+ * @property {boolean=} import use import?
20
20
  */
21
21
 
22
22
  // TODO webpack 6 remove
@@ -25,7 +25,7 @@ const PLUGIN_NAME = "ReadFileCompileWasmPlugin";
25
25
 
26
26
  class ReadFileCompileWasmPlugin {
27
27
  /**
28
- * @param {ReadFileCompileWasmPluginOptions} [options] options object
28
+ * @param {ReadFileCompileWasmPluginOptions=} options options object
29
29
  */
30
30
  constructor(options = {}) {
31
31
  this.options = options;
@@ -17,7 +17,7 @@ const { STAGE_ADVANCED } = require("../OptimizationStages");
17
17
 
18
18
  class AggressiveMergingPlugin {
19
19
  /**
20
- * @param {AggressiveMergingPluginOptions=} [options] options object
20
+ * @param {AggressiveMergingPluginOptions=} options options object
21
21
  */
22
22
  constructor(options) {
23
23
  if (