webpack 5.95.0 → 5.96.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.
- package/README.md +1 -1
- package/lib/AsyncDependenciesBlock.js +1 -1
- package/lib/BannerPlugin.js +2 -1
- package/lib/Chunk.js +30 -0
- package/lib/ChunkGraph.js +11 -6
- package/lib/ChunkGroup.js +2 -2
- package/lib/CleanPlugin.js +4 -5
- package/lib/CodeGenerationResults.js +6 -5
- package/lib/Compilation.js +71 -48
- package/lib/Compiler.js +7 -5
- package/lib/ConcatenationScope.js +7 -20
- package/lib/ContextModule.js +7 -8
- package/lib/CssModule.js +25 -21
- package/lib/DefinePlugin.js +14 -8
- package/lib/DelegatedModule.js +3 -3
- package/lib/DllModule.js +4 -4
- package/lib/DynamicEntryPlugin.js +29 -22
- package/lib/EvalDevToolModulePlugin.js +5 -2
- package/lib/EvalSourceMapDevToolPlugin.js +5 -2
- package/lib/ExternalModule.js +40 -7
- package/lib/ExternalModuleFactoryPlugin.js +33 -9
- package/lib/FileSystemInfo.js +12 -8
- package/lib/Generator.js +5 -4
- package/lib/HotModuleReplacementPlugin.js +8 -6
- package/lib/IgnorePlugin.js +19 -1
- package/lib/LoaderOptionsPlugin.js +3 -1
- package/lib/Module.js +9 -8
- package/lib/ModuleSourceTypesConstants.js +100 -0
- package/lib/NormalModule.js +27 -17
- package/lib/NormalModuleFactory.js +38 -22
- package/lib/OptionsApply.js +12 -1
- package/lib/ProgressPlugin.js +50 -10
- package/lib/RawModule.js +3 -4
- package/lib/RuntimeModule.js +3 -4
- package/lib/RuntimePlugin.js +11 -4
- package/lib/RuntimeTemplate.js +13 -42
- package/lib/SourceMapDevToolPlugin.js +10 -7
- package/lib/Watching.js +2 -2
- package/lib/WebpackOptionsApply.js +42 -21
- package/lib/asset/AssetGenerator.js +347 -194
- package/lib/asset/AssetModulesPlugin.js +2 -1
- package/lib/asset/AssetSourceGenerator.js +82 -27
- package/lib/asset/RawDataUrlModule.js +5 -4
- package/lib/buildChunkGraph.js +2 -2
- package/lib/cache/PackFileCacheStrategy.js +69 -31
- package/lib/cache/ResolverCachePlugin.js +248 -173
- package/lib/config/defaults.js +134 -126
- package/lib/container/ContainerEntryModule.js +3 -4
- package/lib/container/ContainerPlugin.js +8 -0
- package/lib/container/FallbackModule.js +2 -2
- package/lib/container/HoistContainerReferencesPlugin.js +250 -0
- package/lib/container/ModuleFederationPlugin.js +38 -1
- package/lib/container/RemoteModule.js +4 -2
- package/lib/container/RemoteRuntimeModule.js +4 -2
- package/lib/css/CssExportsGenerator.js +16 -12
- package/lib/css/CssGenerator.js +22 -16
- package/lib/css/CssLoadingRuntimeModule.js +7 -6
- package/lib/css/CssModulesPlugin.js +122 -77
- package/lib/css/CssParser.js +655 -526
- package/lib/css/walkCssTokens.js +1168 -338
- package/lib/debug/ProfilingPlugin.js +5 -0
- package/lib/dependencies/CommonJsExportsParserPlugin.js +5 -2
- package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -6
- package/lib/dependencies/CssExportDependency.js +3 -3
- package/lib/dependencies/CssLocalIdentifierDependency.js +26 -17
- package/lib/dependencies/CssUrlDependency.js +33 -3
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +39 -14
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +15 -82
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -2
- package/lib/dependencies/ImportParserPlugin.js +9 -7
- package/lib/dependencies/LoaderPlugin.js +19 -0
- package/lib/dependencies/SystemPlugin.js +2 -1
- package/lib/dependencies/URLPlugin.js +7 -1
- package/lib/dependencies/WorkerPlugin.js +1 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +4 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +16 -4
- package/lib/hmr/lazyCompilationBackend.js +1 -7
- package/lib/index.js +35 -6
- package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
- package/lib/javascript/JavascriptGenerator.js +8 -8
- package/lib/javascript/JavascriptModulesPlugin.js +126 -73
- package/lib/javascript/JavascriptParser.js +338 -117
- package/lib/json/JsonGenerator.js +5 -5
- package/lib/library/EnableLibraryPlugin.js +2 -2
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
- package/lib/library/UmdLibraryPlugin.js +16 -8
- package/lib/logging/Logger.js +11 -11
- package/lib/logging/createConsoleLogger.js +14 -14
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/NodeWatchFileSystem.js +3 -1
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +20 -18
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
- package/lib/node/nodeConsole.js +11 -8
- package/lib/optimize/AggressiveSplittingPlugin.js +21 -7
- package/lib/optimize/ConcatenatedModule.js +43 -145
- package/lib/optimize/FlagIncludedChunksPlugin.js +6 -0
- package/lib/optimize/InnerGraphPlugin.js +57 -16
- package/lib/optimize/LimitChunkCountPlugin.js +2 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
- package/lib/optimize/RealContentHashPlugin.js +1 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
- package/lib/rules/RuleSetCompiler.js +2 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -2
- package/lib/schemes/DataUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +32 -19
- package/lib/serialization/ObjectMiddleware.js +23 -9
- package/lib/serialization/SerializerMiddleware.js +3 -2
- package/lib/serialization/types.js +2 -2
- package/lib/sharing/ConsumeSharedModule.js +2 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +3 -1
- package/lib/sharing/ProvideSharedModule.js +2 -3
- package/lib/stats/DefaultStatsFactoryPlugin.js +22 -20
- package/lib/stats/StatsFactory.js +12 -12
- package/lib/stats/StatsPrinter.js +7 -7
- package/lib/util/AsyncQueue.js +17 -1
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/cleverMerge.js +48 -24
- package/lib/util/concatenate.js +227 -0
- package/lib/util/create-schema-validation.js +22 -9
- package/lib/util/deprecation.js +86 -28
- package/lib/util/fs.js +9 -9
- package/lib/util/hash/wasm-hash.js +12 -1
- package/lib/util/magicComment.js +21 -0
- package/lib/util/makeSerializable.js +24 -1
- package/lib/util/memoize.js +2 -1
- package/lib/util/runtime.js +4 -1
- package/lib/util/semver.js +130 -23
- package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +5 -5
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -5
- package/lib/wasm-sync/WebAssemblyGenerator.js +8 -9
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -5
- package/lib/web/FetchCompileAsyncWasmPlugin.js +1 -2
- package/lib/web/FetchCompileWasmPlugin.js +1 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
- package/package.json +17 -18
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +8 -2
- package/types.d.ts +801 -259
- package/lib/util/mergeScope.js +0 -76
@@ -8,23 +8,45 @@
|
|
8
8
|
const LazySet = require("../util/LazySet");
|
9
9
|
const makeSerializable = require("../util/makeSerializable");
|
10
10
|
|
11
|
+
/** @typedef {import("enhanced-resolve").ResolveContext} ResolveContext */
|
12
|
+
/** @typedef {import("enhanced-resolve").ResolveOptions} ResolveOptions */
|
13
|
+
/** @typedef {import("enhanced-resolve").ResolveRequest} ResolveRequest */
|
11
14
|
/** @typedef {import("enhanced-resolve").Resolver} Resolver */
|
12
15
|
/** @typedef {import("../CacheFacade").ItemCacheFacade} ItemCacheFacade */
|
13
16
|
/** @typedef {import("../Compiler")} Compiler */
|
14
17
|
/** @typedef {import("../FileSystemInfo")} FileSystemInfo */
|
15
18
|
/** @typedef {import("../FileSystemInfo").Snapshot} Snapshot */
|
19
|
+
/** @typedef {import("../FileSystemInfo").SnapshotOptions} SnapshotOptions */
|
20
|
+
/** @typedef {import("../ResolverFactory").ResolveOptionsWithDependencyType} ResolveOptionsWithDependencyType */
|
21
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
22
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
23
|
+
|
24
|
+
/**
|
25
|
+
* @template T
|
26
|
+
* @typedef {import("tapable").SyncHook<T>} SyncHook
|
27
|
+
*/
|
16
28
|
|
17
29
|
class CacheEntry {
|
30
|
+
/**
|
31
|
+
* @param {ResolveRequest} result result
|
32
|
+
* @param {Snapshot} snapshot snapshot
|
33
|
+
*/
|
18
34
|
constructor(result, snapshot) {
|
19
35
|
this.result = result;
|
20
36
|
this.snapshot = snapshot;
|
21
37
|
}
|
22
38
|
|
39
|
+
/**
|
40
|
+
* @param {ObjectSerializerContext} context context
|
41
|
+
*/
|
23
42
|
serialize({ write }) {
|
24
43
|
write(this.result);
|
25
44
|
write(this.snapshot);
|
26
45
|
}
|
27
46
|
|
47
|
+
/**
|
48
|
+
* @param {ObjectDeserializerContext} context context
|
49
|
+
*/
|
28
50
|
deserialize({ read }) {
|
29
51
|
this.result = read();
|
30
52
|
this.snapshot = read();
|
@@ -36,7 +58,7 @@ makeSerializable(CacheEntry, "webpack/lib/cache/ResolverCachePlugin");
|
|
36
58
|
/**
|
37
59
|
* @template T
|
38
60
|
* @param {Set<T> | LazySet<T>} set set to add items to
|
39
|
-
* @param {Set<T> | LazySet<T>} otherSet set to add items from
|
61
|
+
* @param {Set<T> | LazySet<T> | Iterable<T>} otherSet set to add items from
|
40
62
|
* @returns {void}
|
41
63
|
*/
|
42
64
|
const addAllToSet = (set, otherSet) => {
|
@@ -50,7 +72,8 @@ const addAllToSet = (set, otherSet) => {
|
|
50
72
|
};
|
51
73
|
|
52
74
|
/**
|
53
|
-
* @
|
75
|
+
* @template {object} T
|
76
|
+
* @param {T} object an object
|
54
77
|
* @param {boolean} excludeContext if true, context is not included in string
|
55
78
|
* @returns {string} stringified version
|
56
79
|
*/
|
@@ -77,6 +100,7 @@ class ResolverCachePlugin {
|
|
77
100
|
const cache = compiler.getCache("ResolverCachePlugin");
|
78
101
|
/** @type {FileSystemInfo} */
|
79
102
|
let fileSystemInfo;
|
103
|
+
/** @type {SnapshotOptions | undefined} */
|
80
104
|
let snapshotOptions;
|
81
105
|
let realResolves = 0;
|
82
106
|
let cachedResolves = 0;
|
@@ -100,12 +124,16 @@ class ResolverCachePlugin {
|
|
100
124
|
}
|
101
125
|
});
|
102
126
|
});
|
127
|
+
|
128
|
+
/** @typedef {function((Error | null)=, ResolveRequest=): void} Callback */
|
129
|
+
/** @typedef {ResolveRequest & { _ResolverCachePluginCacheMiss: true }} ResolveRequestWithCacheMiss */
|
130
|
+
|
103
131
|
/**
|
104
132
|
* @param {ItemCacheFacade} itemCache cache
|
105
133
|
* @param {Resolver} resolver the resolver
|
106
|
-
* @param {
|
107
|
-
* @param {
|
108
|
-
* @param {
|
134
|
+
* @param {ResolveContext} resolveContext context for resolving meta info
|
135
|
+
* @param {ResolveRequest} request the request info object
|
136
|
+
* @param {Callback} callback callback function
|
109
137
|
* @returns {void}
|
110
138
|
*/
|
111
139
|
const doRealResolve = (
|
@@ -116,10 +144,13 @@ class ResolverCachePlugin {
|
|
116
144
|
callback
|
117
145
|
) => {
|
118
146
|
realResolves++;
|
119
|
-
const newRequest =
|
120
|
-
|
121
|
-
|
122
|
-
|
147
|
+
const newRequest =
|
148
|
+
/** @type {ResolveRequestWithCacheMiss} */
|
149
|
+
({
|
150
|
+
_ResolverCachePluginCacheMiss: true,
|
151
|
+
...request
|
152
|
+
});
|
153
|
+
/** @type {ResolveContext} */
|
123
154
|
const newResolveContext = {
|
124
155
|
...resolveContext,
|
125
156
|
stack: new Set(),
|
@@ -130,16 +161,25 @@ class ResolverCachePlugin {
|
|
130
161
|
/** @type {LazySet<string>} */
|
131
162
|
contextDependencies: new LazySet()
|
132
163
|
};
|
164
|
+
/** @type {ResolveRequest[] | undefined} */
|
133
165
|
let yieldResult;
|
134
166
|
let withYield = false;
|
135
167
|
if (typeof newResolveContext.yield === "function") {
|
136
168
|
yieldResult = [];
|
137
169
|
withYield = true;
|
138
|
-
newResolveContext.yield = obj =>
|
170
|
+
newResolveContext.yield = obj =>
|
171
|
+
/** @type {ResolveRequest[]} */
|
172
|
+
(yieldResult).push(obj);
|
139
173
|
}
|
174
|
+
/**
|
175
|
+
* @param {"fileDependencies" | "contextDependencies" | "missingDependencies"} key key
|
176
|
+
*/
|
140
177
|
const propagate = key => {
|
141
178
|
if (resolveContext[key]) {
|
142
|
-
addAllToSet(
|
179
|
+
addAllToSet(
|
180
|
+
/** @type {Set<string>} */ (resolveContext[key]),
|
181
|
+
/** @type {Set<string>} */ (newResolveContext[key])
|
182
|
+
);
|
143
183
|
}
|
144
184
|
};
|
145
185
|
const resolveTime = Date.now();
|
@@ -158,25 +198,43 @@ class ResolverCachePlugin {
|
|
158
198
|
const missingDependencies = newResolveContext.missingDependencies;
|
159
199
|
fileSystemInfo.createSnapshot(
|
160
200
|
resolveTime,
|
161
|
-
|
162
|
-
|
163
|
-
|
201
|
+
/** @type {Set<string>} */
|
202
|
+
(fileDependencies),
|
203
|
+
/** @type {Set<string>} */
|
204
|
+
(contextDependencies),
|
205
|
+
/** @type {Set<string>} */
|
206
|
+
(missingDependencies),
|
164
207
|
snapshotOptions,
|
165
208
|
(err, snapshot) => {
|
166
209
|
if (err) return callback(err);
|
167
210
|
const resolveResult = withYield ? yieldResult : result;
|
168
211
|
// since we intercept resolve hook
|
169
212
|
// we still can get result in callback
|
170
|
-
if (withYield && result)
|
213
|
+
if (withYield && result)
|
214
|
+
/** @type {ResolveRequest[]} */ (yieldResult).push(result);
|
171
215
|
if (!snapshot) {
|
172
|
-
if (resolveResult)
|
216
|
+
if (resolveResult)
|
217
|
+
return callback(
|
218
|
+
null,
|
219
|
+
/** @type {ResolveRequest} */
|
220
|
+
(resolveResult)
|
221
|
+
);
|
173
222
|
return callback();
|
174
223
|
}
|
175
224
|
itemCache.store(
|
176
|
-
new CacheEntry(
|
225
|
+
new CacheEntry(
|
226
|
+
/** @type {ResolveRequest} */
|
227
|
+
(resolveResult),
|
228
|
+
snapshot
|
229
|
+
),
|
177
230
|
storeErr => {
|
178
231
|
if (storeErr) return callback(storeErr);
|
179
|
-
if (resolveResult)
|
232
|
+
if (resolveResult)
|
233
|
+
return callback(
|
234
|
+
null,
|
235
|
+
/** @type {ResolveRequest} */
|
236
|
+
(resolveResult)
|
237
|
+
);
|
180
238
|
callback();
|
181
239
|
}
|
182
240
|
);
|
@@ -187,175 +245,192 @@ class ResolverCachePlugin {
|
|
187
245
|
};
|
188
246
|
compiler.resolverFactory.hooks.resolver.intercept({
|
189
247
|
factory(type, hook) {
|
190
|
-
/** @type {Map<string, (function(Error=,
|
248
|
+
/** @type {Map<string, (function(Error=, ResolveRequest=): void)[]>} */
|
191
249
|
const activeRequests = new Map();
|
192
|
-
/** @type {Map<string, [function(Error=,
|
250
|
+
/** @type {Map<string, [function(Error=, ResolveRequest=): void, NonNullable<ResolveContext["yield"]>][]>} */
|
193
251
|
const activeRequestsWithYield = new Map();
|
194
|
-
|
195
|
-
|
196
|
-
/**
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
(
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
return callback();
|
220
|
-
}
|
221
|
-
const withYield = typeof resolveContext.yield === "function";
|
222
|
-
const identifier = `${type}${
|
223
|
-
withYield ? "|yield" : "|default"
|
224
|
-
}${optionsIdent}${objectToString(request, !cacheWithContext)}`;
|
252
|
+
/** @type {SyncHook<[Resolver, ResolveOptions, ResolveOptionsWithDependencyType]>} */
|
253
|
+
(hook).tap("ResolverCachePlugin", (resolver, options, userOptions) => {
|
254
|
+
if (/** @type {TODO} */ (options).cache !== true) return;
|
255
|
+
const optionsIdent = objectToString(userOptions, false);
|
256
|
+
const cacheWithContext =
|
257
|
+
options.cacheWithContext !== undefined
|
258
|
+
? options.cacheWithContext
|
259
|
+
: false;
|
260
|
+
resolver.hooks.resolve.tapAsync(
|
261
|
+
{
|
262
|
+
name: "ResolverCachePlugin",
|
263
|
+
stage: -100
|
264
|
+
},
|
265
|
+
(request, resolveContext, callback) => {
|
266
|
+
if (
|
267
|
+
/** @type {ResolveRequestWithCacheMiss} */
|
268
|
+
(request)._ResolverCachePluginCacheMiss ||
|
269
|
+
!fileSystemInfo
|
270
|
+
) {
|
271
|
+
return callback();
|
272
|
+
}
|
273
|
+
const withYield = typeof resolveContext.yield === "function";
|
274
|
+
const identifier = `${type}${
|
275
|
+
withYield ? "|yield" : "|default"
|
276
|
+
}${optionsIdent}${objectToString(request, !cacheWithContext)}`;
|
225
277
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
)
|
233
|
-
|
234
|
-
|
235
|
-
} else {
|
236
|
-
const activeRequest = activeRequests.get(identifier);
|
237
|
-
if (activeRequest) {
|
238
|
-
activeRequest.push(callback);
|
239
|
-
return;
|
240
|
-
}
|
278
|
+
if (withYield) {
|
279
|
+
const activeRequest = activeRequestsWithYield.get(identifier);
|
280
|
+
if (activeRequest) {
|
281
|
+
activeRequest[0].push(callback);
|
282
|
+
activeRequest[1].push(
|
283
|
+
/** @type {NonNullable<ResolveContext["yield"]>} */
|
284
|
+
(resolveContext.yield)
|
285
|
+
);
|
286
|
+
return;
|
241
287
|
}
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
288
|
+
} else {
|
289
|
+
const activeRequest = activeRequests.get(identifier);
|
290
|
+
if (activeRequest) {
|
291
|
+
activeRequest.push(callback);
|
292
|
+
return;
|
293
|
+
}
|
294
|
+
}
|
295
|
+
const itemCache = cache.getItemCache(identifier, null);
|
296
|
+
/** @type {Callback[] | false | undefined} */
|
297
|
+
let callbacks;
|
298
|
+
/** @type {NonNullable<ResolveContext["yield"]>[] | undefined} */
|
299
|
+
let yields;
|
300
|
+
|
301
|
+
/**
|
302
|
+
* @type {function((Error | null)=, ResolveRequest | ResolveRequest[]=): void}
|
303
|
+
*/
|
304
|
+
const done = withYield
|
305
|
+
? (err, result) => {
|
306
|
+
if (callbacks === undefined) {
|
307
|
+
if (err) {
|
308
|
+
callback(err);
|
257
309
|
} else {
|
258
|
-
if (
|
259
|
-
for (const
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
if (result) for (const r of result) yield_(r);
|
265
|
-
cb(null, null);
|
310
|
+
if (result)
|
311
|
+
for (const r of /** @type {ResolveRequest[]} */ (
|
312
|
+
result
|
313
|
+
)) {
|
314
|
+
/** @type {NonNullable<ResolveContext["yield"]>} */
|
315
|
+
(resolveContext.yield)(r);
|
266
316
|
}
|
267
|
-
|
268
|
-
activeRequestsWithYield.delete(identifier);
|
269
|
-
yields = undefined;
|
270
|
-
callbacks = false;
|
317
|
+
callback(null, null);
|
271
318
|
}
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
for (const callback of callbacks) {
|
279
|
-
callback(err, result);
|
280
|
-
}
|
281
|
-
activeRequests.delete(identifier);
|
282
|
-
callbacks = false;
|
283
|
-
}
|
284
|
-
};
|
285
|
-
/**
|
286
|
-
* @param {Error=} err error if any
|
287
|
-
* @param {CacheEntry=} cacheEntry cache entry
|
288
|
-
* @returns {void}
|
289
|
-
*/
|
290
|
-
const processCacheResult = (err, cacheEntry) => {
|
291
|
-
if (err) return done(err);
|
319
|
+
yields = undefined;
|
320
|
+
callbacks = false;
|
321
|
+
} else {
|
322
|
+
const definedCallbacks =
|
323
|
+
/** @type {Callback[]} */
|
324
|
+
(callbacks);
|
292
325
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
);
|
307
|
-
}
|
308
|
-
cachedResolves++;
|
309
|
-
if (resolveContext.missingDependencies) {
|
310
|
-
addAllToSet(
|
311
|
-
/** @type {LazySet<string>} */
|
312
|
-
(resolveContext.missingDependencies),
|
313
|
-
snapshot.getMissingIterable()
|
314
|
-
);
|
315
|
-
}
|
316
|
-
if (resolveContext.fileDependencies) {
|
317
|
-
addAllToSet(
|
318
|
-
/** @type {LazySet<string>} */
|
319
|
-
(resolveContext.fileDependencies),
|
320
|
-
snapshot.getFileIterable()
|
321
|
-
);
|
322
|
-
}
|
323
|
-
if (resolveContext.contextDependencies) {
|
324
|
-
addAllToSet(
|
325
|
-
/** @type {LazySet<string>} */
|
326
|
-
(resolveContext.contextDependencies),
|
327
|
-
snapshot.getContextIterable()
|
328
|
-
);
|
326
|
+
if (err) {
|
327
|
+
for (const cb of definedCallbacks) cb(err);
|
328
|
+
} else {
|
329
|
+
for (let i = 0; i < definedCallbacks.length; i++) {
|
330
|
+
const cb = definedCallbacks[i];
|
331
|
+
const yield_ =
|
332
|
+
/** @type {NonNullable<ResolveContext["yield"]>[]} */
|
333
|
+
(yields)[i];
|
334
|
+
if (result)
|
335
|
+
for (const r of /** @type {ResolveRequest[]} */ (
|
336
|
+
result
|
337
|
+
))
|
338
|
+
yield_(r);
|
339
|
+
cb(null, null);
|
329
340
|
}
|
330
|
-
done(null, result);
|
331
341
|
}
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
resolver,
|
337
|
-
resolveContext,
|
338
|
-
request,
|
339
|
-
done
|
340
|
-
);
|
342
|
+
activeRequestsWithYield.delete(identifier);
|
343
|
+
yields = undefined;
|
344
|
+
callbacks = false;
|
345
|
+
}
|
341
346
|
}
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
347
|
+
: (err, result) => {
|
348
|
+
if (callbacks === undefined) {
|
349
|
+
callback(err, /** @type {ResolveRequest} */ (result));
|
350
|
+
callbacks = false;
|
351
|
+
} else {
|
352
|
+
for (const callback of /** @type {Callback[]} */ (
|
353
|
+
callbacks
|
354
|
+
)) {
|
355
|
+
callback(err, /** @type {ResolveRequest} */ (result));
|
356
|
+
}
|
357
|
+
activeRequests.delete(identifier);
|
358
|
+
callbacks = false;
|
359
|
+
}
|
360
|
+
};
|
361
|
+
/**
|
362
|
+
* @param {(Error | null)=} err error if any
|
363
|
+
* @param {(CacheEntry | null)=} cacheEntry cache entry
|
364
|
+
* @returns {void}
|
365
|
+
*/
|
366
|
+
const processCacheResult = (err, cacheEntry) => {
|
367
|
+
if (err) return done(err);
|
368
|
+
|
369
|
+
if (cacheEntry) {
|
370
|
+
const { snapshot, result } = cacheEntry;
|
371
|
+
fileSystemInfo.checkSnapshotValid(snapshot, (err, valid) => {
|
372
|
+
if (err || !valid) {
|
373
|
+
cacheInvalidResolves++;
|
374
|
+
return doRealResolve(
|
375
|
+
itemCache,
|
376
|
+
resolver,
|
377
|
+
resolveContext,
|
378
|
+
request,
|
379
|
+
done
|
380
|
+
);
|
381
|
+
}
|
382
|
+
cachedResolves++;
|
383
|
+
if (resolveContext.missingDependencies) {
|
384
|
+
addAllToSet(
|
385
|
+
/** @type {Set<string>} */
|
386
|
+
(resolveContext.missingDependencies),
|
387
|
+
snapshot.getMissingIterable()
|
388
|
+
);
|
389
|
+
}
|
390
|
+
if (resolveContext.fileDependencies) {
|
391
|
+
addAllToSet(
|
392
|
+
/** @type {Set<string>} */
|
393
|
+
(resolveContext.fileDependencies),
|
394
|
+
snapshot.getFileIterable()
|
395
|
+
);
|
396
|
+
}
|
397
|
+
if (resolveContext.contextDependencies) {
|
398
|
+
addAllToSet(
|
399
|
+
/** @type {Set<string>} */
|
400
|
+
(resolveContext.contextDependencies),
|
401
|
+
snapshot.getContextIterable()
|
402
|
+
);
|
403
|
+
}
|
404
|
+
done(null, result);
|
405
|
+
});
|
406
|
+
} else {
|
407
|
+
doRealResolve(
|
408
|
+
itemCache,
|
409
|
+
resolver,
|
410
|
+
resolveContext,
|
411
|
+
request,
|
412
|
+
done
|
350
413
|
);
|
351
|
-
} else if (callbacks === undefined) {
|
352
|
-
callbacks = [callback];
|
353
|
-
activeRequests.set(identifier, callbacks);
|
354
414
|
}
|
415
|
+
};
|
416
|
+
itemCache.get(processCacheResult);
|
417
|
+
if (withYield && callbacks === undefined) {
|
418
|
+
callbacks = [callback];
|
419
|
+
yields = [
|
420
|
+
/** @type {NonNullable<ResolveContext["yield"]>} */
|
421
|
+
(resolveContext.yield)
|
422
|
+
];
|
423
|
+
activeRequestsWithYield.set(
|
424
|
+
identifier,
|
425
|
+
/** @type {[any, any]} */ ([callbacks, yields])
|
426
|
+
);
|
427
|
+
} else if (callbacks === undefined) {
|
428
|
+
callbacks = [callback];
|
429
|
+
activeRequests.set(identifier, callbacks);
|
355
430
|
}
|
356
|
-
|
357
|
-
|
358
|
-
);
|
431
|
+
}
|
432
|
+
);
|
433
|
+
});
|
359
434
|
return hook;
|
360
435
|
}
|
361
436
|
});
|