webpack 5.36.2 → 5.38.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 (113) hide show
  1. package/README.md +5 -8
  2. package/bin/webpack.js +0 -0
  3. package/lib/CacheFacade.js +3 -3
  4. package/lib/Chunk.js +10 -5
  5. package/lib/Compilation.js +45 -57
  6. package/lib/Compiler.js +9 -6
  7. package/lib/ConcatenationScope.js +2 -1
  8. package/lib/ContextModule.js +3 -3
  9. package/lib/ContextReplacementPlugin.js +4 -3
  10. package/lib/DefinePlugin.js +16 -12
  11. package/lib/EntryPlugin.js +4 -4
  12. package/lib/EvalSourceMapDevToolPlugin.js +3 -1
  13. package/lib/ExportsInfo.js +20 -13
  14. package/lib/FileSystemInfo.js +25 -31
  15. package/lib/FlagDependencyExportsPlugin.js +8 -7
  16. package/lib/FlagDependencyUsagePlugin.js +2 -4
  17. package/lib/HotModuleReplacementPlugin.js +27 -32
  18. package/lib/JavascriptMetaInfoPlugin.js +2 -1
  19. package/lib/MainTemplate.js +2 -3
  20. package/lib/ModuleFilenameHelpers.js +4 -2
  21. package/lib/ModuleGraphConnection.js +6 -2
  22. package/lib/ModuleInfoHeaderPlugin.js +2 -3
  23. package/lib/MultiCompiler.js +31 -27
  24. package/lib/NormalModule.js +42 -8
  25. package/lib/NormalModuleFactory.js +2 -0
  26. package/lib/RecordIdsPlugin.js +5 -4
  27. package/lib/ResolverFactory.js +10 -7
  28. package/lib/RuntimeGlobals.js +7 -0
  29. package/lib/RuntimePlugin.js +19 -1
  30. package/lib/SourceMapDevToolPlugin.js +14 -15
  31. package/lib/Template.js +4 -2
  32. package/lib/Watching.js +91 -47
  33. package/lib/asset/AssetGenerator.js +46 -29
  34. package/lib/asset/AssetModulesPlugin.js +1 -1
  35. package/lib/buildChunkGraph.js +21 -21
  36. package/lib/cache/PackFileCacheStrategy.js +12 -9
  37. package/lib/config/defaults.js +31 -10
  38. package/lib/config/normalization.js +16 -7
  39. package/lib/config/target.js +7 -2
  40. package/lib/debug/ProfilingPlugin.js +4 -3
  41. package/lib/dependencies/AMDRequireDependency.js +3 -3
  42. package/lib/dependencies/CommonJsExportRequireDependency.js +2 -3
  43. package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -1
  44. package/lib/dependencies/CommonJsImportsParserPlugin.js +2 -4
  45. package/lib/dependencies/CommonJsPlugin.js +8 -7
  46. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
  47. package/lib/dependencies/ContextDependencyHelpers.js +10 -8
  48. package/lib/dependencies/CreateScriptUrlDependency.js +54 -0
  49. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +11 -13
  50. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +2 -4
  51. package/lib/dependencies/HarmonyImportSpecifierDependency.js +4 -11
  52. package/lib/dependencies/ImportDependency.js +3 -3
  53. package/lib/dependencies/ImportParserPlugin.js +2 -4
  54. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +2 -3
  55. package/lib/dependencies/RequireEnsureDependency.js +3 -3
  56. package/lib/dependencies/WorkerDependency.js +6 -6
  57. package/lib/dependencies/WorkerPlugin.js +32 -20
  58. package/lib/hmr/LazyCompilationPlugin.js +6 -4
  59. package/lib/ids/HashedModuleIdsPlugin.js +3 -3
  60. package/lib/ids/OccurrenceModuleIdsPlugin.js +2 -3
  61. package/lib/index.js +5 -3
  62. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -6
  63. package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -3
  64. package/lib/javascript/JavascriptGenerator.js +3 -1
  65. package/lib/javascript/JavascriptModulesPlugin.js +15 -23
  66. package/lib/javascript/JavascriptParser.js +10 -8
  67. package/lib/library/AssignLibraryPlugin.js +4 -2
  68. package/lib/node/NodeEnvironmentPlugin.js +1 -0
  69. package/lib/node/NodeWatchFileSystem.js +19 -4
  70. package/lib/optimize/AggressiveSplittingPlugin.js +5 -4
  71. package/lib/optimize/ConcatenatedModule.js +31 -27
  72. package/lib/optimize/FlagIncludedChunksPlugin.js +4 -6
  73. package/lib/optimize/InnerGraph.js +9 -11
  74. package/lib/optimize/InnerGraphPlugin.js +3 -1
  75. package/lib/optimize/ModuleConcatenationPlugin.js +7 -10
  76. package/lib/optimize/RealContentHashPlugin.js +14 -16
  77. package/lib/optimize/SideEffectsFlagPlugin.js +6 -5
  78. package/lib/optimize/SplitChunksPlugin.js +13 -15
  79. package/lib/runtime/CreateScriptUrlRuntimeModule.js +61 -0
  80. package/lib/runtime/EnsureChunkRuntimeModule.js +9 -8
  81. package/lib/runtime/LoadScriptRuntimeModule.js +12 -5
  82. package/lib/runtime/OnChunksLoadedRuntimeModule.js +38 -37
  83. package/lib/schemes/DataUriPlugin.js +21 -2
  84. package/lib/serialization/BinaryMiddleware.js +5 -3
  85. package/lib/serialization/FileMiddleware.js +3 -1
  86. package/lib/serialization/ObjectMiddleware.js +11 -7
  87. package/lib/stats/DefaultStatsFactoryPlugin.js +7 -7
  88. package/lib/stats/DefaultStatsPrinterPlugin.js +11 -9
  89. package/lib/stats/StatsFactory.js +2 -1
  90. package/lib/stats/StatsPrinter.js +3 -3
  91. package/lib/util/LazyBucketSortedSet.js +3 -3
  92. package/lib/util/cleverMerge.js +3 -1
  93. package/lib/util/comparators.js +13 -13
  94. package/lib/util/createHash.js +5 -4
  95. package/lib/util/fs.js +8 -8
  96. package/lib/util/identifier.js +2 -1
  97. package/lib/util/internalSerializables.js +2 -0
  98. package/lib/util/serialization.js +108 -59
  99. package/lib/validateSchema.js +5 -3
  100. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +4 -4
  101. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +5 -4
  102. package/lib/wasm-sync/WebAssemblyGenerator.js +89 -83
  103. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -1
  104. package/lib/wasm-sync/WebAssemblyParser.js +6 -5
  105. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -4
  106. package/lib/webpack.js +11 -7
  107. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +13 -1
  108. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -4
  109. package/package.json +10 -7
  110. package/schemas/WebpackOptions.check.js +1 -1
  111. package/schemas/WebpackOptions.json +107 -60
  112. package/types.d.ts +480 -285
  113. package/lib/util/DataURI.js +0 -32
@@ -42,8 +42,12 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
42
42
  return hooks;
43
43
  }
44
44
 
45
- constructor() {
45
+ /**
46
+ * @param {boolean=} withCreateScriptUrl use create script url for trusted types
47
+ */
48
+ constructor(withCreateScriptUrl) {
46
49
  super("load script");
50
+ this._withCreateScriptUrl = withCreateScriptUrl;
47
51
  }
48
52
 
49
53
  /**
@@ -61,9 +65,8 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
61
65
  } = outputOptions;
62
66
  const fn = RuntimeGlobals.loadScript;
63
67
 
64
- const { createScript } = LoadScriptRuntimeModule.getCompilationHooks(
65
- compilation
66
- );
68
+ const { createScript } =
69
+ LoadScriptRuntimeModule.getCompilationHooks(compilation);
67
70
 
68
71
  const code = Template.asString([
69
72
  "script = document.createElement('script');",
@@ -78,7 +81,11 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
78
81
  uniqueName
79
82
  ? 'script.setAttribute("data-webpack", dataWebpackPrefix + key);'
80
83
  : "",
81
- `script.src = url;`,
84
+ `script.src = ${
85
+ this._withCreateScriptUrl
86
+ ? `${RuntimeGlobals.createScriptUrl}(url)`
87
+ : "url"
88
+ };`,
82
89
  crossOriginLoading
83
90
  ? Template.asString([
84
91
  "if (script.src.indexOf(window.location.origin + '/') !== 0) {",
@@ -21,49 +21,50 @@ class OnChunksLoadedRuntimeModule extends RuntimeModule {
21
21
  const { runtimeTemplate } = compilation;
22
22
  return Template.asString([
23
23
  "var deferred = [];",
24
- `${
25
- RuntimeGlobals.onChunksLoaded
26
- } = ${runtimeTemplate.basicFunction("result, chunkIds, fn, priority", [
27
- "if(chunkIds) {",
28
- Template.indent([
29
- "priority = priority || 0;",
30
- "for(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];",
31
- "deferred[i] = [chunkIds, fn, priority];",
32
- "return;"
33
- ]),
34
- "}",
35
- "var notFulfilled = Infinity;",
36
- "for (var i = 0; i < deferred.length; i++) {",
37
- Template.indent([
38
- runtimeTemplate.destructureArray(
39
- ["chunkIds", "fn", "priority"],
40
- "deferred[i]"
41
- ),
42
- "var fulfilled = true;",
43
- "for (var j = 0; j < chunkIds.length; j++) {",
24
+ `${RuntimeGlobals.onChunksLoaded} = ${runtimeTemplate.basicFunction(
25
+ "result, chunkIds, fn, priority",
26
+ [
27
+ "if(chunkIds) {",
44
28
  Template.indent([
45
- `if ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(${
46
- RuntimeGlobals.onChunksLoaded
47
- }).every(${runtimeTemplate.returningFunction(
48
- `${RuntimeGlobals.onChunksLoaded}[key](chunkIds[j])`,
49
- "key"
50
- )})) {`,
51
- Template.indent(["chunkIds.splice(j--, 1);"]),
52
- "} else {",
29
+ "priority = priority || 0;",
30
+ "for(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];",
31
+ "deferred[i] = [chunkIds, fn, priority];",
32
+ "return;"
33
+ ]),
34
+ "}",
35
+ "var notFulfilled = Infinity;",
36
+ "for (var i = 0; i < deferred.length; i++) {",
37
+ Template.indent([
38
+ runtimeTemplate.destructureArray(
39
+ ["chunkIds", "fn", "priority"],
40
+ "deferred[i]"
41
+ ),
42
+ "var fulfilled = true;",
43
+ "for (var j = 0; j < chunkIds.length; j++) {",
53
44
  Template.indent([
54
- "fulfilled = false;",
55
- "if(priority < notFulfilled) notFulfilled = priority;"
45
+ `if ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(${
46
+ RuntimeGlobals.onChunksLoaded
47
+ }).every(${runtimeTemplate.returningFunction(
48
+ `${RuntimeGlobals.onChunksLoaded}[key](chunkIds[j])`,
49
+ "key"
50
+ )})) {`,
51
+ Template.indent(["chunkIds.splice(j--, 1);"]),
52
+ "} else {",
53
+ Template.indent([
54
+ "fulfilled = false;",
55
+ "if(priority < notFulfilled) notFulfilled = priority;"
56
+ ]),
57
+ "}"
56
58
  ]),
59
+ "}",
60
+ "if(fulfilled) {",
61
+ Template.indent(["deferred.splice(i--, 1)", "result = fn();"]),
57
62
  "}"
58
63
  ]),
59
64
  "}",
60
- "if(fulfilled) {",
61
- Template.indent(["deferred.splice(i--, 1)", "result = fn();"]),
62
- "}"
63
- ]),
64
- "}",
65
- "return result;"
66
- ])};`
65
+ "return result;"
66
+ ]
67
+ )};`
67
68
  ]);
68
69
  }
69
70
  }
@@ -6,10 +6,25 @@
6
6
  "use strict";
7
7
 
8
8
  const NormalModule = require("../NormalModule");
9
- const { getMimetype, decodeDataURI } = require("../util/DataURI");
10
9
 
11
10
  /** @typedef {import("../Compiler")} Compiler */
12
11
 
12
+ // data URL scheme: "data:text/javascript;charset=utf-8;base64,some-string"
13
+ // http://www.ietf.org/rfc/rfc2397.txt
14
+ const URIRegEx = /^data:(?:[^;,]+)?(?:(?:;[^;,]+)*?)(;base64)?,(.*)$/i;
15
+ const URIMetaRegEx = /^data:([^;,]+)?(?:(?:;[^;,]+)*?)(?:;(base64))?,/i;
16
+
17
+ const decodeDataURI = uri => {
18
+ const match = URIRegEx.exec(uri);
19
+ if (!match) return null;
20
+
21
+ const isBase64 = match[1];
22
+ const body = match[2];
23
+ return isBase64
24
+ ? Buffer.from(body, "base64")
25
+ : Buffer.from(decodeURIComponent(body), "ascii");
26
+ };
27
+
13
28
  class DataUriPlugin {
14
29
  /**
15
30
  * Apply the plugin
@@ -23,7 +38,11 @@ class DataUriPlugin {
23
38
  normalModuleFactory.hooks.resolveForScheme
24
39
  .for("data")
25
40
  .tap("DataUriPlugin", resourceData => {
26
- resourceData.data.mimetype = getMimetype(resourceData.resource);
41
+ const match = URIMetaRegEx.exec(resourceData.resource);
42
+ if (match) {
43
+ resourceData.data.mimetype = match[1] || "";
44
+ resourceData.data.encoding = match[2] || false;
45
+ }
27
46
  });
28
47
  NormalModule.getCompilationHooks(compilation)
29
48
  .readResourceForScheme.for("data")
@@ -100,6 +100,9 @@ const F64_SIZE = 8;
100
100
  const MEASURE_START_OPERATION = Symbol("MEASURE_START_OPERATION");
101
101
  const MEASURE_END_OPERATION = Symbol("MEASURE_END_OPERATION");
102
102
 
103
+ /** @typedef {typeof MEASURE_START_OPERATION} MEASURE_START_OPERATION_TYPE */
104
+ /** @typedef {typeof MEASURE_END_OPERATION} MEASURE_END_OPERATION_TYPE */
105
+
103
106
  const identifyNumber = n => {
104
107
  if (n === (n | 0)) {
105
108
  if (n <= 127 && n >= -128) return 0;
@@ -201,9 +204,8 @@ class BinaryMiddleware extends SerializerMiddleware {
201
204
  if (!SerializerMiddleware.isLazy(thing))
202
205
  throw new Error("Unexpected function " + thing);
203
206
  /** @type {SerializedType | (() => SerializedType)} */
204
- let serializedData = SerializerMiddleware.getLazySerializedValue(
205
- thing
206
- );
207
+ let serializedData =
208
+ SerializerMiddleware.getLazySerializedValue(thing);
207
209
  if (serializedData === undefined) {
208
210
  if (SerializerMiddleware.isLazy(thing, this)) {
209
211
  const data = this._serialize(thing(), context);
@@ -135,7 +135,9 @@ const serialize = async (middleware, data, name, writeFile) => {
135
135
  const backgroundJobs = [];
136
136
  const resolvedData = (
137
137
  await Promise.all(
138
- /** @type {Promise<Buffer[] | Buffer | SerializeResult>[]} */ (processedData)
138
+ /** @type {Promise<Buffer[] | Buffer | SerializeResult>[]} */ (
139
+ processedData
140
+ )
139
141
  )
140
142
  ).map(item => {
141
143
  if (Array.isArray(item) || Buffer.isBuffer(item)) return item;
@@ -450,9 +450,8 @@ class ObjectMiddleware extends SerializerMiddleware {
450
450
  );
451
451
  }
452
452
 
453
- const { request, name, serializer } = ObjectMiddleware.getSerializerFor(
454
- item
455
- );
453
+ const { request, name, serializer } =
454
+ ObjectMiddleware.getSerializerFor(item);
456
455
  const key = `${request}/${name}`;
457
456
  const lastIndex = objectTypeLookup.get(key);
458
457
 
@@ -500,9 +499,8 @@ class ObjectMiddleware extends SerializerMiddleware {
500
499
  if (!SerializerMiddleware.isLazy(item))
501
500
  throw new Error("Unexpected function " + item);
502
501
  /** @type {SerializedType} */
503
- const serializedData = SerializerMiddleware.getLazySerializedValue(
504
- item
505
- );
502
+ const serializedData =
503
+ SerializerMiddleware.getLazySerializedValue(item);
506
504
  if (serializedData !== undefined) {
507
505
  if (typeof serializedData === "function") {
508
506
  result.push(serializedData);
@@ -539,7 +537,13 @@ class ObjectMiddleware extends SerializerMiddleware {
539
537
  // This happens because the optimized code v8 generates
540
538
  // is optimized for our "ctx.write" method so it will reference
541
539
  // it from e. g. Dependency.prototype.serialize -(IC)-> ctx.write
542
- data = result = referenceable = bufferDedupeMap = objectTypeLookup = ctx = undefined;
540
+ data =
541
+ result =
542
+ referenceable =
543
+ bufferDedupeMap =
544
+ objectTypeLookup =
545
+ ctx =
546
+ undefined;
543
547
  }
544
548
  }
545
549
 
@@ -10,7 +10,6 @@ const ModuleDependency = require("../dependencies/ModuleDependency");
10
10
  const formatLocation = require("../formatLocation");
11
11
  const { LogType } = require("../logging/Logger");
12
12
  const AggressiveSplittingPlugin = require("../optimize/AggressiveSplittingPlugin");
13
- const ConcatenatedModule = require("../optimize/ConcatenatedModule");
14
13
  const SizeLimitsPlugin = require("../performance/SizeLimitsPlugin");
15
14
  const { countIterable } = require("../util/IterableHelpers");
16
15
  const {
@@ -1078,9 +1077,8 @@ const SIMPLE_EXTRACTORS = {
1078
1077
  const { compilation, type } = context;
1079
1078
  const built = compilation.builtModules.has(module);
1080
1079
  const codeGenerated = compilation.codeGeneratedModules.has(module);
1081
- const buildTimeExecuted = compilation.buildTimeExecutedModules.has(
1082
- module
1083
- );
1080
+ const buildTimeExecuted =
1081
+ compilation.buildTimeExecutedModules.has(module);
1084
1082
  /** @type {{[x: string]: number}} */
1085
1083
  const sizes = {};
1086
1084
  for (const sourceType of module.getSourceTypes()) {
@@ -1228,11 +1226,13 @@ const SIMPLE_EXTRACTORS = {
1228
1226
  },
1229
1227
  nestedModules: (object, module, context, options, factory) => {
1230
1228
  const { type } = context;
1231
- if (module instanceof ConcatenatedModule) {
1232
- const modules = module.modules;
1229
+ const innerModules = /** @type {Module & { modules?: Module[] }} */ (
1230
+ module
1231
+ ).modules;
1232
+ if (Array.isArray(innerModules)) {
1233
1233
  const groupedModules = factory.create(
1234
1234
  `${type.slice(0, -8)}.modules`,
1235
- modules,
1235
+ innerModules,
1236
1236
  context
1237
1237
  );
1238
1238
  const limited = spaceLimited(
@@ -818,9 +818,8 @@ const SIMPLE_ITEMS_JOINER = {
818
818
  "asset.chunkNames": itemsJoinCommaBracketsWithName("name"),
819
819
  "asset.auxiliaryChunkNames": itemsJoinCommaBracketsWithName("auxiliary name"),
820
820
  "asset.chunkIdHints": itemsJoinCommaBracketsWithName("id hint"),
821
- "asset.auxiliaryChunkIdHints": itemsJoinCommaBracketsWithName(
822
- "auxiliary id hint"
823
- ),
821
+ "asset.auxiliaryChunkIdHints":
822
+ itemsJoinCommaBracketsWithName("auxiliary id hint"),
824
823
  "module.chunks": itemsJoinOneLine,
825
824
  "module.issuerPath": items =>
826
825
  items
@@ -912,11 +911,13 @@ const joinExplicitNewLine = (items, indenter) => {
912
911
  .trim();
913
912
  };
914
913
 
915
- const joinError = error => (items, { red, yellow }) =>
916
- `${error ? red("ERROR") : yellow("WARNING")} in ${joinExplicitNewLine(
917
- items,
918
- ""
919
- )}`;
914
+ const joinError =
915
+ error =>
916
+ (items, { red, yellow }) =>
917
+ `${error ? red("ERROR") : yellow("WARNING")} in ${joinExplicitNewLine(
918
+ items,
919
+ ""
920
+ )}`;
920
921
 
921
922
  /** @type {Record<string, (items: ({ element: string, content: string })[], context: StatsPrinterContext) => string>} */
922
923
  const SIMPLE_ELEMENT_JOINERS = {
@@ -1130,7 +1131,8 @@ const AVAILABLE_FORMATS = {
1130
1131
  format: red
1131
1132
  },
1132
1133
  {
1133
- regExp: /\b(error|failed|unexpected|invalid|not found|not supported|not available|not possible|not implemented|doesn't support|conflict|conflicting|not existing|duplicate)\b/gi,
1134
+ regExp:
1135
+ /\b(error|failed|unexpected|invalid|not found|not supported|not available|not possible|not implemented|doesn't support|conflict|conflicting|not existing|duplicate)\b/gi,
1134
1136
  format: red
1135
1137
  }
1136
1138
  ];
@@ -71,7 +71,8 @@ class StatsFactory {
71
71
  getItemFactory: new HookMap(() => new SyncBailHook(["item", "context"]))
72
72
  });
73
73
  const hooks = this.hooks;
74
- this._caches = /** @type {Record<keyof typeof hooks, Map<string, SyncBailHook<[any[], StatsFactoryContext]>[]>>} */ ({});
74
+ this._caches =
75
+ /** @type {Record<keyof typeof hooks, Map<string, SyncBailHook<[any[], StatsFactoryContext]>[]>>} */ ({});
75
76
  for (const key of Object.keys(hooks)) {
76
77
  this._caches[key] = new Map();
77
78
  }
@@ -87,9 +87,9 @@ class StatsPrinter {
87
87
  * @returns {T[]} hooks
88
88
  */
89
89
  _getAllLevelHooks(hookMap, type) {
90
- let cache = /** @type {Map<string, T[]>} */ (this._levelHookCache.get(
91
- hookMap
92
- ));
90
+ let cache = /** @type {Map<string, T[]>} */ (
91
+ this._levelHookCache.get(hookMap)
92
+ );
93
93
  if (cache === undefined) {
94
94
  cache = new Map();
95
95
  this._levelHookCache.set(hookMap, cache);
@@ -164,9 +164,9 @@ class LazyBucketSortedSet {
164
164
  }
165
165
  };
166
166
  } else {
167
- const oldEntry = /** @type {LazyBucketSortedSet<T, any>} */ (this._map.get(
168
- key
169
- ));
167
+ const oldEntry = /** @type {LazyBucketSortedSet<T, any>} */ (
168
+ this._map.get(key)
169
+ );
170
170
  const finishUpdate = oldEntry.startUpdate(item);
171
171
  return remove => {
172
172
  if (remove) {
@@ -539,7 +539,9 @@ const resolveByProperty = (obj, byProperty, ...values) => {
539
539
  }
540
540
  const { [byProperty]: _byValue, ..._remaining } = /** @type {object} */ (obj);
541
541
  const remaining = /** @type {T} */ (_remaining);
542
- const byValue = /** @type {Record<string, T> | function(...any[]): T} */ (_byValue);
542
+ const byValue = /** @type {Record<string, T> | function(...any[]): T} */ (
543
+ _byValue
544
+ );
543
545
  if (typeof byValue === "object") {
544
546
  const key = values[0];
545
547
  if (key in byValue) {
@@ -68,9 +68,8 @@ const compareModulesById = (chunkGraph, a, b) => {
68
68
  return compareIds(chunkGraph.getModuleId(a), chunkGraph.getModuleId(b));
69
69
  };
70
70
  /** @type {ParameterizedComparator<ChunkGraph, Module>} */
71
- exports.compareModulesById = createCachedParameterizedComparator(
72
- compareModulesById
73
- );
71
+ exports.compareModulesById =
72
+ createCachedParameterizedComparator(compareModulesById);
74
73
 
75
74
  /**
76
75
  * @param {number} a number
@@ -138,9 +137,10 @@ const compareModulesByPostOrderIndexOrIdentifier = (moduleGraph, a, b) => {
138
137
  return compareIds(a.identifier(), b.identifier());
139
138
  };
140
139
  /** @type {ParameterizedComparator<ModuleGraph, Module>} */
141
- exports.compareModulesByPostOrderIndexOrIdentifier = createCachedParameterizedComparator(
142
- compareModulesByPostOrderIndexOrIdentifier
143
- );
140
+ exports.compareModulesByPostOrderIndexOrIdentifier =
141
+ createCachedParameterizedComparator(
142
+ compareModulesByPostOrderIndexOrIdentifier
143
+ );
144
144
 
145
145
  /**
146
146
  * @param {ModuleGraph} moduleGraph the module graph
@@ -157,9 +157,10 @@ const compareModulesByPreOrderIndexOrIdentifier = (moduleGraph, a, b) => {
157
157
  return compareIds(a.identifier(), b.identifier());
158
158
  };
159
159
  /** @type {ParameterizedComparator<ModuleGraph, Module>} */
160
- exports.compareModulesByPreOrderIndexOrIdentifier = createCachedParameterizedComparator(
161
- compareModulesByPreOrderIndexOrIdentifier
162
- );
160
+ exports.compareModulesByPreOrderIndexOrIdentifier =
161
+ createCachedParameterizedComparator(
162
+ compareModulesByPreOrderIndexOrIdentifier
163
+ );
163
164
 
164
165
  /**
165
166
  * @param {ChunkGraph} chunkGraph the chunk graph
@@ -284,10 +285,9 @@ const concatComparators = (c1, c2, ...cRest) => {
284
285
  const [c3, ...cRest2] = cRest;
285
286
  return concatComparators(c1, concatComparators(c2, c3, ...cRest2));
286
287
  }
287
- const cacheEntry = /** @type {Comparator<T>} */ (concatComparatorsCache.get(
288
- c1,
289
- c2
290
- ));
288
+ const cacheEntry = /** @type {Comparator<T>} */ (
289
+ concatComparatorsCache.get(c1, c2)
290
+ );
291
291
  if (cacheEntry !== undefined) return cacheEntry;
292
292
  /**
293
293
  * @param {T} a first value
@@ -67,6 +67,7 @@ class BulkUpdateDecorator extends Hash {
67
67
  */
68
68
  digest(encoding) {
69
69
  let digestCache;
70
+ const buffer = this.buffer;
70
71
  if (this.hash === undefined) {
71
72
  // short data for hash, we can use caching
72
73
  const cacheKey = `${this.hashKey}-${encoding}`;
@@ -74,18 +75,18 @@ class BulkUpdateDecorator extends Hash {
74
75
  if (digestCache === undefined) {
75
76
  digestCache = digestCaches[cacheKey] = new Map();
76
77
  }
77
- const cacheEntry = digestCache.get(this.buffer);
78
+ const cacheEntry = digestCache.get(buffer);
78
79
  if (cacheEntry !== undefined) return cacheEntry;
79
80
  this.hash = this.hashFactory();
80
81
  }
81
- if (this.buffer.length > 0) {
82
- this.hash.update(this.buffer);
82
+ if (buffer.length > 0) {
83
+ this.hash.update(buffer);
83
84
  }
84
85
  const digestResult = this.hash.digest(encoding);
85
86
  const result =
86
87
  typeof digestResult === "string" ? digestResult : digestResult.toString();
87
88
  if (digestCache !== undefined) {
88
- digestCache.set(this.buffer, result);
89
+ digestCache.set(buffer, result);
89
90
  }
90
91
  return result;
91
92
  }
package/lib/util/fs.js CHANGED
@@ -51,14 +51,14 @@ const path = require("path");
51
51
  * @property {string | Buffer} name
52
52
  */
53
53
 
54
- /** @typedef {function(NodeJS.ErrnoException=): void} Callback */
55
- /** @typedef {function(NodeJS.ErrnoException=, Buffer=): void} BufferCallback */
56
- /** @typedef {function(NodeJS.ErrnoException=, Buffer|string=): void} BufferOrStringCallback */
57
- /** @typedef {function(NodeJS.ErrnoException=, (string | Buffer)[] | IDirent[]=): void} DirentArrayCallback */
58
- /** @typedef {function(NodeJS.ErrnoException=, string=): void} StringCallback */
59
- /** @typedef {function(NodeJS.ErrnoException=, number=): void} NumberCallback */
60
- /** @typedef {function(NodeJS.ErrnoException=, IStats=): void} StatsCallback */
61
- /** @typedef {function((NodeJS.ErrnoException | Error)=, any=): void} ReadJsonCallback */
54
+ /** @typedef {function((NodeJS.ErrnoException | null)=): void} Callback */
55
+ /** @typedef {function((NodeJS.ErrnoException | null)=, Buffer=): void} BufferCallback */
56
+ /** @typedef {function((NodeJS.ErrnoException | null)=, Buffer|string=): void} BufferOrStringCallback */
57
+ /** @typedef {function((NodeJS.ErrnoException | null)=, (string | Buffer)[] | IDirent[]=): void} DirentArrayCallback */
58
+ /** @typedef {function((NodeJS.ErrnoException | null)=, string=): void} StringCallback */
59
+ /** @typedef {function((NodeJS.ErrnoException | null)=, number=): void} NumberCallback */
60
+ /** @typedef {function((NodeJS.ErrnoException | null)=, IStats=): void} StatsCallback */
61
+ /** @typedef {function((NodeJS.ErrnoException | Error | null)=, any=): void} ReadJsonCallback */
62
62
 
63
63
  /**
64
64
  * @typedef {Object} Watcher
@@ -244,7 +244,8 @@ const _absolutify = (context, request) => {
244
244
  const absolutify = makeCacheable(_absolutify);
245
245
  exports.absolutify = absolutify;
246
246
 
247
- const PATH_QUERY_FRAGMENT_REGEXP = /^((?:\0.|[^?#\0])*)(\?(?:\0.|[^#\0])*)?(#.*)?$/;
247
+ const PATH_QUERY_FRAGMENT_REGEXP =
248
+ /^((?:\0.|[^?#\0])*)(\?(?:\0.|[^#\0])*)?(#.*)?$/;
248
249
 
249
250
  /** @typedef {{ resource: string, path: string, query: string, fragment: string }} ParsedResource */
250
251
 
@@ -45,6 +45,8 @@ module.exports = {
45
45
  require("../dependencies/AMDRequireItemDependency"),
46
46
  "dependencies/CachedConstDependency": () =>
47
47
  require("../dependencies/CachedConstDependency"),
48
+ "dependencies/CreateScriptUrlDependency": () =>
49
+ require("../dependencies/CreateScriptUrlDependency"),
48
50
  "dependencies/CommonJsRequireContextDependency": () =>
49
51
  require("../dependencies/CommonJsRequireContextDependency"),
50
52
  "dependencies/CommonJsExportRequireDependency": () =>