webpack 5.87.0 → 5.88.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/lib/APIPlugin.js +1 -1
- package/lib/AsyncDependenciesBlock.js +3 -3
- package/lib/ChunkGraph.js +4 -4
- package/lib/ChunkGroup.js +9 -3
- package/lib/CompatibilityPlugin.js +50 -30
- package/lib/Compilation.js +2 -1
- package/lib/ContextModule.js +4 -1
- package/lib/ContextReplacementPlugin.js +13 -0
- package/lib/DelegatedModule.js +15 -3
- package/lib/DelegatedModuleFactoryPlugin.js +6 -0
- package/lib/Dependency.js +11 -5
- package/lib/DllEntryPlugin.js +11 -1
- package/lib/DllReferencePlugin.js +13 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ErrorHelpers.js +1 -0
- package/lib/EvalSourceMapDevToolPlugin.js +4 -0
- package/lib/ExportsInfo.js +17 -3
- package/lib/ExportsInfoApiPlugin.js +14 -5
- package/lib/ExternalModule.js +5 -0
- package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
- package/lib/FlagDependencyUsagePlugin.js +3 -1
- package/lib/HotModuleReplacementPlugin.js +8 -0
- package/lib/InitFragment.js +28 -5
- package/lib/JavascriptMetaInfoPlugin.js +11 -6
- package/lib/LibManifestPlugin.js +20 -4
- package/lib/Module.js +7 -2
- package/lib/ModuleProfile.js +1 -0
- package/lib/ModuleRestoreError.js +2 -0
- package/lib/NodeStuffPlugin.js +32 -6
- package/lib/ProvidePlugin.js +13 -4
- package/lib/RawModule.js +3 -1
- package/lib/RequireJsStuffPlugin.js +7 -0
- package/lib/RuntimeModule.js +3 -3
- package/lib/RuntimePlugin.js +4 -2
- package/lib/RuntimeTemplate.js +2 -2
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
- package/lib/SourceMapDevToolPlugin.js +7 -2
- package/lib/UseStrictPlugin.js +10 -3
- package/lib/WebpackIsIncludedPlugin.js +6 -4
- package/lib/asset/AssetGenerator.js +2 -1
- package/lib/asset/AssetParser.js +11 -6
- package/lib/asset/AssetSourceParser.js +8 -3
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
- package/lib/cache/IdleFileCachePlugin.js +2 -1
- package/lib/cache/PackFileCacheStrategy.js +35 -14
- package/lib/config/browserslistTargetHandler.js +7 -7
- package/lib/config/defaults.js +12 -24
- package/lib/container/RemoteRuntimeModule.js +1 -1
- package/lib/css/CssLoadingRuntimeModule.js +30 -13
- package/lib/css/CssParser.js +11 -1
- package/lib/dependencies/AMDDefineDependency.js +34 -4
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
- package/lib/dependencies/AMDRuntimeModules.js +2 -2
- package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
- package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
- package/lib/dependencies/CommonJsPlugin.js +13 -8
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
- package/lib/dependencies/ContextDependency.js +7 -2
- package/lib/dependencies/CssImportDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
- package/lib/dependencies/CssUrlDependency.js +3 -3
- package/lib/dependencies/DllEntryDependency.js +5 -0
- package/lib/dependencies/DynamicExports.js +10 -6
- package/lib/dependencies/ExportsInfoDependency.js +14 -4
- package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
- package/lib/dependencies/HarmonyExports.js +9 -5
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +32 -17
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +19 -9
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
- package/lib/dependencies/ImportDependency.js +5 -3
- package/lib/dependencies/ImportEagerDependency.js +5 -3
- package/lib/dependencies/ImportMetaPlugin.js +31 -15
- package/lib/dependencies/ImportParserPlugin.js +38 -25
- package/lib/dependencies/ImportWeakDependency.js +5 -3
- package/lib/dependencies/ModuleDependency.js +1 -1
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
- package/lib/dependencies/ProvidedDependency.js +4 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
- package/lib/dependencies/RequireHeaderDependency.js +4 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
- package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
- package/lib/dependencies/SystemPlugin.js +17 -5
- package/lib/dependencies/SystemRuntimeModule.js +1 -1
- package/lib/dependencies/URLDependency.js +2 -2
- package/lib/dependencies/URLPlugin.js +9 -4
- package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +59 -22
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +1 -1
- package/lib/javascript/JavascriptParser.js +17 -5
- package/lib/logging/runtime.js +1 -1
- package/lib/logging/truncateArgs.js +4 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
- package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
- package/lib/optimize/InnerGraph.js +1 -1
- package/lib/optimize/InnerGraphPlugin.js +2 -1
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +1 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +1 -1
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -1
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +4 -4
- package/lib/runtime/AutoPublicPathRuntimeModule.js +1 -1
- package/lib/runtime/BaseUriRuntimeModule.js +1 -1
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
- package/lib/runtime/CompatRuntimeModule.js +1 -1
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/CreateScriptRuntimeModule.js +1 -1
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +1 -1
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +1 -1
- package/lib/runtime/EnsureChunkRuntimeModule.js +1 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -1
- package/lib/runtime/GetFullHashRuntimeModule.js +1 -1
- package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/GlobalRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/NonceRuntimeModule.js +1 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +1 -1
- package/lib/runtime/PublicPathRuntimeModule.js +1 -1
- package/lib/runtime/RelativeUrlRuntimeModule.js +1 -1
- package/lib/runtime/RuntimeIdRuntimeModule.js +1 -1
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
- package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -1
- package/lib/runtime/SystemContextRuntimeModule.js +1 -1
- package/lib/sharing/ConsumeSharedRuntimeModule.js +1 -1
- package/lib/sharing/ShareRuntimeModule.js +1 -1
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +1 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +2 -1
- package/types.d.ts +86 -38
package/lib/APIPlugin.js
CHANGED
@@ -29,7 +29,7 @@ const GetFullHashRuntimeModule = require("./runtime/GetFullHashRuntimeModule");
|
|
29
29
|
/**
|
30
30
|
* @param {boolean} module true if ES module
|
31
31
|
* @param {string} importMetaName `import.meta` name
|
32
|
-
* @returns {Record<string, {expr: string, req: string[], type?: string, assign: boolean}>} replacements
|
32
|
+
* @returns {Record<string, {expr: string, req: string[] | null, type?: string, assign: boolean}>} replacements
|
33
33
|
*/
|
34
34
|
function getReplacements(module, importMetaName) {
|
35
35
|
return {
|
@@ -21,9 +21,9 @@ const makeSerializable = require("./util/makeSerializable");
|
|
21
21
|
|
22
22
|
class AsyncDependenciesBlock extends DependenciesBlock {
|
23
23
|
/**
|
24
|
-
* @param {ChunkGroupOptions & { entryOptions?: EntryOptions }} groupOptions options for the group
|
25
|
-
* @param {DependencyLocation=} loc the line of code
|
26
|
-
* @param {string=} request the request
|
24
|
+
* @param {(ChunkGroupOptions & { entryOptions?: EntryOptions }) | null} groupOptions options for the group
|
25
|
+
* @param {(DependencyLocation | null)=} loc the line of code
|
26
|
+
* @param {(string | null)=} request the request
|
27
27
|
*/
|
28
28
|
constructor(groupOptions, loc, request) {
|
29
29
|
super();
|
package/lib/ChunkGraph.js
CHANGED
@@ -188,7 +188,7 @@ class ChunkGraphModule {
|
|
188
188
|
this.entryInChunks = undefined;
|
189
189
|
/** @type {Set<Chunk> | undefined} */
|
190
190
|
this.runtimeInChunks = undefined;
|
191
|
-
/** @type {RuntimeSpecMap<ModuleHashInfo>} */
|
191
|
+
/** @type {RuntimeSpecMap<ModuleHashInfo> | undefined} */
|
192
192
|
this.hashes = undefined;
|
193
193
|
/** @type {string | number} */
|
194
194
|
this.id = null;
|
@@ -1388,7 +1388,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1388
1388
|
*/
|
1389
1389
|
hasModuleHashes(module, runtime) {
|
1390
1390
|
const cgm = this._getChunkGraphModule(module);
|
1391
|
-
const hashes = cgm.hashes;
|
1391
|
+
const hashes = /** @type {RuntimeSpecMap<ModuleHashInfo>} */ (cgm.hashes);
|
1392
1392
|
return hashes && hashes.has(runtime);
|
1393
1393
|
}
|
1394
1394
|
|
@@ -1399,7 +1399,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1399
1399
|
*/
|
1400
1400
|
getModuleHash(module, runtime) {
|
1401
1401
|
const cgm = this._getChunkGraphModule(module);
|
1402
|
-
const hashes = cgm.hashes;
|
1402
|
+
const hashes = /** @type {RuntimeSpecMap<ModuleHashInfo>} */ (cgm.hashes);
|
1403
1403
|
return this._getModuleHashInfo(module, hashes, runtime).hash;
|
1404
1404
|
}
|
1405
1405
|
|
@@ -1410,7 +1410,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1410
1410
|
*/
|
1411
1411
|
getRenderedModuleHash(module, runtime) {
|
1412
1412
|
const cgm = this._getChunkGraphModule(module);
|
1413
|
-
const hashes = cgm.hashes;
|
1413
|
+
const hashes = /** @type {RuntimeSpecMap<ModuleHashInfo>} */ (cgm.hashes);
|
1414
1414
|
return this._getModuleHashInfo(module, hashes, runtime).renderedHash;
|
1415
1415
|
}
|
1416
1416
|
|
package/lib/ChunkGroup.js
CHANGED
@@ -109,9 +109,15 @@ class ChunkGroup {
|
|
109
109
|
*/
|
110
110
|
addOptions(options) {
|
111
111
|
for (const key of Object.keys(options)) {
|
112
|
-
if (
|
113
|
-
this.options[key]
|
114
|
-
|
112
|
+
if (
|
113
|
+
this.options[/** @type {keyof ChunkGroupOptions} */ (key)] === undefined
|
114
|
+
) {
|
115
|
+
this.options[key] =
|
116
|
+
options[/** @type {keyof ChunkGroupOptions} */ (key)];
|
117
|
+
} else if (
|
118
|
+
this.options[/** @type {keyof ChunkGroupOptions} */ (key)] !==
|
119
|
+
options[/** @type {keyof ChunkGroupOptions} */ (key)]
|
120
|
+
) {
|
115
121
|
if (key.endsWith("Order")) {
|
116
122
|
this.options[key] = Math.max(this.options[key], options[key]);
|
117
123
|
} else {
|
@@ -13,8 +13,11 @@ const {
|
|
13
13
|
const RuntimeGlobals = require("./RuntimeGlobals");
|
14
14
|
const ConstDependency = require("./dependencies/ConstDependency");
|
15
15
|
|
16
|
+
/** @typedef {import("estree").CallExpression} CallExpression */
|
16
17
|
/** @typedef {import("./Compiler")} Compiler */
|
18
|
+
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
17
19
|
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
20
|
+
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
18
21
|
|
19
22
|
const nestedWebpackIdentifierTag = Symbol("nested webpack identifier");
|
20
23
|
const PLUGIN_NAME = "CompatibilityPlugin";
|
@@ -43,31 +46,41 @@ class CompatibilityPlugin {
|
|
43
46
|
)
|
44
47
|
return;
|
45
48
|
|
46
|
-
parser.hooks.call.for("require").tap(
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
const
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
last
|
65
|
-
|
66
|
-
|
49
|
+
parser.hooks.call.for("require").tap(
|
50
|
+
PLUGIN_NAME,
|
51
|
+
/**
|
52
|
+
* @param {CallExpression} expr call expression
|
53
|
+
* @returns {boolean | void} true when need to handle
|
54
|
+
*/
|
55
|
+
expr => {
|
56
|
+
// support for browserify style require delegator: "require(o, !0)"
|
57
|
+
if (expr.arguments.length !== 2) return;
|
58
|
+
const second = parser.evaluateExpression(expr.arguments[1]);
|
59
|
+
if (!second.isBoolean()) return;
|
60
|
+
if (second.asBool() !== true) return;
|
61
|
+
const dep = new ConstDependency(
|
62
|
+
"require",
|
63
|
+
/** @type {Range} */ (expr.callee.range)
|
64
|
+
);
|
65
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
66
|
+
if (parser.state.current.dependencies.length > 0) {
|
67
|
+
const last =
|
68
|
+
parser.state.current.dependencies[
|
69
|
+
parser.state.current.dependencies.length - 1
|
70
|
+
];
|
71
|
+
if (
|
72
|
+
last.critical &&
|
73
|
+
last.options &&
|
74
|
+
last.options.request === "." &&
|
75
|
+
last.userRequest === "." &&
|
76
|
+
last.options.recursive
|
77
|
+
)
|
78
|
+
parser.state.current.dependencies.pop();
|
79
|
+
}
|
80
|
+
parser.state.module.addPresentationalDependency(dep);
|
81
|
+
return true;
|
67
82
|
}
|
68
|
-
|
69
|
-
return true;
|
70
|
-
});
|
83
|
+
);
|
71
84
|
});
|
72
85
|
|
73
86
|
/**
|
@@ -82,7 +95,9 @@ class CompatibilityPlugin {
|
|
82
95
|
statement.id &&
|
83
96
|
statement.id.name === RuntimeGlobals.require
|
84
97
|
) {
|
85
|
-
const newName = `__nested_webpack_require_${
|
98
|
+
const newName = `__nested_webpack_require_${
|
99
|
+
/** @type {Range} */ (statement.range)[0]
|
100
|
+
}__`;
|
86
101
|
parser.tagVariable(
|
87
102
|
statement.id.name,
|
88
103
|
nestedWebpackIdentifierTag,
|
@@ -101,7 +116,9 @@ class CompatibilityPlugin {
|
|
101
116
|
parser.hooks.pattern
|
102
117
|
.for(RuntimeGlobals.require)
|
103
118
|
.tap(PLUGIN_NAME, pattern => {
|
104
|
-
const newName = `__nested_webpack_require_${
|
119
|
+
const newName = `__nested_webpack_require_${
|
120
|
+
/** @type {Range} */ (pattern.range)[0]
|
121
|
+
}__`;
|
105
122
|
parser.tagVariable(pattern.name, nestedWebpackIdentifierTag, {
|
106
123
|
name: newName,
|
107
124
|
declaration: {
|
@@ -135,8 +152,11 @@ class CompatibilityPlugin {
|
|
135
152
|
parser.state.module.addPresentationalDependency(dep);
|
136
153
|
declaration.updated = true;
|
137
154
|
}
|
138
|
-
const dep = new ConstDependency(
|
139
|
-
|
155
|
+
const dep = new ConstDependency(
|
156
|
+
name,
|
157
|
+
/** @type {Range} */ (expr.range)
|
158
|
+
);
|
159
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
140
160
|
parser.state.module.addPresentationalDependency(dep);
|
141
161
|
return true;
|
142
162
|
});
|
@@ -145,11 +165,11 @@ class CompatibilityPlugin {
|
|
145
165
|
parser.hooks.program.tap(PLUGIN_NAME, (program, comments) => {
|
146
166
|
if (comments.length === 0) return;
|
147
167
|
const c = comments[0];
|
148
|
-
if (c.type === "Line" && c.range[0] === 0) {
|
168
|
+
if (c.type === "Line" && /** @type {Range} */ (c.range)[0] === 0) {
|
149
169
|
if (parser.state.source.slice(0, 2).toString() !== "#!") return;
|
150
170
|
// this is a hashbang comment
|
151
171
|
const dep = new ConstDependency("//", 0);
|
152
|
-
dep.loc = c.loc;
|
172
|
+
dep.loc = /** @type {DependencyLocation} */ (c.loc);
|
153
173
|
parser.state.module.addPresentationalDependency(dep);
|
154
174
|
}
|
155
175
|
});
|
package/lib/Compilation.js
CHANGED
@@ -3208,6 +3208,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3208
3208
|
const { chunkGraph, moduleGraph, dependencyTemplates, runtimeTemplate } =
|
3209
3209
|
this;
|
3210
3210
|
const results = this.codeGenerationResults;
|
3211
|
+
/** @type {WebpackError[]} */
|
3211
3212
|
const errors = [];
|
3212
3213
|
/** @type {Set<Module> | undefined} */
|
3213
3214
|
let notCodeGeneratedModules = undefined;
|
@@ -3303,7 +3304,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3303
3304
|
* @param {RuntimeTemplate} runtimeTemplate runtimeTemplate
|
3304
3305
|
* @param {WebpackError[]} errors errors
|
3305
3306
|
* @param {CodeGenerationResults} results results
|
3306
|
-
* @param {function(WebpackError=, boolean=): void} callback callback
|
3307
|
+
* @param {function((WebpackError | null)=, boolean=): void} callback callback
|
3307
3308
|
*/
|
3308
3309
|
_codeGenerationModule(
|
3309
3310
|
module,
|
package/lib/ContextModule.js
CHANGED
@@ -63,7 +63,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
63
63
|
* @property {RawChunkGroupOptions=} groupOptions
|
64
64
|
* @property {string=} typePrefix
|
65
65
|
* @property {string=} category
|
66
|
-
* @property {string[][]=} referencedExports exports referenced from modules (won't be mangled)
|
66
|
+
* @property {(string[][] | null)=} referencedExports exports referenced from modules (won't be mangled)
|
67
67
|
* @property {string=} layer
|
68
68
|
*/
|
69
69
|
|
@@ -231,6 +231,9 @@ class ContextModule extends Module {
|
|
231
231
|
} else if (this.options.namespaceObject) {
|
232
232
|
identifier += "|namespace object";
|
233
233
|
}
|
234
|
+
if (this.layer) {
|
235
|
+
identifier += `|layer: ${this.layer}`;
|
236
|
+
}
|
234
237
|
|
235
238
|
return identifier;
|
236
239
|
}
|
@@ -8,7 +8,15 @@
|
|
8
8
|
const ContextElementDependency = require("./dependencies/ContextElementDependency");
|
9
9
|
const { join } = require("./util/fs");
|
10
10
|
|
11
|
+
/** @typedef {import("./Compiler")} Compiler */
|
12
|
+
|
11
13
|
class ContextReplacementPlugin {
|
14
|
+
/**
|
15
|
+
* @param {RegExp} resourceRegExp A regular expression that determines which files will be selected
|
16
|
+
* @param {TODO=} newContentResource A new resource to replace the match
|
17
|
+
* @param {TODO=} newContentRecursive If true, all subdirectories are searched for matches
|
18
|
+
* @param {TODO=} newContentRegExp A regular expression that determines which files will be selected
|
19
|
+
*/
|
12
20
|
constructor(
|
13
21
|
resourceRegExp,
|
14
22
|
newContentResource,
|
@@ -49,6 +57,11 @@ class ContextReplacementPlugin {
|
|
49
57
|
}
|
50
58
|
}
|
51
59
|
|
60
|
+
/**
|
61
|
+
* Apply the plugin
|
62
|
+
* @param {Compiler} compiler the compiler instance
|
63
|
+
* @returns {void}
|
64
|
+
*/
|
52
65
|
apply(compiler) {
|
53
66
|
const resourceRegExp = this.resourceRegExp;
|
54
67
|
const newContentCallback = this.newContentCallback;
|
package/lib/DelegatedModule.js
CHANGED
@@ -42,6 +42,13 @@ const RUNTIME_REQUIREMENTS = new Set([
|
|
42
42
|
]);
|
43
43
|
|
44
44
|
class DelegatedModule extends Module {
|
45
|
+
/**
|
46
|
+
* @param {string} sourceRequest source request
|
47
|
+
* @param {TODO} data data
|
48
|
+
* @param {"require" | "object"} type type
|
49
|
+
* @param {string} userRequest user request
|
50
|
+
* @param {string | Module} originalRequest original request
|
51
|
+
*/
|
45
52
|
constructor(sourceRequest, data, type, userRequest, originalRequest) {
|
46
53
|
super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
|
47
54
|
|
@@ -51,7 +58,7 @@ class DelegatedModule extends Module {
|
|
51
58
|
this.delegationType = type;
|
52
59
|
this.userRequest = userRequest;
|
53
60
|
this.originalRequest = originalRequest;
|
54
|
-
/** @type {ManifestModuleData} */
|
61
|
+
/** @type {ManifestModuleData | undefined} */
|
55
62
|
this.delegateData = data;
|
56
63
|
|
57
64
|
// Build info
|
@@ -110,7 +117,8 @@ class DelegatedModule extends Module {
|
|
110
117
|
* @returns {void}
|
111
118
|
*/
|
112
119
|
build(options, compilation, resolver, fs, callback) {
|
113
|
-
|
120
|
+
const delegateData = /** @type {ManifestModuleData} */ (this.delegateData);
|
121
|
+
this.buildMeta = { ...delegateData.buildMeta };
|
114
122
|
this.buildInfo = {};
|
115
123
|
this.dependencies.length = 0;
|
116
124
|
this.delegatedSourceDependency = new DelegatedSourceDependency(
|
@@ -118,7 +126,7 @@ class DelegatedModule extends Module {
|
|
118
126
|
);
|
119
127
|
this.addDependency(this.delegatedSourceDependency);
|
120
128
|
this.addDependency(
|
121
|
-
new StaticExportsDependency(
|
129
|
+
new StaticExportsDependency(delegateData.exports || true, false)
|
122
130
|
);
|
123
131
|
callback();
|
124
132
|
}
|
@@ -202,6 +210,10 @@ class DelegatedModule extends Module {
|
|
202
210
|
super.serialize(context);
|
203
211
|
}
|
204
212
|
|
213
|
+
/**
|
214
|
+
* @param {ObjectDeserializerContext} context context\
|
215
|
+
* @returns {DelegatedModule} DelegatedModule
|
216
|
+
*/
|
205
217
|
static deserialize(context) {
|
206
218
|
const { read } = context;
|
207
219
|
const obj = new DelegatedModule(
|
@@ -7,6 +7,8 @@
|
|
7
7
|
|
8
8
|
const DelegatedModule = require("./DelegatedModule");
|
9
9
|
|
10
|
+
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
11
|
+
|
10
12
|
// options.source
|
11
13
|
// options.type
|
12
14
|
// options.context
|
@@ -20,6 +22,10 @@ class DelegatedModuleFactoryPlugin {
|
|
20
22
|
options.extensions = options.extensions || ["", ".js", ".json", ".wasm"];
|
21
23
|
}
|
22
24
|
|
25
|
+
/**
|
26
|
+
* @param {NormalModuleFactory} normalModuleFactory the normal module factory
|
27
|
+
* @returns {void}
|
28
|
+
*/
|
23
29
|
apply(normalModuleFactory) {
|
24
30
|
const scope = this.options.scope;
|
25
31
|
if (scope) {
|
package/lib/Dependency.js
CHANGED
@@ -89,9 +89,9 @@ const getIgnoredModule = memoize(() => {
|
|
89
89
|
|
90
90
|
class Dependency {
|
91
91
|
constructor() {
|
92
|
-
/** @type {Module} */
|
92
|
+
/** @type {Module | undefined} */
|
93
93
|
this._parentModule = undefined;
|
94
|
-
/** @type {DependenciesBlock} */
|
94
|
+
/** @type {DependenciesBlock | undefined} */
|
95
95
|
this._parentDependenciesBlock = undefined;
|
96
96
|
/** @type {number} */
|
97
97
|
this._parentDependenciesBlockIndex = -1;
|
@@ -174,6 +174,12 @@ class Dependency {
|
|
174
174
|
this._loc = loc;
|
175
175
|
}
|
176
176
|
|
177
|
+
/**
|
178
|
+
* @param {number} startLine start line
|
179
|
+
* @param {number} startColumn start column
|
180
|
+
* @param {number} endLine end line
|
181
|
+
* @param {number} endColumn end column
|
182
|
+
*/
|
177
183
|
setLoc(startLine, startColumn, endLine, endColumn) {
|
178
184
|
this._locSL = startLine;
|
179
185
|
this._locSC = startColumn;
|
@@ -247,7 +253,7 @@ class Dependency {
|
|
247
253
|
/**
|
248
254
|
* Returns warnings
|
249
255
|
* @param {ModuleGraph} moduleGraph module graph
|
250
|
-
* @returns {WebpackError[]} warnings
|
256
|
+
* @returns {WebpackError[] | null | undefined} warnings
|
251
257
|
*/
|
252
258
|
getWarnings(moduleGraph) {
|
253
259
|
return null;
|
@@ -256,7 +262,7 @@ class Dependency {
|
|
256
262
|
/**
|
257
263
|
* Returns errors
|
258
264
|
* @param {ModuleGraph} moduleGraph module graph
|
259
|
-
* @returns {WebpackError[]} errors
|
265
|
+
* @returns {WebpackError[] | null | undefined} errors
|
260
266
|
*/
|
261
267
|
getErrors(moduleGraph) {
|
262
268
|
return null;
|
@@ -288,7 +294,7 @@ class Dependency {
|
|
288
294
|
|
289
295
|
/**
|
290
296
|
* @param {string} context context directory
|
291
|
-
* @returns {Module} a module
|
297
|
+
* @returns {Module | null} a module
|
292
298
|
*/
|
293
299
|
createIgnoredModule(context) {
|
294
300
|
return getIgnoredModule();
|
package/lib/DllEntryPlugin.js
CHANGED
@@ -9,6 +9,8 @@ const DllModuleFactory = require("./DllModuleFactory");
|
|
9
9
|
const DllEntryDependency = require("./dependencies/DllEntryDependency");
|
10
10
|
const EntryDependency = require("./dependencies/EntryDependency");
|
11
11
|
|
12
|
+
/** @typedef {import("./Compiler")} Compiler */
|
13
|
+
|
12
14
|
class DllEntryPlugin {
|
13
15
|
/**
|
14
16
|
* @param {string} context context
|
@@ -21,6 +23,11 @@ class DllEntryPlugin {
|
|
21
23
|
this.options = options;
|
22
24
|
}
|
23
25
|
|
26
|
+
/**
|
27
|
+
* Apply the plugin
|
28
|
+
* @param {Compiler} compiler the compiler instance
|
29
|
+
* @returns {void}
|
30
|
+
*/
|
24
31
|
apply(compiler) {
|
25
32
|
compiler.hooks.compilation.tap(
|
26
33
|
"DllEntryPlugin",
|
@@ -51,7 +58,10 @@ class DllEntryPlugin {
|
|
51
58
|
this.options.name
|
52
59
|
),
|
53
60
|
this.options,
|
54
|
-
|
61
|
+
error => {
|
62
|
+
if (error) return callback(error);
|
63
|
+
callback();
|
64
|
+
}
|
55
65
|
);
|
56
66
|
});
|
57
67
|
}
|
@@ -16,6 +16,7 @@ const makePathsRelative = require("./util/identifier").makePathsRelative;
|
|
16
16
|
/** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
|
17
17
|
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptions} DllReferencePluginOptions */
|
18
18
|
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptionsManifest} DllReferencePluginOptionsManifest */
|
19
|
+
/** @typedef {import("./Compiler")} Compiler */
|
19
20
|
|
20
21
|
const validate = createSchemaValidation(
|
21
22
|
require("../schemas/plugins/DllReferencePlugin.check.js"),
|
@@ -37,6 +38,11 @@ class DllReferencePlugin {
|
|
37
38
|
this._compilationData = new WeakMap();
|
38
39
|
}
|
39
40
|
|
41
|
+
/**
|
42
|
+
* Apply the plugin
|
43
|
+
* @param {Compiler} compiler the compiler instance
|
44
|
+
* @returns {void}
|
45
|
+
*/
|
40
46
|
apply(compiler) {
|
41
47
|
compiler.hooks.compilation.tap(
|
42
48
|
"DllReferencePlugin",
|
@@ -140,7 +146,9 @@ class DllReferencePlugin {
|
|
140
146
|
// If there was an error parsing the manifest file, add the
|
141
147
|
// error as a compilation error to make the compilation fail.
|
142
148
|
if (data.error) {
|
143
|
-
compilation.errors.push(
|
149
|
+
compilation.errors.push(
|
150
|
+
/** @type {DllManifestError} */ (data.error)
|
151
|
+
);
|
144
152
|
}
|
145
153
|
compilation.fileDependencies.add(manifest);
|
146
154
|
}
|
@@ -151,6 +159,10 @@ class DllReferencePlugin {
|
|
151
159
|
}
|
152
160
|
|
153
161
|
class DllManifestError extends WebpackError {
|
162
|
+
/**
|
163
|
+
* @param {string} filename filename of the manifest
|
164
|
+
* @param {string} message error message
|
165
|
+
*/
|
154
166
|
constructor(filename, message) {
|
155
167
|
super();
|
156
168
|
|
package/lib/Entrypoint.js
CHANGED
package/lib/ErrorHelpers.js
CHANGED
package/lib/ExportsInfo.js
CHANGED
@@ -14,6 +14,8 @@ const { forEachRuntime } = require("./util/runtime");
|
|
14
14
|
/** @typedef {import("./Module")} Module */
|
15
15
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
16
16
|
/** @typedef {import("./ModuleGraphConnection")} ModuleGraphConnection */
|
17
|
+
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
18
|
+
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
17
19
|
/** @typedef {import("./util/Hash")} Hash */
|
18
20
|
|
19
21
|
/** @typedef {typeof UsageState.OnlyPropertiesUsed | typeof UsageState.NoInfo | typeof UsageState.Unknown | typeof UsageState.Used} RuntimeUsageStateType */
|
@@ -44,6 +46,9 @@ class RestoreProvidedData {
|
|
44
46
|
this.otherTerminalBinding = otherTerminalBinding;
|
45
47
|
}
|
46
48
|
|
49
|
+
/**
|
50
|
+
* @param {ObjectSerializerContext} context context
|
51
|
+
*/
|
47
52
|
serialize({ write }) {
|
48
53
|
write(this.exports);
|
49
54
|
write(this.otherProvided);
|
@@ -51,6 +56,10 @@ class RestoreProvidedData {
|
|
51
56
|
write(this.otherTerminalBinding);
|
52
57
|
}
|
53
58
|
|
59
|
+
/**
|
60
|
+
* @param {ObjectDeserializerContext} context context
|
61
|
+
* @returns {RestoreProvidedData} RestoreProvidedData
|
62
|
+
*/
|
54
63
|
static deserialize({ read }) {
|
55
64
|
return new RestoreProvidedData(read(), read(), read(), read());
|
56
65
|
}
|
@@ -301,7 +310,12 @@ class ExportsInfo {
|
|
301
310
|
changed = true;
|
302
311
|
}
|
303
312
|
if (targetKey) {
|
304
|
-
exportInfo.setTarget(
|
313
|
+
exportInfo.setTarget(
|
314
|
+
targetKey,
|
315
|
+
/** @type {ModuleGraphConnection} */ (targetModule),
|
316
|
+
[exportInfo.name],
|
317
|
+
-1
|
318
|
+
);
|
305
319
|
}
|
306
320
|
}
|
307
321
|
if (this._redirectTo !== undefined) {
|
@@ -331,7 +345,7 @@ class ExportsInfo {
|
|
331
345
|
if (targetKey) {
|
332
346
|
this._otherExportsInfo.setTarget(
|
333
347
|
targetKey,
|
334
|
-
targetModule,
|
348
|
+
/** @type {ModuleGraphConnection} */ (targetModule),
|
335
349
|
undefined,
|
336
350
|
priority
|
337
351
|
);
|
@@ -1226,7 +1240,7 @@ class ExportInfo {
|
|
1226
1240
|
/**
|
1227
1241
|
* @param {ModuleGraph} moduleGraph the module graph
|
1228
1242
|
* @param {function(Module): boolean} validTargetModuleFilter a valid target module
|
1229
|
-
* @param {Set<ExportInfo>
|
1243
|
+
* @param {Set<ExportInfo>} alreadyVisited set of already visited export info to avoid circular references
|
1230
1244
|
* @returns {{ module: Module, export: string[] | undefined } | undefined | false} the target, undefined when there is no target, false when no target is valid
|
1231
1245
|
*/
|
1232
1246
|
_findTarget(moduleGraph, validTargetModuleFilter, alreadyVisited) {
|
@@ -14,7 +14,9 @@ const ConstDependency = require("./dependencies/ConstDependency");
|
|
14
14
|
const ExportsInfoDependency = require("./dependencies/ExportsInfoDependency");
|
15
15
|
|
16
16
|
/** @typedef {import("./Compiler")} Compiler */
|
17
|
+
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
17
18
|
/** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
|
19
|
+
/** @typedef {import("./javascript/JavascriptParser").Range} Range */
|
18
20
|
|
19
21
|
const PLUGIN_NAME = "ExportsInfoApiPlugin";
|
20
22
|
|
@@ -43,20 +45,27 @@ class ExportsInfoApiPlugin {
|
|
43
45
|
const dep =
|
44
46
|
members.length >= 2
|
45
47
|
? new ExportsInfoDependency(
|
46
|
-
expr.range,
|
48
|
+
/** @type {Range} */ (expr.range),
|
47
49
|
members.slice(0, -1),
|
48
50
|
members[members.length - 1]
|
49
51
|
)
|
50
|
-
: new ExportsInfoDependency(
|
51
|
-
|
52
|
+
: new ExportsInfoDependency(
|
53
|
+
/** @type {Range} */ (expr.range),
|
54
|
+
null,
|
55
|
+
members[0]
|
56
|
+
);
|
57
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
52
58
|
parser.state.module.addDependency(dep);
|
53
59
|
return true;
|
54
60
|
});
|
55
61
|
parser.hooks.expression
|
56
62
|
.for("__webpack_exports_info__")
|
57
63
|
.tap(PLUGIN_NAME, expr => {
|
58
|
-
const dep = new ConstDependency(
|
59
|
-
|
64
|
+
const dep = new ConstDependency(
|
65
|
+
"true",
|
66
|
+
/** @type {Range} */ (expr.range)
|
67
|
+
);
|
68
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
60
69
|
parser.state.module.addPresentationalDependency(dep);
|
61
70
|
return true;
|
62
71
|
});
|
package/lib/ExternalModule.js
CHANGED
@@ -384,6 +384,11 @@ const getSourceForDefaultCase = (optional, request, runtimeTemplate) => {
|
|
384
384
|
};
|
385
385
|
|
386
386
|
class ExternalModule extends Module {
|
387
|
+
/**
|
388
|
+
* @param {string | string[] | Record<string, string | string[]>} request request
|
389
|
+
* @param {TODO} type type
|
390
|
+
* @param {string} userRequest user request
|
391
|
+
*/
|
387
392
|
constructor(request, type, userRequest) {
|
388
393
|
super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
|
389
394
|
|
@@ -8,10 +8,14 @@
|
|
8
8
|
const { getEntryRuntime, mergeRuntimeOwned } = require("./util/runtime");
|
9
9
|
|
10
10
|
/** @typedef {import("./Compiler")} Compiler */
|
11
|
+
/** @typedef {import("./Module").FactoryMeta} FactoryMeta */
|
11
12
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
12
13
|
|
13
14
|
const PLUGIN_NAME = "FlagAllModulesAsUsedPlugin";
|
14
15
|
class FlagAllModulesAsUsedPlugin {
|
16
|
+
/**
|
17
|
+
* @param {string} explanation explanation
|
18
|
+
*/
|
15
19
|
constructor(explanation) {
|
16
20
|
this.explanation = explanation;
|
17
21
|
}
|
@@ -40,7 +44,8 @@ class FlagAllModulesAsUsedPlugin {
|
|
40
44
|
if (module.factoryMeta === undefined) {
|
41
45
|
module.factoryMeta = {};
|
42
46
|
}
|
43
|
-
|
47
|
+
/** @type {FactoryMeta} */
|
48
|
+
(module.factoryMeta).sideEffectFree = false;
|
44
49
|
}
|
45
50
|
});
|
46
51
|
});
|
@@ -332,7 +332,9 @@ class FlagDependencyUsagePlugin {
|
|
332
332
|
}
|
333
333
|
|
334
334
|
while (queue.length) {
|
335
|
-
const [module, runtime] =
|
335
|
+
const [module, runtime] = /** @type {[Module, RuntimeSpec]} */ (
|
336
|
+
queue.dequeue()
|
337
|
+
);
|
336
338
|
processModule(module, runtime, false);
|
337
339
|
}
|
338
340
|
logger.timeEnd("trace exports usage in graph");
|