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/README.md
CHANGED
@@ -676,5 +676,5 @@ Before we started using OpenCollective, donations were made anonymously. Now tha
|
|
676
676
|
[builds2-url]: https://dev.azure.com/webpack/webpack/_build/latest?definitionId=3&branchName=main
|
677
677
|
[dependency-review-url]: https://github.com/webpack/webpack/actions/workflows/dependency-review.yml
|
678
678
|
[dependency-review]: https://github.com/webpack/webpack/actions/workflows/dependency-review.yml/badge.svg
|
679
|
-
[cover]: https://codecov.io/gh/webpack/webpack/
|
679
|
+
[cover]: https://codecov.io/gh/webpack/webpack/graph/badge.svg?token=mDP3mQJNnn
|
680
680
|
[cover-url]: https://codecov.io/gh/webpack/webpack
|
package/lib/APIPlugin.js
CHANGED
@@ -134,12 +134,12 @@ const PLUGIN_NAME = "APIPlugin";
|
|
134
134
|
|
135
135
|
/**
|
136
136
|
* @typedef {object} APIPluginOptions
|
137
|
-
* @property {boolean}
|
137
|
+
* @property {boolean=} module the output filename
|
138
138
|
*/
|
139
139
|
|
140
140
|
class APIPlugin {
|
141
141
|
/**
|
142
|
-
* @param {APIPluginOptions}
|
142
|
+
* @param {APIPluginOptions=} options options
|
143
143
|
*/
|
144
144
|
constructor(options = {}) {
|
145
145
|
this.options = options;
|
@@ -11,6 +11,8 @@ const PrefetchDependency = require("./dependencies/PrefetchDependency");
|
|
11
11
|
|
12
12
|
/** @typedef {import("./Compiler")} Compiler */
|
13
13
|
|
14
|
+
const PLUGIN_NAME = "AutomaticPrefetchPlugin";
|
15
|
+
|
14
16
|
class AutomaticPrefetchPlugin {
|
15
17
|
/**
|
16
18
|
* Apply the plugin
|
@@ -19,7 +21,7 @@ class AutomaticPrefetchPlugin {
|
|
19
21
|
*/
|
20
22
|
apply(compiler) {
|
21
23
|
compiler.hooks.compilation.tap(
|
22
|
-
|
24
|
+
PLUGIN_NAME,
|
23
25
|
(compilation, { normalModuleFactory }) => {
|
24
26
|
compilation.dependencyFactories.set(
|
25
27
|
PrefetchDependency,
|
@@ -29,7 +31,7 @@ class AutomaticPrefetchPlugin {
|
|
29
31
|
);
|
30
32
|
/** @type {{context: string | null, request: string}[] | null} */
|
31
33
|
let lastModules = null;
|
32
|
-
compiler.hooks.afterCompile.tap(
|
34
|
+
compiler.hooks.afterCompile.tap(PLUGIN_NAME, compilation => {
|
33
35
|
lastModules = [];
|
34
36
|
|
35
37
|
for (const m of compilation.modules) {
|
@@ -41,26 +43,23 @@ class AutomaticPrefetchPlugin {
|
|
41
43
|
}
|
42
44
|
}
|
43
45
|
});
|
44
|
-
compiler.hooks.make.tapAsync(
|
45
|
-
|
46
|
-
(
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
err
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
);
|
62
|
-
}
|
63
|
-
);
|
46
|
+
compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => {
|
47
|
+
if (!lastModules) return callback();
|
48
|
+
asyncLib.each(
|
49
|
+
lastModules,
|
50
|
+
(m, callback) => {
|
51
|
+
compilation.addModuleChain(
|
52
|
+
m.context || compiler.context,
|
53
|
+
new PrefetchDependency(`!!${m.request}`),
|
54
|
+
callback
|
55
|
+
);
|
56
|
+
},
|
57
|
+
err => {
|
58
|
+
lastModules = null;
|
59
|
+
callback(err);
|
60
|
+
}
|
61
|
+
);
|
62
|
+
});
|
64
63
|
}
|
65
64
|
}
|
66
65
|
module.exports = AutomaticPrefetchPlugin;
|
package/lib/BannerPlugin.js
CHANGED
@@ -44,6 +44,8 @@ const wrapComment = str => {
|
|
44
44
|
.trimEnd()}\n */`;
|
45
45
|
};
|
46
46
|
|
47
|
+
const PLUGIN_NAME = "BannerPlugin";
|
48
|
+
|
47
49
|
class BannerPlugin {
|
48
50
|
/**
|
49
51
|
* @param {BannerPluginArgument} options options object
|
@@ -91,47 +93,41 @@ class BannerPlugin {
|
|
91
93
|
const stage =
|
92
94
|
this.options.stage || Compilation.PROCESS_ASSETS_STAGE_ADDITIONS;
|
93
95
|
|
94
|
-
compiler.hooks.compilation.tap(
|
95
|
-
compilation.hooks.processAssets.tap(
|
96
|
-
{
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
for (const
|
102
|
-
if (
|
96
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
97
|
+
compilation.hooks.processAssets.tap({ name: PLUGIN_NAME, stage }, () => {
|
98
|
+
for (const chunk of compilation.chunks) {
|
99
|
+
if (options.entryOnly && !chunk.canBeInitial()) {
|
100
|
+
continue;
|
101
|
+
}
|
102
|
+
|
103
|
+
for (const file of chunk.files) {
|
104
|
+
if (!matchObject(file)) {
|
103
105
|
continue;
|
104
106
|
}
|
105
107
|
|
106
|
-
|
107
|
-
|
108
|
-
|
108
|
+
/** @type {PathData} */
|
109
|
+
const data = { chunk, filename: file };
|
110
|
+
|
111
|
+
const comment = compilation.getPath(
|
112
|
+
/** @type {TemplatePath} */
|
113
|
+
(banner),
|
114
|
+
data
|
115
|
+
);
|
116
|
+
|
117
|
+
compilation.updateAsset(file, old => {
|
118
|
+
const cached = cache.get(old);
|
119
|
+
if (!cached || cached.comment !== comment) {
|
120
|
+
const source = options.footer
|
121
|
+
? new ConcatSource(old, "\n", comment)
|
122
|
+
: new ConcatSource(comment, "\n", old);
|
123
|
+
cache.set(old, { source, comment });
|
124
|
+
return source;
|
109
125
|
}
|
110
|
-
|
111
|
-
|
112
|
-
const data = { chunk, filename: file };
|
113
|
-
|
114
|
-
const comment = compilation.getPath(
|
115
|
-
/** @type {TemplatePath} */
|
116
|
-
(banner),
|
117
|
-
data
|
118
|
-
);
|
119
|
-
|
120
|
-
compilation.updateAsset(file, old => {
|
121
|
-
const cached = cache.get(old);
|
122
|
-
if (!cached || cached.comment !== comment) {
|
123
|
-
const source = options.footer
|
124
|
-
? new ConcatSource(old, "\n", comment)
|
125
|
-
: new ConcatSource(comment, "\n", old);
|
126
|
-
cache.set(old, { source, comment });
|
127
|
-
return source;
|
128
|
-
}
|
129
|
-
return cached.source;
|
130
|
-
});
|
131
|
-
}
|
126
|
+
return cached.source;
|
127
|
+
});
|
132
128
|
}
|
133
129
|
}
|
134
|
-
);
|
130
|
+
});
|
135
131
|
});
|
136
132
|
}
|
137
133
|
}
|
package/lib/Cache.js
CHANGED
package/lib/Chunk.js
CHANGED
@@ -34,7 +34,9 @@ const { mergeRuntime } = require("./util/runtime");
|
|
34
34
|
/** @typedef {import("./util/Hash")} Hash */
|
35
35
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
36
36
|
|
37
|
+
/** @typedef {string | null} ChunkName */
|
37
38
|
/** @typedef {number | string} ChunkId */
|
39
|
+
/** @typedef {SortableSet<string>} IdNameHints */
|
38
40
|
|
39
41
|
const ChunkFilesSet = createArrayToSetDeprecationSet("chunk.files");
|
40
42
|
|
@@ -46,9 +48,9 @@ const ChunkFilesSet = createArrayToSetDeprecationSet("chunk.files");
|
|
46
48
|
/**
|
47
49
|
* @deprecated
|
48
50
|
* @typedef {object} ChunkMaps
|
49
|
-
* @property {Record<string|number, string>} hash
|
50
|
-
* @property {Record<string|number, Record<string, string>>} contentHash
|
51
|
-
* @property {Record<string|number, string>} name
|
51
|
+
* @property {Record<string | number, string>} hash
|
52
|
+
* @property {Record<string | number, Record<string, string>>} contentHash
|
53
|
+
* @property {Record<string | number, string>} name
|
52
54
|
*/
|
53
55
|
|
54
56
|
/**
|
@@ -66,7 +68,7 @@ let debugId = 1000;
|
|
66
68
|
*/
|
67
69
|
class Chunk {
|
68
70
|
/**
|
69
|
-
* @param {
|
71
|
+
* @param {ChunkName=} name of chunk being created, is optional (for subclasses)
|
70
72
|
* @param {boolean} backCompat enable backward-compatibility
|
71
73
|
*/
|
72
74
|
constructor(name, backCompat = true) {
|
@@ -76,9 +78,9 @@ class Chunk {
|
|
76
78
|
this.ids = null;
|
77
79
|
/** @type {number} */
|
78
80
|
this.debugId = debugId++;
|
79
|
-
/** @type {
|
81
|
+
/** @type {ChunkName | undefined} */
|
80
82
|
this.name = name;
|
81
|
-
/** @type {
|
83
|
+
/** @type {IdNameHints} */
|
82
84
|
this.idNameHints = new SortableSet();
|
83
85
|
/** @type {boolean} */
|
84
86
|
this.preventIntegration = false;
|
@@ -696,7 +698,7 @@ class Chunk {
|
|
696
698
|
/**
|
697
699
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
698
700
|
* @param {ChunkFilterPredicate=} filterFn function used to filter chunks
|
699
|
-
* @returns {Record<string,
|
701
|
+
* @returns {Record<string, ChunkId[]>} a record object of names to lists of child ids(?)
|
700
702
|
*/
|
701
703
|
getChildIdsByOrders(chunkGraph, filterFn) {
|
702
704
|
/** @type {Map<string, {order: number, group: ChunkGroup}[]>} */
|
@@ -717,7 +719,8 @@ class Chunk {
|
|
717
719
|
/** @type {number} */
|
718
720
|
(
|
719
721
|
childGroup.options[
|
720
|
-
/** @type {keyof ChunkGroupOptions} */
|
722
|
+
/** @type {keyof ChunkGroupOptions} */
|
723
|
+
(key)
|
721
724
|
]
|
722
725
|
),
|
723
726
|
group: childGroup
|
@@ -735,7 +738,7 @@ class Chunk {
|
|
735
738
|
if (cmp !== 0) return cmp;
|
736
739
|
return a.group.compareTo(chunkGraph, b.group);
|
737
740
|
});
|
738
|
-
/** @type {Set<
|
741
|
+
/** @type {Set<ChunkId>} */
|
739
742
|
const chunkIdSet = new Set();
|
740
743
|
for (const item of list) {
|
741
744
|
for (const chunk of item.group.chunks) {
|
package/lib/CleanPlugin.js
CHANGED
@@ -296,6 +296,8 @@ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
|
|
296
296
|
/** @type {WeakMap<Compilation, CleanPluginCompilationHooks>} */
|
297
297
|
const compilationHooksMap = new WeakMap();
|
298
298
|
|
299
|
+
const PLUGIN_NAME = "CleanPlugin";
|
300
|
+
|
299
301
|
class CleanPlugin {
|
300
302
|
/**
|
301
303
|
* @param {Compilation} compilation the compilation
|
@@ -349,18 +351,18 @@ class CleanPlugin {
|
|
349
351
|
|
350
352
|
compiler.hooks.emit.tapAsync(
|
351
353
|
{
|
352
|
-
name:
|
354
|
+
name: PLUGIN_NAME,
|
353
355
|
stage: 100
|
354
356
|
},
|
355
357
|
(compilation, callback) => {
|
356
358
|
const hooks = CleanPlugin.getCompilationHooks(compilation);
|
357
|
-
const logger = compilation.getLogger(
|
359
|
+
const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`);
|
358
360
|
const fs = /** @type {OutputFileSystem} */ (compiler.outputFileSystem);
|
359
361
|
|
360
362
|
if (!fs.readdir) {
|
361
363
|
return callback(
|
362
364
|
new Error(
|
363
|
-
|
365
|
+
`${PLUGIN_NAME}: Output filesystem doesn't support listing directories (readdir)`
|
364
366
|
)
|
365
367
|
);
|
366
368
|
}
|
package/lib/Compilation.js
CHANGED
@@ -94,10 +94,13 @@ const { isSourceEqual } = require("./util/source");
|
|
94
94
|
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
95
95
|
/** @typedef {import("./Cache")} Cache */
|
96
96
|
/** @typedef {import("./CacheFacade")} CacheFacade */
|
97
|
+
/** @typedef {import("./Chunk").ChunkName} ChunkName */
|
97
98
|
/** @typedef {import("./Chunk").ChunkId} ChunkId */
|
98
99
|
/** @typedef {import("./ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
|
99
100
|
/** @typedef {import("./Compiler")} Compiler */
|
100
101
|
/** @typedef {import("./Compiler").CompilationParams} CompilationParams */
|
102
|
+
/** @typedef {import("./Compiler").MemCache} MemCache */
|
103
|
+
/** @typedef {import("./Compiler").WeakReferences} WeakReferences */
|
101
104
|
/** @typedef {import("./Compiler").ModuleMemCachesItem} ModuleMemCachesItem */
|
102
105
|
/** @typedef {import("./DependenciesBlock")} DependenciesBlock */
|
103
106
|
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
@@ -106,6 +109,7 @@ const { isSourceEqual } = require("./util/source");
|
|
106
109
|
/** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
|
107
110
|
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
108
111
|
/** @typedef {import("./Module").ValueCacheVersions} ValueCacheVersions */
|
112
|
+
/** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
|
109
113
|
/** @typedef {import("./NormalModule").NormalModuleCompilationHooks} NormalModuleCompilationHooks */
|
110
114
|
/** @typedef {import("./Module").FactoryMeta} FactoryMeta */
|
111
115
|
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
|
@@ -132,7 +136,6 @@ const { isSourceEqual } = require("./util/source");
|
|
132
136
|
* @typedef {import("./util/deprecation").FakeHook<T>} FakeHook<T>
|
133
137
|
*/
|
134
138
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
135
|
-
/** @typedef {WeakMap<Dependency, Module>} References */
|
136
139
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
137
140
|
/**
|
138
141
|
* @callback Callback
|
@@ -168,12 +171,6 @@ const { isSourceEqual } = require("./util/source");
|
|
168
171
|
* @returns {void}
|
169
172
|
*/
|
170
173
|
|
171
|
-
/**
|
172
|
-
* @callback DepBlockVarDependenciesCallback
|
173
|
-
* @param {Dependency} dependency
|
174
|
-
* @returns {any}
|
175
|
-
*/
|
176
|
-
|
177
174
|
/** @typedef {new (...args: EXPECTED_ANY[]) => Dependency} DepConstructor */
|
178
175
|
|
179
176
|
/** @typedef {Record<string, Source>} CompilationAssets */
|
@@ -235,17 +232,17 @@ const { isSourceEqual } = require("./util/source");
|
|
235
232
|
|
236
233
|
/**
|
237
234
|
* @typedef {object} ExecuteModuleObject
|
238
|
-
* @property {string}
|
235
|
+
* @property {string=} id module id
|
239
236
|
* @property {ExecuteModuleExports} exports exports
|
240
237
|
* @property {boolean} loaded is loaded
|
241
|
-
* @property {Error}
|
238
|
+
* @property {Error=} error error
|
242
239
|
*/
|
243
240
|
|
244
241
|
/**
|
245
242
|
* @typedef {object} ExecuteModuleArgument
|
246
243
|
* @property {Module} module
|
247
244
|
* @property {ExecuteModuleObject=} moduleObject
|
248
|
-
* @property {
|
245
|
+
* @property {TODO} preparedInfo
|
249
246
|
* @property {CodeGenerationResult} codeGenerationResult
|
250
247
|
*/
|
251
248
|
|
@@ -253,7 +250,7 @@ const { isSourceEqual } = require("./util/source");
|
|
253
250
|
|
254
251
|
/**
|
255
252
|
* @typedef {object} ExecuteOptions
|
256
|
-
* @property {string}
|
253
|
+
* @property {string=} id module id
|
257
254
|
* @property {ExecuteModuleObject} module module
|
258
255
|
* @property {WebpackRequire} require require function
|
259
256
|
*/
|
@@ -333,6 +330,8 @@ const { isSourceEqual } = require("./util/source");
|
|
333
330
|
* @property {string=} url
|
334
331
|
*/
|
335
332
|
|
333
|
+
/** @typedef {"module" | "chunk" | "root-of-chunk" | "nested"} ExcludeModulesType */
|
334
|
+
|
336
335
|
/**
|
337
336
|
* @typedef {object} KnownNormalizedStatsOptions
|
338
337
|
* @property {string} context
|
@@ -349,7 +348,7 @@ const { isSourceEqual } = require("./util/source");
|
|
349
348
|
* @property {boolean} groupAssetsByExtension
|
350
349
|
* @property {number} assetsSpace
|
351
350
|
* @property {((value: string, asset: StatsAsset) => boolean)[]} excludeAssets
|
352
|
-
* @property {((name: string, module: StatsModule, type:
|
351
|
+
* @property {((name: string, module: StatsModule, type: ExcludeModulesType) => boolean)[]} excludeModules
|
353
352
|
* @property {((warning: StatsError, textValue: string) => boolean)[]} warningsFilter
|
354
353
|
* @property {boolean} cachedModules
|
355
354
|
* @property {boolean} orphanModules
|
@@ -459,10 +458,10 @@ const compareErrors = concatComparators(byModule, byLocation, byMessage);
|
|
459
458
|
|
460
459
|
/**
|
461
460
|
* @typedef {object} KnownUnsafeCacheData
|
462
|
-
* @property {FactoryMeta}
|
463
|
-
* @property {ResolveOptions}
|
464
|
-
* @property {ParserOptions}
|
465
|
-
* @property {GeneratorOptions}
|
461
|
+
* @property {FactoryMeta=} factoryMeta factory meta
|
462
|
+
* @property {ResolveOptions=} resolveOptions resolve options
|
463
|
+
* @property {ParserOptions=} parserOptions
|
464
|
+
* @property {GeneratorOptions=} generatorOptions
|
466
465
|
*/
|
467
466
|
|
468
467
|
/** @typedef {KnownUnsafeCacheData & Record<string, EXPECTED_ANY>} UnsafeCacheData */
|
@@ -477,7 +476,8 @@ const unsafeCacheDependencies = new WeakMap();
|
|
477
476
|
/** @type {WeakMap<ModuleWithRestoreFromUnsafeCache, UnsafeCacheData>} */
|
478
477
|
const unsafeCacheData = new WeakMap();
|
479
478
|
|
480
|
-
/** @typedef {Map<Module,
|
479
|
+
/** @typedef {{ id: ModuleId, modules?: Map<Module, string | number | undefined>, blocks?: (string | number | null)[] }} References */
|
480
|
+
/** @typedef {Map<Module, WeakTupleMap<EXPECTED_ANY[], EXPECTED_ANY>>} ModuleMemCaches */
|
481
481
|
|
482
482
|
class Compilation {
|
483
483
|
/**
|
@@ -690,7 +690,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
690
690
|
processAssetsHook.tapAsync(
|
691
691
|
getOptions(options),
|
692
692
|
(assets, callback) =>
|
693
|
-
/** @type {
|
693
|
+
/** @type {TODO} */ (fn)(...getArgs(), callback)
|
694
694
|
);
|
695
695
|
},
|
696
696
|
/** @type {AsyncSeriesHook<T>["tapPromise"]} */
|
@@ -973,9 +973,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
973
973
|
/** @type {SyncBailHook<[string, LogEntry], boolean | void>} */
|
974
974
|
log: new SyncBailHook(["origin", "logEntry"]),
|
975
975
|
|
976
|
-
/** @type {SyncWaterfallHook<[
|
976
|
+
/** @type {SyncWaterfallHook<[Error[]]>} */
|
977
977
|
processWarnings: new SyncWaterfallHook(["warnings"]),
|
978
|
-
/** @type {SyncWaterfallHook<[
|
978
|
+
/** @type {SyncWaterfallHook<[Error[]]>} */
|
979
979
|
processErrors: new SyncWaterfallHook(["errors"]),
|
980
980
|
|
981
981
|
/** @type {HookMap<SyncHook<[Partial<NormalizedStatsOptions>, CreateStatsOptionsContext]>>} */
|
@@ -1049,6 +1049,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1049
1049
|
};
|
1050
1050
|
defineRemovedModuleTemplates(this.moduleTemplates);
|
1051
1051
|
|
1052
|
+
// We need to think how implement types here
|
1052
1053
|
/** @type {ModuleMemCaches | undefined} */
|
1053
1054
|
this.moduleMemCaches = undefined;
|
1054
1055
|
/** @type {ModuleMemCaches | undefined} */
|
@@ -1099,7 +1100,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1099
1100
|
*/
|
1100
1101
|
this.creatingModuleDuringBuild = new WeakMap();
|
1101
1102
|
|
1102
|
-
/** @type {Map<
|
1103
|
+
/** @type {Map<Exclude<ChunkName, null>, EntryData>} */
|
1103
1104
|
this.entries = new Map();
|
1104
1105
|
/** @type {EntryData} */
|
1105
1106
|
this.globalEntry = {
|
@@ -1142,9 +1143,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1142
1143
|
this.assetsInfo = new Map();
|
1143
1144
|
/** @type {Map<string, Map<string, Set<string>>>} */
|
1144
1145
|
this._assetsRelatedIn = new Map();
|
1145
|
-
/** @type {
|
1146
|
+
/** @type {Error[]} */
|
1146
1147
|
this.errors = [];
|
1147
|
-
/** @type {
|
1148
|
+
/** @type {Error[]} */
|
1148
1149
|
this.warnings = [];
|
1149
1150
|
/** @type {Compilation[]} */
|
1150
1151
|
this.children = [];
|
@@ -2501,10 +2502,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2501
2502
|
|
2502
2503
|
/**
|
2503
2504
|
* @param {Module} module module
|
2504
|
-
* @returns {
|
2505
|
+
* @returns {WeakReferences | undefined} references
|
2505
2506
|
*/
|
2506
2507
|
const computeReferences = module => {
|
2507
|
-
/** @type {
|
2508
|
+
/** @type {WeakReferences | undefined} */
|
2508
2509
|
let references;
|
2509
2510
|
for (const connection of moduleGraph.getOutgoingConnections(module)) {
|
2510
2511
|
const d = connection.dependency;
|
@@ -2518,7 +2519,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2518
2519
|
|
2519
2520
|
/**
|
2520
2521
|
* @param {Module} module the module
|
2521
|
-
* @param {
|
2522
|
+
* @param {WeakReferences | undefined} references references
|
2522
2523
|
* @returns {boolean} true, when the references differ
|
2523
2524
|
*/
|
2524
2525
|
const compareReferences = (module, references) => {
|
@@ -2540,6 +2541,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2540
2541
|
if (buildInfo) {
|
2541
2542
|
if (cachedMemCache.buildInfo !== buildInfo) {
|
2542
2543
|
// use a new one
|
2544
|
+
/** @type {MemCache} */
|
2543
2545
|
const memCache = new WeakTupleMap();
|
2544
2546
|
moduleMemCaches.set(module, memCache);
|
2545
2547
|
affectedModules.add(module);
|
@@ -2549,6 +2551,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2549
2551
|
statChanged++;
|
2550
2552
|
} else if (!compareReferences(module, cachedMemCache.references)) {
|
2551
2553
|
// use a new one
|
2554
|
+
/** @type {MemCache} */
|
2552
2555
|
const memCache = new WeakTupleMap();
|
2553
2556
|
moduleMemCaches.set(module, memCache);
|
2554
2557
|
affectedModules.add(module);
|
@@ -2639,6 +2642,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2639
2642
|
} else {
|
2640
2643
|
affectedModules.add(referencingModule);
|
2641
2644
|
}
|
2645
|
+
/** @type {MemCache} */
|
2642
2646
|
const memCache = new WeakTupleMap();
|
2643
2647
|
const cache =
|
2644
2648
|
/** @type {ModuleMemCachesItem} */
|
@@ -2671,7 +2675,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2671
2675
|
let statNew = 0;
|
2672
2676
|
/**
|
2673
2677
|
* @param {Module} module module
|
2674
|
-
* @returns {
|
2678
|
+
* @returns {References} references
|
2675
2679
|
*/
|
2676
2680
|
const computeReferences = module => {
|
2677
2681
|
const id = /** @type {ModuleId} */ (chunkGraph.getModuleId(module));
|
@@ -2741,9 +2745,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2741
2745
|
};
|
2742
2746
|
|
2743
2747
|
for (const [module, memCache] of moduleMemCaches) {
|
2744
|
-
/** @type {{ references:
|
2748
|
+
/** @type {{ references: References, memCache: MemCache } | undefined} */
|
2745
2749
|
const cache = memCache.get(key);
|
2746
2750
|
if (cache === undefined) {
|
2751
|
+
/** @type {WeakTupleMap<Module[], RuntimeRequirements | null> | undefined} */
|
2747
2752
|
const memCache2 = new WeakTupleMap();
|
2748
2753
|
memCache.set(key, {
|
2749
2754
|
references: computeReferences(module),
|
@@ -2752,6 +2757,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
2752
2757
|
moduleMemCaches2.set(module, memCache2);
|
2753
2758
|
statNew++;
|
2754
2759
|
} else if (!compareReferences(module, cache.references)) {
|
2760
|
+
/** @type {WeakTupleMap<Module[], RuntimeRequirements | null> | undefined} */
|
2755
2761
|
const memCache = new WeakTupleMap();
|
2756
2762
|
cache.references = computeReferences(module);
|
2757
2763
|
cache.memCache = memCache;
|
@@ -3732,7 +3738,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3732
3738
|
chunkGraph.addModuleRuntimeRequirements(
|
3733
3739
|
module,
|
3734
3740
|
runtime,
|
3735
|
-
|
3741
|
+
/** @type {RuntimeRequirements} */
|
3742
|
+
(cached),
|
3736
3743
|
false
|
3737
3744
|
);
|
3738
3745
|
}
|
@@ -3980,7 +3987,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3980
3987
|
/**
|
3981
3988
|
* This method first looks to see if a name is provided for a new chunk,
|
3982
3989
|
* and first looks to see if any named chunks already exist and reuse that chunk instead.
|
3983
|
-
* @param {
|
3990
|
+
* @param {ChunkName=} name optional chunk name to be provided
|
3984
3991
|
* @returns {Chunk} create a chunk (invoked during seal event)
|
3985
3992
|
*/
|
3986
3993
|
addChunk(name) {
|
@@ -4237,7 +4244,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
4237
4244
|
const memCache = moduleMemCaches2 && moduleMemCaches2.get(module);
|
4238
4245
|
for (const runtime of chunkGraph.getModuleRuntimes(module)) {
|
4239
4246
|
if (memCache) {
|
4240
|
-
const digest =
|
4247
|
+
const digest =
|
4248
|
+
/** @type {string} */
|
4249
|
+
(memCache.get(`moduleHash-${getRuntimeKey(runtime)}`));
|
4241
4250
|
if (digest !== undefined) {
|
4242
4251
|
chunkGraph.setModuleHashes(
|
4243
4252
|
module,
|
@@ -5477,9 +5486,9 @@ This prevents using hashes of each other and should be avoided.`);
|
|
5477
5486
|
if (strictModuleExceptionHandling) {
|
5478
5487
|
if (id) delete moduleCache[id];
|
5479
5488
|
} else if (strictModuleErrorHandling) {
|
5480
|
-
moduleObject.error =
|
5481
|
-
|
5482
|
-
|
5489
|
+
moduleObject.error =
|
5490
|
+
/** @type {WebpackError} */
|
5491
|
+
(execErr);
|
5483
5492
|
}
|
5484
5493
|
if (!(/** @type {WebpackError} */ (execErr).module)) {
|
5485
5494
|
/** @type {WebpackError} */
|
@@ -5506,7 +5515,8 @@ This prevents using hashes of each other and should be avoided.`);
|
|
5506
5515
|
`Execution of module code from module graph (${
|
5507
5516
|
/** @type {Module} */
|
5508
5517
|
(module).readableIdentifier(this.requestShortener)
|
5509
|
-
}) failed: ${message}
|
5518
|
+
}) failed: ${message}`,
|
5519
|
+
{ cause: execErr }
|
5510
5520
|
);
|
5511
5521
|
err.stack = stack;
|
5512
5522
|
err.module = module;
|
package/lib/Compiler.js
CHANGED
@@ -40,7 +40,7 @@ const { isSourceEqual } = require("./util/source");
|
|
40
40
|
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
41
41
|
/** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
|
42
42
|
/** @typedef {import("./Chunk")} Chunk */
|
43
|
-
/** @typedef {import("./
|
43
|
+
/** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
|
44
44
|
/** @typedef {import("./Dependency")} Dependency */
|
45
45
|
/** @typedef {import("./Module")} Module */
|
46
46
|
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
@@ -90,10 +90,11 @@ const { isSourceEqual } = require("./util/source");
|
|
90
90
|
*/
|
91
91
|
|
92
92
|
/** @typedef {{ sizeOnlySource: SizeOnlySource | undefined, writtenTo: Map<string, number> }} CacheEntry */
|
93
|
-
|
94
93
|
/** @typedef {{ path: string, source: Source, size: number | undefined, waiting: ({ cacheEntry: CacheEntry, file: string }[] | undefined) }} SimilarEntry */
|
95
94
|
|
96
|
-
/** @typedef {
|
95
|
+
/** @typedef {WeakMap<Dependency, Module>} WeakReferences */
|
96
|
+
/** @typedef {import("./util/WeakTupleMap")<EXPECTED_ANY[], EXPECTED_ANY>} MemCache */
|
97
|
+
/** @typedef {{ buildInfo: BuildInfo, references: WeakReferences | undefined, memCache: MemCache }} ModuleMemCachesItem */
|
97
98
|
|
98
99
|
/**
|
99
100
|
* @param {string[]} array an array
|
@@ -624,7 +625,8 @@ class Compiler {
|
|
624
625
|
callback(err, entries, compilation);
|
625
626
|
} catch (runAsChildErr) {
|
626
627
|
const err = new WebpackError(
|
627
|
-
`compiler.runAsChild callback error: ${runAsChildErr}
|
628
|
+
`compiler.runAsChild callback error: ${runAsChildErr}`,
|
629
|
+
{ cause: runAsChildErr }
|
628
630
|
);
|
629
631
|
err.details = /** @type {Error} */ (runAsChildErr).stack;
|
630
632
|
/** @type {Compilation} */
|
@@ -7,6 +7,8 @@
|
|
7
7
|
/** @typedef {import("./Compiler")} Compiler */
|
8
8
|
/** @typedef {import("./ContextModuleFactory")} ContextModuleFactory */
|
9
9
|
|
10
|
+
const PLUGIN_NAME = "ContextExclusionPlugin";
|
11
|
+
|
10
12
|
class ContextExclusionPlugin {
|
11
13
|
/**
|
12
14
|
* @param {RegExp} negativeMatcher Matcher regular expression
|
@@ -21,8 +23,8 @@ class ContextExclusionPlugin {
|
|
21
23
|
* @returns {void}
|
22
24
|
*/
|
23
25
|
apply(compiler) {
|
24
|
-
compiler.hooks.contextModuleFactory.tap(
|
25
|
-
cmf.hooks.contextModuleFiles.tap(
|
26
|
+
compiler.hooks.contextModuleFactory.tap(PLUGIN_NAME, cmf => {
|
27
|
+
cmf.hooks.contextModuleFiles.tap(PLUGIN_NAME, files =>
|
26
28
|
files.filter(filePath => !this.negativeMatcher.test(filePath))
|
27
29
|
);
|
28
30
|
});
|
package/lib/ContextModule.js
CHANGED
@@ -29,6 +29,7 @@ const {
|
|
29
29
|
const makeSerializable = require("./util/makeSerializable");
|
30
30
|
|
31
31
|
/** @typedef {import("webpack-sources").Source} Source */
|
32
|
+
/** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
32
33
|
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
33
34
|
/** @typedef {import("./Chunk")} Chunk */
|
34
35
|
/** @typedef {import("./Chunk").ChunkId} ChunkId */
|
@@ -83,7 +84,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
83
84
|
* @property {false|string|string[]} resource
|
84
85
|
* @property {string=} resourceQuery
|
85
86
|
* @property {string=} resourceFragment
|
86
|
-
* @property {
|
87
|
+
* @property {ResolveOptions=} resolveOptions
|
87
88
|
*/
|
88
89
|
|
89
90
|
/** @typedef {ContextOptions & ContextModuleOptionsExtras} ContextModuleOptions */
|