webpack 5.86.0 → 5.87.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (105) hide show
  1. package/README.md +5 -2
  2. package/lib/CaseSensitiveModulesWarning.js +3 -1
  3. package/lib/ChunkGroup.js +1 -0
  4. package/lib/Compiler.js +3 -1
  5. package/lib/ConcatenationScope.js +2 -2
  6. package/lib/ConditionalInitFragment.js +11 -1
  7. package/lib/ConstPlugin.js +57 -29
  8. package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
  9. package/lib/ModuleDependencyError.js +4 -2
  10. package/lib/ModuleDependencyWarning.js +4 -2
  11. package/lib/ModuleGraph.js +31 -24
  12. package/lib/ModuleGraphConnection.js +19 -6
  13. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  14. package/lib/ModuleNotFoundError.js +5 -2
  15. package/lib/ModuleStoreError.js +2 -1
  16. package/lib/ModuleTypeConstants.js +7 -0
  17. package/lib/MultiWatching.js +4 -0
  18. package/lib/RuntimeGlobals.js +5 -0
  19. package/lib/RuntimePlugin.js +2 -1
  20. package/lib/RuntimeTemplate.js +20 -2
  21. package/lib/WebpackError.js +6 -5
  22. package/lib/WebpackOptionsApply.js +1 -1
  23. package/lib/WebpackOptionsDefaulter.js +10 -3
  24. package/lib/config/defaults.js +31 -2
  25. package/lib/css/CssModulesPlugin.js +5 -2
  26. package/lib/css/CssParser.js +12 -0
  27. package/lib/dependencies/ConstDependency.js +2 -2
  28. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
  29. package/lib/dependencies/ImportParserPlugin.js +25 -1
  30. package/lib/ids/SyncModuleIdsPlugin.js +1 -0
  31. package/lib/javascript/BasicEvaluatedExpression.js +23 -15
  32. package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
  33. package/lib/javascript/JavascriptParser.js +118 -58
  34. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  35. package/lib/performance/SizeLimitsPlugin.js +7 -4
  36. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +3 -1
  37. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  38. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +5 -2
  39. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +3 -1
  40. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +3 -1
  41. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  42. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  43. package/lib/rules/RuleSetCompiler.js +3 -3
  44. package/lib/rules/UseEffectRulePlugin.js +6 -4
  45. package/lib/runtime/AsyncModuleRuntimeModule.js +4 -1
  46. package/lib/runtime/AutoPublicPathRuntimeModule.js +3 -1
  47. package/lib/runtime/BaseUriRuntimeModule.js +2 -2
  48. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +4 -1
  49. package/lib/runtime/CompatRuntimeModule.js +6 -1
  50. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +4 -1
  51. package/lib/runtime/CreateScriptRuntimeModule.js +3 -1
  52. package/lib/runtime/CreateScriptUrlRuntimeModule.js +3 -1
  53. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +4 -1
  54. package/lib/runtime/EnsureChunkRuntimeModule.js +14 -3
  55. package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -9
  56. package/lib/runtime/GetFullHashRuntimeModule.js +3 -2
  57. package/lib/runtime/GetMainFilenameRuntimeModule.js +4 -1
  58. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +3 -1
  59. package/lib/runtime/HasOwnPropertyRuntimeModule.js +4 -1
  60. package/lib/runtime/LoadScriptRuntimeModule.js +63 -47
  61. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +4 -1
  62. package/lib/runtime/OnChunksLoadedRuntimeModule.js +3 -1
  63. package/lib/runtime/PublicPathRuntimeModule.js +3 -1
  64. package/lib/runtime/RelativeUrlRuntimeModule.js +4 -1
  65. package/lib/runtime/RuntimeIdRuntimeModule.js +5 -1
  66. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -2
  67. package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -1
  68. package/lib/serialization/ObjectMiddleware.js +6 -3
  69. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  70. package/lib/sharing/ConsumeSharedRuntimeModule.js +13 -4
  71. package/lib/sharing/ProvideSharedDependency.js +11 -0
  72. package/lib/sharing/ProvideSharedModule.js +4 -0
  73. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  74. package/lib/sharing/ShareRuntimeModule.js +11 -4
  75. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  76. package/lib/sharing/utils.js +32 -5
  77. package/lib/util/AsyncQueue.js +4 -2
  78. package/lib/util/ParallelismFactorCalculator.js +10 -0
  79. package/lib/util/Semaphore.js +1 -1
  80. package/lib/util/createHash.js +30 -9
  81. package/lib/util/deprecation.js +10 -3
  82. package/lib/util/deterministicGrouping.js +50 -11
  83. package/lib/util/findGraphRoots.js +4 -2
  84. package/lib/util/memoize.js +3 -3
  85. package/lib/util/processAsyncTree.js +7 -1
  86. package/lib/util/registerExternalSerializer.js +1 -1
  87. package/lib/util/runtime.js +14 -1
  88. package/lib/util/smartGrouping.js +1 -1
  89. package/lib/validateSchema.js +6 -2
  90. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -1
  91. package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
  92. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +13 -6
  93. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
  94. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  95. package/lib/wasm-sync/WebAssemblyParser.js +6 -2
  96. package/lib/web/JsonpChunkLoadingRuntimeModule.js +13 -3
  97. package/lib/webpack.js +11 -2
  98. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -15
  99. package/module.d.ts +1 -0
  100. package/package.json +4 -4
  101. package/schemas/WebpackOptions.check.js +1 -1
  102. package/schemas/WebpackOptions.json +39 -5
  103. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  104. package/schemas/plugins/css/CssParserOptions.json +1 -1
  105. package/types.d.ts +433 -184
@@ -8,6 +8,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const RuntimeModule = require("../RuntimeModule");
9
9
 
10
10
  /** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} OutputOptions */
11
+ /** @typedef {import("../Compilation")} Compilation */
11
12
 
12
13
  class PublicPathRuntimeModule extends RuntimeModule {
13
14
  /**
@@ -22,7 +23,8 @@ class PublicPathRuntimeModule extends RuntimeModule {
22
23
  * @returns {string} runtime code
23
24
  */
24
25
  generate() {
25
- const { compilation, publicPath } = this;
26
+ const { publicPath } = this;
27
+ const compilation = /** @type {Compilation} */ (this.compilation);
26
28
 
27
29
  return `${RuntimeGlobals.publicPath} = ${JSON.stringify(
28
30
  compilation.getPath(publicPath || "", {
@@ -8,6 +8,8 @@ const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const Template = require("../Template");
9
9
  const HelperRuntimeModule = require("./HelperRuntimeModule");
10
10
 
11
+ /** @typedef {import("../Compilation")} Compilation */
12
+
11
13
  class RelativeUrlRuntimeModule extends HelperRuntimeModule {
12
14
  constructor() {
13
15
  super("relative url");
@@ -17,7 +19,8 @@ class RelativeUrlRuntimeModule extends HelperRuntimeModule {
17
19
  * @returns {string} runtime code
18
20
  */
19
21
  generate() {
20
- const { runtimeTemplate } = this.compilation;
22
+ const compilation = /** @type {Compilation} */ (this.compilation);
23
+ const { runtimeTemplate } = compilation;
21
24
  return Template.asString([
22
25
  `${RuntimeGlobals.relativeUrl} = function RelativeURL(url) {`,
23
26
  Template.indent([
@@ -7,6 +7,9 @@
7
7
  const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const RuntimeModule = require("../RuntimeModule");
9
9
 
10
+ /** @typedef {import("../Chunk")} Chunk */
11
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
12
+
10
13
  class RuntimeIdRuntimeModule extends RuntimeModule {
11
14
  constructor() {
12
15
  super("runtimeId");
@@ -16,7 +19,8 @@ class RuntimeIdRuntimeModule extends RuntimeModule {
16
19
  * @returns {string} runtime code
17
20
  */
18
21
  generate() {
19
- const { chunkGraph, chunk } = this;
22
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
23
+ const chunk = /** @type {Chunk} */ (this.chunk);
20
24
  const runtime = chunk.runtime;
21
25
  if (typeof runtime !== "string")
22
26
  throw new Error("RuntimeIdRuntimeModule must be in a single runtime");
@@ -9,6 +9,10 @@ const RuntimeGlobals = require("../RuntimeGlobals");
9
9
  const RuntimeModule = require("../RuntimeModule");
10
10
  const Template = require("../Template");
11
11
 
12
+ /** @typedef {import("../Chunk")} Chunk */
13
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
14
+ /** @typedef {import("../Compilation")} Compilation */
15
+
12
16
  class StartupChunkDependenciesRuntimeModule extends RuntimeModule {
13
17
  /**
14
18
  * @param {boolean} asyncChunkLoading use async chunk loading
@@ -22,13 +26,15 @@ class StartupChunkDependenciesRuntimeModule extends RuntimeModule {
22
26
  * @returns {string} runtime code
23
27
  */
24
28
  generate() {
25
- const { chunkGraph, chunk, compilation } = this;
26
- const { runtimeTemplate } = compilation;
29
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
30
+ const chunk = /** @type {Chunk} */ (this.chunk);
27
31
  const chunkIds = Array.from(
28
32
  chunkGraph.getChunkEntryDependentChunksIterable(chunk)
29
33
  ).map(chunk => {
30
34
  return chunk.id;
31
35
  });
36
+ const compilation = /** @type {Compilation} */ (this.compilation);
37
+ const { runtimeTemplate } = compilation;
32
38
  return Template.asString([
33
39
  `var next = ${RuntimeGlobals.startup};`,
34
40
  `${RuntimeGlobals.startup} = ${runtimeTemplate.basicFunction(
@@ -7,6 +7,7 @@
7
7
  const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const RuntimeModule = require("../RuntimeModule");
9
9
 
10
+ /** @typedef {import("../Compilation")} Compilation */
10
11
  /** @typedef {import("../MainTemplate")} MainTemplate */
11
12
 
12
13
  class StartupEntrypointRuntimeModule extends RuntimeModule {
@@ -22,7 +23,7 @@ class StartupEntrypointRuntimeModule extends RuntimeModule {
22
23
  * @returns {string} runtime code
23
24
  */
24
25
  generate() {
25
- const { compilation } = this;
26
+ const compilation = /** @type {Compilation} */ (this.compilation);
26
27
  const { runtimeTemplate } = compilation;
27
28
  return `${
28
29
  RuntimeGlobals.startupEntrypoint
@@ -107,7 +107,7 @@ const ESCAPE_UNDEFINED = false;
107
107
 
108
108
  const CURRENT_VERSION = 2;
109
109
 
110
- /** @type {Map<Constructor, { request?: string, name?: string | number , serializer?: ObjectSerializer }>} */
110
+ /** @type {Map<Constructor, { request?: string, name?: string | number | null, serializer?: ObjectSerializer }>} */
111
111
  const serializers = new Map();
112
112
  /** @type {Map<string | number, ObjectSerializer>} */
113
113
  const serializerInversed = new Map();
@@ -158,7 +158,10 @@ if (exports.constructor !== Object) {
158
158
  }
159
159
 
160
160
  for (const { request, name, serializer } of serializers.values()) {
161
- serializerInversed.set(`${request}/${name}`, serializer);
161
+ serializerInversed.set(
162
+ `${request}/${name}`,
163
+ /** @type {ObjectSerializer} */ (serializer)
164
+ );
162
165
  }
163
166
 
164
167
  /** @type {Map<RegExp, (request: string) => boolean>} */
@@ -191,7 +194,7 @@ class ObjectMiddleware extends SerializerMiddleware {
191
194
  /**
192
195
  * @param {Constructor} Constructor the constructor
193
196
  * @param {string} request the request which will be required when deserializing
194
- * @param {string} name the name to make multiple serializer unique when sharing a request
197
+ * @param {string | null} name the name to make multiple serializer unique when sharing a request
195
198
  * @param {ObjectSerializer} serializer the serializer
196
199
  * @returns {void}
197
200
  */
@@ -9,6 +9,9 @@ const ModuleDependency = require("../dependencies/ModuleDependency");
9
9
  const makeSerializable = require("../util/makeSerializable");
10
10
 
11
11
  class ConsumeSharedFallbackDependency extends ModuleDependency {
12
+ /**
13
+ * @param {string} request the request
14
+ */
12
15
  constructor(request) {
13
16
  super(request);
14
17
  }
@@ -17,10 +17,15 @@ const {
17
17
 
18
18
  /** @typedef {import("webpack-sources").Source} Source */
19
19
  /** @typedef {import("../Chunk")} Chunk */
20
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
21
+ /** @typedef {import("../Compilation")} Compilation */
20
22
  /** @typedef {import("../Module")} Module */
21
23
  /** @typedef {import("./ConsumeSharedModule")} ConsumeSharedModule */
22
24
 
23
25
  class ConsumeSharedRuntimeModule extends RuntimeModule {
26
+ /**
27
+ * @param {ReadonlySet<string>} runtimeRequirements runtime requirements
28
+ */
24
29
  constructor(runtimeRequirements) {
25
30
  super("consumes", RuntimeModule.STAGE_ATTACH);
26
31
  this._runtimeRequirements = runtimeRequirements;
@@ -30,11 +35,13 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
30
35
  * @returns {string} runtime code
31
36
  */
32
37
  generate() {
33
- const { compilation, chunkGraph } = this;
38
+ const compilation = /** @type {Compilation} */ (this.compilation);
39
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
34
40
  const { runtimeTemplate, codeGenerationResults } = compilation;
35
41
  const chunkToModuleMapping = {};
36
42
  /** @type {Map<string | number, Source>} */
37
43
  const moduleIdToSourceMapping = new Map();
44
+ /** @type {(string | number)[]} */
38
45
  const initialConsumes = [];
39
46
  /**
40
47
  *
@@ -57,7 +64,7 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
57
64
  );
58
65
  }
59
66
  };
60
- for (const chunk of this.chunk.getAllAsyncChunks()) {
67
+ for (const chunk of /** @type {Chunk} */ (this.chunk).getAllAsyncChunks()) {
61
68
  const modules = chunkGraph.getChunkModulesIterableBySourceType(
62
69
  chunk,
63
70
  "consume-shared"
@@ -65,7 +72,9 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
65
72
  if (!modules) continue;
66
73
  addModules(modules, chunk, (chunkToModuleMapping[chunk.id] = []));
67
74
  }
68
- for (const chunk of this.chunk.getAllInitialChunks()) {
75
+ for (const chunk of /** @type {Chunk} */ (
76
+ this.chunk
77
+ ).getAllInitialChunks()) {
69
78
  const modules = chunkGraph.getChunkModulesIterableBySourceType(
70
79
  chunk,
71
80
  "consume-shared"
@@ -166,7 +175,7 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
166
175
  ]
167
176
  )};`,
168
177
  `var warn = ${
169
- this.compilation.options.output.ignoreBrowserWarnings
178
+ compilation.outputOptions.ignoreBrowserWarnings
170
179
  ? runtimeTemplate.basicFunction("", "")
171
180
  : runtimeTemplate.basicFunction("msg", [
172
181
  'if (typeof console !== "undefined" && console.warn) console.warn(msg);'
@@ -12,6 +12,13 @@ const makeSerializable = require("../util/makeSerializable");
12
12
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
13
13
 
14
14
  class ProvideSharedDependency extends Dependency {
15
+ /**
16
+ * @param {string} shareScope share scope
17
+ * @param {string} name module name
18
+ * @param {string | false} version version
19
+ * @param {string} request request
20
+ * @param {boolean} eager true, if this is an eager dependency
21
+ */
15
22
  constructor(shareScope, name, version, request, eager) {
16
23
  super();
17
24
  this.shareScope = shareScope;
@@ -46,6 +53,10 @@ class ProvideSharedDependency extends Dependency {
46
53
  super.serialize(context);
47
54
  }
48
55
 
56
+ /**
57
+ * @param {ObjectDeserializerContext} context context
58
+ * @returns {ProvideSharedDependency} deserialize fallback dependency
59
+ */
49
60
  static deserialize(context) {
50
61
  const { read } = context;
51
62
  const obj = new ProvideSharedDependency(
@@ -174,6 +174,10 @@ class ProvideSharedModule extends Module {
174
174
  super.serialize(context);
175
175
  }
176
176
 
177
+ /**
178
+ * @param {ObjectDeserializerContext} context context
179
+ * @returns {ProvideSharedModule} deserialize fallback dependency
180
+ */
177
181
  static deserialize(context) {
178
182
  const { read } = context;
179
183
  const obj = new ProvideSharedModule(read(), read(), read(), read(), read());
@@ -42,27 +42,28 @@ class ProvideSharedPlugin {
42
42
  constructor(options) {
43
43
  validate(options);
44
44
 
45
- /** @type {[string, ProvideOptions][]} */
46
- this._provides = parseOptions(
47
- options.provides,
48
- item => {
49
- if (Array.isArray(item))
50
- throw new Error("Unexpected array of provides");
51
- /** @type {ProvideOptions} */
52
- const result = {
53
- shareKey: item,
54
- version: undefined,
55
- shareScope: options.shareScope || "default",
56
- eager: false
57
- };
58
- return result;
59
- },
60
- item => ({
61
- shareKey: item.shareKey,
62
- version: item.version,
63
- shareScope: item.shareScope || options.shareScope || "default",
64
- eager: !!item.eager
65
- })
45
+ this._provides = /** @type {[string, ProvideOptions][]} */ (
46
+ parseOptions(
47
+ options.provides,
48
+ item => {
49
+ if (Array.isArray(item))
50
+ throw new Error("Unexpected array of provides");
51
+ /** @type {ProvideOptions} */
52
+ const result = {
53
+ shareKey: item,
54
+ version: undefined,
55
+ shareScope: options.shareScope || "default",
56
+ eager: false
57
+ };
58
+ return result;
59
+ },
60
+ item => ({
61
+ shareKey: item.shareKey,
62
+ version: item.version,
63
+ shareScope: item.shareScope || options.shareScope || "default",
64
+ eager: !!item.eager
65
+ })
66
+ )
66
67
  );
67
68
  this._provides.sort(([a], [b]) => {
68
69
  if (a < b) return -1;
@@ -13,6 +13,10 @@ const {
13
13
  compareStrings
14
14
  } = require("../util/comparators");
15
15
 
16
+ /** @typedef {import("../Chunk")} Chunk */
17
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
18
+ /** @typedef {import("../Compilation")} Compilation */
19
+
16
20
  class ShareRuntimeModule extends RuntimeModule {
17
21
  constructor() {
18
22
  super("sharing");
@@ -22,15 +26,18 @@ class ShareRuntimeModule extends RuntimeModule {
22
26
  * @returns {string} runtime code
23
27
  */
24
28
  generate() {
25
- const { compilation, chunkGraph } = this;
29
+ const compilation = /** @type {Compilation} */ (this.compilation);
26
30
  const {
27
31
  runtimeTemplate,
28
32
  codeGenerationResults,
29
- outputOptions: { uniqueName }
33
+ outputOptions: { uniqueName, ignoreBrowserWarnings }
30
34
  } = compilation;
35
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
31
36
  /** @type {Map<string, Map<number, Set<string>>>} */
32
37
  const initCodePerScope = new Map();
33
- for (const chunk of this.chunk.getAllReferencedChunks()) {
38
+ for (const chunk of /** @type {Chunk} */ (
39
+ this.chunk
40
+ ).getAllReferencedChunks()) {
34
41
  const modules = chunkGraph.getOrderedChunkModulesIterableBySourceType(
35
42
  chunk,
36
43
  "share-init",
@@ -78,7 +85,7 @@ class ShareRuntimeModule extends RuntimeModule {
78
85
  "// runs all init snippets from all modules reachable",
79
86
  `var scope = ${RuntimeGlobals.shareScopeMap}[name];`,
80
87
  `var warn = ${
81
- this.compilation.options.output.ignoreBrowserWarnings
88
+ ignoreBrowserWarnings
82
89
  ? runtimeTemplate.basicFunction("", "")
83
90
  : runtimeTemplate.basicFunction("msg", [
84
91
  'if (typeof console !== "undefined" && console.warn) console.warn(msg);'
@@ -66,7 +66,7 @@ exports.resolveMatchedConfigs = (compilation, configs) => {
66
66
  );
67
67
  return resolve();
68
68
  }
69
- resolved.set(result, config);
69
+ resolved.set(/** @type {string} */ (result), config);
70
70
  resolve();
71
71
  }
72
72
  );
@@ -52,6 +52,11 @@ const DEF_GIT_PROTOCOL = "git+ssh://";
52
52
 
53
53
  // thanks to https://github.com/npm/hosted-git-info/blob/latest/git-host-info.js
54
54
  const extractCommithashByDomain = {
55
+ /**
56
+ * @param {string} pathname pathname
57
+ * @param {string} hash hash
58
+ * @returns {string | undefined} hash
59
+ */
55
60
  "github.com": (pathname, hash) => {
56
61
  let [, user, project, type, commithash] = pathname.split("/", 5);
57
62
  if (type && type !== "tree") {
@@ -74,6 +79,11 @@ const extractCommithashByDomain = {
74
79
 
75
80
  return commithash;
76
81
  },
82
+ /**
83
+ * @param {string} pathname pathname
84
+ * @param {string} hash hash
85
+ * @returns {string | undefined} hash
86
+ */
77
87
  "gitlab.com": (pathname, hash) => {
78
88
  const path = pathname.slice(1);
79
89
  if (path.includes("/-/") || path.includes("/archive.tar.gz")) {
@@ -81,7 +91,7 @@ const extractCommithashByDomain = {
81
91
  }
82
92
 
83
93
  const segments = path.split("/");
84
- let project = segments.pop();
94
+ let project = /** @type {string} */ (segments.pop());
85
95
  if (project.endsWith(".git")) {
86
96
  project = project.slice(0, -4);
87
97
  }
@@ -93,6 +103,11 @@ const extractCommithashByDomain = {
93
103
 
94
104
  return hash;
95
105
  },
106
+ /**
107
+ * @param {string} pathname pathname
108
+ * @param {string} hash hash
109
+ * @returns {string | undefined} hash
110
+ */
96
111
  "bitbucket.org": (pathname, hash) => {
97
112
  let [, user, project, aux] = pathname.split("/", 4);
98
113
  if (["get"].includes(aux)) {
@@ -109,6 +124,11 @@ const extractCommithashByDomain = {
109
124
 
110
125
  return hash;
111
126
  },
127
+ /**
128
+ * @param {string} pathname pathname
129
+ * @param {string} hash hash
130
+ * @returns {string | undefined} hash
131
+ */
112
132
  "gist.github.com": (pathname, hash) => {
113
133
  let [, user, project, aux] = pathname.split("/", 4);
114
134
  if (aux === "raw") {
@@ -121,7 +141,6 @@ const extractCommithashByDomain = {
121
141
  }
122
142
 
123
143
  project = user;
124
- user = null;
125
144
  }
126
145
 
127
146
  if (project.endsWith(".git")) {
@@ -136,7 +155,7 @@ const extractCommithashByDomain = {
136
155
  * extract commit hash from parsed url
137
156
  *
138
157
  * @inner
139
- * @param {Object} urlParsed parsed url
158
+ * @param {URL} urlParsed parsed url
140
159
  * @returns {string} commithash
141
160
  */
142
161
  function getCommithash(urlParsed) {
@@ -148,8 +167,16 @@ function getCommithash(urlParsed) {
148
167
  // eslint-disable-next-line no-empty
149
168
  } catch (e) {}
150
169
 
151
- if (extractCommithashByDomain[hostname]) {
152
- return extractCommithashByDomain[hostname](pathname, hash) || "";
170
+ if (
171
+ extractCommithashByDomain[
172
+ /** @type {keyof extractCommithashByDomain} */ (hostname)
173
+ ]
174
+ ) {
175
+ return (
176
+ extractCommithashByDomain[
177
+ /** @type {keyof extractCommithashByDomain} */ (hostname)
178
+ ](pathname, hash) || ""
179
+ );
153
180
  }
154
181
 
155
182
  return hash;
@@ -70,7 +70,7 @@ class AsyncQueue {
70
70
  this._entries = new Map();
71
71
  /** @type {ArrayQueue<AsyncQueueEntry<T, K, R>>} */
72
72
  this._queued = new ArrayQueue();
73
- /** @type {AsyncQueue<any, any, any>[]} */
73
+ /** @type {AsyncQueue<any, any, any>[] | undefined} */
74
74
  this._children = undefined;
75
75
  this._activeTasks = 0;
76
76
  this._willEnsureProcessing = false;
@@ -159,7 +159,9 @@ class AsyncQueue {
159
159
  */
160
160
  invalidate(item) {
161
161
  const key = this._getKey(item);
162
- const entry = this._entries.get(key);
162
+ const entry =
163
+ /** @type {AsyncQueueEntry<T, K, R>} */
164
+ (this._entries.get(key));
163
165
  this._entries.delete(key);
164
166
  if (entry.state === QUEUED_STATE) {
165
167
  this._queued.delete(entry);
@@ -7,12 +7,22 @@
7
7
 
8
8
  const binarySearchBounds = require("../util/binarySearchBounds");
9
9
 
10
+ /** @typedef {function(number): void} Callback */
11
+
10
12
  class ParallelismFactorCalculator {
11
13
  constructor() {
14
+ /** @type {number[]} */
12
15
  this._rangePoints = [];
16
+ /** @type {Callback[]} */
13
17
  this._rangeCallbacks = [];
14
18
  }
15
19
 
20
+ /**
21
+ * @param {number} start range start
22
+ * @param {number} end range end
23
+ * @param {Callback} callback callback
24
+ * @returns {void}
25
+ */
16
26
  range(start, end, callback) {
17
27
  if (start === end) return callback(1);
18
28
  this._rangePoints.push(start);
@@ -44,7 +44,7 @@ class Semaphore {
44
44
  if (this.available > 0) {
45
45
  if (this.waiters.length > 0) {
46
46
  this.available--;
47
- const callback = this.waiters.pop();
47
+ const callback = /** @type {(function(): void)} */ (this.waiters.pop());
48
48
  callback();
49
49
  }
50
50
  }
@@ -11,11 +11,14 @@ const BULK_SIZE = 2000;
11
11
 
12
12
  // We are using an object instead of a Map as this will stay static during the runtime
13
13
  // so access to it can be optimized by v8
14
+ /** @type {Object<string, Map<string, string>>} */
14
15
  const digestCaches = {};
15
16
 
17
+ /** @typedef {function(): Hash} HashFactory */
18
+
16
19
  class BulkUpdateDecorator extends Hash {
17
20
  /**
18
- * @param {Hash | function(): Hash} hashOrFactory function to create a hash
21
+ * @param {Hash | HashFactory} hashOrFactory function to create a hash
19
22
  * @param {string=} hashKey key for caching
20
23
  */
21
24
  constructor(hashOrFactory, hashKey) {
@@ -43,7 +46,8 @@ class BulkUpdateDecorator extends Hash {
43
46
  typeof data !== "string" ||
44
47
  data.length > BULK_SIZE
45
48
  ) {
46
- if (this.hash === undefined) this.hash = this.hashFactory();
49
+ if (this.hash === undefined)
50
+ this.hash = /** @type {HashFactory} */ (this.hashFactory)();
47
51
  if (this.buffer.length > 0) {
48
52
  this.hash.update(this.buffer);
49
53
  this.buffer = "";
@@ -52,7 +56,8 @@ class BulkUpdateDecorator extends Hash {
52
56
  } else {
53
57
  this.buffer += data;
54
58
  if (this.buffer.length > BULK_SIZE) {
55
- if (this.hash === undefined) this.hash = this.hashFactory();
59
+ if (this.hash === undefined)
60
+ this.hash = /** @type {HashFactory} */ (this.hashFactory)();
56
61
  this.hash.update(this.buffer);
57
62
  this.buffer = "";
58
63
  }
@@ -77,7 +82,7 @@ class BulkUpdateDecorator extends Hash {
77
82
  }
78
83
  const cacheEntry = digestCache.get(buffer);
79
84
  if (cacheEntry !== undefined) return cacheEntry;
80
- this.hash = this.hashFactory();
85
+ this.hash = /** @type {HashFactory} */ (this.hashFactory)();
81
86
  }
82
87
  if (buffer.length > 0) {
83
88
  this.hash.update(buffer);
@@ -111,7 +116,9 @@ class DebugHash extends Hash {
111
116
  if (data.startsWith(prefix)) {
112
117
  data = Buffer.from(data.slice(prefix.length), "hex").toString();
113
118
  }
114
- this.string += `[${data}](${new Error().stack.split("\n", 3)[2]})\n`;
119
+ this.string += `[${data}](${
120
+ /** @type {string} */ (new Error().stack).split("\n", 3)[2]
121
+ })\n`;
115
122
  return this;
116
123
  }
117
124
 
@@ -125,9 +132,13 @@ class DebugHash extends Hash {
125
132
  }
126
133
  }
127
134
 
135
+ /** @type {typeof import("crypto") | undefined} */
128
136
  let crypto = undefined;
137
+ /** @type {typeof import("./hash/xxhash64") | undefined} */
129
138
  let createXXHash64 = undefined;
139
+ /** @type {typeof import("./hash/md4") | undefined} */
130
140
  let createMd4 = undefined;
141
+ /** @type {typeof import("./hash/BatchedHash") | undefined} */
131
142
  let BatchedHash = undefined;
132
143
 
133
144
  /**
@@ -150,7 +161,9 @@ module.exports = algorithm => {
150
161
  BatchedHash = require("./hash/BatchedHash");
151
162
  }
152
163
  }
153
- return new BatchedHash(createXXHash64());
164
+ return new /** @type {typeof import("./hash/BatchedHash")} */ (
165
+ BatchedHash
166
+ )(createXXHash64());
154
167
  case "md4":
155
168
  if (createMd4 === undefined) {
156
169
  createMd4 = require("./hash/md4");
@@ -158,14 +171,22 @@ module.exports = algorithm => {
158
171
  BatchedHash = require("./hash/BatchedHash");
159
172
  }
160
173
  }
161
- return new BatchedHash(createMd4());
174
+ return new /** @type {typeof import("./hash/BatchedHash")} */ (
175
+ BatchedHash
176
+ )(createMd4());
162
177
  case "native-md4":
163
178
  if (crypto === undefined) crypto = require("crypto");
164
- return new BulkUpdateDecorator(() => crypto.createHash("md4"), "md4");
179
+ return new BulkUpdateDecorator(
180
+ () => /** @type {typeof import("crypto")} */ (crypto).createHash("md4"),
181
+ "md4"
182
+ );
165
183
  default:
166
184
  if (crypto === undefined) crypto = require("crypto");
167
185
  return new BulkUpdateDecorator(
168
- () => crypto.createHash(algorithm),
186
+ () =>
187
+ /** @type {typeof import("crypto")} */ (crypto).createHash(
188
+ /** @type {string} */ (algorithm)
189
+ ),
169
190
  algorithm
170
191
  );
171
192
  }
@@ -78,7 +78,7 @@ exports.arrayToSetDeprecation = (set, name) => {
78
78
  );
79
79
  /**
80
80
  * @deprecated
81
- * @this {Set}
81
+ * @this {Set<any>}
82
82
  * @returns {number} count
83
83
  */
84
84
  set[method] = function () {
@@ -101,7 +101,7 @@ exports.arrayToSetDeprecation = (set, name) => {
101
101
  );
102
102
  /**
103
103
  * @deprecated
104
- * @this {Set}
104
+ * @this {Set<any>}
105
105
  * @returns {number} count
106
106
  */
107
107
  set.push = function () {
@@ -119,9 +119,13 @@ exports.arrayToSetDeprecation = (set, name) => {
119
119
  );
120
120
  };
121
121
  }
122
+ /**
123
+ * @param {number} index index
124
+ * @returns {any} value
125
+ */
122
126
  const createIndexGetter = index => {
123
127
  /**
124
- * @this {Set} a Set
128
+ * @this {Set<any>} a Set
125
129
  * @returns {any} the value at this location
126
130
  */
127
131
  const fn = function () {
@@ -134,6 +138,9 @@ exports.arrayToSetDeprecation = (set, name) => {
134
138
  };
135
139
  return fn;
136
140
  };
141
+ /**
142
+ * @param {number} index index
143
+ */
137
144
  const defineIndexGetter = index => {
138
145
  Object.defineProperty(set, index, {
139
146
  get: createIndexGetter(index),