webpack 5.85.0 → 5.88.1
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 -2
- package/lib/APIPlugin.js +150 -99
- package/lib/AsyncDependenciesBlock.js +3 -3
- package/lib/BannerPlugin.js +2 -1
- package/lib/CaseSensitiveModulesWarning.js +3 -1
- package/lib/Chunk.js +35 -17
- package/lib/ChunkGraph.js +4 -4
- package/lib/ChunkGroup.js +20 -9
- package/lib/CompatibilityPlugin.js +50 -30
- package/lib/Compilation.js +2 -1
- package/lib/Compiler.js +10 -9
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ConditionalInitFragment.js +11 -1
- package/lib/ConstPlugin.js +73 -32
- package/lib/ContextModule.js +8 -3
- package/lib/ContextModuleFactory.js +1 -0
- package/lib/ContextReplacementPlugin.js +13 -0
- package/lib/DelegatedModule.js +15 -3
- package/lib/DelegatedModuleFactoryPlugin.js +6 -0
- package/lib/DependenciesBlock.js +1 -1
- package/lib/Dependency.js +11 -5
- package/lib/DependencyTemplates.js +1 -1
- package/lib/DllEntryPlugin.js +11 -1
- package/lib/DllModule.js +6 -0
- package/lib/DllReferencePlugin.js +13 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ErrorHelpers.js +1 -0
- package/lib/EvalSourceMapDevToolPlugin.js +6 -1
- package/lib/ExportsInfo.js +22 -4
- package/lib/ExportsInfoApiPlugin.js +14 -5
- package/lib/ExternalModule.js +20 -8
- package/lib/FileSystemInfo.js +52 -24
- package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
- package/lib/FlagDependencyUsagePlugin.js +3 -1
- package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
- package/lib/Generator.js +7 -0
- 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 +14 -3
- package/lib/ModuleDependencyError.js +4 -2
- package/lib/ModuleDependencyWarning.js +4 -2
- package/lib/ModuleGraph.js +31 -24
- package/lib/ModuleGraphConnection.js +19 -6
- package/lib/ModuleInfoHeaderPlugin.js +9 -2
- package/lib/ModuleNotFoundError.js +5 -2
- package/lib/ModuleProfile.js +1 -0
- package/lib/ModuleRestoreError.js +2 -0
- package/lib/ModuleStoreError.js +2 -1
- package/lib/ModuleTypeConstants.js +7 -0
- package/lib/MultiWatching.js +4 -0
- package/lib/NodeStuffPlugin.js +32 -6
- package/lib/ProgressPlugin.js +71 -15
- package/lib/ProvidePlugin.js +13 -4
- package/lib/RawModule.js +3 -1
- package/lib/RequireJsStuffPlugin.js +7 -0
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimeModule.js +3 -3
- package/lib/RuntimePlugin.js +6 -3
- package/lib/RuntimeTemplate.js +22 -4
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
- package/lib/SourceMapDevToolPlugin.js +7 -2
- package/lib/UseStrictPlugin.js +10 -3
- package/lib/Watching.js +62 -25
- package/lib/WebpackError.js +6 -5
- package/lib/WebpackIsIncludedPlugin.js +6 -4
- package/lib/WebpackOptionsApply.js +4 -2
- package/lib/WebpackOptionsDefaulter.js +10 -3
- 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/buildChunkGraph.js +37 -21
- package/lib/cache/IdleFileCachePlugin.js +2 -1
- package/lib/cache/PackFileCacheStrategy.js +53 -22
- package/lib/config/browserslistTargetHandler.js +7 -7
- package/lib/config/defaults.js +43 -26
- package/lib/container/RemoteRuntimeModule.js +1 -1
- package/lib/css/CssExportsGenerator.js +9 -0
- package/lib/css/CssGenerator.js +1 -1
- package/lib/css/CssLoadingRuntimeModule.js +43 -19
- package/lib/css/CssModulesPlugin.js +42 -14
- package/lib/css/CssParser.js +22 -0
- 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/ConstDependency.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 +40 -27
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +31 -21
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
- package/lib/dependencies/ImportDependency.js +5 -3
- package/lib/dependencies/ImportEagerDependency.js +5 -3
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
- package/lib/dependencies/ImportMetaPlugin.js +31 -15
- package/lib/dependencies/ImportParserPlugin.js +62 -25
- package/lib/dependencies/ImportWeakDependency.js +5 -3
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- 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/ids/SyncModuleIdsPlugin.js +1 -0
- package/lib/javascript/BasicEvaluatedExpression.js +28 -19
- package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
- package/lib/javascript/JavascriptModulesPlugin.js +25 -5
- package/lib/javascript/JavascriptParser.js +157 -85
- package/lib/javascript/JavascriptParserHelpers.js +37 -15
- package/lib/json/JsonData.js +2 -2
- package/lib/json/JsonParser.js +25 -12
- package/lib/library/AmdLibraryPlugin.js +2 -2
- package/lib/library/AssignLibraryPlugin.js +13 -1
- package/lib/library/EnableLibraryPlugin.js +4 -0
- package/lib/library/SystemLibraryPlugin.js +1 -1
- package/lib/library/UmdLibraryPlugin.js +20 -2
- package/lib/logging/runtime.js +1 -1
- package/lib/logging/truncateArgs.js +4 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
- package/lib/optimize/AggressiveMergingPlugin.js +8 -0
- package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
- package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
- package/lib/optimize/InnerGraph.js +5 -5
- package/lib/optimize/InnerGraphPlugin.js +2 -1
- package/lib/optimize/LimitChunkCountPlugin.js +29 -4
- package/lib/optimize/MangleExportsPlugin.js +1 -1
- package/lib/optimize/MinMaxSizeWarning.js +5 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
- package/lib/optimize/RealContentHashPlugin.js +80 -30
- package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
- package/lib/optimize/RuntimeChunkPlugin.js +9 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
- package/lib/optimize/SplitChunksPlugin.js +71 -31
- package/lib/performance/SizeLimitsPlugin.js +7 -4
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
- package/lib/rules/BasicEffectRulePlugin.js +4 -0
- package/lib/rules/BasicMatcherRulePlugin.js +5 -0
- package/lib/rules/RuleSetCompiler.js +3 -3
- package/lib/rules/UseEffectRulePlugin.js +6 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +8 -5
- package/lib/runtime/AutoPublicPathRuntimeModule.js +4 -2
- package/lib/runtime/BaseUriRuntimeModule.js +3 -3
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
- package/lib/runtime/CompatRuntimeModule.js +7 -2
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
- package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
- package/lib/runtime/EnsureChunkRuntimeModule.js +15 -4
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -10
- package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
- package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -2
- package/lib/runtime/GlobalRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
- package/lib/runtime/LoadScriptRuntimeModule.js +64 -48
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
- package/lib/runtime/NonceRuntimeModule.js +1 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
- package/lib/runtime/PublicPathRuntimeModule.js +4 -2
- package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
- package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -3
- package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -2
- package/lib/runtime/SystemContextRuntimeModule.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +143 -1
- package/lib/serialization/ErrorObjectSerializer.js +3 -0
- package/lib/serialization/ObjectMiddleware.js +9 -3
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +14 -5
- package/lib/sharing/ProvideSharedDependency.js +11 -0
- package/lib/sharing/ProvideSharedModule.js +4 -0
- package/lib/sharing/ProvideSharedPlugin.js +22 -21
- package/lib/sharing/ShareRuntimeModule.js +12 -5
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/sharing/utils.js +32 -5
- package/lib/util/AsyncQueue.js +4 -2
- package/lib/util/ParallelismFactorCalculator.js +10 -0
- package/lib/util/Semaphore.js +1 -1
- package/lib/util/StackedCacheMap.js +1 -1
- package/lib/util/URLAbsoluteSpecifier.js +1 -1
- package/lib/util/createHash.js +30 -9
- package/lib/util/deprecation.js +10 -3
- package/lib/util/deterministicGrouping.js +50 -11
- package/lib/util/findGraphRoots.js +4 -2
- package/lib/util/memoize.js +3 -3
- package/lib/util/processAsyncTree.js +7 -1
- package/lib/util/registerExternalSerializer.js +1 -1
- package/lib/util/runtime.js +84 -21
- package/lib/util/semver.js +1 -0
- package/lib/util/smartGrouping.js +1 -1
- package/lib/validateSchema.js +6 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +6 -2
- package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +14 -7
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
- package/lib/wasm-sync/WebAssemblyParser.js +6 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +14 -4
- package/lib/webpack.js +11 -2
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -16
- package/module.d.ts +1 -0
- package/package.json +5 -4
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +52 -6
- package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
- package/schemas/plugins/css/CssParserOptions.json +1 -1
- package/types.d.ts +606 -292
@@ -38,6 +38,10 @@ class RequireResolveHeaderDependency extends NullDependency {
|
|
38
38
|
super.serialize(context);
|
39
39
|
}
|
40
40
|
|
41
|
+
/**
|
42
|
+
* @param {ObjectDeserializerContext} context context
|
43
|
+
* @returns {RequireResolveHeaderDependency} RequireResolveHeaderDependency
|
44
|
+
*/
|
41
45
|
static deserialize(context) {
|
42
46
|
const obj = new RequireResolveHeaderDependency(context.read());
|
43
47
|
obj.deserialize(context);
|
@@ -64,6 +68,11 @@ RequireResolveHeaderDependency.Template = class RequireResolveHeaderDependencyTe
|
|
64
68
|
source.replace(dep.range[0], dep.range[1] - 1, "/*require.resolve*/");
|
65
69
|
}
|
66
70
|
|
71
|
+
/**
|
72
|
+
* @param {string} name name
|
73
|
+
* @param {RequireResolveHeaderDependency} dep dependency
|
74
|
+
* @param {ReplaceSource} source source
|
75
|
+
*/
|
67
76
|
applyAsTemplateArgument(name, dep, source) {
|
68
77
|
source.replace(dep.range[0], dep.range[1] - 1, "/*require.resolve*/");
|
69
78
|
}
|
@@ -22,7 +22,9 @@ const SystemRuntimeModule = require("./SystemRuntimeModule");
|
|
22
22
|
|
23
23
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
24
24
|
/** @typedef {import("../Compiler")} Compiler */
|
25
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
25
26
|
/** @typedef {import("../javascript/JavascriptParser")} Parser */
|
27
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
26
28
|
|
27
29
|
const PLUGIN_NAME = "SystemPlugin";
|
28
30
|
|
@@ -58,6 +60,9 @@ class SystemPlugin {
|
|
58
60
|
return;
|
59
61
|
}
|
60
62
|
|
63
|
+
/**
|
64
|
+
* @param {string} name name
|
65
|
+
*/
|
61
66
|
const setNotSupported = name => {
|
62
67
|
parser.hooks.evaluateTypeof
|
63
68
|
.for(name)
|
@@ -97,17 +102,21 @@ class SystemPlugin {
|
|
97
102
|
setNotSupported("System.register");
|
98
103
|
|
99
104
|
parser.hooks.expression.for("System").tap(PLUGIN_NAME, expr => {
|
100
|
-
const dep = new ConstDependency(
|
101
|
-
RuntimeGlobals.system
|
102
|
-
|
103
|
-
|
105
|
+
const dep = new ConstDependency(
|
106
|
+
RuntimeGlobals.system,
|
107
|
+
/** @type {Range} */ (expr.range),
|
108
|
+
[RuntimeGlobals.system]
|
109
|
+
);
|
110
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
104
111
|
parser.state.module.addPresentationalDependency(dep);
|
105
112
|
return true;
|
106
113
|
});
|
107
114
|
|
108
115
|
parser.hooks.call.for("System.import").tap(PLUGIN_NAME, expr => {
|
109
116
|
parser.state.module.addWarning(
|
110
|
-
new SystemImportDeprecationWarning(
|
117
|
+
new SystemImportDeprecationWarning(
|
118
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
119
|
+
)
|
111
120
|
);
|
112
121
|
|
113
122
|
return parser.hooks.importCall.call({
|
@@ -133,6 +142,9 @@ class SystemPlugin {
|
|
133
142
|
}
|
134
143
|
|
135
144
|
class SystemImportDeprecationWarning extends WebpackError {
|
145
|
+
/**
|
146
|
+
* @param {DependencyLocation} loc location
|
147
|
+
*/
|
136
148
|
constructor(loc) {
|
137
149
|
super(
|
138
150
|
"System.import() is deprecated and will be removed soon. Use import() instead.\n" +
|
@@ -42,7 +42,7 @@ class URLDependency extends ModuleDependency {
|
|
42
42
|
this.range = range;
|
43
43
|
this.outerRange = outerRange;
|
44
44
|
this.relative = relative || false;
|
45
|
-
/** @type {Set<string> | boolean} */
|
45
|
+
/** @type {Set<string> | boolean | undefined} */
|
46
46
|
this.usedByExports = undefined;
|
47
47
|
}
|
48
48
|
|
@@ -68,7 +68,7 @@ class URLDependency extends ModuleDependency {
|
|
68
68
|
|
69
69
|
/**
|
70
70
|
* @param {string} context context directory
|
71
|
-
* @returns {Module} a module
|
71
|
+
* @returns {Module | null} a module
|
72
72
|
*/
|
73
73
|
createIgnoredModule(context) {
|
74
74
|
const RawDataUrlModule = getRawDataUrlModule();
|
@@ -18,9 +18,11 @@ const URLDependency = require("./URLDependency");
|
|
18
18
|
/** @typedef {import("estree").NewExpression} NewExpressionNode */
|
19
19
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
20
20
|
/** @typedef {import("../Compiler")} Compiler */
|
21
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
21
22
|
/** @typedef {import("../NormalModule")} NormalModule */
|
22
23
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
23
24
|
/** @typedef {import("../javascript/JavascriptParser")} Parser */
|
25
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
24
26
|
|
25
27
|
const PLUGIN_NAME = "URLPlugin";
|
26
28
|
|
@@ -94,7 +96,7 @@ class URLPlugin {
|
|
94
96
|
|
95
97
|
return new BasicEvaluatedExpression()
|
96
98
|
.setString(url.toString())
|
97
|
-
.setRange(expr.range);
|
99
|
+
.setRange(/** @type {Range} */ (expr.range));
|
98
100
|
});
|
99
101
|
parser.hooks.new.for("URL").tap(PLUGIN_NAME, _expr => {
|
100
102
|
const expr = /** @type {NewExpressionNode} */ (_expr);
|
@@ -106,11 +108,14 @@ class URLPlugin {
|
|
106
108
|
const [arg1, arg2] = expr.arguments;
|
107
109
|
const dep = new URLDependency(
|
108
110
|
request,
|
109
|
-
[
|
110
|
-
|
111
|
+
[
|
112
|
+
/** @type {Range} */ (arg1.range)[0],
|
113
|
+
/** @type {Range} */ (arg2.range)[1]
|
114
|
+
],
|
115
|
+
/** @type {Range} */ (expr.range),
|
111
116
|
relative
|
112
117
|
);
|
113
|
-
dep.loc = expr.loc;
|
118
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
114
119
|
parser.state.current.addDependency(dep);
|
115
120
|
InnerGraph.onUsage(parser.state, e => (dep.usedByExports = e));
|
116
121
|
return true;
|
@@ -55,7 +55,7 @@ class WebAssemblyImportDependency extends ModuleDependency {
|
|
55
55
|
/**
|
56
56
|
* Returns errors
|
57
57
|
* @param {ModuleGraph} moduleGraph module graph
|
58
|
-
* @returns {WebpackError[]} errors
|
58
|
+
* @returns {WebpackError[] | null | undefined} errors
|
59
59
|
*/
|
60
60
|
getErrors(moduleGraph) {
|
61
61
|
const module = moduleGraph.getModule(this);
|
@@ -25,20 +25,32 @@ const {
|
|
25
25
|
} = require("./HarmonyImportDependencyParserPlugin");
|
26
26
|
const WorkerDependency = require("./WorkerDependency");
|
27
27
|
|
28
|
+
/** @typedef {import("estree").CallExpression} CallExpression */
|
28
29
|
/** @typedef {import("estree").Expression} Expression */
|
29
30
|
/** @typedef {import("estree").ObjectExpression} ObjectExpression */
|
30
31
|
/** @typedef {import("estree").Pattern} Pattern */
|
31
32
|
/** @typedef {import("estree").Property} Property */
|
32
33
|
/** @typedef {import("estree").SpreadElement} SpreadElement */
|
34
|
+
/** @typedef {import("../../declarations/WebpackOptions").ChunkLoading} ChunkLoading */
|
33
35
|
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
36
|
+
/** @typedef {import("../../declarations/WebpackOptions").OutputModule} OutputModule */
|
37
|
+
/** @typedef {import("../../declarations/WebpackOptions").WasmLoading} WasmLoading */
|
38
|
+
/** @typedef {import("../../declarations/WebpackOptions").WorkerPublicPath} WorkerPublicPath */
|
34
39
|
/** @typedef {import("../Compiler")} Compiler */
|
40
|
+
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
35
41
|
/** @typedef {import("../Entrypoint").EntryOptions} EntryOptions */
|
42
|
+
/** @typedef {import("../NormalModule")} NormalModule */
|
36
43
|
/** @typedef {import("../Parser").ParserState} ParserState */
|
37
44
|
/** @typedef {import("../javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
|
38
45
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
39
46
|
/** @typedef {import("../javascript/JavascriptParser")} Parser */
|
47
|
+
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
40
48
|
/** @typedef {import("./HarmonyImportDependencyParserPlugin").HarmonySettings} HarmonySettings */
|
41
49
|
|
50
|
+
/**
|
51
|
+
* @param {NormalModule} module module
|
52
|
+
* @returns {string} url
|
53
|
+
*/
|
42
54
|
const getUrl = module => {
|
43
55
|
return pathToFileURL(module.resource).toString();
|
44
56
|
};
|
@@ -58,6 +70,12 @@ const workerIndexMap = new WeakMap();
|
|
58
70
|
const PLUGIN_NAME = "WorkerPlugin";
|
59
71
|
|
60
72
|
class WorkerPlugin {
|
73
|
+
/**
|
74
|
+
* @param {ChunkLoading} chunkLoading chunk loading
|
75
|
+
* @param {WasmLoading} wasmLoading wasm loading
|
76
|
+
* @param {OutputModule} module output module
|
77
|
+
* @param {WorkerPublicPath} workerPublicPath worker public path
|
78
|
+
*/
|
61
79
|
constructor(chunkLoading, wasmLoading, module, workerPublicPath) {
|
62
80
|
this._chunkLoading = chunkLoading;
|
63
81
|
this._wasmLoading = wasmLoading;
|
@@ -99,7 +117,7 @@ class WorkerPlugin {
|
|
99
117
|
/**
|
100
118
|
* @param {JavascriptParser} parser the parser
|
101
119
|
* @param {Expression} expr expression
|
102
|
-
* @returns {[BasicEvaluatedExpression, [number, number]]} parsed
|
120
|
+
* @returns {[BasicEvaluatedExpression, [number, number]] | void} parsed
|
103
121
|
*/
|
104
122
|
const parseModuleUrl = (parser, expr) => {
|
105
123
|
if (
|
@@ -116,13 +134,19 @@ class WorkerPlugin {
|
|
116
134
|
const arg2Value = parser.evaluateExpression(arg2);
|
117
135
|
if (
|
118
136
|
!arg2Value.isString() ||
|
119
|
-
!arg2Value.string.startsWith("file://") ||
|
137
|
+
!(/** @type {string} */ (arg2Value.string).startsWith("file://")) ||
|
120
138
|
arg2Value.string !== getUrl(parser.state.module)
|
121
139
|
) {
|
122
140
|
return;
|
123
141
|
}
|
124
142
|
const arg1Value = parser.evaluateExpression(arg1);
|
125
|
-
return [
|
143
|
+
return [
|
144
|
+
arg1Value,
|
145
|
+
[
|
146
|
+
/** @type {Range} */ (arg1.range)[0],
|
147
|
+
/** @type {Range} */ (arg2.range)[1]
|
148
|
+
]
|
149
|
+
];
|
126
150
|
};
|
127
151
|
|
128
152
|
/**
|
@@ -182,6 +206,10 @@ class WorkerPlugin {
|
|
182
206
|
const options = !Array.isArray(parserOptions.worker)
|
183
207
|
? ["..."]
|
184
208
|
: parserOptions.worker;
|
209
|
+
/**
|
210
|
+
* @param {CallExpression} expr expression
|
211
|
+
* @returns {boolean | void} true when handled
|
212
|
+
*/
|
185
213
|
const handleNewWorker = expr => {
|
186
214
|
if (expr.arguments.length === 0 || expr.arguments.length > 2)
|
187
215
|
return;
|
@@ -209,10 +237,12 @@ class WorkerPlugin {
|
|
209
237
|
values: {},
|
210
238
|
spread: false,
|
211
239
|
insertType: arg2 ? "spread" : "argument",
|
212
|
-
insertLocation: arg2
|
240
|
+
insertLocation: arg2
|
241
|
+
? /** @type {Range} */ (arg2.range)
|
242
|
+
: /** @type {Range} */ (arg1.range)[1]
|
213
243
|
};
|
214
244
|
const { options: importOptions, errors: commentErrors } =
|
215
|
-
parser.parseCommentOptions(expr.range);
|
245
|
+
parser.parseCommentOptions(/** @type {Range} */ (expr.range));
|
216
246
|
|
217
247
|
if (commentErrors) {
|
218
248
|
for (const e of commentErrors) {
|
@@ -235,7 +265,7 @@ class WorkerPlugin {
|
|
235
265
|
parser.state.module.addWarning(
|
236
266
|
new UnsupportedFeatureWarning(
|
237
267
|
`\`webpackIgnore\` expected a boolean, but received: ${importOptions.webpackIgnore}.`,
|
238
|
-
expr.loc
|
268
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
239
269
|
)
|
240
270
|
);
|
241
271
|
} else {
|
@@ -252,7 +282,7 @@ class WorkerPlugin {
|
|
252
282
|
parser.state.module.addWarning(
|
253
283
|
new UnsupportedFeatureWarning(
|
254
284
|
`\`webpackEntryOptions\` expected a object, but received: ${importOptions.webpackEntryOptions}.`,
|
255
|
-
expr.loc
|
285
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
256
286
|
)
|
257
287
|
);
|
258
288
|
} else {
|
@@ -267,7 +297,7 @@ class WorkerPlugin {
|
|
267
297
|
parser.state.module.addWarning(
|
268
298
|
new UnsupportedFeatureWarning(
|
269
299
|
`\`webpackChunkName\` expected a string, but received: ${importOptions.webpackChunkName}.`,
|
270
|
-
expr.loc
|
300
|
+
/** @type {DependencyLocation} */ (expr.loc)
|
271
301
|
)
|
272
302
|
);
|
273
303
|
} else {
|
@@ -310,18 +340,22 @@ class WorkerPlugin {
|
|
310
340
|
}
|
311
341
|
});
|
312
342
|
block.loc = expr.loc;
|
313
|
-
const dep = new WorkerDependency(
|
314
|
-
|
315
|
-
|
316
|
-
|
343
|
+
const dep = new WorkerDependency(
|
344
|
+
/** @type {string} */ (url.string),
|
345
|
+
range,
|
346
|
+
{
|
347
|
+
publicPath: this._workerPublicPath
|
348
|
+
}
|
349
|
+
);
|
350
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
317
351
|
block.addDependency(dep);
|
318
352
|
parser.state.module.addBlock(block);
|
319
353
|
|
320
354
|
if (compilation.outputOptions.trustedTypes) {
|
321
355
|
const dep = new CreateScriptUrlDependency(
|
322
|
-
expr.arguments[0].range
|
356
|
+
/** @type {Range} */ (expr.arguments[0].range)
|
323
357
|
);
|
324
|
-
dep.loc = expr.loc;
|
358
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
325
359
|
parser.state.module.addDependency(dep);
|
326
360
|
}
|
327
361
|
|
@@ -330,9 +364,9 @@ class WorkerPlugin {
|
|
330
364
|
if (options.type !== false) {
|
331
365
|
const dep = new ConstDependency(
|
332
366
|
this._module ? '"module"' : "undefined",
|
333
|
-
expr.range
|
367
|
+
/** @type {Range} */ (expr.range)
|
334
368
|
);
|
335
|
-
dep.loc = expr.loc;
|
369
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
336
370
|
parser.state.module.addPresentationalDependency(dep);
|
337
371
|
expressions.type = undefined;
|
338
372
|
}
|
@@ -342,20 +376,20 @@ class WorkerPlugin {
|
|
342
376
|
`, type: ${this._module ? '"module"' : "undefined"}`,
|
343
377
|
insertLocation
|
344
378
|
);
|
345
|
-
dep.loc = expr.loc;
|
379
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
346
380
|
parser.state.module.addPresentationalDependency(dep);
|
347
381
|
}
|
348
382
|
} else if (insertType === "spread") {
|
349
383
|
const dep1 = new ConstDependency(
|
350
384
|
"Object.assign({}, ",
|
351
|
-
insertLocation[0]
|
385
|
+
/** @type {Range} */ (insertLocation)[0]
|
352
386
|
);
|
353
387
|
const dep2 = new ConstDependency(
|
354
388
|
`, { type: ${this._module ? '"module"' : "undefined"} })`,
|
355
|
-
insertLocation[1]
|
389
|
+
/** @type {Range} */ (insertLocation)[1]
|
356
390
|
);
|
357
|
-
dep1.loc = expr.loc;
|
358
|
-
dep2.loc = expr.loc;
|
391
|
+
dep1.loc = /** @type {DependencyLocation} */ (expr.loc);
|
392
|
+
dep2.loc = /** @type {DependencyLocation} */ (expr.loc);
|
359
393
|
parser.state.module.addPresentationalDependency(dep1);
|
360
394
|
parser.state.module.addPresentationalDependency(dep2);
|
361
395
|
} else if (insertType === "argument") {
|
@@ -364,7 +398,7 @@ class WorkerPlugin {
|
|
364
398
|
', { type: "module" }',
|
365
399
|
insertLocation
|
366
400
|
);
|
367
|
-
dep.loc = expr.loc;
|
401
|
+
dep.loc = /** @type {DependencyLocation} */ (expr.loc);
|
368
402
|
parser.state.module.addPresentationalDependency(dep);
|
369
403
|
}
|
370
404
|
}
|
@@ -382,6 +416,9 @@ class WorkerPlugin {
|
|
382
416
|
|
383
417
|
return true;
|
384
418
|
};
|
419
|
+
/**
|
420
|
+
* @param {string} item item
|
421
|
+
*/
|
385
422
|
const processItem = item => {
|
386
423
|
if (
|
387
424
|
item.startsWith("*") &&
|
@@ -14,7 +14,7 @@ class HotModuleReplacementRuntimeModule extends RuntimeModule {
|
|
14
14
|
super("hot module replacement", RuntimeModule.STAGE_BASIC);
|
15
15
|
}
|
16
16
|
/**
|
17
|
-
* @returns {string} runtime code
|
17
|
+
* @returns {string | null} runtime code
|
18
18
|
*/
|
19
19
|
generate() {
|
20
20
|
return Template.getFunctionContent(
|
@@ -63,6 +63,7 @@ class SyncModuleIdsPlugin {
|
|
63
63
|
if (this._write) {
|
64
64
|
compiler.hooks.emitRecords.tapAsync(plugin, callback => {
|
65
65
|
if (!data || !dataChanged) return callback();
|
66
|
+
/** @type {Object<string, string | number>} */
|
66
67
|
const json = {};
|
67
68
|
const sorted = Array.from(data).sort(([a], [b]) => (a < b ? -1 : 1));
|
68
69
|
for (const [key, value] of sorted) {
|
@@ -5,7 +5,8 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
-
/** @typedef {import("estree").Node}
|
8
|
+
/** @typedef {import("estree").Node} Node */
|
9
|
+
/** @typedef {import("./JavascriptParser").Range} Range */
|
9
10
|
/** @typedef {import("./JavascriptParser").VariableInfoInterface} VariableInfoInterface */
|
10
11
|
|
11
12
|
const TypeUnknown = 0;
|
@@ -26,7 +27,7 @@ const TypeBigInt = 13;
|
|
26
27
|
class BasicEvaluatedExpression {
|
27
28
|
constructor() {
|
28
29
|
this.type = TypeUnknown;
|
29
|
-
/** @type {[number, number]} */
|
30
|
+
/** @type {[number, number] | undefined} */
|
30
31
|
this.range = undefined;
|
31
32
|
/** @type {boolean} */
|
32
33
|
this.falsy = false;
|
@@ -56,23 +57,23 @@ class BasicEvaluatedExpression {
|
|
56
57
|
this.items = undefined;
|
57
58
|
/** @type {BasicEvaluatedExpression[] | undefined} */
|
58
59
|
this.options = undefined;
|
59
|
-
/** @type {BasicEvaluatedExpression | undefined} */
|
60
|
+
/** @type {BasicEvaluatedExpression | undefined | null} */
|
60
61
|
this.prefix = undefined;
|
61
|
-
/** @type {BasicEvaluatedExpression | undefined} */
|
62
|
+
/** @type {BasicEvaluatedExpression | undefined | null} */
|
62
63
|
this.postfix = undefined;
|
63
|
-
/** @type {BasicEvaluatedExpression[]} */
|
64
|
+
/** @type {BasicEvaluatedExpression[] | undefined} */
|
64
65
|
this.wrappedInnerExpressions = undefined;
|
65
66
|
/** @type {string | VariableInfoInterface | undefined} */
|
66
67
|
this.identifier = undefined;
|
67
|
-
/** @type {string | VariableInfoInterface} */
|
68
|
+
/** @type {string | VariableInfoInterface | undefined} */
|
68
69
|
this.rootInfo = undefined;
|
69
|
-
/** @type {() => string[]} */
|
70
|
+
/** @type {(() => string[]) | undefined} */
|
70
71
|
this.getMembers = undefined;
|
71
|
-
/** @type {() => boolean[]} */
|
72
|
+
/** @type {(() => boolean[]) | undefined} */
|
72
73
|
this.getMembersOptionals = undefined;
|
73
|
-
/** @type {() =>
|
74
|
-
this.
|
75
|
-
/** @type {
|
74
|
+
/** @type {(() => Range[]) | undefined} */
|
75
|
+
this.getMemberRanges = undefined;
|
76
|
+
/** @type {Node | undefined} */
|
76
77
|
this.expression = undefined;
|
77
78
|
}
|
78
79
|
|
@@ -292,7 +293,9 @@ class BasicEvaluatedExpression {
|
|
292
293
|
if (this.isRegExp()) return `${this.regExp}`;
|
293
294
|
if (this.isArray()) {
|
294
295
|
let array = [];
|
295
|
-
for (const item of
|
296
|
+
for (const item of /** @type {BasicEvaluatedExpression[]} */ (
|
297
|
+
this.items
|
298
|
+
)) {
|
296
299
|
const itemStr = item.asString();
|
297
300
|
if (itemStr === undefined) return undefined;
|
298
301
|
array.push(itemStr);
|
@@ -302,7 +305,9 @@ class BasicEvaluatedExpression {
|
|
302
305
|
if (this.isConstArray()) return `${this.array}`;
|
303
306
|
if (this.isTemplateString()) {
|
304
307
|
let str = "";
|
305
|
-
for (const part of
|
308
|
+
for (const part of /** @type {BasicEvaluatedExpression[]} */ (
|
309
|
+
this.parts
|
310
|
+
)) {
|
306
311
|
const partStr = part.asString();
|
307
312
|
if (partStr === undefined) return undefined;
|
308
313
|
str += partStr;
|
@@ -312,6 +317,10 @@ class BasicEvaluatedExpression {
|
|
312
317
|
return undefined;
|
313
318
|
}
|
314
319
|
|
320
|
+
/**
|
321
|
+
* @param {string} string value
|
322
|
+
* @returns {BasicEvaluatedExpression} basic evaluated expression
|
323
|
+
*/
|
315
324
|
setString(string) {
|
316
325
|
this.type = TypeString;
|
317
326
|
this.string = string;
|
@@ -386,7 +395,7 @@ class BasicEvaluatedExpression {
|
|
386
395
|
* @param {string | VariableInfoInterface} rootInfo root info
|
387
396
|
* @param {() => string[]} getMembers members
|
388
397
|
* @param {() => boolean[]=} getMembersOptionals optional members
|
389
|
-
* @param {() =>
|
398
|
+
* @param {() => Range[]=} getMemberRanges ranges of progressively increasing sub-expressions
|
390
399
|
* @returns {this} this
|
391
400
|
*/
|
392
401
|
setIdentifier(
|
@@ -394,14 +403,14 @@ class BasicEvaluatedExpression {
|
|
394
403
|
rootInfo,
|
395
404
|
getMembers,
|
396
405
|
getMembersOptionals,
|
397
|
-
|
406
|
+
getMemberRanges
|
398
407
|
) {
|
399
408
|
this.type = TypeIdentifier;
|
400
409
|
this.identifier = identifier;
|
401
410
|
this.rootInfo = rootInfo;
|
402
411
|
this.getMembers = getMembers;
|
403
412
|
this.getMembersOptionals = getMembersOptionals;
|
404
|
-
this.
|
413
|
+
this.getMemberRanges = getMemberRanges;
|
405
414
|
this.sideEffects = true;
|
406
415
|
return this;
|
407
416
|
}
|
@@ -409,8 +418,8 @@ class BasicEvaluatedExpression {
|
|
409
418
|
/**
|
410
419
|
* Wraps an array of expressions with a prefix and postfix expression.
|
411
420
|
*
|
412
|
-
* @param {BasicEvaluatedExpression | null} prefix Expression to be added before the innerExpressions
|
413
|
-
* @param {BasicEvaluatedExpression} postfix Expression to be added after the innerExpressions
|
421
|
+
* @param {BasicEvaluatedExpression | null | undefined} prefix Expression to be added before the innerExpressions
|
422
|
+
* @param {BasicEvaluatedExpression | null | undefined} postfix Expression to be added after the innerExpressions
|
414
423
|
* @param {BasicEvaluatedExpression[]} innerExpressions Expressions to be wrapped
|
415
424
|
* @returns {this} this
|
416
425
|
*/
|
@@ -550,7 +559,7 @@ class BasicEvaluatedExpression {
|
|
550
559
|
/**
|
551
560
|
* Set the expression node for the expression.
|
552
561
|
*
|
553
|
-
* @param {
|
562
|
+
* @param {Node | undefined} expression expression
|
554
563
|
* @returns {this} this
|
555
564
|
*/
|
556
565
|
setExpression(expression) {
|
@@ -17,7 +17,9 @@ const {
|
|
17
17
|
updateHashForEntryStartup
|
18
18
|
} = require("./StartupHelpers");
|
19
19
|
|
20
|
+
/** @typedef {import("../Chunk")} Chunk */
|
20
21
|
/** @typedef {import("../Compiler")} Compiler */
|
22
|
+
/** @typedef {import("../Entrypoint")} Entrypoint */
|
21
23
|
|
22
24
|
class CommonJsChunkFormatPlugin {
|
23
25
|
/**
|
@@ -66,7 +68,9 @@ class CommonJsChunkFormatPlugin {
|
|
66
68
|
chunkGraph.getChunkEntryModulesWithChunkGroupIterable(chunk)
|
67
69
|
);
|
68
70
|
if (entries.length > 0) {
|
69
|
-
const runtimeChunk =
|
71
|
+
const runtimeChunk =
|
72
|
+
/** @type {Entrypoint} */
|
73
|
+
(entries[0][1]).getRuntimeChunk();
|
70
74
|
const currentOutputName = compilation
|
71
75
|
.getPath(
|
72
76
|
getChunkFilenameTemplate(chunk, compilation.outputOptions),
|
@@ -83,7 +87,7 @@ class CommonJsChunkFormatPlugin {
|
|
83
87
|
compilation.outputOptions
|
84
88
|
),
|
85
89
|
{
|
86
|
-
chunk: runtimeChunk,
|
90
|
+
chunk: /** @type {Chunk} */ (runtimeChunk),
|
87
91
|
contentHashType: "javascript"
|
88
92
|
}
|
89
93
|
)
|
@@ -60,14 +60,27 @@ const chunkHasJs = (chunk, chunkGraph) => {
|
|
60
60
|
: false;
|
61
61
|
};
|
62
62
|
|
63
|
+
/**
|
64
|
+
* @param {Module} module a module
|
65
|
+
* @param {string} code the code
|
66
|
+
* @returns {string} generated code for the stack
|
67
|
+
*/
|
63
68
|
const printGeneratedCodeForStack = (module, code) => {
|
64
69
|
const lines = code.split("\n");
|
65
70
|
const n = `${lines.length}`.length;
|
66
71
|
return `\n\nGenerated code for ${module.identifier()}\n${lines
|
67
|
-
.map(
|
68
|
-
|
69
|
-
|
70
|
-
|
72
|
+
.map(
|
73
|
+
/**
|
74
|
+
* @param {string} line the line
|
75
|
+
* @param {number} i the index
|
76
|
+
* @param {string[]} lines the lines
|
77
|
+
* @returns {string} the line with line number
|
78
|
+
*/
|
79
|
+
(line, i, lines) => {
|
80
|
+
const iStr = `${i + 1}`;
|
81
|
+
return `${" ".repeat(n - iStr.length)}${iStr} | ${line}`;
|
82
|
+
}
|
83
|
+
)
|
71
84
|
.join("\n")}`;
|
72
85
|
};
|
73
86
|
|
@@ -443,7 +456,10 @@ class JavascriptModulesPlugin {
|
|
443
456
|
context.__webpack_require__
|
444
457
|
);
|
445
458
|
} catch (e) {
|
446
|
-
e.stack += printGeneratedCodeForStack(
|
459
|
+
e.stack += printGeneratedCodeForStack(
|
460
|
+
options.module,
|
461
|
+
/** @type {string} */ (code)
|
462
|
+
);
|
447
463
|
throw e;
|
448
464
|
}
|
449
465
|
});
|
@@ -937,6 +953,7 @@ class JavascriptModulesPlugin {
|
|
937
953
|
"JavascriptModulesPlugin error: JavascriptModulesPlugin.getCompilationHooks().renderContent plugins should return something"
|
938
954
|
);
|
939
955
|
}
|
956
|
+
|
940
957
|
finalSource = InitFragment.addToSource(
|
941
958
|
finalSource,
|
942
959
|
chunkRenderContext.chunkInitFragments,
|
@@ -1006,6 +1023,9 @@ class JavascriptModulesPlugin {
|
|
1006
1023
|
const useRequire =
|
1007
1024
|
requireFunction || interceptModuleExecution || moduleUsed;
|
1008
1025
|
|
1026
|
+
/**
|
1027
|
+
* @type {{startup: string[], beforeStartup: string[], header: string[], afterStartup: string[], allowInlineStartup: boolean}}
|
1028
|
+
*/
|
1009
1029
|
const result = {
|
1010
1030
|
header: [],
|
1011
1031
|
beforeStartup: [],
|