webpack 5.99.5 → 5.99.7
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.
- package/README.md +1 -1
- package/lib/APIPlugin.js +2 -2
- package/lib/AutomaticPrefetchPlugin.js +21 -22
- package/lib/BannerPlugin.js +31 -35
- package/lib/Cache.js +1 -1
- package/lib/Chunk.js +12 -9
- package/lib/CleanPlugin.js +5 -3
- package/lib/Compilation.js +45 -35
- package/lib/Compiler.js +6 -4
- package/lib/ContextExclusionPlugin.js +4 -2
- package/lib/ContextModule.js +2 -1
- package/lib/ContextReplacementPlugin.js +5 -3
- package/lib/DelegatedPlugin.js +4 -2
- package/lib/DllEntryPlugin.js +4 -2
- package/lib/DllPlugin.js +5 -3
- package/lib/DllReferencePlugin.js +56 -60
- package/lib/DynamicEntryPlugin.js +4 -2
- package/lib/EntryOptionPlugin.js +3 -1
- package/lib/EntryPlugin.js +4 -2
- package/lib/EnvironmentPlugin.js +4 -2
- package/lib/EvalDevToolModulePlugin.js +9 -7
- package/lib/EvalSourceMapDevToolPlugin.js +137 -138
- package/lib/ExternalsPlugin.js +3 -1
- package/lib/FlagDependencyExportsPlugin.js +2 -1
- package/lib/HotModuleReplacementPlugin.js +3 -3
- package/lib/IgnorePlugin.js +6 -4
- package/lib/IgnoreWarningsPlugin.js +4 -2
- package/lib/LibManifestPlugin.js +3 -4
- package/lib/LoaderOptionsPlugin.js +4 -2
- package/lib/LoaderTargetPlugin.js +4 -2
- package/lib/Module.js +29 -14
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +15 -10
- package/lib/ModuleInfoHeaderPlugin.js +11 -12
- package/lib/MultiCompiler.js +5 -3
- package/lib/NoEmitOnErrorsPlugin.js +5 -3
- package/lib/NormalModule.js +6 -2
- package/lib/NormalModuleReplacementPlugin.js +33 -36
- package/lib/PlatformPlugin.js +3 -1
- package/lib/PrefetchPlugin.js +5 -3
- package/lib/ProgressPlugin.js +23 -26
- package/lib/RecordIdsPlugin.js +73 -103
- package/lib/RuntimePlugin.js +34 -32
- package/lib/SourceMapDevToolPlugin.js +8 -6
- package/lib/Template.js +1 -1
- package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
- package/lib/WarnNoModeSetPlugin.js +3 -1
- package/lib/WatchIgnorePlugin.js +3 -1
- package/lib/WebpackError.js +11 -3
- package/lib/WebpackOptionsApply.js +22 -5
- package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
- package/lib/buildChunkGraph.js +7 -2
- package/lib/cache/IdleFileCachePlugin.js +12 -13
- package/lib/cache/MemoryCachePlugin.js +2 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +10 -7
- package/lib/cache/PackFileCacheStrategy.js +13 -21
- package/lib/cache/ResolverCachePlugin.js +22 -22
- package/lib/cli.js +8 -4
- package/lib/config/defaults.js +2 -2
- package/lib/config/normalization.js +9 -3
- package/lib/config/target.js +6 -6
- package/lib/container/ContainerReferencePlugin.js +24 -26
- package/lib/container/ModuleFederationPlugin.js +2 -1
- package/lib/css/CssGenerator.js +1 -1
- package/lib/css/CssModulesPlugin.js +6 -4
- package/lib/css/CssParser.js +1 -1
- package/lib/debug/ProfilingPlugin.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +1 -1
- package/lib/dependencies/CssIcssImportDependency.js +3 -2
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +9 -15
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -1
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/dependencies/LoaderPlugin.js +5 -3
- package/lib/dependencies/LocalModulesHelpers.js +1 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
- package/lib/dependencies/RequireResolveDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/esm/ModuleChunkLoadingPlugin.js +76 -57
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +11 -9
- package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/LazyCompilationPlugin.js +17 -18
- package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +48 -49
- package/lib/ids/HashedModuleIdsPlugin.js +4 -2
- package/lib/ids/NamedChunkIdsPlugin.js +6 -4
- package/lib/ids/NamedModuleIdsPlugin.js +6 -4
- package/lib/ids/NaturalChunkIdsPlugin.js +4 -2
- package/lib/ids/NaturalModuleIdsPlugin.js +4 -2
- package/lib/ids/OccurrenceChunkIdsPlugin.js +4 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -2
- package/lib/index.js +1 -1
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/JavascriptParser.js +670 -688
- package/lib/library/EnableLibraryPlugin.js +15 -2
- package/lib/library/ModuleLibraryPlugin.js +66 -43
- package/lib/logging/createConsoleLogger.js +0 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +71 -75
- package/lib/node/NodeEnvironmentPlugin.js +3 -1
- package/lib/node/NodeTemplatePlugin.js +2 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +3 -3
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +224 -232
- package/lib/optimize/ConcatenatedModule.js +12 -15
- package/lib/optimize/FlagIncludedChunksPlugin.js +92 -97
- package/lib/optimize/LimitChunkCountPlugin.js +4 -2
- package/lib/optimize/MangleExportsPlugin.js +15 -16
- package/lib/optimize/MinChunkSizePlugin.js +4 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
- package/lib/optimize/RealContentHashPlugin.js +4 -2
- package/lib/optimize/RemoveEmptyChunksPlugin.js +5 -3
- package/lib/optimize/RemoveParentModulesPlugin.js +4 -2
- package/lib/optimize/RuntimeChunkPlugin.js +17 -18
- package/lib/optimize/SplitChunksPlugin.js +9 -6
- package/lib/performance/SizeLimitsPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
- package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
- package/lib/schemes/DataUriPlugin.js +5 -3
- package/lib/schemes/FileUriPlugin.js +5 -3
- package/lib/schemes/HttpUriPlugin.js +32 -39
- package/lib/serialization/AggregateErrorSerializer.js +42 -0
- package/lib/serialization/BinaryMiddleware.js +22 -38
- package/lib/serialization/ErrorObjectSerializer.js +7 -2
- package/lib/serialization/FileMiddleware.js +29 -33
- package/lib/serialization/ObjectMiddleware.js +42 -30
- package/lib/serialization/Serializer.js +29 -18
- package/lib/serialization/SerializerMiddleware.js +105 -72
- package/lib/serialization/SingleItemMiddleware.js +4 -5
- package/lib/sharing/ProvideSharedPlugin.js +6 -4
- package/lib/stats/DefaultStatsFactoryPlugin.js +128 -57
- package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +486 -334
- package/lib/stats/StatsFactory.js +47 -10
- package/lib/stats/StatsPrinter.js +52 -31
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/TupleQueue.js +9 -7
- package/lib/util/TupleSet.js +37 -18
- package/lib/util/WeakTupleMap.js +50 -37
- package/lib/util/cleverMerge.js +2 -2
- package/lib/util/comparators.js +1 -1
- package/lib/util/concatenate.js +4 -2
- package/lib/util/createHash.js +1 -1
- package/lib/util/fs.js +1 -1
- package/lib/util/makeSerializable.js +1 -1
- package/lib/util/runtime.js +1 -0
- package/lib/util/serialization.js +50 -42
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -1
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/web/FetchCompileWasmPlugin.js +2 -2
- package/lib/web/JsonpChunkLoadingPlugin.js +73 -74
- package/lib/webpack.js +1 -1
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
- package/package.json +4 -3
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +24 -2
- package/types.d.ts +273 -128
@@ -10,13 +10,33 @@ const { concatComparators, keepOriginalOrder } = require("../util/comparators");
|
|
10
10
|
const smartGrouping = require("../util/smartGrouping");
|
11
11
|
|
12
12
|
/** @typedef {import("../Chunk")} Chunk */
|
13
|
+
/** @typedef {import("../ChunkGroup").OriginRecord} OriginRecord */
|
13
14
|
/** @typedef {import("../Compilation")} Compilation */
|
15
|
+
/** @typedef {import("../Compilation").Asset} Asset */
|
14
16
|
/** @typedef {import("../Compilation").NormalizedStatsOptions} NormalizedStatsOptions */
|
17
|
+
/** @typedef {import("../Dependency")} Dependency */
|
15
18
|
/** @typedef {import("../Module")} Module */
|
19
|
+
/** @typedef {import("../ModuleGraph").ModuleProfile} ModuleProfile */
|
20
|
+
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
16
21
|
/** @typedef {import("../WebpackError")} WebpackError */
|
17
|
-
/** @typedef {import("../util/comparators").Comparator<
|
22
|
+
/** @typedef {import("../util/comparators").Comparator<EXPECTED_ANY>} Comparator */
|
18
23
|
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
19
|
-
/** @typedef {import("../util/smartGrouping").GroupConfig<
|
24
|
+
/** @typedef {import("../util/smartGrouping").GroupConfig<EXPECTED_ANY, EXPECTED_OBJECT>} GroupConfig */
|
25
|
+
/** @typedef {import("./DefaultStatsFactoryPlugin").ChunkGroupInfoWithName} ChunkGroupInfoWithName */
|
26
|
+
/** @typedef {import("./DefaultStatsFactoryPlugin").ModuleIssuerPath} ModuleIssuerPath */
|
27
|
+
/** @typedef {import("./DefaultStatsFactoryPlugin").ModuleTrace} ModuleTrace */
|
28
|
+
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsAsset} StatsAsset */
|
29
|
+
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsChunk} StatsChunk */
|
30
|
+
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsChunkGroup} StatsChunkGroup */
|
31
|
+
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsChunkOrigin} StatsChunkOrigin */
|
32
|
+
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsCompilation} StatsCompilation */
|
33
|
+
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsError} StatsError */
|
34
|
+
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsModule} StatsModule */
|
35
|
+
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsModuleIssuer} StatsModuleIssuer */
|
36
|
+
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsModuleReason} StatsModuleReason */
|
37
|
+
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsModuleTraceDependency} StatsModuleTraceDependency */
|
38
|
+
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsModuleTraceItem} StatsModuleTraceItem */
|
39
|
+
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsProfile} StatsProfile */
|
20
40
|
|
21
41
|
/**
|
22
42
|
* @typedef {object} KnownStatsFactoryContext
|
@@ -33,11 +53,24 @@ const smartGrouping = require("../util/smartGrouping");
|
|
33
53
|
|
34
54
|
/** @typedef {KnownStatsFactoryContext & Record<string, EXPECTED_ANY>} StatsFactoryContext */
|
35
55
|
|
36
|
-
|
37
|
-
|
38
|
-
/**
|
39
|
-
|
40
|
-
|
56
|
+
// StatsLogging StatsLoggingEntry
|
57
|
+
|
58
|
+
/**
|
59
|
+
* @template T
|
60
|
+
* @template F
|
61
|
+
* @typedef {T extends Compilation ? StatsCompilation : T extends ChunkGroupInfoWithName ? StatsChunkGroup : T extends Chunk ? StatsChunk : T extends OriginRecord ? StatsChunkOrigin : T extends Module ? StatsModule : T extends ModuleGraphConnection ? StatsModuleReason : T extends Asset ? StatsAsset : T extends ModuleTrace ? StatsModuleTraceItem : T extends Dependency ? StatsModuleTraceDependency : T extends Error ? StatsError : T extends ModuleProfile ? StatsProfile : F} StatsObject
|
62
|
+
*/
|
63
|
+
|
64
|
+
/**
|
65
|
+
* @template T
|
66
|
+
* @template F
|
67
|
+
* @typedef {T extends ChunkGroupInfoWithName[] ? Record<string, StatsObject<ChunkGroupInfoWithName, F>> : T extends (infer V)[] ? StatsObject<V, F>[] : StatsObject<T, F>} CreatedObject
|
68
|
+
*/
|
69
|
+
|
70
|
+
/** @typedef {TODO} FactoryData */
|
71
|
+
/** @typedef {TODO} FactoryDataItem */
|
72
|
+
/** @typedef {TODO} Result */
|
73
|
+
/** @typedef {Record<string, TODO>} ObjectForExtract */
|
41
74
|
|
42
75
|
/**
|
43
76
|
* @typedef {object} StatsFactoryHooks
|
@@ -188,10 +221,12 @@ class StatsFactory {
|
|
188
221
|
}
|
189
222
|
|
190
223
|
/**
|
224
|
+
* @template FactoryData
|
225
|
+
* @template FallbackCreatedObject
|
191
226
|
* @param {string} type type
|
192
227
|
* @param {FactoryData} data factory data
|
193
228
|
* @param {Omit<StatsFactoryContext, "type">} baseContext context used as base
|
194
|
-
* @returns {CreatedObject} created object
|
229
|
+
* @returns {CreatedObject<FactoryData, FallbackCreatedObject>} created object
|
195
230
|
*/
|
196
231
|
create(type, data, baseContext) {
|
197
232
|
if (this._inCreate) {
|
@@ -208,11 +243,13 @@ class StatsFactory {
|
|
208
243
|
}
|
209
244
|
|
210
245
|
/**
|
246
|
+
* @private
|
247
|
+
* @template FactoryData
|
248
|
+
* @template FallbackCreatedObject
|
211
249
|
* @param {string} type type
|
212
250
|
* @param {FactoryData} data factory data
|
213
251
|
* @param {Omit<StatsFactoryContext, "type">} baseContext context used as base
|
214
|
-
* @returns {CreatedObject} created object
|
215
|
-
* @private
|
252
|
+
* @returns {CreatedObject<FactoryData, FallbackCreatedObject>} created object
|
216
253
|
*/
|
217
254
|
_create(type, data, baseContext) {
|
218
255
|
const context = /** @type {StatsFactoryContext} */ ({
|
@@ -23,7 +23,7 @@ const { HookMap, SyncWaterfallHook, SyncBailHook } = require("tapable");
|
|
23
23
|
/**
|
24
24
|
* @typedef {object} PrintedElement
|
25
25
|
* @property {string} element
|
26
|
-
* @property {string} content
|
26
|
+
* @property {string | undefined} content
|
27
27
|
*/
|
28
28
|
|
29
29
|
/**
|
@@ -44,14 +44,16 @@ const { HookMap, SyncWaterfallHook, SyncBailHook } = require("tapable");
|
|
44
44
|
* @property {StatsModuleTraceDependency=} moduleTraceDependency
|
45
45
|
*/
|
46
46
|
|
47
|
+
/** @typedef {(value: string | number) => string} ColorFunction */
|
48
|
+
|
47
49
|
/**
|
48
|
-
* @typedef {object}
|
49
|
-
* @property {
|
50
|
-
* @property {
|
51
|
-
* @property {
|
52
|
-
* @property {
|
53
|
-
* @property {
|
54
|
-
* @property {
|
50
|
+
* @typedef {object} KnownStatsPrinterColorFunctions
|
51
|
+
* @property {ColorFunction=} bold
|
52
|
+
* @property {ColorFunction=} yellow
|
53
|
+
* @property {ColorFunction=} red
|
54
|
+
* @property {ColorFunction=} green
|
55
|
+
* @property {ColorFunction=} magenta
|
56
|
+
* @property {ColorFunction=} cyan
|
55
57
|
*/
|
56
58
|
|
57
59
|
/**
|
@@ -67,17 +69,18 @@ const { HookMap, SyncWaterfallHook, SyncBailHook } = require("tapable");
|
|
67
69
|
* @property {(message: string) => string=} formatError
|
68
70
|
*/
|
69
71
|
|
70
|
-
/** @typedef {
|
71
|
-
/** @typedef {
|
72
|
+
/** @typedef {KnownStatsPrinterColorFunctions & KnownStatsPrinterFormatters & KnownStatsPrinterContext & Record<string, EXPECTED_ANY>} StatsPrinterContext */
|
73
|
+
/** @typedef {StatsPrinterContext & Required<KnownStatsPrinterColorFunctions> & Required<KnownStatsPrinterFormatters> & { type: string }} StatsPrinterContextWithExtra */
|
74
|
+
/** @typedef {EXPECTED_ANY} PrintObject */
|
72
75
|
|
73
76
|
/**
|
74
77
|
* @typedef {object} StatsPrintHooks
|
75
78
|
* @property {HookMap<SyncBailHook<[string[], StatsPrinterContext], void>>} sortElements
|
76
|
-
* @property {HookMap<SyncBailHook<[PrintedElement[], StatsPrinterContext], string | void>>} printElements
|
79
|
+
* @property {HookMap<SyncBailHook<[PrintedElement[], StatsPrinterContext], string | undefined | void>>} printElements
|
77
80
|
* @property {HookMap<SyncBailHook<[PrintObject[], StatsPrinterContext], boolean | void>>} sortItems
|
78
81
|
* @property {HookMap<SyncBailHook<[PrintObject, StatsPrinterContext], string | void>>} getItemName
|
79
|
-
* @property {HookMap<SyncBailHook<[string[], StatsPrinterContext], string |
|
80
|
-
* @property {HookMap<SyncBailHook<[PrintObject, StatsPrinterContext], string | void>>} print
|
82
|
+
* @property {HookMap<SyncBailHook<[string[], StatsPrinterContext], string | undefined>>} printItems
|
83
|
+
* @property {HookMap<SyncBailHook<[PrintObject, StatsPrinterContext], string | undefined | void>>} print
|
81
84
|
* @property {HookMap<SyncWaterfallHook<[string, StatsPrinterContext]>>} result
|
82
85
|
*/
|
83
86
|
|
@@ -97,7 +100,6 @@ class StatsPrinter {
|
|
97
100
|
() => new SyncBailHook(["printedItems", "context"])
|
98
101
|
),
|
99
102
|
print: new HookMap(() => new SyncBailHook(["object", "context"])),
|
100
|
-
/** @type {HookMap<SyncWaterfallHook<[string, StatsPrinterContext]>>} */
|
101
103
|
result: new HookMap(() => new SyncWaterfallHook(["result", "context"]))
|
102
104
|
});
|
103
105
|
/**
|
@@ -147,13 +149,13 @@ class StatsPrinter {
|
|
147
149
|
* @template {H extends import("tapable").Hook<any, infer R> ? R : never} R
|
148
150
|
* @param {HM} hookMap hook map
|
149
151
|
* @param {string} type type
|
150
|
-
* @param {(hooK: H) => R | void} fn fn
|
151
|
-
* @returns {R |
|
152
|
+
* @param {(hooK: H) => R | undefined | void} fn fn
|
153
|
+
* @returns {R | undefined} hook
|
152
154
|
*/
|
153
155
|
_forEachLevel(hookMap, type, fn) {
|
154
156
|
for (const hook of this._getAllLevelHooks(hookMap, type)) {
|
155
157
|
const result = fn(/** @type {H} */ (hook));
|
156
|
-
if (result !== undefined) return result;
|
158
|
+
if (result !== undefined) return /** @type {R} */ (result);
|
157
159
|
}
|
158
160
|
}
|
159
161
|
|
@@ -166,7 +168,7 @@ class StatsPrinter {
|
|
166
168
|
* @param {string} type type
|
167
169
|
* @param {string} data data
|
168
170
|
* @param {(hook: H, data: string) => string} fn fn
|
169
|
-
* @returns {string} result of `fn`
|
171
|
+
* @returns {string | undefined} result of `fn`
|
170
172
|
*/
|
171
173
|
_forEachLevelWaterfall(hookMap, type, data, fn) {
|
172
174
|
for (const hook of this._getAllLevelHooks(hookMap, type)) {
|
@@ -179,7 +181,7 @@ class StatsPrinter {
|
|
179
181
|
* @param {string} type The type
|
180
182
|
* @param {PrintObject} object Object to print
|
181
183
|
* @param {StatsPrinterContext=} baseContext The base context
|
182
|
-
* @returns {string} printed result
|
184
|
+
* @returns {string | undefined} printed result
|
183
185
|
*/
|
184
186
|
print(type, object, baseContext) {
|
185
187
|
if (this._inPrint) {
|
@@ -199,7 +201,7 @@ class StatsPrinter {
|
|
199
201
|
* @param {string} type type
|
200
202
|
* @param {PrintObject} object object
|
201
203
|
* @param {StatsPrinterContext=} baseContext context
|
202
|
-
* @returns {string} printed result
|
204
|
+
* @returns {string | undefined} printed result
|
203
205
|
*/
|
204
206
|
_print(type, object, baseContext) {
|
205
207
|
/** @type {StatsPrinterContext} */
|
@@ -209,6 +211,7 @@ class StatsPrinter {
|
|
209
211
|
[type]: object
|
210
212
|
};
|
211
213
|
|
214
|
+
/** @type {string | undefined} */
|
212
215
|
let printResult = this._forEachLevel(this.hooks.print, type, hook =>
|
213
216
|
hook.call(object, context)
|
214
217
|
);
|
@@ -216,14 +219,19 @@ class StatsPrinter {
|
|
216
219
|
if (Array.isArray(object)) {
|
217
220
|
const sortedItems = object.slice();
|
218
221
|
this._forEachLevel(this.hooks.sortItems, type, h =>
|
219
|
-
h.call(
|
222
|
+
h.call(
|
223
|
+
sortedItems,
|
224
|
+
/** @type {StatsPrinterContextWithExtra} */
|
225
|
+
(context)
|
226
|
+
)
|
220
227
|
);
|
221
228
|
const printedItems = sortedItems.map((item, i) => {
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
229
|
+
const itemContext =
|
230
|
+
/** @type {StatsPrinterContextWithExtra} */
|
231
|
+
({
|
232
|
+
...context,
|
233
|
+
_index: i
|
234
|
+
});
|
227
235
|
const itemName = this._forEachLevel(
|
228
236
|
this.hooks.getItemName,
|
229
237
|
`${type}[]`,
|
@@ -237,7 +245,11 @@ class StatsPrinter {
|
|
237
245
|
);
|
238
246
|
});
|
239
247
|
printResult = this._forEachLevel(this.hooks.printItems, type, h =>
|
240
|
-
h.call(
|
248
|
+
h.call(
|
249
|
+
/** @type {string[]} */ (printedItems),
|
250
|
+
/** @type {StatsPrinterContextWithExtra} */
|
251
|
+
(context)
|
252
|
+
)
|
241
253
|
);
|
242
254
|
if (printResult === undefined) {
|
243
255
|
const result = printedItems.filter(Boolean);
|
@@ -248,7 +260,11 @@ class StatsPrinter {
|
|
248
260
|
key => object[key] !== undefined
|
249
261
|
);
|
250
262
|
this._forEachLevel(this.hooks.sortElements, type, h =>
|
251
|
-
h.call(
|
263
|
+
h.call(
|
264
|
+
elements,
|
265
|
+
/** @type {StatsPrinterContextWithExtra} */
|
266
|
+
(context)
|
267
|
+
)
|
252
268
|
);
|
253
269
|
const printedElements = elements.map(element => {
|
254
270
|
const content = this.print(`${type}.${element}`, object[element], {
|
@@ -260,7 +276,11 @@ class StatsPrinter {
|
|
260
276
|
return { element, content };
|
261
277
|
});
|
262
278
|
printResult = this._forEachLevel(this.hooks.printElements, type, h =>
|
263
|
-
h.call(
|
279
|
+
h.call(
|
280
|
+
printedElements,
|
281
|
+
/** @type {StatsPrinterContextWithExtra} */
|
282
|
+
(context)
|
283
|
+
)
|
264
284
|
);
|
265
285
|
if (printResult === undefined) {
|
266
286
|
const result = printedElements.map(e => e.content).filter(Boolean);
|
@@ -272,8 +292,9 @@ class StatsPrinter {
|
|
272
292
|
return this._forEachLevelWaterfall(
|
273
293
|
this.hooks.result,
|
274
294
|
type,
|
275
|
-
/** @type {string} */
|
276
|
-
(
|
295
|
+
/** @type {string} */
|
296
|
+
(printResult),
|
297
|
+
(h, r) => h.call(r, /** @type {StatsPrinterContextWithExtra} */ (context))
|
277
298
|
);
|
278
299
|
}
|
279
300
|
}
|
package/lib/util/ArrayQueue.js
CHANGED
package/lib/util/AsyncQueue.js
CHANGED
@@ -69,7 +69,7 @@ class AsyncQueue {
|
|
69
69
|
* @param {string=} options.name name of the queue
|
70
70
|
* @param {number=} options.parallelism how many items should be processed at once
|
71
71
|
* @param {string=} options.context context of execution
|
72
|
-
* @param {AsyncQueue<
|
72
|
+
* @param {AsyncQueue<EXPECTED_ANY, EXPECTED_ANY, EXPECTED_ANY>=} options.parent parent queue, which will have priority over this queue and with shared parallelism
|
73
73
|
* @param {getKey<T, K>=} options.getKey extract key from item
|
74
74
|
* @param {Processor<T, R>} options.processor async function to process items
|
75
75
|
*/
|
package/lib/util/TupleQueue.js
CHANGED
@@ -13,17 +13,17 @@ const TupleSet = require("./TupleSet");
|
|
13
13
|
*/
|
14
14
|
class TupleQueue {
|
15
15
|
/**
|
16
|
-
* @param {Iterable<[T, V]>=} items The initial elements.
|
16
|
+
* @param {Iterable<[T, V, ...EXPECTED_ANY]>=} items The initial elements.
|
17
17
|
*/
|
18
18
|
constructor(items) {
|
19
19
|
/**
|
20
20
|
* @private
|
21
|
-
* @type {TupleSet<
|
21
|
+
* @type {TupleSet<T, V>}
|
22
22
|
*/
|
23
23
|
this._set = new TupleSet(items);
|
24
24
|
/**
|
25
25
|
* @private
|
26
|
-
* @type {Iterator<[T, V]>}
|
26
|
+
* @type {Iterator<[T, V, ...EXPECTED_ANY]>}
|
27
27
|
*/
|
28
28
|
this._iterator = this._set[Symbol.iterator]();
|
29
29
|
}
|
@@ -38,7 +38,7 @@ class TupleQueue {
|
|
38
38
|
|
39
39
|
/**
|
40
40
|
* Appends the specified element to this queue.
|
41
|
-
* @param {[T, V]} item The element to add.
|
41
|
+
* @param {[T, V, ...EXPECTED_ANY]} item The element to add.
|
42
42
|
* @returns {void}
|
43
43
|
*/
|
44
44
|
enqueue(...item) {
|
@@ -47,20 +47,22 @@ class TupleQueue {
|
|
47
47
|
|
48
48
|
/**
|
49
49
|
* Retrieves and removes the head of this queue.
|
50
|
-
* @returns {[T, V] | undefined} The head of the queue of `undefined` if this queue is empty.
|
50
|
+
* @returns {[T, V, ...EXPECTED_ANY] | undefined} The head of the queue of `undefined` if this queue is empty.
|
51
51
|
*/
|
52
52
|
dequeue() {
|
53
53
|
const result = this._iterator.next();
|
54
54
|
if (result.done) {
|
55
55
|
if (this._set.size > 0) {
|
56
56
|
this._iterator = this._set[Symbol.iterator]();
|
57
|
-
const value =
|
57
|
+
const value =
|
58
|
+
/** @type {[T, V, ...EXPECTED_ANY]} */
|
59
|
+
(this._iterator.next().value);
|
58
60
|
this._set.delete(...value);
|
59
61
|
return value;
|
60
62
|
}
|
61
63
|
return;
|
62
64
|
}
|
63
|
-
this._set.delete(.../** @type {[T, V]} */ (result.value));
|
65
|
+
this._set.delete(.../** @type {[T, V, ...EXPECTED_ANY]} */ (result.value));
|
64
66
|
return result.value;
|
65
67
|
}
|
66
68
|
}
|
package/lib/util/TupleSet.js
CHANGED
@@ -6,14 +6,21 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
/**
|
9
|
-
* @template
|
9
|
+
* @template K
|
10
|
+
* @template V
|
11
|
+
* @typedef {Map<K, InnerMap<K, V> | Set<V>>} InnerMap
|
12
|
+
*/
|
13
|
+
|
14
|
+
/**
|
15
|
+
* @template T
|
16
|
+
* @template V
|
10
17
|
*/
|
11
18
|
class TupleSet {
|
12
19
|
/**
|
13
|
-
* @param {Iterable<T>=} init init
|
20
|
+
* @param {Iterable<[T, V, ...EXPECTED_ANY]>=} init init
|
14
21
|
*/
|
15
22
|
constructor(init) {
|
16
|
-
/** @type {
|
23
|
+
/** @type {InnerMap<T, V>} */
|
17
24
|
this._map = new Map();
|
18
25
|
this.size = 0;
|
19
26
|
if (init) {
|
@@ -24,7 +31,7 @@ class TupleSet {
|
|
24
31
|
}
|
25
32
|
|
26
33
|
/**
|
27
|
-
* @param {T} args tuple
|
34
|
+
* @param {[T, V, ...EXPECTED_ANY]} args tuple
|
28
35
|
* @returns {void}
|
29
36
|
*/
|
30
37
|
add(...args) {
|
@@ -35,12 +42,12 @@ class TupleSet {
|
|
35
42
|
if (innerMap === undefined) {
|
36
43
|
map.set(arg, (map = new Map()));
|
37
44
|
} else {
|
38
|
-
map = innerMap;
|
45
|
+
map = /** @type {InnerMap<T, V>} */ (innerMap);
|
39
46
|
}
|
40
47
|
}
|
41
48
|
|
42
49
|
const beforeLast = args[args.length - 2];
|
43
|
-
let set = map.get(beforeLast);
|
50
|
+
let set = /** @type {Set<V>} */ (map.get(beforeLast));
|
44
51
|
if (set === undefined) {
|
45
52
|
map.set(beforeLast, (set = new Set()));
|
46
53
|
}
|
@@ -52,14 +59,14 @@ class TupleSet {
|
|
52
59
|
}
|
53
60
|
|
54
61
|
/**
|
55
|
-
* @param {T} args tuple
|
62
|
+
* @param {[T, V, ...EXPECTED_ANY]} args tuple
|
56
63
|
* @returns {boolean} true, if the tuple is in the Set
|
57
64
|
*/
|
58
65
|
has(...args) {
|
59
66
|
let map = this._map;
|
60
67
|
for (let i = 0; i < args.length - 2; i++) {
|
61
68
|
const arg = args[i];
|
62
|
-
map = map.get(arg);
|
69
|
+
map = /** @type {InnerMap<T, V>} */ (map.get(arg));
|
63
70
|
if (map === undefined) {
|
64
71
|
return false;
|
65
72
|
}
|
@@ -76,14 +83,14 @@ class TupleSet {
|
|
76
83
|
}
|
77
84
|
|
78
85
|
/**
|
79
|
-
* @param {T} args tuple
|
86
|
+
* @param {[T, V, ...EXPECTED_ANY]} args tuple
|
80
87
|
* @returns {void}
|
81
88
|
*/
|
82
89
|
delete(...args) {
|
83
90
|
let map = this._map;
|
84
91
|
for (let i = 0; i < args.length - 2; i++) {
|
85
92
|
const arg = args[i];
|
86
|
-
map = map.get(arg);
|
93
|
+
map = /** @type {InnerMap<T, V>} */ (map.get(arg));
|
87
94
|
if (map === undefined) {
|
88
95
|
return;
|
89
96
|
}
|
@@ -102,18 +109,20 @@ class TupleSet {
|
|
102
109
|
}
|
103
110
|
|
104
111
|
/**
|
105
|
-
* @returns {Iterator<T>} iterator
|
112
|
+
* @returns {Iterator<[T, V, ...EXPECTED_ANY]>} iterator
|
106
113
|
*/
|
107
114
|
[Symbol.iterator]() {
|
108
|
-
|
115
|
+
// This is difficult to type because we can have a map inside a map inside a map, etc. where the end is a set (each key is an argument)
|
116
|
+
// But in basic use we only have 2 arguments in our methods, so we have `Map<K, Set<V>>`
|
117
|
+
/** @type {MapIterator<[T, InnerMap<T, V> | Set<V>]>[]} */
|
109
118
|
const iteratorStack = [];
|
110
|
-
/** @type {T
|
119
|
+
/** @type {[T?, V?, ...EXPECTED_ANY]} */
|
111
120
|
const tuple = [];
|
112
|
-
/** @type {
|
121
|
+
/** @type {SetIterator<V> | undefined} */
|
113
122
|
let currentSetIterator;
|
114
123
|
|
115
124
|
/**
|
116
|
-
* @param {
|
125
|
+
* @param {MapIterator<[T, InnerMap<T, V> | Set<V>]>} it iterator
|
117
126
|
* @returns {boolean} result
|
118
127
|
*/
|
119
128
|
const next = it => {
|
@@ -121,7 +130,10 @@ class TupleSet {
|
|
121
130
|
if (result.done) {
|
122
131
|
if (iteratorStack.length === 0) return false;
|
123
132
|
tuple.pop();
|
124
|
-
return next(
|
133
|
+
return next(
|
134
|
+
/** @type {MapIterator<[T, InnerMap<T, V> | Set<V>]>} */
|
135
|
+
(iteratorStack.pop())
|
136
|
+
);
|
125
137
|
}
|
126
138
|
const [key, value] = result.value;
|
127
139
|
iteratorStack.push(it);
|
@@ -141,13 +153,20 @@ class TupleSet {
|
|
141
153
|
const result = currentSetIterator.next();
|
142
154
|
if (result.done) {
|
143
155
|
tuple.pop();
|
144
|
-
if (
|
156
|
+
if (
|
157
|
+
!next(
|
158
|
+
/** @type {MapIterator<[T, InnerMap<T, V> | Set<V>]>} */
|
159
|
+
(iteratorStack.pop())
|
160
|
+
)
|
161
|
+
) {
|
145
162
|
currentSetIterator = undefined;
|
146
163
|
}
|
147
164
|
} else {
|
148
165
|
return {
|
149
166
|
done: false,
|
150
|
-
value:
|
167
|
+
value:
|
168
|
+
/** @type {[T, V, ...EXPECTED_ANY]} */
|
169
|
+
(tuple.concat(result.value))
|
151
170
|
};
|
152
171
|
}
|
153
172
|
}
|