webpack 5.107.2 → 5.108.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.
- package/hot/dev-server.js +2 -0
- package/lib/APIPlugin.js +8 -4
- package/lib/CacheFacade.js +7 -0
- package/lib/Chunk.js +4 -0
- package/lib/ChunkGraph.js +30 -9
- package/lib/CircularModulesPlugin.js +190 -0
- package/lib/CleanPlugin.js +2 -1
- package/lib/Compilation.js +396 -65
- package/lib/Compiler.js +25 -11
- package/lib/ConcatenationScope.js +10 -3
- package/lib/ContextExclusionPlugin.js +1 -0
- package/lib/ContextModule.js +92 -47
- package/lib/ContextReplacementPlugin.js +4 -0
- package/lib/DefinePlugin.js +89 -15
- package/lib/Dependency.js +111 -7
- package/lib/EntryOptionPlugin.js +39 -2
- package/lib/EntryPlugin.js +2 -0
- package/lib/ExportsInfo.js +314 -73
- package/lib/ExternalModule.js +82 -34
- package/lib/ExternalModuleFactoryPlugin.js +1 -0
- package/lib/ExternalsPlugin.js +1 -0
- package/lib/FileSystemInfo.js +173 -23
- package/lib/FlagAllModulesAsUsedPlugin.js +1 -5
- package/lib/FlagDependencyExportsPlugin.js +23 -0
- package/lib/FlagDependencyUsagePlugin.js +87 -5
- package/lib/FlagEntryExportAsUsedPlugin.js +2 -0
- package/lib/Generator.js +8 -0
- package/lib/HotModuleReplacementPlugin.js +65 -28
- package/lib/IgnorePlugin.js +1 -0
- package/lib/InitFragment.js +5 -0
- package/lib/JavascriptMetaInfoPlugin.js +7 -5
- package/lib/LazyBarrel.js +361 -0
- package/lib/LoaderTargetPlugin.js +1 -0
- package/lib/Module.js +21 -42
- package/lib/ModuleGraph.js +3 -2
- package/lib/ModuleProfile.js +27 -1
- package/lib/ModuleTemplate.js +2 -0
- package/lib/MultiCompiler.js +2 -0
- package/lib/MultiStats.js +1 -0
- package/lib/MultiWatching.js +2 -0
- package/lib/NodeStuffPlugin.js +22 -17
- package/lib/NormalModule.js +142 -80
- package/lib/NormalModuleReplacementPlugin.js +2 -0
- package/lib/PrefetchPlugin.js +2 -0
- package/lib/ProgressPlugin.js +8 -0
- package/lib/ProvidePlugin.js +1 -0
- package/lib/RawModule.js +20 -16
- package/lib/RecordIdsPlugin.js +1 -0
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimePlugin.js +58 -26
- package/lib/RuntimeTemplate.js +278 -21
- package/lib/SelfModuleFactory.js +1 -0
- package/lib/SourceMapDevToolPlugin.js +3 -5
- package/lib/Stats.js +1 -0
- package/lib/Template.js +8 -2
- package/lib/TemplatedPathPlugin.js +473 -131
- package/lib/WarnCaseSensitiveModulesPlugin.js +1 -0
- package/lib/WarnDeprecatedOptionPlugin.js +4 -0
- package/lib/WarnNoModeSetPlugin.js +1 -0
- package/lib/WatchIgnorePlugin.js +1 -0
- package/lib/Watching.js +9 -0
- package/lib/WebpackOptionsApply.js +50 -5
- package/lib/asset/AssetBytesGenerator.js +11 -3
- package/lib/asset/AssetGenerator.js +47 -22
- package/lib/asset/AssetModule.js +47 -0
- package/lib/asset/AssetModulesPlugin.js +14 -14
- package/lib/asset/AssetParser.js +2 -2
- package/lib/asset/AssetSourceGenerator.js +8 -0
- package/lib/asset/RawDataUrlModule.js +12 -13
- package/lib/buildChunkGraph.js +64 -7
- package/lib/bun/BunTargetPlugin.js +48 -0
- package/lib/cache/AddBuildDependenciesPlugin.js +1 -0
- package/lib/cache/AddManagedPathsPlugin.js +3 -0
- package/lib/cache/IdleFileCachePlugin.js +4 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +1 -0
- package/lib/cache/ResolverCachePlugin.js +2 -0
- package/lib/cache/mergeEtags.js +2 -0
- package/lib/cli.js +109 -19
- package/lib/config/browserslistTargetHandler.js +99 -0
- package/lib/config/defaults.js +147 -7
- package/lib/config/defineConfig.js +31 -0
- package/lib/config/normalization.js +5 -0
- package/lib/config/target.js +181 -2
- package/lib/container/ContainerEntryModule.js +15 -14
- package/lib/container/ContainerExposedDependency.js +2 -2
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackDependency.js +5 -7
- package/lib/container/FallbackModule.js +10 -9
- package/lib/container/RemoteModule.js +20 -10
- package/lib/container/RemoteRuntimeModule.js +14 -12
- package/lib/css/CssGenerator.js +353 -327
- package/lib/css/CssInjectStyleRuntimeModule.js +36 -8
- package/lib/css/CssLoadingRuntimeModule.js +118 -47
- package/lib/css/CssModule.js +52 -23
- package/lib/css/CssModulesPlugin.js +107 -124
- package/lib/css/CssParser.js +2759 -2205
- package/lib/css/syntax.js +2859 -0
- package/lib/debug/ProfilingPlugin.js +2 -0
- package/lib/deno/DenoTargetPlugin.js +47 -0
- package/lib/dependencies/AMDDefineDependency.js +22 -17
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +1 -0
- package/lib/dependencies/AMDRequireArrayDependency.js +7 -11
- package/lib/dependencies/AMDRequireContextDependency.js +7 -11
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -0
- package/lib/dependencies/AMDRequireDependency.js +24 -20
- package/lib/dependencies/CachedConstDependency.js +3 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +1 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +79 -31
- package/lib/dependencies/CommonJsExportsDependency.js +21 -16
- package/lib/dependencies/CommonJsExportsParserPlugin.js +230 -7
- package/lib/dependencies/CommonJsFullRequireDependency.js +27 -19
- package/lib/dependencies/CommonJsImportsParserPlugin.js +51 -16
- package/lib/dependencies/CommonJsPlugin.js +1 -1
- package/lib/dependencies/CommonJsRequireContextDependency.js +10 -13
- package/lib/dependencies/CommonJsRequireDependency.js +42 -11
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -14
- package/lib/dependencies/ConstDependency.js +16 -11
- package/lib/dependencies/ContextDependency.js +4 -0
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +23 -14
- package/lib/dependencies/CreateRequireParserPlugin.js +1 -0
- package/lib/dependencies/CreateScriptUrlDependency.js +5 -7
- package/lib/dependencies/CriticalDependencyWarning.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +512 -574
- package/lib/dependencies/CssIcssImportDependency.js +9 -9
- package/lib/dependencies/CssIcssSymbolDependency.js +22 -15
- package/lib/dependencies/CssImportDependency.js +25 -1
- package/lib/dependencies/CssUrlDependency.js +23 -14
- package/lib/dependencies/DllEntryDependency.js +9 -13
- package/lib/dependencies/ExportBindingInitFragment.js +164 -0
- package/lib/dependencies/ExportsInfoDependency.js +12 -12
- package/lib/dependencies/ExternalModuleDependency.js +8 -5
- package/lib/dependencies/ExternalModuleInitFragment.js +7 -5
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +13 -10
- package/lib/dependencies/HarmonyAcceptDependency.js +11 -11
- package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -0
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +47 -22
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +28 -2
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +46 -22
- package/lib/dependencies/HarmonyExportExpressionDependency.js +107 -30
- package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -9
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +109 -31
- package/lib/dependencies/HarmonyExportInitFragment.js +18 -15
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +83 -18
- package/lib/dependencies/HarmonyExports.js +4 -1
- package/lib/dependencies/HarmonyImportDependency.js +24 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +110 -74
- package/lib/dependencies/HarmonyImportGuard.js +254 -0
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +18 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +118 -14
- package/lib/dependencies/HarmonyLinkingError.js +1 -0
- package/lib/dependencies/HarmonyModulesPlugin.js +1 -0
- package/lib/dependencies/{HtmlScriptSrcDependency.js → HtmlEntryDependency.js} +261 -109
- package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
- package/lib/dependencies/HtmlInlineScriptDependency.js +17 -13
- package/lib/dependencies/HtmlInlineStyleDependency.js +45 -11
- package/lib/dependencies/ImportContextDependency.js +5 -9
- package/lib/dependencies/ImportDependency.js +44 -2
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -0
- package/lib/dependencies/ImportMetaPlugin.js +74 -30
- package/lib/dependencies/ImportParserPlugin.js +19 -0
- package/lib/dependencies/ImportWeakDependency.js +1 -0
- package/lib/dependencies/JsonExportsDependency.js +9 -9
- package/lib/dependencies/LoaderImportDependency.js +1 -0
- package/lib/dependencies/LocalModule.js +11 -12
- package/lib/dependencies/LocalModuleDependency.js +11 -13
- package/lib/dependencies/ModuleDecoratorDependency.js +9 -9
- package/lib/dependencies/ModuleDependency.js +7 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +1 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +1 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +15 -11
- package/lib/dependencies/ProvidedDependency.js +31 -27
- package/lib/dependencies/PureExpressionDependency.js +7 -9
- package/lib/dependencies/RequireEnsureDependency.js +12 -13
- package/lib/dependencies/RequireHeaderDependency.js +3 -4
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
- package/lib/dependencies/RequireResolveContextDependency.js +7 -11
- package/lib/dependencies/RequireResolveDependency.js +1 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +3 -5
- package/lib/dependencies/RuntimeRequirementsDependency.js +6 -7
- package/lib/dependencies/StaticExportsDependency.js +10 -10
- package/lib/dependencies/SystemPlugin.js +2 -0
- package/lib/dependencies/URLContextDependency.js +5 -7
- package/lib/dependencies/URLDependency.js +14 -16
- package/lib/dependencies/UnsupportedDependency.js +8 -13
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +11 -16
- package/lib/dependencies/WebAssemblyImportDependency.js +14 -16
- package/lib/dependencies/WebpackIsIncludedDependency.js +1 -0
- package/lib/dependencies/WorkerDependency.js +19 -8
- package/lib/dependencies/WorkerPlugin.js +22 -6
- package/lib/dependencies/processExportInfo.js +13 -11
- package/lib/dll/DelegatedModule.js +29 -15
- package/lib/dll/DelegatedModuleFactoryPlugin.js +1 -0
- package/lib/dll/DelegatedPlugin.js +1 -0
- package/lib/dll/DllEntryPlugin.js +3 -0
- package/lib/dll/DllModule.js +3 -2
- package/lib/dll/DllPlugin.js +16 -0
- package/lib/dll/DllReferencePlugin.js +3 -0
- package/lib/dll/LibManifestPlugin.js +1 -0
- package/lib/electron/ElectronTargetPlugin.js +22 -4
- package/lib/errors/ConcurrentCompilationError.js +1 -0
- package/lib/errors/HookWebpackError.js +11 -13
- package/lib/errors/IgnoreErrorModuleFactory.js +1 -0
- package/lib/errors/InvalidDependenciesModuleWarning.js +2 -0
- package/lib/errors/JSONParseError.js +9 -8
- package/lib/errors/ModuleBuildError.js +16 -13
- package/lib/errors/ModuleDependencyError.js +8 -1
- package/lib/errors/ModuleDependencyWarning.js +8 -1
- package/lib/errors/ModuleError.js +5 -11
- package/lib/errors/ModuleHashingError.js +4 -0
- package/lib/errors/ModuleNotFoundError.js +3 -0
- package/lib/errors/ModuleParseError.js +5 -11
- package/lib/errors/ModuleRestoreError.js +2 -0
- package/lib/errors/ModuleStoreError.js +3 -0
- package/lib/errors/ModuleWarning.js +7 -11
- package/lib/errors/NodeStuffInWebError.js +1 -0
- package/lib/errors/NonErrorEmittedError.js +2 -0
- package/lib/errors/UnhandledSchemeError.js +1 -0
- package/lib/esm/ModuleChunkLoadingPlugin.js +0 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +28 -23
- package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +7 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
- package/lib/hmr/LazyCompilationPlugin.js +30 -6
- package/lib/html/HtmlGenerator.js +217 -23
- package/lib/html/HtmlModule.js +40 -0
- package/lib/html/HtmlModulesPlugin.js +219 -55
- package/lib/html/HtmlParser.js +1108 -1099
- package/lib/html/{walkHtmlTokens.js → syntax.js} +4701 -212
- package/lib/ids/IdHelpers.js +4 -2
- package/lib/index.js +19 -0
- package/lib/javascript/BasicEvaluatedExpression.js +1 -0
- package/lib/javascript/EnableChunkLoadingPlugin.js +1 -0
- package/lib/javascript/JavascriptGenerator.js +6 -2
- package/lib/javascript/JavascriptModule.js +54 -0
- package/lib/javascript/JavascriptModulesPlugin.js +257 -102
- package/lib/javascript/JavascriptParser.js +285 -158
- package/lib/json/JsonModule.js +40 -0
- package/lib/json/JsonModulesPlugin.js +7 -0
- package/lib/json/JsonParser.js +4 -2
- package/lib/library/AssignLibraryPlugin.js +5 -3
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -0
- package/lib/library/FalseIIFEUmdWarning.js +1 -0
- package/lib/library/ModuleLibraryPlugin.js +24 -5
- package/lib/library/SystemLibraryPlugin.js +3 -3
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/node/NodeWatchFileSystem.js +1 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -9
- package/lib/node/RequireChunkLoadingRuntimeModule.js +18 -16
- package/lib/optimize/ConcatenatedModule.js +395 -77
- package/lib/optimize/ConstExportsPlugin.js +211 -0
- package/lib/optimize/InlineExports.js +178 -0
- package/lib/optimize/InnerGraph.js +372 -275
- package/lib/optimize/InnerGraphPlugin.js +196 -99
- package/lib/optimize/ModuleConcatenationPlugin.js +56 -25
- package/lib/optimize/RealContentHashPlugin.js +14 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +234 -64
- package/lib/runtime/AsyncModuleRuntimeModule.js +32 -30
- package/lib/runtime/AutoPublicPathRuntimeModule.js +11 -5
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +6 -4
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +33 -4
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +82 -3
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +18 -13
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +39 -26
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
- package/lib/runtime/RelativeUrlRuntimeModule.js +3 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
- package/lib/runtime/StartupEntrypointRuntimeModule.js +4 -3
- package/lib/runtime/WorkerRuntimeModule.js +33 -0
- package/lib/schemes/HttpUriPlugin.js +3 -2
- package/lib/serialization/AggregateErrorSerializer.js +7 -6
- package/lib/serialization/ArraySerializer.js +4 -8
- package/lib/serialization/BinaryMiddleware.js +538 -468
- package/lib/serialization/DateObjectSerializer.js +2 -2
- package/lib/serialization/ErrorObjectSerializer.js +7 -6
- package/lib/serialization/MapObjectSerializer.js +5 -9
- package/lib/serialization/NullPrototypeObjectSerializer.js +7 -9
- package/lib/serialization/ObjectMiddleware.js +50 -13
- package/lib/serialization/PlainObjectSerializer.js +9 -8
- package/lib/serialization/RegExpObjectSerializer.js +2 -2
- package/lib/serialization/Serializer.js +1 -0
- package/lib/serialization/SetObjectSerializer.js +4 -8
- package/lib/sharing/ConsumeSharedModule.js +6 -7
- package/lib/sharing/ConsumeSharedPlugin.js +1 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +46 -41
- package/lib/sharing/ProvideSharedDependency.js +30 -15
- package/lib/sharing/ProvideSharedModule.js +30 -11
- package/lib/sharing/ProvideSharedPlugin.js +4 -2
- package/lib/sharing/SharePlugin.js +3 -0
- package/lib/sharing/ShareRuntimeModule.js +18 -16
- package/lib/sharing/resolveMatchedConfigs.js +2 -1
- package/lib/sharing/utils.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +4 -6
- package/lib/stats/DefaultStatsPrinterPlugin.js +14 -14
- package/lib/stats/StatsFactory.js +11 -9
- package/lib/stats/StatsPrinter.js +9 -2
- package/lib/url/URLParserPlugin.js +5 -2
- package/lib/util/AsyncQueue.js +10 -0
- package/lib/util/LazyBucketSortedSet.js +5 -0
- package/lib/util/LazySet.js +6 -4
- package/lib/util/LocConverter.js +11 -1
- package/lib/util/Semaphore.js +1 -0
- package/lib/util/SourceProcessor.js +106 -0
- package/lib/util/TupleSet.js +1 -0
- package/lib/util/WeakTupleMap.js +27 -1
- package/lib/util/chainedImports.js +3 -3
- package/lib/util/comparators.js +2 -2
- package/lib/util/concatenate.js +31 -7
- package/lib/util/createHash.js +0 -1
- package/lib/util/deterministicGrouping.js +19 -12
- package/lib/util/extractSourceMap.js +1 -1
- package/lib/util/findGraphRoots.js +2 -0
- package/lib/util/fs.js +10 -5
- package/lib/util/hash/DebugHash.js +1 -0
- package/lib/util/hash/hash-digest.js +24 -15
- package/lib/util/identifier.js +7 -0
- package/lib/util/internalSerializables.js +11 -2
- package/lib/util/magicComment.js +42 -0
- package/lib/util/makeSerializable.js +1 -0
- package/lib/util/nonNumericOnlyHash.js +30 -1
- package/lib/util/property.js +7 -1
- package/lib/util/publicPathPlaceholder.js +64 -0
- package/lib/util/registerExternalSerializer.js +4 -4
- package/lib/wasm-async/AsyncWasmModule.js +77 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -96
- package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +1 -1
- package/lib/wasm-sync/SyncWasmModule.js +39 -0
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +1 -0
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -3
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -1
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +10 -0
- package/lib/wasm-sync/WebAssemblyParser.js +7 -3
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +45 -39
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +11 -10
- package/package.json +35 -27
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +212 -3
- package/schemas/plugins/HtmlGeneratorOptions.check.js +1 -1
- package/schemas/plugins/HtmlParserOptions.check.d.ts +7 -0
- package/schemas/plugins/HtmlParserOptions.check.js +6 -0
- package/schemas/plugins/HtmlParserOptions.json +3 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/types.d.ts +1456 -290
- package/lib/css/walkCssTokens.js +0 -2020
- package/lib/util/AppendOnlyStackedSet.js +0 -93
|
@@ -22,6 +22,7 @@ const {
|
|
|
22
22
|
} = require("../util/runtime");
|
|
23
23
|
const ConcatenatedModule = require("./ConcatenatedModule");
|
|
24
24
|
|
|
25
|
+
/** @typedef {import("../Chunk")} Chunk */
|
|
25
26
|
/** @typedef {import("../Compilation")} Compilation */
|
|
26
27
|
/** @typedef {import("../Compiler")} Compiler */
|
|
27
28
|
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
|
@@ -30,6 +31,26 @@ const ConcatenatedModule = require("./ConcatenatedModule");
|
|
|
30
31
|
|
|
31
32
|
/** @typedef {Module | ((requestShortener: RequestShortener) => string)} Problem */
|
|
32
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Merged runtime of all chunks a module is in, memoized for the whole pass.
|
|
36
|
+
* Safe: the chunk graph is not mutated while configurations are built.
|
|
37
|
+
* @param {ChunkGraph} chunkGraph the chunk graph
|
|
38
|
+
* @param {Map<Module, RuntimeSpec>} cache memoization cache
|
|
39
|
+
* @param {Module} module the module
|
|
40
|
+
* @returns {RuntimeSpec} the merged runtime
|
|
41
|
+
*/
|
|
42
|
+
const getMergedModuleRuntime = (chunkGraph, cache, module) => {
|
|
43
|
+
const cached = cache.get(module);
|
|
44
|
+
if (cached !== undefined || cache.has(module)) return cached;
|
|
45
|
+
/** @type {RuntimeSpec} */
|
|
46
|
+
let runtime;
|
|
47
|
+
for (const r of chunkGraph.getModuleRuntimes(module)) {
|
|
48
|
+
runtime = mergeRuntimeOwned(runtime, r);
|
|
49
|
+
}
|
|
50
|
+
cache.set(module, runtime);
|
|
51
|
+
return runtime;
|
|
52
|
+
};
|
|
53
|
+
|
|
33
54
|
/**
|
|
34
55
|
* Defines the statistics type used by this module.
|
|
35
56
|
* @typedef {object} Statistics
|
|
@@ -285,17 +306,20 @@ class ModuleConcatenationPlugin {
|
|
|
285
306
|
const concatConfigurations = [];
|
|
286
307
|
/** @type {Set<Module>} */
|
|
287
308
|
const usedAsInner = new Set();
|
|
309
|
+
// module -> merged runtime of its chunks, shared across all roots
|
|
310
|
+
/** @type {Map<Module, RuntimeSpec>} */
|
|
311
|
+
const moduleRuntimeCache = new Map();
|
|
288
312
|
for (const currentRoot of relevantModules) {
|
|
289
313
|
// when used by another configuration as inner:
|
|
290
314
|
// the other configuration is better and we can skip this one
|
|
291
315
|
// TODO reconsider that when it's only used in a different runtime
|
|
292
316
|
if (usedAsInner.has(currentRoot)) continue;
|
|
293
317
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
318
|
+
const chunkRuntime = getMergedModuleRuntime(
|
|
319
|
+
chunkGraph,
|
|
320
|
+
moduleRuntimeCache,
|
|
321
|
+
currentRoot
|
|
322
|
+
);
|
|
299
323
|
const exportsInfo = moduleGraph.getExportsInfo(currentRoot);
|
|
300
324
|
const filteredRuntime = filterRuntime(chunkRuntime, (r) =>
|
|
301
325
|
exportsInfo.isModuleUsed(r)
|
|
@@ -307,10 +331,12 @@ class ModuleConcatenationPlugin {
|
|
|
307
331
|
? undefined
|
|
308
332
|
: filteredRuntime;
|
|
309
333
|
|
|
310
|
-
// create a configuration with the root
|
|
334
|
+
// create a configuration with the root; cache the root's chunks once
|
|
335
|
+
// so every candidate check reuses them instead of re-materializing
|
|
311
336
|
const currentConfiguration = new ConcatConfiguration(
|
|
312
337
|
currentRoot,
|
|
313
|
-
activeRuntime
|
|
338
|
+
activeRuntime,
|
|
339
|
+
[...chunkGraph.getModuleChunksIterable(currentRoot)]
|
|
314
340
|
);
|
|
315
341
|
|
|
316
342
|
// cache failures to add modules
|
|
@@ -342,6 +368,7 @@ class ModuleConcatenationPlugin {
|
|
|
342
368
|
possibleInners,
|
|
343
369
|
impCandidates,
|
|
344
370
|
failureCache,
|
|
371
|
+
moduleRuntimeCache,
|
|
345
372
|
chunkGraph,
|
|
346
373
|
true,
|
|
347
374
|
stats
|
|
@@ -387,10 +414,10 @@ class ModuleConcatenationPlugin {
|
|
|
387
414
|
logger.debug(
|
|
388
415
|
`${statsCandidates} candidates were considered for adding (${stats.cached} cached failure, ${stats.alreadyInConfig} already in config, ${stats.invalidModule} invalid module, ${stats.incorrectChunks} incorrect chunks, ${stats.incorrectDependency} incorrect dependency, ${stats.incorrectChunksOfImporter} incorrect chunks of importer, ${stats.incorrectModuleDependency} incorrect module dependency, ${stats.incorrectRuntimeCondition} incorrect runtime condition, ${stats.importerFailed} importer failed, ${stats.added} added)`
|
|
389
416
|
);
|
|
390
|
-
//
|
|
391
|
-
//
|
|
392
|
-
//
|
|
393
|
-
//
|
|
417
|
+
// Create the largest configurations first: if a root also ended up inside
|
|
418
|
+
// a bigger configuration, the bigger one wins (smaller skipped below).
|
|
419
|
+
// Configurations can't be reused across roots: a module shared by several
|
|
420
|
+
// chunks is concatenated into each consumer (module duplication).
|
|
394
421
|
logger.time("sort concat configurations");
|
|
395
422
|
concatConfigurations.sort((a, b) => b.modules.size - a.modules.size);
|
|
396
423
|
logger.timeEnd("sort concat configurations");
|
|
@@ -403,8 +430,8 @@ class ModuleConcatenationPlugin {
|
|
|
403
430
|
(concatConfiguration, callback) => {
|
|
404
431
|
const rootModule = concatConfiguration.rootModule;
|
|
405
432
|
|
|
406
|
-
//
|
|
407
|
-
//
|
|
433
|
+
// Root already concatenated into a larger configuration: skip.
|
|
434
|
+
// (Inner modules may still be shared, e.g. duplicated across entries.)
|
|
408
435
|
if (usedModules.has(rootModule)) return callback();
|
|
409
436
|
const modules = concatConfiguration.getModules();
|
|
410
437
|
for (const m of modules) {
|
|
@@ -586,6 +613,7 @@ class ModuleConcatenationPlugin {
|
|
|
586
613
|
* @param {Set<Module>} possibleModules modules that are candidates
|
|
587
614
|
* @param {Set<Module>} candidates list of potential candidates (will be added to)
|
|
588
615
|
* @param {Map<Module, Problem>} failureCache cache for problematic modules to be more performant
|
|
616
|
+
* @param {Map<Module, RuntimeSpec>} moduleRuntimeCache memoized merged runtime per module, shared across roots
|
|
589
617
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
|
590
618
|
* @param {boolean} avoidMutateOnFailure avoid mutating the config when adding fails
|
|
591
619
|
* @param {Statistics} statistics gathering metrics
|
|
@@ -600,6 +628,7 @@ class ModuleConcatenationPlugin {
|
|
|
600
628
|
possibleModules,
|
|
601
629
|
candidates,
|
|
602
630
|
failureCache,
|
|
631
|
+
moduleRuntimeCache,
|
|
603
632
|
chunkGraph,
|
|
604
633
|
avoidMutateOnFailure,
|
|
605
634
|
statistics
|
|
@@ -624,9 +653,9 @@ class ModuleConcatenationPlugin {
|
|
|
624
653
|
}
|
|
625
654
|
|
|
626
655
|
// Module must be in the correct chunks
|
|
627
|
-
const missingChunks =
|
|
628
|
-
|
|
629
|
-
|
|
656
|
+
const missingChunks = config.rootChunks.filter(
|
|
657
|
+
(chunk) => !chunkGraph.isModuleInChunk(module, chunk)
|
|
658
|
+
);
|
|
630
659
|
if (missingChunks.length > 0) {
|
|
631
660
|
/**
|
|
632
661
|
* Returns problem description.
|
|
@@ -707,11 +736,11 @@ class ModuleConcatenationPlugin {
|
|
|
707
736
|
if (chunkGraph.getNumberOfModuleChunks(originModule) === 0) continue;
|
|
708
737
|
|
|
709
738
|
// We don't care for connections from other runtimes
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
739
|
+
const originRuntime = getMergedModuleRuntime(
|
|
740
|
+
chunkGraph,
|
|
741
|
+
moduleRuntimeCache,
|
|
742
|
+
originModule
|
|
743
|
+
);
|
|
715
744
|
|
|
716
745
|
if (!intersectRuntime(runtime, originRuntime)) continue;
|
|
717
746
|
|
|
@@ -729,9 +758,7 @@ class ModuleConcatenationPlugin {
|
|
|
729
758
|
|
|
730
759
|
// Module must be in the same chunks like the referencing module
|
|
731
760
|
const otherChunkModules = incomingModules.filter((originModule) => {
|
|
732
|
-
for (const chunk of
|
|
733
|
-
config.rootModule
|
|
734
|
-
)) {
|
|
761
|
+
for (const chunk of config.rootChunks) {
|
|
735
762
|
if (!chunkGraph.isModuleInChunk(originModule, chunk)) {
|
|
736
763
|
return true;
|
|
737
764
|
}
|
|
@@ -881,6 +908,7 @@ class ModuleConcatenationPlugin {
|
|
|
881
908
|
possibleModules,
|
|
882
909
|
candidates,
|
|
883
910
|
failureCache,
|
|
911
|
+
moduleRuntimeCache,
|
|
884
912
|
chunkGraph,
|
|
885
913
|
false,
|
|
886
914
|
statistics
|
|
@@ -909,12 +937,15 @@ class ConcatConfiguration {
|
|
|
909
937
|
* Creates an instance of ConcatConfiguration.
|
|
910
938
|
* @param {Module} rootModule the root module
|
|
911
939
|
* @param {RuntimeSpec} runtime the runtime
|
|
940
|
+
* @param {Chunk[]} rootChunks the chunks the root module is in
|
|
912
941
|
*/
|
|
913
|
-
constructor(rootModule, runtime) {
|
|
942
|
+
constructor(rootModule, runtime, rootChunks) {
|
|
914
943
|
/** @type {Module} */
|
|
915
944
|
this.rootModule = rootModule;
|
|
916
945
|
/** @type {RuntimeSpec} */
|
|
917
946
|
this.runtime = runtime;
|
|
947
|
+
/** @type {Chunk[]} the root's chunks, reused for every candidate's chunk check */
|
|
948
|
+
this.rootChunks = rootChunks;
|
|
918
949
|
/** @type {Set<Module>} */
|
|
919
950
|
this.modules = new Set();
|
|
920
951
|
this.modules.add(rootModule);
|
|
@@ -241,12 +241,21 @@ class RealContentHashPlugin {
|
|
|
241
241
|
const assetsWithInfo = [];
|
|
242
242
|
/** @type {Map<string, [AssetInfoForRealContentHash]>} */
|
|
243
243
|
const hashToAssets = new Map();
|
|
244
|
+
// Inline `[contenthash:<digest>]` digest per hash, so the recomputed
|
|
245
|
+
// real hash is re-encoded in it instead of `output.hashDigest`.
|
|
246
|
+
/** @type {Map<string, string>} */
|
|
247
|
+
const hashToDigest = new Map();
|
|
244
248
|
for (const { source, info, name } of assets) {
|
|
245
249
|
const cachedSource = toCachedSource(source);
|
|
246
250
|
const content = /** @type {string} */ (cachedSource.source());
|
|
247
251
|
/** @type {Hashes} */
|
|
248
252
|
const hashes = new Set();
|
|
249
253
|
addToList(info.contenthash, hashes);
|
|
254
|
+
if (info.contenthashDigest) {
|
|
255
|
+
for (const hash of Object.keys(info.contenthashDigest)) {
|
|
256
|
+
hashToDigest.set(hash, info.contenthashDigest[hash]);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
250
259
|
/** @type {AssetInfoForRealContentHash} */
|
|
251
260
|
const data = {
|
|
252
261
|
name,
|
|
@@ -519,7 +528,11 @@ ${referencingAssets
|
|
|
519
528
|
for (const chunks of uniqueChunkArrays) {
|
|
520
529
|
for (const c of chunks) hash.update(c);
|
|
521
530
|
}
|
|
522
|
-
const digest = hash.digest(
|
|
531
|
+
const digest = hash.digest(
|
|
532
|
+
/** @type {HashDigest} */ (
|
|
533
|
+
hashToDigest.get(oldHash) || this._hashDigest
|
|
534
|
+
)
|
|
535
|
+
);
|
|
523
536
|
newHash = digest.slice(0, oldHash.length);
|
|
524
537
|
}
|
|
525
538
|
hashToNewHash.set(oldHash, newHash);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
-
const glob2regexp = require("
|
|
8
|
+
const glob2regexp = require("watchpack").util.globToRegExp;
|
|
9
9
|
const {
|
|
10
10
|
JAVASCRIPT_MODULE_TYPE_AUTO,
|
|
11
11
|
JAVASCRIPT_MODULE_TYPE_DYNAMIC,
|
|
@@ -25,10 +25,16 @@ const { CompilerHintNotationRegExp } = require("../util/magicComment");
|
|
|
25
25
|
/** @typedef {import("../Compiler")} Compiler */
|
|
26
26
|
/** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
|
|
27
27
|
/** @typedef {import("../Module")} Module */
|
|
28
|
+
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
|
29
|
+
/** @typedef {import("../Module").BuildInfo} BuildInfo */
|
|
28
30
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
|
31
|
+
/** @typedef {import("../javascript/JavascriptModule").JavascriptModuleBuildInfo} JavascriptModuleBuildInfo */
|
|
29
32
|
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
|
33
|
+
/** @typedef {import("../ExportsInfo").ExportInfo} ExportInfo */
|
|
34
|
+
/** @typedef {import("../ExportsInfo").TargetItemWithConnection} TargetItemWithConnection */
|
|
30
35
|
/** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
|
|
31
36
|
/** @typedef {import("../javascript/JavascriptParser").Range} Range */
|
|
37
|
+
/** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
|
|
32
38
|
|
|
33
39
|
/**
|
|
34
40
|
* Defines the export in module type used by this module.
|
|
@@ -57,9 +63,8 @@ const globToRegexp = (glob, cache) => {
|
|
|
57
63
|
if (!glob.includes("/")) {
|
|
58
64
|
glob = `**/${glob}`;
|
|
59
65
|
}
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
const regexp = new RegExp(`^(\\./)?${regexpSource.slice(1)}`);
|
|
66
|
+
const regexpSource = glob2regexp(glob);
|
|
67
|
+
const regexp = new RegExp(`^(\\./)?${regexpSource}$`);
|
|
63
68
|
cache.set(glob, regexp);
|
|
64
69
|
return regexp;
|
|
65
70
|
};
|
|
@@ -84,6 +89,39 @@ const hasNoSideEffectsNotation = (parser, start, end) => {
|
|
|
84
89
|
|
|
85
90
|
const PLUGIN_NAME = "SideEffectsFlagPlugin";
|
|
86
91
|
|
|
92
|
+
const notSideEffectsTag = Symbol("NoSideEffects");
|
|
93
|
+
|
|
94
|
+
/** @type {(target: { module: Module }) => boolean} */
|
|
95
|
+
const RETURNS_FALSE = () => false;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Detects if the module is "pure single-star passthrough": one whose entire export
|
|
99
|
+
* surface is exactly one `export * from "x"` (no named/local/default-bearing
|
|
100
|
+
* exports, no second star). For such a module `export * from "passthrough"` is
|
|
101
|
+
* equivalent to `export * from "x"`, so the passthrough can be skipped.
|
|
102
|
+
* @param {Module} module the candidate passthrough module
|
|
103
|
+
* @returns {boolean} true when the module is a pure single-star passthrough
|
|
104
|
+
*/
|
|
105
|
+
const moduleHasSingleStarReexport = (module) => {
|
|
106
|
+
/** @type {HarmonyExportImportedSpecifierDependency | undefined} */
|
|
107
|
+
let starReexportDep;
|
|
108
|
+
for (const dep of module.dependencies) {
|
|
109
|
+
if (!(dep instanceof HarmonyExportImportedSpecifierDependency)) continue;
|
|
110
|
+
// a named re-export (`export { x } from` / `export * as ns from`) means
|
|
111
|
+
// the module owns names a star into its source wouldn't reproduce
|
|
112
|
+
if (dep.name !== null) return false;
|
|
113
|
+
// any named/local export populates the shared activeExports set
|
|
114
|
+
if (dep.activeExports.size !== 0) return false;
|
|
115
|
+
// more than one `export *` can't be collapsed to a single source
|
|
116
|
+
if (dep.allStarExports && dep.allStarExports.dependencies.length !== 1) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
starReexportDep = dep;
|
|
120
|
+
}
|
|
121
|
+
if (starReexportDep === undefined) return false;
|
|
122
|
+
return true;
|
|
123
|
+
};
|
|
124
|
+
|
|
87
125
|
class SideEffectsFlagPlugin {
|
|
88
126
|
/**
|
|
89
127
|
* Creates an instance of SideEffectsFlagPlugin.
|
|
@@ -282,24 +320,51 @@ class SideEffectsFlagPlugin {
|
|
|
282
320
|
|
|
283
321
|
/**
|
|
284
322
|
* @param {JavascriptParser} parser the parser
|
|
323
|
+
* @param {JavascriptParserOptions} parserOptions the parser options
|
|
285
324
|
* @returns {void}
|
|
286
325
|
*/
|
|
287
|
-
const applyNoSideEffectsNotationHandler = (parser) => {
|
|
288
|
-
/** @type {Set<string>} */
|
|
289
|
-
let
|
|
326
|
+
const applyNoSideEffectsNotationHandler = (parser, parserOptions) => {
|
|
327
|
+
/** @type {Set<string> | undefined} */
|
|
328
|
+
let pureFunctions;
|
|
329
|
+
|
|
330
|
+
const pureFunctionsFromOption =
|
|
331
|
+
parserOptions &&
|
|
332
|
+
Array.isArray(parserOptions.pureFunctions) &&
|
|
333
|
+
parserOptions.pureFunctions.length > 0
|
|
334
|
+
? new Set(parserOptions.pureFunctions)
|
|
335
|
+
: undefined;
|
|
290
336
|
|
|
291
337
|
parser.hooks.program.tap(PLUGIN_NAME, () => {
|
|
292
|
-
|
|
338
|
+
pureFunctions = undefined;
|
|
293
339
|
});
|
|
294
340
|
|
|
341
|
+
/**
|
|
342
|
+
* @param {string} name function name
|
|
343
|
+
*/
|
|
344
|
+
const markPure = (name) => {
|
|
345
|
+
if (pureFunctions === undefined) pureFunctions = new Set();
|
|
346
|
+
else if (pureFunctions.has(name)) return;
|
|
347
|
+
parser.tagVariable(name, notSideEffectsTag, {});
|
|
348
|
+
pureFunctions.add(name);
|
|
349
|
+
};
|
|
350
|
+
|
|
295
351
|
// Detect on function declarations
|
|
296
352
|
// Covers:
|
|
297
353
|
// 1. function foo
|
|
298
354
|
// 2. export function foo
|
|
299
355
|
// 3. export default function foo
|
|
356
|
+
// 4. export default function / export default () => {} (anonymous)
|
|
300
357
|
parser.hooks.preStatement.tap(PLUGIN_NAME, (statement) => {
|
|
301
358
|
if (parser.scope.topLevelScope !== true) return;
|
|
302
|
-
if (statement.type !== "FunctionDeclaration"
|
|
359
|
+
if (statement.type !== "FunctionDeclaration") {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
const name = statement.id ? statement.id.name : "default";
|
|
363
|
+
if (
|
|
364
|
+
pureFunctionsFromOption &&
|
|
365
|
+
pureFunctionsFromOption.has(name)
|
|
366
|
+
) {
|
|
367
|
+
markPure(name);
|
|
303
368
|
return;
|
|
304
369
|
}
|
|
305
370
|
const commentsStart = parser.prevStatement
|
|
@@ -312,14 +377,22 @@ class SideEffectsFlagPlugin {
|
|
|
312
377
|
/** @type {Range} */ (statement.range)[0]
|
|
313
378
|
)
|
|
314
379
|
) {
|
|
315
|
-
|
|
380
|
+
markPure(name);
|
|
316
381
|
}
|
|
317
382
|
});
|
|
318
383
|
|
|
319
384
|
// Detect on variable declarations with function init
|
|
320
385
|
parser.hooks.preDeclarator.tap(PLUGIN_NAME, (decl, statement) => {
|
|
321
386
|
if (parser.scope.topLevelScope !== true) return;
|
|
322
|
-
if (
|
|
387
|
+
if (decl.id.type !== "Identifier") return;
|
|
388
|
+
if (
|
|
389
|
+
pureFunctionsFromOption &&
|
|
390
|
+
pureFunctionsFromOption.has(decl.id.name)
|
|
391
|
+
) {
|
|
392
|
+
markPure(decl.id.name);
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
if (!decl.init) return;
|
|
323
396
|
if (!decl.init.type.endsWith("FunctionExpression")) return;
|
|
324
397
|
|
|
325
398
|
let hasAnnotation = false;
|
|
@@ -343,25 +416,60 @@ class SideEffectsFlagPlugin {
|
|
|
343
416
|
);
|
|
344
417
|
}
|
|
345
418
|
if (hasAnnotation) {
|
|
346
|
-
|
|
419
|
+
markPure(decl.id.name);
|
|
347
420
|
}
|
|
348
421
|
});
|
|
349
422
|
|
|
350
|
-
|
|
423
|
+
if (pureFunctionsFromOption) {
|
|
424
|
+
parser.hooks.blockPreStatement.tap(PLUGIN_NAME, (statement) => {
|
|
425
|
+
if (parser.scope.topLevelScope !== true) return;
|
|
426
|
+
if (
|
|
427
|
+
statement.type === "ExportDefaultDeclaration" &&
|
|
428
|
+
pureFunctionsFromOption.has("default")
|
|
429
|
+
) {
|
|
430
|
+
const decl = statement.declaration;
|
|
431
|
+
if (
|
|
432
|
+
decl.type === "ArrowFunctionExpression" ||
|
|
433
|
+
decl.type === "FunctionExpression"
|
|
434
|
+
) {
|
|
435
|
+
markPure("default");
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
|
|
351
441
|
parser.hooks.isPure
|
|
352
442
|
.for("CallExpression")
|
|
353
443
|
.tap(PLUGIN_NAME, (expression, commentsStartPos) => {
|
|
354
444
|
const expr = /** @type {CallExpression} */ (expression);
|
|
355
445
|
if (expr.callee.type !== "Identifier") return;
|
|
356
|
-
if (!
|
|
446
|
+
if (!parser.getTagData(expr.callee.name, notSideEffectsTag)) {
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
357
449
|
commentsStartPos = /** @type {Range} */ (expr.callee.range)[1];
|
|
358
|
-
|
|
359
|
-
if (arg.type === "SpreadElement") return;
|
|
360
|
-
|
|
450
|
+
return expr.arguments.every((arg) => {
|
|
451
|
+
if (arg.type === "SpreadElement") return false;
|
|
452
|
+
const pure = parser.isPure(arg, commentsStartPos);
|
|
361
453
|
commentsStartPos = /** @type {Range} */ (arg.range)[1];
|
|
362
|
-
|
|
363
|
-
|
|
454
|
+
return pure;
|
|
455
|
+
});
|
|
364
456
|
});
|
|
457
|
+
|
|
458
|
+
parser.hooks.finish.tap(PLUGIN_NAME, () => {
|
|
459
|
+
if (pureFunctions === undefined || pureFunctions.size === 0) {
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
const buildInfo = /** @type {JavascriptModuleBuildInfo} */ (
|
|
463
|
+
parser.state.module.buildInfo
|
|
464
|
+
);
|
|
465
|
+
if (buildInfo.pureFunctions) {
|
|
466
|
+
for (const fn of pureFunctions) {
|
|
467
|
+
buildInfo.pureFunctions.add(fn);
|
|
468
|
+
}
|
|
469
|
+
} else {
|
|
470
|
+
buildInfo.pureFunctions = pureFunctions;
|
|
471
|
+
}
|
|
472
|
+
});
|
|
365
473
|
};
|
|
366
474
|
|
|
367
475
|
for (const key of [
|
|
@@ -371,8 +479,8 @@ class SideEffectsFlagPlugin {
|
|
|
371
479
|
]) {
|
|
372
480
|
normalModuleFactory.hooks.parser
|
|
373
481
|
.for(key)
|
|
374
|
-
.tap(PLUGIN_NAME, (parser) => {
|
|
375
|
-
applyNoSideEffectsNotationHandler(parser);
|
|
482
|
+
.tap(PLUGIN_NAME, (parser, parserOptions) => {
|
|
483
|
+
applyNoSideEffectsNotationHandler(parser, parserOptions);
|
|
376
484
|
applySideEffectsStmtHandler(parser);
|
|
377
485
|
});
|
|
378
486
|
}
|
|
@@ -392,6 +500,31 @@ class SideEffectsFlagPlugin {
|
|
|
392
500
|
/** @type {Set<Module>} */
|
|
393
501
|
const optimizedModules = new Set();
|
|
394
502
|
|
|
503
|
+
// Re-export resolution is idempotent within a pass, so cache it
|
|
504
|
+
// per export info: a shared barrel imported by many modules
|
|
505
|
+
// resolves each name once instead of once per consumer.
|
|
506
|
+
/** @type {Map<ExportInfo, TargetItemWithConnection | null>} */
|
|
507
|
+
const reexportTargetCache = new Map();
|
|
508
|
+
|
|
509
|
+
// Dependencies don't change within the pass, so the passthrough
|
|
510
|
+
// check is cached per module across all moveTarget filter calls.
|
|
511
|
+
/** @type {Map<Module, boolean>} */
|
|
512
|
+
const singleStarReexportCache = new Map();
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Cached variant of moduleHasSingleStarReexport.
|
|
516
|
+
* @param {Module} module the candidate passthrough module
|
|
517
|
+
* @returns {boolean} true when the module is a pure single-star passthrough
|
|
518
|
+
*/
|
|
519
|
+
const hasSingleStarReexport = (module) => {
|
|
520
|
+
let result = singleStarReexportCache.get(module);
|
|
521
|
+
if (result === undefined) {
|
|
522
|
+
result = moduleHasSingleStarReexport(module);
|
|
523
|
+
singleStarReexportCache.set(module, result);
|
|
524
|
+
}
|
|
525
|
+
return result;
|
|
526
|
+
};
|
|
527
|
+
|
|
395
528
|
/**
|
|
396
529
|
* Optimize incoming connections.
|
|
397
530
|
* @param {Module} module module
|
|
@@ -417,56 +550,93 @@ class SideEffectsFlagPlugin {
|
|
|
417
550
|
if (connection.originModule !== null) {
|
|
418
551
|
optimizeIncomingConnections(connection.originModule);
|
|
419
552
|
}
|
|
420
|
-
|
|
421
|
-
if (isReexport
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
connection: targetConnection
|
|
435
|
-
}) => {
|
|
436
|
-
moduleGraph.updateModule(dep, newModule);
|
|
437
|
-
moduleGraph.updateParent(
|
|
438
|
-
dep,
|
|
439
|
-
targetConnection,
|
|
553
|
+
|
|
554
|
+
if (isReexport) {
|
|
555
|
+
if (!dep.name && !hasSingleStarReexport(module)) continue;
|
|
556
|
+
|
|
557
|
+
const infos = dep.name
|
|
558
|
+
? // Named re-exports resolve their single target here;
|
|
559
|
+
// e.g. `export * as foo from "mod"` / `export { dep as name } from "mod"`
|
|
560
|
+
[
|
|
561
|
+
moduleGraph.getExportInfo(
|
|
562
|
+
/** @type {Module} */ (connection.originModule),
|
|
563
|
+
dep.name
|
|
564
|
+
)
|
|
565
|
+
]
|
|
566
|
+
: moduleGraph.getExportsInfo(
|
|
440
567
|
/** @type {Module} */ (connection.originModule)
|
|
441
|
-
);
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
return /** @type {ModuleGraphConnection} */ (
|
|
454
|
-
moduleGraph.getConnection(dep)
|
|
455
|
-
);
|
|
568
|
+
).exports;
|
|
569
|
+
|
|
570
|
+
for (const exportInfo of infos) {
|
|
571
|
+
const immediate = exportInfo.getTarget(
|
|
572
|
+
moduleGraph,
|
|
573
|
+
RETURNS_FALSE
|
|
574
|
+
);
|
|
575
|
+
if (
|
|
576
|
+
immediate === undefined ||
|
|
577
|
+
immediate.connection.dependency !== dep
|
|
578
|
+
) {
|
|
579
|
+
continue;
|
|
456
580
|
}
|
|
457
|
-
|
|
581
|
+
|
|
582
|
+
exportInfo.moveTarget(
|
|
583
|
+
moduleGraph,
|
|
584
|
+
({ module }) =>
|
|
585
|
+
module.getSideEffectsConnectionState(
|
|
586
|
+
moduleGraph
|
|
587
|
+
) === false &&
|
|
588
|
+
(Boolean(dep.name) ||
|
|
589
|
+
hasSingleStarReexport(
|
|
590
|
+
/** @type {Module} */ (module)
|
|
591
|
+
)),
|
|
592
|
+
({
|
|
593
|
+
module: newModule,
|
|
594
|
+
export: exportName,
|
|
595
|
+
connection: targetConnection
|
|
596
|
+
}) => {
|
|
597
|
+
moduleGraph.updateModule(dep, newModule);
|
|
598
|
+
moduleGraph.updateParent(
|
|
599
|
+
dep,
|
|
600
|
+
targetConnection,
|
|
601
|
+
/** @type {Module} */ (connection.originModule)
|
|
602
|
+
);
|
|
603
|
+
moduleGraph.addExplanation(
|
|
604
|
+
dep,
|
|
605
|
+
"(skipped side-effect-free modules)"
|
|
606
|
+
);
|
|
607
|
+
const ids = dep.getIds(moduleGraph);
|
|
608
|
+
if (ids.length) {
|
|
609
|
+
dep.setIds(
|
|
610
|
+
moduleGraph,
|
|
611
|
+
exportName
|
|
612
|
+
? [...exportName, ...ids.slice(1)]
|
|
613
|
+
: ids.slice(1)
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
return /** @type {ModuleGraphConnection} */ (
|
|
617
|
+
moduleGraph.getConnection(dep)
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
);
|
|
621
|
+
}
|
|
458
622
|
continue;
|
|
459
623
|
}
|
|
460
|
-
|
|
624
|
+
|
|
461
625
|
const ids = dep.getIds(moduleGraph);
|
|
462
626
|
if (ids.length > 0) {
|
|
463
627
|
const exportInfo = exportsInfo.getExportInfo(ids[0]);
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
628
|
+
let target = reexportTargetCache.get(exportInfo);
|
|
629
|
+
if (target === undefined) {
|
|
630
|
+
target =
|
|
631
|
+
exportInfo.getTarget(
|
|
632
|
+
moduleGraph,
|
|
633
|
+
({ module }) =>
|
|
634
|
+
module.getSideEffectsConnectionState(
|
|
635
|
+
moduleGraph
|
|
636
|
+
) === false
|
|
637
|
+
) || null;
|
|
638
|
+
reexportTargetCache.set(exportInfo, target);
|
|
639
|
+
}
|
|
470
640
|
if (!target) continue;
|
|
471
641
|
|
|
472
642
|
moduleGraph.updateModule(dep, target.module);
|