webpack 5.90.2 → 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 +263 -94
- package/lib/Compiler.js +199 -83
- package/lib/ConditionalInitFragment.js +4 -5
- package/lib/ContextModule.js +4 -1
- package/lib/ContextModuleFactory.js +4 -2
- package/lib/ContextReplacementPlugin.js +3 -2
- package/lib/CssModule.js +0 -3
- package/lib/DefinePlugin.js +4 -2
- package/lib/DelegatedModule.js +2 -1
- package/lib/Dependency.js +4 -2
- package/lib/DependencyTemplate.js +7 -2
- package/lib/DllModule.js +3 -1
- 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 +120 -25
- 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 +54 -5
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +56 -27
- package/lib/ModuleGraphConnection.js +2 -1
- package/lib/MultiCompiler.js +61 -17
- package/lib/NodeStuffPlugin.js +14 -3
- package/lib/NormalModule.js +239 -86
- package/lib/NormalModuleFactory.js +163 -32
- package/lib/NormalModuleReplacementPlugin.js +5 -1
- package/lib/ProvidePlugin.js +3 -1
- package/lib/RawModule.js +4 -2
- package/lib/ResolverFactory.js +5 -1
- package/lib/RuntimeModule.js +6 -5
- package/lib/RuntimePlugin.js +1 -0
- package/lib/RuntimeTemplate.js +102 -34
- package/lib/SourceMapDevToolPlugin.js +4 -1
- package/lib/Stats.js +12 -5
- 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 +5 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
- package/lib/buildChunkGraph.js +220 -392
- 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 +5 -2
- package/lib/container/ContainerPlugin.js +14 -10
- package/lib/container/FallbackModule.js +3 -2
- package/lib/container/RemoteModule.js +2 -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 +21 -10
- 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/WorkerDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +6 -5
- package/lib/dependencies/getFunctionExpression.js +3 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
- package/lib/hmr/LazyCompilationPlugin.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 +140 -55
- 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 +3 -2
- package/lib/sharing/ConsumeSharedPlugin.js +17 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
- package/lib/sharing/ProvideSharedModule.js +2 -1
- 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/memoize.js +2 -0
- 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/WebAssemblyJavascriptGenerator.js +2 -1
- package/lib/wasm-sync/WebAssemblyParser.js +7 -4
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
- package/lib/webpack.js +11 -5
- 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 +1772 -673
@@ -7,9 +7,16 @@
|
|
7
7
|
|
8
8
|
const util = require("util");
|
9
9
|
const ExternalModule = require("./ExternalModule");
|
10
|
+
const ContextElementDependency = require("./dependencies/ContextElementDependency");
|
11
|
+
const CssImportDependency = require("./dependencies/CssImportDependency");
|
12
|
+
const HarmonyImportDependency = require("./dependencies/HarmonyImportDependency");
|
13
|
+
const ImportDependency = require("./dependencies/ImportDependency");
|
10
14
|
const { resolveByProperty, cachedSetProperty } = require("./util/cleverMerge");
|
11
15
|
|
12
16
|
/** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
|
17
|
+
/** @typedef {import("./Compilation").DepConstructor} DepConstructor */
|
18
|
+
/** @typedef {import("./ExternalModule").DependencyMeta} DependencyMeta */
|
19
|
+
/** @typedef {import("./Module")} Module */
|
13
20
|
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
14
21
|
|
15
22
|
const UNSPECIFIED_EXTERNAL_TYPE_REGEXP = /^[a-z0-9-]+ /;
|
@@ -67,7 +74,7 @@ class ExternalModuleFactoryPlugin {
|
|
67
74
|
/**
|
68
75
|
* @param {string|string[]|boolean|Record<string, string|string[]>} value the external config
|
69
76
|
* @param {string|undefined} type type of external
|
70
|
-
* @param {function(Error=, ExternalModule=): void} callback callback
|
77
|
+
* @param {function((Error | null)=, ExternalModule=): void} callback callback
|
71
78
|
* @returns {void}
|
72
79
|
*/
|
73
80
|
const handleExternal = (value, type, callback) => {
|
@@ -105,12 +112,34 @@ class ExternalModuleFactoryPlugin {
|
|
105
112
|
];
|
106
113
|
}
|
107
114
|
}
|
115
|
+
|
116
|
+
// TODO make it pluggable/add hooks to `ExternalModule` to allow output modules own externals?
|
117
|
+
/** @type {DependencyMeta | undefined} */
|
118
|
+
let dependencyMeta;
|
119
|
+
|
120
|
+
if (
|
121
|
+
dependency instanceof HarmonyImportDependency ||
|
122
|
+
dependency instanceof ImportDependency ||
|
123
|
+
dependency instanceof ContextElementDependency
|
124
|
+
) {
|
125
|
+
dependencyMeta = {
|
126
|
+
attributes: dependency.assertions
|
127
|
+
};
|
128
|
+
} else if (dependency instanceof CssImportDependency) {
|
129
|
+
dependencyMeta = {
|
130
|
+
layer: dependency.layer,
|
131
|
+
supports: dependency.supports,
|
132
|
+
media: dependency.media
|
133
|
+
};
|
134
|
+
}
|
135
|
+
|
108
136
|
callback(
|
109
137
|
null,
|
110
138
|
new ExternalModule(
|
111
139
|
externalConfig,
|
112
140
|
type || globalType,
|
113
|
-
dependency.request
|
141
|
+
dependency.request,
|
142
|
+
dependencyMeta
|
114
143
|
)
|
115
144
|
);
|
116
145
|
};
|
@@ -128,7 +157,13 @@ class ExternalModuleFactoryPlugin {
|
|
128
157
|
} else if (Array.isArray(externals)) {
|
129
158
|
let i = 0;
|
130
159
|
const next = () => {
|
160
|
+
/** @type {boolean | undefined} */
|
131
161
|
let asyncFlag;
|
162
|
+
/**
|
163
|
+
* @param {(Error | null)=} err err
|
164
|
+
* @param {ExternalModule=} module module
|
165
|
+
* @returns {void}
|
166
|
+
*/
|
132
167
|
const handleExternalsAndCallback = (err, module) => {
|
133
168
|
if (err) return callback(err);
|
134
169
|
if (!module) {
|
package/lib/FileSystemInfo.js
CHANGED
package/lib/Generator.js
CHANGED
@@ -13,6 +13,7 @@
|
|
13
13
|
/** @typedef {import("./DependencyTemplate")} DependencyTemplate */
|
14
14
|
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
15
15
|
/** @typedef {import("./Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
|
16
|
+
/** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
|
16
17
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
17
18
|
/** @typedef {import("./NormalModule")} NormalModule */
|
18
19
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
@@ -25,7 +26,7 @@
|
|
25
26
|
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
26
27
|
* @property {ModuleGraph} moduleGraph the module graph
|
27
28
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
28
|
-
* @property {
|
29
|
+
* @property {RuntimeRequirements} runtimeRequirements the requirements for runtime
|
29
30
|
* @property {RuntimeSpec} runtime the runtime
|
30
31
|
* @property {RuntimeSpec[]} [runtimes] the runtimes
|
31
32
|
* @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
|
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
@@ -21,12 +21,14 @@ const makeSerializable = require("./util/makeSerializable");
|
|
21
21
|
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
22
22
|
/** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
|
23
23
|
/** @typedef {import("./Compilation")} Compilation */
|
24
|
+
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
24
25
|
/** @typedef {import("./ConcatenationScope")} ConcatenationScope */
|
25
26
|
/** @typedef {import("./Dependency")} Dependency */
|
26
27
|
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
27
28
|
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
28
29
|
/** @typedef {import("./ExportsInfo").UsageStateType} UsageStateType */
|
29
30
|
/** @typedef {import("./FileSystemInfo")} FileSystemInfo */
|
31
|
+
/** @typedef {import("./FileSystemInfo").Snapshot} Snapshot */
|
30
32
|
/** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
|
31
33
|
/** @typedef {import("./ModuleTypeConstants").ModuleTypes} ModuleTypes */
|
32
34
|
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
@@ -62,7 +64,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
62
64
|
* @property {RuntimeSpec} runtime the runtime code should be generated for
|
63
65
|
* @property {RuntimeSpec[]} [runtimes] the runtimes code should be generated for
|
64
66
|
* @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
|
65
|
-
* @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)
|
66
68
|
* @property {Compilation=} compilation the compilation
|
67
69
|
* @property {ReadonlySet<string>=} sourceTypes source types
|
68
70
|
*/
|
@@ -73,11 +75,14 @@ const makeSerializable = require("./util/makeSerializable");
|
|
73
75
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
74
76
|
*/
|
75
77
|
|
78
|
+
/** @typedef {Set<string>} RuntimeRequirements */
|
79
|
+
/** @typedef {ReadonlySet<string>} ReadOnlyRuntimeRequirements */
|
80
|
+
|
76
81
|
/**
|
77
82
|
* @typedef {Object} CodeGenerationResult
|
78
83
|
* @property {Map<string, Source>} sources the resulting sources for all source types
|
79
84
|
* @property {Map<string, any>=} data the resulting data for all source types
|
80
|
-
* @property {
|
85
|
+
* @property {ReadOnlyRuntimeRequirements} runtimeRequirements the runtime requirements
|
81
86
|
* @property {string=} hash a hash of the code generation result (will be automatically calculated from sources and runtimeRequirements if not provided)
|
82
87
|
*/
|
83
88
|
|
@@ -100,6 +105,21 @@ const makeSerializable = require("./util/makeSerializable");
|
|
100
105
|
* @property {boolean=} sideEffectFree
|
101
106
|
*/
|
102
107
|
|
108
|
+
/**
|
109
|
+
* @typedef {Object} KnownBuildInfo
|
110
|
+
* @property {boolean=} cacheable
|
111
|
+
* @property {boolean=} parsed
|
112
|
+
* @property {LazySet<string>=} fileDependencies
|
113
|
+
* @property {LazySet<string>=} contextDependencies
|
114
|
+
* @property {LazySet<string>=} missingDependencies
|
115
|
+
* @property {LazySet<string>=} buildDependencies
|
116
|
+
* @property {(Map<string, string | Set<string>>)=} valueDependencies
|
117
|
+
* @property {TODO=} hash
|
118
|
+
* @property {Record<string, Source>=} assets
|
119
|
+
* @property {Map<string, AssetInfo | undefined>=} assetsInfo
|
120
|
+
* @property {(Snapshot | null)=} snapshot
|
121
|
+
*/
|
122
|
+
|
103
123
|
/**
|
104
124
|
* @typedef {Object} NeedBuildContext
|
105
125
|
* @property {Compilation} compilation
|
@@ -108,13 +128,17 @@ const makeSerializable = require("./util/makeSerializable");
|
|
108
128
|
*/
|
109
129
|
|
110
130
|
/** @typedef {KnownBuildMeta & Record<string, any>} BuildMeta */
|
111
|
-
/** @typedef {Record<string, any>} BuildInfo */
|
131
|
+
/** @typedef {KnownBuildInfo & Record<string, any>} BuildInfo */
|
112
132
|
|
113
133
|
/**
|
114
134
|
* @typedef {Object} FactoryMeta
|
115
135
|
* @property {boolean=} sideEffectFree
|
116
136
|
*/
|
117
137
|
|
138
|
+
/** @typedef {Set<string>} SourceTypes */
|
139
|
+
|
140
|
+
/** @typedef {{ factoryMeta: FactoryMeta | undefined, resolveOptions: ResolveOptions | undefined }} UnsafeCacheData */
|
141
|
+
|
118
142
|
const EMPTY_RESOLVE_OPTIONS = {};
|
119
143
|
|
120
144
|
let debugId = 1000;
|
@@ -249,6 +273,9 @@ class Module extends DependenciesBlock {
|
|
249
273
|
).setProfile(this, value);
|
250
274
|
}
|
251
275
|
|
276
|
+
/**
|
277
|
+
* @returns {number | null} the pre order index
|
278
|
+
*/
|
252
279
|
get index() {
|
253
280
|
return ModuleGraph.getModuleGraphForModule(
|
254
281
|
this,
|
@@ -257,6 +284,9 @@ class Module extends DependenciesBlock {
|
|
257
284
|
).getPreOrderIndex(this);
|
258
285
|
}
|
259
286
|
|
287
|
+
/**
|
288
|
+
* @param {number} value the pre order index
|
289
|
+
*/
|
260
290
|
set index(value) {
|
261
291
|
ModuleGraph.getModuleGraphForModule(
|
262
292
|
this,
|
@@ -265,6 +295,9 @@ class Module extends DependenciesBlock {
|
|
265
295
|
).setPreOrderIndex(this, value);
|
266
296
|
}
|
267
297
|
|
298
|
+
/**
|
299
|
+
* @returns {number | null} the post order index
|
300
|
+
*/
|
268
301
|
get index2() {
|
269
302
|
return ModuleGraph.getModuleGraphForModule(
|
270
303
|
this,
|
@@ -273,6 +306,9 @@ class Module extends DependenciesBlock {
|
|
273
306
|
).getPostOrderIndex(this);
|
274
307
|
}
|
275
308
|
|
309
|
+
/**
|
310
|
+
* @param {number} value the post order index
|
311
|
+
*/
|
276
312
|
set index2(value) {
|
277
313
|
ModuleGraph.getModuleGraphForModule(
|
278
314
|
this,
|
@@ -281,6 +317,9 @@ class Module extends DependenciesBlock {
|
|
281
317
|
).setPostOrderIndex(this, value);
|
282
318
|
}
|
283
319
|
|
320
|
+
/**
|
321
|
+
* @returns {number | null} the depth
|
322
|
+
*/
|
284
323
|
get depth() {
|
285
324
|
return ModuleGraph.getModuleGraphForModule(
|
286
325
|
this,
|
@@ -289,6 +328,9 @@ class Module extends DependenciesBlock {
|
|
289
328
|
).getDepth(this);
|
290
329
|
}
|
291
330
|
|
331
|
+
/**
|
332
|
+
* @param {number} value the depth
|
333
|
+
*/
|
292
334
|
set depth(value) {
|
293
335
|
ModuleGraph.getModuleGraphForModule(
|
294
336
|
this,
|
@@ -297,6 +339,9 @@ class Module extends DependenciesBlock {
|
|
297
339
|
).setDepth(this, value);
|
298
340
|
}
|
299
341
|
|
342
|
+
/**
|
343
|
+
* @returns {Module | null | undefined} issuer
|
344
|
+
*/
|
300
345
|
get issuer() {
|
301
346
|
return ModuleGraph.getModuleGraphForModule(
|
302
347
|
this,
|
@@ -305,6 +350,9 @@ class Module extends DependenciesBlock {
|
|
305
350
|
).getIssuer(this);
|
306
351
|
}
|
307
352
|
|
353
|
+
/**
|
354
|
+
* @param {Module | null} value issuer
|
355
|
+
*/
|
308
356
|
set issuer(value) {
|
309
357
|
ModuleGraph.getModuleGraphForModule(
|
310
358
|
this,
|
@@ -812,7 +860,7 @@ class Module extends DependenciesBlock {
|
|
812
860
|
|
813
861
|
/**
|
814
862
|
* @abstract
|
815
|
-
* @returns {
|
863
|
+
* @returns {SourceTypes} types available (do not mutate)
|
816
864
|
*/
|
817
865
|
getSourceTypes() {
|
818
866
|
// Better override this method to return the correct types
|
@@ -851,6 +899,7 @@ class Module extends DependenciesBlock {
|
|
851
899
|
codeGenerationResults: undefined
|
852
900
|
};
|
853
901
|
const sources = this.codeGeneration(codeGenContext).sources;
|
902
|
+
|
854
903
|
return type ? sources.get(type) : sources.get(first(this.getSourceTypes()));
|
855
904
|
}
|
856
905
|
|
@@ -956,7 +1005,7 @@ class Module extends DependenciesBlock {
|
|
956
1005
|
/**
|
957
1006
|
* Module should be unsafe cached. Get data that's needed for that.
|
958
1007
|
* This data will be passed to restoreFromUnsafeCache later.
|
959
|
-
* @returns {
|
1008
|
+
* @returns {UnsafeCacheData} cached data
|
960
1009
|
*/
|
961
1010
|
getUnsafeCacheData() {
|
962
1011
|
return {
|
@@ -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,
|