webpack 5.90.3 → 5.91.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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +5 -5
- package/bin/webpack.js +5 -1
- package/lib/APIPlugin.js +8 -4
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +3 -1
- package/lib/Cache.js +7 -1
- package/lib/CacheFacade.js +3 -3
- package/lib/ChunkGraph.js +32 -18
- package/lib/ChunkGroup.js +14 -14
- package/lib/CleanPlugin.js +7 -5
- package/lib/Compilation.js +262 -93
- package/lib/Compiler.js +199 -83
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +2 -0
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/DefinePlugin.js +4 -2
- package/lib/Dependency.js +4 -2
- package/lib/DependencyTemplate.js +7 -2
- package/lib/DllModule.js +1 -0
- package/lib/DllReferencePlugin.js +6 -2
- package/lib/EntryOptionPlugin.js +4 -1
- package/lib/EntryPlugin.js +6 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ExportsInfo.js +1 -4
- package/lib/ExternalModule.js +118 -24
- package/lib/ExternalModuleFactoryPlugin.js +37 -2
- package/lib/FileSystemInfo.js +1 -1
- package/lib/Generator.js +2 -1
- package/lib/HookWebpackError.js +2 -2
- package/lib/InitFragment.js +5 -3
- package/lib/LibManifestPlugin.js +15 -7
- package/lib/Module.js +30 -2
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +56 -27
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +26 -8
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +3 -1
- package/lib/NormalModuleFactory.js +1 -1
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +2 -1
- package/lib/ResolverFactory.js +3 -1
- package/lib/RuntimeModule.js +4 -4
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +102 -34
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +10 -3
- package/lib/TemplatedPathPlugin.js +32 -6
- package/lib/Watching.js +67 -60
- package/lib/WebpackError.js +6 -6
- package/lib/WebpackOptionsApply.js +18 -5
- package/lib/asset/RawDataUrlModule.js +3 -1
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +117 -64
- package/lib/cache/IdleFileCachePlugin.js +8 -3
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
- package/lib/cache/PackFileCacheStrategy.js +49 -16
- package/lib/cache/ResolverCachePlugin.js +14 -6
- package/lib/cache/getLazyHashedEtag.js +1 -1
- package/lib/config/defaults.js +24 -1
- package/lib/config/normalization.js +3 -1
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +3 -1
- package/lib/container/ContainerPlugin.js +14 -10
- package/lib/container/FallbackModule.js +1 -1
- package/lib/container/RemoteRuntimeModule.js +12 -3
- package/lib/css/CssExportsGenerator.js +34 -17
- package/lib/css/CssGenerator.js +20 -2
- package/lib/css/CssLoadingRuntimeModule.js +212 -96
- package/lib/css/CssModulesPlugin.js +47 -13
- package/lib/debug/ProfilingPlugin.js +27 -2
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
- package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
- package/lib/dependencies/CommonJsExportsDependency.js +13 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
- package/lib/dependencies/ContextDependencyHelpers.js +49 -29
- package/lib/dependencies/ContextElementDependency.js +8 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +63 -8
- package/lib/dependencies/CssUrlDependency.js +5 -3
- package/lib/dependencies/ExportsInfoDependency.js +4 -3
- package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
- package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
- package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
- package/lib/dependencies/HarmonyImportDependency.js +28 -12
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +44 -16
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +6 -5
- package/lib/dependencies/ImportDependency.js +9 -2
- package/lib/dependencies/ImportEagerDependency.js +4 -2
- package/lib/dependencies/ImportMetaContextDependency.js +7 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
- package/lib/dependencies/ImportParserPlugin.js +12 -4
- package/lib/dependencies/ImportWeakDependency.js +4 -2
- package/lib/dependencies/LoaderDependency.js +2 -1
- package/lib/dependencies/LoaderImportDependency.js +2 -1
- package/lib/dependencies/ModuleDependency.js +4 -5
- package/lib/dependencies/PureExpressionDependency.js +4 -1
- package/lib/dependencies/RequireContextPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
- package/lib/dependencies/RequireEnsureDependency.js +1 -1
- package/lib/dependencies/URLDependency.js +7 -4
- package/lib/dependencies/WorkerPlugin.js +2 -1
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/JavascriptParser.js +169 -57
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/StartupHelpers.js +22 -5
- package/lib/logging/Logger.js +27 -2
- package/lib/logging/createConsoleLogger.js +11 -7
- package/lib/node/NodeEnvironmentPlugin.js +13 -7
- package/lib/node/NodeWatchFileSystem.js +37 -26
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
- package/lib/node/nodeConsole.js +24 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
- package/lib/optimize/ConcatenatedModule.js +138 -54
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/InnerGraph.js +7 -2
- package/lib/optimize/InnerGraphPlugin.js +36 -13
- package/lib/optimize/ModuleConcatenationPlugin.js +12 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/RuntimeChunkPlugin.js +6 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +46 -15
- package/lib/optimize/SplitChunksPlugin.js +2 -2
- package/lib/performance/SizeLimitsPlugin.js +11 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +4 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/serialization/FileMiddleware.js +1 -0
- package/lib/serialization/ObjectMiddleware.js +2 -0
- package/lib/serialization/Serializer.js +19 -0
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedPlugin.js +12 -5
- package/lib/sharing/resolveMatchedConfigs.js +2 -2
- package/lib/sharing/utils.js +13 -6
- package/lib/util/StackedCacheMap.js +26 -0
- package/lib/util/WeakTupleMap.js +57 -13
- package/lib/util/cleverMerge.js +24 -11
- package/lib/util/comparators.js +34 -14
- package/lib/util/conventions.js +129 -0
- package/lib/util/fs.js +379 -65
- package/lib/util/hash/BatchedHash.js +3 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/runtime.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +15 -6
- package/lib/wasm-sync/WebAssemblyGenerator.js +27 -6
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
- package/lib/webpack.js +7 -3
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
- package/package.json +25 -26
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +69 -8
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +5 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/types.d.ts +1668 -613
package/lib/HookWebpackError.js
CHANGED
@@ -12,7 +12,7 @@ const WebpackError = require("./WebpackError");
|
|
12
12
|
/**
|
13
13
|
* @template T
|
14
14
|
* @callback Callback
|
15
|
-
* @param {Error
|
15
|
+
* @param {Error | null} err
|
16
16
|
* @param {T=} stats
|
17
17
|
* @returns {void}
|
18
18
|
*/
|
@@ -51,7 +51,7 @@ module.exports.makeWebpackError = makeWebpackError;
|
|
51
51
|
|
52
52
|
/**
|
53
53
|
* @template T
|
54
|
-
* @param {function(
|
54
|
+
* @param {function(WebpackError | null, T=): void} callback webpack error callback
|
55
55
|
* @param {string} hook name of hook
|
56
56
|
* @returns {Callback<T>} generic callback
|
57
57
|
*/
|
package/lib/InitFragment.js
CHANGED
@@ -40,7 +40,7 @@ const sortFragmentWithIndex = ([a, i], [b, j]) => {
|
|
40
40
|
*/
|
41
41
|
class InitFragment {
|
42
42
|
/**
|
43
|
-
* @param {string | Source} content the source code that will be included as initialization code
|
43
|
+
* @param {string | Source | undefined} content the source code that will be included as initialization code
|
44
44
|
* @param {number} stage category of initialization code (contribute to order)
|
45
45
|
* @param {number} position position in the category (contribute to order)
|
46
46
|
* @param {string=} key unique key to avoid emitting the same initialization code twice
|
@@ -56,7 +56,7 @@ class InitFragment {
|
|
56
56
|
|
57
57
|
/**
|
58
58
|
* @param {GenerateContext} context context
|
59
|
-
* @returns {string | Source} the source code that will be included as initialization code
|
59
|
+
* @returns {string | Source | undefined} the source code that will be included as initialization code
|
60
60
|
*/
|
61
61
|
getContent(context) {
|
62
62
|
return this.content;
|
@@ -171,7 +171,9 @@ class InitFragment {
|
|
171
171
|
|
172
172
|
makeSerializable(InitFragment, "webpack/lib/InitFragment");
|
173
173
|
|
174
|
-
InitFragment.prototype.merge =
|
174
|
+
InitFragment.prototype.merge =
|
175
|
+
/** @type {TODO} */
|
176
|
+
(undefined);
|
175
177
|
|
176
178
|
InitFragment.STAGE_CONSTANTS = 10;
|
177
179
|
InitFragment.STAGE_ASYNC_BOUNDARY = 20;
|
package/lib/LibManifestPlugin.js
CHANGED
@@ -12,6 +12,7 @@ const { compareModulesById } = require("./util/comparators");
|
|
12
12
|
const { dirname, mkdirp } = require("./util/fs");
|
13
13
|
|
14
14
|
/** @typedef {import("./Compiler")} Compiler */
|
15
|
+
/** @typedef {import("./Compiler").IntermediateFileSystem} IntermediateFileSystem */
|
15
16
|
/** @typedef {import("./Module").BuildMeta} BuildMeta */
|
16
17
|
|
17
18
|
/**
|
@@ -52,6 +53,8 @@ class LibManifestPlugin {
|
|
52
53
|
},
|
53
54
|
(compilation, callback) => {
|
54
55
|
const moduleGraph = compilation.moduleGraph;
|
56
|
+
// store used paths to detect issue and output an error. #18200
|
57
|
+
const usedPaths = new Set();
|
55
58
|
asyncLib.forEach(
|
56
59
|
Array.from(compilation.chunks),
|
57
60
|
(chunk, callback) => {
|
@@ -63,6 +66,11 @@ class LibManifestPlugin {
|
|
63
66
|
const targetPath = compilation.getPath(this.options.path, {
|
64
67
|
chunk
|
65
68
|
});
|
69
|
+
if (usedPaths.has(targetPath)) {
|
70
|
+
callback(new Error(`each chunk must have a unique path`));
|
71
|
+
return;
|
72
|
+
}
|
73
|
+
usedPaths.add(targetPath);
|
66
74
|
const name =
|
67
75
|
this.options.name &&
|
68
76
|
compilation.getPath(this.options.name, {
|
@@ -113,16 +121,16 @@ class LibManifestPlugin {
|
|
113
121
|
? JSON.stringify(manifest, null, 2)
|
114
122
|
: JSON.stringify(manifest);
|
115
123
|
const buffer = Buffer.from(manifestContent, "utf8");
|
124
|
+
const intermediateFileSystem =
|
125
|
+
/** @type {IntermediateFileSystem} */ (
|
126
|
+
compiler.intermediateFileSystem
|
127
|
+
);
|
116
128
|
mkdirp(
|
117
|
-
|
118
|
-
dirname(
|
129
|
+
intermediateFileSystem,
|
130
|
+
dirname(intermediateFileSystem, targetPath),
|
119
131
|
err => {
|
120
132
|
if (err) return callback(err);
|
121
|
-
|
122
|
-
targetPath,
|
123
|
-
buffer,
|
124
|
-
callback
|
125
|
-
);
|
133
|
+
intermediateFileSystem.writeFile(targetPath, buffer, callback);
|
126
134
|
}
|
127
135
|
);
|
128
136
|
},
|
package/lib/Module.js
CHANGED
@@ -64,7 +64,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
64
64
|
* @property {RuntimeSpec} runtime the runtime code should be generated for
|
65
65
|
* @property {RuntimeSpec[]} [runtimes] the runtimes code should be generated for
|
66
66
|
* @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
|
67
|
-
* @property {CodeGenerationResults} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
|
67
|
+
* @property {CodeGenerationResults | undefined} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
|
68
68
|
* @property {Compilation=} compilation the compilation
|
69
69
|
* @property {ReadonlySet<string>=} sourceTypes source types
|
70
70
|
*/
|
@@ -75,11 +75,14 @@ const makeSerializable = require("./util/makeSerializable");
|
|
75
75
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
76
76
|
*/
|
77
77
|
|
78
|
+
/** @typedef {Set<string>} RuntimeRequirements */
|
79
|
+
/** @typedef {ReadonlySet<string>} ReadOnlyRuntimeRequirements */
|
80
|
+
|
78
81
|
/**
|
79
82
|
* @typedef {Object} CodeGenerationResult
|
80
83
|
* @property {Map<string, Source>} sources the resulting sources for all source types
|
81
84
|
* @property {Map<string, any>=} data the resulting data for all source types
|
82
|
-
* @property {
|
85
|
+
* @property {ReadOnlyRuntimeRequirements} runtimeRequirements the runtime requirements
|
83
86
|
* @property {string=} hash a hash of the code generation result (will be automatically calculated from sources and runtimeRequirements if not provided)
|
84
87
|
*/
|
85
88
|
|
@@ -270,6 +273,9 @@ class Module extends DependenciesBlock {
|
|
270
273
|
).setProfile(this, value);
|
271
274
|
}
|
272
275
|
|
276
|
+
/**
|
277
|
+
* @returns {number | null} the pre order index
|
278
|
+
*/
|
273
279
|
get index() {
|
274
280
|
return ModuleGraph.getModuleGraphForModule(
|
275
281
|
this,
|
@@ -278,6 +284,9 @@ class Module extends DependenciesBlock {
|
|
278
284
|
).getPreOrderIndex(this);
|
279
285
|
}
|
280
286
|
|
287
|
+
/**
|
288
|
+
* @param {number} value the pre order index
|
289
|
+
*/
|
281
290
|
set index(value) {
|
282
291
|
ModuleGraph.getModuleGraphForModule(
|
283
292
|
this,
|
@@ -286,6 +295,9 @@ class Module extends DependenciesBlock {
|
|
286
295
|
).setPreOrderIndex(this, value);
|
287
296
|
}
|
288
297
|
|
298
|
+
/**
|
299
|
+
* @returns {number | null} the post order index
|
300
|
+
*/
|
289
301
|
get index2() {
|
290
302
|
return ModuleGraph.getModuleGraphForModule(
|
291
303
|
this,
|
@@ -294,6 +306,9 @@ class Module extends DependenciesBlock {
|
|
294
306
|
).getPostOrderIndex(this);
|
295
307
|
}
|
296
308
|
|
309
|
+
/**
|
310
|
+
* @param {number} value the post order index
|
311
|
+
*/
|
297
312
|
set index2(value) {
|
298
313
|
ModuleGraph.getModuleGraphForModule(
|
299
314
|
this,
|
@@ -302,6 +317,9 @@ class Module extends DependenciesBlock {
|
|
302
317
|
).setPostOrderIndex(this, value);
|
303
318
|
}
|
304
319
|
|
320
|
+
/**
|
321
|
+
* @returns {number | null} the depth
|
322
|
+
*/
|
305
323
|
get depth() {
|
306
324
|
return ModuleGraph.getModuleGraphForModule(
|
307
325
|
this,
|
@@ -310,6 +328,9 @@ class Module extends DependenciesBlock {
|
|
310
328
|
).getDepth(this);
|
311
329
|
}
|
312
330
|
|
331
|
+
/**
|
332
|
+
* @param {number} value the depth
|
333
|
+
*/
|
313
334
|
set depth(value) {
|
314
335
|
ModuleGraph.getModuleGraphForModule(
|
315
336
|
this,
|
@@ -318,6 +339,9 @@ class Module extends DependenciesBlock {
|
|
318
339
|
).setDepth(this, value);
|
319
340
|
}
|
320
341
|
|
342
|
+
/**
|
343
|
+
* @returns {Module | null | undefined} issuer
|
344
|
+
*/
|
321
345
|
get issuer() {
|
322
346
|
return ModuleGraph.getModuleGraphForModule(
|
323
347
|
this,
|
@@ -326,6 +350,9 @@ class Module extends DependenciesBlock {
|
|
326
350
|
).getIssuer(this);
|
327
351
|
}
|
328
352
|
|
353
|
+
/**
|
354
|
+
* @param {Module | null} value issuer
|
355
|
+
*/
|
329
356
|
set issuer(value) {
|
330
357
|
ModuleGraph.getModuleGraphForModule(
|
331
358
|
this,
|
@@ -872,6 +899,7 @@ class Module extends DependenciesBlock {
|
|
872
899
|
codeGenerationResults: undefined
|
873
900
|
};
|
874
901
|
const sources = this.codeGeneration(codeGenContext).sources;
|
902
|
+
|
875
903
|
return type ? sources.get(type) : sources.get(first(this.getSourceTypes()));
|
876
904
|
}
|
877
905
|
|
@@ -115,7 +115,7 @@ const asRegExp = test => {
|
|
115
115
|
* @template T
|
116
116
|
* Returns a lazy object. The object is lazy in the sense that the properties are
|
117
117
|
* only evaluated when they are accessed. This is only obtained by setting a function as the value for each key.
|
118
|
-
* @param {Record<string, () => T>} obj the object to
|
118
|
+
* @param {Record<string, () => T>} obj the object to convert to a lazy access object
|
119
119
|
* @returns {Object} the lazy access object
|
120
120
|
*/
|
121
121
|
const lazyObject = obj => {
|
package/lib/ModuleGraph.js
CHANGED
@@ -89,13 +89,16 @@ const getConnectionsByModule = set => {
|
|
89
89
|
return map;
|
90
90
|
};
|
91
91
|
|
92
|
+
/** @typedef {SortableSet<ModuleGraphConnection>} IncomingConnections */
|
93
|
+
/** @typedef {SortableSet<ModuleGraphConnection>} OutgoingConnections */
|
94
|
+
|
92
95
|
class ModuleGraphModule {
|
93
96
|
constructor() {
|
94
|
-
/** @type {
|
97
|
+
/** @type {IncomingConnections} */
|
95
98
|
this.incomingConnections = new SortableSet();
|
96
|
-
/** @type {
|
99
|
+
/** @type {OutgoingConnections | undefined} */
|
97
100
|
this.outgoingConnections = undefined;
|
98
|
-
/** @type {Module | null} */
|
101
|
+
/** @type {Module | null | undefined} */
|
99
102
|
this.issuer = undefined;
|
100
103
|
/** @type {(string | OptimizationBailoutFunction)[]} */
|
101
104
|
this.optimizationBailout = [];
|
@@ -107,31 +110,47 @@ class ModuleGraphModule {
|
|
107
110
|
this.postOrderIndex = null;
|
108
111
|
/** @type {number | null} */
|
109
112
|
this.depth = null;
|
110
|
-
/** @type {ModuleProfile | undefined
|
113
|
+
/** @type {ModuleProfile | undefined} */
|
111
114
|
this.profile = undefined;
|
112
115
|
/** @type {boolean} */
|
113
116
|
this.async = false;
|
114
|
-
/** @type {ModuleGraphConnection[]} */
|
117
|
+
/** @type {ModuleGraphConnection[] | undefined} */
|
115
118
|
this._unassignedConnections = undefined;
|
116
119
|
}
|
117
120
|
}
|
118
121
|
|
119
122
|
class ModuleGraph {
|
120
123
|
constructor() {
|
121
|
-
/**
|
124
|
+
/**
|
125
|
+
* @type {WeakMap<Dependency, ModuleGraphConnection | null>}
|
126
|
+
* @private
|
127
|
+
*/
|
122
128
|
this._dependencyMap = new WeakMap();
|
123
|
-
/**
|
129
|
+
/**
|
130
|
+
* @type {Map<Module, ModuleGraphModule>}
|
131
|
+
* @private
|
132
|
+
*/
|
124
133
|
this._moduleMap = new Map();
|
125
|
-
/**
|
134
|
+
/**
|
135
|
+
* @type {WeakMap<any, Object>}
|
136
|
+
* @private
|
137
|
+
*/
|
126
138
|
this._metaMap = new WeakMap();
|
127
|
-
|
128
|
-
|
139
|
+
/**
|
140
|
+
* @type {WeakTupleMap<any[], any> | undefined}
|
141
|
+
* @private
|
142
|
+
*/
|
129
143
|
this._cache = undefined;
|
130
|
-
|
131
|
-
|
144
|
+
/**
|
145
|
+
* @type {Map<Module, WeakTupleMap<any, any>> | undefined}
|
146
|
+
* @private
|
147
|
+
*/
|
132
148
|
this._moduleMemCaches = undefined;
|
133
149
|
|
134
|
-
/**
|
150
|
+
/**
|
151
|
+
* @type {string | undefined}
|
152
|
+
* @private
|
153
|
+
*/
|
135
154
|
this._cacheStage = undefined;
|
136
155
|
}
|
137
156
|
|
@@ -163,7 +182,7 @@ class ModuleGraph {
|
|
163
182
|
|
164
183
|
/**
|
165
184
|
* @param {Dependency} dependency the dependency
|
166
|
-
* @returns {Module} parent module
|
185
|
+
* @returns {Module | undefined} parent module
|
167
186
|
*/
|
168
187
|
getParentModule(dependency) {
|
169
188
|
return dependency._parentModule;
|
@@ -171,7 +190,7 @@ class ModuleGraph {
|
|
171
190
|
|
172
191
|
/**
|
173
192
|
* @param {Dependency} dependency the dependency
|
174
|
-
* @returns {DependenciesBlock} parent block
|
193
|
+
* @returns {DependenciesBlock | undefined} parent block
|
175
194
|
*/
|
176
195
|
getParentBlock(dependency) {
|
177
196
|
return dependency._parentDependenciesBlock;
|
@@ -186,7 +205,7 @@ class ModuleGraph {
|
|
186
205
|
}
|
187
206
|
|
188
207
|
/**
|
189
|
-
* @param {Module} originModule the referencing module
|
208
|
+
* @param {Module | null} originModule the referencing module
|
190
209
|
* @param {Dependency} dependency the referencing dependency
|
191
210
|
* @param {Module} module the referenced module
|
192
211
|
* @returns {void}
|
@@ -231,8 +250,11 @@ class ModuleGraph {
|
|
231
250
|
newConnection.module = module;
|
232
251
|
this._dependencyMap.set(dependency, newConnection);
|
233
252
|
connection.setActive(false);
|
234
|
-
const originMgm = this._getModuleGraphModule(
|
235
|
-
|
253
|
+
const originMgm = this._getModuleGraphModule(
|
254
|
+
/** @type {Module} */ (connection.originModule)
|
255
|
+
);
|
256
|
+
/** @type {OutgoingConnections} */
|
257
|
+
(originMgm.outgoingConnections).add(newConnection);
|
236
258
|
const targetMgm = this._getModuleGraphModule(module);
|
237
259
|
targetMgm.incomingConnections.add(newConnection);
|
238
260
|
}
|
@@ -242,11 +264,16 @@ class ModuleGraph {
|
|
242
264
|
* @returns {void}
|
243
265
|
*/
|
244
266
|
removeConnection(dependency) {
|
245
|
-
const connection =
|
267
|
+
const connection =
|
268
|
+
/** @type {ModuleGraphConnection} */
|
269
|
+
(this.getConnection(dependency));
|
246
270
|
const targetMgm = this._getModuleGraphModule(connection.module);
|
247
271
|
targetMgm.incomingConnections.delete(connection);
|
248
|
-
const originMgm = this._getModuleGraphModule(
|
249
|
-
|
272
|
+
const originMgm = this._getModuleGraphModule(
|
273
|
+
/** @type {Module} */ (connection.originModule)
|
274
|
+
);
|
275
|
+
/** @type {OutgoingConnections} */
|
276
|
+
(originMgm.outgoingConnections).delete(connection);
|
250
277
|
this._dependencyMap.set(dependency, null);
|
251
278
|
}
|
252
279
|
|
@@ -256,7 +283,9 @@ class ModuleGraph {
|
|
256
283
|
* @returns {void}
|
257
284
|
*/
|
258
285
|
addExplanation(dependency, explanation) {
|
259
|
-
const connection =
|
286
|
+
const connection =
|
287
|
+
/** @type {ModuleGraphConnection} */
|
288
|
+
(this.getConnection(dependency));
|
260
289
|
connection.addExplanation(explanation);
|
261
290
|
}
|
262
291
|
|
@@ -468,7 +497,7 @@ class ModuleGraph {
|
|
468
497
|
|
469
498
|
/**
|
470
499
|
* @param {Module} module the module
|
471
|
-
* @returns {readonly Map<Module | undefined, readonly ModuleGraphConnection[]>} reasons why a module is included, in a map by source module
|
500
|
+
* @returns {readonly Map<Module | undefined | null, readonly ModuleGraphConnection[]>} reasons why a module is included, in a map by source module
|
472
501
|
*/
|
473
502
|
getIncomingConnectionsByOriginModule(module) {
|
474
503
|
const connections = this._getModuleGraphModule(module).incomingConnections;
|
@@ -488,7 +517,7 @@ class ModuleGraph {
|
|
488
517
|
|
489
518
|
/**
|
490
519
|
* @param {Module} module the module
|
491
|
-
* @returns {ModuleProfile |
|
520
|
+
* @returns {ModuleProfile | undefined} the module profile
|
492
521
|
*/
|
493
522
|
getProfile(module) {
|
494
523
|
const mgm = this._getModuleGraphModule(module);
|
@@ -497,7 +526,7 @@ class ModuleGraph {
|
|
497
526
|
|
498
527
|
/**
|
499
528
|
* @param {Module} module the module
|
500
|
-
* @param {ModuleProfile |
|
529
|
+
* @param {ModuleProfile | undefined} profile the module profile
|
501
530
|
* @returns {void}
|
502
531
|
*/
|
503
532
|
setProfile(module, profile) {
|
@@ -507,7 +536,7 @@ class ModuleGraph {
|
|
507
536
|
|
508
537
|
/**
|
509
538
|
* @param {Module} module the module
|
510
|
-
* @returns {Module | null} the issuer module
|
539
|
+
* @returns {Module | null | undefined} the issuer module
|
511
540
|
*/
|
512
541
|
getIssuer(module) {
|
513
542
|
const mgm = this._getModuleGraphModule(module);
|
@@ -789,7 +818,7 @@ class ModuleGraph {
|
|
789
818
|
const fn = args.pop();
|
790
819
|
if (this._moduleMemCaches && this._cacheStage) {
|
791
820
|
const memCache = this._moduleMemCaches.get(
|
792
|
-
this.getParentModule(dependency)
|
821
|
+
/** @type {Module} */ (this.getParentModule(dependency))
|
793
822
|
);
|
794
823
|
if (memCache !== undefined) {
|
795
824
|
return memCache.provide(dependency, this._cacheStage, ...args, () =>
|
@@ -6,6 +6,7 @@
|
|
6
6
|
"use strict";
|
7
7
|
|
8
8
|
/** @typedef {import("./Dependency")} Dependency */
|
9
|
+
/** @typedef {import("./Dependency").GetConditionFn} GetConditionFn */
|
9
10
|
/** @typedef {import("./Module")} Module */
|
10
11
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
11
12
|
|
@@ -56,7 +57,7 @@ class ModuleGraphConnection {
|
|
56
57
|
* @param {Module} module the referenced module
|
57
58
|
* @param {string=} explanation some extra detail
|
58
59
|
* @param {boolean=} weak the reference is weak
|
59
|
-
* @param {false |
|
60
|
+
* @param {false | null | GetConditionFn | undefined} condition condition for the connection
|
60
61
|
*/
|
61
62
|
constructor(
|
62
63
|
originModule,
|
package/lib/MultiCompiler.js
CHANGED
@@ -28,7 +28,7 @@ const ArrayQueue = require("./util/ArrayQueue");
|
|
28
28
|
/**
|
29
29
|
* @template T
|
30
30
|
* @callback Callback
|
31
|
-
* @param {
|
31
|
+
* @param {Error | null} err
|
32
32
|
* @param {T=} result
|
33
33
|
*/
|
34
34
|
|
@@ -50,9 +50,11 @@ module.exports = class MultiCompiler {
|
|
50
50
|
*/
|
51
51
|
constructor(compilers, options) {
|
52
52
|
if (!Array.isArray(compilers)) {
|
53
|
+
/** @type {Compiler[]} */
|
53
54
|
compilers = Object.keys(compilers).map(name => {
|
54
|
-
|
55
|
-
|
55
|
+
/** @type {Record<string, Compiler>} */
|
56
|
+
(compilers)[name].name = name;
|
57
|
+
return /** @type {Record<string, Compiler>} */ (compilers)[name];
|
56
58
|
});
|
57
59
|
}
|
58
60
|
|
@@ -221,10 +223,19 @@ module.exports = class MultiCompiler {
|
|
221
223
|
}
|
222
224
|
return false;
|
223
225
|
};
|
226
|
+
/**
|
227
|
+
* @param {{source: Compiler, target: Compiler}} e1 edge 1
|
228
|
+
* @param {{source: Compiler, target: Compiler}} e2 edge 2
|
229
|
+
* @returns {number} result
|
230
|
+
*/
|
224
231
|
const sortEdges = (e1, e2) => {
|
225
232
|
return (
|
226
|
-
|
227
|
-
e1.
|
233
|
+
/** @type {string} */
|
234
|
+
(e1.source.name).localeCompare(
|
235
|
+
/** @type {string} */ (e2.source.name)
|
236
|
+
) ||
|
237
|
+
/** @type {string} */
|
238
|
+
(e1.target.name).localeCompare(/** @type {string} */ (e2.target.name))
|
228
239
|
);
|
229
240
|
};
|
230
241
|
for (const source of this.compilers) {
|
@@ -290,6 +301,9 @@ module.exports = class MultiCompiler {
|
|
290
301
|
* @returns {boolean} when dependency was fulfilled
|
291
302
|
*/
|
292
303
|
const isDependencyFulfilled = d => fulfilledNames.has(d);
|
304
|
+
/**
|
305
|
+
* @returns {Compiler[]} compilers
|
306
|
+
*/
|
293
307
|
const getReadyCompilers = () => {
|
294
308
|
let readyCompilers = [];
|
295
309
|
let list = remainingCompilers;
|
@@ -311,7 +325,7 @@ module.exports = class MultiCompiler {
|
|
311
325
|
* @returns {void}
|
312
326
|
*/
|
313
327
|
const runCompilers = callback => {
|
314
|
-
if (remainingCompilers.length === 0) return callback();
|
328
|
+
if (remainingCompilers.length === 0) return callback(null);
|
315
329
|
asyncLib.map(
|
316
330
|
getReadyCompilers(),
|
317
331
|
(compiler, callback) => {
|
@@ -321,7 +335,9 @@ module.exports = class MultiCompiler {
|
|
321
335
|
runCompilers(callback);
|
322
336
|
});
|
323
337
|
},
|
324
|
-
|
338
|
+
(err, results) => {
|
339
|
+
callback(err, /** @type {TODO} */ (results));
|
340
|
+
}
|
325
341
|
);
|
326
342
|
};
|
327
343
|
runCompilers(callback);
|
@@ -602,7 +618,9 @@ module.exports = class MultiCompiler {
|
|
602
618
|
(compiler, callback) => {
|
603
619
|
compiler.close(callback);
|
604
620
|
},
|
605
|
-
|
621
|
+
error => {
|
622
|
+
callback(error);
|
623
|
+
}
|
606
624
|
);
|
607
625
|
}
|
608
626
|
};
|
package/lib/NodeStuffPlugin.js
CHANGED
@@ -32,6 +32,7 @@ const { parseResource } = require("./util/identifier");
|
|
32
32
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
33
33
|
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
34
34
|
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
35
|
+
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
35
36
|
|
36
37
|
const PLUGIN_NAME = "NodeStuffPlugin";
|
37
38
|
|
@@ -193,7 +194,11 @@ class NodeStuffPlugin {
|
|
193
194
|
break;
|
194
195
|
case true:
|
195
196
|
setModuleConstant("__filename", module =>
|
196
|
-
relative(
|
197
|
+
relative(
|
198
|
+
/** @type {InputFileSystem} */ (compiler.inputFileSystem),
|
199
|
+
context,
|
200
|
+
module.resource
|
201
|
+
)
|
197
202
|
);
|
198
203
|
break;
|
199
204
|
}
|
@@ -227,7 +232,11 @@ class NodeStuffPlugin {
|
|
227
232
|
break;
|
228
233
|
case true:
|
229
234
|
setModuleConstant("__dirname", module =>
|
230
|
-
relative(
|
235
|
+
relative(
|
236
|
+
/** @type {InputFileSystem} */ (compiler.inputFileSystem),
|
237
|
+
context,
|
238
|
+
/** @type {string} */ (module.context)
|
239
|
+
)
|
231
240
|
);
|
232
241
|
break;
|
233
242
|
}
|
@@ -236,7 +245,9 @@ class NodeStuffPlugin {
|
|
236
245
|
.for("__dirname")
|
237
246
|
.tap(PLUGIN_NAME, expr => {
|
238
247
|
if (!parser.state.module) return;
|
239
|
-
return evaluateToString(
|
248
|
+
return evaluateToString(
|
249
|
+
/** @type {string} */ (parser.state.module.context)
|
250
|
+
)(expr);
|
240
251
|
});
|
241
252
|
}
|
242
253
|
parser.hooks.expression
|
package/lib/NormalModule.js
CHANGED
@@ -926,6 +926,8 @@ class NormalModule extends Module {
|
|
926
926
|
loaderContext._compilation =
|
927
927
|
loaderContext._compiler =
|
928
928
|
loaderContext._module =
|
929
|
+
// eslint-disable-next-line no-warning-comments
|
930
|
+
// @ts-ignore
|
929
931
|
loaderContext.fs =
|
930
932
|
undefined;
|
931
933
|
|
@@ -1352,7 +1354,7 @@ class NormalModule extends Module {
|
|
1352
1354
|
? new RawSource(
|
1353
1355
|
"throw new Error(" + JSON.stringify(this.error.message) + ");"
|
1354
1356
|
)
|
1355
|
-
: this.generator.generate(this, {
|
1357
|
+
: /** @type {Generator} */ (this.generator).generate(this, {
|
1356
1358
|
dependencyTemplates,
|
1357
1359
|
runtimeTemplate,
|
1358
1360
|
moduleGraph,
|
@@ -268,7 +268,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
268
268
|
resolveInScheme: new HookMap(
|
269
269
|
() => new AsyncSeriesBailHook(["resourceData", "resolveData"])
|
270
270
|
),
|
271
|
-
/** @type {AsyncSeriesBailHook<[ResolveData], Module>} */
|
271
|
+
/** @type {AsyncSeriesBailHook<[ResolveData], Module | undefined>} */
|
272
272
|
factorize: new AsyncSeriesBailHook(["resolveData"]),
|
273
273
|
/** @type {AsyncSeriesBailHook<[ResolveData], false | void>} */
|
274
274
|
beforeResolve: new AsyncSeriesBailHook(["resolveData"]),
|
@@ -8,6 +8,8 @@
|
|
8
8
|
const { join, dirname } = require("./util/fs");
|
9
9
|
|
10
10
|
/** @typedef {import("./Compiler")} Compiler */
|
11
|
+
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
12
|
+
|
11
13
|
/** @typedef {function(import("./NormalModuleFactory").ResolveData): void} ModuleReplacer */
|
12
14
|
|
13
15
|
class NormalModuleReplacementPlugin {
|
@@ -49,7 +51,9 @@ class NormalModuleReplacementPlugin {
|
|
49
51
|
if (typeof newResource === "function") {
|
50
52
|
newResource(result);
|
51
53
|
} else {
|
52
|
-
const fs =
|
54
|
+
const fs =
|
55
|
+
/** @type {InputFileSystem} */
|
56
|
+
(compiler.inputFileSystem);
|
53
57
|
if (
|
54
58
|
newResource.startsWith("/") ||
|
55
59
|
(newResource.length > 1 && newResource[1] === ":")
|
package/lib/ProvidePlugin.js
CHANGED
@@ -59,7 +59,9 @@ class ProvidePlugin {
|
|
59
59
|
*/
|
60
60
|
const handler = (parser, parserOptions) => {
|
61
61
|
Object.keys(definitions).forEach(name => {
|
62
|
-
const request =
|
62
|
+
const request =
|
63
|
+
/** @type {string[]} */
|
64
|
+
([]).concat(definitions[name]);
|
63
65
|
const splittedName = name.split(".");
|
64
66
|
if (splittedName.length > 0) {
|
65
67
|
splittedName.slice(1).forEach((_, i) => {
|
package/lib/RawModule.js
CHANGED
@@ -19,6 +19,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
19
19
|
/** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
|
20
20
|
/** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
|
21
21
|
/** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
|
22
|
+
/** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
22
23
|
/** @typedef {import("./Module").SourceTypes} SourceTypes */
|
23
24
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
24
25
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
@@ -36,7 +37,7 @@ class RawModule extends Module {
|
|
36
37
|
* @param {string} source source code
|
37
38
|
* @param {string} identifier unique identifier
|
38
39
|
* @param {string=} readableIdentifier readable identifier
|
39
|
-
* @param {
|
40
|
+
* @param {ReadOnlyRuntimeRequirements=} runtimeRequirements runtime requirements needed for the source code
|
40
41
|
*/
|
41
42
|
constructor(source, identifier, readableIdentifier, runtimeRequirements) {
|
42
43
|
super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
|
package/lib/ResolverFactory.js
CHANGED
@@ -61,7 +61,9 @@ const convertToResolveOptions = resolveOptionsWithDepType => {
|
|
61
61
|
);
|
62
62
|
|
63
63
|
return removeOperations(
|
64
|
-
resolveByProperty(options, "byDependency", dependencyType)
|
64
|
+
resolveByProperty(options, "byDependency", dependencyType),
|
65
|
+
// Keep the `unsafeCache` because it can be a `Proxy`
|
66
|
+
["unsafeCache"]
|
65
67
|
);
|
66
68
|
};
|
67
69
|
|
package/lib/RuntimeModule.js
CHANGED
@@ -47,7 +47,7 @@ class RuntimeModule extends Module {
|
|
47
47
|
this.chunkGraph = undefined;
|
48
48
|
this.fullHash = false;
|
49
49
|
this.dependentHash = false;
|
50
|
-
/** @type {string | undefined} */
|
50
|
+
/** @type {string | undefined | null} */
|
51
51
|
this._cachedGeneratedCode = undefined;
|
52
52
|
}
|
53
53
|
|
@@ -113,9 +113,9 @@ class RuntimeModule extends Module {
|
|
113
113
|
if (this.fullHash || this.dependentHash) {
|
114
114
|
// Do not use getGeneratedCode here, because i. e. compilation hash might be not
|
115
115
|
// ready at this point. We will cache it later instead.
|
116
|
-
hash.update(this.generate());
|
116
|
+
hash.update(/** @type {string} */ (this.generate()));
|
117
117
|
} else {
|
118
|
-
hash.update(this.getGeneratedCode());
|
118
|
+
hash.update(/** @type {string} */ (this.getGeneratedCode()));
|
119
119
|
}
|
120
120
|
} catch (err) {
|
121
121
|
hash.update(/** @type {Error} */ (err).message);
|
@@ -179,7 +179,7 @@ class RuntimeModule extends Module {
|
|
179
179
|
*/
|
180
180
|
getGeneratedCode() {
|
181
181
|
if (this._cachedGeneratedCode) {
|
182
|
-
return
|
182
|
+
return this._cachedGeneratedCode;
|
183
183
|
}
|
184
184
|
return (this._cachedGeneratedCode = this.generate());
|
185
185
|
}
|