webpack 5.90.3 → 5.92.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 (257) hide show
  1. package/README.md +5 -5
  2. package/bin/webpack.js +6 -3
  3. package/lib/APIPlugin.js +14 -6
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/BannerPlugin.js +3 -1
  6. package/lib/Cache.js +8 -2
  7. package/lib/CacheFacade.js +3 -3
  8. package/lib/Chunk.js +7 -4
  9. package/lib/ChunkGraph.js +52 -25
  10. package/lib/ChunkGroup.js +23 -17
  11. package/lib/CleanPlugin.js +8 -6
  12. package/lib/Compilation.js +295 -120
  13. package/lib/Compiler.js +223 -87
  14. package/lib/ConcatenationScope.js +3 -3
  15. package/lib/ConditionalInitFragment.js +4 -5
  16. package/lib/ContextModule.js +95 -41
  17. package/lib/ContextModuleFactory.js +4 -2
  18. package/lib/ContextReplacementPlugin.js +3 -2
  19. package/lib/DefinePlugin.js +18 -6
  20. package/lib/Dependency.js +12 -10
  21. package/lib/DependencyTemplate.js +17 -7
  22. package/lib/DllModule.js +1 -0
  23. package/lib/DllReferencePlugin.js +7 -3
  24. package/lib/EntryOptionPlugin.js +4 -1
  25. package/lib/EntryPlugin.js +6 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/EvalDevToolModulePlugin.js +11 -0
  28. package/lib/ExportsInfo.js +23 -8
  29. package/lib/ExternalModule.js +160 -35
  30. package/lib/ExternalModuleFactoryPlugin.js +37 -2
  31. package/lib/FileSystemInfo.js +69 -42
  32. package/lib/FlagDependencyExportsPlugin.js +21 -7
  33. package/lib/Generator.js +4 -4
  34. package/lib/HookWebpackError.js +2 -2
  35. package/lib/HotModuleReplacementPlugin.js +108 -45
  36. package/lib/IgnorePlugin.js +4 -1
  37. package/lib/InitFragment.js +5 -3
  38. package/lib/LibManifestPlugin.js +17 -9
  39. package/lib/Module.js +41 -14
  40. package/lib/ModuleFactory.js +3 -3
  41. package/lib/ModuleFilenameHelpers.js +30 -17
  42. package/lib/ModuleGraph.js +60 -31
  43. package/lib/ModuleGraphConnection.js +2 -1
  44. package/lib/MultiCompiler.js +62 -9
  45. package/lib/NodeStuffPlugin.js +14 -3
  46. package/lib/NormalModule.js +13 -13
  47. package/lib/NormalModuleFactory.js +18 -9
  48. package/lib/NormalModuleReplacementPlugin.js +5 -1
  49. package/lib/Parser.js +1 -1
  50. package/lib/PlatformPlugin.js +39 -0
  51. package/lib/ProgressPlugin.js +1 -1
  52. package/lib/ProvidePlugin.js +3 -1
  53. package/lib/RawModule.js +2 -1
  54. package/lib/RecordIdsPlugin.js +4 -4
  55. package/lib/ResolverFactory.js +6 -4
  56. package/lib/RuntimeModule.js +4 -4
  57. package/lib/RuntimePlugin.js +1 -0
  58. package/lib/RuntimeTemplate.js +124 -52
  59. package/lib/SourceMapDevToolPlugin.js +4 -1
  60. package/lib/Stats.js +11 -4
  61. package/lib/Template.js +5 -5
  62. package/lib/TemplatedPathPlugin.js +48 -7
  63. package/lib/Watching.js +67 -60
  64. package/lib/WebpackError.js +6 -6
  65. package/lib/WebpackOptionsApply.js +18 -5
  66. package/lib/asset/AssetGenerator.js +15 -0
  67. package/lib/asset/RawDataUrlModule.js +3 -1
  68. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  69. package/lib/buildChunkGraph.js +120 -67
  70. package/lib/cache/IdleFileCachePlugin.js +8 -3
  71. package/lib/cache/MemoryCachePlugin.js +1 -1
  72. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  73. package/lib/cache/PackFileCacheStrategy.js +51 -18
  74. package/lib/cache/ResolverCachePlugin.js +22 -14
  75. package/lib/cache/getLazyHashedEtag.js +2 -2
  76. package/lib/cli.js +5 -5
  77. package/lib/config/browserslistTargetHandler.js +7 -1
  78. package/lib/config/defaults.js +108 -34
  79. package/lib/config/normalization.js +3 -1
  80. package/lib/config/target.js +18 -11
  81. package/lib/container/ContainerEntryDependency.js +2 -1
  82. package/lib/container/ContainerEntryModule.js +4 -2
  83. package/lib/container/ContainerPlugin.js +14 -10
  84. package/lib/container/FallbackModule.js +1 -1
  85. package/lib/container/RemoteRuntimeModule.js +12 -3
  86. package/lib/css/CssExportsGenerator.js +68 -25
  87. package/lib/css/CssGenerator.js +34 -6
  88. package/lib/css/CssLoadingRuntimeModule.js +217 -98
  89. package/lib/css/CssModulesPlugin.js +238 -107
  90. package/lib/css/CssParser.js +24 -15
  91. package/lib/css/walkCssTokens.js +1 -1
  92. package/lib/debug/ProfilingPlugin.js +28 -3
  93. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
  94. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  95. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
  96. package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
  97. package/lib/dependencies/CommonJsExportsDependency.js +13 -5
  98. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
  99. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
  100. package/lib/dependencies/ContextDependencyHelpers.js +49 -29
  101. package/lib/dependencies/ContextElementDependency.js +8 -1
  102. package/lib/dependencies/CssExportDependency.js +2 -2
  103. package/lib/dependencies/CssLocalIdentifierDependency.js +71 -9
  104. package/lib/dependencies/CssUrlDependency.js +10 -7
  105. package/lib/dependencies/ExportsInfoDependency.js +5 -4
  106. package/lib/dependencies/ExternalModuleDependency.js +4 -2
  107. package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
  108. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
  109. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
  110. package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
  111. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
  112. package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
  113. package/lib/dependencies/HarmonyImportDependency.js +28 -12
  114. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +70 -19
  115. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
  116. package/lib/dependencies/HarmonyImportSpecifierDependency.js +47 -35
  117. package/lib/dependencies/ImportDependency.js +9 -2
  118. package/lib/dependencies/ImportEagerDependency.js +4 -2
  119. package/lib/dependencies/ImportMetaContextDependency.js +7 -0
  120. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
  121. package/lib/dependencies/ImportMetaPlugin.js +1 -1
  122. package/lib/dependencies/ImportParserPlugin.js +15 -5
  123. package/lib/dependencies/ImportWeakDependency.js +4 -2
  124. package/lib/dependencies/LoaderDependency.js +2 -1
  125. package/lib/dependencies/LoaderImportDependency.js +2 -1
  126. package/lib/dependencies/LoaderPlugin.js +2 -2
  127. package/lib/dependencies/ModuleDependency.js +4 -5
  128. package/lib/dependencies/PureExpressionDependency.js +64 -47
  129. package/lib/dependencies/RequireContextPlugin.js +1 -1
  130. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
  131. package/lib/dependencies/RequireEnsureDependency.js +1 -1
  132. package/lib/dependencies/URLDependency.js +7 -4
  133. package/lib/dependencies/WorkerDependency.js +1 -1
  134. package/lib/dependencies/WorkerPlugin.js +2 -1
  135. package/lib/dependencies/getFunctionExpression.js +3 -1
  136. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -3
  137. package/lib/hmr/LazyCompilationPlugin.js +2 -2
  138. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
  139. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  140. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  141. package/lib/ids/IdHelpers.js +6 -6
  142. package/lib/ids/NamedChunkIdsPlugin.js +1 -1
  143. package/lib/ids/NamedModuleIdsPlugin.js +1 -1
  144. package/lib/ids/SyncModuleIdsPlugin.js +2 -2
  145. package/lib/index.js +11 -0
  146. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  147. package/lib/javascript/ChunkHelpers.js +2 -2
  148. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  149. package/lib/javascript/JavascriptGenerator.js +0 -1
  150. package/lib/javascript/JavascriptModulesPlugin.js +174 -17
  151. package/lib/javascript/JavascriptParser.js +204 -71
  152. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  153. package/lib/javascript/StartupHelpers.js +22 -5
  154. package/lib/library/AbstractLibraryPlugin.js +2 -2
  155. package/lib/library/AmdLibraryPlugin.js +2 -2
  156. package/lib/library/AssignLibraryPlugin.js +3 -3
  157. package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
  158. package/lib/library/JsonpLibraryPlugin.js +2 -2
  159. package/lib/library/ModuleLibraryPlugin.js +2 -2
  160. package/lib/library/SystemLibraryPlugin.js +2 -2
  161. package/lib/library/UmdLibraryPlugin.js +33 -12
  162. package/lib/logging/Logger.js +27 -2
  163. package/lib/logging/createConsoleLogger.js +13 -9
  164. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
  165. package/lib/node/NodeEnvironmentPlugin.js +14 -8
  166. package/lib/node/NodeTemplatePlugin.js +1 -1
  167. package/lib/node/NodeWatchFileSystem.js +37 -26
  168. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
  169. package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
  170. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
  171. package/lib/node/nodeConsole.js +24 -1
  172. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  173. package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
  174. package/lib/optimize/ConcatenatedModule.js +140 -121
  175. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  176. package/lib/optimize/InnerGraph.js +8 -3
  177. package/lib/optimize/InnerGraphPlugin.js +36 -13
  178. package/lib/optimize/LimitChunkCountPlugin.js +1 -2
  179. package/lib/optimize/ModuleConcatenationPlugin.js +13 -3
  180. package/lib/optimize/RealContentHashPlugin.js +3 -3
  181. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  182. package/lib/optimize/RuntimeChunkPlugin.js +6 -1
  183. package/lib/optimize/SideEffectsFlagPlugin.js +48 -17
  184. package/lib/optimize/SplitChunksPlugin.js +10 -10
  185. package/lib/performance/SizeLimitsPlugin.js +13 -2
  186. package/lib/rules/ObjectMatcherRulePlugin.js +15 -1
  187. package/lib/rules/RuleSetCompiler.js +9 -7
  188. package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
  189. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  190. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  191. package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
  192. package/lib/schemes/HttpUriPlugin.js +1 -1
  193. package/lib/serialization/BinaryMiddleware.js +4 -4
  194. package/lib/serialization/FileMiddleware.js +4 -3
  195. package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
  196. package/lib/serialization/ObjectMiddleware.js +8 -5
  197. package/lib/serialization/PlainObjectSerializer.js +2 -2
  198. package/lib/serialization/Serializer.js +19 -0
  199. package/lib/serialization/SerializerMiddleware.js +2 -2
  200. package/lib/serialization/SingleItemMiddleware.js +2 -2
  201. package/lib/serialization/types.js +1 -1
  202. package/lib/sharing/ConsumeSharedModule.js +2 -2
  203. package/lib/sharing/ConsumeSharedPlugin.js +17 -3
  204. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
  205. package/lib/sharing/ProvideSharedPlugin.js +13 -6
  206. package/lib/sharing/resolveMatchedConfigs.js +3 -3
  207. package/lib/sharing/utils.js +13 -6
  208. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
  209. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  210. package/lib/stats/StatsFactory.js +2 -2
  211. package/lib/stats/StatsPrinter.js +6 -6
  212. package/lib/util/ArrayQueue.js +14 -21
  213. package/lib/util/AsyncQueue.js +1 -1
  214. package/lib/util/Queue.js +8 -2
  215. package/lib/util/SortableSet.js +16 -4
  216. package/lib/util/StackedCacheMap.js +26 -0
  217. package/lib/util/TupleQueue.js +8 -2
  218. package/lib/util/WeakTupleMap.js +57 -13
  219. package/lib/util/binarySearchBounds.js +1 -1
  220. package/lib/util/cleverMerge.js +26 -13
  221. package/lib/util/comparators.js +37 -15
  222. package/lib/util/conventions.js +129 -0
  223. package/lib/util/createHash.js +3 -5
  224. package/lib/util/deprecation.js +3 -3
  225. package/lib/util/deterministicGrouping.js +2 -2
  226. package/lib/util/findGraphRoots.js +1 -1
  227. package/lib/util/fs.js +383 -69
  228. package/lib/util/hash/BatchedHash.js +3 -0
  229. package/lib/util/hash/xxhash64.js +2 -2
  230. package/lib/util/identifier.js +5 -5
  231. package/lib/util/mergeScope.js +79 -0
  232. package/lib/util/runtime.js +2 -17
  233. package/lib/util/semver.js +3 -0
  234. package/lib/util/smartGrouping.js +3 -3
  235. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
  236. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  237. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
  238. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  239. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +16 -7
  240. package/lib/wasm-sync/WebAssemblyGenerator.js +40 -19
  241. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  242. package/lib/wasm-sync/WebAssemblyParser.js +7 -4
  243. package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
  244. package/lib/web/FetchCompileWasmPlugin.js +1 -1
  245. package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -2
  246. package/lib/webpack.js +19 -6
  247. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
  248. package/package.json +40 -39
  249. package/schemas/WebpackOptions.check.js +1 -1
  250. package/schemas/WebpackOptions.json +97 -8
  251. package/schemas/plugins/BannerPlugin.check.js +1 -1
  252. package/schemas/plugins/BannerPlugin.json +5 -1
  253. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  254. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  255. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  256. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  257. package/types.d.ts +1826 -639
@@ -27,7 +27,8 @@ const {
27
27
  getDefaultTarget
28
28
  } = require("./target");
29
29
 
30
- /** @typedef {import("../../declarations/WebpackOptions").CacheOptionsNormalized} CacheOptions */
30
+ /** @typedef {import("../../declarations/WebpackOptions").CacheOptions} CacheOptions */
31
+ /** @typedef {import("../../declarations/WebpackOptions").CacheOptionsNormalized} CacheOptionsNormalized */
31
32
  /** @typedef {import("../../declarations/WebpackOptions").Context} Context */
32
33
  /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorOptions} CssGeneratorOptions */
33
34
  /** @typedef {import("../../declarations/WebpackOptions").CssParserOptions} CssParserOptions */
@@ -60,12 +61,20 @@ const {
60
61
  /** @typedef {import("../../declarations/WebpackOptions").RuleSetRules} RuleSetRules */
61
62
  /** @typedef {import("../../declarations/WebpackOptions").SnapshotOptions} SnapshotOptions */
62
63
  /** @typedef {import("../../declarations/WebpackOptions").Target} Target */
63
- /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
64
+ /** @typedef {import("../../declarations/WebpackOptions").WebpackOptions} WebpackOptions */
65
+ /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptionsNormalized */
64
66
  /** @typedef {import("../Compiler")} Compiler */
65
67
  /** @typedef {import("../Module")} Module */
68
+ /** @typedef {import("./target").PlatformTargetProperties} PlatformTargetProperties */
66
69
  /** @typedef {import("./target").TargetProperties} TargetProperties */
67
70
 
71
+ /**
72
+ * @typedef {object} ResolvedOptions
73
+ * @property {PlatformTargetProperties | false} platform - platform target properties
74
+ */
75
+
68
76
  const NODE_MODULES_REGEXP = /[\\/]node_modules[\\/]/i;
77
+ const DEFAULT_CACHE_NAME = "default";
69
78
 
70
79
  /**
71
80
  * Sets a constant default value when undefined
@@ -137,7 +146,7 @@ const A = (obj, prop, factory) => {
137
146
  };
138
147
 
139
148
  /**
140
- * @param {WebpackOptions} options options to be modified
149
+ * @param {WebpackOptionsNormalized} options options to be modified
141
150
  * @returns {void}
142
151
  */
143
152
  const applyWebpackOptionsBaseDefaults = options => {
@@ -146,10 +155,11 @@ const applyWebpackOptionsBaseDefaults = options => {
146
155
  };
147
156
 
148
157
  /**
149
- * @param {WebpackOptions} options options to be modified
150
- * @returns {void}
158
+ * @param {WebpackOptionsNormalized} options options to be modified
159
+ * @param {number} [compilerIndex] index of compiler
160
+ * @returns {ResolvedOptions} Resolved options after apply defaults
151
161
  */
152
- const applyWebpackOptionsDefaults = options => {
162
+ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
153
163
  F(options, "context", () => process.cwd());
154
164
  F(options, "target", () => {
155
165
  return getDefaultTarget(/** @type {string} */ (options.context));
@@ -201,10 +211,11 @@ const applyWebpackOptionsDefaults = options => {
201
211
  development ? { type: /** @type {"memory"} */ ("memory") } : false
202
212
  );
203
213
  applyCacheDefaults(options.cache, {
204
- name: name || "default",
214
+ name: name || DEFAULT_CACHE_NAME,
205
215
  mode: mode || "production",
206
216
  development,
207
- cacheUnaffected: options.experiments.cacheUnaffected
217
+ cacheUnaffected: options.experiments.cacheUnaffected,
218
+ compilerIndex
208
219
  });
209
220
  const cache = !!options.cache;
210
221
 
@@ -242,7 +253,6 @@ const applyWebpackOptionsDefaults = options => {
242
253
  (options.experiments.outputModule),
243
254
  development,
244
255
  entry: options.entry,
245
- module: options.module,
246
256
  futureDefaults
247
257
  });
248
258
 
@@ -252,7 +262,9 @@ const applyWebpackOptionsDefaults = options => {
252
262
  });
253
263
 
254
264
  applyLoaderDefaults(
255
- /** @type {NonNullable<WebpackOptions["loader"]>} */ (options.loader),
265
+ /** @type {NonNullable<WebpackOptionsNormalized["loader"]>} */ (
266
+ options.loader
267
+ ),
256
268
  { targetProperties, environment: options.output.environment }
257
269
  );
258
270
 
@@ -269,7 +281,7 @@ const applyWebpackOptionsDefaults = options => {
269
281
 
270
282
  applyNodeDefaults(options.node, {
271
283
  futureDefaults:
272
- /** @type {NonNullable<WebpackOptions["experiments"]["futureDefaults"]>} */
284
+ /** @type {NonNullable<WebpackOptionsNormalized["experiments"]["futureDefaults"]>} */
273
285
  (options.experiments.futureDefaults),
274
286
  outputModule: options.output.module,
275
287
  targetProperties
@@ -283,7 +295,7 @@ const applyWebpackOptionsDefaults = options => {
283
295
  : false
284
296
  );
285
297
  applyPerformanceDefaults(
286
- /** @type {NonNullable<WebpackOptions["performance"]>} */
298
+ /** @type {NonNullable<WebpackOptionsNormalized["performance"]>} */
287
299
  (options.performance),
288
300
  {
289
301
  production
@@ -316,11 +328,25 @@ const applyWebpackOptionsDefaults = options => {
316
328
  getResolveLoaderDefaults({ cache }),
317
329
  options.resolveLoader
318
330
  );
331
+
332
+ return {
333
+ platform:
334
+ targetProperties === false
335
+ ? targetProperties
336
+ : {
337
+ web: targetProperties.web,
338
+ browser: targetProperties.browser,
339
+ webworker: targetProperties.webworker,
340
+ node: targetProperties.node,
341
+ nwjs: targetProperties.nwjs,
342
+ electron: targetProperties.electron
343
+ }
344
+ };
319
345
  };
320
346
 
321
347
  /**
322
348
  * @param {ExperimentsNormalized} experiments options
323
- * @param {Object} options options
349
+ * @param {object} options options
324
350
  * @param {boolean} options.production is production
325
351
  * @param {boolean} options.development is development mode
326
352
  * @param {TargetProperties | false} options.targetProperties target properties
@@ -355,22 +381,27 @@ const applyExperimentsDefaults = (
355
381
  };
356
382
 
357
383
  /**
358
- * @param {CacheOptions} cache options
359
- * @param {Object} options options
384
+ * @param {CacheOptionsNormalized} cache options
385
+ * @param {object} options options
360
386
  * @param {string} options.name name
361
387
  * @param {Mode} options.mode mode
362
388
  * @param {boolean} options.development is development mode
389
+ * @param {number} [options.compilerIndex] index of compiler
363
390
  * @param {Experiments["cacheUnaffected"]} options.cacheUnaffected the cacheUnaffected experiment is enabled
364
391
  * @returns {void}
365
392
  */
366
393
  const applyCacheDefaults = (
367
394
  cache,
368
- { name, mode, development, cacheUnaffected }
395
+ { name, mode, development, cacheUnaffected, compilerIndex }
369
396
  ) => {
370
397
  if (cache === false) return;
371
398
  switch (cache.type) {
372
399
  case "filesystem":
373
- F(cache, "name", () => name + "-" + mode);
400
+ F(cache, "name", () =>
401
+ compilerIndex !== undefined
402
+ ? `${name + "-" + mode}__compiler${compilerIndex + 1}__`
403
+ : name + "-" + mode
404
+ );
374
405
  D(cache, "version", "");
375
406
  F(cache, "cacheDirectory", () => {
376
407
  const cwd = process.cwd();
@@ -433,7 +464,7 @@ const applyCacheDefaults = (
433
464
 
434
465
  /**
435
466
  * @param {SnapshotOptions} snapshot options
436
- * @param {Object} options options
467
+ * @param {object} options options
437
468
  * @param {boolean} options.production is production
438
469
  * @param {boolean} options.futureDefaults is future defaults enabled
439
470
  * @returns {void}
@@ -472,7 +503,6 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
472
503
  }
473
504
  return [];
474
505
  });
475
- F(snapshot, "unmanagedPaths", () => []);
476
506
  A(snapshot, "immutablePaths", () => {
477
507
  if (process.versions.pnp === "1") {
478
508
  const match =
@@ -494,6 +524,7 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
494
524
  return [];
495
525
  });
496
526
  }
527
+ F(snapshot, "unmanagedPaths", () => []);
497
528
  F(snapshot, "resolveBuildDependencies", () => ({
498
529
  timestamp: true,
499
530
  hash: true
@@ -509,7 +540,7 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
509
540
 
510
541
  /**
511
542
  * @param {JavascriptParserOptions} parserOptions parser options
512
- * @param {Object} options options
543
+ * @param {object} options options
513
544
  * @param {boolean} options.futureDefaults is future defaults enabled
514
545
  * @param {boolean} options.isNode is node target platform
515
546
  * @returns {void}
@@ -541,7 +572,7 @@ const applyJavascriptParserOptionsDefaults = (
541
572
 
542
573
  /**
543
574
  * @param {CssGeneratorOptions} generatorOptions generator options
544
- * @param {Object} options options
575
+ * @param {object} options options
545
576
  * @param {TargetProperties | false} options.targetProperties target properties
546
577
  * @returns {void}
547
578
  */
@@ -554,11 +585,12 @@ const applyCssGeneratorOptionsDefaults = (
554
585
  "exportsOnly",
555
586
  !targetProperties || !targetProperties.document
556
587
  );
588
+ D(generatorOptions, "esModule", true);
557
589
  };
558
590
 
559
591
  /**
560
592
  * @param {ModuleOptions} module options
561
- * @param {Object} options options
593
+ * @param {object} options options
562
594
  * @param {boolean} options.cache is caching enabled
563
595
  * @param {boolean} options.syncWebAssembly is syncWebAssembly enabled
564
596
  * @param {boolean} options.asyncWebAssembly is asyncWebAssembly enabled
@@ -641,6 +673,30 @@ const applyModuleDefaults = (
641
673
  (module.generator.css),
642
674
  { targetProperties }
643
675
  );
676
+
677
+ F(module.generator, "css/auto", () => ({}));
678
+ D(
679
+ module.generator["css/auto"],
680
+ "localIdentName",
681
+ "[uniqueName]-[id]-[local]"
682
+ );
683
+ D(module.generator["css/auto"], "exportsConvention", "as-is");
684
+
685
+ F(module.generator, "css/module", () => ({}));
686
+ D(
687
+ module.generator["css/module"],
688
+ "localIdentName",
689
+ "[uniqueName]-[id]-[local]"
690
+ );
691
+ D(module.generator["css/module"], "exportsConvention", "as-is");
692
+
693
+ F(module.generator, "css/global", () => ({}));
694
+ D(
695
+ module.generator["css/global"],
696
+ "localIdentName",
697
+ "[uniqueName]-[id]-[local]"
698
+ );
699
+ D(module.generator["css/global"], "exportsConvention", "as-is");
644
700
  }
645
701
 
646
702
  A(module, "defaultRules", () => {
@@ -782,6 +838,10 @@ const applyModuleDefaults = (
782
838
  {
783
839
  assert: { type: "json" },
784
840
  type: JSON_MODULE_TYPE
841
+ },
842
+ {
843
+ with: { type: "json" },
844
+ type: JSON_MODULE_TYPE
785
845
  }
786
846
  );
787
847
  return rules;
@@ -790,14 +850,13 @@ const applyModuleDefaults = (
790
850
 
791
851
  /**
792
852
  * @param {Output} output options
793
- * @param {Object} options options
853
+ * @param {object} options options
794
854
  * @param {string} options.context context
795
855
  * @param {TargetProperties | false} options.targetProperties target properties
796
856
  * @param {boolean} options.isAffectedByBrowserslist is affected by browserslist
797
857
  * @param {boolean} options.outputModule is outputModule experiment enabled
798
858
  * @param {boolean} options.development is development mode
799
859
  * @param {Entry} options.entry entry option
800
- * @param {ModuleOptions} options.module module option
801
860
  * @param {boolean} options.futureDefaults is future defaults enabled
802
861
  * @returns {void}
803
862
  */
@@ -810,7 +869,6 @@ const applyOutputDefaults = (
810
869
  outputModule,
811
870
  development,
812
871
  entry,
813
- module,
814
872
  futureDefaults
815
873
  }
816
874
  ) => {
@@ -901,6 +959,7 @@ const applyOutputDefaults = (
901
959
  }
902
960
  return "[id].css";
903
961
  });
962
+ D(output, "cssHeadDataCompression", !development);
904
963
  D(output, "assetModuleFilename", "[hash][ext][query]");
905
964
  D(output, "webassemblyModuleFilename", "[hash].module.wasm");
906
965
  D(output, "compareBeforeEmit", true);
@@ -961,7 +1020,7 @@ const applyOutputDefaults = (
961
1020
  if (tp.nodeBuiltins) return "async-node";
962
1021
  break;
963
1022
  case "module":
964
- if (tp.dynamicImport) return "import";
1023
+ if (tp.dynamicImport || output.module) return "import";
965
1024
  break;
966
1025
  }
967
1026
  if (
@@ -986,7 +1045,7 @@ const applyOutputDefaults = (
986
1045
  if (tp.nodeBuiltins) return "async-node";
987
1046
  break;
988
1047
  case "module":
989
- if (tp.dynamicImportInWorker) return "import";
1048
+ if (tp.dynamicImportInWorker || output.module) return "import";
990
1049
  break;
991
1050
  }
992
1051
  if (
@@ -1098,6 +1157,15 @@ const applyOutputDefaults = (
1098
1157
  () =>
1099
1158
  tp && optimistic(/** @type {boolean | undefined} */ (tp.optionalChaining))
1100
1159
  );
1160
+ F(
1161
+ environment,
1162
+ "nodePrefixForCoreModules",
1163
+ () =>
1164
+ tp &&
1165
+ optimistic(
1166
+ /** @type {boolean | undefined} */ (tp.nodePrefixForCoreModules)
1167
+ )
1168
+ );
1101
1169
  F(
1102
1170
  environment,
1103
1171
  "templateLiteral",
@@ -1122,6 +1190,11 @@ const applyOutputDefaults = (
1122
1190
  output.module
1123
1191
  )
1124
1192
  );
1193
+ F(
1194
+ environment,
1195
+ "document",
1196
+ () => tp && optimistic(/** @type {boolean | undefined} */ (tp.document))
1197
+ );
1125
1198
 
1126
1199
  const { trustedTypes } = output;
1127
1200
  if (trustedTypes) {
@@ -1193,7 +1266,7 @@ const applyOutputDefaults = (
1193
1266
 
1194
1267
  /**
1195
1268
  * @param {ExternalsPresets} externalsPresets options
1196
- * @param {Object} options options
1269
+ * @param {object} options options
1197
1270
  * @param {TargetProperties | false} options.targetProperties target properties
1198
1271
  * @param {boolean} options.buildHttp buildHttp experiment enabled
1199
1272
  * @returns {void}
@@ -1260,7 +1333,7 @@ const applyExternalsPresetsDefaults = (
1260
1333
 
1261
1334
  /**
1262
1335
  * @param {Loader} loader options
1263
- * @param {Object} options options
1336
+ * @param {object} options options
1264
1337
  * @param {TargetProperties | false} options.targetProperties target properties
1265
1338
  * @param {Environment} options.environment environment
1266
1339
  * @returns {void}
@@ -1284,7 +1357,7 @@ const applyLoaderDefaults = (loader, { targetProperties, environment }) => {
1284
1357
 
1285
1358
  /**
1286
1359
  * @param {WebpackNode} node options
1287
- * @param {Object} options options
1360
+ * @param {object} options options
1288
1361
  * @param {TargetProperties | false} options.targetProperties target properties
1289
1362
  * @param {boolean} options.futureDefaults is future defaults enabled
1290
1363
  * @param {boolean} options.outputModule is output type is module
@@ -1315,7 +1388,7 @@ const applyNodeDefaults = (
1315
1388
 
1316
1389
  /**
1317
1390
  * @param {Performance} performance options
1318
- * @param {Object} options options
1391
+ * @param {object} options options
1319
1392
  * @param {boolean} options.production is production
1320
1393
  * @returns {void}
1321
1394
  */
@@ -1328,7 +1401,7 @@ const applyPerformanceDefaults = (performance, { production }) => {
1328
1401
 
1329
1402
  /**
1330
1403
  * @param {Optimization} optimization options
1331
- * @param {Object} options options
1404
+ * @param {object} options options
1332
1405
  * @param {boolean} options.production is production
1333
1406
  * @param {boolean} options.development is development
1334
1407
  * @param {boolean} options.css is css enabled
@@ -1420,7 +1493,7 @@ const applyOptimizationDefaults = (
1420
1493
  };
1421
1494
 
1422
1495
  /**
1423
- * @param {Object} options options
1496
+ * @param {object} options options
1424
1497
  * @param {boolean} options.cache is cache enable
1425
1498
  * @param {string} options.context build context
1426
1499
  * @param {TargetProperties | false} options.targetProperties target properties
@@ -1480,6 +1553,7 @@ const getResolveDefaults = ({
1480
1553
  exportsFields: ["exports"],
1481
1554
  roots: [context],
1482
1555
  mainFields: ["main"],
1556
+ importsFields: ["imports"],
1483
1557
  byDependency: {
1484
1558
  wasm: esmDeps(),
1485
1559
  esm: esmDeps(),
@@ -1525,7 +1599,7 @@ const getResolveDefaults = ({
1525
1599
  };
1526
1600
 
1527
1601
  /**
1528
- * @param {Object} options options
1602
+ * @param {object} options options
1529
1603
  * @param {boolean} options.cache is cache enable
1530
1604
  * @returns {ResolveOptions} resolve options
1531
1605
  */
@@ -320,6 +320,7 @@ const getNormalizedWebpackOptions = config => {
320
320
  chunkLoadTimeout: output.chunkLoadTimeout,
321
321
  cssFilename: output.cssFilename,
322
322
  cssChunkFilename: output.cssChunkFilename,
323
+ cssHeadDataCompression: output.cssHeadDataCompression,
323
324
  clean: output.clean,
324
325
  compareBeforeEmit: output.compareBeforeEmit,
325
326
  crossOriginLoading: output.crossOriginLoading,
@@ -446,7 +447,8 @@ const getNormalizedWebpackOptions = config => {
446
447
  hash: module.hash
447
448
  })),
448
449
  immutablePaths: optionalNestedArray(snapshot.immutablePaths, p => [...p]),
449
- managedPaths: optionalNestedArray(snapshot.managedPaths, p => [...p])
450
+ managedPaths: optionalNestedArray(snapshot.managedPaths, p => [...p]),
451
+ unmanagedPaths: optionalNestedArray(snapshot.unmanagedPaths, p => [...p])
450
452
  })),
451
453
  stats: nestedConfig(config.stats, stats => {
452
454
  if (stats === false) {
@@ -21,7 +21,7 @@ const getDefaultTarget = context => {
21
21
  };
22
22
 
23
23
  /**
24
- * @typedef {Object} PlatformTargetProperties
24
+ * @typedef {object} PlatformTargetProperties
25
25
  * @property {boolean | null} web web platform, importing of http(s) and std: is available
26
26
  * @property {boolean | null} browser browser platform, running in a normal web browser
27
27
  * @property {boolean | null} webworker (Web)Worker platform, running in a web/shared/service worker
@@ -31,16 +31,17 @@ const getDefaultTarget = context => {
31
31
  */
32
32
 
33
33
  /**
34
- * @typedef {Object} ElectronContextTargetProperties
34
+ * @typedef {object} ElectronContextTargetProperties
35
35
  * @property {boolean | null} electronMain in main context
36
36
  * @property {boolean | null} electronPreload in preload context
37
37
  * @property {boolean | null} electronRenderer in renderer context with node integration
38
38
  */
39
39
 
40
40
  /**
41
- * @typedef {Object} ApiTargetProperties
41
+ * @typedef {object} ApiTargetProperties
42
42
  * @property {boolean | null} require has require function available
43
43
  * @property {boolean | null} nodeBuiltins has node.js built-in modules available
44
+ * @property {boolean | null} nodePrefixForCoreModules node.js allows to use `node:` prefix for core modules
44
45
  * @property {boolean | null} document has document available (allows script tags)
45
46
  * @property {boolean | null} importScripts has importScripts available
46
47
  * @property {boolean | null} importScriptsInWorker has importScripts available when creating a worker
@@ -49,7 +50,7 @@ const getDefaultTarget = context => {
49
50
  */
50
51
 
51
52
  /**
52
- * @typedef {Object} EcmaTargetProperties
53
+ * @typedef {object} EcmaTargetProperties
53
54
  * @property {boolean | null} globalThis has globalThis variable available
54
55
  * @property {boolean | null} bigIntLiteral big int literal syntax is available
55
56
  * @property {boolean | null} const const and let variable declarations are available
@@ -168,8 +169,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
168
169
  [
169
170
  "[async-]node[X[.Y]]",
170
171
  "Node.js in version X.Y. The 'async-' prefix will load chunks asynchronously via 'fs' and 'vm' instead of 'require()'. Examples: node14.5, async-node10.",
171
- /^(async-)?node(\d+(?:\.(\d+))?)?$/,
172
- (asyncFlag, major, minor) => {
172
+ /^(async-)?node((\d+)(?:\.(\d+))?)?$/,
173
+ (asyncFlag, _, major, minor) => {
173
174
  const v = versionDependent(major, minor);
174
175
  // see https://node.green/
175
176
  return {
@@ -182,6 +183,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
182
183
 
183
184
  require: !asyncFlag,
184
185
  nodeBuiltins: true,
186
+ // v16.0.0, v14.18.0
187
+ nodePrefixForCoreModules: +major < 15 ? v(14, 18) : v(16),
185
188
  global: true,
186
189
  document: false,
187
190
  fetchWasm: false,
@@ -206,8 +209,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
206
209
  [
207
210
  "electron[X[.Y]]-main/preload/renderer",
208
211
  "Electron in version X.Y. Script is running in main, preload resp. renderer context.",
209
- /^electron(\d+(?:\.(\d+))?)?-(main|preload|renderer)$/,
210
- (major, minor, context) => {
212
+ /^electron((\d+)(?:\.(\d+))?)?-(main|preload|renderer)$/,
213
+ (_, major, minor, context) => {
211
214
  const v = versionDependent(major, minor);
212
215
  // see https://node.green/ + https://github.com/electron/releases
213
216
  return {
@@ -224,6 +227,10 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
224
227
 
225
228
  global: true,
226
229
  nodeBuiltins: true,
230
+ // 15.0.0 - Node.js v16.5
231
+ // 14.0.0 - Mode.js v14.17, but prefixes only since v14.18
232
+ nodePrefixForCoreModules: v(15),
233
+
227
234
  require: true,
228
235
  document: context === "renderer",
229
236
  fetchWasm: context === "renderer",
@@ -248,8 +255,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
248
255
  [
249
256
  "nwjs[X[.Y]] / node-webkit[X[.Y]]",
250
257
  "NW.js in version X.Y.",
251
- /^(?:nwjs|node-webkit)(\d+(?:\.(\d+))?)?$/,
252
- (major, minor) => {
258
+ /^(?:nwjs|node-webkit)((\d+)(?:\.(\d+))?)?$/,
259
+ (_, major, minor) => {
253
260
  const v = versionDependent(major, minor);
254
261
  // see https://node.green/ + https://github.com/nwjs/nw.js/blob/nw48/CHANGELOG.md
255
262
  return {
@@ -341,7 +348,7 @@ const mergeTargetProperties = targetProperties => {
341
348
  keys.add(/** @type {keyof TargetProperties} */ (key));
342
349
  }
343
350
  }
344
- /** @type {Object} */
351
+ /** @type {object} */
345
352
  const result = {};
346
353
  for (const key of keys) {
347
354
  let hasTrue = false;
@@ -9,11 +9,12 @@ const Dependency = require("../Dependency");
9
9
  const makeSerializable = require("../util/makeSerializable");
10
10
 
11
11
  /** @typedef {import("./ContainerEntryModule").ExposeOptions} ExposeOptions */
12
+ /** @typedef {import("./ContainerEntryModule").ExposesList} ExposesList */
12
13
 
13
14
  class ContainerEntryDependency extends Dependency {
14
15
  /**
15
16
  * @param {string} name entry name
16
- * @param {[string, ExposeOptions][]} exposes list of exposed modules
17
+ * @param {ExposesList} exposes list of exposed modules
17
18
  * @param {string} shareScope name of the share scope
18
19
  */
19
20
  constructor(name, exposes, shareScope) {
@@ -34,17 +34,19 @@ const ContainerExposedDependency = require("./ContainerExposedDependency");
34
34
  /** @typedef {import("./ContainerEntryDependency")} ContainerEntryDependency */
35
35
 
36
36
  /**
37
- * @typedef {Object} ExposeOptions
37
+ * @typedef {object} ExposeOptions
38
38
  * @property {string[]} import requests to exposed modules (last one is exported)
39
39
  * @property {string} name custom chunk name for the exposed module
40
40
  */
41
41
 
42
+ /** @typedef {[string, ExposeOptions][]} ExposesList */
43
+
42
44
  const SOURCE_TYPES = new Set(["javascript"]);
43
45
 
44
46
  class ContainerEntryModule extends Module {
45
47
  /**
46
48
  * @param {string} name container entry name
47
- * @param {[string, ExposeOptions][]} exposes list of exposed modules
49
+ * @param {ExposesList} exposes list of exposed modules
48
50
  * @param {string} shareScope name of the share scope
49
51
  */
50
52
  constructor(name, exposes, shareScope) {
@@ -13,6 +13,8 @@ const { parseOptions } = require("./options");
13
13
 
14
14
  /** @typedef {import("../../declarations/plugins/container/ContainerPlugin").ContainerPluginOptions} ContainerPluginOptions */
15
15
  /** @typedef {import("../Compiler")} Compiler */
16
+ /** @typedef {import("./ContainerEntryModule").ExposeOptions} ExposeOptions */
17
+ /** @typedef {import("./ContainerEntryModule").ExposesList} ExposesList */
16
18
 
17
19
  const validate = createSchemaValidation(
18
20
  require("../../schemas/plugins/container/ContainerPlugin.check.js"),
@@ -41,16 +43,18 @@ class ContainerPlugin {
41
43
  },
42
44
  runtime: options.runtime,
43
45
  filename: options.filename || undefined,
44
- exposes: parseOptions(
45
- options.exposes,
46
- item => ({
47
- import: Array.isArray(item) ? item : [item],
48
- name: undefined
49
- }),
50
- item => ({
51
- import: Array.isArray(item.import) ? item.import : [item.import],
52
- name: item.name || undefined
53
- })
46
+ exposes: /** @type {ExposesList} */ (
47
+ parseOptions(
48
+ options.exposes,
49
+ item => ({
50
+ import: Array.isArray(item) ? item : [item],
51
+ name: undefined
52
+ }),
53
+ item => ({
54
+ import: Array.isArray(item.import) ? item.import : [item.import],
55
+ name: item.name || undefined
56
+ })
57
+ )
54
58
  )
55
59
  };
56
60
  }
@@ -129,7 +129,7 @@ class FallbackModule extends Module {
129
129
  */
130
130
  codeGeneration({ runtimeTemplate, moduleGraph, chunkGraph }) {
131
131
  const ids = this.dependencies.map(dep =>
132
- chunkGraph.getModuleId(moduleGraph.getModule(dep))
132
+ chunkGraph.getModuleId(/** @type {Module} */ (moduleGraph.getModule(dep)))
133
133
  );
134
134
  const code = Template.asString([
135
135
  `var ids = ${JSON.stringify(ids)};`,
@@ -10,6 +10,9 @@ const RuntimeModule = require("../RuntimeModule");
10
10
  const Template = require("../Template");
11
11
 
12
12
  /** @typedef {import("../Chunk")} Chunk */
13
+ /** @typedef {import("../Chunk").ChunkId} ChunkId */
14
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
15
+ /** @typedef {import("../Compilation")} Compilation */
13
16
  /** @typedef {import("./RemoteModule")} RemoteModule */
14
17
 
15
18
  class RemoteRuntimeModule extends RuntimeModule {
@@ -21,17 +24,23 @@ class RemoteRuntimeModule extends RuntimeModule {
21
24
  * @returns {string | null} runtime code
22
25
  */
23
26
  generate() {
24
- const { compilation, chunkGraph } = this;
27
+ const compilation = /** @type {Compilation} */ (this.compilation);
28
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
25
29
  const { runtimeTemplate, moduleGraph } = compilation;
30
+ /** @type {Record<ChunkId, (string | number)[]>} */
26
31
  const chunkToRemotesMapping = {};
32
+ /** @type {Record<string | number, [string, string, string | number | null]>} */
27
33
  const idToExternalAndNameMapping = {};
28
- for (const chunk of this.chunk.getAllAsyncChunks()) {
34
+ for (const chunk of /** @type {Chunk} */ (this.chunk).getAllAsyncChunks()) {
29
35
  const modules = chunkGraph.getChunkModulesIterableBySourceType(
30
36
  chunk,
31
37
  "remote"
32
38
  );
33
39
  if (!modules) continue;
34
- const remotes = (chunkToRemotesMapping[chunk.id] = []);
40
+ /** @type {(string | number)[]} */
41
+ const remotes = (chunkToRemotesMapping[
42
+ /** @type {ChunkId} */ (chunk.id)
43
+ ] = []);
35
44
  for (const m of modules) {
36
45
  const module = /** @type {RemoteModule} */ (m);
37
46
  const name = module.internalRequest;