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
package/lib/buildChunkGraph.js
CHANGED
@@ -256,6 +256,7 @@ const visitModules = (
|
|
256
256
|
) => {
|
257
257
|
const { moduleGraph, chunkGraph, moduleMemCaches } = compilation;
|
258
258
|
|
259
|
+
/** @type {Map<RuntimeSpec, BlockModulesMap>} */
|
259
260
|
const blockModulesRuntimeMap = new Map();
|
260
261
|
|
261
262
|
/** @type {BlockModulesMap | undefined} */
|
@@ -288,11 +289,12 @@ const visitModules = (
|
|
288
289
|
/**
|
289
290
|
* @param {DependenciesBlock} block block
|
290
291
|
* @param {RuntimeSpec} runtime runtime
|
291
|
-
* @returns {BlockModulesInFlattenTuples} block modules in flatten tuples
|
292
|
+
* @returns {BlockModulesInFlattenTuples | undefined} block modules in flatten tuples
|
292
293
|
*/
|
293
294
|
const getBlockModules = (block, runtime) => {
|
294
295
|
blockModulesMap = blockModulesRuntimeMap.get(runtime);
|
295
296
|
if (blockModulesMap === undefined) {
|
297
|
+
/** @type {BlockModulesMap} */
|
296
298
|
blockModulesMap = new Map();
|
297
299
|
blockModulesRuntimeMap.set(runtime, blockModulesMap);
|
298
300
|
}
|
@@ -301,6 +303,7 @@ const visitModules = (
|
|
301
303
|
const module = /** @type {Module} */ (block.getRootBlock());
|
302
304
|
const memCache = moduleMemCaches && moduleMemCaches.get(module);
|
303
305
|
if (memCache !== undefined) {
|
306
|
+
/** @type {BlockModulesMap} */
|
304
307
|
const map = memCache.provide(
|
305
308
|
"bundleChunkGraph.blockModules",
|
306
309
|
runtime,
|
@@ -1162,7 +1165,9 @@ const visitModules = (
|
|
1162
1165
|
* @param {BlocksWithNestedBlocks} visited visited dependencies blocks
|
1163
1166
|
*/
|
1164
1167
|
const process = (current, visited) => {
|
1165
|
-
const blockModules =
|
1168
|
+
const blockModules =
|
1169
|
+
/** @type {BlockModulesInFlattenTuples} */
|
1170
|
+
(getBlockModules(current, runtime));
|
1166
1171
|
for (let i = 0, len = blockModules.length; i < len; i += 3) {
|
1167
1172
|
const activeState = /** @type {ConnectionState} */ (
|
1168
1173
|
blockModules[i + 1]
|
@@ -12,6 +12,7 @@ const ProgressPlugin = require("../ProgressPlugin");
|
|
12
12
|
/** @typedef {import("./PackFileCacheStrategy")} PackFileCacheStrategy */
|
13
13
|
|
14
14
|
const BUILD_DEPENDENCIES_KEY = Symbol("build dependencies key");
|
15
|
+
const PLUGIN_NAME = "IdleFileCachePlugin";
|
15
16
|
|
16
17
|
class IdleFileCachePlugin {
|
17
18
|
/**
|
@@ -55,7 +56,7 @@ class IdleFileCachePlugin {
|
|
55
56
|
const pendingIdleTasks = new Map();
|
56
57
|
|
57
58
|
compiler.cache.hooks.store.tap(
|
58
|
-
{ name:
|
59
|
+
{ name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
|
59
60
|
(identifier, etag, data) => {
|
60
61
|
pendingIdleTasks.set(identifier, () =>
|
61
62
|
strategy.store(identifier, etag, data)
|
@@ -64,7 +65,7 @@ class IdleFileCachePlugin {
|
|
64
65
|
);
|
65
66
|
|
66
67
|
compiler.cache.hooks.get.tapPromise(
|
67
|
-
{ name:
|
68
|
+
{ name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
|
68
69
|
(identifier, etag, gotHandlers) => {
|
69
70
|
const restore = () =>
|
70
71
|
strategy.restore(identifier, etag).then(cacheEntry => {
|
@@ -91,7 +92,7 @@ class IdleFileCachePlugin {
|
|
91
92
|
);
|
92
93
|
|
93
94
|
compiler.cache.hooks.storeBuildDependencies.tap(
|
94
|
-
{ name:
|
95
|
+
{ name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
|
95
96
|
dependencies => {
|
96
97
|
pendingIdleTasks.set(BUILD_DEPENDENCIES_KEY, () =>
|
97
98
|
Promise.resolve().then(() =>
|
@@ -102,7 +103,7 @@ class IdleFileCachePlugin {
|
|
102
103
|
);
|
103
104
|
|
104
105
|
compiler.cache.hooks.shutdown.tapPromise(
|
105
|
-
{ name:
|
106
|
+
{ name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
|
106
107
|
() => {
|
107
108
|
if (idleTimer) {
|
108
109
|
clearTimeout(idleTimer);
|
@@ -129,7 +130,7 @@ class IdleFileCachePlugin {
|
|
129
130
|
}
|
130
131
|
);
|
131
132
|
|
132
|
-
/** @type {Promise<
|
133
|
+
/** @type {Promise<TODO>} */
|
133
134
|
let currentIdlePromise = resolvedPromise;
|
134
135
|
let isIdle = false;
|
135
136
|
let isInitialStore = true;
|
@@ -165,9 +166,7 @@ class IdleFileCachePlugin {
|
|
165
166
|
timeSpendInBuild = 0;
|
166
167
|
})
|
167
168
|
.catch(err => {
|
168
|
-
const logger = compiler.getInfrastructureLogger(
|
169
|
-
"IdleFileCachePlugin"
|
170
|
-
);
|
169
|
+
const logger = compiler.getInfrastructureLogger(PLUGIN_NAME);
|
171
170
|
logger.warn(`Background tasks during idle failed: ${err.message}`);
|
172
171
|
logger.debug(err.stack);
|
173
172
|
});
|
@@ -177,12 +176,12 @@ class IdleFileCachePlugin {
|
|
177
176
|
/** @type {ReturnType<typeof setTimeout> | undefined} */
|
178
177
|
let idleTimer;
|
179
178
|
compiler.cache.hooks.beginIdle.tap(
|
180
|
-
{ name:
|
179
|
+
{ name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
|
181
180
|
() => {
|
182
181
|
const isLargeChange = timeSpendInBuild > avgTimeSpendInStore * 2;
|
183
182
|
if (isInitialStore && idleTimeoutForInitialStore < idleTimeout) {
|
184
183
|
compiler
|
185
|
-
.getInfrastructureLogger(
|
184
|
+
.getInfrastructureLogger(PLUGIN_NAME)
|
186
185
|
.log(
|
187
186
|
`Initial cache was generated and cache will be persisted in ${
|
188
187
|
idleTimeoutForInitialStore / 1000
|
@@ -193,7 +192,7 @@ class IdleFileCachePlugin {
|
|
193
192
|
idleTimeoutAfterLargeChanges < idleTimeout
|
194
193
|
) {
|
195
194
|
compiler
|
196
|
-
.getInfrastructureLogger(
|
195
|
+
.getInfrastructureLogger(PLUGIN_NAME)
|
197
196
|
.log(
|
198
197
|
`Spend ${Math.round(timeSpendInBuild) / 1000}s in build and ${
|
199
198
|
Math.round(avgTimeSpendInStore) / 1000
|
@@ -218,7 +217,7 @@ class IdleFileCachePlugin {
|
|
218
217
|
}
|
219
218
|
);
|
220
219
|
compiler.cache.hooks.endIdle.tap(
|
221
|
-
{ name:
|
220
|
+
{ name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
|
222
221
|
() => {
|
223
222
|
if (idleTimer) {
|
224
223
|
clearTimeout(idleTimer);
|
@@ -227,7 +226,7 @@ class IdleFileCachePlugin {
|
|
227
226
|
isIdle = false;
|
228
227
|
}
|
229
228
|
);
|
230
|
-
compiler.hooks.done.tap(
|
229
|
+
compiler.hooks.done.tap(PLUGIN_NAME, stats => {
|
231
230
|
// 10% build overhead is ignored, as it's not cacheable
|
232
231
|
timeSpendInBuild *= 0.9;
|
233
232
|
timeSpendInBuild +=
|
@@ -8,6 +8,7 @@
|
|
8
8
|
const Cache = require("../Cache");
|
9
9
|
|
10
10
|
/** @typedef {import("webpack-sources").Source} Source */
|
11
|
+
/** @typedef {import("../Cache").Data} Data */
|
11
12
|
/** @typedef {import("../Cache").Etag} Etag */
|
12
13
|
/** @typedef {import("../Compiler")} Compiler */
|
13
14
|
/** @typedef {import("../Module")} Module */
|
@@ -19,7 +20,7 @@ class MemoryCachePlugin {
|
|
19
20
|
* @returns {void}
|
20
21
|
*/
|
21
22
|
apply(compiler) {
|
22
|
-
/** @type {Map<string, { etag: Etag | null, data:
|
23
|
+
/** @type {Map<string, { etag: Etag | null, data: Data } | null>} */
|
23
24
|
const cache = new Map();
|
24
25
|
compiler.cache.hooks.store.tap(
|
25
26
|
{ name: "MemoryCachePlugin", stage: Cache.STAGE_MEMORY },
|
@@ -8,6 +8,7 @@
|
|
8
8
|
const Cache = require("../Cache");
|
9
9
|
|
10
10
|
/** @typedef {import("webpack-sources").Source} Source */
|
11
|
+
/** @typedef {import("../Cache").Data} Data */
|
11
12
|
/** @typedef {import("../Cache").Etag} Etag */
|
12
13
|
/** @typedef {import("../Compiler")} Compiler */
|
13
14
|
/** @typedef {import("../Module")} Module */
|
@@ -17,6 +18,8 @@ const Cache = require("../Cache");
|
|
17
18
|
* @property {number} maxGenerations max generations
|
18
19
|
*/
|
19
20
|
|
21
|
+
const PLUGIN_NAME = "MemoryWithGcCachePlugin";
|
22
|
+
|
20
23
|
class MemoryWithGcCachePlugin {
|
21
24
|
/**
|
22
25
|
* @param {MemoryWithGcCachePluginOptions} options options
|
@@ -32,14 +35,14 @@ class MemoryWithGcCachePlugin {
|
|
32
35
|
*/
|
33
36
|
apply(compiler) {
|
34
37
|
const maxGenerations = this._maxGenerations;
|
35
|
-
/** @type {Map<string, { etag: Etag | null, data:
|
38
|
+
/** @type {Map<string, { etag: Etag | null, data: Data } | undefined | null>} */
|
36
39
|
const cache = new Map();
|
37
|
-
/** @type {Map<string, { entry: { etag: Etag | null, data:
|
40
|
+
/** @type {Map<string, { entry: { etag: Etag | null, data: Data } | null, until: number }>} */
|
38
41
|
const oldCache = new Map();
|
39
42
|
let generation = 0;
|
40
43
|
let cachePosition = 0;
|
41
|
-
const logger = compiler.getInfrastructureLogger(
|
42
|
-
compiler.hooks.afterDone.tap(
|
44
|
+
const logger = compiler.getInfrastructureLogger(PLUGIN_NAME);
|
45
|
+
compiler.hooks.afterDone.tap(PLUGIN_NAME, () => {
|
43
46
|
generation++;
|
44
47
|
let clearedEntries = 0;
|
45
48
|
let lastClearedIdentifier;
|
@@ -90,13 +93,13 @@ class MemoryWithGcCachePlugin {
|
|
90
93
|
}
|
91
94
|
});
|
92
95
|
compiler.cache.hooks.store.tap(
|
93
|
-
{ name:
|
96
|
+
{ name: PLUGIN_NAME, stage: Cache.STAGE_MEMORY },
|
94
97
|
(identifier, etag, data) => {
|
95
98
|
cache.set(identifier, { etag, data });
|
96
99
|
}
|
97
100
|
);
|
98
101
|
compiler.cache.hooks.get.tap(
|
99
|
-
{ name:
|
102
|
+
{ name: PLUGIN_NAME, stage: Cache.STAGE_MEMORY },
|
100
103
|
(identifier, etag, gotHandlers) => {
|
101
104
|
const cacheEntry = cache.get(identifier);
|
102
105
|
if (cacheEntry === null) {
|
@@ -128,7 +131,7 @@ class MemoryWithGcCachePlugin {
|
|
128
131
|
}
|
129
132
|
);
|
130
133
|
compiler.cache.hooks.shutdown.tap(
|
131
|
-
{ name:
|
134
|
+
{ name: PLUGIN_NAME, stage: Cache.STAGE_MEMORY },
|
132
135
|
() => {
|
133
136
|
cache.clear();
|
134
137
|
oldCache.clear();
|
@@ -18,6 +18,7 @@ const {
|
|
18
18
|
} = require("../util/serialization");
|
19
19
|
|
20
20
|
/** @typedef {import("../../declarations/WebpackOptions").SnapshotOptions} SnapshotOptions */
|
21
|
+
/** @typedef {import("../Cache").Data} Data */
|
21
22
|
/** @typedef {import("../Cache").Etag} Etag */
|
22
23
|
/** @typedef {import("../Compiler")} Compiler */
|
23
24
|
/** @typedef {import("../FileSystemInfo").ResolveBuildDependenciesResult} ResolveBuildDependenciesResult */
|
@@ -96,14 +97,11 @@ const MIN_ITEMS_IN_FRESH_PACK = 100;
|
|
96
97
|
const MAX_ITEMS_IN_FRESH_PACK = 50000;
|
97
98
|
const MAX_TIME_IN_FRESH_PACK = 1 * 60 * 1000; // 1 min
|
98
99
|
|
99
|
-
/** @typedef {TODO | undefined} Value */
|
100
|
-
/** @typedef {TODO | undefined} LazyValue */
|
101
|
-
|
102
100
|
class PackItemInfo {
|
103
101
|
/**
|
104
102
|
* @param {string} identifier identifier of item
|
105
103
|
* @param {string | null | undefined} etag etag of item
|
106
|
-
* @param {
|
104
|
+
* @param {Data} value fresh value of item
|
107
105
|
*/
|
108
106
|
constructor(identifier, etag, value) {
|
109
107
|
this.identifier = identifier;
|
@@ -158,7 +156,7 @@ class Pack {
|
|
158
156
|
/**
|
159
157
|
* @param {string} identifier unique name for the resource
|
160
158
|
* @param {string | null} etag etag of the resource
|
161
|
-
* @returns {
|
159
|
+
* @returns {Data} cached content
|
162
160
|
*/
|
163
161
|
get(identifier, etag) {
|
164
162
|
const info = this.itemInfo.get(identifier);
|
@@ -181,7 +179,7 @@ class Pack {
|
|
181
179
|
/**
|
182
180
|
* @param {string} identifier unique name for the resource
|
183
181
|
* @param {string | null} etag etag of the resource
|
184
|
-
* @param {
|
182
|
+
* @param {Data} data cached content
|
185
183
|
* @returns {void}
|
186
184
|
*/
|
187
185
|
set(identifier, etag, data) {
|
@@ -667,7 +665,7 @@ class Pack {
|
|
667
665
|
|
668
666
|
makeSerializable(Pack, "webpack/lib/cache/PackFileCacheStrategy", "Pack");
|
669
667
|
|
670
|
-
/** @typedef {Map<string,
|
668
|
+
/** @typedef {Map<string, Data>} Content */
|
671
669
|
|
672
670
|
class PackContentItems {
|
673
671
|
/**
|
@@ -799,7 +797,7 @@ makeSerializable(
|
|
799
797
|
"PackContentItems"
|
800
798
|
);
|
801
799
|
|
802
|
-
/** @typedef {(() => Promise<PackContentItems> | PackContentItems)} LazyFunction */
|
800
|
+
/** @typedef {(() => Promise<PackContentItems> | PackContentItems) & Partial<{ options: { size?: number }}>} LazyFunction */
|
803
801
|
|
804
802
|
class PackContent {
|
805
803
|
/*
|
@@ -830,7 +828,7 @@ class PackContent {
|
|
830
828
|
*/
|
831
829
|
constructor(items, usedItems, dataOrFn, logger, lazyName) {
|
832
830
|
this.items = items;
|
833
|
-
/** @type {
|
831
|
+
/** @type {LazyFunction | undefined} */
|
834
832
|
this.lazy = typeof dataOrFn === "function" ? dataOrFn : undefined;
|
835
833
|
/** @type {Content | undefined} */
|
836
834
|
this.content = typeof dataOrFn === "function" ? undefined : dataOrFn.map;
|
@@ -877,10 +875,7 @@ class PackContent {
|
|
877
875
|
}
|
878
876
|
// Move to state C
|
879
877
|
this.content = map;
|
880
|
-
this.lazy = SerializerMiddleware.unMemoizeLazy(
|
881
|
-
/** @type {LazyFunction} */
|
882
|
-
(this.lazy)
|
883
|
-
);
|
878
|
+
this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy);
|
884
879
|
return map.get(identifier);
|
885
880
|
});
|
886
881
|
}
|
@@ -891,10 +886,7 @@ class PackContent {
|
|
891
886
|
}
|
892
887
|
// Move to state C
|
893
888
|
this.content = map;
|
894
|
-
this.lazy = SerializerMiddleware.unMemoizeLazy(
|
895
|
-
/** @type {LazyFunction} */
|
896
|
-
(this.lazy)
|
897
|
-
);
|
889
|
+
this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy);
|
898
890
|
return map.get(identifier);
|
899
891
|
}
|
900
892
|
|
@@ -966,8 +958,7 @@ class PackContent {
|
|
966
958
|
}
|
967
959
|
|
968
960
|
/**
|
969
|
-
* @
|
970
|
-
* @param {(item?: LazyValue) => (() => Promise<PackContentItems> | PackContentItems)} write write function
|
961
|
+
* @param {(lazy: LazyFunction) => (() => PackContentItems | Promise<PackContentItems>)} write write function
|
971
962
|
* @returns {void}
|
972
963
|
*/
|
973
964
|
writeLazy(write) {
|
@@ -1100,6 +1091,7 @@ class PackFileCacheStrategy {
|
|
1100
1091
|
compression,
|
1101
1092
|
readonly
|
1102
1093
|
}) {
|
1094
|
+
/** @type {import("../serialization/Serializer")<PackContainer, null, {}>} */
|
1103
1095
|
this.fileSerializer = createFileSerializer(
|
1104
1096
|
fs,
|
1105
1097
|
/** @type {string | Hash} */
|
@@ -1319,7 +1311,7 @@ class PackFileCacheStrategy {
|
|
1319
1311
|
/**
|
1320
1312
|
* @param {string} identifier unique name for the resource
|
1321
1313
|
* @param {Etag | null} etag etag of the resource
|
1322
|
-
* @param {
|
1314
|
+
* @param {Data} data cached content
|
1323
1315
|
* @returns {Promise<void>} promise
|
1324
1316
|
*/
|
1325
1317
|
store(identifier, etag, data) {
|
@@ -1333,7 +1325,7 @@ class PackFileCacheStrategy {
|
|
1333
1325
|
/**
|
1334
1326
|
* @param {string} identifier unique name for the resource
|
1335
1327
|
* @param {Etag | null} etag etag of the resource
|
1336
|
-
* @returns {Promise<
|
1328
|
+
* @returns {Promise<Data>} promise to the cached content
|
1337
1329
|
*/
|
1338
1330
|
restore(identifier, etag) {
|
1339
1331
|
return this._getPack()
|
@@ -95,6 +95,10 @@ const objectToString = (object, excludeContext) => {
|
|
95
95
|
return str;
|
96
96
|
};
|
97
97
|
|
98
|
+
/** @typedef {NonNullable<ResolveContext["yield"]>} Yield */
|
99
|
+
|
100
|
+
const PLUGIN_NAME = "ResolverCachePlugin";
|
101
|
+
|
98
102
|
class ResolverCachePlugin {
|
99
103
|
/**
|
100
104
|
* Apply the plugin
|
@@ -102,7 +106,7 @@ class ResolverCachePlugin {
|
|
102
106
|
* @returns {void}
|
103
107
|
*/
|
104
108
|
apply(compiler) {
|
105
|
-
const cache = compiler.getCache(
|
109
|
+
const cache = compiler.getCache(PLUGIN_NAME);
|
106
110
|
/** @type {FileSystemInfo} */
|
107
111
|
let fileSystemInfo;
|
108
112
|
/** @type {SnapshotOptions | undefined} */
|
@@ -111,12 +115,12 @@ class ResolverCachePlugin {
|
|
111
115
|
let cachedResolves = 0;
|
112
116
|
let cacheInvalidResolves = 0;
|
113
117
|
let concurrentResolves = 0;
|
114
|
-
compiler.hooks.thisCompilation.tap(
|
118
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
|
115
119
|
snapshotOptions = compilation.options.snapshot.resolve;
|
116
120
|
fileSystemInfo = compilation.fileSystemInfo;
|
117
|
-
compilation.hooks.finishModules.tap(
|
121
|
+
compilation.hooks.finishModules.tap(PLUGIN_NAME, () => {
|
118
122
|
if (realResolves + cachedResolves > 0) {
|
119
|
-
const logger = compilation.getLogger(
|
123
|
+
const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`);
|
120
124
|
logger.log(
|
121
125
|
`${Math.round(
|
122
126
|
(100 * realResolves) / (realResolves + cachedResolves)
|
@@ -253,13 +257,17 @@ class ResolverCachePlugin {
|
|
253
257
|
/** @typedef {(err?: Error, resolveRequest?: ResolveRequest) => void} ActiveRequest */
|
254
258
|
/** @type {Map<string, ActiveRequest[]>} */
|
255
259
|
const activeRequests = new Map();
|
256
|
-
/** @type {Map<string, [ActiveRequest,
|
260
|
+
/** @type {Map<string, [ActiveRequest[], Yield[]]>} */
|
257
261
|
const activeRequestsWithYield = new Map();
|
258
262
|
const hook =
|
259
263
|
/** @type {SyncHook<[Resolver, ResolveOptions, ResolveOptionsWithDependencyType]>} */
|
260
264
|
(_hook);
|
261
|
-
hook.tap(
|
262
|
-
if (
|
265
|
+
hook.tap(PLUGIN_NAME, (resolver, options, userOptions) => {
|
266
|
+
if (
|
267
|
+
/** @type {ResolveOptions & { cache: boolean }} */
|
268
|
+
(options).cache !== true
|
269
|
+
)
|
270
|
+
return;
|
263
271
|
const optionsIdent = objectToString(userOptions, false);
|
264
272
|
const cacheWithContext =
|
265
273
|
options.cacheWithContext !== undefined
|
@@ -267,7 +275,7 @@ class ResolverCachePlugin {
|
|
267
275
|
: false;
|
268
276
|
resolver.hooks.resolve.tapAsync(
|
269
277
|
{
|
270
|
-
name:
|
278
|
+
name: PLUGIN_NAME,
|
271
279
|
stage: -100
|
272
280
|
},
|
273
281
|
(request, resolveContext, callback) => {
|
@@ -288,7 +296,7 @@ class ResolverCachePlugin {
|
|
288
296
|
if (activeRequest) {
|
289
297
|
activeRequest[0].push(callback);
|
290
298
|
activeRequest[1].push(
|
291
|
-
/** @type {
|
299
|
+
/** @type {Yield} */
|
292
300
|
(resolveContext.yield)
|
293
301
|
);
|
294
302
|
return;
|
@@ -303,7 +311,7 @@ class ResolverCachePlugin {
|
|
303
311
|
const itemCache = cache.getItemCache(identifier, null);
|
304
312
|
/** @type {Callback[] | false | undefined} */
|
305
313
|
let callbacks;
|
306
|
-
/** @type {
|
314
|
+
/** @type {Yield[] | undefined} */
|
307
315
|
let yields;
|
308
316
|
|
309
317
|
/**
|
@@ -319,7 +327,7 @@ class ResolverCachePlugin {
|
|
319
327
|
for (const r of /** @type {ResolveRequest[]} */ (
|
320
328
|
result
|
321
329
|
)) {
|
322
|
-
/** @type {
|
330
|
+
/** @type {Yield} */
|
323
331
|
(resolveContext.yield)(r);
|
324
332
|
}
|
325
333
|
callback(null, null);
|
@@ -336,9 +344,7 @@ class ResolverCachePlugin {
|
|
336
344
|
} else {
|
337
345
|
for (let i = 0; i < definedCallbacks.length; i++) {
|
338
346
|
const cb = definedCallbacks[i];
|
339
|
-
const yield_ =
|
340
|
-
/** @type {NonNullable<ResolveContext["yield"]>[]} */
|
341
|
-
(yields)[i];
|
347
|
+
const yield_ = /** @type {Yield[]} */ (yields)[i];
|
342
348
|
if (result)
|
343
349
|
for (const r of /** @type {ResolveRequest[]} */ (
|
344
350
|
result
|
@@ -424,14 +430,8 @@ class ResolverCachePlugin {
|
|
424
430
|
itemCache.get(processCacheResult);
|
425
431
|
if (withYield && callbacks === undefined) {
|
426
432
|
callbacks = [callback];
|
427
|
-
yields = [
|
428
|
-
|
429
|
-
(resolveContext.yield)
|
430
|
-
];
|
431
|
-
activeRequestsWithYield.set(
|
432
|
-
identifier,
|
433
|
-
/** @type {[any, any]} */ ([callbacks, yields])
|
434
|
-
);
|
433
|
+
yields = [/** @type {Yield} */ (resolveContext.yield)];
|
434
|
+
activeRequestsWithYield.set(identifier, [callbacks, yields]);
|
435
435
|
} else if (callbacks === undefined) {
|
436
436
|
callbacks = [callback];
|
437
437
|
activeRequests.set(identifier, callbacks);
|
package/lib/cli.js
CHANGED
@@ -8,7 +8,11 @@
|
|
8
8
|
const path = require("path");
|
9
9
|
const webpackSchema = require("../schemas/WebpackOptions.json");
|
10
10
|
|
11
|
-
/** @typedef {
|
11
|
+
/** @typedef {import("json-schema").JSONSchema4} JSONSchema4 */
|
12
|
+
/** @typedef {import("json-schema").JSONSchema6} JSONSchema6 */
|
13
|
+
/** @typedef {import("json-schema").JSONSchema7} JSONSchema7 */
|
14
|
+
/** @typedef {JSONSchema4 | JSONSchema6 | JSONSchema7} JSONSchema */
|
15
|
+
/** @typedef {JSONSchema & { absolutePath: boolean, instanceof: string, cli: { helper?: boolean, exclude?: boolean, description?: string, negatedDescription?: string, resetDescription?: string } }} Schema */
|
12
16
|
|
13
17
|
// TODO add originPath to PathItem for better errors
|
14
18
|
/**
|
@@ -44,11 +48,11 @@ const webpackSchema = require("../schemas/WebpackOptions.json");
|
|
44
48
|
|
45
49
|
/**
|
46
50
|
* @typedef {object} ArgumentConfig
|
47
|
-
* @property {string
|
48
|
-
* @property {string}
|
51
|
+
* @property {string=} description
|
52
|
+
* @property {string=} negatedDescription
|
49
53
|
* @property {string} path
|
50
54
|
* @property {boolean} multiple
|
51
|
-
* @property {"enum"|"string"|"path"|"number"|"boolean"|"RegExp"|"reset"} type
|
55
|
+
* @property {"enum" | "string" | "path" | "number" | "boolean" | "RegExp" | "reset"} type
|
52
56
|
* @property {EnumValue[]=} values
|
53
57
|
*/
|
54
58
|
|
package/lib/config/defaults.js
CHANGED
@@ -166,7 +166,7 @@ const applyWebpackOptionsBaseDefaults = options => {
|
|
166
166
|
|
167
167
|
/**
|
168
168
|
* @param {WebpackOptionsNormalized} options options to be modified
|
169
|
-
* @param {number}
|
169
|
+
* @param {number=} compilerIndex index of compiler
|
170
170
|
* @returns {ResolvedOptions} Resolved options after apply defaults
|
171
171
|
*/
|
172
172
|
const applyWebpackOptionsDefaults = (options, compilerIndex) => {
|
@@ -405,7 +405,7 @@ const applyExperimentsDefaults = (
|
|
405
405
|
* @param {Mode} options.mode mode
|
406
406
|
* @param {boolean} options.futureDefaults is future defaults enabled
|
407
407
|
* @param {boolean} options.development is development mode
|
408
|
-
* @param {number}
|
408
|
+
* @param {number=} options.compilerIndex index of compiler
|
409
409
|
* @param {Experiments["cacheUnaffected"]} options.cacheUnaffected the cacheUnaffected experiment is enabled
|
410
410
|
* @returns {void}
|
411
411
|
*/
|
@@ -22,6 +22,7 @@ const util = require("util");
|
|
22
22
|
/** @typedef {import("../../declarations/WebpackOptions").WebpackOptions} WebpackOptions */
|
23
23
|
/** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptionsNormalized */
|
24
24
|
/** @typedef {import("../Entrypoint")} Entrypoint */
|
25
|
+
/** @typedef {import("../WebpackError")} WebpackError */
|
25
26
|
|
26
27
|
const handledDeprecatedNoEmitOnErrors = util.deprecate(
|
27
28
|
/**
|
@@ -210,14 +211,19 @@ const getNormalizedWebpackOptions = config => ({
|
|
210
211
|
}
|
211
212
|
if (
|
212
213
|
i.module &&
|
213
|
-
(!warning.module ||
|
214
|
+
(!(/** @type {WebpackError} */ (warning).module) ||
|
214
215
|
!i.module.test(
|
215
|
-
|
216
|
+
/** @type {WebpackError} */
|
217
|
+
(warning).module.readableIdentifier(requestShortener)
|
216
218
|
))
|
217
219
|
) {
|
218
220
|
return false;
|
219
221
|
}
|
220
|
-
if (
|
222
|
+
if (
|
223
|
+
i.file &&
|
224
|
+
(!(/** @type {WebpackError} */ (warning).file) ||
|
225
|
+
!i.file.test(/** @type {WebpackError} */ (warning).file))
|
226
|
+
) {
|
221
227
|
return false;
|
222
228
|
}
|
223
229
|
return true;
|
package/lib/config/target.js
CHANGED
@@ -22,12 +22,12 @@ const getDefaultTarget = context => {
|
|
22
22
|
|
23
23
|
/**
|
24
24
|
* @typedef {object} PlatformTargetProperties
|
25
|
-
* @property {boolean | null}
|
26
|
-
* @property {boolean | null}
|
27
|
-
* @property {boolean | null}
|
28
|
-
* @property {boolean | null}
|
29
|
-
* @property {boolean | null}
|
30
|
-
* @property {boolean | null}
|
25
|
+
* @property {boolean | null=} web web platform, importing of http(s) and std: is available
|
26
|
+
* @property {boolean | null=} browser browser platform, running in a normal web browser
|
27
|
+
* @property {boolean | null=} webworker (Web)Worker platform, running in a web/shared/service worker
|
28
|
+
* @property {boolean | null=} node node platform, require of node built-in modules is available
|
29
|
+
* @property {boolean | null=} nwjs nwjs platform, require of legacy nw.gui is available
|
30
|
+
* @property {boolean | null=} electron electron platform, require of some electron built-in modules is available
|
31
31
|
*/
|
32
32
|
|
33
33
|
/**
|
@@ -31,6 +31,7 @@ const validate = createSchemaValidation(
|
|
31
31
|
);
|
32
32
|
|
33
33
|
const slashCode = "/".charCodeAt(0);
|
34
|
+
const PLUGIN_NAME = "ContainerReferencePlugin";
|
34
35
|
|
35
36
|
class ContainerReferencePlugin {
|
36
37
|
/**
|
@@ -79,7 +80,7 @@ class ContainerReferencePlugin {
|
|
79
80
|
new ExternalsPlugin(remoteType, remoteExternals).apply(compiler);
|
80
81
|
|
81
82
|
compiler.hooks.compilation.tap(
|
82
|
-
|
83
|
+
PLUGIN_NAME,
|
83
84
|
(compilation, { normalModuleFactory }) => {
|
84
85
|
compilation.dependencyFactories.set(
|
85
86
|
RemoteToExternalDependency,
|
@@ -96,37 +97,34 @@ class ContainerReferencePlugin {
|
|
96
97
|
new FallbackModuleFactory()
|
97
98
|
);
|
98
99
|
|
99
|
-
normalModuleFactory.hooks.factorize.tap(
|
100
|
-
"
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
data.request.
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
config.shareScope
|
120
|
-
);
|
121
|
-
}
|
100
|
+
normalModuleFactory.hooks.factorize.tap(PLUGIN_NAME, data => {
|
101
|
+
if (!data.request.includes("!")) {
|
102
|
+
for (const [key, config] of remotes) {
|
103
|
+
if (
|
104
|
+
data.request.startsWith(`${key}`) &&
|
105
|
+
(data.request.length === key.length ||
|
106
|
+
data.request.charCodeAt(key.length) === slashCode)
|
107
|
+
) {
|
108
|
+
return new RemoteModule(
|
109
|
+
data.request,
|
110
|
+
config.external.map((external, i) =>
|
111
|
+
external.startsWith("internal ")
|
112
|
+
? external.slice(9)
|
113
|
+
: `webpack/container/reference/${key}${
|
114
|
+
i ? `/fallback-${i}` : ""
|
115
|
+
}`
|
116
|
+
),
|
117
|
+
`.${data.request.slice(key.length)}`,
|
118
|
+
config.shareScope
|
119
|
+
);
|
122
120
|
}
|
123
121
|
}
|
124
122
|
}
|
125
|
-
);
|
123
|
+
});
|
126
124
|
|
127
125
|
compilation.hooks.runtimeRequirementInTree
|
128
126
|
.for(RuntimeGlobals.ensureChunkHandlers)
|
129
|
-
.tap(
|
127
|
+
.tap(PLUGIN_NAME, (chunk, set) => {
|
130
128
|
set.add(RuntimeGlobals.module);
|
131
129
|
set.add(RuntimeGlobals.moduleFactoriesAddOnly);
|
132
130
|
set.add(RuntimeGlobals.hasOwnProperty);
|
@@ -37,6 +37,7 @@ const validate = createSchemaValidation(
|
|
37
37
|
|
38
38
|
/** @type {WeakMap<Compilation, CompilationHooks>} */
|
39
39
|
const compilationHooksMap = new WeakMap();
|
40
|
+
const PLUGIN_NAME = "ModuleFederationPlugin";
|
40
41
|
|
41
42
|
class ModuleFederationPlugin {
|
42
43
|
/**
|
@@ -89,7 +90,7 @@ class ModuleFederationPlugin {
|
|
89
90
|
) {
|
90
91
|
compiler.options.output.enabledLibraryTypes.push(library.type);
|
91
92
|
}
|
92
|
-
compiler.hooks.afterPlugins.tap(
|
93
|
+
compiler.hooks.afterPlugins.tap(PLUGIN_NAME, () => {
|
93
94
|
if (
|
94
95
|
options.exposes &&
|
95
96
|
(Array.isArray(options.exposes)
|
package/lib/css/CssGenerator.js
CHANGED