webpack 5.85.0 → 5.88.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +5 -2
- package/lib/APIPlugin.js +150 -99
- package/lib/AsyncDependenciesBlock.js +3 -3
- package/lib/BannerPlugin.js +2 -1
- package/lib/CaseSensitiveModulesWarning.js +3 -1
- package/lib/Chunk.js +35 -17
- package/lib/ChunkGraph.js +4 -4
- package/lib/ChunkGroup.js +20 -9
- package/lib/CompatibilityPlugin.js +50 -30
- package/lib/Compilation.js +2 -1
- package/lib/Compiler.js +10 -9
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ConditionalInitFragment.js +11 -1
- package/lib/ConstPlugin.js +73 -32
- package/lib/ContextModule.js +8 -3
- package/lib/ContextModuleFactory.js +1 -0
- package/lib/ContextReplacementPlugin.js +13 -0
- package/lib/DelegatedModule.js +15 -3
- package/lib/DelegatedModuleFactoryPlugin.js +6 -0
- package/lib/DependenciesBlock.js +1 -1
- package/lib/Dependency.js +11 -5
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DllEntryPlugin.js +11 -1
- package/lib/DllModule.js +6 -0
- package/lib/DllReferencePlugin.js +13 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ErrorHelpers.js +1 -0
- package/lib/EvalSourceMapDevToolPlugin.js +6 -1
- package/lib/ExportsInfo.js +22 -4
- package/lib/ExportsInfoApiPlugin.js +14 -5
- package/lib/ExternalModule.js +20 -8
- package/lib/FileSystemInfo.js +52 -24
- package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
- package/lib/FlagDependencyUsagePlugin.js +3 -1
- package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
- package/lib/Generator.js +7 -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 +14 -3
- 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/ProgressPlugin.js +71 -15
- 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/Watching.js +62 -25
- package/lib/WebpackError.js +6 -5
- package/lib/WebpackIsIncludedPlugin.js +6 -4
- package/lib/WebpackOptionsApply.js +4 -2
- 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/buildChunkGraph.js +37 -21
- package/lib/cache/IdleFileCachePlugin.js +2 -1
- package/lib/cache/PackFileCacheStrategy.js +53 -22
- package/lib/config/browserslistTargetHandler.js +7 -7
- package/lib/config/defaults.js +43 -26
- package/lib/container/RemoteRuntimeModule.js +1 -1
- package/lib/css/CssExportsGenerator.js +9 -0
- package/lib/css/CssGenerator.js +1 -1
- package/lib/css/CssLoadingRuntimeModule.js +43 -19
- package/lib/css/CssModulesPlugin.js +42 -14
- 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 +40 -27
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +31 -21
- 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/JsonExportsDependency.js +1 -1
- 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 +28 -19
- package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
- package/lib/javascript/JavascriptModulesPlugin.js +25 -5
- package/lib/javascript/JavascriptParser.js +157 -85
- package/lib/javascript/JavascriptParserHelpers.js +37 -15
- package/lib/json/JsonData.js +2 -2
- package/lib/json/JsonParser.js +25 -12
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +13 -1
- package/lib/library/EnableLibraryPlugin.js +4 -0
- package/lib/library/SystemLibraryPlugin.js +1 -1
- package/lib/library/UmdLibraryPlugin.js +20 -2
- package/lib/logging/runtime.js +1 -1
- package/lib/logging/truncateArgs.js +4 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
- package/lib/optimize/AggressiveMergingPlugin.js +8 -0
- package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
- package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
- package/lib/optimize/InnerGraph.js +5 -5
- package/lib/optimize/InnerGraphPlugin.js +2 -1
- package/lib/optimize/LimitChunkCountPlugin.js +29 -4
- package/lib/optimize/MangleExportsPlugin.js +1 -1
- package/lib/optimize/MinMaxSizeWarning.js +5 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
- package/lib/optimize/RealContentHashPlugin.js +80 -30
- package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
- package/lib/optimize/RuntimeChunkPlugin.js +9 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
- package/lib/optimize/SplitChunksPlugin.js +71 -31
- 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/BinaryMiddleware.js +143 -1
- package/lib/serialization/ErrorObjectSerializer.js +3 -0
- package/lib/serialization/ObjectMiddleware.js +9 -3
- package/lib/serialization/types.js +1 -1
- 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/StackedCacheMap.js +1 -1
- package/lib/util/URLAbsoluteSpecifier.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 +84 -21
- package/lib/util/semver.js +1 -0
- 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 +52 -6
- package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
- package/schemas/plugins/css/CssParserOptions.json +1 -1
- package/types.d.ts +606 -292
package/lib/Watching.js
CHANGED
@@ -11,6 +11,8 @@ const Stats = require("./Stats");
|
|
11
11
|
/** @typedef {import("./Compilation")} Compilation */
|
12
12
|
/** @typedef {import("./Compiler")} Compiler */
|
13
13
|
/** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
|
14
|
+
/** @typedef {import("./WebpackError")} WebpackError */
|
15
|
+
/** @typedef {import("./logging/Logger").Logger} Logger */
|
14
16
|
|
15
17
|
/**
|
16
18
|
* @template T
|
@@ -58,9 +60,9 @@ class Watching {
|
|
58
60
|
this._needRecords = true;
|
59
61
|
this.watcher = undefined;
|
60
62
|
this.pausedWatcher = undefined;
|
61
|
-
/** @type {Set<string>} */
|
63
|
+
/** @type {Set<string> | undefined} */
|
62
64
|
this._collectedChangedFiles = undefined;
|
63
|
-
/** @type {Set<string>} */
|
65
|
+
/** @type {Set<string> | undefined} */
|
64
66
|
this._collectedRemovedFiles = undefined;
|
65
67
|
this._done = this._done.bind(this);
|
66
68
|
process.nextTick(() => {
|
@@ -69,8 +71,8 @@ class Watching {
|
|
69
71
|
}
|
70
72
|
|
71
73
|
/**
|
72
|
-
* @param {ReadonlySet<string
|
73
|
-
* @param {ReadonlySet<string
|
74
|
+
* @param {ReadonlySet<string>=} changedFiles changed files
|
75
|
+
* @param {ReadonlySet<string>=} removedFiles removed files
|
74
76
|
*/
|
75
77
|
_mergeWithCollected(changedFiles, removedFiles) {
|
76
78
|
if (!changedFiles) return;
|
@@ -80,11 +82,13 @@ class Watching {
|
|
80
82
|
} else {
|
81
83
|
for (const file of changedFiles) {
|
82
84
|
this._collectedChangedFiles.add(file);
|
83
|
-
|
85
|
+
/** @type {Set<string>} */
|
86
|
+
(this._collectedRemovedFiles).delete(file);
|
84
87
|
}
|
85
|
-
for (const file of removedFiles) {
|
88
|
+
for (const file of /** @type {ReadonlySet<string>} */ (removedFiles)) {
|
86
89
|
this._collectedChangedFiles.delete(file);
|
87
|
-
|
90
|
+
/** @type {Set<string>} */
|
91
|
+
(this._collectedRemovedFiles).add(file);
|
88
92
|
}
|
89
93
|
}
|
90
94
|
}
|
@@ -228,7 +232,7 @@ class Watching {
|
|
228
232
|
}
|
229
233
|
|
230
234
|
/**
|
231
|
-
* @param {Error=} err an optional error
|
235
|
+
* @param {(Error | null)=} err an optional error
|
232
236
|
* @param {Compilation=} compilation the compilation
|
233
237
|
* @returns {void}
|
234
238
|
*/
|
@@ -237,13 +241,18 @@ class Watching {
|
|
237
241
|
|
238
242
|
const logger = compilation && compilation.getLogger("webpack.Watching");
|
239
243
|
|
244
|
+
/** @type {Stats | null} */
|
240
245
|
let stats = null;
|
241
246
|
|
247
|
+
/**
|
248
|
+
* @param {Error} err error
|
249
|
+
* @param {Callback<void>[]=} cbs callbacks
|
250
|
+
*/
|
242
251
|
const handleError = (err, cbs) => {
|
243
252
|
this.compiler.hooks.failed.call(err);
|
244
253
|
this.compiler.cache.beginIdle();
|
245
254
|
this.compiler.idle = true;
|
246
|
-
this.handler(err, stats);
|
255
|
+
this.handler(err, /** @type {Stats} */ (stats));
|
247
256
|
if (!cbs) {
|
248
257
|
cbs = this.callbacks;
|
249
258
|
this.callbacks = [];
|
@@ -258,11 +267,13 @@ class Watching {
|
|
258
267
|
!(this._isBlocked() && (this.blocked = true))
|
259
268
|
) {
|
260
269
|
if (compilation) {
|
261
|
-
|
270
|
+
/** @type {Logger} */
|
271
|
+
(logger).time("storeBuildDependencies");
|
262
272
|
this.compiler.cache.storeBuildDependencies(
|
263
273
|
compilation.buildDependencies,
|
264
274
|
err => {
|
265
|
-
|
275
|
+
/** @type {Logger} */
|
276
|
+
(logger).timeEnd("storeBuildDependencies");
|
266
277
|
if (err) return handleError(err);
|
267
278
|
this._go();
|
268
279
|
}
|
@@ -283,32 +294,42 @@ class Watching {
|
|
283
294
|
|
284
295
|
const cbs = this.callbacks;
|
285
296
|
this.callbacks = [];
|
286
|
-
|
287
|
-
|
288
|
-
|
297
|
+
/** @type {Logger} */
|
298
|
+
(logger).time("done hook");
|
299
|
+
this.compiler.hooks.done.callAsync(/** @type {Stats} */ (stats), err => {
|
300
|
+
/** @type {Logger} */
|
301
|
+
(logger).timeEnd("done hook");
|
289
302
|
if (err) return handleError(err, cbs);
|
290
|
-
this.handler(null, stats);
|
291
|
-
|
303
|
+
this.handler(null, /** @type {Stats} */ (stats));
|
304
|
+
/** @type {Logger} */
|
305
|
+
(logger).time("storeBuildDependencies");
|
292
306
|
this.compiler.cache.storeBuildDependencies(
|
293
|
-
|
307
|
+
/** @type {Compilation} */
|
308
|
+
(compilation).buildDependencies,
|
294
309
|
err => {
|
295
|
-
|
310
|
+
/** @type {Logger} */
|
311
|
+
(logger).timeEnd("storeBuildDependencies");
|
296
312
|
if (err) return handleError(err, cbs);
|
297
|
-
|
313
|
+
/** @type {Logger} */
|
314
|
+
(logger).time("beginIdle");
|
298
315
|
this.compiler.cache.beginIdle();
|
299
316
|
this.compiler.idle = true;
|
300
|
-
|
317
|
+
/** @type {Logger} */
|
318
|
+
(logger).timeEnd("beginIdle");
|
301
319
|
process.nextTick(() => {
|
302
320
|
if (!this.closed) {
|
303
321
|
this.watch(
|
304
|
-
|
305
|
-
compilation.
|
306
|
-
|
322
|
+
/** @type {Compilation} */
|
323
|
+
(compilation).fileDependencies,
|
324
|
+
/** @type {Compilation} */
|
325
|
+
(compilation).contextDependencies,
|
326
|
+
/** @type {Compilation} */
|
327
|
+
(compilation).missingDependencies
|
307
328
|
);
|
308
329
|
}
|
309
330
|
});
|
310
331
|
for (const cb of cbs) cb(null);
|
311
|
-
this.compiler.hooks.afterDone.call(stats);
|
332
|
+
this.compiler.hooks.afterDone.call(/** @type {Stats} */ (stats));
|
312
333
|
}
|
313
334
|
);
|
314
335
|
});
|
@@ -377,6 +398,13 @@ class Watching {
|
|
377
398
|
this._invalidate();
|
378
399
|
}
|
379
400
|
|
401
|
+
/**
|
402
|
+
* @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore">=} fileTimeInfoEntries info for files
|
403
|
+
* @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore">=} contextTimeInfoEntries info for directories
|
404
|
+
* @param {ReadonlySet<string>=} changedFiles changed files
|
405
|
+
* @param {ReadonlySet<string>=} removedFiles removed files
|
406
|
+
* @returns {void}
|
407
|
+
*/
|
380
408
|
_invalidate(
|
381
409
|
fileTimeInfoEntries,
|
382
410
|
contextTimeInfoEntries,
|
@@ -423,6 +451,10 @@ class Watching {
|
|
423
451
|
}
|
424
452
|
return;
|
425
453
|
}
|
454
|
+
/**
|
455
|
+
* @param {(WebpackError | null)=} err error if any
|
456
|
+
* @param {Compilation=} compilation compilation if any
|
457
|
+
*/
|
426
458
|
const finalCallback = (err, compilation) => {
|
427
459
|
this.running = false;
|
428
460
|
this.compiler.running = false;
|
@@ -433,9 +465,14 @@ class Watching {
|
|
433
465
|
this.compiler.fileTimestamps = undefined;
|
434
466
|
this.compiler.contextTimestamps = undefined;
|
435
467
|
this.compiler.fsStartTime = undefined;
|
468
|
+
/**
|
469
|
+
* @param {(WebpackError | null)=} err error if any
|
470
|
+
*/
|
436
471
|
const shutdown = err => {
|
437
472
|
this.compiler.hooks.watchClose.call();
|
438
|
-
const closeCallbacks =
|
473
|
+
const closeCallbacks =
|
474
|
+
/** @type {Callback<void>[]} */
|
475
|
+
(this._closeCallbacks);
|
439
476
|
this._closeCallbacks = undefined;
|
440
477
|
for (const cb of closeCallbacks) cb(err);
|
441
478
|
};
|
package/lib/WebpackError.js
CHANGED
@@ -22,16 +22,17 @@ class WebpackError extends Error {
|
|
22
22
|
constructor(message) {
|
23
23
|
super(message);
|
24
24
|
|
25
|
+
/** @type {string | undefined} */
|
25
26
|
this.details = undefined;
|
26
|
-
/** @type {Module} */
|
27
|
+
/** @type {Module | undefined | null} */
|
27
28
|
this.module = undefined;
|
28
|
-
/** @type {DependencyLocation} */
|
29
|
+
/** @type {DependencyLocation | undefined} */
|
29
30
|
this.loc = undefined;
|
30
|
-
/** @type {boolean} */
|
31
|
+
/** @type {boolean | undefined} */
|
31
32
|
this.hideStack = undefined;
|
32
|
-
/** @type {Chunk} */
|
33
|
+
/** @type {Chunk | undefined} */
|
33
34
|
this.chunk = undefined;
|
34
|
-
/** @type {string} */
|
35
|
+
/** @type {string | undefined} */
|
35
36
|
this.file = undefined;
|
36
37
|
}
|
37
38
|
|
@@ -16,10 +16,12 @@ const {
|
|
16
16
|
toConstantDependency
|
17
17
|
} = require("./javascript/JavascriptParserHelpers");
|
18
18
|
|
19
|
-
/** @typedef {import("enhanced-resolve
|
19
|
+
/** @typedef {import("enhanced-resolve").Resolver} Resolver */
|
20
20
|
/** @typedef {import("./Compiler")} Compiler */
|
21
|
+
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
21
22
|
/** @typedef {import("./Module")} Module */
|
22
23
|
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
24
|
+
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
23
25
|
|
24
26
|
const PLUGIN_NAME = "WebpackIsIncludedPlugin";
|
25
27
|
|
@@ -61,10 +63,10 @@ class WebpackIsIncludedPlugin {
|
|
61
63
|
if (!request.isString()) return;
|
62
64
|
|
63
65
|
const dep = new WebpackIsIncludedDependency(
|
64
|
-
request.string,
|
65
|
-
expr.range
|
66
|
+
/** @type {string} */ (request.string),
|
67
|
+
/** @type {Range} */ (expr.range)
|
66
68
|
);
|
67
|
-
dep.loc = expr.loc;
|
69
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
68
70
|
parser.state.module.addDependency(dep);
|
69
71
|
return true;
|
70
72
|
});
|
@@ -368,7 +368,9 @@ class WebpackOptionsApply extends OptionsApply {
|
|
368
368
|
const NodeStuffPlugin = require("./NodeStuffPlugin");
|
369
369
|
new NodeStuffPlugin(options.node).apply(compiler);
|
370
370
|
}
|
371
|
-
new APIPlugin(
|
371
|
+
new APIPlugin({
|
372
|
+
module: options.output.module
|
373
|
+
}).apply(compiler);
|
372
374
|
new ExportsInfoApiPlugin().apply(compiler);
|
373
375
|
new WebpackIsIncludedPlugin().apply(compiler);
|
374
376
|
new ConstPlugin().apply(compiler);
|
@@ -564,7 +566,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
564
566
|
for (const minimizer of options.optimization.minimizer) {
|
565
567
|
if (typeof minimizer === "function") {
|
566
568
|
minimizer.call(compiler, compiler);
|
567
|
-
} else if (minimizer !== "...") {
|
569
|
+
} else if (minimizer !== "..." && minimizer) {
|
568
570
|
minimizer.apply(compiler);
|
569
571
|
}
|
570
572
|
}
|
@@ -8,11 +8,18 @@
|
|
8
8
|
const { applyWebpackOptionsDefaults } = require("./config/defaults");
|
9
9
|
const { getNormalizedWebpackOptions } = require("./config/normalization");
|
10
10
|
|
11
|
+
/** @typedef {import("./config/normalization").WebpackOptions} WebpackOptions */
|
12
|
+
/** @typedef {import("./config/normalization").WebpackOptionsNormalized} WebpackOptionsNormalized */
|
13
|
+
|
11
14
|
class WebpackOptionsDefaulter {
|
15
|
+
/**
|
16
|
+
* @param {WebpackOptions} options webpack options
|
17
|
+
* @returns {WebpackOptionsNormalized} normalized webpack options
|
18
|
+
*/
|
12
19
|
process(options) {
|
13
|
-
|
14
|
-
applyWebpackOptionsDefaults(
|
15
|
-
return
|
20
|
+
const normalizedOptions = getNormalizedWebpackOptions(options);
|
21
|
+
applyWebpackOptionsDefaults(normalizedOptions);
|
22
|
+
return normalizedOptions;
|
16
23
|
}
|
17
24
|
}
|
18
25
|
|
@@ -181,6 +181,7 @@ class AssetGenerator extends Generator {
|
|
181
181
|
);
|
182
182
|
}
|
183
183
|
|
184
|
+
/** @type {string | boolean | undefined} */
|
184
185
|
let mimeType = this.dataUrlOptions.mimetype;
|
185
186
|
if (mimeType === undefined) {
|
186
187
|
const ext = path.extname(module.nameForCondition());
|
@@ -213,7 +214,7 @@ class AssetGenerator extends Generator {
|
|
213
214
|
);
|
214
215
|
}
|
215
216
|
|
216
|
-
return mimeType;
|
217
|
+
return /** @type {string} */ (mimeType);
|
217
218
|
}
|
218
219
|
|
219
220
|
/**
|
package/lib/asset/AssetParser.js
CHANGED
@@ -9,6 +9,8 @@ const Parser = require("../Parser");
|
|
9
9
|
|
10
10
|
/** @typedef {import("../../declarations/WebpackOptions").AssetParserDataUrlOptions} AssetParserDataUrlOptions */
|
11
11
|
/** @typedef {import("../../declarations/WebpackOptions").AssetParserOptions} AssetParserOptions */
|
12
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
13
|
+
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
12
14
|
/** @typedef {import("../Parser").ParserState} ParserState */
|
13
15
|
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
14
16
|
|
@@ -30,22 +32,25 @@ class AssetParser extends Parser {
|
|
30
32
|
if (typeof source === "object" && !Buffer.isBuffer(source)) {
|
31
33
|
throw new Error("AssetParser doesn't accept preparsed AST");
|
32
34
|
}
|
33
|
-
|
34
|
-
state.module.
|
35
|
-
|
35
|
+
|
36
|
+
const buildInfo = /** @type {BuildInfo} */ (state.module.buildInfo);
|
37
|
+
buildInfo.strict = true;
|
38
|
+
const buildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
|
39
|
+
buildMeta.exportsType = "default";
|
40
|
+
buildMeta.defaultObject = false;
|
36
41
|
|
37
42
|
if (typeof this.dataUrlCondition === "function") {
|
38
|
-
|
43
|
+
buildInfo.dataUrl = this.dataUrlCondition(source, {
|
39
44
|
filename: state.module.matchResource || state.module.resource,
|
40
45
|
module: state.module
|
41
46
|
});
|
42
47
|
} else if (typeof this.dataUrlCondition === "boolean") {
|
43
|
-
|
48
|
+
buildInfo.dataUrl = this.dataUrlCondition;
|
44
49
|
} else if (
|
45
50
|
this.dataUrlCondition &&
|
46
51
|
typeof this.dataUrlCondition === "object"
|
47
52
|
) {
|
48
|
-
|
53
|
+
buildInfo.dataUrl =
|
49
54
|
Buffer.byteLength(source) <=
|
50
55
|
/** @type {NonNullable<AssetParserDataUrlOptions["maxSize"]>} */
|
51
56
|
(this.dataUrlCondition.maxSize);
|
@@ -7,6 +7,8 @@
|
|
7
7
|
|
8
8
|
const Parser = require("../Parser");
|
9
9
|
|
10
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
11
|
+
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
10
12
|
/** @typedef {import("../Parser").ParserState} ParserState */
|
11
13
|
/** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
|
12
14
|
|
@@ -21,9 +23,12 @@ class AssetSourceParser extends Parser {
|
|
21
23
|
throw new Error("AssetSourceParser doesn't accept preparsed AST");
|
22
24
|
}
|
23
25
|
const { module } = state;
|
24
|
-
|
25
|
-
module.
|
26
|
-
|
26
|
+
/** @type {BuildInfo} */
|
27
|
+
(module.buildInfo).strict = true;
|
28
|
+
/** @type {BuildMeta} */
|
29
|
+
(module.buildMeta).exportsType = "default";
|
30
|
+
/** @type {BuildMeta} */
|
31
|
+
(state.module.buildMeta).defaultObject = false;
|
27
32
|
|
28
33
|
return state;
|
29
34
|
}
|
@@ -29,6 +29,10 @@ class AwaitDependenciesInitFragment extends InitFragment {
|
|
29
29
|
this.promises = promises;
|
30
30
|
}
|
31
31
|
|
32
|
+
/**
|
33
|
+
* @param {AwaitDependenciesInitFragment} other other AwaitDependenciesInitFragment
|
34
|
+
* @returns {AwaitDependenciesInitFragment} AwaitDependenciesInitFragment
|
35
|
+
*/
|
32
36
|
merge(other) {
|
33
37
|
const promises = new Set(other.promises);
|
34
38
|
for (const p of this.promises) {
|
package/lib/buildChunkGraph.js
CHANGED
@@ -16,6 +16,7 @@ const { getEntryRuntime, mergeRuntime } = require("./util/runtime");
|
|
16
16
|
/** @typedef {import("./Compilation")} Compilation */
|
17
17
|
/** @typedef {import("./DependenciesBlock")} DependenciesBlock */
|
18
18
|
/** @typedef {import("./Dependency")} Dependency */
|
19
|
+
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
19
20
|
/** @typedef {import("./Entrypoint")} Entrypoint */
|
20
21
|
/** @typedef {import("./Module")} Module */
|
21
22
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
@@ -39,15 +40,15 @@ const { getEntryRuntime, mergeRuntime } = require("./util/runtime");
|
|
39
40
|
* @typedef {Object} ChunkGroupInfo
|
40
41
|
* @property {ChunkGroup} chunkGroup the chunk group
|
41
42
|
* @property {RuntimeSpec} runtime the runtimes
|
42
|
-
* @property {ModuleSetPlus} minAvailableModules current minimal set of modules available at this point
|
43
|
-
* @property {boolean} minAvailableModulesOwned true, if minAvailableModules is owned and can be modified
|
43
|
+
* @property {ModuleSetPlus | undefined} minAvailableModules current minimal set of modules available at this point
|
44
|
+
* @property {boolean | undefined} minAvailableModulesOwned true, if minAvailableModules is owned and can be modified
|
44
45
|
* @property {ModuleSetPlus[]} availableModulesToBeMerged enqueued updates to the minimal set of available modules
|
45
46
|
* @property {Set<Module>=} skippedItems modules that were skipped because module is already available in parent chunks (need to reconsider when minAvailableModules is shrinking)
|
46
47
|
* @property {Set<[Module, ConnectionState]>=} skippedModuleConnections referenced modules that where skipped because they were not active in this runtime
|
47
|
-
* @property {ModuleSetPlus} resultingAvailableModules set of modules available including modules from this chunk group
|
48
|
-
* @property {Set<ChunkGroupInfo>} children set of children chunk groups, that will be revisited when availableModules shrink
|
49
|
-
* @property {Set<ChunkGroupInfo>} availableSources set of chunk groups that are the source for minAvailableModules
|
50
|
-
* @property {Set<ChunkGroupInfo>} availableChildren set of chunk groups which depend on the this chunk group as availableSource
|
48
|
+
* @property {ModuleSetPlus | undefined} resultingAvailableModules set of modules available including modules from this chunk group
|
49
|
+
* @property {Set<ChunkGroupInfo> | undefined} children set of children chunk groups, that will be revisited when availableModules shrink
|
50
|
+
* @property {Set<ChunkGroupInfo> | undefined} availableSources set of chunk groups that are the source for minAvailableModules
|
51
|
+
* @property {Set<ChunkGroupInfo> | undefined} availableChildren set of chunk groups which depend on the this chunk group as availableSource
|
51
52
|
* @property {number} preOrderIndex next pre order index
|
52
53
|
* @property {number} postOrderIndex next post order index
|
53
54
|
* @property {boolean} chunkLoading has a chunk loading mechanism
|
@@ -199,6 +200,7 @@ const visitModules = (
|
|
199
200
|
|
200
201
|
/** @type {RuntimeSpec | false} */
|
201
202
|
let blockModulesMapRuntime = false;
|
203
|
+
/** @type {Map<DependenciesBlock, (Module | ConnectionState)[]>} */
|
202
204
|
let blockModulesMap;
|
203
205
|
|
204
206
|
/**
|
@@ -239,7 +241,7 @@ const visitModules = (
|
|
239
241
|
extractBlockModules(module, moduleGraph, runtime, blockModulesMap);
|
240
242
|
blockModules = blockModulesMap.get(block);
|
241
243
|
logger.timeAggregate("visitModules: prepare");
|
242
|
-
return blockModules;
|
244
|
+
return /** @type {(Module | ConnectionState)[]} */ (blockModules);
|
243
245
|
}
|
244
246
|
};
|
245
247
|
|
@@ -290,7 +292,7 @@ const visitModules = (
|
|
290
292
|
for (const [chunkGroup, modules] of inputEntrypointsAndModules) {
|
291
293
|
const runtime = getEntryRuntime(
|
292
294
|
compilation,
|
293
|
-
chunkGroup.name,
|
295
|
+
/** @type {string} */ (chunkGroup.name),
|
294
296
|
chunkGroup.options
|
295
297
|
);
|
296
298
|
/** @type {ChunkGroupInfo} */
|
@@ -352,7 +354,9 @@ const visitModules = (
|
|
352
354
|
const { chunkGroup } = chunkGroupInfo;
|
353
355
|
chunkGroupInfo.availableSources = new Set();
|
354
356
|
for (const parent of chunkGroup.parentsIterable) {
|
355
|
-
const parentChunkGroupInfo =
|
357
|
+
const parentChunkGroupInfo =
|
358
|
+
/** @type {ChunkGroupInfo} */
|
359
|
+
(chunkGroupInfoMap.get(parent));
|
356
360
|
chunkGroupInfo.availableSources.add(parentChunkGroupInfo);
|
357
361
|
if (parentChunkGroupInfo.availableChildren === undefined) {
|
358
362
|
parentChunkGroupInfo.availableChildren = new Set();
|
@@ -399,15 +403,15 @@ const visitModules = (
|
|
399
403
|
// 1. We create a chunk group with single chunk in it for this Block
|
400
404
|
// but only once (blockChunkGroups map)
|
401
405
|
let cgi = blockChunkGroups.get(b);
|
402
|
-
/** @type {ChunkGroup} */
|
406
|
+
/** @type {ChunkGroup | undefined} */
|
403
407
|
let c;
|
404
|
-
/** @type {Entrypoint} */
|
408
|
+
/** @type {Entrypoint | undefined} */
|
405
409
|
let entrypoint;
|
406
410
|
const entryOptions = b.groupOptions && b.groupOptions.entryOptions;
|
407
411
|
if (cgi === undefined) {
|
408
412
|
const chunkName = (b.groupOptions && b.groupOptions.name) || b.chunkName;
|
409
413
|
if (entryOptions) {
|
410
|
-
cgi = namedAsyncEntrypoints.get(chunkName);
|
414
|
+
cgi = namedAsyncEntrypoints.get(/** @type {string} */ (chunkName));
|
411
415
|
if (!cgi) {
|
412
416
|
entrypoint = compilation.addAsyncEntrypoint(
|
413
417
|
entryOptions,
|
@@ -505,7 +509,11 @@ const visitModules = (
|
|
505
509
|
c = cgi.chunkGroup;
|
506
510
|
if (c.isInitial()) {
|
507
511
|
compilation.errors.push(
|
508
|
-
new AsyncDependencyToInitialChunkError(
|
512
|
+
new AsyncDependencyToInitialChunkError(
|
513
|
+
/** @type {string} */ (chunkName),
|
514
|
+
module,
|
515
|
+
b.loc
|
516
|
+
)
|
509
517
|
);
|
510
518
|
c = chunkGroup;
|
511
519
|
} else {
|
@@ -515,7 +523,7 @@ const visitModules = (
|
|
515
523
|
}
|
516
524
|
blockConnections.set(b, []);
|
517
525
|
}
|
518
|
-
blockChunkGroups.set(b, cgi);
|
526
|
+
blockChunkGroups.set(b, /** @type {ChunkGroupInfo} */ (cgi));
|
519
527
|
} else if (entryOptions) {
|
520
528
|
entrypoint = /** @type {Entrypoint} */ (cgi.chunkGroup);
|
521
529
|
} else {
|
@@ -536,7 +544,7 @@ const visitModules = (
|
|
536
544
|
connectList = new Set();
|
537
545
|
queueConnect.set(chunkGroupInfo, connectList);
|
538
546
|
}
|
539
|
-
connectList.add(cgi);
|
547
|
+
connectList.add(/** @type {ChunkGroupInfo} */ (cgi));
|
540
548
|
|
541
549
|
// TODO check if this really need to be done for each traversal
|
542
550
|
// or if it is enough when it's queued when created
|
@@ -547,7 +555,7 @@ const visitModules = (
|
|
547
555
|
module: module,
|
548
556
|
chunk: c.chunks[0],
|
549
557
|
chunkGroup: c,
|
550
|
-
chunkGroupInfo: cgi
|
558
|
+
chunkGroupInfo: /** @type {ChunkGroupInfo} */ (cgi)
|
551
559
|
});
|
552
560
|
} else if (entrypoint !== undefined) {
|
553
561
|
chunkGroupInfo.chunkGroup.addAsyncEntrypoint(entrypoint);
|
@@ -690,7 +698,7 @@ const visitModules = (
|
|
690
698
|
const processQueue = () => {
|
691
699
|
while (queue.length) {
|
692
700
|
statProcessedQueueItems++;
|
693
|
-
const queueItem = queue.pop();
|
701
|
+
const queueItem = /** @type {QueueItem} */ (queue.pop());
|
694
702
|
module = queueItem.module;
|
695
703
|
block = queueItem.block;
|
696
704
|
chunk = queueItem.chunk;
|
@@ -1087,7 +1095,9 @@ const visitModules = (
|
|
1087
1095
|
|
1088
1096
|
const processChunkGroupsForCombining = () => {
|
1089
1097
|
for (const info of chunkGroupsForCombining) {
|
1090
|
-
for (const source of
|
1098
|
+
for (const source of /** @type {Set<ChunkGroupInfo>} */ (
|
1099
|
+
info.availableSources
|
1100
|
+
)) {
|
1091
1101
|
if (!source.minAvailableModules) {
|
1092
1102
|
chunkGroupsForCombining.delete(info);
|
1093
1103
|
break;
|
@@ -1106,7 +1116,9 @@ const visitModules = (
|
|
1106
1116
|
}
|
1107
1117
|
};
|
1108
1118
|
// combine minAvailableModules from all resultingAvailableModules
|
1109
|
-
for (const source of
|
1119
|
+
for (const source of /** @type {Set<ChunkGroupInfo>} */ (
|
1120
|
+
info.availableSources
|
1121
|
+
)) {
|
1110
1122
|
const resultingAvailableModules =
|
1111
1123
|
calculateResultingAvailableModules(source);
|
1112
1124
|
mergeSet(resultingAvailableModules);
|
@@ -1126,7 +1138,9 @@ const visitModules = (
|
|
1126
1138
|
for (const info of outdatedChunkGroupInfo) {
|
1127
1139
|
// 1. Reconsider skipped items
|
1128
1140
|
if (info.skippedItems !== undefined) {
|
1129
|
-
const
|
1141
|
+
const minAvailableModules =
|
1142
|
+
/** @type {ModuleSetPlus} */
|
1143
|
+
(info.minAvailableModules);
|
1130
1144
|
for (const module of info.skippedItems) {
|
1131
1145
|
if (
|
1132
1146
|
!minAvailableModules.has(module) &&
|
@@ -1147,7 +1161,9 @@ const visitModules = (
|
|
1147
1161
|
|
1148
1162
|
// 2. Reconsider skipped connections
|
1149
1163
|
if (info.skippedModuleConnections !== undefined) {
|
1150
|
-
const
|
1164
|
+
const minAvailableModules =
|
1165
|
+
/** @type {ModuleSetPlus} */
|
1166
|
+
(info.minAvailableModules);
|
1151
1167
|
for (const entry of info.skippedModuleConnections) {
|
1152
1168
|
const [module, activeState] = entry;
|
1153
1169
|
if (activeState === false) continue;
|
@@ -50,7 +50,7 @@ class IdleFileCachePlugin {
|
|
50
50
|
let timeSpendInStore = 0;
|
51
51
|
let avgTimeSpendInStore = 0;
|
52
52
|
|
53
|
-
/** @type {Map<string | typeof BUILD_DEPENDENCIES_KEY, () => Promise
|
53
|
+
/** @type {Map<string | typeof BUILD_DEPENDENCIES_KEY, () => Promise<void>>} */
|
54
54
|
const pendingIdleTasks = new Map();
|
55
55
|
|
56
56
|
compiler.cache.hooks.store.tap(
|
@@ -171,6 +171,7 @@ class IdleFileCachePlugin {
|
|
171
171
|
isInitialStore = false;
|
172
172
|
}
|
173
173
|
};
|
174
|
+
/** @type {ReturnType<typeof setTimeout> | undefined} */
|
174
175
|
let idleTimer = undefined;
|
175
176
|
compiler.cache.hooks.beginIdle.tap(
|
176
177
|
{ name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
|