webpack 5.86.0 → 5.88.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.
- package/README.md +5 -2
- package/lib/APIPlugin.js +1 -1
- package/lib/AsyncDependenciesBlock.js +3 -3
- package/lib/CaseSensitiveModulesWarning.js +3 -1
- package/lib/ChunkGraph.js +4 -4
- package/lib/ChunkGroup.js +10 -3
- package/lib/CompatibilityPlugin.js +50 -30
- package/lib/Compilation.js +2 -1
- package/lib/Compiler.js +3 -1
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ConditionalInitFragment.js +11 -1
- package/lib/ConstPlugin.js +57 -29
- package/lib/ContextModule.js +4 -1
- package/lib/ContextReplacementPlugin.js +13 -0
- package/lib/DelegatedModule.js +15 -3
- package/lib/DelegatedModuleFactoryPlugin.js +6 -0
- package/lib/Dependency.js +11 -5
- package/lib/DllEntryPlugin.js +11 -1
- package/lib/DllReferencePlugin.js +13 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ErrorHelpers.js +1 -0
- package/lib/EvalSourceMapDevToolPlugin.js +4 -0
- package/lib/ExportsInfo.js +17 -3
- package/lib/ExportsInfoApiPlugin.js +14 -5
- package/lib/ExternalModule.js +5 -0
- package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
- package/lib/FlagDependencyUsagePlugin.js +3 -1
- package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
- package/lib/HotModuleReplacementPlugin.js +8 -0
- package/lib/InitFragment.js +28 -5
- package/lib/JavascriptMetaInfoPlugin.js +11 -6
- package/lib/LibManifestPlugin.js +20 -4
- package/lib/Module.js +7 -2
- package/lib/ModuleDependencyError.js +4 -2
- package/lib/ModuleDependencyWarning.js +4 -2
- package/lib/ModuleGraph.js +31 -24
- package/lib/ModuleGraphConnection.js +19 -6
- package/lib/ModuleInfoHeaderPlugin.js +9 -2
- package/lib/ModuleNotFoundError.js +5 -2
- package/lib/ModuleProfile.js +1 -0
- package/lib/ModuleRestoreError.js +2 -0
- package/lib/ModuleStoreError.js +2 -1
- package/lib/ModuleTypeConstants.js +7 -0
- package/lib/MultiWatching.js +4 -0
- package/lib/NodeStuffPlugin.js +32 -6
- package/lib/ProvidePlugin.js +13 -4
- package/lib/RawModule.js +3 -1
- package/lib/RequireJsStuffPlugin.js +7 -0
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimeModule.js +3 -3
- package/lib/RuntimePlugin.js +6 -3
- package/lib/RuntimeTemplate.js +22 -4
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
- package/lib/SourceMapDevToolPlugin.js +7 -2
- package/lib/UseStrictPlugin.js +10 -3
- package/lib/WebpackError.js +6 -5
- package/lib/WebpackIsIncludedPlugin.js +6 -4
- package/lib/WebpackOptionsApply.js +1 -1
- package/lib/WebpackOptionsDefaulter.js +10 -3
- package/lib/asset/AssetGenerator.js +2 -1
- package/lib/asset/AssetParser.js +11 -6
- package/lib/asset/AssetSourceParser.js +8 -3
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
- package/lib/cache/IdleFileCachePlugin.js +2 -1
- package/lib/cache/PackFileCacheStrategy.js +35 -14
- package/lib/config/browserslistTargetHandler.js +7 -7
- package/lib/config/defaults.js +43 -26
- package/lib/container/RemoteRuntimeModule.js +1 -1
- package/lib/css/CssLoadingRuntimeModule.js +30 -13
- package/lib/css/CssModulesPlugin.js +5 -2
- package/lib/css/CssParser.js +22 -0
- package/lib/dependencies/AMDDefineDependency.js +34 -4
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
- package/lib/dependencies/AMDRuntimeModules.js +2 -2
- package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
- package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
- package/lib/dependencies/CommonJsPlugin.js +13 -8
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
- package/lib/dependencies/ConstDependency.js +2 -2
- package/lib/dependencies/ContextDependency.js +7 -2
- package/lib/dependencies/CssImportDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
- package/lib/dependencies/CssUrlDependency.js +3 -3
- package/lib/dependencies/DllEntryDependency.js +5 -0
- package/lib/dependencies/DynamicExports.js +10 -6
- package/lib/dependencies/ExportsInfoDependency.js +14 -4
- package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExports.js +9 -5
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +32 -17
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +19 -9
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
- package/lib/dependencies/ImportDependency.js +5 -3
- package/lib/dependencies/ImportEagerDependency.js +5 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
- package/lib/dependencies/ImportMetaPlugin.js +31 -15
- package/lib/dependencies/ImportParserPlugin.js +62 -25
- package/lib/dependencies/ImportWeakDependency.js +5 -3
- package/lib/dependencies/ModuleDependency.js +1 -1
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
- package/lib/dependencies/ProvidedDependency.js +4 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
- package/lib/dependencies/RequireHeaderDependency.js +4 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
- package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
- package/lib/dependencies/SystemPlugin.js +17 -5
- package/lib/dependencies/SystemRuntimeModule.js +1 -1
- package/lib/dependencies/URLDependency.js +2 -2
- package/lib/dependencies/URLPlugin.js +9 -4
- package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +59 -22
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +1 -0
- package/lib/javascript/BasicEvaluatedExpression.js +23 -15
- package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
- package/lib/javascript/JavascriptParser.js +135 -63
- package/lib/javascript/JavascriptParserHelpers.js +37 -15
- package/lib/logging/runtime.js +1 -1
- package/lib/logging/truncateArgs.js +4 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
- package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
- package/lib/optimize/InnerGraph.js +1 -1
- package/lib/optimize/InnerGraphPlugin.js +2 -1
- package/lib/performance/SizeLimitsPlugin.js +7 -4
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
- package/lib/rules/BasicEffectRulePlugin.js +4 -0
- package/lib/rules/BasicMatcherRulePlugin.js +5 -0
- package/lib/rules/RuleSetCompiler.js +3 -3
- package/lib/rules/UseEffectRulePlugin.js +6 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +8 -5
- package/lib/runtime/AutoPublicPathRuntimeModule.js +4 -2
- package/lib/runtime/BaseUriRuntimeModule.js +3 -3
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
- package/lib/runtime/CompatRuntimeModule.js +7 -2
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
- package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
- package/lib/runtime/EnsureChunkRuntimeModule.js +15 -4
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -10
- package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
- package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -2
- package/lib/runtime/GlobalRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
- package/lib/runtime/LoadScriptRuntimeModule.js +64 -48
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
- package/lib/runtime/NonceRuntimeModule.js +1 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
- package/lib/runtime/PublicPathRuntimeModule.js +4 -2
- package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
- package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -3
- package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -2
- package/lib/runtime/SystemContextRuntimeModule.js +1 -1
- package/lib/serialization/ObjectMiddleware.js +6 -3
- package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +14 -5
- package/lib/sharing/ProvideSharedDependency.js +11 -0
- package/lib/sharing/ProvideSharedModule.js +4 -0
- package/lib/sharing/ProvideSharedPlugin.js +22 -21
- package/lib/sharing/ShareRuntimeModule.js +12 -5
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/sharing/utils.js +32 -5
- package/lib/util/AsyncQueue.js +4 -2
- package/lib/util/ParallelismFactorCalculator.js +10 -0
- package/lib/util/Semaphore.js +1 -1
- package/lib/util/createHash.js +30 -9
- package/lib/util/deprecation.js +10 -3
- package/lib/util/deterministicGrouping.js +50 -11
- package/lib/util/findGraphRoots.js +4 -2
- package/lib/util/memoize.js +3 -3
- package/lib/util/processAsyncTree.js +7 -1
- package/lib/util/registerExternalSerializer.js +1 -1
- package/lib/util/runtime.js +14 -1
- package/lib/util/smartGrouping.js +1 -1
- package/lib/validateSchema.js +6 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +6 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +14 -7
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
- package/lib/wasm-sync/WebAssemblyParser.js +6 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +14 -4
- package/lib/webpack.js +11 -2
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -16
- package/module.d.ts +1 -0
- package/package.json +5 -4
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +39 -5
- package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
- package/schemas/plugins/css/CssParserOptions.json +1 -1
- package/types.d.ts +519 -222
@@ -17,24 +17,31 @@ 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;
|
27
32
|
}
|
28
33
|
|
29
34
|
/**
|
30
|
-
* @returns {string} runtime code
|
35
|
+
* @returns {string | null} runtime code
|
31
36
|
*/
|
32
37
|
generate() {
|
33
|
-
const
|
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
|
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
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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,24 +13,31 @@ 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");
|
19
23
|
}
|
20
24
|
|
21
25
|
/**
|
22
|
-
* @returns {string} runtime code
|
26
|
+
* @returns {string | null} runtime code
|
23
27
|
*/
|
24
28
|
generate() {
|
25
|
-
const
|
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
|
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
|
-
|
88
|
+
ignoreBrowserWarnings
|
82
89
|
? runtimeTemplate.basicFunction("", "")
|
83
90
|
: runtimeTemplate.basicFunction("msg", [
|
84
91
|
'if (typeof console !== "undefined" && console.warn) console.warn(msg);'
|
package/lib/sharing/utils.js
CHANGED
@@ -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 {
|
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 (
|
152
|
-
|
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;
|
package/lib/util/AsyncQueue.js
CHANGED
@@ -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 =
|
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);
|
package/lib/util/Semaphore.js
CHANGED
package/lib/util/createHash.js
CHANGED
@@ -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 |
|
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)
|
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)
|
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}](${
|
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(
|
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(
|
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(
|
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
|
-
() =>
|
186
|
+
() =>
|
187
|
+
/** @type {typeof import("crypto")} */ (crypto).createHash(
|
188
|
+
/** @type {string} */ (algorithm)
|
189
|
+
),
|
169
190
|
algorithm
|
170
191
|
);
|
171
192
|
}
|
package/lib/util/deprecation.js
CHANGED
@@ -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),
|
@@ -94,7 +94,8 @@ const subtractSizeFrom = (total, size) => {
|
|
94
94
|
};
|
95
95
|
|
96
96
|
/**
|
97
|
-
* @
|
97
|
+
* @template T
|
98
|
+
* @param {Iterable<Node<T>>} nodes some nodes
|
98
99
|
* @returns {Record<string, number>} total size
|
99
100
|
*/
|
100
101
|
const sumSize = nodes => {
|
@@ -105,6 +106,11 @@ const sumSize = nodes => {
|
|
105
106
|
return sum;
|
106
107
|
};
|
107
108
|
|
109
|
+
/**
|
110
|
+
* @param {Record<string, number>} size size
|
111
|
+
* @param {Record<string, number>} maxSize minimum size
|
112
|
+
* @returns {boolean} true, when size is too big
|
113
|
+
*/
|
108
114
|
const isTooBig = (size, maxSize) => {
|
109
115
|
for (const key of Object.keys(size)) {
|
110
116
|
const s = size[key];
|
@@ -117,6 +123,11 @@ const isTooBig = (size, maxSize) => {
|
|
117
123
|
return false;
|
118
124
|
};
|
119
125
|
|
126
|
+
/**
|
127
|
+
* @param {Record<string, number>} size size
|
128
|
+
* @param {Record<string, number>} minSize minimum size
|
129
|
+
* @returns {boolean} true, when size is too small
|
130
|
+
*/
|
120
131
|
const isTooSmall = (size, minSize) => {
|
121
132
|
for (const key of Object.keys(size)) {
|
122
133
|
const s = size[key];
|
@@ -129,6 +140,11 @@ const isTooSmall = (size, minSize) => {
|
|
129
140
|
return false;
|
130
141
|
};
|
131
142
|
|
143
|
+
/**
|
144
|
+
* @param {Record<string, number>} size size
|
145
|
+
* @param {Record<string, number>} minSize minimum size
|
146
|
+
* @returns {Set<string>} set of types that are too small
|
147
|
+
*/
|
132
148
|
const getTooSmallTypes = (size, minSize) => {
|
133
149
|
const types = new Set();
|
134
150
|
for (const key of Object.keys(size)) {
|
@@ -142,6 +158,12 @@ const getTooSmallTypes = (size, minSize) => {
|
|
142
158
|
return types;
|
143
159
|
};
|
144
160
|
|
161
|
+
/**
|
162
|
+
* @template T
|
163
|
+
* @param {TODO} size size
|
164
|
+
* @param {Set<string>} types types
|
165
|
+
* @returns {number} number of matching size types
|
166
|
+
*/
|
145
167
|
const getNumberOfMatchingSizeTypes = (size, types) => {
|
146
168
|
let i = 0;
|
147
169
|
for (const key of Object.keys(size)) {
|
@@ -150,6 +172,11 @@ const getNumberOfMatchingSizeTypes = (size, types) => {
|
|
150
172
|
return i;
|
151
173
|
};
|
152
174
|
|
175
|
+
/**
|
176
|
+
* @param {Record<string, number>} size size
|
177
|
+
* @param {Set<string>} types types
|
178
|
+
* @returns {number} selective size sum
|
179
|
+
*/
|
153
180
|
const selectiveSizeSum = (size, types) => {
|
154
181
|
let sum = 0;
|
155
182
|
for (const key of Object.keys(size)) {
|
@@ -180,20 +207,20 @@ class Node {
|
|
180
207
|
class Group {
|
181
208
|
/**
|
182
209
|
* @param {Node<T>[]} nodes nodes
|
183
|
-
* @param {number[]} similarities similarities between the nodes (length = nodes.length - 1)
|
210
|
+
* @param {number[] | null} similarities similarities between the nodes (length = nodes.length - 1)
|
184
211
|
* @param {Record<string, number>=} size size of the group
|
185
212
|
*/
|
186
213
|
constructor(nodes, similarities, size) {
|
187
214
|
this.nodes = nodes;
|
188
215
|
this.similarities = similarities;
|
189
216
|
this.size = size || sumSize(nodes);
|
190
|
-
/** @type {string} */
|
217
|
+
/** @type {string | undefined} */
|
191
218
|
this.key = undefined;
|
192
219
|
}
|
193
220
|
|
194
221
|
/**
|
195
|
-
* @param {function(Node): boolean} filter filter function
|
196
|
-
* @returns {Node[]} removed nodes
|
222
|
+
* @param {function(Node<T>): boolean} filter filter function
|
223
|
+
* @returns {Node<T>[] | undefined} removed nodes
|
197
224
|
*/
|
198
225
|
popNodes(filter) {
|
199
226
|
const newNodes = [];
|
@@ -208,7 +235,7 @@ class Group {
|
|
208
235
|
if (newNodes.length > 0) {
|
209
236
|
newSimilarities.push(
|
210
237
|
lastNode === this.nodes[i - 1]
|
211
|
-
? this.similarities[i - 1]
|
238
|
+
? /** @type {number[]} */ (this.similarities)[i - 1]
|
212
239
|
: similarity(lastNode.key, node.key)
|
213
240
|
);
|
214
241
|
}
|
@@ -225,7 +252,8 @@ class Group {
|
|
225
252
|
}
|
226
253
|
|
227
254
|
/**
|
228
|
-
* @
|
255
|
+
* @template T
|
256
|
+
* @param {Iterable<Node<T>>} nodes nodes
|
229
257
|
* @returns {number[]} similarities
|
230
258
|
*/
|
231
259
|
const getSimilarities = nodes => {
|
@@ -297,6 +325,11 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
297
325
|
if (initialNodes.length > 0) {
|
298
326
|
const initialGroup = new Group(initialNodes, getSimilarities(initialNodes));
|
299
327
|
|
328
|
+
/**
|
329
|
+
* @param {Group<T>} group group
|
330
|
+
* @param {Record<string, number>} consideredSize size of the group to consider
|
331
|
+
* @returns {boolean} true, if the group was modified
|
332
|
+
*/
|
300
333
|
const removeProblematicNodes = (group, consideredSize = group.size) => {
|
301
334
|
const problemTypes = getTooSmallTypes(consideredSize, minSize);
|
302
335
|
if (problemTypes.size > 0) {
|
@@ -347,7 +380,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
347
380
|
const queue = [initialGroup];
|
348
381
|
|
349
382
|
while (queue.length) {
|
350
|
-
const group = queue.pop();
|
383
|
+
const group = /** @type {Group<T>} */ (queue.pop());
|
351
384
|
// only groups bigger than maxSize need to be splitted
|
352
385
|
if (!isTooBig(group.size, maxSize)) {
|
353
386
|
result.push(group);
|
@@ -428,7 +461,9 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
428
461
|
// rightSize ^^^^^^^^^^^^^^^
|
429
462
|
|
430
463
|
while (pos <= right + 1) {
|
431
|
-
const similarity = group.similarities[
|
464
|
+
const similarity = /** @type {number[]} */ (group.similarities)[
|
465
|
+
pos - 1
|
466
|
+
];
|
432
467
|
if (
|
433
468
|
similarity < bestSimilarity &&
|
434
469
|
!isTooSmall(leftSize, minSize) &&
|
@@ -458,7 +493,9 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
458
493
|
/** @type {number[]} */
|
459
494
|
const rightSimilarities = [];
|
460
495
|
for (let i = right + 2; i < group.nodes.length; i++) {
|
461
|
-
rightSimilarities.push(
|
496
|
+
rightSimilarities.push(
|
497
|
+
/** @type {number[]} */ (group.similarities)[i - 1]
|
498
|
+
);
|
462
499
|
rightNodes.push(group.nodes[i]);
|
463
500
|
}
|
464
501
|
queue.push(new Group(rightNodes, rightSimilarities));
|
@@ -467,7 +504,9 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
|
|
467
504
|
/** @type {number[]} */
|
468
505
|
const leftSimilarities = [];
|
469
506
|
for (let i = 1; i < left; i++) {
|
470
|
-
leftSimilarities.push(
|
507
|
+
leftSimilarities.push(
|
508
|
+
/** @type {number[]} */ (group.similarities)[i - 1]
|
509
|
+
);
|
471
510
|
leftNodes.push(group.nodes[i]);
|
472
511
|
}
|
473
512
|
queue.push(new Group(leftNodes, leftSimilarities));
|
@@ -109,7 +109,9 @@ module.exports = (items, getDependencies) => {
|
|
109
109
|
// Are there still edges unprocessed in the current node?
|
110
110
|
if (topOfStack.openEdges.length > 0) {
|
111
111
|
// Process one dependency
|
112
|
-
const dependency =
|
112
|
+
const dependency =
|
113
|
+
/** @type {Node<T>} */
|
114
|
+
(topOfStack.openEdges.pop());
|
113
115
|
switch (dependency.marker) {
|
114
116
|
case NO_MARKER:
|
115
117
|
// dependency has not be visited yet
|
@@ -169,7 +171,7 @@ module.exports = (items, getDependencies) => {
|
|
169
171
|
// so it's not really a root cycle
|
170
172
|
// remove the cycle from the root cycles
|
171
173
|
// and convert it to a normal node
|
172
|
-
rootCycles.delete(dependency.cycle);
|
174
|
+
rootCycles.delete(/** @type {Cycle<T>} */ (dependency.cycle));
|
173
175
|
dependency.marker = DONE_MARKER;
|
174
176
|
break;
|
175
177
|
// DONE_MARKER: nothing to do, don't recurse into dependencies
|