webpack 5.102.0 → 5.102.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.
Files changed (53) hide show
  1. package/lib/ChunkGraph.js +2 -2
  2. package/lib/CodeGenerationResults.js +1 -1
  3. package/lib/Compilation.js +5 -11
  4. package/lib/ContextModule.js +3 -1
  5. package/lib/DefinePlugin.js +1 -1
  6. package/lib/DependencyTemplates.js +1 -1
  7. package/lib/FileSystemInfo.js +9 -12
  8. package/lib/ModuleFilenameHelpers.js +1 -1
  9. package/lib/NormalModule.js +1 -1
  10. package/lib/NormalModuleFactory.js +75 -4
  11. package/lib/RuntimeTemplate.js +10 -1
  12. package/lib/SourceMapDevToolPlugin.js +6 -8
  13. package/lib/asset/AssetBytesGenerator.js +1 -0
  14. package/lib/asset/AssetGenerator.js +2 -3
  15. package/lib/cache/getLazyHashedEtag.js +1 -1
  16. package/lib/config/browserslistTargetHandler.js +77 -76
  17. package/lib/config/defaults.js +7 -2
  18. package/lib/config/target.js +1 -1
  19. package/lib/css/CssModulesPlugin.js +2 -6
  20. package/lib/css/walkCssTokens.js +1 -1
  21. package/lib/dependencies/ContextElementDependency.js +2 -2
  22. package/lib/dependencies/CssLocalIdentifierDependency.js +1 -3
  23. package/lib/dependencies/HarmonyImportDependency.js +5 -2
  24. package/lib/dependencies/ImportContextDependency.js +13 -0
  25. package/lib/dependencies/ImportDependency.js +2 -2
  26. package/lib/dependencies/ImportMetaPlugin.js +1 -1
  27. package/lib/dependencies/WorkerPlugin.js +1 -3
  28. package/lib/ids/HashedModuleIdsPlugin.js +5 -7
  29. package/lib/ids/IdHelpers.js +1 -1
  30. package/lib/javascript/JavascriptModulesPlugin.js +2 -3
  31. package/lib/javascript/JavascriptParser.js +1 -1
  32. package/lib/library/SystemLibraryPlugin.js +15 -5
  33. package/lib/optimize/RealContentHashPlugin.js +5 -3
  34. package/lib/serialization/FileMiddleware.js +1 -1
  35. package/lib/serialization/ObjectMiddleware.js +1 -1
  36. package/lib/stats/DefaultStatsFactoryPlugin.js +1 -1
  37. package/lib/util/Hash.js +35 -5
  38. package/lib/util/create-schema-validation.js +1 -1
  39. package/lib/util/createHash.js +85 -15
  40. package/lib/util/hash/BatchedHash.js +47 -8
  41. package/lib/util/hash/wasm-hash.js +53 -13
  42. package/lib/wasm-async/AsyncWebAssemblyParser.js +0 -9
  43. package/lib/wasm-sync/WebAssemblyParser.js +0 -9
  44. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
  45. package/package.json +18 -18
  46. package/schemas/WebpackOptions.check.js +1 -1
  47. package/schemas/WebpackOptions.json +16 -3
  48. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +7 -0
  49. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +6 -0
  50. package/schemas/plugins/{HashedModuleIdsPlugin.json → ids/HashedModuleIdsPlugin.json} +15 -2
  51. package/types.d.ts +590 -196
  52. package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +0 -7
  53. package/schemas/plugins/HashedModuleIdsPlugin.check.js +0 -6
package/lib/ChunkGraph.js CHANGED
@@ -1670,7 +1670,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1670
1670
  for (const type of sourceTypes) hash.update(type);
1671
1671
  }
1672
1672
  this.moduleGraph.getExportsInfo(module).updateHash(hash, runtime);
1673
- return BigInt(`0x${/** @type {string} */ (hash.digest("hex"))}`);
1673
+ return BigInt(`0x${hash.digest("hex")}`);
1674
1674
  });
1675
1675
  return graphHash;
1676
1676
  }
@@ -1808,7 +1808,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1808
1808
  }
1809
1809
  }
1810
1810
  hash.update(graphHash);
1811
- return /** @type {string} */ (hash.digest("hex"));
1811
+ return hash.digest("hex");
1812
1812
  });
1813
1813
  }
1814
1814
 
@@ -141,7 +141,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
141
141
  if (info.runtimeRequirements) {
142
142
  for (const rr of info.runtimeRequirements) hash.update(rr);
143
143
  }
144
- return (info.hash = /** @type {string} */ (hash.digest("hex")));
144
+ return (info.hash = hash.digest("hex"));
145
145
  }
146
146
 
147
147
  /**
@@ -4378,7 +4378,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4378
4378
  runtime,
4379
4379
  runtimeTemplate
4380
4380
  });
4381
- moduleHashDigest = /** @type {string} */ (moduleHash.digest(hashDigest));
4381
+ moduleHashDigest = moduleHash.digest(hashDigest);
4382
4382
  } catch (err) {
4383
4383
  errors.push(new ModuleHashingError(module, /** @type {Error} */ (err)));
4384
4384
  moduleHashDigest = "XXXXXX";
@@ -4601,9 +4601,7 @@ This prevents using hashes of each other and should be avoided.`);
4601
4601
  moduleGraph: this.moduleGraph,
4602
4602
  runtimeTemplate: this.runtimeTemplate
4603
4603
  });
4604
- const chunkHashDigest = /** @type {string} */ (
4605
- chunkHash.digest(hashDigest)
4606
- );
4604
+ const chunkHashDigest = chunkHash.digest(hashDigest);
4607
4605
  hash.update(chunkHashDigest);
4608
4606
  chunk.hash = chunkHashDigest;
4609
4607
  chunk.renderedHash = chunk.hash.slice(0, hashDigestLength);
@@ -4637,7 +4635,7 @@ This prevents using hashes of each other and should be avoided.`);
4637
4635
  this.logger.timeAggregateEnd("hashing: hash chunks");
4638
4636
  this.logger.time("hashing: hash digest");
4639
4637
  this.hooks.fullHash.call(hash);
4640
- this.fullHash = /** @type {string} */ (hash.digest(hashDigest));
4638
+ this.fullHash = hash.digest(hashDigest);
4641
4639
  this.hash = this.fullHash.slice(0, hashDigestLength);
4642
4640
  this.logger.timeEnd("hashing: hash digest");
4643
4641
 
@@ -4652,9 +4650,7 @@ This prevents using hashes of each other and should be avoided.`);
4652
4650
  runtime: chunk.runtime,
4653
4651
  runtimeTemplate
4654
4652
  });
4655
- const moduleHashDigest = /** @type {string} */ (
4656
- moduleHash.digest(hashDigest)
4657
- );
4653
+ const moduleHashDigest = moduleHash.digest(hashDigest);
4658
4654
  const oldHash = chunkGraph.getModuleHash(module, chunk.runtime);
4659
4655
  chunkGraph.setModuleHashes(
4660
4656
  module,
@@ -4671,9 +4667,7 @@ This prevents using hashes of each other and should be avoided.`);
4671
4667
  const chunkHash = createHash(hashFunction);
4672
4668
  chunkHash.update(chunk.hash);
4673
4669
  chunkHash.update(this.hash);
4674
- const chunkHashDigest =
4675
- /** @type {string} */
4676
- (chunkHash.digest(hashDigest));
4670
+ const chunkHashDigest = chunkHash.digest(hashDigest);
4677
4671
  chunk.hash = chunkHashDigest;
4678
4672
  chunk.renderedHash = chunk.hash.slice(0, hashDigestLength);
4679
4673
  this.hooks.contentHash.call(chunk);
@@ -254,10 +254,12 @@ class ContextModule extends Module {
254
254
  } else if (this.options.namespaceObject) {
255
255
  identifier += "|namespace object";
256
256
  }
257
+ if (this.options.attributes) {
258
+ identifier += `|importAttributes: ${JSON.stringify(this.options.attributes)}`;
259
+ }
257
260
  if (this.layer) {
258
261
  identifier += `|layer: ${this.layer}`;
259
262
  }
260
-
261
263
  return identifier;
262
264
  }
263
265
 
@@ -830,7 +830,7 @@ class DefinePlugin {
830
830
 
831
831
  compilation.valueCacheVersions.set(
832
832
  VALUE_DEP_MAIN,
833
- /** @type {string} */ (mainHash.digest("hex").slice(0, 8))
833
+ mainHash.digest("hex").slice(0, 8)
834
834
  );
835
835
  }
836
836
  );
@@ -48,7 +48,7 @@ class DependencyTemplates {
48
48
  updateHash(part) {
49
49
  const hash = createHash(this._hashFunction);
50
50
  hash.update(`${this._hash}${part}`);
51
- this._hash = /** @type {string} */ (hash.digest("hex"));
51
+ this._hash = hash.digest("hex");
52
52
  }
53
53
 
54
54
  getHash() {
@@ -3350,7 +3350,7 @@ class FileSystemInfo {
3350
3350
 
3351
3351
  hash.update(/** @type {string | Buffer} */ (content));
3352
3352
 
3353
- const digest = /** @type {string} */ (hash.digest("hex"));
3353
+ const digest = hash.digest("hex");
3354
3354
 
3355
3355
  this._fileHashes.set(path, digest);
3356
3356
 
@@ -3618,7 +3618,7 @@ class FileSystemInfo {
3618
3618
  }
3619
3619
  }
3620
3620
 
3621
- const digest = /** @type {string} */ (hash.digest("hex"));
3621
+ const digest = hash.digest("hex");
3622
3622
  /** @type {ContextFileSystemInfoEntry} */
3623
3623
  const result = {
3624
3624
  safeTime,
@@ -3681,7 +3681,7 @@ class FileSystemInfo {
3681
3681
  null,
3682
3682
  (entry.resolved = {
3683
3683
  safeTime,
3684
- timestampHash: /** @type {string} */ (hash.digest("hex"))
3684
+ timestampHash: hash.digest("hex")
3685
3685
  })
3686
3686
  );
3687
3687
  }
@@ -3743,7 +3743,7 @@ class FileSystemInfo {
3743
3743
 
3744
3744
  /** @type {ContextHash} */
3745
3745
  const result = {
3746
- hash: /** @type {string} */ (hash.digest("hex"))
3746
+ hash: hash.digest("hex")
3747
3747
  };
3748
3748
  if (symlinks) result.symlinks = symlinks;
3749
3749
  return result;
@@ -3790,10 +3790,7 @@ class FileSystemInfo {
3790
3790
  for (const h of hashes) {
3791
3791
  hash.update(h);
3792
3792
  }
3793
- callback(
3794
- null,
3795
- (entry.resolved = /** @type {string} */ (hash.digest("hex")))
3796
- );
3793
+ callback(null, (entry.resolved = hash.digest("hex")));
3797
3794
  }
3798
3795
  );
3799
3796
  }
@@ -3910,8 +3907,8 @@ class FileSystemInfo {
3910
3907
  /** @type {ContextTimestampAndHash} */
3911
3908
  const result = {
3912
3909
  safeTime,
3913
- timestampHash: /** @type {string} */ (tsHash.digest("hex")),
3914
- hash: /** @type {string} */ (hash.digest("hex"))
3910
+ timestampHash: tsHash.digest("hex"),
3911
+ hash: hash.digest("hex")
3915
3912
  };
3916
3913
  if (symlinks) result.symlinks = symlinks;
3917
3914
  return result;
@@ -3979,8 +3976,8 @@ class FileSystemInfo {
3979
3976
  null,
3980
3977
  (entry.resolved = {
3981
3978
  safeTime,
3982
- timestampHash: /** @type {string} */ (tsHash.digest("hex")),
3983
- hash: /** @type {string} */ (hash.digest("hex"))
3979
+ timestampHash: tsHash.digest("hex"),
3980
+ hash: hash.digest("hex")
3984
3981
  })
3985
3982
  );
3986
3983
  }
@@ -84,7 +84,7 @@ const getHash =
84
84
  () => {
85
85
  const hash = createHash(hashFunction);
86
86
  hash.update(strFn());
87
- const digest = /** @type {string} */ (hash.digest("hex"));
87
+ const digest = hash.digest("hex");
88
88
  return digest.slice(0, 4);
89
89
  };
90
90
 
@@ -1211,7 +1211,7 @@ class NormalModule extends Module {
1211
1211
  hash.update("meta");
1212
1212
  hash.update(JSON.stringify(this.buildMeta));
1213
1213
  /** @type {BuildInfo} */
1214
- (this.buildInfo).hash = /** @type {string} */ (hash.digest("hex"));
1214
+ (this.buildInfo).hash = hash.digest("hex");
1215
1215
  }
1216
1216
 
1217
1217
  /**
@@ -114,6 +114,7 @@ const {
114
114
  /** @typedef {import("./ModuleTypeConstants").ASSET_MODULE_TYPE_INLINE} ASSET_MODULE_TYPE_INLINE */
115
115
  /** @typedef {import("./ModuleTypeConstants").ASSET_MODULE_TYPE_RESOURCE} ASSET_MODULE_TYPE_RESOURCE */
116
116
  /** @typedef {import("./ModuleTypeConstants").ASSET_MODULE_TYPE_SOURCE} ASSET_MODULE_TYPE_SOURCE */
117
+ /** @typedef {import("./ModuleTypeConstants").ASSET_MODULE_TYPE_BYTES} ASSET_MODULE_TYPE_BYTES */
117
118
  /** @typedef {import("./ModuleTypeConstants").WEBASSEMBLY_MODULE_TYPE_ASYNC} WEBASSEMBLY_MODULE_TYPE_ASYNC */
118
119
  /** @typedef {import("./ModuleTypeConstants").WEBASSEMBLY_MODULE_TYPE_SYNC} WEBASSEMBLY_MODULE_TYPE_SYNC */
119
120
  /** @typedef {import("./ModuleTypeConstants").CSS_MODULE_TYPE} CSS_MODULE_TYPE */
@@ -268,6 +269,76 @@ const ruleSetCompiler = new RuleSetCompiler([
268
269
  new UseEffectRulePlugin()
269
270
  ]);
270
271
 
272
+ /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
273
+ /** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
274
+ /** @typedef {import("./javascript/JavascriptGenerator")} JavascriptGenerator */
275
+ /** @typedef {import("../declarations/WebpackOptions").EmptyGeneratorOptions} EmptyGeneratorOptions */
276
+
277
+ /** @typedef {import("./json/JsonParser")} JsonParser */
278
+ /** @typedef {import("../declarations/WebpackOptions").JsonParserOptions} JsonParserOptions */
279
+ /** @typedef {import("./json/JsonGenerator")} JsonGenerator */
280
+ /** @typedef {import("../declarations/WebpackOptions").JsonGeneratorOptions} JsonGeneratorOptions */
281
+
282
+ /** @typedef {import("./asset/AssetParser")} AssetParser */
283
+ /** @typedef {import("./asset/AssetSourceParser")} AssetSourceParser */
284
+ /** @typedef {import("./asset/AssetBytesParser")} AssetBytesParser */
285
+ /** @typedef {import("../declarations/WebpackOptions").AssetParserOptions} AssetParserOptions */
286
+ /** @typedef {import("../declarations/WebpackOptions").EmptyParserOptions} EmptyParserOptions */
287
+ /** @typedef {import("./asset/AssetGenerator")} AssetGenerator */
288
+ /** @typedef {import("../declarations/WebpackOptions").AssetGeneratorOptions} AssetGeneratorOptions */
289
+ /** @typedef {import("../declarations/WebpackOptions").AssetInlineGeneratorOptions} AssetInlineGeneratorOptions */
290
+ /** @typedef {import("../declarations/WebpackOptions").AssetResourceGeneratorOptions} AssetResourceGeneratorOptions */
291
+ /** @typedef {import("./asset/AssetSourceGenerator")} AssetSourceGenerator */
292
+ /** @typedef {import("./asset/AssetBytesGenerator")} AssetBytesGenerator */
293
+
294
+ /** @typedef {import("./wasm-async/AsyncWebAssemblyParser")} AsyncWebAssemblyParser */
295
+ /** @typedef {import("./wasm-sync/WebAssemblyParser")} WebAssemblyParser */
296
+
297
+ /** @typedef {import("./css/CssParser")} CssParser */
298
+ /** @typedef {import("../declarations/WebpackOptions").CssParserOptions} CssParserOptions */
299
+ /** @typedef {import("../declarations/WebpackOptions").CssAutoParserOptions} CssAutoParserOptions */
300
+ /** @typedef {import("../declarations/WebpackOptions").CssGlobalParserOptions} CssGlobalParserOptions */
301
+ /** @typedef {import("../declarations/WebpackOptions").CssModuleParserOptions} CssModuleParserOptions */
302
+ /** @typedef {import("./css/CssGenerator")} CssGenerator */
303
+ /** @typedef {import("../declarations/WebpackOptions").CssGeneratorOptions} CssGeneratorOptions */
304
+ /** @typedef {import("../declarations/WebpackOptions").CssGlobalGeneratorOptions} CssGlobalGeneratorOptions */
305
+ /** @typedef {import("../declarations/WebpackOptions").CssModuleGeneratorOptions} CssModuleGeneratorOptions */
306
+ /** @typedef {import("../declarations/WebpackOptions").CssAutoGeneratorOptions} CssAutoGeneratorOptions */
307
+
308
+ /**
309
+ * @typedef {[
310
+ * [JAVASCRIPT_MODULE_TYPE_AUTO, JavascriptParser, JavascriptParserOptions, JavascriptGenerator, EmptyGeneratorOptions],
311
+ * [JAVASCRIPT_MODULE_TYPE_DYNAMIC, JavascriptParser, JavascriptParserOptions, JavascriptGenerator, EmptyGeneratorOptions],
312
+ * [JAVASCRIPT_MODULE_TYPE_ESM, JavascriptParser, JavascriptParserOptions, JavascriptGenerator, EmptyGeneratorOptions],
313
+ * [JSON_MODULE_TYPE, JsonParser, JsonParserOptions, JsonGenerator, JsonGeneratorOptions],
314
+ * [ASSET_MODULE_TYPE, AssetParser, AssetParserOptions, AssetGenerator, AssetGeneratorOptions],
315
+ * [ASSET_MODULE_TYPE_INLINE, AssetParser, EmptyParserOptions, AssetGenerator, AssetGeneratorOptions],
316
+ * [ASSET_MODULE_TYPE_RESOURCE, AssetParser, EmptyParserOptions, AssetGenerator, AssetGeneratorOptions],
317
+ * [ASSET_MODULE_TYPE_SOURCE, AssetSourceParser, EmptyParserOptions, AssetSourceGenerator, EmptyGeneratorOptions],
318
+ * [ASSET_MODULE_TYPE_BYTES, AssetBytesParser, EmptyParserOptions, AssetBytesGenerator, EmptyGeneratorOptions],
319
+ * [WEBASSEMBLY_MODULE_TYPE_ASYNC, AsyncWebAssemblyParser, EmptyParserOptions, Generator, EmptyParserOptions],
320
+ * [WEBASSEMBLY_MODULE_TYPE_SYNC, WebAssemblyParser, EmptyParserOptions, Generator, EmptyParserOptions],
321
+ * [CSS_MODULE_TYPE, CssParser, CssParserOptions, CssGenerator, CssGeneratorOptions],
322
+ * [CSS_MODULE_TYPE_AUTO, CssParser, CssAutoParserOptions, CssGenerator, CssAutoGeneratorOptions],
323
+ * [CSS_MODULE_TYPE_MODULE, CssParser, CssModuleParserOptions, CssGenerator, CssModuleGeneratorOptions],
324
+ * [CSS_MODULE_TYPE_GLOBAL, CssParser, CssGlobalParserOptions, CssGenerator, CssGlobalGeneratorOptions],
325
+ * [string, Parser, ParserOptions, Generator, GeneratorOptions],
326
+ * ]} ParsersAndGeneratorsByTypes
327
+ */
328
+
329
+ /**
330
+ * @template {unknown[]} T
331
+ * @template {number[]} I
332
+ * @typedef {{ [K in keyof I]: K extends keyof I ? I[K] extends keyof T ? T[I[K]] : never : never }} ExtractTupleElements
333
+ */
334
+
335
+ /**
336
+ * @template {unknown[]} T
337
+ * @template {number[]} A
338
+ * @template [R=void]
339
+ * @typedef {T extends [infer Head extends [string, ...unknown[]], ...infer Tail extends [string, ...unknown[]][]] ? Record<Head[0], SyncBailHook<ExtractTupleElements<Head, A>, R extends number ? Head[R] : R>> & RecordFactoryFromTuple<Tail, A, R> : unknown } RecordFactoryFromTuple
340
+ */
341
+
271
342
  class NormalModuleFactory extends ModuleFactory {
272
343
  /**
273
344
  * @param {object} param params
@@ -306,15 +377,15 @@ class NormalModuleFactory extends ModuleFactory {
306
377
  createModule: new AsyncSeriesBailHook(["createData", "resolveData"]),
307
378
  /** @type {SyncWaterfallHook<[Module, CreateData, ResolveData]>} */
308
379
  module: new SyncWaterfallHook(["module", "createData", "resolveData"]),
309
- /** @type {HookMap<SyncBailHook<[ParserOptions], Parser | void>>} */
380
+ /** @type {import("tapable").TypedHookMap<RecordFactoryFromTuple<ParsersAndGeneratorsByTypes, [2], 1>>} */
310
381
  createParser: new HookMap(() => new SyncBailHook(["parserOptions"])),
311
- /** @type {HookMap<SyncBailHook<[EXPECTED_ANY, ParserOptions], void>>} */
382
+ /** @type {import("tapable").TypedHookMap<RecordFactoryFromTuple<ParsersAndGeneratorsByTypes, [1, 2]>>} */
312
383
  parser: new HookMap(() => new SyncHook(["parser", "parserOptions"])),
313
- /** @type {HookMap<SyncBailHook<[GeneratorOptions], Generator | void>>} */
384
+ /** @type {import("tapable").TypedHookMap<RecordFactoryFromTuple<ParsersAndGeneratorsByTypes, [4], 3>>} */
314
385
  createGenerator: new HookMap(
315
386
  () => new SyncBailHook(["generatorOptions"])
316
387
  ),
317
- /** @type {HookMap<SyncBailHook<[EXPECTED_ANY, GeneratorOptions], void>>} */
388
+ /** @type {import("tapable").TypedHookMap<RecordFactoryFromTuple<ParsersAndGeneratorsByTypes, [3, 4]>>} */
318
389
  generator: new HookMap(
319
390
  () => new SyncHook(["generator", "generatorOptions"])
320
391
  ),
@@ -949,7 +949,16 @@ class RuntimeTemplate {
949
949
  // when the defaultInterop is used (when a ESM imports a CJS module),
950
950
  if (exportName.length > 0 && exportName[0] === "default") {
951
951
  if (isDeferred && exportsType !== "namespace") {
952
- const access = `${importVar}.a${propertyAccess(exportName, 1)}`;
952
+ const exportsInfo = moduleGraph.getExportsInfo(module);
953
+ const name = exportName.slice(1);
954
+ const used = exportsInfo.getUsedName(name, runtime);
955
+ if (!used) {
956
+ const comment = Template.toNormalComment(
957
+ `unused export ${propertyAccess(exportName)}`
958
+ );
959
+ return `${comment} undefined`;
960
+ }
961
+ const access = `${importVar}.a${propertyAccess(used)}`;
953
962
  if (isCall || asiSafe === undefined) {
954
963
  return access;
955
964
  }
@@ -482,14 +482,12 @@ class SourceMapDevToolPlugin {
482
482
  const sourceMapString = JSON.stringify(sourceMap);
483
483
  if (sourceMapFilename) {
484
484
  const filename = file;
485
- const sourceMapContentHash =
486
- /** @type {string} */
487
- (
488
- usesContentHash &&
489
- createHash(compilation.outputOptions.hashFunction)
490
- .update(sourceMapString)
491
- .digest("hex")
492
- );
485
+ const sourceMapContentHash = usesContentHash
486
+ ? createHash(compilation.outputOptions.hashFunction)
487
+ .update(sourceMapString)
488
+ .digest("hex")
489
+ : undefined;
490
+
493
491
  const pathParams = {
494
492
  chunk,
495
493
  filename: options.fileContext
@@ -53,6 +53,7 @@ class AssetSourceGenerator extends Generator {
53
53
 
54
54
  const encodedSource = originalSource.buffer().toString("base64");
55
55
 
56
+ runtimeRequirements.add(RuntimeGlobals.requireScope);
56
57
  runtimeRequirements.add(RuntimeGlobals.toBinary);
57
58
 
58
59
  let sourceContent;
@@ -244,11 +244,10 @@ class AssetGenerator extends Generator {
244
244
  hash.update(module.error.toString());
245
245
  }
246
246
 
247
- const fullContentHash = /** @type {string} */ (
248
- hash.digest(runtimeTemplate.outputOptions.hashDigest)
247
+ const fullContentHash = hash.digest(
248
+ runtimeTemplate.outputOptions.hashDigest
249
249
  );
250
250
 
251
- /** @type {string} */
252
251
  const contentHash = nonNumericOnlyHash(
253
252
  fullContentHash,
254
253
  runtimeTemplate.outputOptions.hashDigestLength
@@ -34,7 +34,7 @@ class LazyHashedEtag {
34
34
  if (this._hash === undefined) {
35
35
  const hash = createHash(this._hashFunction);
36
36
  this._obj.updateHash(hash);
37
- this._hash = /** @type {string} */ (hash.digest("base64"));
37
+ this._hash = hash.digest("base64");
38
38
  }
39
39
  return this._hash;
40
40
  }
@@ -15,59 +15,46 @@ const browserslist = require("browserslist");
15
15
  // [[C:]/path/to/config][:env]
16
16
  const inputRx = /^(?:((?:[A-Z]:)?[/\\].*?))?(?::(.+?))?$/i;
17
17
 
18
- /**
19
- * @typedef {object} BrowserslistHandlerConfig
20
- * @property {string=} configPath
21
- * @property {string=} env
22
- * @property {string=} query
23
- */
24
-
25
18
  /**
26
19
  * @param {string | null | undefined} input input string
27
20
  * @param {string} context the context directory
28
- * @returns {BrowserslistHandlerConfig} config
21
+ * @returns {string[] | undefined} selected browsers
29
22
  */
30
- const parse = (input, context) => {
31
- if (!input) {
32
- return {};
33
- }
34
-
35
- if (path.isAbsolute(input)) {
23
+ const load = (input, context) => {
24
+ // browserslist:path-to-config
25
+ // browserslist:path-to-config:env
26
+ if (input && path.isAbsolute(input)) {
36
27
  const [, configPath, env] = inputRx.exec(input) || [];
37
- return { configPath, env };
38
- }
39
28
 
40
- const config = browserslist.findConfig(context);
29
+ const config = browserslist.loadConfig({
30
+ config: configPath,
31
+ env
32
+ });
41
33
 
42
- if (config && Object.keys(config).includes(input)) {
43
- return { env: input };
34
+ return browserslist(config, { env });
44
35
  }
45
36
 
46
- return { query: input };
47
- };
37
+ const env = input || undefined;
48
38
 
49
- /**
50
- * @param {string | null | undefined} input input string
51
- * @param {string} context the context directory
52
- * @returns {string[] | undefined} selected browsers
53
- */
54
- const load = (input, context) => {
55
- const { configPath, env, query } = parse(input, context);
39
+ const config = browserslist.loadConfig({
40
+ path: context,
41
+ env
42
+ });
56
43
 
57
- // if a query is specified, then use it, else
58
- // if a path to a config is specified then load it, else
59
- // find a nearest config
60
- const config =
61
- query ||
62
- (configPath
63
- ? browserslist.loadConfig({
64
- config: configPath,
65
- env
66
- })
67
- : browserslist.loadConfig({ path: context, env }));
44
+ // browserslist
45
+ // browserslist:env
46
+ if (config) {
47
+ try {
48
+ return browserslist(config, { env, throwOnMissing: true });
49
+ } catch (_err) {
50
+ // Nothing, no `env` was found in browserslist, maybe input is `queries`
51
+ }
52
+ }
68
53
 
69
- if (!config) return;
70
- return browserslist(config);
54
+ // browserslist:query
55
+ if (env) {
56
+ return browserslist(env);
57
+ }
71
58
  };
72
59
 
73
60
  /**
@@ -104,28 +91,6 @@ const resolve = (browsers) => {
104
91
  const anyBrowser = browsers.some((b) => /^(?!node)/.test(b));
105
92
  const browserProperty = !anyBrowser ? false : anyNode ? null : true;
106
93
  const nodeProperty = !anyNode ? false : anyBrowser ? null : true;
107
- // Internet Explorer Mobile, Blackberry browser and Opera Mini are very old browsers, they do not support new features
108
- const es6DynamicImport = rawChecker({
109
- /* eslint-disable camelcase */
110
- chrome: 63,
111
- and_chr: 63,
112
- edge: 79,
113
- firefox: 67,
114
- and_ff: 67,
115
- // ie: Not supported
116
- opera: 50,
117
- op_mob: 46,
118
- safari: [11, 1],
119
- ios_saf: [11, 3],
120
- samsung: [8, 2],
121
- android: 63,
122
- and_qq: [10, 4],
123
- baidu: [13, 18],
124
- and_uc: [15, 5],
125
- kaios: [3, 0],
126
- node: [12, 17]
127
- /* eslint-enable camelcase */
128
- });
129
94
 
130
95
  return {
131
96
  /* eslint-disable camelcase */
@@ -188,9 +153,9 @@ const resolve = (browsers) => {
188
153
  ios_saf: 7,
189
154
  samsung: [3, 0],
190
155
  android: 38,
191
- // and_qq: Unknown support
156
+ and_qq: [10, 4],
192
157
  // baidu: Unknown support
193
- // and_uc: Unknown support
158
+ and_uc: [12, 12],
194
159
  kaios: [3, 0],
195
160
  node: [0, 12]
196
161
  }),
@@ -207,9 +172,9 @@ const resolve = (browsers) => {
207
172
  ios_saf: 8,
208
173
  samsung: [5, 0],
209
174
  android: 49,
210
- // and_qq: Unknown support
175
+ and_qq: [10, 4],
211
176
  // baidu: Unknown support
212
- // and_uc: Unknown support
177
+ and_uc: [12, 12],
213
178
  kaios: [2, 5],
214
179
  node: [6, 0]
215
180
  }),
@@ -253,8 +218,44 @@ const resolve = (browsers) => {
253
218
  kaios: [3, 0],
254
219
  node: [12, 17]
255
220
  }),
256
- dynamicImport: es6DynamicImport,
257
- dynamicImportInWorker: es6DynamicImport && !anyNode,
221
+ dynamicImport: rawChecker({
222
+ chrome: 63,
223
+ and_chr: 63,
224
+ edge: 79,
225
+ firefox: 67,
226
+ and_ff: 67,
227
+ // ie: Not supported
228
+ opera: 50,
229
+ op_mob: 46,
230
+ safari: [11, 1],
231
+ ios_saf: [11, 3],
232
+ samsung: [8, 2],
233
+ android: 63,
234
+ and_qq: [10, 4],
235
+ baidu: [13, 18],
236
+ and_uc: [15, 5],
237
+ kaios: [3, 0],
238
+ node: [12, 17]
239
+ }),
240
+ dynamicImportInWorker: rawChecker({
241
+ chrome: 80,
242
+ and_chr: 80,
243
+ edge: 80,
244
+ firefox: 114,
245
+ and_ff: 114,
246
+ // ie: Not supported
247
+ opera: 67,
248
+ op_mob: 57,
249
+ safari: [15, 0],
250
+ ios_saf: [15, 0],
251
+ samsung: [13, 0],
252
+ android: 80,
253
+ and_qq: [10, 4],
254
+ baidu: [13, 18],
255
+ and_uc: [15, 5],
256
+ kaios: [3, 0],
257
+ node: [12, 17]
258
+ }),
258
259
  // browserslist does not have info about globalThis
259
260
  // so this is based on mdn-browser-compat-data
260
261
  globalThis: rawChecker({
@@ -270,9 +271,9 @@ const resolve = (browsers) => {
270
271
  ios_saf: [12, 2],
271
272
  samsung: [10, 1],
272
273
  android: 71,
273
- // and_qq: Unknown support
274
+ and_qq: [13, 1],
274
275
  // baidu: Unknown support
275
- // and_uc: Unknown support
276
+ and_uc: [15, 5],
276
277
  kaios: [3, 0],
277
278
  node: 12
278
279
  }),
@@ -289,9 +290,9 @@ const resolve = (browsers) => {
289
290
  ios_saf: [13, 4],
290
291
  samsung: 13,
291
292
  android: 80,
292
- // and_qq: Not supported
293
+ and_qq: [13, 1],
293
294
  // baidu: Not supported
294
- // and_uc: Not supported
295
+ and_uc: [15, 5],
295
296
  kaios: [3, 0],
296
297
  node: 14
297
298
  }),
@@ -327,9 +328,9 @@ const resolve = (browsers) => {
327
328
  ios_saf: 11,
328
329
  samsung: [6, 2],
329
330
  android: 55,
330
- and_qq: [13, 1],
331
+ and_qq: [10, 4],
331
332
  baidu: [13, 18],
332
- and_uc: [15, 5],
333
+ and_uc: [12, 12],
333
334
  kaios: 3,
334
335
  node: [7, 6]
335
336
  }),
@@ -345,7 +346,7 @@ const resolve = (browsers) => {
345
346
  fetchWasm: browserProperty,
346
347
  global: nodeProperty,
347
348
  importScripts: false,
348
- importScriptsInWorker: true,
349
+ importScriptsInWorker: Boolean(browserProperty),
349
350
  nodeBuiltins: nodeProperty,
350
351
  nodePrefixForCoreModules:
351
352
  nodeProperty &&
@@ -1326,8 +1326,13 @@ const applyOutputDefaults = (
1326
1326
  if (tp.importScripts) return "array-push";
1327
1327
  throw new Error(
1328
1328
  "For the selected environment is no default script chunk format available:\n" +
1329
- "JSONP Array push can be chosen when 'document' or 'importScripts' is available.\n" +
1330
- `CommonJs exports can be chosen when 'require' or node builtins are available.\n${
1329
+ `${
1330
+ tp.module
1331
+ ? "Module ('module') can be chosen when ES modules are available (please set 'experiments.outputModule' and 'output.module' to `true`)"
1332
+ : ""
1333
+ }\n` +
1334
+ "JSONP Array push ('array-push') can be chosen when 'document' or 'importScripts' is available.\n" +
1335
+ `CommonJs exports ('commonjs') can be chosen when 'require' or node builtins are available.\n${
1331
1336
  helpMessage
1332
1337
  }`
1333
1338
  );
@@ -16,7 +16,7 @@ const getBrowserslistTargetHandler = memoize(() =>
16
16
  * @returns {string} default target
17
17
  */
18
18
  const getDefaultTarget = (context) => {
19
- const browsers = getBrowserslistTargetHandler().load(null, context);
19
+ const browsers = getBrowserslistTargetHandler().load(undefined, context);
20
20
  return browsers ? "browserslist" : "web";
21
21
  };
22
22
 
@@ -470,12 +470,8 @@ class CssModulesPlugin {
470
470
  hash.update(chunkGraph.getModuleHash(module, chunk.runtime));
471
471
  }
472
472
  }
473
- const digest = /** @type {string} */ (hash.digest(hashDigest));
474
- chunk.contentHash.css = nonNumericOnlyHash(
475
- digest,
476
- /** @type {number} */
477
- (hashDigestLength)
478
- );
473
+ const digest = hash.digest(hashDigest);
474
+ chunk.contentHash.css = nonNumericOnlyHash(digest, hashDigestLength);
479
475
  });
480
476
  compilation.hooks.renderManifest.tap(PLUGIN_NAME, (result, options) => {
481
477
  const { chunkGraph } = compilation;