webpack 5.59.0 → 5.94.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/README.md +48 -38
- package/bin/webpack.js +34 -10
- package/hot/dev-server.js +19 -5
- package/hot/lazy-compilation-node.js +13 -1
- package/hot/lazy-compilation-web.js +9 -0
- package/hot/log-apply-result.js +5 -0
- package/hot/log.js +23 -4
- package/hot/only-dev-server.js +3 -2
- package/hot/poll.js +5 -2
- package/hot/signal.js +6 -2
- package/lib/APIPlugin.js +226 -122
- package/lib/AbstractMethodError.js +10 -5
- package/lib/AsyncDependenciesBlock.js +13 -5
- package/lib/AutomaticPrefetchPlugin.js +2 -1
- package/lib/BannerPlugin.js +33 -12
- package/lib/Cache.js +16 -12
- package/lib/CacheFacade.js +13 -16
- package/lib/CaseSensitiveModulesWarning.js +8 -8
- package/lib/Chunk.js +60 -33
- package/lib/ChunkGraph.js +207 -72
- package/lib/ChunkGroup.js +40 -20
- package/lib/ChunkTemplate.js +43 -0
- package/lib/CleanPlugin.js +117 -32
- package/lib/CodeGenerationResults.js +8 -7
- package/lib/CommentCompilationWarning.js +0 -1
- package/lib/CompatibilityPlugin.js +85 -46
- package/lib/Compilation.js +712 -392
- package/lib/Compiler.js +393 -172
- package/lib/ConcatenationScope.js +10 -13
- package/lib/ConditionalInitFragment.js +22 -14
- package/lib/ConstPlugin.js +104 -64
- package/lib/ContextExclusionPlugin.js +3 -3
- package/lib/ContextModule.js +283 -108
- package/lib/ContextModuleFactory.js +151 -63
- package/lib/ContextReplacementPlugin.js +25 -10
- package/lib/CssModule.js +166 -0
- package/lib/DefinePlugin.js +254 -148
- package/lib/DelegatedModule.js +29 -6
- package/lib/DelegatedModuleFactoryPlugin.js +42 -22
- package/lib/DelegatedPlugin.js +4 -0
- package/lib/DependenciesBlock.js +17 -2
- package/lib/Dependency.js +58 -29
- package/lib/DependencyTemplate.js +24 -3
- package/lib/DependencyTemplates.js +2 -2
- package/lib/DllEntryPlugin.js +18 -1
- package/lib/DllModule.js +21 -4
- package/lib/DllModuleFactory.js +2 -1
- package/lib/DllPlugin.js +9 -7
- package/lib/DllReferencePlugin.js +50 -19
- package/lib/EntryOptionPlugin.js +6 -1
- package/lib/EntryPlugin.js +7 -4
- package/lib/Entrypoint.js +2 -2
- package/lib/EnvironmentNotSupportAsyncWarning.js +52 -0
- package/lib/EnvironmentPlugin.js +5 -2
- package/lib/ErrorHelpers.js +65 -26
- package/lib/EvalDevToolModulePlugin.js +37 -13
- package/lib/EvalSourceMapDevToolPlugin.js +50 -20
- package/lib/ExportsInfo.js +234 -133
- package/lib/ExportsInfoApiPlugin.js +31 -15
- package/lib/ExternalModule.js +391 -129
- package/lib/ExternalModuleFactoryPlugin.js +65 -17
- package/lib/FileSystemInfo.js +1038 -523
- package/lib/FlagAllModulesAsUsedPlugin.js +27 -27
- package/lib/FlagDependencyExportsPlugin.js +352 -349
- package/lib/FlagDependencyUsagePlugin.js +10 -10
- package/lib/FlagEntryExportAsUsedPlugin.js +26 -23
- package/lib/Generator.js +16 -8
- package/lib/GraphHelpers.js +3 -2
- package/lib/HookWebpackError.js +11 -13
- package/lib/HotModuleReplacementPlugin.js +221 -128
- package/lib/IgnoreErrorModuleFactory.js +4 -4
- package/lib/IgnorePlugin.js +5 -4
- package/lib/IgnoreWarningsPlugin.js +6 -9
- package/lib/InitFragment.js +39 -15
- package/lib/JavascriptMetaInfoPlugin.js +27 -15
- package/lib/LibManifestPlugin.js +45 -16
- package/lib/LoaderOptionsPlugin.js +13 -3
- package/lib/MainTemplate.js +74 -21
- package/lib/Module.js +155 -34
- package/lib/ModuleBuildError.js +13 -11
- package/lib/ModuleDependencyError.js +6 -4
- package/lib/ModuleDependencyWarning.js +6 -4
- package/lib/ModuleError.js +10 -5
- package/lib/ModuleFactory.js +4 -4
- package/lib/ModuleFilenameHelpers.js +164 -54
- package/lib/ModuleGraph.js +93 -53
- package/lib/ModuleGraphConnection.js +27 -13
- package/lib/ModuleHashingError.js +29 -0
- package/lib/ModuleInfoHeaderPlugin.js +92 -33
- package/lib/ModuleNotFoundError.js +5 -2
- package/lib/ModuleParseError.js +17 -9
- package/lib/ModuleProfile.js +1 -0
- package/lib/ModuleRestoreError.js +3 -1
- package/lib/ModuleStoreError.js +3 -2
- package/lib/ModuleTemplate.js +33 -1
- package/lib/ModuleTypeConstants.js +168 -0
- package/lib/ModuleWarning.js +10 -5
- package/lib/MultiCompiler.js +115 -38
- package/lib/MultiStats.js +75 -33
- package/lib/MultiWatching.js +6 -2
- package/lib/NodeStuffPlugin.js +136 -37
- package/lib/NormalModule.js +437 -194
- package/lib/NormalModuleFactory.js +313 -116
- package/lib/NormalModuleReplacementPlugin.js +10 -4
- package/lib/NullFactory.js +1 -1
- package/lib/OptimizationStages.js +3 -3
- package/lib/Parser.js +1 -1
- package/lib/PlatformPlugin.js +39 -0
- package/lib/PrefetchPlugin.js +4 -0
- package/lib/ProgressPlugin.js +83 -28
- package/lib/ProvidePlugin.js +37 -19
- package/lib/RawModule.js +18 -5
- package/lib/RecordIdsPlugin.js +8 -8
- package/lib/RequireJsStuffPlugin.js +22 -15
- package/lib/ResolverFactory.js +8 -4
- package/lib/RuntimeGlobals.js +99 -65
- package/lib/RuntimeModule.js +17 -15
- package/lib/RuntimePlugin.js +116 -13
- package/lib/RuntimeTemplate.js +304 -102
- package/lib/SelfModuleFactory.js +12 -0
- package/lib/SizeFormatHelpers.js +2 -4
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
- package/lib/SourceMapDevToolPlugin.js +89 -42
- package/lib/Stats.js +12 -7
- package/lib/Template.js +30 -33
- package/lib/TemplatedPathPlugin.js +102 -34
- package/lib/UseStrictPlugin.js +37 -12
- package/lib/WarnCaseSensitiveModulesPlugin.js +12 -0
- package/lib/WarnDeprecatedOptionPlugin.js +6 -0
- package/lib/WatchIgnorePlugin.js +46 -13
- package/lib/Watching.js +139 -76
- package/lib/WebpackError.js +14 -5
- package/lib/WebpackIsIncludedPlugin.js +22 -13
- package/lib/WebpackOptionsApply.js +162 -56
- package/lib/WebpackOptionsDefaulter.js +10 -3
- package/lib/asset/AssetGenerator.js +351 -99
- package/lib/asset/AssetModulesPlugin.js +57 -33
- package/lib/asset/AssetParser.js +15 -6
- package/lib/asset/AssetSourceGenerator.js +30 -10
- package/lib/asset/AssetSourceParser.js +8 -2
- package/lib/asset/RawDataUrlModule.js +162 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +16 -13
- package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
- package/lib/buildChunkGraph.js +376 -420
- package/lib/cache/AddManagedPathsPlugin.js +6 -1
- package/lib/cache/IdleFileCachePlugin.js +26 -13
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +13 -7
- package/lib/cache/PackFileCacheStrategy.js +172 -94
- package/lib/cache/ResolverCachePlugin.js +115 -43
- package/lib/cache/getLazyHashedEtag.js +2 -2
- package/lib/cache/mergeEtags.js +16 -21
- package/lib/cli.js +195 -110
- package/lib/config/browserslistTargetHandler.js +106 -41
- package/lib/config/defaults.js +572 -154
- package/lib/config/normalization.js +361 -322
- package/lib/config/target.js +105 -66
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +27 -11
- package/lib/container/ContainerEntryModuleFactory.js +1 -1
- package/lib/container/ContainerExposedDependency.js +9 -0
- package/lib/container/ContainerPlugin.js +18 -12
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackDependency.js +13 -0
- package/lib/container/FallbackItemDependency.js +3 -0
- package/lib/container/FallbackModule.js +19 -8
- package/lib/container/FallbackModuleFactory.js +1 -1
- package/lib/container/ModuleFederationPlugin.js +2 -0
- package/lib/container/RemoteModule.js +17 -4
- package/lib/container/RemoteRuntimeModule.js +31 -17
- package/lib/container/RemoteToExternalDependency.js +3 -0
- package/lib/container/options.js +18 -4
- package/lib/css/CssExportsGenerator.js +203 -0
- package/lib/css/CssGenerator.js +151 -0
- package/lib/css/CssLoadingRuntimeModule.js +592 -0
- package/lib/css/CssModulesPlugin.js +888 -0
- package/lib/css/CssParser.js +1049 -0
- package/lib/css/walkCssTokens.js +775 -0
- package/lib/debug/ProfilingPlugin.js +102 -54
- package/lib/dependencies/AMDDefineDependency.js +54 -10
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +204 -61
- package/lib/dependencies/AMDPlugin.js +44 -24
- package/lib/dependencies/AMDRequireArrayDependency.js +34 -10
- package/lib/dependencies/AMDRequireContextDependency.js +15 -0
- package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +185 -54
- package/lib/dependencies/AMDRequireDependency.js +21 -6
- package/lib/dependencies/AMDRequireItemDependency.js +6 -0
- package/lib/dependencies/AMDRuntimeModules.js +4 -4
- package/lib/dependencies/CachedConstDependency.js +22 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +16 -2
- package/lib/dependencies/CommonJsExportRequireDependency.js +77 -47
- package/lib/dependencies/CommonJsExportsDependency.js +28 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +111 -39
- package/lib/dependencies/CommonJsFullRequireDependency.js +42 -8
- package/lib/dependencies/CommonJsImportsParserPlugin.js +530 -130
- package/lib/dependencies/CommonJsPlugin.js +51 -26
- package/lib/dependencies/CommonJsRequireContextDependency.js +23 -2
- package/lib/dependencies/CommonJsRequireDependency.js +9 -1
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -8
- package/lib/dependencies/ConstDependency.js +12 -3
- package/lib/dependencies/ContextDependency.js +32 -5
- package/lib/dependencies/ContextDependencyHelpers.js +92 -62
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
- package/lib/dependencies/ContextElementDependency.js +41 -4
- package/lib/dependencies/CreateScriptUrlDependency.js +22 -1
- package/lib/dependencies/CriticalDependencyWarning.js +4 -1
- package/lib/dependencies/CssExportDependency.js +156 -0
- package/lib/dependencies/CssImportDependency.js +125 -0
- package/lib/dependencies/CssLocalIdentifierDependency.js +245 -0
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +111 -0
- package/lib/dependencies/CssUrlDependency.js +164 -0
- package/lib/dependencies/DelegatedSourceDependency.js +3 -0
- package/lib/dependencies/DllEntryDependency.js +14 -0
- package/lib/dependencies/DynamicExports.js +15 -11
- package/lib/dependencies/ExportsInfoDependency.js +26 -5
- package/lib/dependencies/ExternalModuleDependency.js +109 -0
- package/lib/dependencies/ExternalModuleInitFragment.js +133 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +11 -2
- package/lib/dependencies/HarmonyAcceptImportDependency.js +9 -4
- package/lib/dependencies/HarmonyCompatibilityDependency.js +6 -5
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +29 -3
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +152 -0
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +96 -51
- package/lib/dependencies/HarmonyExportExpressionDependency.js +21 -4
- package/lib/dependencies/HarmonyExportHeaderDependency.js +13 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +216 -108
- package/lib/dependencies/HarmonyExportInitFragment.js +21 -9
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +12 -0
- package/lib/dependencies/HarmonyExports.js +13 -7
- package/lib/dependencies/HarmonyImportDependency.js +65 -19
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +268 -74
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +11 -5
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +180 -36
- package/lib/dependencies/HarmonyModulesPlugin.js +33 -5
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
- package/lib/dependencies/ImportContextDependency.js +15 -2
- package/lib/dependencies/ImportDependency.js +50 -12
- package/lib/dependencies/ImportEagerDependency.js +11 -6
- package/lib/dependencies/ImportMetaContextDependency.js +42 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +301 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +72 -0
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
- package/lib/dependencies/ImportMetaPlugin.js +128 -59
- package/lib/dependencies/ImportParserPlugin.js +153 -83
- package/lib/dependencies/ImportPlugin.js +21 -7
- package/lib/dependencies/ImportWeakDependency.js +11 -6
- package/lib/dependencies/JsonExportsDependency.js +38 -30
- package/lib/dependencies/LoaderDependency.js +14 -0
- package/lib/dependencies/LoaderImportDependency.js +14 -0
- package/lib/dependencies/LoaderPlugin.js +54 -40
- package/lib/dependencies/LocalModule.js +17 -1
- package/lib/dependencies/LocalModuleDependency.js +15 -0
- package/lib/dependencies/LocalModulesHelpers.js +22 -4
- package/lib/dependencies/ModuleDecoratorDependency.js +9 -1
- package/lib/dependencies/ModuleDependency.js +24 -7
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
- package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
- package/lib/dependencies/PrefetchDependency.js +3 -0
- package/lib/dependencies/ProvidedDependency.js +43 -8
- package/lib/dependencies/PureExpressionDependency.js +73 -39
- package/lib/dependencies/RequireContextDependency.js +6 -16
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +14 -6
- package/lib/dependencies/RequireContextPlugin.js +20 -7
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +7 -0
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +29 -12
- package/lib/dependencies/RequireEnsureDependency.js +16 -2
- package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
- package/lib/dependencies/RequireEnsurePlugin.js +27 -7
- package/lib/dependencies/RequireHeaderDependency.js +14 -1
- package/lib/dependencies/RequireIncludeDependency.js +6 -1
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +29 -5
- package/lib/dependencies/RequireIncludePlugin.js +25 -5
- package/lib/dependencies/RequireResolveContextDependency.js +19 -2
- package/lib/dependencies/RequireResolveDependency.js +8 -1
- package/lib/dependencies/RequireResolveHeaderDependency.js +18 -0
- package/lib/dependencies/RuntimeRequirementsDependency.js +9 -1
- package/lib/dependencies/StaticExportsDependency.js +8 -0
- package/lib/dependencies/SystemPlugin.js +49 -22
- package/lib/dependencies/SystemRuntimeModule.js +1 -1
- package/lib/dependencies/URLDependency.js +20 -13
- package/lib/dependencies/URLPlugin.js +115 -27
- package/lib/dependencies/UnsupportedDependency.js +13 -0
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +14 -0
- package/lib/dependencies/WebAssemblyImportDependency.js +9 -1
- package/lib/dependencies/WebpackIsIncludedDependency.js +6 -1
- package/lib/dependencies/WorkerDependency.js +47 -3
- package/lib/dependencies/WorkerPlugin.js +143 -59
- package/lib/dependencies/getFunctionExpression.js +9 -0
- package/lib/dependencies/processExportInfo.js +3 -1
- package/lib/electron/ElectronTargetPlugin.js +1 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +3 -2
- package/lib/esm/ModuleChunkFormatPlugin.js +92 -55
- package/lib/esm/ModuleChunkLoadingPlugin.js +12 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +141 -25
- package/lib/formatLocation.js +1 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +37 -25
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +2 -1
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +13 -15
- package/lib/hmr/LazyCompilationPlugin.js +94 -41
- package/lib/hmr/lazyCompilationBackend.js +107 -44
- package/lib/ids/ChunkModuleIdRangePlugin.js +12 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +13 -6
- package/lib/ids/DeterministicModuleIdsPlugin.js +59 -35
- package/lib/ids/HashedModuleIdsPlugin.js +24 -16
- package/lib/ids/IdHelpers.js +59 -49
- package/lib/ids/NamedChunkIdsPlugin.js +13 -1
- package/lib/ids/NamedModuleIdsPlugin.js +20 -12
- package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
- package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +14 -11
- package/lib/ids/SyncModuleIdsPlugin.js +146 -0
- package/lib/index.js +44 -5
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +9 -7
- package/lib/javascript/BasicEvaluatedExpression.js +133 -19
- package/lib/javascript/ChunkHelpers.js +33 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +18 -15
- package/lib/javascript/EnableChunkLoadingPlugin.js +11 -6
- package/lib/javascript/JavascriptGenerator.js +37 -6
- package/lib/javascript/JavascriptModulesPlugin.js +523 -295
- package/lib/javascript/JavascriptParser.js +1591 -574
- package/lib/javascript/JavascriptParserHelpers.js +58 -37
- package/lib/javascript/StartupHelpers.js +69 -47
- package/lib/json/JsonData.js +33 -0
- package/lib/json/JsonGenerator.js +29 -21
- package/lib/json/JsonModulesPlugin.js +13 -7
- package/lib/json/JsonParser.js +30 -16
- package/lib/library/AbstractLibraryPlugin.js +6 -2
- package/lib/library/AmdLibraryPlugin.js +34 -18
- package/lib/library/AssignLibraryPlugin.js +68 -32
- package/lib/library/EnableLibraryPlugin.js +39 -14
- package/lib/library/ExportPropertyLibraryPlugin.js +14 -5
- package/lib/library/JsonpLibraryPlugin.js +4 -3
- package/lib/library/ModernModuleLibraryPlugin.js +144 -0
- package/lib/library/ModuleLibraryPlugin.js +12 -7
- package/lib/library/SystemLibraryPlugin.js +6 -4
- package/lib/library/UmdLibraryPlugin.js +119 -100
- package/lib/logging/Logger.js +59 -6
- package/lib/logging/createConsoleLogger.js +25 -40
- package/lib/logging/runtime.js +8 -9
- package/lib/logging/truncateArgs.js +9 -8
- package/lib/node/CommonJsChunkLoadingPlugin.js +18 -2
- package/lib/node/NodeEnvironmentPlugin.js +14 -8
- package/lib/node/NodeTargetPlugin.js +7 -0
- package/lib/node/NodeTemplatePlugin.js +10 -2
- package/lib/node/NodeWatchFileSystem.js +100 -50
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +51 -26
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +13 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +21 -3
- package/lib/node/RequireChunkLoadingRuntimeModule.js +49 -26
- package/lib/node/nodeConsole.js +48 -31
- package/lib/optimize/AggressiveMergingPlugin.js +10 -4
- package/lib/optimize/AggressiveSplittingPlugin.js +26 -21
- package/lib/optimize/ConcatenatedModule.js +353 -212
- package/lib/optimize/EnsureChunkConditionsPlugin.js +4 -1
- package/lib/optimize/FlagIncludedChunksPlugin.js +14 -8
- package/lib/optimize/InnerGraph.js +30 -25
- package/lib/optimize/InnerGraphPlugin.js +105 -64
- package/lib/optimize/LimitChunkCountPlugin.js +32 -9
- package/lib/optimize/MangleExportsPlugin.js +7 -2
- package/lib/optimize/MinMaxSizeWarning.js +6 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +150 -83
- package/lib/optimize/RealContentHashPlugin.js +99 -43
- package/lib/optimize/RemoveParentModulesPlugin.js +131 -48
- package/lib/optimize/RuntimeChunkPlugin.js +15 -2
- package/lib/optimize/SideEffectsFlagPlugin.js +119 -63
- package/lib/optimize/SplitChunksPlugin.js +129 -78
- package/lib/performance/SizeLimitsPlugin.js +22 -8
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +4 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +8 -5
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +5 -3
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +5 -3
- package/lib/rules/BasicEffectRulePlugin.js +7 -1
- package/lib/rules/BasicMatcherRulePlugin.js +8 -1
- package/lib/rules/ObjectMatcherRulePlugin.js +19 -2
- package/lib/rules/RuleSetCompiler.js +53 -32
- package/lib/rules/UseEffectRulePlugin.js +42 -36
- package/lib/runtime/AsyncModuleRuntimeModule.js +56 -69
- package/lib/runtime/AutoPublicPathRuntimeModule.js +25 -9
- package/lib/runtime/BaseUriRuntimeModule.js +35 -0
- 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 +7 -4
- package/lib/runtime/CreateScriptRuntimeModule.js +38 -0
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +13 -36
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +6 -3
- package/lib/runtime/EnsureChunkRuntimeModule.js +29 -15
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +56 -43
- package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
- package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +98 -0
- package/lib/runtime/GlobalRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
- package/lib/runtime/LoadScriptRuntimeModule.js +61 -45
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
- package/lib/runtime/NonceRuntimeModule.js +24 -0
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
- package/lib/runtime/PublicPathRuntimeModule.js +9 -2
- package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
- package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
- package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +36 -28
- package/lib/runtime/StartupEntrypointRuntimeModule.js +13 -9
- package/lib/runtime/SystemContextRuntimeModule.js +1 -1
- package/lib/schemes/DataUriPlugin.js +16 -3
- package/lib/schemes/HttpUriPlugin.js +336 -120
- package/lib/serialization/ArraySerializer.js +22 -6
- package/lib/serialization/BinaryMiddleware.js +212 -33
- package/lib/serialization/DateObjectSerializer.js +16 -4
- package/lib/serialization/ErrorObjectSerializer.js +23 -6
- package/lib/serialization/FileMiddleware.js +187 -86
- package/lib/serialization/MapObjectSerializer.js +25 -8
- package/lib/serialization/NullPrototypeObjectSerializer.js +26 -8
- package/lib/serialization/ObjectMiddleware.js +96 -66
- package/lib/serialization/PlainObjectSerializer.js +51 -14
- package/lib/serialization/RegExpObjectSerializer.js +17 -5
- package/lib/serialization/Serializer.js +23 -5
- package/lib/serialization/SerializerMiddleware.js +8 -8
- package/lib/serialization/SetObjectSerializer.js +22 -6
- package/lib/serialization/SingleItemMiddleware.js +2 -2
- package/lib/serialization/types.js +2 -2
- package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
- package/lib/sharing/ConsumeSharedModule.js +40 -17
- package/lib/sharing/ConsumeSharedPlugin.js +139 -102
- package/lib/sharing/ConsumeSharedRuntimeModule.js +144 -130
- package/lib/sharing/ProvideForSharedDependency.js +0 -1
- package/lib/sharing/ProvideSharedDependency.js +17 -0
- package/lib/sharing/ProvideSharedModule.js +19 -6
- package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +37 -30
- package/lib/sharing/SharePlugin.js +2 -2
- package/lib/sharing/ShareRuntimeModule.js +20 -10
- package/lib/sharing/resolveMatchedConfigs.js +6 -5
- package/lib/sharing/utils.js +338 -34
- package/lib/stats/DefaultStatsFactoryPlugin.js +660 -396
- package/lib/stats/DefaultStatsPresetPlugin.js +85 -25
- package/lib/stats/DefaultStatsPrinterPlugin.js +525 -145
- package/lib/stats/StatsFactory.js +128 -57
- package/lib/stats/StatsPrinter.js +77 -46
- package/lib/util/ArrayHelpers.js +35 -1
- package/lib/util/ArrayQueue.js +15 -22
- package/lib/util/AsyncQueue.js +37 -16
- package/lib/util/IterableHelpers.js +3 -4
- package/lib/util/LazyBucketSortedSet.js +60 -44
- package/lib/util/LazySet.js +11 -2
- package/lib/util/MapHelpers.js +17 -5
- package/lib/util/ParallelismFactorCalculator.js +11 -1
- package/lib/util/Queue.js +9 -3
- package/lib/util/Semaphore.js +4 -7
- package/lib/util/SetHelpers.js +5 -5
- package/lib/util/SortableSet.js +19 -6
- package/lib/util/StackedCacheMap.js +33 -3
- package/lib/util/StackedMap.js +1 -3
- package/lib/util/StringXor.js +46 -0
- package/lib/util/TupleQueue.js +9 -3
- package/lib/util/TupleSet.js +15 -5
- package/lib/util/URLAbsoluteSpecifier.js +8 -8
- package/lib/util/WeakTupleMap.js +70 -28
- package/lib/util/binarySearchBounds.js +51 -9
- package/lib/util/chainedImports.js +97 -0
- package/lib/util/cleverMerge.js +51 -36
- package/lib/util/comparators.js +146 -83
- package/lib/util/compileBooleanMatcher.js +35 -7
- package/lib/util/conventions.js +126 -0
- package/lib/util/create-schema-validation.js +9 -2
- package/lib/util/createHash.js +49 -14
- package/lib/util/deprecation.js +48 -15
- package/lib/util/deterministicGrouping.js +71 -39
- package/lib/util/extractUrlAndGlobal.js +3 -0
- package/lib/util/findGraphRoots.js +7 -5
- package/lib/util/fs.js +419 -94
- package/lib/util/hash/BatchedHash.js +10 -4
- package/lib/util/hash/md4.js +20 -0
- package/lib/util/hash/wasm-hash.js +163 -0
- package/lib/util/hash/xxhash64.js +7 -141
- package/lib/util/identifier.js +140 -93
- package/lib/util/internalSerializables.js +22 -0
- package/lib/util/makeSerializable.js +7 -0
- package/lib/util/memoize.js +10 -10
- package/lib/util/mergeScope.js +76 -0
- package/lib/util/nonNumericOnlyHash.js +22 -0
- package/lib/util/numberHash.js +84 -34
- package/lib/util/objectToMap.js +0 -1
- package/lib/util/processAsyncTree.js +7 -1
- package/lib/util/propertyAccess.js +7 -55
- package/lib/util/propertyName.js +77 -0
- package/lib/util/registerExternalSerializer.js +2 -2
- package/lib/util/runtime.js +188 -133
- package/lib/util/semver.js +64 -56
- package/lib/util/serialization.js +26 -1
- package/lib/util/smartGrouping.js +10 -10
- package/lib/util/source.js +1 -1
- package/lib/validateSchema.js +6 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +9 -4
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +70 -30
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +34 -16
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +32 -12
- package/lib/wasm-async/AsyncWebAssemblyParser.js +17 -4
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +72 -31
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +17 -6
- package/lib/wasm-sync/WebAssemblyGenerator.js +72 -52
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -4
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +53 -43
- package/lib/wasm-sync/WebAssemblyParser.js +23 -9
- package/lib/wasm-sync/WebAssemblyUtils.js +5 -4
- package/lib/web/FetchCompileAsyncWasmPlugin.js +11 -1
- package/lib/web/FetchCompileWasmPlugin.js +59 -42
- package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +71 -41
- package/lib/webpack.js +43 -12
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +15 -12
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +55 -40
- package/module.d.ts +233 -0
- package/package.json +85 -139
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +679 -47
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +9 -1
- package/schemas/plugins/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +10 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +2 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +12 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoParserOptions.json +3 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssGlobalParserOptions.json +3 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssParserOptions.json +3 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
- package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
- package/types.d.ts +5026 -1756
package/lib/ExportsInfo.js
CHANGED
@@ -14,6 +14,8 @@ const { forEachRuntime } = require("./util/runtime");
|
|
14
14
|
/** @typedef {import("./Module")} Module */
|
15
15
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
16
16
|
/** @typedef {import("./ModuleGraphConnection")} ModuleGraphConnection */
|
17
|
+
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
18
|
+
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
17
19
|
/** @typedef {import("./util/Hash")} Hash */
|
18
20
|
|
19
21
|
/** @typedef {typeof UsageState.OnlyPropertiesUsed | typeof UsageState.NoInfo | typeof UsageState.Unknown | typeof UsageState.Used} RuntimeUsageStateType */
|
@@ -44,6 +46,9 @@ class RestoreProvidedData {
|
|
44
46
|
this.otherTerminalBinding = otherTerminalBinding;
|
45
47
|
}
|
46
48
|
|
49
|
+
/**
|
50
|
+
* @param {ObjectSerializerContext} context context
|
51
|
+
*/
|
47
52
|
serialize({ write }) {
|
48
53
|
write(this.exports);
|
49
54
|
write(this.otherProvided);
|
@@ -51,6 +56,10 @@ class RestoreProvidedData {
|
|
51
56
|
write(this.otherTerminalBinding);
|
52
57
|
}
|
53
58
|
|
59
|
+
/**
|
60
|
+
* @param {ObjectDeserializerContext} context context
|
61
|
+
* @returns {RestoreProvidedData} RestoreProvidedData
|
62
|
+
*/
|
54
63
|
static deserialize({ read }) {
|
55
64
|
return new RestoreProvidedData(read(), read(), read(), read());
|
56
65
|
}
|
@@ -62,9 +71,12 @@ makeSerializable(
|
|
62
71
|
"RestoreProvidedData"
|
63
72
|
);
|
64
73
|
|
74
|
+
/** @typedef {Map<string, ExportInfo>} Exports */
|
75
|
+
/** @typedef {string | string[] | false} UsedName */
|
76
|
+
|
65
77
|
class ExportsInfo {
|
66
78
|
constructor() {
|
67
|
-
/** @type {
|
79
|
+
/** @type {Exports} */
|
68
80
|
this._exports = new Map();
|
69
81
|
this._otherExportsInfo = new ExportInfo(null);
|
70
82
|
this._sideEffectsOnlyInfo = new ExportInfo("*side effects only*");
|
@@ -135,6 +147,10 @@ class ExportsInfo {
|
|
135
147
|
return this._otherExportsInfo;
|
136
148
|
}
|
137
149
|
|
150
|
+
/**
|
151
|
+
* @param {Exports} exports exports
|
152
|
+
* @private
|
153
|
+
*/
|
138
154
|
_sortExportsMap(exports) {
|
139
155
|
if (exports.size > 1) {
|
140
156
|
const namesInOrder = [];
|
@@ -150,7 +166,7 @@ class ExportsInfo {
|
|
150
166
|
}
|
151
167
|
for (; i < namesInOrder.length; i++) {
|
152
168
|
const name = namesInOrder[i];
|
153
|
-
const correctEntry = exports.get(name);
|
169
|
+
const correctEntry = /** @type {ExportInfo} */ (exports.get(name));
|
154
170
|
exports.delete(name);
|
155
171
|
exports.set(name, correctEntry);
|
156
172
|
}
|
@@ -162,6 +178,10 @@ class ExportsInfo {
|
|
162
178
|
this._exportsAreOrdered = true;
|
163
179
|
}
|
164
180
|
|
181
|
+
/**
|
182
|
+
* @param {ExportsInfo | undefined} exportsInfo exports info
|
183
|
+
* @returns {boolean} result
|
184
|
+
*/
|
165
185
|
setRedirectNamedTo(exportsInfo) {
|
166
186
|
if (this._redirectTo === exportsInfo) return false;
|
167
187
|
this._redirectTo = exportsInfo;
|
@@ -198,9 +218,6 @@ class ExportsInfo {
|
|
198
218
|
this._redirectTo.setHasUseInfo();
|
199
219
|
} else {
|
200
220
|
this._otherExportsInfo.setHasUseInfo();
|
201
|
-
if (this._otherExportsInfo.canMangleUse === undefined) {
|
202
|
-
this._otherExportsInfo.canMangleUse = true;
|
203
|
-
}
|
204
221
|
}
|
205
222
|
}
|
206
223
|
|
@@ -251,7 +268,7 @@ class ExportsInfo {
|
|
251
268
|
getReadOnlyExportInfoRecursive(name) {
|
252
269
|
const exportInfo = this.getReadOnlyExportInfo(name[0]);
|
253
270
|
if (name.length === 1) return exportInfo;
|
254
|
-
if (!exportInfo.exportsInfo) return
|
271
|
+
if (!exportInfo.exportsInfo) return;
|
255
272
|
return exportInfo.exportsInfo.getReadOnlyExportInfoRecursive(name.slice(1));
|
256
273
|
}
|
257
274
|
|
@@ -262,7 +279,7 @@ class ExportsInfo {
|
|
262
279
|
getNestedExportsInfo(name) {
|
263
280
|
if (Array.isArray(name) && name.length > 0) {
|
264
281
|
const info = this.getReadOnlyExportInfo(name[0]);
|
265
|
-
if (!info.exportsInfo) return
|
282
|
+
if (!info.exportsInfo) return;
|
266
283
|
return info.exportsInfo.getNestedExportsInfo(name.slice(1));
|
267
284
|
}
|
268
285
|
return this;
|
@@ -291,17 +308,22 @@ class ExportsInfo {
|
|
291
308
|
}
|
292
309
|
}
|
293
310
|
for (const exportInfo of this._exports.values()) {
|
311
|
+
if (!canMangle && exportInfo.canMangleProvide !== false) {
|
312
|
+
exportInfo.canMangleProvide = false;
|
313
|
+
changed = true;
|
314
|
+
}
|
294
315
|
if (excludeExports && excludeExports.has(exportInfo.name)) continue;
|
295
316
|
if (exportInfo.provided !== true && exportInfo.provided !== null) {
|
296
317
|
exportInfo.provided = null;
|
297
318
|
changed = true;
|
298
319
|
}
|
299
|
-
if (!canMangle && exportInfo.canMangleProvide !== false) {
|
300
|
-
exportInfo.canMangleProvide = false;
|
301
|
-
changed = true;
|
302
|
-
}
|
303
320
|
if (targetKey) {
|
304
|
-
exportInfo.setTarget(
|
321
|
+
exportInfo.setTarget(
|
322
|
+
targetKey,
|
323
|
+
/** @type {ModuleGraphConnection} */ (targetModule),
|
324
|
+
[exportInfo.name],
|
325
|
+
-1
|
326
|
+
);
|
305
327
|
}
|
306
328
|
}
|
307
329
|
if (this._redirectTo !== undefined) {
|
@@ -331,7 +353,7 @@ class ExportsInfo {
|
|
331
353
|
if (targetKey) {
|
332
354
|
this._otherExportsInfo.setTarget(
|
333
355
|
targetKey,
|
334
|
-
targetModule,
|
356
|
+
/** @type {ModuleGraphConnection} */ (targetModule),
|
335
357
|
undefined,
|
336
358
|
priority
|
337
359
|
);
|
@@ -436,10 +458,8 @@ class ExportsInfo {
|
|
436
458
|
if (this._redirectTo.isUsed(runtime)) {
|
437
459
|
return true;
|
438
460
|
}
|
439
|
-
} else {
|
440
|
-
|
441
|
-
return true;
|
442
|
-
}
|
461
|
+
} else if (this._otherExportsInfo.getUsed(runtime) !== UsageState.Unused) {
|
462
|
+
return true;
|
443
463
|
}
|
444
464
|
for (const exportInfo of this._exports.values()) {
|
445
465
|
if (exportInfo.getUsed(runtime) !== UsageState.Unused) {
|
@@ -465,6 +485,7 @@ class ExportsInfo {
|
|
465
485
|
* @returns {SortableSet<string> | boolean | null} set of used exports, or true (when namespace object is used), or false (when unused), or null (when unknown)
|
466
486
|
*/
|
467
487
|
getUsedExports(runtime) {
|
488
|
+
// eslint-disable-next-line no-constant-binary-expression
|
468
489
|
if (!this._redirectTo !== undefined) {
|
469
490
|
switch (this._otherExportsInfo.getUsed(runtime)) {
|
470
491
|
case UsageState.NoInfo:
|
@@ -506,13 +527,14 @@ class ExportsInfo {
|
|
506
527
|
return false;
|
507
528
|
}
|
508
529
|
}
|
509
|
-
return new SortableSet(array);
|
530
|
+
return /** @type {SortableSet<string>} */ (new SortableSet(array));
|
510
531
|
}
|
511
532
|
|
512
533
|
/**
|
513
534
|
* @returns {null | true | string[]} list of exports when known
|
514
535
|
*/
|
515
536
|
getProvidedExports() {
|
537
|
+
// eslint-disable-next-line no-constant-binary-expression
|
516
538
|
if (!this._redirectTo !== undefined) {
|
517
539
|
switch (this._otherExportsInfo.provided) {
|
518
540
|
case undefined:
|
@@ -584,7 +606,7 @@ class ExportsInfo {
|
|
584
606
|
if (info.exportsInfo && name.length > 1) {
|
585
607
|
return info.exportsInfo.isExportProvided(name.slice(1));
|
586
608
|
}
|
587
|
-
return info.provided;
|
609
|
+
return info.provided ? name.length === 1 || undefined : info.provided;
|
588
610
|
}
|
589
611
|
const info = this.getReadOnlyExportInfo(name);
|
590
612
|
return info.provided;
|
@@ -616,13 +638,11 @@ class ExportsInfo {
|
|
616
638
|
isEquallyUsed(runtimeA, runtimeB) {
|
617
639
|
if (this._redirectTo !== undefined) {
|
618
640
|
if (!this._redirectTo.isEquallyUsed(runtimeA, runtimeB)) return false;
|
619
|
-
} else
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
return false;
|
625
|
-
}
|
641
|
+
} else if (
|
642
|
+
this._otherExportsInfo.getUsed(runtimeA) !==
|
643
|
+
this._otherExportsInfo.getUsed(runtimeB)
|
644
|
+
) {
|
645
|
+
return false;
|
626
646
|
}
|
627
647
|
if (
|
628
648
|
this._sideEffectsOnlyInfo.getUsed(runtimeA) !==
|
@@ -645,20 +665,20 @@ class ExportsInfo {
|
|
645
665
|
getUsed(name, runtime) {
|
646
666
|
if (Array.isArray(name)) {
|
647
667
|
if (name.length === 0) return this.otherExportsInfo.getUsed(runtime);
|
648
|
-
|
668
|
+
const info = this.getReadOnlyExportInfo(name[0]);
|
649
669
|
if (info.exportsInfo && name.length > 1) {
|
650
670
|
return info.exportsInfo.getUsed(name.slice(1), runtime);
|
651
671
|
}
|
652
672
|
return info.getUsed(runtime);
|
653
673
|
}
|
654
|
-
|
674
|
+
const info = this.getReadOnlyExportInfo(name);
|
655
675
|
return info.getUsed(runtime);
|
656
676
|
}
|
657
677
|
|
658
678
|
/**
|
659
679
|
* @param {string | string[]} name the export name
|
660
680
|
* @param {RuntimeSpec} runtime check usage for this runtime only
|
661
|
-
* @returns {
|
681
|
+
* @returns {UsedName} the used name
|
662
682
|
*/
|
663
683
|
getUsedName(name, runtime) {
|
664
684
|
if (Array.isArray(name)) {
|
@@ -667,10 +687,12 @@ class ExportsInfo {
|
|
667
687
|
if (!this.isUsed(runtime)) return false;
|
668
688
|
return name;
|
669
689
|
}
|
670
|
-
|
690
|
+
const info = this.getReadOnlyExportInfo(name[0]);
|
671
691
|
const x = info.getUsedName(name[0], runtime);
|
672
692
|
if (x === false) return false;
|
673
|
-
const arr =
|
693
|
+
const arr =
|
694
|
+
/** @type {string[]} */
|
695
|
+
(x === name[0] && name.length === 1 ? name : [x]);
|
674
696
|
if (name.length === 1) {
|
675
697
|
return arr;
|
676
698
|
}
|
@@ -681,14 +703,12 @@ class ExportsInfo {
|
|
681
703
|
const nested = info.exportsInfo.getUsedName(name.slice(1), runtime);
|
682
704
|
if (!nested) return false;
|
683
705
|
return arr.concat(nested);
|
684
|
-
} else {
|
685
|
-
return arr.concat(name.slice(1));
|
686
706
|
}
|
687
|
-
|
688
|
-
let info = this.getReadOnlyExportInfo(name);
|
689
|
-
const usedName = info.getUsedName(name, runtime);
|
690
|
-
return usedName;
|
707
|
+
return arr.concat(name.slice(1));
|
691
708
|
}
|
709
|
+
const info = this.getReadOnlyExportInfo(name);
|
710
|
+
const usedName = info.getUsedName(name, runtime);
|
711
|
+
return usedName;
|
692
712
|
}
|
693
713
|
|
694
714
|
/**
|
@@ -721,6 +741,9 @@ class ExportsInfo {
|
|
721
741
|
}
|
722
742
|
}
|
723
743
|
|
744
|
+
/**
|
745
|
+
* @returns {RestoreProvidedData} restore provided data
|
746
|
+
*/
|
724
747
|
getRestoreProvidedData() {
|
725
748
|
const otherProvided = this._otherExportsInfo.provided;
|
726
749
|
const otherCanMangleProvide = this._otherExportsInfo.canMangleProvide;
|
@@ -739,7 +762,8 @@ class ExportsInfo {
|
|
739
762
|
canMangleProvide: exportInfo.canMangleProvide,
|
740
763
|
terminalBinding: exportInfo.terminalBinding,
|
741
764
|
exportsInfo: exportInfo.exportsInfoOwned
|
742
|
-
?
|
765
|
+
? /** @type {NonNullable<ExportInfo["exportsInfo"]>} */
|
766
|
+
(exportInfo.exportsInfo).getRestoreProvidedData()
|
743
767
|
: undefined
|
744
768
|
});
|
745
769
|
}
|
@@ -752,6 +776,9 @@ class ExportsInfo {
|
|
752
776
|
);
|
753
777
|
}
|
754
778
|
|
779
|
+
/**
|
780
|
+
* @param {{ otherProvided: any, otherCanMangleProvide: any, otherTerminalBinding: any, exports: any }} data data
|
781
|
+
*/
|
755
782
|
restoreProvided({
|
756
783
|
otherProvided,
|
757
784
|
otherCanMangleProvide,
|
@@ -782,6 +809,10 @@ class ExportsInfo {
|
|
782
809
|
}
|
783
810
|
}
|
784
811
|
|
812
|
+
/** @typedef {{ module: Module, export: string[] }} TargetItemWithoutConnection */
|
813
|
+
/** @typedef {{ module: Module, connection: ModuleGraphConnection, export: string[] | undefined }} TargetItem */
|
814
|
+
/** @typedef {Map<any, { connection: ModuleGraphConnection | null, export: string[], priority: number }>} Target */
|
815
|
+
|
785
816
|
class ExportInfo {
|
786
817
|
/**
|
787
818
|
* @param {string} name the original name of the export
|
@@ -790,16 +821,28 @@ class ExportInfo {
|
|
790
821
|
constructor(name, initFrom) {
|
791
822
|
/** @type {string} */
|
792
823
|
this.name = name;
|
793
|
-
/**
|
824
|
+
/**
|
825
|
+
* @private
|
826
|
+
* @type {string | null}
|
827
|
+
*/
|
794
828
|
this._usedName = initFrom ? initFrom._usedName : null;
|
795
|
-
/**
|
829
|
+
/**
|
830
|
+
* @private
|
831
|
+
* @type {UsageStateType | undefined}
|
832
|
+
*/
|
796
833
|
this._globalUsed = initFrom ? initFrom._globalUsed : undefined;
|
797
|
-
/**
|
834
|
+
/**
|
835
|
+
* @private
|
836
|
+
* @type {Map<string, RuntimeUsageStateType>}
|
837
|
+
*/
|
798
838
|
this._usedInRuntime =
|
799
839
|
initFrom && initFrom._usedInRuntime
|
800
840
|
? new Map(initFrom._usedInRuntime)
|
801
841
|
: undefined;
|
802
|
-
/**
|
842
|
+
/**
|
843
|
+
* @private
|
844
|
+
* @type {boolean}
|
845
|
+
*/
|
803
846
|
this._hasUseInRuntimeInfo = initFrom
|
804
847
|
? initFrom._hasUseInRuntimeInfo
|
805
848
|
: false;
|
@@ -832,9 +875,9 @@ class ExportInfo {
|
|
832
875
|
this.canMangleUse = initFrom ? initFrom.canMangleUse : undefined;
|
833
876
|
/** @type {boolean} */
|
834
877
|
this.exportsInfoOwned = false;
|
835
|
-
/** @type {ExportsInfo
|
878
|
+
/** @type {ExportsInfo | undefined} */
|
836
879
|
this.exportsInfo = undefined;
|
837
|
-
/** @type {
|
880
|
+
/** @type {Target | undefined} */
|
838
881
|
this._target = undefined;
|
839
882
|
if (initFrom && initFrom._target) {
|
840
883
|
this._target = new Map();
|
@@ -846,19 +889,11 @@ class ExportInfo {
|
|
846
889
|
});
|
847
890
|
}
|
848
891
|
}
|
849
|
-
/** @type {
|
892
|
+
/** @type {Target | undefined} */
|
850
893
|
this._maxTarget = undefined;
|
851
894
|
}
|
852
895
|
|
853
896
|
// TODO webpack 5 remove
|
854
|
-
/** @private */
|
855
|
-
get used() {
|
856
|
-
throw new Error("REMOVED");
|
857
|
-
}
|
858
|
-
/** @private */
|
859
|
-
get usedName() {
|
860
|
-
throw new Error("REMOVED");
|
861
|
-
}
|
862
897
|
/**
|
863
898
|
* @private
|
864
899
|
* @param {*} v v
|
@@ -866,6 +901,14 @@ class ExportInfo {
|
|
866
901
|
set used(v) {
|
867
902
|
throw new Error("REMOVED");
|
868
903
|
}
|
904
|
+
|
905
|
+
// TODO webpack 5 remove
|
906
|
+
/** @private */
|
907
|
+
get used() {
|
908
|
+
throw new Error("REMOVED");
|
909
|
+
}
|
910
|
+
|
911
|
+
// TODO webpack 5 remove
|
869
912
|
/**
|
870
913
|
* @private
|
871
914
|
* @param {*} v v
|
@@ -874,6 +917,12 @@ class ExportInfo {
|
|
874
917
|
throw new Error("REMOVED");
|
875
918
|
}
|
876
919
|
|
920
|
+
// TODO webpack 5 remove
|
921
|
+
/** @private */
|
922
|
+
get usedName() {
|
923
|
+
throw new Error("REMOVED");
|
924
|
+
}
|
925
|
+
|
877
926
|
get canMangle() {
|
878
927
|
switch (this.canMangleProvide) {
|
879
928
|
case undefined:
|
@@ -941,7 +990,8 @@ class ExportInfo {
|
|
941
990
|
this.canMangleUse = true;
|
942
991
|
}
|
943
992
|
if (this.exportsInfoOwned) {
|
944
|
-
|
993
|
+
/** @type {ExportsInfo} */
|
994
|
+
(this.exportsInfo).setHasUseInfo();
|
945
995
|
}
|
946
996
|
}
|
947
997
|
|
@@ -956,25 +1006,26 @@ class ExportInfo {
|
|
956
1006
|
if (this._globalUsed === undefined) {
|
957
1007
|
this._globalUsed = newValue;
|
958
1008
|
return true;
|
959
|
-
}
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
}
|
1009
|
+
}
|
1010
|
+
if (this._globalUsed !== newValue && condition(this._globalUsed)) {
|
1011
|
+
this._globalUsed = newValue;
|
1012
|
+
return true;
|
964
1013
|
}
|
965
1014
|
} else if (this._usedInRuntime === undefined) {
|
966
1015
|
if (newValue !== UsageState.Unused && condition(UsageState.Unused)) {
|
967
1016
|
this._usedInRuntime = new Map();
|
968
1017
|
forEachRuntime(runtime, runtime =>
|
969
|
-
this._usedInRuntime.set(runtime, newValue)
|
1018
|
+
this._usedInRuntime.set(/** @type {string} */ (runtime), newValue)
|
970
1019
|
);
|
971
1020
|
return true;
|
972
1021
|
}
|
973
1022
|
} else {
|
974
1023
|
let changed = false;
|
975
|
-
forEachRuntime(runtime,
|
976
|
-
/** @type {
|
977
|
-
let oldValue =
|
1024
|
+
forEachRuntime(runtime, _runtime => {
|
1025
|
+
const runtime = /** @type {string} */ (_runtime);
|
1026
|
+
let oldValue =
|
1027
|
+
/** @type {UsageStateType} */
|
1028
|
+
(this._usedInRuntime.get(runtime));
|
978
1029
|
if (oldValue === undefined) oldValue = UsageState.Unused;
|
979
1030
|
if (newValue !== oldValue && condition(oldValue)) {
|
980
1031
|
if (newValue === UsageState.Unused) {
|
@@ -1008,15 +1059,17 @@ class ExportInfo {
|
|
1008
1059
|
if (newValue !== UsageState.Unused) {
|
1009
1060
|
this._usedInRuntime = new Map();
|
1010
1061
|
forEachRuntime(runtime, runtime =>
|
1011
|
-
this._usedInRuntime.set(runtime, newValue)
|
1062
|
+
this._usedInRuntime.set(/** @type {string} */ (runtime), newValue)
|
1012
1063
|
);
|
1013
1064
|
return true;
|
1014
1065
|
}
|
1015
1066
|
} else {
|
1016
1067
|
let changed = false;
|
1017
|
-
forEachRuntime(runtime,
|
1018
|
-
/** @type {
|
1019
|
-
let oldValue =
|
1068
|
+
forEachRuntime(runtime, _runtime => {
|
1069
|
+
const runtime = /** @type {string} */ (_runtime);
|
1070
|
+
let oldValue =
|
1071
|
+
/** @type {UsageStateType} */
|
1072
|
+
(this._usedInRuntime.get(runtime));
|
1020
1073
|
if (oldValue === undefined) oldValue = UsageState.Unused;
|
1021
1074
|
if (newValue !== oldValue) {
|
1022
1075
|
if (newValue === UsageState.Unused) {
|
@@ -1051,7 +1104,7 @@ class ExportInfo {
|
|
1051
1104
|
/**
|
1052
1105
|
* @param {any} key the key
|
1053
1106
|
* @param {ModuleGraphConnection} connection the target module if a single one
|
1054
|
-
* @param {string[]=} exportName the exported name
|
1107
|
+
* @param {(string[] | null)=} exportName the exported name
|
1055
1108
|
* @param {number=} priority priority
|
1056
1109
|
* @returns {boolean} true, if something has changed
|
1057
1110
|
*/
|
@@ -1059,13 +1112,21 @@ class ExportInfo {
|
|
1059
1112
|
if (exportName) exportName = [...exportName];
|
1060
1113
|
if (!this._target) {
|
1061
1114
|
this._target = new Map();
|
1062
|
-
this._target.set(key, {
|
1115
|
+
this._target.set(key, {
|
1116
|
+
connection,
|
1117
|
+
export: /** @type {string[]} */ (exportName),
|
1118
|
+
priority
|
1119
|
+
});
|
1063
1120
|
return true;
|
1064
1121
|
}
|
1065
1122
|
const oldTarget = this._target.get(key);
|
1066
1123
|
if (!oldTarget) {
|
1067
1124
|
if (oldTarget === null && !connection) return false;
|
1068
|
-
this._target.set(key, {
|
1125
|
+
this._target.set(key, {
|
1126
|
+
connection,
|
1127
|
+
export: /** @type {string[]} */ (exportName),
|
1128
|
+
priority
|
1129
|
+
});
|
1069
1130
|
this._maxTarget = undefined;
|
1070
1131
|
return true;
|
1071
1132
|
}
|
@@ -1077,7 +1138,7 @@ class ExportInfo {
|
|
1077
1138
|
: oldTarget.export)
|
1078
1139
|
) {
|
1079
1140
|
oldTarget.connection = connection;
|
1080
|
-
oldTarget.export = exportName;
|
1141
|
+
oldTarget.export = /** @type {string[]} */ (exportName);
|
1081
1142
|
oldTarget.priority = priority;
|
1082
1143
|
this._maxTarget = undefined;
|
1083
1144
|
return true;
|
@@ -1107,20 +1168,20 @@ class ExportInfo {
|
|
1107
1168
|
if (max < value) max = value;
|
1108
1169
|
}
|
1109
1170
|
return max;
|
1110
|
-
}
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
if (max < value) max = value;
|
1171
|
+
}
|
1172
|
+
|
1173
|
+
/** @type {UsageStateType} */
|
1174
|
+
let max = UsageState.Unused;
|
1175
|
+
for (const item of runtime) {
|
1176
|
+
const value = this._usedInRuntime.get(item);
|
1177
|
+
if (value !== undefined) {
|
1178
|
+
if (value === UsageState.Used) {
|
1179
|
+
return UsageState.Used;
|
1120
1180
|
}
|
1181
|
+
if (max < value) max = value;
|
1121
1182
|
}
|
1122
|
-
return max;
|
1123
1183
|
}
|
1184
|
+
return max;
|
1124
1185
|
}
|
1125
1186
|
|
1126
1187
|
/**
|
@@ -1139,19 +1200,18 @@ class ExportInfo {
|
|
1139
1200
|
if (!this._usedInRuntime.has(runtime)) {
|
1140
1201
|
return false;
|
1141
1202
|
}
|
1142
|
-
} else if (
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
}
|
1203
|
+
} else if (
|
1204
|
+
runtime !== undefined &&
|
1205
|
+
Array.from(runtime).every(
|
1206
|
+
runtime => !this._usedInRuntime.has(runtime)
|
1207
|
+
)
|
1208
|
+
) {
|
1209
|
+
return false;
|
1150
1210
|
}
|
1151
1211
|
}
|
1152
1212
|
}
|
1153
1213
|
if (this._usedName !== null) return this._usedName;
|
1154
|
-
return this.name || fallbackName;
|
1214
|
+
return /** @type {string | false} */ (this.name || fallbackName);
|
1155
1215
|
}
|
1156
1216
|
|
1157
1217
|
/**
|
@@ -1172,13 +1232,13 @@ class ExportInfo {
|
|
1172
1232
|
|
1173
1233
|
/**
|
1174
1234
|
* @param {ModuleGraph} moduleGraph the module graph
|
1175
|
-
* @param {function(
|
1235
|
+
* @param {function(TargetItem): boolean} resolveTargetFilter filter function to further resolve target
|
1176
1236
|
* @returns {ExportInfo | ExportsInfo | undefined} the terminal binding export(s) info if known
|
1177
1237
|
*/
|
1178
1238
|
getTerminalBinding(moduleGraph, resolveTargetFilter = RETURNS_TRUE) {
|
1179
1239
|
if (this.terminalBinding) return this;
|
1180
1240
|
const target = this.getTarget(moduleGraph, resolveTargetFilter);
|
1181
|
-
if (!target) return
|
1241
|
+
if (!target) return;
|
1182
1242
|
const exportsInfo = moduleGraph.getExportsInfo(target.module);
|
1183
1243
|
if (!target.export) return exportsInfo;
|
1184
1244
|
return exportsInfo.getReadOnlyExportInfoRecursive(target.export);
|
@@ -1190,10 +1250,11 @@ class ExportInfo {
|
|
1190
1250
|
|
1191
1251
|
_getMaxTarget() {
|
1192
1252
|
if (this._maxTarget !== undefined) return this._maxTarget;
|
1193
|
-
if (this._target.size <= 1)
|
1253
|
+
if (/** @type {Target} */ (this._target).size <= 1)
|
1254
|
+
return (this._maxTarget = this._target);
|
1194
1255
|
let maxPriority = -Infinity;
|
1195
1256
|
let minPriority = Infinity;
|
1196
|
-
for (const { priority } of this._target.values()) {
|
1257
|
+
for (const { priority } of /** @type {Target} */ (this._target).values()) {
|
1197
1258
|
if (maxPriority < priority) maxPriority = priority;
|
1198
1259
|
if (minPriority > priority) minPriority = priority;
|
1199
1260
|
}
|
@@ -1202,7 +1263,7 @@ class ExportInfo {
|
|
1202
1263
|
|
1203
1264
|
// This is an edge case
|
1204
1265
|
const map = new Map();
|
1205
|
-
for (const [key, value] of this._target) {
|
1266
|
+
for (const [key, value] of /** @type {Target} */ (this._target)) {
|
1206
1267
|
if (maxPriority === value.priority) {
|
1207
1268
|
map.set(key, value);
|
1208
1269
|
}
|
@@ -1214,7 +1275,7 @@ class ExportInfo {
|
|
1214
1275
|
/**
|
1215
1276
|
* @param {ModuleGraph} moduleGraph the module graph
|
1216
1277
|
* @param {function(Module): boolean} validTargetModuleFilter a valid target module
|
1217
|
-
* @returns {
|
1278
|
+
* @returns {TargetItemWithoutConnection | null | undefined | false} the target, undefined when there is no target, false when no target is valid
|
1218
1279
|
*/
|
1219
1280
|
findTarget(moduleGraph, validTargetModuleFilter) {
|
1220
1281
|
return this._findTarget(moduleGraph, validTargetModuleFilter, new Set());
|
@@ -1223,14 +1284,16 @@ class ExportInfo {
|
|
1223
1284
|
/**
|
1224
1285
|
* @param {ModuleGraph} moduleGraph the module graph
|
1225
1286
|
* @param {function(Module): boolean} validTargetModuleFilter a valid target module
|
1226
|
-
* @param {Set<ExportInfo>
|
1227
|
-
* @returns {
|
1287
|
+
* @param {Set<ExportInfo>} alreadyVisited set of already visited export info to avoid circular references
|
1288
|
+
* @returns {TargetItemWithoutConnection | null | undefined | false} the target, undefined when there is no target, false when no target is valid
|
1228
1289
|
*/
|
1229
1290
|
_findTarget(moduleGraph, validTargetModuleFilter, alreadyVisited) {
|
1230
|
-
if (!this._target || this._target.size === 0) return
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1291
|
+
if (!this._target || this._target.size === 0) return;
|
1292
|
+
const rawTarget =
|
1293
|
+
/** @type {Target} */
|
1294
|
+
(this._getMaxTarget()).values().next().value;
|
1295
|
+
if (!rawTarget) return;
|
1296
|
+
/** @type {TargetItemWithoutConnection} */
|
1234
1297
|
let target = {
|
1235
1298
|
module: rawTarget.connection.module,
|
1236
1299
|
export: rawTarget.export
|
@@ -1261,26 +1324,26 @@ class ExportInfo {
|
|
1261
1324
|
|
1262
1325
|
/**
|
1263
1326
|
* @param {ModuleGraph} moduleGraph the module graph
|
1264
|
-
* @param {function(
|
1265
|
-
* @returns {
|
1327
|
+
* @param {function(TargetItem): boolean} resolveTargetFilter filter function to further resolve target
|
1328
|
+
* @returns {TargetItem | undefined} the target
|
1266
1329
|
*/
|
1267
1330
|
getTarget(moduleGraph, resolveTargetFilter = RETURNS_TRUE) {
|
1268
1331
|
const result = this._getTarget(moduleGraph, resolveTargetFilter, undefined);
|
1269
|
-
if (result === CIRCULAR) return
|
1332
|
+
if (result === CIRCULAR) return;
|
1270
1333
|
return result;
|
1271
1334
|
}
|
1272
1335
|
|
1273
1336
|
/**
|
1274
1337
|
* @param {ModuleGraph} moduleGraph the module graph
|
1275
|
-
* @param {function(
|
1338
|
+
* @param {function(TargetItem): boolean} resolveTargetFilter filter function to further resolve target
|
1276
1339
|
* @param {Set<ExportInfo> | undefined} alreadyVisited set of already visited export info to avoid circular references
|
1277
|
-
* @returns {
|
1340
|
+
* @returns {TargetItem | CIRCULAR | undefined} the target
|
1278
1341
|
*/
|
1279
1342
|
_getTarget(moduleGraph, resolveTargetFilter, alreadyVisited) {
|
1280
1343
|
/**
|
1281
|
-
* @param {
|
1344
|
+
* @param {TargetItem | null} inputTarget unresolved target
|
1282
1345
|
* @param {Set<ExportInfo>} alreadyVisited set of already visited export info to avoid circular references
|
1283
|
-
* @returns {
|
1346
|
+
* @returns {TargetItem | CIRCULAR | null} resolved target
|
1284
1347
|
*/
|
1285
1348
|
const resolveTarget = (inputTarget, alreadyVisited) => {
|
1286
1349
|
if (!inputTarget) return null;
|
@@ -1291,7 +1354,7 @@ class ExportInfo {
|
|
1291
1354
|
export: undefined
|
1292
1355
|
};
|
1293
1356
|
}
|
1294
|
-
/** @type {
|
1357
|
+
/** @type {TargetItem} */
|
1295
1358
|
let target = {
|
1296
1359
|
module: inputTarget.connection.module,
|
1297
1360
|
connection: inputTarget.connection,
|
@@ -1301,7 +1364,10 @@ class ExportInfo {
|
|
1301
1364
|
let alreadyVisitedOwned = false;
|
1302
1365
|
for (;;) {
|
1303
1366
|
const exportsInfo = moduleGraph.getExportsInfo(target.module);
|
1304
|
-
const exportInfo = exportsInfo.getExportInfo(
|
1367
|
+
const exportInfo = exportsInfo.getExportInfo(
|
1368
|
+
/** @type {NonNullable<TargetItem["export"]>} */
|
1369
|
+
(target.export)[0]
|
1370
|
+
);
|
1305
1371
|
if (!exportInfo) return target;
|
1306
1372
|
if (alreadyVisited.has(exportInfo)) return CIRCULAR;
|
1307
1373
|
const newTarget = exportInfo._getTarget(
|
@@ -1311,7 +1377,10 @@ class ExportInfo {
|
|
1311
1377
|
);
|
1312
1378
|
if (newTarget === CIRCULAR) return CIRCULAR;
|
1313
1379
|
if (!newTarget) return target;
|
1314
|
-
if (
|
1380
|
+
if (
|
1381
|
+
/** @type {NonNullable<TargetItem["export"]>} */
|
1382
|
+
(target.export).length === 1
|
1383
|
+
) {
|
1315
1384
|
target = newTarget;
|
1316
1385
|
if (!target.export) return target;
|
1317
1386
|
} else {
|
@@ -1319,8 +1388,12 @@ class ExportInfo {
|
|
1319
1388
|
module: newTarget.module,
|
1320
1389
|
connection: newTarget.connection,
|
1321
1390
|
export: newTarget.export
|
1322
|
-
? newTarget.export.concat(
|
1323
|
-
|
1391
|
+
? newTarget.export.concat(
|
1392
|
+
/** @type {NonNullable<TargetItem["export"]>} */
|
1393
|
+
(target.export).slice(1)
|
1394
|
+
)
|
1395
|
+
: /** @type {NonNullable<TargetItem["export"]>} */
|
1396
|
+
(target.export).slice(1)
|
1324
1397
|
};
|
1325
1398
|
}
|
1326
1399
|
if (!resolveTargetFilter(target)) return target;
|
@@ -1332,22 +1405,26 @@ class ExportInfo {
|
|
1332
1405
|
}
|
1333
1406
|
};
|
1334
1407
|
|
1335
|
-
if (!this._target || this._target.size === 0) return
|
1408
|
+
if (!this._target || this._target.size === 0) return;
|
1336
1409
|
if (alreadyVisited && alreadyVisited.has(this)) return CIRCULAR;
|
1337
1410
|
const newAlreadyVisited = new Set(alreadyVisited);
|
1338
1411
|
newAlreadyVisited.add(this);
|
1339
|
-
const values = this._getMaxTarget().values();
|
1412
|
+
const values = /** @type {Target} */ (this._getMaxTarget()).values();
|
1340
1413
|
const target = resolveTarget(values.next().value, newAlreadyVisited);
|
1341
1414
|
if (target === CIRCULAR) return CIRCULAR;
|
1342
|
-
if (target === null) return
|
1415
|
+
if (target === null) return;
|
1343
1416
|
let result = values.next();
|
1344
1417
|
while (!result.done) {
|
1345
1418
|
const t = resolveTarget(result.value, newAlreadyVisited);
|
1346
1419
|
if (t === CIRCULAR) return CIRCULAR;
|
1347
|
-
if (t === null) return
|
1348
|
-
if (t.module !== target.module) return
|
1349
|
-
if (!t.export !== !target.export) return
|
1350
|
-
if (
|
1420
|
+
if (t === null) return;
|
1421
|
+
if (t.module !== target.module) return;
|
1422
|
+
if (!t.export !== !target.export) return;
|
1423
|
+
if (
|
1424
|
+
target.export &&
|
1425
|
+
!equals(/** @type {ArrayLike<string>} */ (t.export), target.export)
|
1426
|
+
)
|
1427
|
+
return;
|
1351
1428
|
result = values.next();
|
1352
1429
|
}
|
1353
1430
|
return target;
|
@@ -1356,34 +1433,42 @@ class ExportInfo {
|
|
1356
1433
|
/**
|
1357
1434
|
* Move the target forward as long resolveTargetFilter is fulfilled
|
1358
1435
|
* @param {ModuleGraph} moduleGraph the module graph
|
1359
|
-
* @param {function(
|
1360
|
-
* @param {function(
|
1361
|
-
* @returns {
|
1436
|
+
* @param {function(TargetItem): boolean} resolveTargetFilter filter function to further resolve target
|
1437
|
+
* @param {function(TargetItem): ModuleGraphConnection=} updateOriginalConnection updates the original connection instead of using the target connection
|
1438
|
+
* @returns {TargetItem | undefined} the resolved target when moved
|
1362
1439
|
*/
|
1363
1440
|
moveTarget(moduleGraph, resolveTargetFilter, updateOriginalConnection) {
|
1364
1441
|
const target = this._getTarget(moduleGraph, resolveTargetFilter, undefined);
|
1365
|
-
if (target === CIRCULAR) return
|
1366
|
-
if (!target) return
|
1367
|
-
const originalTarget =
|
1442
|
+
if (target === CIRCULAR) return;
|
1443
|
+
if (!target) return;
|
1444
|
+
const originalTarget =
|
1445
|
+
/** @type {Target} */
|
1446
|
+
(this._getMaxTarget()).values().next().value;
|
1368
1447
|
if (
|
1369
1448
|
originalTarget.connection === target.connection &&
|
1370
1449
|
originalTarget.export === target.export
|
1371
1450
|
) {
|
1372
|
-
return
|
1451
|
+
return;
|
1373
1452
|
}
|
1374
|
-
|
1375
|
-
this._target.
|
1453
|
+
/** @type {Target} */
|
1454
|
+
(this._target).clear();
|
1455
|
+
/** @type {Target} */
|
1456
|
+
(this._target).set(undefined, {
|
1376
1457
|
connection: updateOriginalConnection
|
1377
1458
|
? updateOriginalConnection(target)
|
1378
1459
|
: target.connection,
|
1379
|
-
export: target.export,
|
1460
|
+
export: /** @type {NonNullable<TargetItem["export"]>} */ (target.export),
|
1380
1461
|
priority: 0
|
1381
1462
|
});
|
1382
1463
|
return target;
|
1383
1464
|
}
|
1384
1465
|
|
1466
|
+
/**
|
1467
|
+
* @returns {ExportsInfo} an exports info
|
1468
|
+
*/
|
1385
1469
|
createNestedExportsInfo() {
|
1386
|
-
if (this.exportsInfoOwned)
|
1470
|
+
if (this.exportsInfoOwned)
|
1471
|
+
return /** @type {ExportsInfo} */ (this.exportsInfo);
|
1387
1472
|
this.exportsInfoOwned = true;
|
1388
1473
|
const oldExportsInfo = this.exportsInfo;
|
1389
1474
|
this.exportsInfo = new ExportsInfo();
|
@@ -1398,6 +1483,11 @@ class ExportInfo {
|
|
1398
1483
|
return this.exportsInfo;
|
1399
1484
|
}
|
1400
1485
|
|
1486
|
+
/**
|
1487
|
+
* @param {ExportInfo} baseInfo base info
|
1488
|
+
* @param {RuntimeSpec} runtime runtime
|
1489
|
+
* @returns {boolean} true when has info, otherwise false
|
1490
|
+
*/
|
1401
1491
|
hasInfo(baseInfo, runtime) {
|
1402
1492
|
return (
|
1403
1493
|
(this._usedName && this._usedName !== this.name) ||
|
@@ -1407,10 +1497,20 @@ class ExportInfo {
|
|
1407
1497
|
);
|
1408
1498
|
}
|
1409
1499
|
|
1500
|
+
/**
|
1501
|
+
* @param {Hash} hash the hash
|
1502
|
+
* @param {RuntimeSpec} runtime the runtime
|
1503
|
+
* @returns {void}
|
1504
|
+
*/
|
1410
1505
|
updateHash(hash, runtime) {
|
1411
1506
|
this._updateHash(hash, runtime, new Set());
|
1412
1507
|
}
|
1413
1508
|
|
1509
|
+
/**
|
1510
|
+
* @param {Hash} hash the hash
|
1511
|
+
* @param {RuntimeSpec} runtime the runtime
|
1512
|
+
* @param {Set<ExportsInfo>} alreadyVisitedExportsInfo for circular references
|
1513
|
+
*/
|
1414
1514
|
_updateHash(hash, runtime, alreadyVisitedExportsInfo) {
|
1415
1515
|
hash.update(
|
1416
1516
|
`${this._usedName || this.name}${this.getUsed(runtime)}${this.provided}${
|
@@ -1444,6 +1544,7 @@ class ExportInfo {
|
|
1444
1544
|
if (list !== undefined) list.push(runtime);
|
1445
1545
|
else map.set(used, [runtime]);
|
1446
1546
|
}
|
1547
|
+
// eslint-disable-next-line array-callback-return
|
1447
1548
|
const specificInfo = Array.from(map, ([used, runtimes]) => {
|
1448
1549
|
switch (used) {
|
1449
1550
|
case UsageState.NoInfo:
|