webpack 5.97.1 → 5.99.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +345 -392
- package/lib/AsyncDependenciesBlock.js +3 -1
- package/lib/BannerPlugin.js +1 -1
- package/lib/Cache.js +9 -7
- package/lib/CacheFacade.js +5 -5
- package/lib/Chunk.js +2 -2
- package/lib/ChunkGraph.js +21 -16
- package/lib/ChunkTemplate.js +6 -6
- package/lib/CleanPlugin.js +10 -10
- package/lib/CodeGenerationResults.js +4 -3
- package/lib/CompatibilityPlugin.js +4 -1
- package/lib/Compilation.js +343 -167
- package/lib/Compiler.js +13 -18
- package/lib/ConditionalInitFragment.js +1 -1
- package/lib/ConstPlugin.js +5 -3
- package/lib/ContextModule.js +4 -2
- package/lib/ContextModuleFactory.js +3 -3
- package/lib/ContextReplacementPlugin.js +43 -16
- package/lib/DefinePlugin.js +25 -24
- package/lib/DelegatedModule.js +4 -2
- package/lib/DelegatedModuleFactoryPlugin.js +2 -1
- package/lib/Dependency.js +19 -13
- package/lib/DependencyTemplates.js +4 -3
- package/lib/DllModule.js +4 -2
- package/lib/DllModuleFactory.js +2 -2
- package/lib/DllReferencePlugin.js +2 -1
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EnvironmentPlugin.js +4 -2
- package/lib/ExportsInfo.js +72 -40
- package/lib/ExternalModule.js +14 -5
- package/lib/ExternalModuleFactoryPlugin.js +24 -12
- package/lib/FileSystemInfo.js +129 -94
- package/lib/FlagDependencyExportsPlugin.js +6 -4
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +29 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/HotModuleReplacementPlugin.js +3 -9
- package/lib/IgnoreErrorModuleFactory.js +2 -2
- package/lib/IgnorePlugin.js +0 -5
- package/lib/InitFragment.js +1 -1
- package/lib/LoaderOptionsPlugin.js +8 -5
- package/lib/MainTemplate.js +7 -7
- package/lib/Module.js +44 -21
- package/lib/ModuleBuildError.js +3 -1
- package/lib/ModuleDependencyError.js +4 -3
- package/lib/ModuleDependencyWarning.js +4 -3
- package/lib/ModuleFactory.js +9 -3
- package/lib/ModuleFilenameHelpers.js +21 -39
- package/lib/ModuleGraph.js +20 -14
- package/lib/ModuleGraphConnection.js +7 -13
- package/lib/ModuleNotFoundError.js +1 -1
- package/lib/ModuleParseError.js +2 -1
- package/lib/ModuleSourceTypesConstants.js +11 -0
- package/lib/ModuleTemplate.js +5 -5
- package/lib/ModuleTypeConstants.js +15 -0
- package/lib/MultiCompiler.js +4 -4
- package/lib/MultiStats.js +1 -1
- package/lib/NormalModule.js +101 -54
- package/lib/NormalModuleFactory.js +38 -33
- package/lib/NormalModuleReplacementPlugin.js +3 -2
- package/lib/NullFactory.js +2 -2
- package/lib/Parser.js +4 -3
- package/lib/ProgressPlugin.js +1 -2
- package/lib/RawModule.js +4 -2
- package/lib/RecordIdsPlugin.js +6 -2
- package/lib/RequestShortener.js +3 -1
- package/lib/ResolverFactory.js +12 -9
- package/lib/RuntimeModule.js +4 -2
- package/lib/RuntimeTemplate.js +2 -1
- package/lib/SelfModuleFactory.js +2 -2
- package/lib/SourceMapDevToolPlugin.js +0 -8
- package/lib/Template.js +6 -5
- package/lib/TemplatedPathPlugin.js +15 -12
- package/lib/WebpackOptionsApply.js +1 -1
- package/lib/asset/AssetGenerator.js +237 -170
- package/lib/asset/AssetModulesPlugin.js +52 -10
- package/lib/asset/AssetSourceGenerator.js +18 -0
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/buildChunkGraph.js +14 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +137 -121
- package/lib/cache/ResolverCachePlugin.js +15 -7
- package/lib/cache/getLazyHashedEtag.js +4 -3
- package/lib/cli.js +23 -15
- package/lib/config/defaults.js +104 -28
- package/lib/config/normalization.js +14 -13
- package/lib/config/target.js +8 -8
- package/lib/container/ContainerEntryModule.js +4 -2
- package/lib/container/ContainerEntryModuleFactory.js +2 -2
- package/lib/container/FallbackModule.js +4 -2
- package/lib/container/FallbackModuleFactory.js +2 -2
- package/lib/container/RemoteModule.js +4 -2
- package/lib/container/options.js +5 -5
- package/lib/css/CssGenerator.js +71 -9
- package/lib/css/CssLoadingRuntimeModule.js +5 -2
- package/lib/css/CssModulesPlugin.js +41 -9
- package/lib/css/CssParser.js +37 -17
- package/lib/css/walkCssTokens.js +17 -17
- package/lib/debug/ProfilingPlugin.js +98 -38
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +10 -4
- package/lib/dependencies/AMDPlugin.js +5 -2
- package/lib/dependencies/AMDRequireArrayDependency.js +4 -3
- package/lib/dependencies/AMDRequireContextDependency.js +2 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +15 -7
- package/lib/dependencies/AMDRuntimeModules.js +3 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +4 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -3
- package/lib/dependencies/CommonJsImportsParserPlugin.js +38 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +13 -6
- package/lib/dependencies/CssIcssExportDependency.js +15 -12
- package/lib/dependencies/CssIcssImportDependency.js +4 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +18 -15
- package/lib/dependencies/ExportsInfoDependency.js +6 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +5 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +22 -15
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +23 -8
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +8 -6
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -14
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -5
- package/lib/dependencies/ImportContextDependency.js +2 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -4
- package/lib/dependencies/JsonExportsDependency.js +49 -27
- package/lib/dependencies/LoaderPlugin.js +4 -14
- package/lib/dependencies/RequireContextDependency.js +2 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +6 -3
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +11 -5
- package/lib/dependencies/RequireResolveContextDependency.js +1 -1
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +1 -1
- package/lib/dependencies/WorkerDependency.js +6 -3
- package/lib/dependencies/WorkerPlugin.js +100 -41
- package/lib/esm/ModuleChunkFormatPlugin.js +5 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +3 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +32 -24
- package/lib/hmr/lazyCompilationBackend.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/ids/IdHelpers.js +15 -14
- package/lib/ids/SyncModuleIdsPlugin.js +9 -5
- package/lib/index.js +5 -5
- package/lib/javascript/BasicEvaluatedExpression.js +6 -6
- package/lib/javascript/JavascriptGenerator.js +11 -1
- package/lib/javascript/JavascriptModulesPlugin.js +54 -34
- package/lib/javascript/JavascriptParser.js +272 -188
- package/lib/javascript/JavascriptParserHelpers.js +10 -9
- package/lib/javascript/StartupHelpers.js +4 -1
- package/lib/json/JsonData.js +4 -4
- package/lib/json/JsonGenerator.js +54 -22
- package/lib/json/JsonModulesPlugin.js +16 -3
- package/lib/json/JsonParser.js +10 -4
- package/lib/library/AbstractLibraryPlugin.js +7 -3
- package/lib/library/AssignLibraryPlugin.js +29 -1
- package/lib/library/EnableLibraryPlugin.js +7 -10
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +121 -15
- package/lib/logging/Logger.js +2 -2
- package/lib/logging/createConsoleLogger.js +4 -4
- package/lib/node/NodeEnvironmentPlugin.js +6 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
- package/lib/node/nodeConsole.js +3 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +19 -12
- package/lib/optimize/InnerGraph.js +3 -2
- package/lib/optimize/InnerGraphPlugin.js +13 -7
- package/lib/optimize/LimitChunkCountPlugin.js +20 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +10 -7
- package/lib/optimize/RealContentHashPlugin.js +8 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +4 -2
- package/lib/optimize/SplitChunksPlugin.js +90 -65
- package/lib/rules/BasicEffectRulePlugin.js +9 -1
- package/lib/rules/BasicMatcherRulePlugin.js +15 -4
- package/lib/rules/ObjectMatcherRulePlugin.js +12 -3
- package/lib/rules/RuleSetCompiler.js +25 -14
- package/lib/rules/UseEffectRulePlugin.js +47 -17
- package/lib/runtime/AutoPublicPathRuntimeModule.js +1 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -6
- package/lib/schemes/HttpUriPlugin.js +38 -17
- package/lib/serialization/BinaryMiddleware.js +52 -19
- package/lib/serialization/FileMiddleware.js +78 -48
- package/lib/serialization/ObjectMiddleware.js +78 -29
- package/lib/serialization/PlainObjectSerializer.js +1 -1
- package/lib/serialization/Serializer.js +15 -10
- package/lib/serialization/SerializerMiddleware.js +80 -41
- package/lib/serialization/SingleItemMiddleware.js +10 -7
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModule.js +4 -2
- package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
- package/lib/sharing/utils.js +2 -2
- package/lib/stats/DefaultStatsFactoryPlugin.js +81 -79
- package/lib/stats/DefaultStatsPresetPlugin.js +43 -23
- package/lib/stats/DefaultStatsPrinterPlugin.js +85 -43
- package/lib/stats/StatsFactory.js +11 -11
- package/lib/stats/StatsPrinter.js +7 -7
- package/lib/util/ArrayHelpers.js +2 -4
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +4 -4
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +41 -23
- package/lib/util/LazySet.js +3 -2
- package/lib/util/MapHelpers.js +1 -1
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/Semaphore.js +3 -3
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/SortableSet.js +9 -7
- package/lib/util/TupleQueue.js +9 -8
- package/lib/util/TupleSet.js +2 -2
- package/lib/util/WeakTupleMap.js +12 -11
- package/lib/util/binarySearchBounds.js +2 -1
- package/lib/util/cleverMerge.js +84 -54
- package/lib/util/comparators.js +22 -21
- package/lib/util/compileBooleanMatcher.js +3 -3
- package/lib/util/concatenate.js +6 -4
- package/lib/util/create-schema-validation.js +4 -4
- package/lib/util/createHash.js +2 -2
- package/lib/util/deprecation.js +35 -33
- package/lib/util/deterministicGrouping.js +6 -6
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +39 -39
- package/lib/util/hash/wasm-hash.js +2 -2
- package/lib/util/identifier.js +15 -18
- package/lib/util/makeSerializable.js +1 -1
- package/lib/util/memoize.js +4 -1
- package/lib/util/objectToMap.js +3 -2
- package/lib/util/processAsyncTree.js +2 -2
- package/lib/util/propertyName.js +0 -1
- package/lib/util/registerExternalSerializer.js +15 -18
- package/lib/util/removeBOM.js +25 -0
- package/lib/util/runtime.js +34 -27
- package/lib/util/semver.js +18 -8
- package/lib/util/serialization.js +5 -16
- package/lib/util/smartGrouping.js +3 -3
- package/lib/validateSchema.js +4 -7
- package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +11 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -0
- package/lib/wasm-sync/WebAssemblyGenerator.js +28 -12
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +10 -0
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
- package/lib/wasm-sync/WebAssemblyParser.js +9 -4
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -2
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -25
- package/package.json +27 -26
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +48 -13
- package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +7 -0
- package/schemas/plugins/JsonModulesPluginGenerator.check.js +6 -0
- package/schemas/plugins/JsonModulesPluginGenerator.json +11 -0
- package/schemas/plugins/JsonModulesPluginParser.check.js +1 -1
- package/schemas/plugins/JsonModulesPluginParser.json +4 -0
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/types.d.ts +888 -583
- package/lib/library/ModernModuleLibraryPlugin.js +0 -144
@@ -6,6 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
const NormalModule = require("./NormalModule");
|
9
|
+
const { DEFAULTS } = require("./config/defaults");
|
9
10
|
const createHash = require("./util/createHash");
|
10
11
|
const memoize = require("./util/memoize");
|
11
12
|
|
@@ -15,7 +16,7 @@ const memoize = require("./util/memoize");
|
|
15
16
|
/** @typedef {typeof import("./util/Hash")} Hash */
|
16
17
|
|
17
18
|
/** @typedef {string | RegExp | (string | RegExp)[]} Matcher */
|
18
|
-
/** @typedef {{test?: Matcher, include?: Matcher, exclude?: Matcher }} MatchObject */
|
19
|
+
/** @typedef {{ test?: Matcher, include?: Matcher, exclude?: Matcher }} MatchObject */
|
19
20
|
|
20
21
|
const ModuleFilenameHelpers = module.exports;
|
21
22
|
|
@@ -79,7 +80,7 @@ const getBefore = (strFn, token) => () => {
|
|
79
80
|
* @returns {ReturnStringCallback} a function that returns the hash of the string
|
80
81
|
*/
|
81
82
|
const getHash =
|
82
|
-
(strFn, hashFunction =
|
83
|
+
(strFn, hashFunction = DEFAULTS.HASH_FUNCTION) =>
|
83
84
|
() => {
|
84
85
|
const hash = createHash(hashFunction);
|
85
86
|
hash.update(strFn());
|
@@ -87,37 +88,15 @@ const getHash =
|
|
87
88
|
return digest.slice(0, 4);
|
88
89
|
};
|
89
90
|
|
90
|
-
/**
|
91
|
-
* Returns a function that returns the string with the token replaced with the replacement
|
92
|
-
* @param {string|RegExp} test A regular expression string or Regular Expression object
|
93
|
-
* @returns {RegExp} A regular expression object
|
94
|
-
* @example
|
95
|
-
* ```js
|
96
|
-
* const test = asRegExp("test");
|
97
|
-
* test.test("test"); // true
|
98
|
-
*
|
99
|
-
* const test2 = asRegExp(/test/);
|
100
|
-
* test2.test("test"); // true
|
101
|
-
* ```
|
102
|
-
*/
|
103
|
-
const asRegExp = test => {
|
104
|
-
if (typeof test === "string") {
|
105
|
-
// Escape special characters in the string to prevent them from being interpreted as special characters in a regular expression. Do this by
|
106
|
-
// adding a backslash before each special character
|
107
|
-
test = new RegExp(`^${test.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")}`);
|
108
|
-
}
|
109
|
-
return test;
|
110
|
-
};
|
111
|
-
|
112
91
|
/**
|
113
92
|
* @template T
|
114
93
|
* Returns a lazy object. The object is lazy in the sense that the properties are
|
115
94
|
* only evaluated when they are accessed. This is only obtained by setting a function as the value for each key.
|
116
95
|
* @param {Record<string, () => T>} obj the object to convert to a lazy access object
|
117
|
-
* @returns {
|
96
|
+
* @returns {T} the lazy access object
|
118
97
|
*/
|
119
98
|
const lazyObject = obj => {
|
120
|
-
const newObj = {};
|
99
|
+
const newObj = /** @type {T} */ ({});
|
121
100
|
for (const key of Object.keys(obj)) {
|
122
101
|
const fn = obj[key];
|
123
102
|
Object.defineProperty(newObj, key, {
|
@@ -140,18 +119,15 @@ const SQUARE_BRACKET_TAG_REGEXP = /\[\\*([\w-]+)\\*\]/gi;
|
|
140
119
|
|
141
120
|
/**
|
142
121
|
* @param {Module | string} module the module
|
143
|
-
* @param {TODO} options options
|
144
|
-
* @param {
|
145
|
-
* @param {RequestShortener} contextInfo.requestShortener requestShortener
|
146
|
-
* @param {ChunkGraph} contextInfo.chunkGraph chunk graph
|
147
|
-
* @param {string | Hash=} contextInfo.hashFunction the hash function to use
|
122
|
+
* @param {{ namespace?: string, moduleFilenameTemplate?: string | TODO }} options options
|
123
|
+
* @param {{ requestShortener: RequestShortener, chunkGraph: ChunkGraph, hashFunction?: string | Hash }} contextInfo context info
|
148
124
|
* @returns {string} the filename
|
149
125
|
*/
|
150
126
|
ModuleFilenameHelpers.createFilename = (
|
151
127
|
// eslint-disable-next-line default-param-last
|
152
128
|
module = "",
|
153
129
|
options,
|
154
|
-
{ requestShortener, chunkGraph, hashFunction =
|
130
|
+
{ requestShortener, chunkGraph, hashFunction = DEFAULTS.HASH_FUNCTION }
|
155
131
|
) => {
|
156
132
|
const opts = {
|
157
133
|
namespace: "",
|
@@ -163,6 +139,7 @@ ModuleFilenameHelpers.createFilename = (
|
|
163
139
|
})
|
164
140
|
};
|
165
141
|
|
142
|
+
/** @type {ReturnStringCallback} */
|
166
143
|
let absoluteResourcePath;
|
167
144
|
let hash;
|
168
145
|
/** @type {ReturnStringCallback} */
|
@@ -177,7 +154,8 @@ ModuleFilenameHelpers.createFilename = (
|
|
177
154
|
(memoize(() => requestShortener.shorten(module)));
|
178
155
|
identifier = shortIdentifier;
|
179
156
|
moduleId = () => "";
|
180
|
-
absoluteResourcePath = () =>
|
157
|
+
absoluteResourcePath = () =>
|
158
|
+
/** @type {string} */ (module.split("!").pop());
|
181
159
|
hash = getHash(identifier, hashFunction);
|
182
160
|
} else {
|
183
161
|
shortIdentifier = memoize(() =>
|
@@ -192,7 +170,7 @@ ModuleFilenameHelpers.createFilename = (
|
|
192
170
|
absoluteResourcePath = () =>
|
193
171
|
module instanceof NormalModule
|
194
172
|
? module.resource
|
195
|
-
: module.identifier().split("!").pop();
|
173
|
+
: /** @type {string} */ (module.identifier().split("!").pop());
|
196
174
|
hash = getHash(identifier, hashFunction);
|
197
175
|
}
|
198
176
|
const resource =
|
@@ -225,7 +203,7 @@ ModuleFilenameHelpers.createFilename = (
|
|
225
203
|
}
|
226
204
|
|
227
205
|
// TODO webpack 6: consider removing alternatives without dashes
|
228
|
-
/** @type {Map<string,
|
206
|
+
/** @type {Map<string, () => string>} */
|
229
207
|
const replacements = new Map([
|
230
208
|
["identifier", identifier],
|
231
209
|
["short-identifier", shortIdentifier],
|
@@ -335,15 +313,19 @@ ModuleFilenameHelpers.replaceDuplicates = (array, fn, comparator) => {
|
|
335
313
|
* ModuleFilenameHelpers.matchPart("foo.js", [/^baz/, /^bar/]); // false
|
336
314
|
* ```
|
337
315
|
*/
|
338
|
-
|
316
|
+
const matchPart = (str, test) => {
|
339
317
|
if (!test) return true;
|
340
|
-
|
341
318
|
if (Array.isArray(test)) {
|
342
|
-
return test.
|
319
|
+
return test.some(test => matchPart(str, test));
|
320
|
+
}
|
321
|
+
if (typeof test === "string") {
|
322
|
+
return str.startsWith(test);
|
343
323
|
}
|
344
|
-
return
|
324
|
+
return test.test(str);
|
345
325
|
};
|
346
326
|
|
327
|
+
ModuleFilenameHelpers.matchPart = matchPart;
|
328
|
+
|
347
329
|
/**
|
348
330
|
* Tests if a string matches a match object. The match object can have the following properties:
|
349
331
|
* - `test`: a RegExp or an array of RegExp
|
package/lib/ModuleGraph.js
CHANGED
@@ -11,6 +11,7 @@ const ModuleGraphConnection = require("./ModuleGraphConnection");
|
|
11
11
|
const SortableSet = require("./util/SortableSet");
|
12
12
|
const WeakTupleMap = require("./util/WeakTupleMap");
|
13
13
|
|
14
|
+
/** @typedef {import("./Compilation").ModuleMemCaches} ModuleMemCaches */
|
14
15
|
/** @typedef {import("./DependenciesBlock")} DependenciesBlock */
|
15
16
|
/** @typedef {import("./Dependency")} Dependency */
|
16
17
|
/** @typedef {import("./ExportsInfo").ExportInfo} ExportInfo */
|
@@ -119,6 +120,11 @@ class ModuleGraphModule {
|
|
119
120
|
}
|
120
121
|
}
|
121
122
|
|
123
|
+
/** @typedef {(moduleGraphConnection: ModuleGraphConnection) => boolean} FilterConnection */
|
124
|
+
|
125
|
+
/** @typedef {EXPECTED_OBJECT} MetaKey */
|
126
|
+
/** @typedef {TODO} Meta */
|
127
|
+
|
122
128
|
class ModuleGraph {
|
123
129
|
constructor() {
|
124
130
|
/**
|
@@ -132,7 +138,7 @@ class ModuleGraph {
|
|
132
138
|
*/
|
133
139
|
this._moduleMap = new Map();
|
134
140
|
/**
|
135
|
-
* @type {WeakMap<
|
141
|
+
* @type {WeakMap<MetaKey, Meta>}
|
136
142
|
* @private
|
137
143
|
*/
|
138
144
|
this._metaMap = new WeakMap();
|
@@ -142,7 +148,7 @@ class ModuleGraph {
|
|
142
148
|
*/
|
143
149
|
this._cache = undefined;
|
144
150
|
/**
|
145
|
-
* @type {
|
151
|
+
* @type {ModuleMemCaches | undefined}
|
146
152
|
* @private
|
147
153
|
*/
|
148
154
|
this._moduleMemCaches = undefined;
|
@@ -331,7 +337,7 @@ class ModuleGraph {
|
|
331
337
|
/**
|
332
338
|
* @param {Module} oldModule the old referencing module
|
333
339
|
* @param {Module} newModule the new referencing module
|
334
|
-
* @param {
|
340
|
+
* @param {FilterConnection} filterConnection filter predicate for replacement
|
335
341
|
* @returns {void}
|
336
342
|
*/
|
337
343
|
moveModuleConnections(oldModule, newModule, filterConnection) {
|
@@ -368,7 +374,7 @@ class ModuleGraph {
|
|
368
374
|
/**
|
369
375
|
* @param {Module} oldModule the old referencing module
|
370
376
|
* @param {Module} newModule the new referencing module
|
371
|
-
* @param {
|
377
|
+
* @param {FilterConnection} filterConnection filter predicate for replacement
|
372
378
|
* @returns {void}
|
373
379
|
*/
|
374
380
|
copyOutgoingModuleConnections(oldModule, newModule, filterConnection) {
|
@@ -756,21 +762,21 @@ class ModuleGraph {
|
|
756
762
|
}
|
757
763
|
|
758
764
|
/**
|
759
|
-
* @param {
|
760
|
-
* @returns {
|
765
|
+
* @param {MetaKey} thing any thing
|
766
|
+
* @returns {Meta} metadata
|
761
767
|
*/
|
762
768
|
getMeta(thing) {
|
763
769
|
let meta = this._metaMap.get(thing);
|
764
770
|
if (meta === undefined) {
|
765
771
|
meta = Object.create(null);
|
766
|
-
this._metaMap.set(thing,
|
772
|
+
this._metaMap.set(thing, meta);
|
767
773
|
}
|
768
|
-
return
|
774
|
+
return meta;
|
769
775
|
}
|
770
776
|
|
771
777
|
/**
|
772
|
-
* @param {
|
773
|
-
* @returns {
|
778
|
+
* @param {MetaKey} thing any thing
|
779
|
+
* @returns {Meta | undefined} metadata
|
774
780
|
*/
|
775
781
|
getMetaIfExisting(thing) {
|
776
782
|
return this._metaMap.get(thing);
|
@@ -790,10 +796,10 @@ class ModuleGraph {
|
|
790
796
|
}
|
791
797
|
|
792
798
|
/**
|
793
|
-
* @template
|
799
|
+
* @template T
|
794
800
|
* @template V
|
795
|
-
* @param {(moduleGraph: ModuleGraph, ...args: T) => V} fn computer
|
796
|
-
* @param {T} args arguments
|
801
|
+
* @param {(moduleGraph: ModuleGraph, ...args: T[]) => V} fn computer
|
802
|
+
* @param {...T} args arguments
|
797
803
|
* @returns {V} computed value or cached
|
798
804
|
*/
|
799
805
|
cached(fn, ...args) {
|
@@ -802,7 +808,7 @@ class ModuleGraph {
|
|
802
808
|
}
|
803
809
|
|
804
810
|
/**
|
805
|
-
* @param {
|
811
|
+
* @param {ModuleMemCaches} moduleMemCaches mem caches for modules for better caching
|
806
812
|
*/
|
807
813
|
setModuleMemCaches(moduleMemCaches) {
|
808
814
|
this._moduleMemCaches = moduleMemCaches;
|
@@ -75,7 +75,6 @@ class ModuleGraphConnection {
|
|
75
75
|
this.weak = weak;
|
76
76
|
this.conditional = Boolean(condition);
|
77
77
|
this._active = condition !== false;
|
78
|
-
/** @type {(function(ModuleGraphConnection, RuntimeSpec): ConnectionState) | undefined} */
|
79
78
|
this.condition = condition || undefined;
|
80
79
|
/** @type {Set<string> | undefined} */
|
81
80
|
this.explanations = undefined;
|
@@ -103,15 +102,16 @@ class ModuleGraphConnection {
|
|
103
102
|
}
|
104
103
|
|
105
104
|
/**
|
106
|
-
* @param {
|
105
|
+
* @param {GetConditionFn} condition condition for the connection
|
107
106
|
* @returns {void}
|
108
107
|
*/
|
109
108
|
addCondition(condition) {
|
110
109
|
if (this.conditional) {
|
111
110
|
const old =
|
112
|
-
/** @type {
|
111
|
+
/** @type {GetConditionFn} */
|
113
112
|
(this.condition);
|
114
|
-
|
113
|
+
/** @type {GetConditionFn} */
|
114
|
+
(this.condition) = (c, r) =>
|
115
115
|
intersectConnectionStates(old(c, r), condition(c, r));
|
116
116
|
} else if (this._active) {
|
117
117
|
this.conditional = true;
|
@@ -143,9 +143,7 @@ class ModuleGraphConnection {
|
|
143
143
|
if (!this.conditional) return this._active;
|
144
144
|
|
145
145
|
return (
|
146
|
-
/** @type {(
|
147
|
-
this.condition
|
148
|
-
)(this, runtime) !== false
|
146
|
+
/** @type {GetConditionFn} */ (this.condition)(this, runtime) !== false
|
149
147
|
);
|
150
148
|
}
|
151
149
|
|
@@ -156,9 +154,7 @@ class ModuleGraphConnection {
|
|
156
154
|
isTargetActive(runtime) {
|
157
155
|
if (!this.conditional) return this._active;
|
158
156
|
return (
|
159
|
-
/** @type {(
|
160
|
-
this.condition
|
161
|
-
)(this, runtime) === true
|
157
|
+
/** @type {GetConditionFn} */ (this.condition)(this, runtime) === true
|
162
158
|
);
|
163
159
|
}
|
164
160
|
|
@@ -168,9 +164,7 @@ class ModuleGraphConnection {
|
|
168
164
|
*/
|
169
165
|
getActiveState(runtime) {
|
170
166
|
if (!this.conditional) return this._active;
|
171
|
-
return /** @type {(
|
172
|
-
this.condition
|
173
|
-
)(this, runtime);
|
167
|
+
return /** @type {GetConditionFn} */ (this.condition)(this, runtime);
|
174
168
|
}
|
175
169
|
|
176
170
|
/**
|
@@ -44,7 +44,7 @@ const previouslyPolyfilledBuiltinModules = {
|
|
44
44
|
class ModuleNotFoundError extends WebpackError {
|
45
45
|
/**
|
46
46
|
* @param {Module | null} module module tied to dependency
|
47
|
-
* @param {Error&
|
47
|
+
* @param {Error & { details?: string }} err error thrown
|
48
48
|
* @param {DependencyLocation} loc location of dependency
|
49
49
|
*/
|
50
50
|
constructor(module, err, loc) {
|
package/lib/ModuleParseError.js
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
const WebpackError = require("./WebpackError");
|
9
9
|
const makeSerializable = require("./util/makeSerializable");
|
10
10
|
|
11
|
+
/** @typedef {import("./Dependency").SourcePosition} SourcePosition */
|
11
12
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
12
13
|
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
13
14
|
|
@@ -16,7 +17,7 @@ const WASM_HEADER = Buffer.from([0x00, 0x61, 0x73, 0x6d]);
|
|
16
17
|
class ModuleParseError extends WebpackError {
|
17
18
|
/**
|
18
19
|
* @param {string | Buffer} source source code
|
19
|
-
* @param {Error &
|
20
|
+
* @param {Error & { loc?: SourcePosition }} err the parse error
|
20
21
|
* @param {string[]} loaders the loaders used
|
21
22
|
* @param {string} type module type
|
22
23
|
*/
|
@@ -34,6 +34,11 @@ const ASSET_AND_JS_AND_CSS_URL_TYPES = new Set([
|
|
34
34
|
"css-url"
|
35
35
|
]);
|
36
36
|
|
37
|
+
/**
|
38
|
+
* @type {"javascript"}
|
39
|
+
*/
|
40
|
+
const JS_TYPE = "javascript";
|
41
|
+
|
37
42
|
/**
|
38
43
|
* @type {ReadonlySet<"javascript">}
|
39
44
|
*/
|
@@ -54,6 +59,10 @@ const JS_AND_CSS_URL_TYPES = new Set(["javascript", "css-url"]);
|
|
54
59
|
*/
|
55
60
|
const JS_AND_CSS_TYPES = new Set(["javascript", "css"]);
|
56
61
|
|
62
|
+
/**
|
63
|
+
* @type {"css"}
|
64
|
+
*/
|
65
|
+
const CSS_TYPE = "css";
|
57
66
|
/**
|
58
67
|
* @type {ReadonlySet<"css">}
|
59
68
|
*/
|
@@ -94,6 +103,7 @@ const CONSUME_SHARED_TYPES = new Set(["consume-shared"]);
|
|
94
103
|
const SHARED_INIT_TYPES = new Set(["share-init"]);
|
95
104
|
|
96
105
|
module.exports.NO_TYPES = NO_TYPES;
|
106
|
+
module.exports.JS_TYPE = JS_TYPE;
|
97
107
|
module.exports.JS_TYPES = JS_TYPES;
|
98
108
|
module.exports.JS_AND_CSS_TYPES = JS_AND_CSS_TYPES;
|
99
109
|
module.exports.JS_AND_CSS_URL_TYPES = JS_AND_CSS_URL_TYPES;
|
@@ -102,6 +112,7 @@ module.exports.ASSET_TYPES = ASSET_TYPES;
|
|
102
112
|
module.exports.ASSET_AND_JS_TYPES = ASSET_AND_JS_TYPES;
|
103
113
|
module.exports.ASSET_AND_CSS_URL_TYPES = ASSET_AND_CSS_URL_TYPES;
|
104
114
|
module.exports.ASSET_AND_JS_AND_CSS_URL_TYPES = ASSET_AND_JS_AND_CSS_URL_TYPES;
|
115
|
+
module.exports.CSS_TYPE = CSS_TYPE;
|
105
116
|
module.exports.CSS_TYPES = CSS_TYPES;
|
106
117
|
module.exports.CSS_URL_TYPES = CSS_URL_TYPES;
|
107
118
|
module.exports.CSS_IMPORT_TYPES = CSS_IMPORT_TYPES;
|
package/lib/ModuleTemplate.js
CHANGED
@@ -44,7 +44,7 @@ class ModuleTemplate {
|
|
44
44
|
/**
|
45
45
|
* @template AdditionalOptions
|
46
46
|
* @param {string | Tap & IfSet<AdditionalOptions>} options options
|
47
|
-
* @param {
|
47
|
+
* @param {(source: Source, module: Module, chunkRenderContext: ChunkRenderContext, dependencyTemplates: DependencyTemplates) => Source} fn fn
|
48
48
|
*/
|
49
49
|
(options, fn) => {
|
50
50
|
getJavascriptModulesPlugin()
|
@@ -69,7 +69,7 @@ class ModuleTemplate {
|
|
69
69
|
/**
|
70
70
|
* @template AdditionalOptions
|
71
71
|
* @param {string | Tap & IfSet<AdditionalOptions>} options options
|
72
|
-
* @param {
|
72
|
+
* @param {(source: Source, module: Module, chunkRenderContext: ChunkRenderContext, dependencyTemplates: DependencyTemplates) => Source} fn fn
|
73
73
|
*/
|
74
74
|
(options, fn) => {
|
75
75
|
getJavascriptModulesPlugin()
|
@@ -94,7 +94,7 @@ class ModuleTemplate {
|
|
94
94
|
/**
|
95
95
|
* @template AdditionalOptions
|
96
96
|
* @param {string | Tap & IfSet<AdditionalOptions>} options options
|
97
|
-
* @param {
|
97
|
+
* @param {(source: Source, module: Module, chunkRenderContext: ChunkRenderContext, dependencyTemplates: DependencyTemplates) => Source} fn fn
|
98
98
|
*/
|
99
99
|
(options, fn) => {
|
100
100
|
getJavascriptModulesPlugin()
|
@@ -119,7 +119,7 @@ class ModuleTemplate {
|
|
119
119
|
/**
|
120
120
|
* @template AdditionalOptions
|
121
121
|
* @param {string | Tap & IfSet<AdditionalOptions>} options options
|
122
|
-
* @param {
|
122
|
+
* @param {(source: Source, module: Module, chunkRenderContext: ChunkRenderContext, dependencyTemplates: DependencyTemplates) => Source} fn fn
|
123
123
|
*/
|
124
124
|
(options, fn) => {
|
125
125
|
getJavascriptModulesPlugin()
|
@@ -144,7 +144,7 @@ class ModuleTemplate {
|
|
144
144
|
/**
|
145
145
|
* @template AdditionalOptions
|
146
146
|
* @param {string | Tap & IfSet<AdditionalOptions>} options options
|
147
|
-
* @param {
|
147
|
+
* @param {(hash: Hash) => void} fn fn
|
148
148
|
*/
|
149
149
|
(options, fn) => {
|
150
150
|
compilation.hooks.fullHash.tap(options, fn);
|
@@ -151,13 +151,28 @@ module.exports.ASSET_MODULE_TYPE_INLINE = ASSET_MODULE_TYPE_INLINE;
|
|
151
151
|
module.exports.JAVASCRIPT_MODULE_TYPE_AUTO = JAVASCRIPT_MODULE_TYPE_AUTO;
|
152
152
|
module.exports.JAVASCRIPT_MODULE_TYPE_DYNAMIC = JAVASCRIPT_MODULE_TYPE_DYNAMIC;
|
153
153
|
module.exports.JAVASCRIPT_MODULE_TYPE_ESM = JAVASCRIPT_MODULE_TYPE_ESM;
|
154
|
+
module.exports.JAVASCRIPT_MODULES = [
|
155
|
+
JAVASCRIPT_MODULE_TYPE_AUTO,
|
156
|
+
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
157
|
+
JAVASCRIPT_MODULE_TYPE_ESM
|
158
|
+
];
|
154
159
|
module.exports.JSON_MODULE_TYPE = JSON_MODULE_TYPE;
|
155
160
|
module.exports.WEBASSEMBLY_MODULE_TYPE_ASYNC = WEBASSEMBLY_MODULE_TYPE_ASYNC;
|
156
161
|
module.exports.WEBASSEMBLY_MODULE_TYPE_SYNC = WEBASSEMBLY_MODULE_TYPE_SYNC;
|
162
|
+
module.exports.WEBASSEMBLY_MODULES = [
|
163
|
+
WEBASSEMBLY_MODULE_TYPE_SYNC,
|
164
|
+
WEBASSEMBLY_MODULE_TYPE_SYNC
|
165
|
+
];
|
157
166
|
module.exports.CSS_MODULE_TYPE = CSS_MODULE_TYPE;
|
158
167
|
module.exports.CSS_MODULE_TYPE_GLOBAL = CSS_MODULE_TYPE_GLOBAL;
|
159
168
|
module.exports.CSS_MODULE_TYPE_MODULE = CSS_MODULE_TYPE_MODULE;
|
160
169
|
module.exports.CSS_MODULE_TYPE_AUTO = CSS_MODULE_TYPE_AUTO;
|
170
|
+
module.exports.CSS_MODULES = [
|
171
|
+
CSS_MODULE_TYPE,
|
172
|
+
CSS_MODULE_TYPE_GLOBAL,
|
173
|
+
CSS_MODULE_TYPE_MODULE,
|
174
|
+
CSS_MODULE_TYPE_AUTO
|
175
|
+
];
|
161
176
|
module.exports.WEBPACK_MODULE_TYPE_RUNTIME = WEBPACK_MODULE_TYPE_RUNTIME;
|
162
177
|
module.exports.WEBPACK_MODULE_TYPE_FALLBACK = WEBPACK_MODULE_TYPE_FALLBACK;
|
163
178
|
module.exports.WEBPACK_MODULE_TYPE_REMOTE = WEBPACK_MODULE_TYPE_REMOTE;
|
package/lib/MultiCompiler.js
CHANGED
@@ -70,7 +70,7 @@ module.exports = class MultiCompiler {
|
|
70
70
|
watchClose: new SyncHook([]),
|
71
71
|
/** @type {MultiHook<AsyncSeriesHook<[Compiler]>>} */
|
72
72
|
watchRun: new MultiHook(compilers.map(c => c.hooks.watchRun)),
|
73
|
-
/** @type {MultiHook<SyncBailHook<[string, string,
|
73
|
+
/** @type {MultiHook<SyncBailHook<[string, string, EXPECTED_ANY[] | undefined], true | void>>} */
|
74
74
|
infrastructureLog: new MultiHook(
|
75
75
|
compilers.map(c => c.hooks.infrastructureLog)
|
76
76
|
)
|
@@ -223,7 +223,7 @@ module.exports = class MultiCompiler {
|
|
223
223
|
}
|
224
224
|
|
225
225
|
/**
|
226
|
-
* @param {string | (
|
226
|
+
* @param {string | (() => string)} name name of the logger, or function called once to get the logger name
|
227
227
|
* @returns {Logger} a logger with that name
|
228
228
|
*/
|
229
229
|
getInfrastructureLogger(name) {
|
@@ -377,8 +377,8 @@ module.exports = class MultiCompiler {
|
|
377
377
|
|
378
378
|
/**
|
379
379
|
* @template SetupResult
|
380
|
-
* @param {
|
381
|
-
* @param {
|
380
|
+
* @param {(compiler: Compiler, index: number, doneCallback: Callback<Stats>, isBlocked: () => boolean, setChanged: () => void, setInvalid: () => void) => SetupResult} setup setup a single compiler
|
381
|
+
* @param {(compiler: Compiler, setupResult: SetupResult, callback: Callback<Stats>) => void} run run/continue a single compiler
|
382
382
|
* @param {Callback<MultiStats>} callback callback when all compilers are done, result includes Stats of all changed compilers
|
383
383
|
* @returns {SetupResult[]} result of setup
|
384
384
|
*/
|
package/lib/MultiStats.js
CHANGED