webpack 5.99.5 → 5.99.6

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 (87) hide show
  1. package/README.md +1 -1
  2. package/lib/APIPlugin.js +2 -2
  3. package/lib/Cache.js +1 -1
  4. package/lib/Chunk.js +12 -9
  5. package/lib/Compilation.js +36 -27
  6. package/lib/Compiler.js +4 -3
  7. package/lib/ContextModule.js +2 -1
  8. package/lib/HotModuleReplacementPlugin.js +3 -3
  9. package/lib/Module.js +10 -2
  10. package/lib/ModuleFilenameHelpers.js +1 -1
  11. package/lib/ModuleGraph.js +15 -10
  12. package/lib/NormalModule.js +1 -1
  13. package/lib/PrefetchPlugin.js +1 -1
  14. package/lib/RecordIdsPlugin.js +1 -1
  15. package/lib/SourceMapDevToolPlugin.js +1 -1
  16. package/lib/Template.js +1 -1
  17. package/lib/WebpackOptionsApply.js +17 -2
  18. package/lib/buildChunkGraph.js +7 -2
  19. package/lib/cache/IdleFileCachePlugin.js +1 -1
  20. package/lib/cache/MemoryCachePlugin.js +2 -1
  21. package/lib/cache/MemoryWithGcCachePlugin.js +3 -2
  22. package/lib/cache/PackFileCacheStrategy.js +13 -21
  23. package/lib/cache/ResolverCachePlugin.js +14 -16
  24. package/lib/cli.js +3 -3
  25. package/lib/config/defaults.js +2 -2
  26. package/lib/config/target.js +6 -6
  27. package/lib/css/CssParser.js +1 -1
  28. package/lib/debug/ProfilingPlugin.js +1 -1
  29. package/lib/dependencies/ContextDependencyHelpers.js +1 -1
  30. package/lib/dependencies/CssIcssImportDependency.js +3 -2
  31. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  32. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
  33. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -1
  34. package/lib/dependencies/JsonExportsDependency.js +1 -1
  35. package/lib/dependencies/LocalModulesHelpers.js +1 -1
  36. package/lib/dependencies/RequireResolveDependency.js +1 -1
  37. package/lib/dependencies/WorkerPlugin.js +2 -2
  38. package/lib/esm/ModuleChunkLoadingPlugin.js +20 -0
  39. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +11 -9
  40. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  41. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  42. package/lib/ids/NamedChunkIdsPlugin.js +2 -2
  43. package/lib/ids/NamedModuleIdsPlugin.js +2 -2
  44. package/lib/index.js +1 -1
  45. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  46. package/lib/javascript/JavascriptParser.js +41 -37
  47. package/lib/library/EnableLibraryPlugin.js +15 -2
  48. package/lib/library/ModuleLibraryPlugin.js +6 -1
  49. package/lib/logging/createConsoleLogger.js +0 -1
  50. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -2
  51. package/lib/node/NodeTemplatePlugin.js +2 -2
  52. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
  53. package/lib/node/ReadFileCompileWasmPlugin.js +3 -3
  54. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  55. package/lib/optimize/SplitChunksPlugin.js +2 -1
  56. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
  57. package/lib/serialization/BinaryMiddleware.js +22 -38
  58. package/lib/serialization/FileMiddleware.js +29 -33
  59. package/lib/serialization/ObjectMiddleware.js +29 -30
  60. package/lib/serialization/Serializer.js +29 -18
  61. package/lib/serialization/SerializerMiddleware.js +105 -72
  62. package/lib/serialization/SingleItemMiddleware.js +4 -5
  63. package/lib/stats/DefaultStatsFactoryPlugin.js +39 -24
  64. package/lib/stats/DefaultStatsPrinterPlugin.js +267 -80
  65. package/lib/stats/StatsFactory.js +47 -10
  66. package/lib/stats/StatsPrinter.js +52 -31
  67. package/lib/util/ArrayQueue.js +1 -1
  68. package/lib/util/AsyncQueue.js +1 -1
  69. package/lib/util/TupleQueue.js +9 -7
  70. package/lib/util/TupleSet.js +37 -18
  71. package/lib/util/WeakTupleMap.js +50 -37
  72. package/lib/util/cleverMerge.js +2 -2
  73. package/lib/util/comparators.js +1 -1
  74. package/lib/util/createHash.js +1 -1
  75. package/lib/util/fs.js +1 -1
  76. package/lib/util/makeSerializable.js +1 -1
  77. package/lib/util/runtime.js +1 -0
  78. package/lib/util/serialization.js +50 -42
  79. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  80. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -1
  81. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  82. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -1
  83. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  84. package/lib/web/FetchCompileWasmPlugin.js +2 -2
  85. package/lib/webpack.js +1 -1
  86. package/package.json +1 -1
  87. package/types.d.ts +125 -73
@@ -8,6 +8,7 @@
8
8
  const Cache = require("../Cache");
9
9
 
10
10
  /** @typedef {import("webpack-sources").Source} Source */
11
+ /** @typedef {import("../Cache").Data} Data */
11
12
  /** @typedef {import("../Cache").Etag} Etag */
12
13
  /** @typedef {import("../Compiler")} Compiler */
13
14
  /** @typedef {import("../Module")} Module */
@@ -32,9 +33,9 @@ class MemoryWithGcCachePlugin {
32
33
  */
33
34
  apply(compiler) {
34
35
  const maxGenerations = this._maxGenerations;
35
- /** @type {Map<string, { etag: Etag | null, data: any } | undefined | null>} */
36
+ /** @type {Map<string, { etag: Etag | null, data: Data } | undefined | null>} */
36
37
  const cache = new Map();
37
- /** @type {Map<string, { entry: { etag: Etag | null, data: any } | null, until: number }>} */
38
+ /** @type {Map<string, { entry: { etag: Etag | null, data: Data } | null, until: number }>} */
38
39
  const oldCache = new Map();
39
40
  let generation = 0;
40
41
  let cachePosition = 0;
@@ -18,6 +18,7 @@ const {
18
18
  } = require("../util/serialization");
19
19
 
20
20
  /** @typedef {import("../../declarations/WebpackOptions").SnapshotOptions} SnapshotOptions */
21
+ /** @typedef {import("../Cache").Data} Data */
21
22
  /** @typedef {import("../Cache").Etag} Etag */
22
23
  /** @typedef {import("../Compiler")} Compiler */
23
24
  /** @typedef {import("../FileSystemInfo").ResolveBuildDependenciesResult} ResolveBuildDependenciesResult */
@@ -96,14 +97,11 @@ const MIN_ITEMS_IN_FRESH_PACK = 100;
96
97
  const MAX_ITEMS_IN_FRESH_PACK = 50000;
97
98
  const MAX_TIME_IN_FRESH_PACK = 1 * 60 * 1000; // 1 min
98
99
 
99
- /** @typedef {TODO | undefined} Value */
100
- /** @typedef {TODO | undefined} LazyValue */
101
-
102
100
  class PackItemInfo {
103
101
  /**
104
102
  * @param {string} identifier identifier of item
105
103
  * @param {string | null | undefined} etag etag of item
106
- * @param {Value} value fresh value of item
104
+ * @param {Data} value fresh value of item
107
105
  */
108
106
  constructor(identifier, etag, value) {
109
107
  this.identifier = identifier;
@@ -158,7 +156,7 @@ class Pack {
158
156
  /**
159
157
  * @param {string} identifier unique name for the resource
160
158
  * @param {string | null} etag etag of the resource
161
- * @returns {Value} cached content
159
+ * @returns {Data} cached content
162
160
  */
163
161
  get(identifier, etag) {
164
162
  const info = this.itemInfo.get(identifier);
@@ -181,7 +179,7 @@ class Pack {
181
179
  /**
182
180
  * @param {string} identifier unique name for the resource
183
181
  * @param {string | null} etag etag of the resource
184
- * @param {Value} data cached content
182
+ * @param {Data} data cached content
185
183
  * @returns {void}
186
184
  */
187
185
  set(identifier, etag, data) {
@@ -667,7 +665,7 @@ class Pack {
667
665
 
668
666
  makeSerializable(Pack, "webpack/lib/cache/PackFileCacheStrategy", "Pack");
669
667
 
670
- /** @typedef {Map<string, Value>} Content */
668
+ /** @typedef {Map<string, Data>} Content */
671
669
 
672
670
  class PackContentItems {
673
671
  /**
@@ -799,7 +797,7 @@ makeSerializable(
799
797
  "PackContentItems"
800
798
  );
801
799
 
802
- /** @typedef {(() => Promise<PackContentItems> | PackContentItems)} LazyFunction */
800
+ /** @typedef {(() => Promise<PackContentItems> | PackContentItems) & Partial<{ options: { size?: number }}>} LazyFunction */
803
801
 
804
802
  class PackContent {
805
803
  /*
@@ -830,7 +828,7 @@ class PackContent {
830
828
  */
831
829
  constructor(items, usedItems, dataOrFn, logger, lazyName) {
832
830
  this.items = items;
833
- /** @type {LazyValue} */
831
+ /** @type {LazyFunction | undefined} */
834
832
  this.lazy = typeof dataOrFn === "function" ? dataOrFn : undefined;
835
833
  /** @type {Content | undefined} */
836
834
  this.content = typeof dataOrFn === "function" ? undefined : dataOrFn.map;
@@ -877,10 +875,7 @@ class PackContent {
877
875
  }
878
876
  // Move to state C
879
877
  this.content = map;
880
- this.lazy = SerializerMiddleware.unMemoizeLazy(
881
- /** @type {LazyFunction} */
882
- (this.lazy)
883
- );
878
+ this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy);
884
879
  return map.get(identifier);
885
880
  });
886
881
  }
@@ -891,10 +886,7 @@ class PackContent {
891
886
  }
892
887
  // Move to state C
893
888
  this.content = map;
894
- this.lazy = SerializerMiddleware.unMemoizeLazy(
895
- /** @type {LazyFunction} */
896
- (this.lazy)
897
- );
889
+ this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy);
898
890
  return map.get(identifier);
899
891
  }
900
892
 
@@ -966,8 +958,7 @@ class PackContent {
966
958
  }
967
959
 
968
960
  /**
969
- * @template T
970
- * @param {(item?: LazyValue) => (() => Promise<PackContentItems> | PackContentItems)} write write function
961
+ * @param {(lazy: LazyFunction) => (() => PackContentItems | Promise<PackContentItems>)} write write function
971
962
  * @returns {void}
972
963
  */
973
964
  writeLazy(write) {
@@ -1100,6 +1091,7 @@ class PackFileCacheStrategy {
1100
1091
  compression,
1101
1092
  readonly
1102
1093
  }) {
1094
+ /** @type {import("../serialization/Serializer")<PackContainer, null, {}>} */
1103
1095
  this.fileSerializer = createFileSerializer(
1104
1096
  fs,
1105
1097
  /** @type {string | Hash} */
@@ -1319,7 +1311,7 @@ class PackFileCacheStrategy {
1319
1311
  /**
1320
1312
  * @param {string} identifier unique name for the resource
1321
1313
  * @param {Etag | null} etag etag of the resource
1322
- * @param {Value} data cached content
1314
+ * @param {Data} data cached content
1323
1315
  * @returns {Promise<void>} promise
1324
1316
  */
1325
1317
  store(identifier, etag, data) {
@@ -1333,7 +1325,7 @@ class PackFileCacheStrategy {
1333
1325
  /**
1334
1326
  * @param {string} identifier unique name for the resource
1335
1327
  * @param {Etag | null} etag etag of the resource
1336
- * @returns {Promise<Value>} promise to the cached content
1328
+ * @returns {Promise<Data>} promise to the cached content
1337
1329
  */
1338
1330
  restore(identifier, etag) {
1339
1331
  return this._getPack()
@@ -95,6 +95,8 @@ const objectToString = (object, excludeContext) => {
95
95
  return str;
96
96
  };
97
97
 
98
+ /** @typedef {NonNullable<ResolveContext["yield"]>} Yield */
99
+
98
100
  class ResolverCachePlugin {
99
101
  /**
100
102
  * Apply the plugin
@@ -253,13 +255,17 @@ class ResolverCachePlugin {
253
255
  /** @typedef {(err?: Error, resolveRequest?: ResolveRequest) => void} ActiveRequest */
254
256
  /** @type {Map<string, ActiveRequest[]>} */
255
257
  const activeRequests = new Map();
256
- /** @type {Map<string, [ActiveRequest, NonNullable<ResolveContext["yield"]>][]>} */
258
+ /** @type {Map<string, [ActiveRequest[], Yield[]]>} */
257
259
  const activeRequestsWithYield = new Map();
258
260
  const hook =
259
261
  /** @type {SyncHook<[Resolver, ResolveOptions, ResolveOptionsWithDependencyType]>} */
260
262
  (_hook);
261
263
  hook.tap("ResolverCachePlugin", (resolver, options, userOptions) => {
262
- if (/** @type {TODO} */ (options).cache !== true) return;
264
+ if (
265
+ /** @type {ResolveOptions & { cache: boolean }} */
266
+ (options).cache !== true
267
+ )
268
+ return;
263
269
  const optionsIdent = objectToString(userOptions, false);
264
270
  const cacheWithContext =
265
271
  options.cacheWithContext !== undefined
@@ -288,7 +294,7 @@ class ResolverCachePlugin {
288
294
  if (activeRequest) {
289
295
  activeRequest[0].push(callback);
290
296
  activeRequest[1].push(
291
- /** @type {NonNullable<ResolveContext["yield"]>} */
297
+ /** @type {Yield} */
292
298
  (resolveContext.yield)
293
299
  );
294
300
  return;
@@ -303,7 +309,7 @@ class ResolverCachePlugin {
303
309
  const itemCache = cache.getItemCache(identifier, null);
304
310
  /** @type {Callback[] | false | undefined} */
305
311
  let callbacks;
306
- /** @type {NonNullable<ResolveContext["yield"]>[] | undefined} */
312
+ /** @type {Yield[] | undefined} */
307
313
  let yields;
308
314
 
309
315
  /**
@@ -319,7 +325,7 @@ class ResolverCachePlugin {
319
325
  for (const r of /** @type {ResolveRequest[]} */ (
320
326
  result
321
327
  )) {
322
- /** @type {NonNullable<ResolveContext["yield"]>} */
328
+ /** @type {Yield} */
323
329
  (resolveContext.yield)(r);
324
330
  }
325
331
  callback(null, null);
@@ -336,9 +342,7 @@ class ResolverCachePlugin {
336
342
  } else {
337
343
  for (let i = 0; i < definedCallbacks.length; i++) {
338
344
  const cb = definedCallbacks[i];
339
- const yield_ =
340
- /** @type {NonNullable<ResolveContext["yield"]>[]} */
341
- (yields)[i];
345
+ const yield_ = /** @type {Yield[]} */ (yields)[i];
342
346
  if (result)
343
347
  for (const r of /** @type {ResolveRequest[]} */ (
344
348
  result
@@ -424,14 +428,8 @@ class ResolverCachePlugin {
424
428
  itemCache.get(processCacheResult);
425
429
  if (withYield && callbacks === undefined) {
426
430
  callbacks = [callback];
427
- yields = [
428
- /** @type {NonNullable<ResolveContext["yield"]>} */
429
- (resolveContext.yield)
430
- ];
431
- activeRequestsWithYield.set(
432
- identifier,
433
- /** @type {[any, any]} */ ([callbacks, yields])
434
- );
431
+ yields = [/** @type {Yield} */ (resolveContext.yield)];
432
+ activeRequestsWithYield.set(identifier, [callbacks, yields]);
435
433
  } else if (callbacks === undefined) {
436
434
  callbacks = [callback];
437
435
  activeRequests.set(identifier, callbacks);
package/lib/cli.js CHANGED
@@ -44,11 +44,11 @@ const webpackSchema = require("../schemas/WebpackOptions.json");
44
44
 
45
45
  /**
46
46
  * @typedef {object} ArgumentConfig
47
- * @property {string | undefined} description
48
- * @property {string} [negatedDescription]
47
+ * @property {string=} description
48
+ * @property {string=} negatedDescription
49
49
  * @property {string} path
50
50
  * @property {boolean} multiple
51
- * @property {"enum"|"string"|"path"|"number"|"boolean"|"RegExp"|"reset"} type
51
+ * @property {"enum" | "string" | "path" | "number" | "boolean" | "RegExp" | "reset"} type
52
52
  * @property {EnumValue[]=} values
53
53
  */
54
54
 
@@ -166,7 +166,7 @@ const applyWebpackOptionsBaseDefaults = options => {
166
166
 
167
167
  /**
168
168
  * @param {WebpackOptionsNormalized} options options to be modified
169
- * @param {number} [compilerIndex] index of compiler
169
+ * @param {number=} compilerIndex index of compiler
170
170
  * @returns {ResolvedOptions} Resolved options after apply defaults
171
171
  */
172
172
  const applyWebpackOptionsDefaults = (options, compilerIndex) => {
@@ -405,7 +405,7 @@ const applyExperimentsDefaults = (
405
405
  * @param {Mode} options.mode mode
406
406
  * @param {boolean} options.futureDefaults is future defaults enabled
407
407
  * @param {boolean} options.development is development mode
408
- * @param {number} [options.compilerIndex] index of compiler
408
+ * @param {number=} options.compilerIndex index of compiler
409
409
  * @param {Experiments["cacheUnaffected"]} options.cacheUnaffected the cacheUnaffected experiment is enabled
410
410
  * @returns {void}
411
411
  */
@@ -22,12 +22,12 @@ const getDefaultTarget = context => {
22
22
 
23
23
  /**
24
24
  * @typedef {object} PlatformTargetProperties
25
- * @property {boolean | null} [web] web platform, importing of http(s) and std: is available
26
- * @property {boolean | null} [browser] browser platform, running in a normal web browser
27
- * @property {boolean | null} [webworker] (Web)Worker platform, running in a web/shared/service worker
28
- * @property {boolean | null} [node] node platform, require of node built-in modules is available
29
- * @property {boolean | null} [nwjs] nwjs platform, require of legacy nw.gui is available
30
- * @property {boolean | null} [electron] electron platform, require of some electron built-in modules is available
25
+ * @property {boolean | null=} web web platform, importing of http(s) and std: is available
26
+ * @property {boolean | null=} browser browser platform, running in a normal web browser
27
+ * @property {boolean | null=} webworker (Web)Worker platform, running in a web/shared/service worker
28
+ * @property {boolean | null=} node node platform, require of node built-in modules is available
29
+ * @property {boolean | null=} nwjs nwjs platform, require of legacy nw.gui is available
30
+ * @property {boolean | null=} electron electron platform, require of some electron built-in modules is available
31
31
  */
32
32
 
33
33
  /**
@@ -293,7 +293,7 @@ const eatSemi = walkCssTokens.eatUntil(";");
293
293
 
294
294
  class CssParser extends Parser {
295
295
  /**
296
- * @param {CssParserOptions} [options] options
296
+ * @param {CssParserOptions=} options options
297
297
  */
298
298
  constructor({
299
299
  defaultMode = "pure",
@@ -88,7 +88,7 @@ class Profiler {
88
88
 
89
89
  /**
90
90
  * @param {string} method method name
91
- * @param {Record<string, EXPECTED_ANY>} [params] params
91
+ * @param {Record<string, EXPECTED_ANY>=} params params
92
92
  * @returns {Promise<TODO>} Promise for the result
93
93
  */
94
94
  sendCommand(method, params) {
@@ -42,7 +42,7 @@ const splitContextFromPrefix = prefix => {
42
42
  };
43
43
 
44
44
  /** @typedef {Partial<Omit<ContextDependencyOptions, "resource">>} PartialContextDependencyOptions */
45
- /** @typedef {{ new(options: ContextDependencyOptions, range: Range, valueRange: [number, number], ...args: any[]): ContextDependency }} ContextDependencyConstructor */
45
+ /** @typedef {{ new(options: ContextDependencyOptions, range: Range, valueRange: Range, ...args: any[]): ContextDependency }} ContextDependencyConstructor */
46
46
 
47
47
  /**
48
48
  * @param {ContextDependencyConstructor} Dep the Dependency class
@@ -16,6 +16,7 @@ const ModuleDependency = require("./ModuleDependency");
16
16
  /** @typedef {import("../DependencyTemplate").CssDependencyTemplateContext} DependencyTemplateContext */
17
17
  /** @typedef {import("../Module")} Module */
18
18
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
19
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
19
20
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
20
21
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
21
22
 
@@ -26,12 +27,12 @@ class CssIcssImportDependency extends ModuleDependency {
26
27
  *:import('./style.css') { IMPORTED_NAME: v-primary }
27
28
  * @param {string} request request request path which needs resolving
28
29
  * @param {string} exportName export name
29
- * @param {[number, number]} range the range of dependency
30
+ * @param {Range} range the range of dependency
30
31
  */
31
32
  constructor(request, exportName, range) {
32
33
  super(request);
33
- this.range = range;
34
34
  this.exportName = exportName;
35
+ this.range = range;
35
36
  }
36
37
 
37
38
  get type() {
@@ -27,7 +27,7 @@ class HarmonyExportExpressionDependency extends NullDependency {
27
27
  * @param {Range} range range
28
28
  * @param {Range} rangeStatement range statement
29
29
  * @param {string} prefix prefix
30
- * @param {string | { range: Range, prefix: string, suffix: string }} [declarationId] declaration id
30
+ * @param {string | { range: Range, prefix: string, suffix: string }=} declarationId declaration id
31
31
  */
32
32
  constructor(range, rangeStatement, prefix, declarationId) {
33
33
  super();
@@ -226,7 +226,8 @@ const getMode = (moduleGraph, dep, runtimeKey) => {
226
226
 
227
227
  const importedExportsType = importedModule.getExportsType(
228
228
  moduleGraph,
229
- /** @type {BuildMeta} */ (parentModule.buildMeta).strictHarmonyModule
229
+ /** @type {BuildMeta} */
230
+ (parentModule.buildMeta).strictHarmonyModule
230
231
  );
231
232
 
232
233
  const ids = dep.getIds(moduleGraph);
@@ -48,7 +48,7 @@ const harmonySpecifierTag = Symbol("harmony import");
48
48
  * @property {number} sourceOrder
49
49
  * @property {string} name
50
50
  * @property {boolean} await
51
- * @property {Record<string, any> | undefined} attributes
51
+ * @property {ImportAttributes=} attributes
52
52
  */
53
53
 
54
54
  module.exports = class HarmonyImportDependencyParserPlugin {
@@ -22,7 +22,7 @@ const NullDependency = require("./NullDependency");
22
22
  /**
23
23
  * @callback GetExportsFromDataFn
24
24
  * @param {JsonValue} data raw json data
25
- * @param {number} [curDepth] current depth
25
+ * @param {number=} curDepth current depth
26
26
  * @returns {ExportSpec[] | null} export spec or nothing
27
27
  */
28
28
 
@@ -50,7 +50,7 @@ module.exports.addLocalModule = (state, name) => {
50
50
  /**
51
51
  * @param {ParserState} state parser state
52
52
  * @param {string} name name
53
- * @param {string} [namedModule] named module
53
+ * @param {string=} namedModule named module
54
54
  * @returns {LocalModule | null} local module or null
55
55
  */
56
56
  module.exports.getLocalModule = (state, name, namedModule) => {
@@ -19,7 +19,7 @@ class RequireResolveDependency extends ModuleDependency {
19
19
  /**
20
20
  * @param {string} request the request string
21
21
  * @param {Range} range location in source code
22
- * @param {string} [context] context
22
+ * @param {string=} context context
23
23
  */
24
24
  constructor(request, range, context) {
25
25
  super(request);
@@ -119,7 +119,7 @@ class WorkerPlugin {
119
119
  /**
120
120
  * @param {JavascriptParser} parser the parser
121
121
  * @param {Expression} expr expression
122
- * @returns {[string, [number, number]] | void} parsed
122
+ * @returns {[string, Range] | void} parsed
123
123
  */
124
124
  const parseModuleUrl = (parser, expr) => {
125
125
  if (expr.type !== "NewExpression" || expr.callee.type === "Super")
@@ -259,7 +259,7 @@ class WorkerPlugin {
259
259
 
260
260
  /** @type {string} */
261
261
  let url;
262
- /** @type {[number, number]} */
262
+ /** @type {Range} */
263
263
  let range;
264
264
  /** @type {boolean} */
265
265
  let needNewUrl = false;
@@ -73,10 +73,30 @@ class ModuleChunkLoadingPlugin {
73
73
  );
74
74
  });
75
75
 
76
+ // We need public path only when we prefetch/preload chunk or public path is not `auto`
77
+ compilation.hooks.runtimeRequirementInTree
78
+ .for(RuntimeGlobals.prefetchChunkHandlers)
79
+ .tap("ModuleChunkLoadingPlugin", (chunk, set) => {
80
+ if (!isEnabledForChunk(chunk)) return;
81
+ set.add(RuntimeGlobals.publicPath);
82
+ });
83
+
84
+ compilation.hooks.runtimeRequirementInTree
85
+ .for(RuntimeGlobals.preloadChunkHandlers)
86
+ .tap("ModuleChunkLoadingPlugin", (chunk, set) => {
87
+ if (!isEnabledForChunk(chunk)) return;
88
+ set.add(RuntimeGlobals.publicPath);
89
+ });
90
+
76
91
  compilation.hooks.runtimeRequirementInTree
77
92
  .for(RuntimeGlobals.ensureChunkHandlers)
78
93
  .tap("ModuleChunkLoadingPlugin", (chunk, set) => {
79
94
  if (!isEnabledForChunk(chunk)) return;
95
+
96
+ if (compilation.outputOptions.publicPath !== "auto") {
97
+ set.add(RuntimeGlobals.publicPath);
98
+ }
99
+
80
100
  set.add(RuntimeGlobals.getChunkScriptFilename);
81
101
  });
82
102
  }
@@ -214,9 +214,11 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
214
214
  : `if(${hasJsMatcher("chunkId")}) {`,
215
215
  Template.indent([
216
216
  "// setup Promise in chunk cache",
217
- `var promise = ${importFunctionName}(${JSON.stringify(
218
- rootOutputDir
219
- )} + ${
217
+ `var promise = ${importFunctionName}(${
218
+ compilation.outputOptions.publicPath === "auto"
219
+ ? ""
220
+ : `${RuntimeGlobals.publicPath} + `
221
+ }${JSON.stringify(rootOutputDir)} + ${
220
222
  RuntimeGlobals.getChunkScriptFilename
221
223
  }(chunkId)).then(installChunk, ${runtimeTemplate.basicFunction(
222
224
  "e",
@@ -248,6 +250,9 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
248
250
  ? `${
249
251
  RuntimeGlobals.prefetchChunkHandlers
250
252
  }.j = ${runtimeTemplate.basicFunction("chunkId", [
253
+ isNeutralPlatform
254
+ ? "if (typeof document === 'undefined') return;"
255
+ : "",
251
256
  `if((!${
252
257
  RuntimeGlobals.hasOwnProperty
253
258
  }(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
@@ -255,9 +260,6 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
255
260
  }) {`,
256
261
  Template.indent([
257
262
  "installedChunks[chunkId] = null;",
258
- isNeutralPlatform
259
- ? "if (typeof document === 'undefined') return;"
260
- : "",
261
263
  linkPrefetch.call(
262
264
  Template.asString([
263
265
  "var link = document.createElement('link');",
@@ -288,6 +290,9 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
288
290
  ? `${
289
291
  RuntimeGlobals.preloadChunkHandlers
290
292
  }.j = ${runtimeTemplate.basicFunction("chunkId", [
293
+ isNeutralPlatform
294
+ ? "if (typeof document === 'undefined') return;"
295
+ : "",
291
296
  `if((!${
292
297
  RuntimeGlobals.hasOwnProperty
293
298
  }(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${
@@ -295,9 +300,6 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
295
300
  }) {`,
296
301
  Template.indent([
297
302
  "installedChunks[chunkId] = null;",
298
- isNeutralPlatform
299
- ? "if (typeof document === 'undefined') return;"
300
- : "",
301
303
  linkPreload.call(
302
304
  Template.asString([
303
305
  "var link = document.createElement('link');",
@@ -23,7 +23,7 @@ const {
23
23
 
24
24
  class DeterministicChunkIdsPlugin {
25
25
  /**
26
- * @param {DeterministicChunkIdsPluginOptions} [options] options
26
+ * @param {DeterministicChunkIdsPluginOptions=} options options
27
27
  */
28
28
  constructor(options = {}) {
29
29
  this.options = options;
@@ -29,7 +29,7 @@ const {
29
29
 
30
30
  class DeterministicModuleIdsPlugin {
31
31
  /**
32
- * @param {DeterministicModuleIdsPluginOptions} [options] options
32
+ * @param {DeterministicModuleIdsPluginOptions=} options options
33
33
  */
34
34
  constructor(options = {}) {
35
35
  this.options = options;
@@ -21,8 +21,8 @@ const {
21
21
 
22
22
  /**
23
23
  * @typedef {object} NamedChunkIdsPluginOptions
24
- * @property {string} [context] context
25
- * @property {string} [delimiter] delimiter
24
+ * @property {string=} context context
25
+ * @property {string=} delimiter delimiter
26
26
  */
27
27
 
28
28
  class NamedChunkIdsPlugin {
@@ -20,12 +20,12 @@ const {
20
20
 
21
21
  /**
22
22
  * @typedef {object} NamedModuleIdsPluginOptions
23
- * @property {string} [context] context
23
+ * @property {string=} context context
24
24
  */
25
25
 
26
26
  class NamedModuleIdsPlugin {
27
27
  /**
28
- * @param {NamedModuleIdsPluginOptions} [options] options
28
+ * @param {NamedModuleIdsPluginOptions=} options options
29
29
  */
30
30
  constructor(options = {}) {
31
31
  this.options = options;
package/lib/index.js CHANGED
@@ -70,7 +70,7 @@ const memoize = require("./util/memoize");
70
70
  */
71
71
  const lazyFunction = factory => {
72
72
  const fac = memoize(factory);
73
- const f = /** @type {any} */ (
73
+ const f = /** @type {unknown} */ (
74
74
  /**
75
75
  * @param {...EXPECTED_ANY} args args
76
76
  * @returns {T} result
@@ -179,7 +179,7 @@ class BasicEvaluatedExpression {
179
179
 
180
180
  /**
181
181
  * Gets the compile-time value of the expression
182
- * @returns {any} the javascript value
182
+ * @returns {undefined | null | string | number | boolean | RegExp | EXPECTED_ANY[] | bigint} the javascript value
183
183
  */
184
184
  asCompileTimeValue() {
185
185
  switch (this.type) {
@@ -524,7 +524,7 @@ class BasicEvaluatedExpression {
524
524
 
525
525
  /**
526
526
  * Set's the range for the expression.
527
- * @param {[number, number]} range range to set
527
+ * @param {Range} range range to set
528
528
  * @returns {this} this
529
529
  */
530
530
  setRange(range) {