webpack 5.83.1 → 5.84.1

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 (137) hide show
  1. package/README.md +2 -2
  2. package/lib/CompatibilityPlugin.js +3 -2
  3. package/lib/Compilation.js +2 -2
  4. package/lib/ContextModule.js +3 -3
  5. package/lib/DefinePlugin.js +11 -2
  6. package/lib/DllEntryPlugin.js +5 -0
  7. package/lib/DllModule.js +1 -1
  8. package/lib/EvalSourceMapDevToolPlugin.js +3 -1
  9. package/lib/MainTemplate.js +2 -2
  10. package/lib/PrefetchPlugin.js +4 -0
  11. package/lib/RuntimeTemplate.js +5 -5
  12. package/lib/SelfModuleFactory.js +12 -0
  13. package/lib/SourceMapDevToolPlugin.js +9 -2
  14. package/lib/Template.js +2 -1
  15. package/lib/config/browserslistTargetHandler.js +3 -3
  16. package/lib/config/defaults.js +209 -70
  17. package/lib/config/normalization.js +103 -71
  18. package/lib/config/target.js +37 -10
  19. package/lib/container/FallbackModule.js +1 -1
  20. package/lib/container/RemoteRuntimeModule.js +1 -1
  21. package/lib/css/CssParser.js +168 -73
  22. package/lib/debug/ProfilingPlugin.js +11 -0
  23. package/lib/dependencies/AMDDefineDependency.js +12 -6
  24. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -2
  25. package/lib/dependencies/AMDPlugin.js +7 -0
  26. package/lib/dependencies/AMDRequireArrayDependency.js +5 -0
  27. package/lib/dependencies/AMDRequireContextDependency.js +6 -0
  28. package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
  29. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -2
  30. package/lib/dependencies/AMDRequireDependency.js +8 -1
  31. package/lib/dependencies/AMDRequireItemDependency.js +6 -0
  32. package/lib/dependencies/CachedConstDependency.js +6 -0
  33. package/lib/dependencies/CommonJsExportRequireDependency.js +11 -0
  34. package/lib/dependencies/CommonJsExportsDependency.js +8 -0
  35. package/lib/dependencies/CommonJsExportsParserPlugin.js +2 -2
  36. package/lib/dependencies/CommonJsFullRequireDependency.js +2 -1
  37. package/lib/dependencies/CommonJsPlugin.js +14 -0
  38. package/lib/dependencies/CommonJsRequireContextDependency.js +8 -0
  39. package/lib/dependencies/CommonJsRequireDependency.js +7 -0
  40. package/lib/dependencies/CommonJsSelfReferenceDependency.js +8 -0
  41. package/lib/dependencies/ConstDependency.js +2 -1
  42. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  43. package/lib/dependencies/CreateScriptUrlDependency.js +2 -1
  44. package/lib/dependencies/CriticalDependencyWarning.js +3 -0
  45. package/lib/dependencies/CssImportDependency.js +2 -1
  46. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -1
  47. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
  48. package/lib/dependencies/CssUrlDependency.js +12 -2
  49. package/lib/dependencies/DelegatedSourceDependency.js +3 -0
  50. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  51. package/lib/dependencies/HarmonyAcceptDependency.js +2 -1
  52. package/lib/dependencies/HarmonyAcceptImportDependency.js +3 -0
  53. package/lib/dependencies/HarmonyDetectionParserPlugin.js +16 -0
  54. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +11 -0
  55. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -0
  56. package/lib/dependencies/HarmonyExportExpressionDependency.js +8 -0
  57. package/lib/dependencies/HarmonyExportHeaderDependency.js +5 -0
  58. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
  59. package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
  60. package/lib/dependencies/HarmonyImportDependency.js +2 -1
  61. package/lib/dependencies/HarmonyImportSideEffectDependency.js +6 -0
  62. package/lib/dependencies/HarmonyImportSpecifierDependency.js +11 -0
  63. package/lib/dependencies/HarmonyModulesPlugin.js +12 -0
  64. package/lib/dependencies/ImportContextDependency.js +6 -0
  65. package/lib/dependencies/ImportDependency.js +2 -1
  66. package/lib/dependencies/ImportEagerDependency.js +2 -1
  67. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +32 -13
  68. package/lib/dependencies/ImportMetaContextPlugin.js +7 -0
  69. package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
  70. package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
  71. package/lib/dependencies/ImportParserPlugin.js +5 -0
  72. package/lib/dependencies/ImportPlugin.js +7 -0
  73. package/lib/dependencies/ImportWeakDependency.js +2 -1
  74. package/lib/dependencies/LocalModule.js +16 -0
  75. package/lib/dependencies/LocalModuleDependency.js +7 -0
  76. package/lib/dependencies/LocalModulesHelpers.js +18 -0
  77. package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
  78. package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
  79. package/lib/dependencies/PrefetchDependency.js +3 -0
  80. package/lib/dependencies/ProvidedDependency.js +2 -1
  81. package/lib/dependencies/PureExpressionDependency.js +2 -1
  82. package/lib/dependencies/RequireContextDependency.js +6 -0
  83. package/lib/dependencies/RequireContextPlugin.js +7 -0
  84. package/lib/dependencies/RequireEnsureDependenciesBlock.js +4 -0
  85. package/lib/dependencies/RequireEnsureDependency.js +8 -2
  86. package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
  87. package/lib/dependencies/RequireEnsurePlugin.js +14 -0
  88. package/lib/dependencies/RequireHeaderDependency.js +5 -1
  89. package/lib/dependencies/RequireIncludeDependency.js +5 -0
  90. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
  91. package/lib/dependencies/RequireIncludePlugin.js +14 -0
  92. package/lib/dependencies/RequireResolveContextDependency.js +8 -0
  93. package/lib/dependencies/RequireResolveDependency.js +6 -0
  94. package/lib/dependencies/RequireResolveHeaderDependency.js +4 -0
  95. package/lib/dependencies/SystemPlugin.js +10 -1
  96. package/lib/dependencies/URLDependency.js +3 -2
  97. package/lib/dependencies/URLPlugin.js +7 -5
  98. package/lib/dependencies/UnsupportedDependency.js +5 -0
  99. package/lib/dependencies/WebAssemblyExportImportedDependency.js +6 -0
  100. package/lib/dependencies/WebpackIsIncludedDependency.js +5 -0
  101. package/lib/dependencies/WorkerDependency.js +2 -1
  102. package/lib/dependencies/WorkerPlugin.js +5 -2
  103. package/lib/dependencies/getFunctionExpression.js +7 -0
  104. package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -1
  105. package/lib/esm/ModuleChunkFormatPlugin.js +2 -2
  106. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +5 -2
  107. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
  108. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  109. package/lib/javascript/JavascriptModulesPlugin.js +13 -13
  110. package/lib/javascript/JavascriptParser.js +550 -180
  111. package/lib/javascript/StartupHelpers.js +1 -1
  112. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
  113. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -2
  114. package/lib/optimize/ConcatenatedModule.js +1 -1
  115. package/lib/optimize/InnerGraphPlugin.js +11 -4
  116. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
  117. package/lib/runtime/StartupEntrypointRuntimeModule.js +5 -5
  118. package/lib/serialization/ArraySerializer.js +22 -6
  119. package/lib/serialization/BinaryMiddleware.js +21 -0
  120. package/lib/serialization/DateObjectSerializer.js +15 -4
  121. package/lib/serialization/ErrorObjectSerializer.js +20 -8
  122. package/lib/serialization/FileMiddleware.js +17 -0
  123. package/lib/serialization/MapObjectSerializer.js +24 -8
  124. package/lib/serialization/NullPrototypeObjectSerializer.js +25 -8
  125. package/lib/serialization/ObjectMiddleware.js +23 -0
  126. package/lib/serialization/PlainObjectSerializer.js +23 -12
  127. package/lib/serialization/RegExpObjectSerializer.js +16 -5
  128. package/lib/serialization/SetObjectSerializer.js +21 -6
  129. package/lib/sharing/ShareRuntimeModule.js +1 -1
  130. package/lib/util/makeSerializable.js +7 -0
  131. package/lib/util/serialization.js +10 -0
  132. package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -1
  133. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +5 -1
  134. package/package.json +3 -3
  135. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  136. package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
  137. package/types.d.ts +469 -149
@@ -25,30 +25,39 @@ const {
25
25
  } = require("./target");
26
26
 
27
27
  /** @typedef {import("../../declarations/WebpackOptions").CacheOptionsNormalized} CacheOptions */
28
+ /** @typedef {import("../../declarations/WebpackOptions").Context} Context */
28
29
  /** @typedef {import("../../declarations/WebpackOptions").CssExperimentOptions} CssExperimentOptions */
29
30
  /** @typedef {import("../../declarations/WebpackOptions").EntryDescription} EntryDescription */
30
31
  /** @typedef {import("../../declarations/WebpackOptions").EntryNormalized} Entry */
32
+ /** @typedef {import("../../declarations/WebpackOptions").EntryStaticNormalized} EntryStaticNormalized */
33
+ /** @typedef {import("../../declarations/WebpackOptions").Environment} Environment */
31
34
  /** @typedef {import("../../declarations/WebpackOptions").Experiments} Experiments */
32
35
  /** @typedef {import("../../declarations/WebpackOptions").ExperimentsNormalized} ExperimentsNormalized */
33
36
  /** @typedef {import("../../declarations/WebpackOptions").ExternalsPresets} ExternalsPresets */
34
37
  /** @typedef {import("../../declarations/WebpackOptions").ExternalsType} ExternalsType */
38
+ /** @typedef {import("../../declarations/WebpackOptions").FileCacheOptions} FileCacheOptions */
35
39
  /** @typedef {import("../../declarations/WebpackOptions").InfrastructureLogging} InfrastructureLogging */
36
40
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
37
41
  /** @typedef {import("../../declarations/WebpackOptions").Library} Library */
38
42
  /** @typedef {import("../../declarations/WebpackOptions").LibraryName} LibraryName */
39
43
  /** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
44
+ /** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
40
45
  /** @typedef {import("../../declarations/WebpackOptions").Loader} Loader */
41
46
  /** @typedef {import("../../declarations/WebpackOptions").Mode} Mode */
42
47
  /** @typedef {import("../../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
43
48
  /** @typedef {import("../../declarations/WebpackOptions").Node} WebpackNode */
44
49
  /** @typedef {import("../../declarations/WebpackOptions").Optimization} Optimization */
50
+ /** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksOptions} OptimizationSplitChunksOptions */
45
51
  /** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} Output */
52
+ /** @typedef {import("../../declarations/WebpackOptions").ParserOptionsByModuleTypeKnown} ParserOptionsByModuleTypeKnown */
46
53
  /** @typedef {import("../../declarations/WebpackOptions").Performance} Performance */
47
54
  /** @typedef {import("../../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
48
55
  /** @typedef {import("../../declarations/WebpackOptions").RuleSetRules} RuleSetRules */
49
56
  /** @typedef {import("../../declarations/WebpackOptions").SnapshotOptions} SnapshotOptions */
50
57
  /** @typedef {import("../../declarations/WebpackOptions").Target} Target */
51
58
  /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
59
+ /** @typedef {import("../Compiler")} Compiler */
60
+ /** @typedef {import("../Module")} Module */
52
61
  /** @typedef {import("./target").TargetProperties} TargetProperties */
53
62
 
54
63
  const NODE_MODULES_REGEXP = /[\\/]node_modules[\\/]/i;
@@ -100,7 +109,7 @@ const A = (obj, prop, factory) => {
100
109
  if (value === undefined) {
101
110
  obj[prop] = factory();
102
111
  } else if (Array.isArray(value)) {
103
- /** @type {any[]} */
112
+ /** @type {any[] | undefined} */
104
113
  let newArray = undefined;
105
114
  for (let i = 0; i < value.length; i++) {
106
115
  const item = value[i];
@@ -138,7 +147,7 @@ const applyWebpackOptionsBaseDefaults = options => {
138
147
  const applyWebpackOptionsDefaults = options => {
139
148
  F(options, "context", () => process.cwd());
140
149
  F(options, "target", () => {
141
- return getDefaultTarget(options.context);
150
+ return getDefaultTarget(/** @type {string} */ (options.context));
142
151
  });
143
152
 
144
153
  const { mode, name, target } = options;
@@ -147,8 +156,11 @@ const applyWebpackOptionsDefaults = options => {
147
156
  target === false
148
157
  ? /** @type {false} */ (false)
149
158
  : typeof target === "string"
150
- ? getTargetProperties(target, options.context)
151
- : getTargetsProperties(target, options.context);
159
+ ? getTargetProperties(target, /** @type {Context} */ (options.context))
160
+ : getTargetsProperties(
161
+ /** @type {string[]} */ (target),
162
+ /** @type {Context} */ (options.context)
163
+ );
152
164
 
153
165
  const development = mode === "development";
154
166
  const production = mode === "production" || !mode;
@@ -176,7 +188,9 @@ const applyWebpackOptionsDefaults = options => {
176
188
  targetProperties
177
189
  });
178
190
 
179
- const futureDefaults = options.experiments.futureDefaults;
191
+ const futureDefaults =
192
+ /** @type {NonNullable<ExperimentsNormalized["futureDefaults"]>} */
193
+ (options.experiments.futureDefaults);
180
194
 
181
195
  F(options, "cache", () =>
182
196
  development ? { type: /** @type {"memory"} */ ("memory") } : false
@@ -196,22 +210,30 @@ const applyWebpackOptionsDefaults = options => {
196
210
 
197
211
  applyModuleDefaults(options.module, {
198
212
  cache,
199
- syncWebAssembly: options.experiments.syncWebAssembly,
200
- asyncWebAssembly: options.experiments.asyncWebAssembly,
201
- css: options.experiments.css,
213
+ syncWebAssembly:
214
+ /** @type {NonNullable<ExperimentsNormalized["syncWebAssembly"]>} */
215
+ (options.experiments.syncWebAssembly),
216
+ asyncWebAssembly:
217
+ /** @type {NonNullable<ExperimentsNormalized["asyncWebAssembly"]>} */
218
+ (options.experiments.asyncWebAssembly),
219
+ css:
220
+ /** @type {NonNullable<ExperimentsNormalized["css"]>} */
221
+ (options.experiments.css),
202
222
  futureDefaults,
203
223
  isNode: targetProperties && targetProperties.node === true
204
224
  });
205
225
 
206
226
  applyOutputDefaults(options.output, {
207
- context: options.context,
227
+ context: /** @type {Context} */ (options.context),
208
228
  targetProperties,
209
229
  isAffectedByBrowserslist:
210
230
  target === undefined ||
211
231
  (typeof target === "string" && target.startsWith("browserslist")) ||
212
232
  (Array.isArray(target) &&
213
233
  target.some(target => target.startsWith("browserslist"))),
214
- outputModule: options.experiments.outputModule,
234
+ outputModule:
235
+ /** @type {NonNullable<ExperimentsNormalized["outputModule"]>} */
236
+ (options.experiments.outputModule),
215
237
  development,
216
238
  entry: options.entry,
217
239
  module: options.module,
@@ -223,7 +245,10 @@ const applyWebpackOptionsDefaults = options => {
223
245
  buildHttp: !!options.experiments.buildHttp
224
246
  });
225
247
 
226
- applyLoaderDefaults(options.loader, { targetProperties });
248
+ applyLoaderDefaults(
249
+ /** @type {NonNullable<WebpackOptions["loader"]>} */ (options.loader),
250
+ { targetProperties }
251
+ );
227
252
 
228
253
  F(options, "externalsType", () => {
229
254
  const validExternalTypes = require("../../schemas/WebpackOptions.json")
@@ -237,7 +262,9 @@ const applyWebpackOptionsDefaults = options => {
237
262
  });
238
263
 
239
264
  applyNodeDefaults(options.node, {
240
- futureDefaults: options.experiments.futureDefaults,
265
+ futureDefaults:
266
+ /** @type {NonNullable<WebpackOptions["experiments"]["futureDefaults"]>} */
267
+ (options.experiments.futureDefaults),
241
268
  targetProperties
242
269
  });
243
270
 
@@ -248,23 +275,29 @@ const applyWebpackOptionsDefaults = options => {
248
275
  ? {}
249
276
  : false
250
277
  );
251
- applyPerformanceDefaults(options.performance, {
252
- production
253
- });
278
+ applyPerformanceDefaults(
279
+ /** @type {NonNullable<WebpackOptions["performance"]>} */
280
+ (options.performance),
281
+ {
282
+ production
283
+ }
284
+ );
254
285
 
255
286
  applyOptimizationDefaults(options.optimization, {
256
287
  development,
257
288
  production,
258
- css: options.experiments.css,
289
+ css:
290
+ /** @type {NonNullable<ExperimentsNormalized["css"]>} */
291
+ (options.experiments.css),
259
292
  records: !!(options.recordsInputPath || options.recordsOutputPath)
260
293
  });
261
294
 
262
295
  options.resolve = cleverMerge(
263
296
  getResolveDefaults({
264
297
  cache,
265
- context: options.context,
298
+ context: /** @type {Context} */ (options.context),
266
299
  targetProperties,
267
- mode: options.mode
300
+ mode: /** @type {Mode} */ (options.mode)
268
301
  }),
269
302
  options.resolve
270
303
  );
@@ -323,9 +356,9 @@ const applyExperimentsDefaults = (
323
356
  * @param {CacheOptions} cache options
324
357
  * @param {Object} options options
325
358
  * @param {string} options.name name
326
- * @param {string} options.mode mode
359
+ * @param {Mode} options.mode mode
327
360
  * @param {boolean} options.development is development mode
328
- * @param {boolean} options.cacheUnaffected the cacheUnaffected experiment is enabled
361
+ * @param {Experiments["cacheUnaffected"]} options.cacheUnaffected the cacheUnaffected experiment is enabled
329
362
  * @returns {void}
330
363
  */
331
364
  const applyCacheDefaults = (
@@ -339,6 +372,7 @@ const applyCacheDefaults = (
339
372
  D(cache, "version", "");
340
373
  F(cache, "cacheDirectory", () => {
341
374
  const cwd = process.cwd();
375
+ /** @type {string | undefined} */
342
376
  let dir = cwd;
343
377
  for (;;) {
344
378
  try {
@@ -363,7 +397,11 @@ const applyCacheDefaults = (
363
397
  }
364
398
  });
365
399
  F(cache, "cacheLocation", () =>
366
- path.resolve(cache.cacheDirectory, cache.name)
400
+ path.resolve(
401
+ /** @type {NonNullable<FileCacheOptions["cacheDirectory"]>} */
402
+ (cache.cacheDirectory),
403
+ /** @type {NonNullable<FileCacheOptions["name"]>} */ (cache.name)
404
+ )
367
405
  );
368
406
  D(cache, "hashAlgorithm", "md4");
369
407
  D(cache, "store", "pack");
@@ -376,9 +414,12 @@ const applyCacheDefaults = (
376
414
  D(cache, "maxAge", 1000 * 60 * 60 * 24 * 60); // 1 month
377
415
  D(cache, "allowCollectingMemory", development);
378
416
  D(cache, "memoryCacheUnaffected", development && cacheUnaffected);
379
- D(cache.buildDependencies, "defaultWebpack", [
380
- path.resolve(__dirname, "..") + path.sep
381
- ]);
417
+ D(
418
+ /** @type {NonNullable<FileCacheOptions["buildDependencies"]>} */
419
+ (cache.buildDependencies),
420
+ "defaultWebpack",
421
+ [path.resolve(__dirname, "..") + path.sep]
422
+ );
382
423
  break;
383
424
  case "memory":
384
425
  D(cache, "maxGenerations", Infinity);
@@ -510,25 +551,53 @@ const applyModuleDefaults = (
510
551
  { cache, syncWebAssembly, asyncWebAssembly, css, futureDefaults, isNode }
511
552
  ) => {
512
553
  if (cache) {
513
- D(module, "unsafeCache", module => {
514
- const name = module.nameForCondition();
515
- return name && NODE_MODULES_REGEXP.test(name);
516
- });
554
+ D(
555
+ module,
556
+ "unsafeCache",
557
+ /**
558
+ * @param {Module} module module
559
+ * @returns {boolean | null | string} true, if we want to cache the module
560
+ */
561
+ module => {
562
+ const name = module.nameForCondition();
563
+ return name && NODE_MODULES_REGEXP.test(name);
564
+ }
565
+ );
517
566
  } else {
518
567
  D(module, "unsafeCache", false);
519
568
  }
520
569
 
521
570
  F(module.parser, ASSET_MODULE_TYPE, () => ({}));
522
- F(module.parser.asset, "dataUrlCondition", () => ({}));
523
- if (typeof module.parser.asset.dataUrlCondition === "object") {
524
- D(module.parser.asset.dataUrlCondition, "maxSize", 8096);
571
+ F(
572
+ /** @type {NonNullable<ParserOptionsByModuleTypeKnown["asset"]>} */
573
+ (module.parser.asset),
574
+ "dataUrlCondition",
575
+ () => ({})
576
+ );
577
+ if (
578
+ typeof (
579
+ /** @type {NonNullable<ParserOptionsByModuleTypeKnown["asset"]>} */
580
+ (module.parser.asset).dataUrlCondition
581
+ ) === "object"
582
+ ) {
583
+ D(
584
+ /** @type {NonNullable<ParserOptionsByModuleTypeKnown["asset"]>} */
585
+ (module.parser.asset).dataUrlCondition,
586
+ "maxSize",
587
+ 8096
588
+ );
525
589
  }
526
590
 
527
591
  F(module.parser, "javascript", () => ({}));
528
- applyJavascriptParserOptionsDefaults(module.parser.javascript, {
529
- futureDefaults,
530
- isNode
531
- });
592
+
593
+ applyJavascriptParserOptionsDefaults(
594
+ /** @type {NonNullable<ParserOptionsByModuleTypeKnown["javascript"]>} */
595
+ (module.parser.javascript),
596
+ {
597
+ futureDefaults,
598
+ isNode
599
+ }
600
+ );
532
601
 
533
602
  A(module, "defaultRules", () => {
534
603
  const esm = {
@@ -726,7 +795,7 @@ const applyOutputDefaults = (
726
795
  !Array.isArray(library) &&
727
796
  "type" in library
728
797
  ? library.name
729
- : /** @type {LibraryName=} */ (library);
798
+ : /** @type {LibraryName} */ (library);
730
799
  if (Array.isArray(libraryName)) {
731
800
  return libraryName.join(".");
732
801
  } else if (typeof libraryName === "object") {
@@ -753,8 +822,11 @@ const applyOutputDefaults = (
753
822
  const packageInfo = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
754
823
  return packageInfo.name || "";
755
824
  } catch (e) {
756
- if (e.code !== "ENOENT") {
757
- e.message += `\nwhile determining default 'output.uniqueName' from 'name' in ${pkgPath}`;
825
+ if (/** @type {Error & { code: string }} */ (e).code !== "ENOENT") {
826
+ /** @type {Error & { code: string }} */
827
+ (
828
+ e
829
+ ).message += `\nwhile determining default 'output.uniqueName' from 'name' in ${pkgPath}`;
758
830
  throw e;
759
831
  }
760
832
  return "";
@@ -767,7 +839,9 @@ const applyOutputDefaults = (
767
839
  D(output, "importFunctionName", "import");
768
840
  D(output, "importMetaName", "import.meta");
769
841
  F(output, "chunkFilename", () => {
770
- const filename = output.filename;
842
+ const filename =
843
+ /** @type {NonNullable<Output["chunkFilename"]>} */
844
+ (output.filename);
771
845
  if (typeof filename !== "function") {
772
846
  const hasName = filename.includes("[name]");
773
847
  const hasId = filename.includes("[id]");
@@ -781,14 +855,18 @@ const applyOutputDefaults = (
781
855
  return output.module ? "[id].mjs" : "[id].js";
782
856
  });
783
857
  F(output, "cssFilename", () => {
784
- const filename = output.filename;
858
+ const filename =
859
+ /** @type {NonNullable<Output["cssFilename"]>} */
860
+ (output.filename);
785
861
  if (typeof filename !== "function") {
786
862
  return filename.replace(/\.[mc]?js(\?|$)/, ".css$1");
787
863
  }
788
864
  return "[id].css";
789
865
  });
790
866
  F(output, "cssChunkFilename", () => {
791
- const chunkFilename = output.chunkFilename;
867
+ const chunkFilename =
868
+ /** @type {NonNullable<Output["cssChunkFilename"]>} */
869
+ (output.chunkFilename);
792
870
  if (typeof chunkFilename !== "function") {
793
871
  return chunkFilename.replace(/\.[mc]?js(\?|$)/, ".css$1");
794
872
  }
@@ -800,12 +878,18 @@ const applyOutputDefaults = (
800
878
  D(output, "charset", true);
801
879
  F(output, "hotUpdateGlobal", () =>
802
880
  Template.toIdentifier(
803
- "webpackHotUpdate" + Template.toIdentifier(output.uniqueName)
881
+ "webpackHotUpdate" +
882
+ Template.toIdentifier(
883
+ /** @type {NonNullable<Output["uniqueName"]>} */ (output.uniqueName)
884
+ )
804
885
  )
805
886
  );
806
887
  F(output, "chunkLoadingGlobal", () =>
807
888
  Template.toIdentifier(
808
- "webpackChunk" + Template.toIdentifier(output.uniqueName)
889
+ "webpackChunk" +
890
+ Template.toIdentifier(
891
+ /** @type {NonNullable<Output["uniqueName"]>} */ (output.uniqueName)
892
+ )
809
893
  )
810
894
  );
811
895
  F(output, "globalObject", () => {
@@ -938,26 +1022,56 @@ const applyOutputDefaults = (
938
1022
  D(output, "hashDigestLength", futureDefaults ? 16 : 20);
939
1023
  D(output, "strictModuleExceptionHandling", false);
940
1024
 
1025
+ const environment = /** @type {Environment} */ (output.environment);
1026
+ /**
1027
+ * @param {boolean | undefined} v value
1028
+ * @returns {boolean} true, when v is truthy or undefined
1029
+ */
941
1030
  const optimistic = v => v || v === undefined;
1031
+ /**
1032
+ * @param {boolean | undefined} v value
1033
+ * @param {boolean | undefined} c condition
1034
+ * @returns {boolean | undefined} true, when v is truthy or undefined, or c is truthy
1035
+ */
942
1036
  const conditionallyOptimistic = (v, c) => (v === undefined && c) || v;
943
1037
  F(
944
- output.environment,
1038
+ environment,
945
1039
  "arrowFunction",
946
- () => tp && optimistic(tp.arrowFunction)
1040
+ () =>
1041
+ tp && optimistic(/** @type {boolean | undefined} */ (tp.arrowFunction))
1042
+ );
1043
+ F(
1044
+ environment,
1045
+ "const",
1046
+ () => tp && optimistic(/** @type {boolean | undefined} */ (tp.const))
947
1047
  );
948
- F(output.environment, "const", () => tp && optimistic(tp.const));
949
1048
  F(
950
- output.environment,
1049
+ environment,
951
1050
  "destructuring",
952
- () => tp && optimistic(tp.destructuring)
1051
+ () =>
1052
+ tp && optimistic(/** @type {boolean | undefined} */ (tp.destructuring))
953
1053
  );
954
- F(output.environment, "forOf", () => tp && optimistic(tp.forOf));
955
- F(output.environment, "bigIntLiteral", () => tp && tp.bigIntLiteral);
956
- F(output.environment, "dynamicImport", () =>
957
- conditionallyOptimistic(tp && tp.dynamicImport, output.module)
1054
+ F(
1055
+ environment,
1056
+ "forOf",
1057
+ () => tp && optimistic(/** @type {boolean | undefined} */ (tp.forOf))
958
1058
  );
959
- F(output.environment, "module", () =>
960
- conditionallyOptimistic(tp && tp.module, output.module)
1059
+ F(
1060
+ environment,
1061
+ "bigIntLiteral",
1062
+ () => /** @type {boolean | undefined} */ (tp && tp.bigIntLiteral)
1063
+ );
1064
+ F(environment, "dynamicImport", () =>
1065
+ conditionallyOptimistic(
1066
+ /** @type {boolean | undefined} */ (tp && tp.dynamicImport),
1067
+ output.module
1068
+ )
1069
+ );
1070
+ F(environment, "module", () =>
1071
+ conditionallyOptimistic(
1072
+ /** @type {boolean | undefined} */ (tp && tp.module),
1073
+ output.module
1074
+ )
961
1075
  );
962
1076
 
963
1077
  const { trustedTypes } = output;
@@ -966,7 +1080,8 @@ const applyOutputDefaults = (
966
1080
  trustedTypes,
967
1081
  "policyName",
968
1082
  () =>
969
- output.uniqueName.replace(/[^a-zA-Z0-9\-#=_/@.%]+/g, "_") || "webpack"
1083
+ /** @type {NonNullable<Output["uniqueName"]>} */
1084
+ (output.uniqueName).replace(/[^a-zA-Z0-9\-#=_/@.%]+/g, "_") || "webpack"
970
1085
  );
971
1086
  D(trustedTypes, "onPolicyCreationFailure", "stop");
972
1087
  }
@@ -977,10 +1092,11 @@ const applyOutputDefaults = (
977
1092
  */
978
1093
  const forEachEntry = fn => {
979
1094
  for (const name of Object.keys(entry)) {
980
- fn(entry[name]);
1095
+ fn(/** @type {{[k: string] : EntryDescription}} */ (entry)[name]);
981
1096
  }
982
1097
  };
983
1098
  A(output, "enabledLibraryTypes", () => {
1099
+ /** @type {LibraryType[]} */
984
1100
  const enabledLibraryTypes = [];
985
1101
  if (output.library) {
986
1102
  enabledLibraryTypes.push(output.library.type);
@@ -1040,35 +1156,56 @@ const applyExternalsPresetsDefaults = (
1040
1156
  D(
1041
1157
  externalsPresets,
1042
1158
  "web",
1043
- !buildHttp && targetProperties && targetProperties.web
1159
+ /** @type {boolean | undefined} */
1160
+ (!buildHttp && targetProperties && targetProperties.web)
1161
+ );
1162
+ D(
1163
+ externalsPresets,
1164
+ "node",
1165
+ /** @type {boolean | undefined} */
1166
+ (targetProperties && targetProperties.node)
1167
+ );
1168
+ D(
1169
+ externalsPresets,
1170
+ "nwjs",
1171
+ /** @type {boolean | undefined} */
1172
+ (targetProperties && targetProperties.nwjs)
1044
1173
  );
1045
- D(externalsPresets, "node", targetProperties && targetProperties.node);
1046
- D(externalsPresets, "nwjs", targetProperties && targetProperties.nwjs);
1047
1174
  D(
1048
1175
  externalsPresets,
1049
1176
  "electron",
1050
- targetProperties && targetProperties.electron
1177
+ /** @type {boolean | undefined} */
1178
+ (targetProperties && targetProperties.electron)
1051
1179
  );
1052
1180
  D(
1053
1181
  externalsPresets,
1054
1182
  "electronMain",
1055
- targetProperties &&
1056
- targetProperties.electron &&
1057
- targetProperties.electronMain
1183
+ /** @type {boolean | undefined} */
1184
+ (
1185
+ targetProperties &&
1186
+ targetProperties.electron &&
1187
+ targetProperties.electronMain
1188
+ )
1058
1189
  );
1059
1190
  D(
1060
1191
  externalsPresets,
1061
1192
  "electronPreload",
1062
- targetProperties &&
1063
- targetProperties.electron &&
1064
- targetProperties.electronPreload
1193
+ /** @type {boolean | undefined} */
1194
+ (
1195
+ targetProperties &&
1196
+ targetProperties.electron &&
1197
+ targetProperties.electronPreload
1198
+ )
1065
1199
  );
1066
1200
  D(
1067
1201
  externalsPresets,
1068
1202
  "electronRenderer",
1069
- targetProperties &&
1070
- targetProperties.electron &&
1071
- targetProperties.electronRenderer
1203
+ /** @type {boolean | undefined} */
1204
+ (
1205
+ targetProperties &&
1206
+ targetProperties.electron &&
1207
+ targetProperties.electronRenderer
1208
+ )
1072
1209
  );
1073
1210
  };
1074
1211
 
@@ -1209,7 +1346,9 @@ const applyOptimizationDefaults = (
1209
1346
  F(splitChunks, "maxAsyncRequests", () => (production ? 30 : Infinity));
1210
1347
  F(splitChunks, "maxInitialRequests", () => (production ? 30 : Infinity));
1211
1348
  D(splitChunks, "automaticNameDelimiter", "-");
1212
- const { cacheGroups } = splitChunks;
1349
+ const cacheGroups =
1350
+ /** @type {NonNullable<OptimizationSplitChunksOptions["cacheGroups"]>} */
1351
+ (splitChunks.cacheGroups);
1213
1352
  F(cacheGroups, "default", () => ({
1214
1353
  idHint: "",
1215
1354
  reuseExistingChunk: true,