webpack 5.112.0 → 5.112.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.
- package/bin/webpack.js +13 -7
- package/lib/Compilation.js +152 -60
- package/lib/Compiler.js +12 -25
- package/lib/asset/AssetBytesGenerator.js +14 -6
- package/lib/asset/AssetBytesParser.js +10 -8
- package/lib/asset/AssetGenerator.js +36 -48
- package/lib/asset/AssetModule.js +11 -0
- package/lib/asset/AssetModulesPlugin.js +5 -4
- package/lib/asset/AssetParser.js +8 -8
- package/lib/asset/AssetSourceGenerator.js +16 -8
- package/lib/asset/AssetSourceParser.js +10 -8
- package/lib/asset/WebManifestGenerator.js +11 -6
- package/lib/asset/WebManifestParser.js +3 -3
- package/lib/async-modules/AsyncModuleHelpers.js +8 -2
- package/lib/async-modules/InferAsyncModulesPlugin.js +7 -2
- package/lib/cache/CacheFacade.js +1 -1
- package/lib/cache/PackFileCacheStrategy.js +6 -10
- package/lib/cache/ResolverCachePlugin.js +58 -8
- package/lib/config/WebpackOptionsApply.js +8 -28
- package/lib/config/cli.js +9 -6
- package/lib/config/defaults.js +24 -13
- package/lib/config/getClaimedAssetTypes.js +2 -2
- package/lib/config/target.js +1 -1
- package/lib/context/ContextModule.js +1 -1
- package/lib/context/ContextModuleFactory.js +1 -1
- package/lib/context/ContextReplacementPlugin.js +3 -9
- package/lib/css/CssGenerator.js +40 -37
- package/lib/css/CssModule.js +10 -0
- package/lib/css/CssModulesPlugin.js +2 -2
- package/lib/css/CssParser.js +33 -32
- package/lib/css/conventions.js +1 -1
- package/lib/css/data.js +224 -219
- package/lib/css/syntax-parser.js +1159 -298
- package/lib/css/syntax-printer.js +90 -35
- package/lib/debug/ProfilingPlugin.js +65 -43
- package/lib/define/DefinePlugin.js +10 -15
- package/lib/define/DotenvPlugin.js +10 -6
- package/lib/define/EnvironmentPlugin.js +4 -2
- package/lib/dependencies/amd/AMDDefineDependencyParserPlugin.js +1 -2
- package/lib/dependencies/amd/AMDRequireDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/commonjs/CommonJsExportRequireDependency.js +1 -4
- package/lib/dependencies/commonjs/CommonJsExportsParserPlugin.js +18 -33
- package/lib/dependencies/commonjs/CommonJsImportsParserPlugin.js +1 -3
- package/lib/dependencies/commonjs/CommonJsObjectExportDependency.js +4 -4
- package/lib/dependencies/commonjs/CommonJsPlugin.js +2 -5
- package/lib/dependencies/commonjs/RequireEnsureDependenciesBlockParserPlugin.js +4 -1
- package/lib/dependencies/context/ImportMetaContextDependencyParserPlugin.js +1 -2
- package/lib/dependencies/context/ImportMetaGlobDependencyParserPlugin.js +4 -7
- package/lib/dependencies/context/ImportMetaGlobHelpers.js +8 -10
- package/lib/dependencies/core/CachedConstDependency.js +9 -6
- package/lib/dependencies/css/CssIcssExportDependency.js +6 -7
- package/lib/dependencies/css/CssIcssImportDependency.js +1 -3
- package/lib/dependencies/css/CssUrlDependency.js +2 -6
- package/lib/dependencies/esm/ESMDetectionParserPlugin.js +2 -4
- package/lib/dependencies/esm/ESMExportExpressionDependency.js +2 -2
- package/lib/dependencies/esm/ESMExportImportedSpecifierDependency.js +16 -18
- package/lib/dependencies/esm/ESMExportSpecifierDependency.js +20 -3
- package/lib/dependencies/esm/ESMExports.js +2 -10
- package/lib/dependencies/esm/ESMImportDependency.js +17 -2
- package/lib/dependencies/esm/ESMImportDependencyParserPlugin.js +6 -17
- package/lib/dependencies/esm/ESMImportGuard.js +11 -23
- package/lib/dependencies/esm/ESMImportSideEffectDependency.js +1 -1
- package/lib/dependencies/esm/ESMImportSpecifierDependency.js +4 -1
- package/lib/dependencies/esm/ESMLiveExportDependency.js +311 -0
- package/lib/dependencies/esm/ESMLiveExportParserPlugin.js +862 -0
- package/lib/dependencies/esm/ESMModulesPlugin.js +1 -3
- package/lib/dependencies/esm/TopLevelAwaitDependency.js +1 -8
- package/lib/dependencies/helpers/DynamicExports.js +4 -6
- package/lib/dependencies/html/HtmlEntryDependency.js +5 -14
- package/lib/dependencies/html/HtmlInlineHtmlDependency.js +1 -4
- package/lib/dependencies/html/HtmlInlineScriptDependency.js +2 -6
- package/lib/dependencies/html/HtmlInlineStyleDependency.js +1 -4
- package/lib/dependencies/import/ImportParserPlugin.js +3 -6
- package/lib/dependencies/import-meta/ImportMetaPlugin.js +4 -6
- package/lib/dependencies/url/URLParserPlugin.js +1 -1
- package/lib/dependencies/worker/WorkerAndWorkletPlugin.js +51 -20
- package/lib/devtool/ModuleFilenameHelpers.js +1 -1
- package/lib/devtool/SourceMapDevToolPlugin.js +1 -1
- package/lib/dll/DelegatedModule.js +3 -3
- package/lib/dll/DllModule.js +3 -1
- package/lib/dll/DllReferencePlugin.js +1 -4
- package/lib/errors/AbstractMethodError.js +1 -1
- package/lib/errors/ErrorHelpers.js +2 -1
- package/lib/errors/HookWebpackError.js +2 -1
- package/lib/errors/JSONParseError.js +4 -4
- package/lib/errors/WebpackError.js +3 -2
- package/lib/esm/ModuleChunkFormatPlugin.js +36 -1
- package/lib/externals/ExternalModule.js +12 -9
- package/lib/externals/ExternalModuleFactoryPlugin.js +1 -2
- package/lib/externals/ExternalsPlugin.js +1 -1
- package/lib/fs/FileSystemInfo.js +4 -4
- package/lib/graph/AsyncDependenciesBlock.js +1 -1
- package/lib/graph/ChunkGraph.js +5 -0
- package/lib/graph/Dependency.js +8 -2
- package/lib/graph/ExportsInfo.js +1 -1
- package/lib/graph/ModuleGraph.js +14 -3
- package/lib/graph/buildChunkGraph.js +17 -19
- package/lib/graph/findGraphRoots.js +1 -1
- package/lib/hmr/HotModuleReplacement.runtime.js +10 -9
- package/lib/hmr/HotModuleReplacementPlugin.js +5 -11
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +16 -19
- package/lib/hmr/LazyCompilationPlugin.js +1 -7
- package/lib/html/HtmlGenerator.js +25 -17
- package/lib/html/HtmlModule.js +11 -1
- package/lib/html/HtmlModulesPlugin.js +12 -11
- package/lib/html/HtmlParser.js +10 -9
- package/lib/html/builtinEmbeddedRenderer.js +31 -33
- package/lib/html/data.js +42 -21
- package/lib/html/htmlMinify.js +4 -1
- package/lib/html/syntax-parser.js +34 -35
- package/lib/html/syntax-printer.js +2 -3
- package/lib/html/xmlMinify.js +4 -1
- package/lib/ids/HashedModuleIdsPlugin.js +1 -1
- package/lib/index.js +13 -12
- package/lib/javascript/APIPlugin.js +7 -13
- package/lib/javascript/BasicEvaluatedExpression.js +5 -5
- package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -7
- package/lib/javascript/ConstPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +16 -11
- package/lib/javascript/JavascriptMetaInfoPlugin.js +3 -15
- package/lib/javascript/JavascriptModule.js +10 -0
- package/lib/javascript/JavascriptModulesPlugin.js +2 -4
- package/lib/javascript/JavascriptParser.js +99 -11
- package/lib/javascript/ScopeAnalyzer.js +183 -107
- package/lib/javascript/UseStrictPlugin.js +2 -5
- package/lib/javascript/jsMinify.js +1 -1
- package/lib/javascript/regexp.js +2 -2
- package/lib/javascript/syntax-parser.js +2114 -1506
- package/lib/javascript/syntax-printer-data.js +167 -1
- package/lib/javascript/syntax-printer.js +9554 -2782
- package/lib/json/JsonGenerator.js +15 -7
- package/lib/json/JsonModule.js +11 -0
- package/lib/json/JsonParser.js +7 -6
- package/lib/library/AssignLibraryPlugin.js +1 -1
- package/lib/library/JsonpLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +399 -23
- package/lib/loaders/LoaderRunner.js +76 -38
- package/lib/loaders/loadLoader.js +16 -10
- package/lib/module/Generator.js +17 -9
- package/lib/module/Module.js +2 -2
- package/lib/module/NormalModule.js +7 -5
- package/lib/module/NormalModuleFactory.js +11 -17
- package/lib/module/Parser.js +9 -2
- package/lib/module/extractSourceMap.js +69 -18
- package/lib/module/findCaseMismatch.js +2 -2
- package/lib/node/ExternalModuleInitFragment.js +2 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +4 -12
- package/lib/node/ReadFileCompileWasmPlugin.js +2 -6
- package/lib/node/nodeConsole.js +4 -3
- package/lib/optimize/CircularModulesPlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +2 -6
- package/lib/optimize/FlagDependencyExportsPlugin.js +6 -11
- package/lib/optimize/FlagDependencyUsagePlugin.js +28 -3
- package/lib/optimize/InlineExports.js +4 -7
- package/lib/optimize/LazyBarrels.js +41 -5
- package/lib/optimize/ModuleConcatenationPlugin.js +8 -10
- package/lib/optimize/RealContentHashPlugin.js +2 -6
- package/lib/optimize/SideEffectsFlagPlugin.js +7 -21
- package/lib/optimize/SplitChunksPlugin.js +11 -24
- package/lib/optimize/TupleQueue.js +1 -1
- package/lib/output/CleanPlugin.js +3 -1
- package/lib/output/CopyPlugin.js +3 -4
- package/lib/performance/EvalUsagePlugin.js +1 -3
- package/lib/performance/HotspotsPlugin.js +33 -9
- package/lib/performance/PureAnnotationsPlugin.js +16 -10
- package/lib/performance/TopLevelThisPlugin.js +17 -9
- package/lib/prefetch/ResourceHintPlugin.js +1 -1
- package/lib/provide/ProvidedDependency.js +36 -4
- package/lib/rules/BasicEffectRulePlugin.js +1 -1
- package/lib/rules/RuleSetCompiler.js +15 -5
- package/lib/rules/UseEffectRulePlugin.js +1 -3
- package/lib/runtime/AsyncModuleRuntimeModule.js +7 -1
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -5
- package/lib/runtime/RuntimeGlobals.js +6 -0
- package/lib/runtime/RuntimePlugin.js +2 -0
- package/lib/schemes/HttpUriPlugin.js +1 -2
- package/lib/schemes/VirtualUrlPlugin.js +3 -1
- package/lib/serialization/AggregateErrorSerializer.js +3 -3
- package/lib/serialization/BinaryMiddleware.js +4 -1
- package/lib/serialization/ErrorObjectSerializer.js +2 -5
- package/lib/serialization/ObjectMiddleware.js +17 -15
- package/lib/serialization/PlainObjectSerializer.js +3 -7
- package/lib/serialization/Serializer.js +21 -11
- package/lib/serialization/SerializerMiddleware.js +8 -6
- package/lib/stats/DefaultStatsFactoryPlugin.js +35 -35
- package/lib/stats/DefaultStatsPresetPlugin.js +2 -6
- package/lib/stats/DefaultStatsPrinterPlugin.js +12 -11
- package/lib/stats/StatsFactory.js +194 -24
- package/lib/stats/StatsPrinter.js +126 -13
- package/lib/template/DependencyTemplate.js +1 -1
- package/lib/template/RuntimeTemplate.js +13 -32
- package/lib/template/Template.js +1 -1
- package/lib/util/SourceProcessor.js +98 -15
- package/lib/util/WeakTupleMap.js +10 -4
- package/lib/util/cleverMerge.js +61 -33
- package/lib/util/comparators.js +9 -5
- package/lib/util/dataURL.js +2 -0
- package/lib/util/deprecation.js +4 -3
- package/lib/util/globUtils.js +1 -4
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/makeSerializable.js +6 -4
- package/lib/util/memoize.js +1 -1
- package/lib/util/parseJson.js +2 -2
- package/lib/util/serialization.js +31 -27
- package/lib/wasm/AsyncWasmModule.js +12 -2
- package/lib/wasm/AsyncWebAssemblyGenerator.js +12 -4
- package/lib/wasm/AsyncWebAssemblyJavascriptGenerator.js +13 -5
- package/lib/wasm/AsyncWebAssemblyParser.js +7 -5
- package/lib/wasm/UniversalCompileAsyncWasmPlugin.js +2 -6
- package/lib/wasm-sync/SyncWasmModule.js +16 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +15 -10
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +13 -5
- package/lib/wasm-sync/WebAssemblyParser.js +10 -12
- package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -12
- package/lib/web/FetchCompileWasmPlugin.js +2 -6
- package/package.json +16 -18
- package/schemas/WebpackOptions.check.js +3 -3
- package/schemas/WebpackOptions.json +2 -2
- package/schemas/plugins/BannerPlugin.check.js +3 -3
- package/schemas/plugins/HtmlGeneratorOptions.check.js +3 -3
- package/schemas/plugins/HtmlParserOptions.check.js +3 -3
- package/schemas/plugins/IgnorePlugin.check.js +3 -3
- package/schemas/plugins/LoaderOptionsPlugin.check.js +3 -3
- package/schemas/plugins/ManifestPlugin.check.js +3 -3
- package/schemas/plugins/ProgressPlugin.check.js +3 -3
- package/schemas/plugins/SSRManifestPlugin.check.js +3 -3
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +3 -3
- package/schemas/plugins/WatchIgnorePlugin.check.js +3 -3
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetParserOptions.check.js +3 -3
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +3 -3
- package/schemas/plugins/container/ContainerPlugin.check.js +3 -3
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +3 -3
- package/schemas/plugins/container/ExternalsType.check.js +3 -3
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +3 -3
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +3 -3
- package/schemas/plugins/css/CssGeneratorOptions.check.js +3 -3
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +3 -3
- package/schemas/plugins/css/CssModuleParserOptions.check.js +3 -3
- package/schemas/plugins/css/CssParserOptions.check.js +3 -3
- package/schemas/plugins/debug/ProfilingPlugin.check.js +3 -3
- package/schemas/plugins/define/DotenvPluginOptions.check.js +7 -0
- package/schemas/plugins/define/DotenvPluginOptions.json +3 -0
- package/schemas/plugins/dll/DllPlugin.check.js +3 -3
- package/schemas/plugins/dll/DllReferencePlugin.check.js +3 -3
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +3 -3
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +3 -3
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +3 -3
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +3 -3
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +3 -3
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +3 -3
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +3 -3
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +3 -3
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +3 -3
- package/schemas/plugins/output/CleanOptions.check.js +7 -0
- package/schemas/plugins/output/CleanOptions.json +3 -0
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +3 -3
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +3 -3
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +3 -3
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +3 -3
- package/schemas/plugins/sharing/SharePlugin.check.js +3 -3
- package/types.d.ts +1482 -358
|
@@ -36,7 +36,6 @@ const TopLevelAwaitDependency = require("./TopLevelAwaitDependency");
|
|
|
36
36
|
*/
|
|
37
37
|
/** @import Compiler from "../../Compiler" */
|
|
38
38
|
/** @import Parser from "../../javascript/JavascriptParser" */
|
|
39
|
-
/** @import { BuildInfo } from "../../module/Module" */
|
|
40
39
|
|
|
41
40
|
/**
|
|
42
41
|
* Defines the harmony modules plugin options type used by this module.
|
|
@@ -179,8 +178,7 @@ class ESMModulesPlugin {
|
|
|
179
178
|
// Recorded on the module, because an importer asks the module it
|
|
180
179
|
// imports whether its namespace is a spec exotic object.
|
|
181
180
|
parser.hooks.program.tap(PLUGIN_NAME, () => {
|
|
182
|
-
|
|
183
|
-
(parser.state.module.buildInfo).specNamespaceObject = true;
|
|
181
|
+
parser.state.module.buildInfo.specNamespaceObject = true;
|
|
184
182
|
});
|
|
185
183
|
}
|
|
186
184
|
|
|
@@ -11,7 +11,6 @@ const NullDependency = require("../core/NullDependency");
|
|
|
11
11
|
/** @import { ReplaceSource } from "webpack-sources" */
|
|
12
12
|
/** @import Dependency from "../../graph/Dependency" */
|
|
13
13
|
/** @import { DependencyTemplateContext } from "../../template/DependencyTemplate" */
|
|
14
|
-
/** @import Module from "../../module/Module" */
|
|
15
14
|
/** @import { Range } from "../../javascript/JavascriptParser" */
|
|
16
15
|
/**
|
|
17
16
|
* @import {
|
|
@@ -80,13 +79,7 @@ TopLevelAwaitDependency.Template = class TopLevelAwaitDependencyTemplate extends
|
|
|
80
79
|
// Only rewrite when the body is a generator (no `async`/`await`, but
|
|
81
80
|
// generators). `await` and `yield` differ in precedence, so wrap the
|
|
82
81
|
// whole expression: `await X` -> `(yield X)`.
|
|
83
|
-
if (
|
|
84
|
-
!isGeneratorLowered(
|
|
85
|
-
/** @type {Module} */ (module),
|
|
86
|
-
moduleGraph,
|
|
87
|
-
runtimeTemplate
|
|
88
|
-
)
|
|
89
|
-
) {
|
|
82
|
+
if (!isGeneratorLowered(module, moduleGraph, runtimeTemplate)) {
|
|
90
83
|
return;
|
|
91
84
|
}
|
|
92
85
|
const dep = /** @type {TopLevelAwaitDependency} */ (dependency);
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
-
/** @import { BuildMeta } from "../../module/Module" */
|
|
9
8
|
/** @import { JavascriptParserState } from "../../javascript/JavascriptParser" */
|
|
10
9
|
|
|
11
10
|
/** @type {WeakMap<JavascriptParserState, boolean>} */
|
|
@@ -20,7 +19,7 @@ module.exports.bailout = (parserState) => {
|
|
|
20
19
|
const value = parserStateExportsState.get(parserState);
|
|
21
20
|
parserStateExportsState.set(parserState, false);
|
|
22
21
|
if (value === true) {
|
|
23
|
-
const buildMeta =
|
|
22
|
+
const buildMeta = parserState.module.buildMeta;
|
|
24
23
|
buildMeta.exportsType = undefined;
|
|
25
24
|
buildMeta.defaultObject = false;
|
|
26
25
|
}
|
|
@@ -36,7 +35,7 @@ module.exports.enable = (parserState) => {
|
|
|
36
35
|
if (value === false) return;
|
|
37
36
|
parserStateExportsState.set(parserState, true);
|
|
38
37
|
if (value !== true) {
|
|
39
|
-
const buildMeta =
|
|
38
|
+
const buildMeta = parserState.module.buildMeta;
|
|
40
39
|
buildMeta.exportsType = "default";
|
|
41
40
|
buildMeta.defaultObject = "redirect";
|
|
42
41
|
}
|
|
@@ -60,8 +59,7 @@ module.exports.isEnabled = (parserState) => {
|
|
|
60
59
|
module.exports.setDynamic = (parserState) => {
|
|
61
60
|
const value = parserStateExportsState.get(parserState);
|
|
62
61
|
if (value !== true) return;
|
|
63
|
-
|
|
64
|
-
(parserState.module.buildMeta).exportsType = "dynamic";
|
|
62
|
+
parserState.module.buildMeta.exportsType = "dynamic";
|
|
65
63
|
};
|
|
66
64
|
|
|
67
65
|
/**
|
|
@@ -72,7 +70,7 @@ module.exports.setDynamic = (parserState) => {
|
|
|
72
70
|
module.exports.setFlagged = (parserState) => {
|
|
73
71
|
const value = parserStateExportsState.get(parserState);
|
|
74
72
|
if (value !== true) return;
|
|
75
|
-
const buildMeta =
|
|
73
|
+
const buildMeta = parserState.module.buildMeta;
|
|
76
74
|
if (buildMeta.exportsType === "dynamic") return;
|
|
77
75
|
buildMeta.exportsType = "flagged";
|
|
78
76
|
};
|
|
@@ -192,7 +192,7 @@ class HtmlEntryDependency extends ModuleDependency {
|
|
|
192
192
|
* HTML contains tags for both the leader and the dependant entries.
|
|
193
193
|
*/
|
|
194
194
|
const getEntrypointChunksInLoadOrder = (entrypoint) => {
|
|
195
|
-
const entryChunk =
|
|
195
|
+
const entryChunk = entrypoint.getEntrypointChunk();
|
|
196
196
|
const runtimeChunk = entrypoint.getRuntimeChunk();
|
|
197
197
|
|
|
198
198
|
/** @type {Set<Chunk>} */
|
|
@@ -679,9 +679,7 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
|
|
|
679
679
|
|
|
680
680
|
const { chunkGraph } = compilation;
|
|
681
681
|
const { crossOriginLoading } = compilation.outputOptions;
|
|
682
|
-
const entrypoint =
|
|
683
|
-
compilation.entrypoints.get(dep.entryName)
|
|
684
|
-
);
|
|
682
|
+
const entrypoint = compilation.entrypoints.get(dep.entryName);
|
|
685
683
|
|
|
686
684
|
if (!entrypoint) {
|
|
687
685
|
source.replace(dep.range[0], dep.range[1] - 1, "data:,");
|
|
@@ -783,9 +781,7 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
|
|
|
783
781
|
// Only inline when the HTML module is emitted as a standalone page (extract mode).
|
|
784
782
|
// If it's exported as a JS string, sentinels would end up embedded in the JS chunk.
|
|
785
783
|
const isExtractedHtml = chunkGraph
|
|
786
|
-
.getModuleSourceTypes(
|
|
787
|
-
/** @type {import("../../module/Module")} */ (templateContext.module)
|
|
788
|
-
)
|
|
784
|
+
.getModuleSourceTypes(templateContext.module)
|
|
789
785
|
.has("html");
|
|
790
786
|
const entryInlined =
|
|
791
787
|
isExtractedHtml &&
|
|
@@ -956,10 +952,7 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
|
|
|
956
952
|
if (hasCss) {
|
|
957
953
|
cssChunks.push(chunk);
|
|
958
954
|
}
|
|
959
|
-
|
|
960
|
-
// preserving the runtime-first invariant. A chunk emitting neither
|
|
961
|
-
// `.js` nor `.css` still gets a clone, as it always has.
|
|
962
|
-
if (hasJs || !hasCss) jsChunks.push(chunk);
|
|
955
|
+
if (hasJs) jsChunks.push(chunk);
|
|
963
956
|
}
|
|
964
957
|
// When the entry chunk carries CSS itself, fold it into the same
|
|
965
958
|
// ordering so its `<link>` lands in the right cascade position
|
|
@@ -1113,9 +1106,7 @@ HtmlEntryDependency.Template = class HtmlEntryDependencyTemplate extends (
|
|
|
1113
1106
|
// `<script>` entry — that's what users key on.
|
|
1114
1107
|
let entryName = dep.entryName;
|
|
1115
1108
|
for (const c of chunkGraph.getModuleChunks(
|
|
1116
|
-
|
|
1117
|
-
templateContext.module
|
|
1118
|
-
)
|
|
1109
|
+
templateContext.module
|
|
1119
1110
|
)) {
|
|
1120
1111
|
if (c.name) {
|
|
1121
1112
|
entryName = c.name;
|
|
@@ -9,7 +9,6 @@ const makeSerializable = require("../../util/makeSerializable");
|
|
|
9
9
|
const ModuleDependency = require("../core/ModuleDependency");
|
|
10
10
|
|
|
11
11
|
/** @import { ReplaceSource } from "webpack-sources" */
|
|
12
|
-
/** @import CodeGenerationResults from "../../module/CodeGenerationResults" */
|
|
13
12
|
/** @import Dependency, { UpdateHashContext } from "../../graph/Dependency" */
|
|
14
13
|
/** @import { DependencyTemplateContext } from "../../template/DependencyTemplate" */
|
|
15
14
|
/** @import Module from "../../module/Module" */
|
|
@@ -83,9 +82,7 @@ HtmlInlineHtmlDependency.Template = class HtmlInlineHtmlDependencyTemplate exten
|
|
|
83
82
|
const dep = /** @type {HtmlInlineHtmlDependency} */ (dependency);
|
|
84
83
|
// The module is guaranteed — it is registered as a code-generation dependency.
|
|
85
84
|
const module = /** @type {Module} */ (moduleGraph.getModule(dep));
|
|
86
|
-
const codeGen =
|
|
87
|
-
/** @type {CodeGenerationResults} */
|
|
88
|
-
(codeGenerationResults).get(module, runtime);
|
|
85
|
+
const codeGen = codeGenerationResults.get(module, runtime);
|
|
89
86
|
const htmlSource = codeGen.sources.get(HTML_TYPE);
|
|
90
87
|
|
|
91
88
|
// The attribute value was entity-decoded before parsing, so re-escape the
|
|
@@ -12,10 +12,8 @@ const ModuleDependency = require("../core/ModuleDependency");
|
|
|
12
12
|
const getHtmlGenerator = memoize(() => require("../../html/HtmlGenerator"));
|
|
13
13
|
|
|
14
14
|
/** @import { ReplaceSource } from "webpack-sources" */
|
|
15
|
-
/** @import Chunk from "../../graph/Chunk" */
|
|
16
15
|
/** @import Dependency from "../../graph/Dependency" */
|
|
17
16
|
/** @import { DependencyTemplateContext } from "../../template/DependencyTemplate" */
|
|
18
|
-
/** @import Entrypoint from "../../graph/Entrypoint" */
|
|
19
17
|
/** @import { Range } from "../../javascript/JavascriptParser" */
|
|
20
18
|
/** @typedef {import("../../serialization/ObjectMiddleware").ObjectDeserializerContext<[number, Range, string, string, Range | undefined, boolean]>} ObjectDeserializerContext */
|
|
21
19
|
/** @typedef {import("../../serialization/ObjectMiddleware").ObjectSerializerContext<[number, Range, string, string, Range | undefined, boolean]>} ObjectSerializerContext */
|
|
@@ -124,15 +122,13 @@ HtmlInlineScriptDependency.Template = class HtmlInlineScriptDependencyTemplate e
|
|
|
124
122
|
return;
|
|
125
123
|
}
|
|
126
124
|
const compilation = runtimeTemplate.compilation;
|
|
127
|
-
const entrypoint =
|
|
128
|
-
compilation.entrypoints.get(dep.entryName)
|
|
129
|
-
);
|
|
125
|
+
const entrypoint = compilation.entrypoints.get(dep.entryName);
|
|
130
126
|
|
|
131
127
|
/** @type {string} */
|
|
132
128
|
let url = "data:,";
|
|
133
129
|
|
|
134
130
|
if (entrypoint) {
|
|
135
|
-
const chunk =
|
|
131
|
+
const chunk = entrypoint.getEntrypointChunk();
|
|
136
132
|
// A sentinel only resolves in a page webpack emits; exported as a JS
|
|
137
133
|
// string it would ride along unresolved.
|
|
138
134
|
const isExtractedHtml = chunkGraph
|
|
@@ -9,7 +9,6 @@ const makeSerializable = require("../../util/makeSerializable");
|
|
|
9
9
|
const ModuleDependency = require("../core/ModuleDependency");
|
|
10
10
|
|
|
11
11
|
/** @import { ReplaceSource } from "webpack-sources" */
|
|
12
|
-
/** @import CodeGenerationResults from "../../module/CodeGenerationResults" */
|
|
13
12
|
/** @import Dependency, { UpdateHashContext } from "../../graph/Dependency" */
|
|
14
13
|
/** @import { DependencyTemplateContext } from "../../template/DependencyTemplate" */
|
|
15
14
|
/** @import Module from "../../module/Module" */
|
|
@@ -141,9 +140,7 @@ HtmlInlineStyleDependency.Template = class HtmlInlineStyleDependencyTemplate ext
|
|
|
141
140
|
let cssText = "";
|
|
142
141
|
|
|
143
142
|
if (module) {
|
|
144
|
-
const codeGen =
|
|
145
|
-
/** @type {CodeGenerationResults} */
|
|
146
|
-
(codeGenerationResults).get(module, runtime);
|
|
143
|
+
const codeGen = codeGenerationResults.get(module, runtime);
|
|
147
144
|
const cssTextSource = codeGen.sources.get(CSS_TEXT_TYPE);
|
|
148
145
|
if (cssTextSource) {
|
|
149
146
|
cssText = /** @type {string} */ (cssTextSource.source());
|
|
@@ -47,7 +47,6 @@ const getCommentCompilationWarning = memoize(() =>
|
|
|
47
47
|
/** @import { RawChunkGroupOptions } from "../../graph/ChunkGroup" */
|
|
48
48
|
/** @import { ContextMode } from "../../context/ContextModule" */
|
|
49
49
|
/** @import { RawReferencedExports } from "../../graph/Dependency" */
|
|
50
|
-
/** @import { BuildMeta } from "../../module/Module" */
|
|
51
50
|
/**
|
|
52
51
|
* @import JavascriptParser, {
|
|
53
52
|
* ImportExpression,
|
|
@@ -660,11 +659,9 @@ class ImportParserPlugin {
|
|
|
660
659
|
include,
|
|
661
660
|
exclude,
|
|
662
661
|
mode,
|
|
663
|
-
namespaceObject:
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
? "strict"
|
|
667
|
-
: true,
|
|
662
|
+
namespaceObject: parser.state.module.buildMeta.strictHarmonyModule
|
|
663
|
+
? "strict"
|
|
664
|
+
: true,
|
|
668
665
|
typePrefix: "import()",
|
|
669
666
|
category: "esm",
|
|
670
667
|
referencedExports: exports,
|
|
@@ -55,7 +55,7 @@ const WEBPACK_VERSION = Number.parseInt(
|
|
|
55
55
|
/** @import Compiler from "../../Compiler" */
|
|
56
56
|
/** @import { MergedDefinitionNode } from "../../define/DefinePlugin" */
|
|
57
57
|
/** @import { ValueCacheVersion } from "../../module/Module" */
|
|
58
|
-
/** @import NormalModule
|
|
58
|
+
/** @import NormalModule from "../../module/NormalModule" */
|
|
59
59
|
/**
|
|
60
60
|
* @import {
|
|
61
61
|
* JavascriptModuleBuildInfo
|
|
@@ -320,7 +320,7 @@ class ImportMetaPlugin {
|
|
|
320
320
|
.for(IMPORT_META)
|
|
321
321
|
.tap(PLUGIN_NAME, (metaProperty) => {
|
|
322
322
|
const dep = new ConstDependency(
|
|
323
|
-
|
|
323
|
+
importMetaName,
|
|
324
324
|
/** @type {Range} */ (metaProperty.range)
|
|
325
325
|
);
|
|
326
326
|
dep.loc = parser.getLocation(metaProperty);
|
|
@@ -381,9 +381,7 @@ class ImportMetaPlugin {
|
|
|
381
381
|
*/
|
|
382
382
|
const addDefinitionValueDependencies = () => {
|
|
383
383
|
if (definitionValueDependencies.size === 0) return;
|
|
384
|
-
const buildInfo =
|
|
385
|
-
parser.state.module.buildInfo
|
|
386
|
-
);
|
|
384
|
+
const buildInfo = parser.state.module.buildInfo;
|
|
387
385
|
const valueDependencies =
|
|
388
386
|
buildInfo.valueDependencies ||
|
|
389
387
|
(buildInfo.valueDependencies = new Map());
|
|
@@ -708,7 +706,7 @@ class ImportMetaPlugin {
|
|
|
708
706
|
parser.hooks.call
|
|
709
707
|
.for(IMPORT_META_RESOLVE)
|
|
710
708
|
.tap(PLUGIN_NAME, (expr) => {
|
|
711
|
-
const call =
|
|
709
|
+
const call = expr;
|
|
712
710
|
// Non-static forms are left untouched for runtime evaluation.
|
|
713
711
|
const request = getImportMetaResolveRequest(call, parser);
|
|
714
712
|
if (request === undefined) return;
|
|
@@ -182,7 +182,7 @@ class URLParserPlugin {
|
|
|
182
182
|
.setRange(/** @type {Range} */ (expr.range));
|
|
183
183
|
});
|
|
184
184
|
parser.hooks.new.for("URL").tap(PLUGIN_NAME, (_expr) => {
|
|
185
|
-
const expr =
|
|
185
|
+
const expr = _expr;
|
|
186
186
|
const { options: importOptions, errors: commentErrors } =
|
|
187
187
|
parser.parseCommentOptions(/** @type {Range} */ (expr.range));
|
|
188
188
|
|
|
@@ -464,10 +464,10 @@ class WorkerAndWorkletPlugin {
|
|
|
464
464
|
/**
|
|
465
465
|
* Handles a matched `new Worker(...)` expression.
|
|
466
466
|
* @param {CallExpression} expr expression
|
|
467
|
-
* @param {
|
|
467
|
+
* @param {string=} workerSyntax matched global constructor syntax
|
|
468
468
|
* @returns {boolean | void} true when handled
|
|
469
469
|
*/
|
|
470
|
-
const handleNewWorker = (expr,
|
|
470
|
+
const handleNewWorker = (expr, workerSyntax) => {
|
|
471
471
|
const parsedUrl = resolveWorkerUrl(expr);
|
|
472
472
|
if (!parsedUrl) return;
|
|
473
473
|
const { url, range, needNewUrl, arg1, arg2 } = parsedUrl;
|
|
@@ -547,9 +547,10 @@ class WorkerAndWorkletPlugin {
|
|
|
547
547
|
const dep = new WorkerDependency(url, range, {
|
|
548
548
|
publicPath: this._workerPublicPath,
|
|
549
549
|
needNewUrl,
|
|
550
|
-
workerConstructorRange:
|
|
551
|
-
|
|
552
|
-
|
|
550
|
+
workerConstructorRange:
|
|
551
|
+
workerSyntax === "Worker"
|
|
552
|
+
? /** @type {Range} */ (expr.callee.range)
|
|
553
|
+
: undefined,
|
|
553
554
|
resourceHint
|
|
554
555
|
});
|
|
555
556
|
dep.loc = parser.getLocation(expr);
|
|
@@ -588,18 +589,48 @@ class WorkerAndWorkletPlugin {
|
|
|
588
589
|
const type = this._module ? '"module"' : "undefined";
|
|
589
590
|
// `{ ...(opts), type }` is equivalent to `Object.assign({}, opts, { type })`
|
|
590
591
|
const useSpread = compilation.outputOptions.environment.spread;
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
592
|
+
let prefix = useSpread ? "{ ...(" : "Object.assign({}, ";
|
|
593
|
+
let suffix = useSpread
|
|
594
|
+
? `), type: ${type} }`
|
|
595
|
+
: `, { type: ${type} })`;
|
|
596
|
+
if (
|
|
597
|
+
workerSyntax !== undefined &&
|
|
598
|
+
(workerSyntax === "SharedWorker" ||
|
|
599
|
+
workerSyntax.endsWith(".SharedWorker"))
|
|
600
|
+
) {
|
|
601
|
+
const optionsExpression = /** @type {Expression} */ (arg2);
|
|
602
|
+
if (
|
|
603
|
+
optionsExpression.type === "Literal" &&
|
|
604
|
+
typeof optionsExpression.value === "string"
|
|
605
|
+
) {
|
|
606
|
+
prefix = this._module ? "{ name: " : "";
|
|
607
|
+
suffix = this._module ? `, type: ${type} }` : "";
|
|
608
|
+
} else {
|
|
609
|
+
const stringOptions = this._module
|
|
610
|
+
? `{ name: options, type: ${type} }`
|
|
611
|
+
: "options";
|
|
612
|
+
// Evaluate the argument once, outside the wrapper's scope.
|
|
613
|
+
prefix = `(${compilation.runtimeTemplate.returningFunction(
|
|
614
|
+
`typeof options === "string" ? ${stringOptions} : ${prefix}options${suffix}`,
|
|
615
|
+
"options"
|
|
616
|
+
)})((`;
|
|
617
|
+
suffix = "))";
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
if (prefix) {
|
|
621
|
+
const dep1 = new ConstDependency(
|
|
622
|
+
prefix,
|
|
623
|
+
/** @type {Range} */ (insertLocation)[0]
|
|
624
|
+
);
|
|
625
|
+
const dep2 = new ConstDependency(
|
|
626
|
+
suffix,
|
|
627
|
+
/** @type {Range} */ (insertLocation)[1]
|
|
628
|
+
);
|
|
629
|
+
dep1.loc = parser.getLocation(expr);
|
|
630
|
+
dep2.loc = parser.getLocation(expr);
|
|
631
|
+
parser.state.module.addPresentationalDependency(dep1);
|
|
632
|
+
parser.state.module.addPresentationalDependency(dep2);
|
|
633
|
+
}
|
|
603
634
|
} else if (insertType === "argument" && this._module) {
|
|
604
635
|
const dep = new ConstDependency(
|
|
605
636
|
', { type: "module" }',
|
|
@@ -687,7 +718,7 @@ class WorkerAndWorkletPlugin {
|
|
|
687
718
|
/**
|
|
688
719
|
* Registers the parser hooks matching a single syntax item.
|
|
689
720
|
* @param {string} item item
|
|
690
|
-
* @param {(expr: CallExpression,
|
|
721
|
+
* @param {(expr: CallExpression, workerSyntax?: string) => boolean | void} handle handler invoked on a match
|
|
691
722
|
* @param {symbol} specifierTag tag used for `*variable` syntax
|
|
692
723
|
*/
|
|
693
724
|
const processItem = (item, handle, specifierTag) => {
|
|
@@ -752,7 +783,7 @@ class WorkerAndWorkletPlugin {
|
|
|
752
783
|
} else {
|
|
753
784
|
parser.hooks.new
|
|
754
785
|
.for(item)
|
|
755
|
-
.tap(PLUGIN_NAME, (expr) => handle(expr, item
|
|
786
|
+
.tap(PLUGIN_NAME, (expr) => handle(expr, item));
|
|
756
787
|
}
|
|
757
788
|
}
|
|
758
789
|
};
|
|
@@ -761,7 +792,7 @@ class WorkerAndWorkletPlugin {
|
|
|
761
792
|
* Expands and registers a syntax list.
|
|
762
793
|
* @param {string[]} syntaxList syntax list (may contain "...")
|
|
763
794
|
* @param {string[]} defaultSyntax default syntax used for "..."
|
|
764
|
-
* @param {(expr: CallExpression,
|
|
795
|
+
* @param {(expr: CallExpression, workerSyntax?: string) => boolean | void} handle handler
|
|
765
796
|
* @param {symbol} specifierTag tag used for `*variable` syntax
|
|
766
797
|
*/
|
|
767
798
|
const processList = (
|
|
@@ -280,7 +280,7 @@ ModuleFilenameHelpers.createFilename = (
|
|
|
280
280
|
]);
|
|
281
281
|
|
|
282
282
|
// TODO in the next major release: consider removing weird double placeholders
|
|
283
|
-
return
|
|
283
|
+
return opts.moduleFilenameTemplate
|
|
284
284
|
.replace(ModuleFilenameHelpers.REGEXP_ALL_LOADERS_RESOURCE, "[identifier]")
|
|
285
285
|
.replace(
|
|
286
286
|
ModuleFilenameHelpers.REGEXP_LOADERS_RESOURCE,
|
|
@@ -326,9 +326,9 @@ class DelegatedModule extends Module {
|
|
|
326
326
|
*/
|
|
327
327
|
cleanupForCache() {
|
|
328
328
|
super.cleanupForCache();
|
|
329
|
-
this.delegateData =
|
|
330
|
-
/** @type {
|
|
331
|
-
|
|
329
|
+
this.delegateData = /** @type {DelegatedModuleData} */ (
|
|
330
|
+
/** @type {DelegatedModuleData | undefined} */ (undefined)
|
|
331
|
+
);
|
|
332
332
|
}
|
|
333
333
|
}
|
|
334
334
|
|
package/lib/dll/DllModule.js
CHANGED
|
@@ -187,7 +187,9 @@ class DllModule extends Module {
|
|
|
187
187
|
*/
|
|
188
188
|
cleanupForCache() {
|
|
189
189
|
super.cleanupForCache();
|
|
190
|
-
this.dependencies = /** @type {
|
|
190
|
+
this.dependencies = /** @type {Dependency[]} */ (
|
|
191
|
+
/** @type {Dependency[] | undefined} */ (undefined)
|
|
192
|
+
);
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
195
|
|
|
@@ -179,10 +179,7 @@ class DllReferencePlugin {
|
|
|
179
179
|
try {
|
|
180
180
|
data.data =
|
|
181
181
|
/** @type {DllReferencePluginOptionsManifest} */
|
|
182
|
-
(
|
|
183
|
-
/** @type {unknown} */
|
|
184
|
-
(parseJson(/** @type {Buffer} */ (result).toString("utf8")))
|
|
185
|
-
);
|
|
182
|
+
(parseJson(/** @type {Buffer} */ (result).toString("utf8")));
|
|
186
183
|
} catch (parseErr) {
|
|
187
184
|
// Store the error in the params so that it can
|
|
188
185
|
// be added as a compilation error later on.
|
|
@@ -134,7 +134,8 @@ const cutOffWrappingFrames = (stack) => {
|
|
|
134
134
|
/**
|
|
135
135
|
* Returns the value as an error, naming whatever a tap, a loader or a plugin
|
|
136
136
|
* failed with when that is not one. Everything reading a failure expects one.
|
|
137
|
-
* @
|
|
137
|
+
* @template T
|
|
138
|
+
* @param {T} value value something failed with
|
|
138
139
|
* @returns {Error} the value, or an error naming it
|
|
139
140
|
*/
|
|
140
141
|
const toError = (value) => {
|
|
@@ -68,7 +68,8 @@ makeSerializable(HookWebpackError, "webpack/lib/errors/HookWebpackError");
|
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
70
|
* Creates webpack error.
|
|
71
|
-
* @
|
|
71
|
+
* @template T
|
|
72
|
+
* @param {T} error what a plugin failed with
|
|
72
73
|
* @param {string} hook name of the hook
|
|
73
74
|
* @returns {WebpackError} a webpack error
|
|
74
75
|
*/
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
"use strict";
|
|
6
6
|
|
|
7
|
-
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[Error,
|
|
8
|
-
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[Error,
|
|
7
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[Error, string | Buffer, string]>} ObjectDeserializerContext */
|
|
8
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[Error, string | Buffer, string]>} ObjectSerializerContext */
|
|
9
9
|
|
|
10
10
|
const makeSerializable = require("../util/makeSerializable");
|
|
11
11
|
|
|
@@ -14,7 +14,7 @@ const CONTEXT = 20;
|
|
|
14
14
|
class JSONParseError extends SyntaxError {
|
|
15
15
|
/**
|
|
16
16
|
* @param {Error} err err
|
|
17
|
-
* @param {
|
|
17
|
+
* @param {string | Buffer} raw the text `parseJson` was handed, before its byte order mark is stripped
|
|
18
18
|
* @param {string} txt text
|
|
19
19
|
*/
|
|
20
20
|
constructor(err, raw, txt) {
|
|
@@ -80,7 +80,7 @@ class JSONParseError extends SyntaxError {
|
|
|
80
80
|
this.stack = undefined;
|
|
81
81
|
/** @type {Error} */
|
|
82
82
|
this.systemError = err;
|
|
83
|
-
/** @type {
|
|
83
|
+
/** @type {string | Buffer} */
|
|
84
84
|
this.raw = raw;
|
|
85
85
|
/** @type {string} */
|
|
86
86
|
this.txt = txt;
|
|
@@ -43,8 +43,9 @@ class WebpackError extends Error {
|
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Whether an error is a webpack error rather than any other thrown value.
|
|
46
|
-
* @
|
|
47
|
-
* @
|
|
46
|
+
* @template T
|
|
47
|
+
* @param {T} value an error
|
|
48
|
+
* @returns {value is T & WebpackError} true when the value is a webpack error
|
|
48
49
|
*/
|
|
49
50
|
static isWebpackError(value) {
|
|
50
51
|
return value instanceof WebpackError;
|
|
@@ -103,6 +103,33 @@ function getChunkNamedImport(index) {
|
|
|
103
103
|
return `__webpack_chunk_${index}__`;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Returns the chunks, other than the runtime chunk, whose files the startup of an entry chunk imports.
|
|
108
|
+
* @param {Chunk} chunk the chunk
|
|
109
|
+
* @param {ChunkGraph} chunkGraph the chunk graph
|
|
110
|
+
* @returns {Iterable<Chunk>} the imported chunks
|
|
111
|
+
*/
|
|
112
|
+
function getImportedChunks(chunk, chunkGraph) {
|
|
113
|
+
if (chunk.hasRuntime()) {
|
|
114
|
+
return chunkGraph.getNumberOfEntryModules(chunk) > 0
|
|
115
|
+
? chunkGraph.getChunkEntryDependentChunksIterable(chunk)
|
|
116
|
+
: [];
|
|
117
|
+
}
|
|
118
|
+
const { entries, runtimeChunk } = getChunkInfo(chunk, chunkGraph);
|
|
119
|
+
/** @type {Set<Chunk>} */
|
|
120
|
+
const chunks = new Set();
|
|
121
|
+
for (const [, entrypoint] of entries) {
|
|
122
|
+
for (const c of getAllChunks(
|
|
123
|
+
/** @type {Entrypoint} */ (entrypoint),
|
|
124
|
+
chunk,
|
|
125
|
+
runtimeChunk
|
|
126
|
+
)) {
|
|
127
|
+
chunks.add(c);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return chunks;
|
|
131
|
+
}
|
|
132
|
+
|
|
106
133
|
const PLUGIN_NAME = "ModuleChunkFormatPlugin";
|
|
107
134
|
|
|
108
135
|
class ModuleChunkFormatPlugin {
|
|
@@ -259,7 +286,7 @@ class ModuleChunkFormatPlugin {
|
|
|
259
286
|
const chunks = getAllChunks(
|
|
260
287
|
/** @type {Entrypoint} */ (entrypoint),
|
|
261
288
|
chunk,
|
|
262
|
-
|
|
289
|
+
runtimeChunk
|
|
263
290
|
);
|
|
264
291
|
/** @type {Set<Chunk>} */
|
|
265
292
|
const processChunks = new Set();
|
|
@@ -343,6 +370,14 @@ class ModuleChunkFormatPlugin {
|
|
|
343
370
|
return source;
|
|
344
371
|
});
|
|
345
372
|
hooks.chunkHash.tap(PLUGIN_NAME, createChunkHashHandler(PLUGIN_NAME));
|
|
373
|
+
hooks.chunkHash.tap(PLUGIN_NAME, (chunk, hash, { chunkGraph }) => {
|
|
374
|
+
// WHY: the startup imports these chunks by their hashed filenames, so a
|
|
375
|
+
// cached render keyed by this hash must not outlive one of them;
|
|
376
|
+
// `Compilation#createHash` hashes them before this chunk.
|
|
377
|
+
for (const c of getImportedChunks(chunk, chunkGraph)) {
|
|
378
|
+
if (chunkHasJs(c, chunkGraph)) hash.update(`${c.hash}`);
|
|
379
|
+
}
|
|
380
|
+
});
|
|
346
381
|
});
|
|
347
382
|
}
|
|
348
383
|
}
|
|
@@ -59,7 +59,6 @@ const getEnvironmentNotSupportAsyncWarning = memoize(() =>
|
|
|
59
59
|
/** @import Compilation, { UnsafeCacheData } from "../Compilation" */
|
|
60
60
|
/** @import { UpdateHashContext } from "../graph/Dependency" */
|
|
61
61
|
/** @import ExportsInfo from "../graph/ExportsInfo" */
|
|
62
|
-
/** @import { GenerateContext } from "../module/Generator" */
|
|
63
62
|
/**
|
|
64
63
|
* @import {
|
|
65
64
|
* BuildMeta,
|
|
@@ -88,7 +87,8 @@ const getEnvironmentNotSupportAsyncWarning = memoize(() =>
|
|
|
88
87
|
/** @import RuntimeTemplate from "../template/RuntimeTemplate" */
|
|
89
88
|
/**
|
|
90
89
|
* @import {
|
|
91
|
-
* ChunkRenderContext
|
|
90
|
+
* ChunkRenderContext,
|
|
91
|
+
* ChunkRenderContext as GenerateContext
|
|
92
92
|
* } from "../javascript/JavascriptModulesPlugin"
|
|
93
93
|
*/
|
|
94
94
|
/** @import { ImportAttributes } from "../javascript/JavascriptParser" */
|
|
@@ -766,9 +766,7 @@ const getSourceForModuleExternal = (
|
|
|
766
766
|
runtimeRequirements: moduleRemapping
|
|
767
767
|
? RUNTIME_REQUIREMENTS_FOR_MODULE
|
|
768
768
|
: undefined,
|
|
769
|
-
chunkInitFragments: [
|
|
770
|
-
/** @type {InitFragment<EXPECTED_ANY>} */ (initFragment)
|
|
771
|
-
]
|
|
769
|
+
chunkInitFragments: [initFragment]
|
|
772
770
|
};
|
|
773
771
|
};
|
|
774
772
|
|
|
@@ -1364,7 +1362,8 @@ class ExternalModule extends Module {
|
|
|
1364
1362
|
const { node } = runtimeTemplate.compilation.options.externalsPresets;
|
|
1365
1363
|
// ESM has no `require`; load via `createRequire` when the target is node
|
|
1366
1364
|
const createRequireInModule =
|
|
1367
|
-
/** @type {
|
|
1365
|
+
/** @type {ExternalModuleBuildInfo} */ (this.buildInfo)
|
|
1366
|
+
.javascriptModule &&
|
|
1368
1367
|
(externalType === "node-commonjs" || Boolean(node));
|
|
1369
1368
|
if (!createRequireInModule) {
|
|
1370
1369
|
return getSourceForCommonJsExternal(request);
|
|
@@ -1401,7 +1400,12 @@ class ExternalModule extends Module {
|
|
|
1401
1400
|
case "script":
|
|
1402
1401
|
return getSourceForScriptExternal(request, runtimeTemplate);
|
|
1403
1402
|
case "module": {
|
|
1404
|
-
if (
|
|
1403
|
+
if (
|
|
1404
|
+
!(
|
|
1405
|
+
/** @type {ExternalModuleBuildInfo} */ (this.buildInfo)
|
|
1406
|
+
.javascriptModule
|
|
1407
|
+
)
|
|
1408
|
+
) {
|
|
1405
1409
|
if (!runtimeTemplate.supportsDynamicImport()) {
|
|
1406
1410
|
throw new Error(
|
|
1407
1411
|
`The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script${
|
|
@@ -1511,8 +1515,7 @@ class ExternalModule extends Module {
|
|
|
1511
1515
|
// renders the plain `module.exports =` form: its exports are read
|
|
1512
1516
|
// through the wrapper accessor, not through a shared-scope binding.
|
|
1513
1517
|
const wrapped = Boolean(
|
|
1514
|
-
concatenationScope &&
|
|
1515
|
-
/** @type {ConcatenationScope} */ (concatenationScope).isWrapped()
|
|
1518
|
+
concatenationScope && concatenationScope.isWrapped()
|
|
1516
1519
|
);
|
|
1517
1520
|
const sourceData = this._getSourceData(
|
|
1518
1521
|
request,
|