@depup/webpack 5.106.1-depup.0 → 5.109.2-depup.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 +9 -11
- package/bin/webpack.js +12 -0
- package/changes.json +16 -24
- package/hot/dev-server.js +2 -0
- package/lib/APIPlugin.js +60 -35
- package/lib/AsyncDependenciesBlock.js +3 -0
- package/lib/AutomaticPrefetchPlugin.js +6 -1
- package/lib/BannerPlugin.js +13 -5
- package/lib/Cache.js +27 -5
- package/lib/CacheFacade.js +41 -0
- package/lib/Chunk.js +71 -25
- package/lib/ChunkGraph.js +153 -19
- package/lib/ChunkGroup.js +115 -28
- package/lib/ChunkTemplate.js +9 -0
- package/lib/CircularModulesPlugin.js +190 -0
- package/lib/CleanPlugin.js +27 -28
- package/lib/CodeGenerationResults.js +19 -0
- package/lib/CompatibilityPlugin.js +85 -37
- package/lib/Compilation.js +656 -112
- package/lib/Compiler.js +109 -35
- package/lib/ConcatenationScope.js +34 -4
- package/lib/ConditionalInitFragment.js +6 -0
- package/lib/ConstPlugin.js +15 -12
- package/lib/ContextExclusionPlugin.js +3 -1
- package/lib/ContextModule.js +345 -55
- package/lib/ContextModuleFactory.js +193 -51
- package/lib/ContextReplacementPlugin.js +8 -1
- package/lib/DefinePlugin.js +537 -139
- package/lib/DependenciesBlock.js +6 -1
- package/lib/Dependency.js +159 -11
- package/lib/DependencyTemplate.js +7 -1
- package/lib/DependencyTemplates.js +4 -0
- package/lib/DotenvPlugin.js +3 -0
- package/lib/DynamicEntryPlugin.js +3 -1
- package/lib/EntryOptionPlugin.js +42 -2
- package/lib/EntryPlugin.js +4 -1
- package/lib/Entrypoint.js +5 -1
- package/lib/EnvironmentPlugin.js +3 -2
- package/lib/ErrorHelpers.js +7 -0
- package/lib/EvalDevToolModulePlugin.js +3 -1
- package/lib/EvalSourceMapDevToolPlugin.js +11 -11
- package/lib/ExportsInfo.js +421 -113
- package/lib/ExportsInfoApiPlugin.js +4 -3
- package/lib/ExternalModule.js +381 -80
- package/lib/ExternalModuleFactoryPlugin.js +75 -3
- package/lib/ExternalsPlugin.js +3 -1
- package/lib/FileSystemInfo.js +701 -175
- package/lib/FlagAllModulesAsUsedPlugin.js +3 -6
- package/lib/FlagDependencyExportsPlugin.js +82 -9
- package/lib/FlagDependencyUsagePlugin.js +115 -8
- package/lib/FlagEntryExportAsUsedPlugin.js +4 -1
- package/lib/Generator.js +24 -3
- package/lib/HotModuleReplacementPlugin.js +110 -44
- package/lib/IgnorePlugin.js +5 -2
- package/lib/IgnoreWarningsPlugin.js +2 -1
- package/lib/InitFragment.js +33 -30
- package/lib/JavascriptMetaInfoPlugin.js +9 -6
- package/lib/LazyBarrel.js +389 -0
- package/lib/LibraryTemplatePlugin.js +2 -1
- package/lib/LoaderOptionsPlugin.js +3 -1
- package/lib/LoaderTargetPlugin.js +3 -1
- package/lib/MainTemplate.js +15 -0
- package/lib/ManifestPlugin.js +9 -2
- package/lib/Module.js +121 -57
- package/lib/ModuleFactory.js +6 -1
- package/lib/ModuleFilenameHelpers.js +18 -4
- package/lib/ModuleGraph.js +69 -2
- package/lib/ModuleGraphConnection.js +9 -0
- package/lib/ModuleInfoHeaderPlugin.js +5 -0
- package/lib/ModuleNotFoundError.js +3 -83
- package/lib/ModuleProfile.js +27 -1
- package/lib/ModuleSourceTypeConstants.js +52 -19
- package/lib/ModuleTemplate.js +10 -0
- package/lib/ModuleTypeConstants.js +20 -4
- package/lib/MultiCompiler.js +59 -4
- package/lib/MultiStats.js +9 -0
- package/lib/MultiWatching.js +6 -0
- package/lib/NoEmitOnErrorsPlugin.js +1 -1
- package/lib/NodeStuffPlugin.js +78 -46
- package/lib/NormalModule.js +519 -206
- package/lib/NormalModuleFactory.js +156 -31
- package/lib/NormalModuleReplacementPlugin.js +3 -1
- package/lib/NullFactory.js +1 -0
- package/lib/OptionsApply.js +1 -0
- package/lib/Parser.js +3 -1
- package/lib/PlatformPlugin.js +2 -1
- package/lib/PrefetchPlugin.js +4 -1
- package/lib/ProgressPlugin.js +351 -161
- package/lib/ProvidePlugin.js +6 -3
- package/lib/RawModule.js +32 -16
- package/lib/RecordIdsPlugin.js +9 -0
- package/lib/RequestShortener.js +8 -0
- package/lib/ResolverFactory.js +5 -0
- package/lib/RuntimeGlobals.js +58 -5
- package/lib/RuntimeModule.js +22 -7
- package/lib/RuntimePlugin.js +123 -118
- package/lib/RuntimeTemplate.js +616 -37
- package/lib/SelfModuleFactory.js +3 -0
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +2 -0
- package/lib/SourceMapDevToolPlugin.js +341 -63
- package/lib/Stats.js +6 -0
- package/lib/Template.js +52 -6
- package/lib/TemplatedPathPlugin.js +505 -138
- package/lib/UseStrictPlugin.js +3 -2
- package/lib/WarnCaseSensitiveModulesPlugin.js +72 -3
- package/lib/WarnDeprecatedOptionPlugin.js +6 -2
- package/lib/WarnNoModeSetPlugin.js +18 -2
- package/lib/WatchIgnorePlugin.js +5 -1
- package/lib/Watching.js +25 -3
- package/lib/WebpackError.js +3 -74
- package/lib/WebpackIsIncludedPlugin.js +4 -2
- package/lib/WebpackOptionsApply.js +88 -25
- package/lib/WebpackOptionsDefaulter.js +1 -0
- package/lib/asset/AssetBytesGenerator.js +28 -10
- package/lib/asset/AssetBytesParser.js +1 -0
- package/lib/asset/AssetGenerator.js +199 -60
- package/lib/asset/AssetModule.js +47 -0
- package/lib/asset/AssetModulesPlugin.js +115 -24
- package/lib/asset/AssetParser.js +4 -2
- package/lib/asset/AssetSourceGenerator.js +26 -8
- package/lib/asset/AssetSourceParser.js +1 -0
- package/lib/asset/RawDataUrlModule.js +23 -13
- package/lib/asset/WebManifestGenerator.js +164 -0
- package/lib/asset/WebManifestParser.js +130 -0
- package/lib/async-modules/AsyncModuleHelpers.js +1 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +18 -4
- package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
- package/lib/async-modules/isGeneratorLowered.js +26 -0
- package/lib/buildChunkGraph.js +107 -15
- package/lib/bun/BunTargetPlugin.js +42 -0
- package/lib/cache/AddBuildDependenciesPlugin.js +3 -1
- package/lib/cache/AddManagedPathsPlugin.js +5 -1
- package/lib/cache/IdleFileCachePlugin.js +6 -1
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +4 -1
- package/lib/cache/PackFileCacheStrategy.js +302 -12
- package/lib/cache/ResolverCachePlugin.js +12 -1
- package/lib/cache/getLazyHashedEtag.js +13 -2
- package/lib/cache/mergeEtags.js +4 -0
- package/lib/cli.js +142 -20
- package/lib/config/browserslistTargetHandler.js +141 -0
- package/lib/config/defaults.js +612 -43
- package/lib/config/defineConfig.js +31 -0
- package/lib/config/normalization.js +46 -1
- package/lib/config/target.js +200 -2
- package/lib/container/ContainerEntryDependency.js +2 -0
- package/lib/container/ContainerEntryModule.js +27 -14
- package/lib/container/ContainerEntryModuleFactory.js +1 -0
- package/lib/container/ContainerExposedDependency.js +6 -2
- package/lib/container/ContainerPlugin.js +2 -1
- package/lib/container/ContainerReferencePlugin.js +3 -2
- package/lib/container/FallbackDependency.js +9 -7
- package/lib/container/FallbackItemDependency.js +1 -0
- package/lib/container/FallbackModule.js +22 -9
- package/lib/container/FallbackModuleFactory.js +1 -0
- package/lib/container/HoistContainerReferencesPlugin.js +47 -55
- package/lib/container/ModuleFederationPlugin.js +21 -29
- package/lib/container/RemoteModule.js +33 -10
- package/lib/container/RemoteRuntimeModule.js +15 -12
- package/lib/container/RemoteToExternalDependency.js +1 -0
- package/lib/container/options.js +7 -0
- package/lib/css/CssGenerator.js +540 -272
- package/lib/css/CssInjectStyleRuntimeModule.js +86 -70
- package/lib/css/CssLoadingRuntimeModule.js +173 -81
- package/lib/{CssModule.js → css/CssModule.js} +72 -37
- package/lib/css/CssModulesPlugin.js +371 -208
- package/lib/css/CssParser.js +3538 -1963
- package/lib/css/syntax.js +4155 -0
- package/lib/debug/ProfilingPlugin.js +33 -2
- package/lib/deno/DenoTargetPlugin.js +41 -0
- package/lib/dependencies/AMDDefineDependency.js +29 -17
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +19 -6
- package/lib/dependencies/AMDPlugin.js +6 -3
- package/lib/dependencies/AMDRequireArrayDependency.js +13 -11
- package/lib/dependencies/AMDRequireContextDependency.js +10 -11
- package/lib/dependencies/AMDRequireDependenciesBlock.js +1 -0
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -14
- package/lib/dependencies/AMDRequireDependency.js +28 -20
- package/lib/dependencies/AMDRequireItemDependency.js +1 -0
- package/lib/dependencies/AMDRuntimeModules.js +3 -0
- package/lib/dependencies/CachedConstDependency.js +9 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +104 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +157 -38
- package/lib/dependencies/CommonJsExportsDependency.js +74 -20
- package/lib/dependencies/CommonJsExportsParserPlugin.js +246 -15
- package/lib/dependencies/CommonJsFullRequireDependency.js +91 -27
- package/lib/dependencies/CommonJsImportsParserPlugin.js +189 -24
- package/lib/dependencies/CommonJsPlugin.js +7 -4
- package/lib/dependencies/CommonJsRequireContextDependency.js +13 -13
- package/lib/dependencies/CommonJsRequireDependency.js +135 -13
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +60 -16
- package/lib/dependencies/ConstDependency.js +22 -12
- package/lib/dependencies/ContextDependency.js +13 -2
- package/lib/dependencies/ContextDependencyHelpers.js +7 -4
- package/lib/dependencies/ContextDependencyTemplateAsId.js +2 -1
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
- package/lib/dependencies/ContextElementDependency.js +27 -14
- package/lib/dependencies/CreateRequireParserPlugin.js +14 -7
- package/lib/dependencies/CreateScriptUrlDependency.js +9 -7
- package/lib/dependencies/CriticalDependencyWarning.js +3 -1
- package/lib/dependencies/CssIcssExportDependency.js +681 -367
- package/lib/dependencies/CssIcssImportDependency.js +62 -17
- package/lib/dependencies/CssIcssSymbolDependency.js +36 -17
- package/lib/dependencies/CssImportDependency.js +37 -1
- package/lib/dependencies/CssUrlDependency.js +87 -14
- package/lib/dependencies/DelegatedSourceDependency.js +1 -0
- package/lib/dependencies/DllEntryDependency.js +12 -13
- package/lib/dependencies/DynamicExports.js +5 -0
- package/lib/dependencies/EntryDependency.js +1 -0
- package/lib/dependencies/ExportBindingInitFragment.js +164 -0
- package/lib/dependencies/ExportsInfoDependency.js +18 -12
- package/lib/dependencies/ExternalModuleDependency.js +13 -5
- package/lib/dependencies/ExternalModuleInitFragment.js +10 -5
- package/lib/dependencies/ExternalModuleInitFragmentDependency.js +19 -12
- package/lib/dependencies/HarmonyAcceptDependency.js +24 -26
- package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -0
- package/lib/dependencies/HarmonyCompatibilityDependency.js +33 -14
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +108 -30
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +34 -3
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +70 -33
- package/lib/dependencies/HarmonyExportExpressionDependency.js +133 -43
- package/lib/dependencies/HarmonyExportHeaderDependency.js +11 -9
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +268 -44
- package/lib/dependencies/HarmonyExportInitFragment.js +28 -20
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +88 -18
- package/lib/dependencies/HarmonyExports.js +6 -1
- package/lib/dependencies/HarmonyImportDependency.js +60 -4
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +139 -146
- package/lib/dependencies/HarmonyImportGuard.js +427 -0
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +22 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +146 -24
- package/lib/{HarmonyLinkingError.js → dependencies/HarmonyLinkingError.js} +6 -3
- package/lib/dependencies/HarmonyModulesPlugin.js +11 -1
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +2 -1
- package/lib/dependencies/HtmlEntryDependency.js +1295 -0
- package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
- package/lib/dependencies/HtmlInlineScriptDependency.js +126 -0
- package/lib/dependencies/HtmlInlineStyleDependency.js +152 -0
- package/lib/dependencies/HtmlSourceDependency.js +172 -0
- package/lib/dependencies/ImportContextDependency.js +9 -9
- package/lib/dependencies/ImportDependency.js +92 -3
- package/lib/dependencies/ImportEagerDependency.js +2 -0
- package/lib/dependencies/ImportMetaContextDependency.js +1 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +35 -19
- package/lib/dependencies/ImportMetaContextPlugin.js +40 -8
- package/lib/dependencies/ImportMetaGlobDependency.js +81 -0
- package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +78 -0
- package/lib/dependencies/ImportMetaGlobHelpers.js +660 -0
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +2 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +2 -0
- package/lib/dependencies/ImportMetaPlugin.js +595 -209
- package/lib/dependencies/ImportMetaResolveDependency.js +90 -0
- package/lib/dependencies/ImportParserPlugin.js +114 -27
- package/lib/dependencies/ImportPhase.js +17 -11
- package/lib/dependencies/ImportPlugin.js +2 -1
- package/lib/dependencies/ImportWeakDependency.js +3 -0
- package/lib/dependencies/JsonExportsDependency.js +15 -10
- package/lib/dependencies/LoaderDependency.js +2 -0
- package/lib/dependencies/LoaderImportDependency.js +3 -0
- package/lib/dependencies/LoaderPlugin.js +9 -2
- package/lib/dependencies/LocalModule.js +15 -12
- package/lib/dependencies/LocalModuleDependency.js +15 -13
- package/lib/dependencies/LocalModulesHelpers.js +3 -0
- package/lib/dependencies/ModuleDecoratorDependency.js +16 -10
- package/lib/dependencies/ModuleDependency.js +14 -0
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +1 -0
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +2 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +2 -0
- package/lib/dependencies/ModuleInitFragmentDependency.js +19 -11
- package/lib/dependencies/NullDependency.js +2 -0
- package/lib/dependencies/PrefetchDependency.js +1 -0
- package/lib/dependencies/ProvidedDependency.js +36 -27
- package/lib/dependencies/PureExpressionDependency.js +14 -10
- package/lib/dependencies/RequireContextDependency.js +1 -0
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +2 -1
- package/lib/dependencies/RequireContextPlugin.js +2 -1
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -0
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +4 -6
- package/lib/dependencies/RequireEnsureDependency.js +16 -13
- package/lib/dependencies/RequireEnsureItemDependency.js +1 -0
- package/lib/dependencies/RequireEnsurePlugin.js +2 -1
- package/lib/dependencies/RequireHeaderDependency.js +7 -4
- package/lib/dependencies/RequireIncludeDependency.js +2 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +11 -12
- package/lib/dependencies/RequireIncludePlugin.js +2 -1
- package/lib/{RequireJsStuffPlugin.js → dependencies/RequireJsStuffPlugin.js} +9 -8
- package/lib/dependencies/RequireResolveContextDependency.js +10 -11
- package/lib/dependencies/RequireResolveDependency.js +2 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +8 -5
- package/lib/dependencies/RuntimeRequirementsDependency.js +11 -8
- package/lib/dependencies/StaticExportsDependency.js +13 -10
- package/lib/dependencies/SystemPlugin.js +9 -6
- package/lib/dependencies/SystemRuntimeModule.js +1 -0
- package/lib/dependencies/TopLevelAwaitDependency.js +93 -0
- package/lib/dependencies/URLContextDependency.js +8 -7
- package/lib/dependencies/URLDependency.js +157 -33
- package/lib/dependencies/URLPlugin.js +2 -0
- package/lib/dependencies/UnsupportedDependency.js +12 -13
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +15 -16
- package/lib/dependencies/WebAssemblyImportDependency.js +19 -18
- package/lib/dependencies/WebpackIsIncludedDependency.js +3 -0
- package/lib/dependencies/{WorkerPlugin.js → WorkerAndWorkletPlugin.js} +364 -114
- package/lib/dependencies/WorkerDependency.js +111 -27
- package/lib/dependencies/WorkletDependency.js +278 -0
- package/lib/dependencies/getFunctionExpression.js +1 -0
- package/lib/dependencies/processExportInfo.js +14 -11
- package/lib/{DelegatedModule.js → dll/DelegatedModule.js} +71 -44
- package/lib/{DelegatedModuleFactoryPlugin.js → dll/DelegatedModuleFactoryPlugin.js} +27 -4
- package/lib/{DelegatedPlugin.js → dll/DelegatedPlugin.js} +5 -3
- package/lib/{DllEntryPlugin.js → dll/DllEntryPlugin.js} +9 -5
- package/lib/{DllModule.js → dll/DllModule.js} +36 -24
- package/lib/{DllModuleFactory.js → dll/DllModuleFactory.js} +5 -4
- package/lib/{DllPlugin.js → dll/DllPlugin.js} +24 -6
- package/lib/{DllReferencePlugin.js → dll/DllReferencePlugin.js} +26 -18
- package/lib/{LibManifestPlugin.js → dll/LibManifestPlugin.js} +14 -10
- package/lib/electron/ElectronTargetPlugin.js +24 -5
- package/lib/{AbstractMethodError.js → errors/AbstractMethodError.js} +10 -1
- package/lib/{AsyncDependencyToInitialChunkError.js → errors/AsyncDependencyToInitialChunkError.js} +8 -3
- package/lib/errors/BuildCycleError.js +1 -1
- package/lib/{ChunkRenderError.js → errors/ChunkRenderError.js} +1 -1
- package/lib/{CodeGenerationError.js → errors/CodeGenerationError.js} +1 -1
- package/lib/{CommentCompilationWarning.js → errors/CommentCompilationWarning.js} +9 -3
- package/lib/{ConcurrentCompilationError.js → errors/ConcurrentCompilationError.js} +5 -2
- package/lib/{EnvironmentNotSupportAsyncWarning.js → errors/EnvironmentNotSupportAsyncWarning.js} +5 -5
- package/lib/{HookWebpackError.js → errors/HookWebpackError.js} +20 -16
- package/lib/{IgnoreErrorModuleFactory.js → errors/IgnoreErrorModuleFactory.js} +7 -4
- package/lib/{InvalidDependenciesModuleWarning.js → errors/InvalidDependenciesModuleWarning.js} +6 -3
- package/lib/errors/JSONParseError.js +115 -0
- package/lib/errors/LoaderLoadingError.js +20 -0
- package/lib/{ModuleBuildError.js → errors/ModuleBuildError.js} +22 -16
- package/lib/{ModuleDependencyError.js → errors/ModuleDependencyError.js} +10 -3
- package/lib/{ModuleDependencyWarning.js → errors/ModuleDependencyWarning.js} +13 -5
- package/lib/{ModuleError.js → errors/ModuleError.js} +10 -14
- package/lib/{ModuleHashingError.js → errors/ModuleHashingError.js} +5 -1
- package/lib/errors/ModuleNotFoundError.js +94 -0
- package/lib/errors/ModuleParseError.js +141 -0
- package/lib/{ModuleRestoreError.js → errors/ModuleRestoreError.js} +4 -1
- package/lib/{ModuleStoreError.js → errors/ModuleStoreError.js} +5 -1
- package/lib/{ModuleWarning.js → errors/ModuleWarning.js} +13 -14
- package/lib/{NodeStuffInWebError.js → errors/NodeStuffInWebError.js} +7 -5
- package/lib/errors/NonErrorEmittedError.js +30 -0
- package/lib/{UnhandledSchemeError.js → errors/UnhandledSchemeError.js} +9 -2
- package/lib/{UnsupportedFeatureWarning.js → errors/UnsupportedFeatureWarning.js} +4 -3
- package/lib/errors/WebpackError.js +84 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +52 -15
- package/lib/esm/ModuleChunkLoadingPlugin.js +11 -3
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +80 -52
- package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +8 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +154 -7
- package/lib/hmr/lazyCompilationBackend.js +53 -12
- package/lib/html/HtmlGenerator.js +1490 -0
- package/lib/html/HtmlModule.js +41 -0
- package/lib/html/HtmlModulesPlugin.js +1129 -0
- package/lib/html/HtmlParser.js +1970 -0
- package/lib/html/favicon.svg +1 -0
- package/lib/html/syntax.js +9106 -0
- package/lib/ids/ChunkModuleIdRangePlugin.js +3 -1
- package/lib/ids/DeterministicChunkIdsPlugin.js +3 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +3 -1
- package/lib/ids/HashedModuleIdsPlugin.js +2 -1
- package/lib/ids/IdHelpers.js +49 -12
- package/lib/ids/NamedChunkIdsPlugin.js +3 -1
- package/lib/ids/NamedModuleIdsPlugin.js +3 -1
- package/lib/ids/NaturalChunkIdsPlugin.js +1 -1
- package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -1
- package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -1
- package/lib/ids/SyncModuleIdsPlugin.js +3 -1
- package/lib/index.js +66 -15
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +5 -6
- package/lib/javascript/BasicEvaluatedExpression.js +370 -49
- package/lib/javascript/ChunkFormatHelpers.js +2 -1
- package/lib/javascript/ChunkHelpers.js +1 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
- package/lib/javascript/EnableChunkLoadingPlugin.js +6 -1
- package/lib/javascript/JavascriptGenerator.js +213 -51
- package/lib/javascript/JavascriptModule.js +54 -0
- package/lib/javascript/JavascriptModulesPlugin.js +628 -198
- package/lib/javascript/JavascriptParser.js +1334 -471
- package/lib/javascript/JavascriptParserHelpers.js +10 -7
- package/lib/javascript/StartupHelpers.js +5 -0
- package/lib/javascript/syntax.js +5037 -0
- package/lib/json/JsonData.js +5 -0
- package/lib/json/JsonGenerator.js +21 -0
- package/lib/json/JsonModule.js +40 -0
- package/lib/json/JsonModulesPlugin.js +8 -1
- package/lib/json/JsonParser.js +18 -27
- package/lib/library/AbstractLibraryPlugin.js +17 -2
- package/lib/library/AmdLibraryPlugin.js +8 -0
- package/lib/library/AssignLibraryPlugin.js +21 -3
- package/lib/library/EnableLibraryPlugin.js +8 -2
- package/lib/library/ExportPropertyLibraryPlugin.js +10 -0
- package/lib/{FalseIIFEUmdWarning.js → library/FalseIIFEUmdWarning.js} +2 -1
- package/lib/library/JsonpLibraryPlugin.js +8 -0
- package/lib/library/ModuleLibraryPlugin.js +154 -7
- package/lib/library/SystemLibraryPlugin.js +11 -3
- package/lib/library/UmdLibraryPlugin.js +16 -0
- package/lib/loaders/LoaderRunner.js +714 -0
- package/lib/loaders/loadLoader.js +100 -0
- package/lib/logging/Logger.js +17 -0
- package/lib/logging/createConsoleLogger.js +7 -0
- package/lib/logging/runtime.js +2 -0
- package/lib/logging/truncateArgs.js +2 -0
- package/lib/node/CommonJsChunkLoadingPlugin.js +5 -1
- package/lib/node/NodeEnvironmentPlugin.js +7 -3
- package/lib/node/NodeSourcePlugin.js +1 -1
- package/lib/node/NodeTargetPlugin.js +4 -63
- package/lib/node/NodeTemplatePlugin.js +3 -1
- package/lib/node/NodeWatchFileSystem.js +40 -22
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +13 -9
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +33 -3
- package/lib/node/ReadFileCompileWasmPlugin.js +28 -3
- package/lib/node/RequireChunkLoadingRuntimeModule.js +21 -16
- package/lib/node/nodeBuiltins.js +80 -0
- package/lib/node/nodeConsole.js +116 -64
- package/lib/optimize/AggressiveMergingPlugin.js +22 -16
- package/lib/optimize/AggressiveSplittingPlugin.js +6 -1
- package/lib/optimize/ConcatenatedModule.js +603 -130
- package/lib/optimize/ConstExportsPlugin.js +211 -0
- package/lib/optimize/EnsureChunkConditionsPlugin.js +2 -1
- package/lib/optimize/FlagIncludedChunksPlugin.js +15 -4
- package/lib/optimize/InlineExports.js +178 -0
- package/lib/optimize/InnerGraph.js +374 -262
- package/lib/optimize/InnerGraphPlugin.js +246 -117
- package/lib/optimize/LimitChunkCountPlugin.js +9 -0
- package/lib/optimize/MangleExportsPlugin.js +5 -1
- package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -0
- package/lib/optimize/MinChunkSizePlugin.js +2 -1
- package/lib/optimize/MinMaxSizeWarning.js +5 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +229 -55
- package/lib/optimize/RealContentHashPlugin.js +130 -52
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
- package/lib/optimize/RemoveParentModulesPlugin.js +3 -1
- package/lib/optimize/RuntimeChunkPlugin.js +2 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +381 -55
- package/lib/optimize/SplitChunksPlugin.js +200 -50
- package/lib/performance/AssetsOverSizeLimitWarning.js +3 -2
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +3 -2
- package/lib/performance/NoAsyncChunksWarning.js +5 -3
- package/lib/performance/SizeLimitsPlugin.js +8 -2
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +1 -0
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +21 -0
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +1 -0
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +5 -1
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +25 -13
- package/lib/prefetch/ResourceHintPlugin.js +687 -0
- package/lib/prefetch/ResourceHintRuntimeModule.js +149 -0
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +210 -0
- package/lib/prefetch/parseResourceHintOptions.js +103 -0
- package/lib/rules/BasicEffectRulePlugin.js +3 -0
- package/lib/rules/BasicMatcherRulePlugin.js +3 -0
- package/lib/rules/ObjectMatcherRulePlugin.js +3 -0
- package/lib/rules/RuleSetCompiler.js +132 -0
- package/lib/rules/UseEffectRulePlugin.js +10 -3
- package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +56 -0
- package/lib/runtime/AsyncModuleRuntimeModule.js +52 -33
- package/lib/runtime/AutoPublicPathRuntimeModule.js +22 -9
- package/lib/runtime/BaseUriRuntimeModule.js +1 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
- package/lib/runtime/CommonJsWrapRuntimeModule.js +37 -0
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +2 -1
- package/lib/runtime/CompatRuntimeModule.js +2 -0
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +7 -4
- package/lib/runtime/CreateScriptRuntimeModule.js +1 -0
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +1 -0
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +34 -4
- package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +88 -8
- package/lib/runtime/GetFullHashRuntimeModule.js +1 -0
- package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -0
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
- package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +59 -0
- package/lib/runtime/GlobalRuntimeModule.js +1 -0
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +2 -1
- package/lib/runtime/HelperRuntimeModule.js +5 -0
- package/lib/runtime/LoadScriptRuntimeModule.js +28 -37
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +354 -37
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +2 -1
- package/lib/runtime/NonceRuntimeModule.js +1 -0
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +5 -4
- package/lib/runtime/PublicPathRuntimeModule.js +1 -0
- package/lib/runtime/RelativeUrlRuntimeModule.js +4 -2
- package/lib/runtime/RuntimeIdRuntimeModule.js +1 -0
- package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +38 -0
- package/lib/runtime/StartupChunkDependenciesPlugin.js +13 -1
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +2 -1
- package/lib/runtime/StartupEntrypointRuntimeModule.js +5 -3
- package/lib/runtime/SystemContextRuntimeModule.js +1 -0
- package/lib/runtime/ToBinaryRuntimeModule.js +1 -0
- package/lib/runtime/WorkerRuntimeModule.js +33 -0
- package/lib/schemes/DataUriPlugin.js +14 -2
- package/lib/schemes/FileUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +86 -4
- package/lib/schemes/VirtualUrlPlugin.js +8 -4
- package/lib/serialization/AggregateErrorSerializer.js +9 -6
- package/lib/serialization/ArraySerializer.js +6 -8
- package/lib/serialization/BinaryMiddleware.js +427 -1006
- package/lib/serialization/DateObjectSerializer.js +4 -2
- package/lib/serialization/ErrorObjectSerializer.js +10 -6
- package/lib/serialization/FileMiddleware.js +345 -59
- package/lib/serialization/MapObjectSerializer.js +7 -9
- package/lib/serialization/NullPrototypeObjectSerializer.js +9 -9
- package/lib/serialization/ObjectMiddleware.js +73 -13
- package/lib/serialization/PlainObjectSerializer.js +16 -8
- package/lib/serialization/RegExpObjectSerializer.js +4 -2
- package/lib/serialization/Serializer.js +6 -0
- package/lib/serialization/SerializerMiddleware.js +14 -2
- package/lib/serialization/SetObjectSerializer.js +6 -8
- package/lib/serialization/SingleItemMiddleware.js +3 -0
- package/lib/sharing/ConsumeSharedFallbackDependency.js +1 -0
- package/lib/sharing/ConsumeSharedModule.js +21 -7
- package/lib/sharing/ConsumeSharedPlugin.js +11 -11
- package/lib/sharing/ConsumeSharedRuntimeModule.js +55 -45
- package/lib/sharing/ProvideForSharedDependency.js +1 -0
- package/lib/sharing/ProvideSharedDependency.js +34 -15
- package/lib/sharing/ProvideSharedModule.js +42 -12
- package/lib/sharing/ProvideSharedModuleFactory.js +1 -0
- package/lib/sharing/ProvideSharedPlugin.js +13 -8
- package/lib/sharing/SharePlugin.js +5 -1
- package/lib/sharing/ShareRuntimeModule.js +19 -16
- package/lib/sharing/resolveMatchedConfigs.js +6 -2
- package/lib/sharing/utils.js +9 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +289 -201
- package/lib/stats/DefaultStatsPresetPlugin.js +14 -2
- package/lib/stats/DefaultStatsPrinterPlugin.js +74 -170
- package/lib/stats/StatsFactory.js +70 -27
- package/lib/stats/StatsPrinter.js +16 -2
- package/lib/typescript/TypeScriptPlugin.js +210 -0
- package/lib/url/URLParserPlugin.js +111 -23
- package/lib/util/ArrayHelpers.js +1 -0
- package/lib/util/ArrayQueue.js +10 -5
- package/lib/util/AsyncQueue.js +154 -74
- package/lib/util/Hash.js +2 -2
- package/lib/util/IterableHelpers.js +3 -0
- package/lib/util/LazyBucketSortedSet.js +26 -0
- package/lib/util/LazySet.js +45 -4
- package/lib/util/LocConverter.js +64 -0
- package/lib/util/ParallelismFactorCalculator.js +1 -0
- package/lib/util/Queue.js +6 -3
- package/lib/util/Semaphore.js +15 -1
- package/lib/util/SetHelpers.js +4 -1
- package/lib/util/SortableSet.js +7 -1
- package/lib/util/SourceProcessor.js +119 -0
- package/lib/util/StackedCacheMap.js +20 -3
- package/lib/util/StackedMap.js +162 -43
- package/lib/util/StringXor.js +1 -1
- package/lib/util/TupleQueue.js +7 -3
- package/lib/util/TupleSet.js +14 -0
- package/lib/util/URLAbsoluteSpecifier.js +1 -0
- package/lib/util/WeakTupleMap.js +60 -1
- package/lib/util/binarySearchBounds.js +3 -2
- package/lib/util/chainedImports.js +3 -3
- package/lib/util/cleverMerge.js +19 -2
- package/lib/util/comparators.js +35 -4
- package/lib/util/compileBooleanMatcher.js +9 -0
- package/lib/util/concatenate.js +80 -24
- package/lib/util/conventions.js +46 -1
- package/lib/util/createHash.js +0 -1
- package/lib/util/createHooksRegistry.js +43 -0
- package/lib/util/createMappings.js +118 -0
- package/lib/util/dataURL.js +3 -2
- package/lib/util/deprecation.js +19 -0
- package/lib/util/deterministicGrouping.js +46 -17
- package/lib/util/extractSourceMap.js +2 -1
- package/lib/util/extractUrlAndGlobal.js +1 -0
- package/lib/util/findGraphRoots.js +7 -0
- package/lib/{formatLocation.js → util/formatLocation.js} +4 -2
- package/lib/{SizeFormatHelpers.js → util/formatSize.js} +10 -3
- package/lib/util/fs.js +87 -14
- package/lib/util/generateDebugId.js +1 -0
- package/lib/util/globUtils.js +710 -0
- package/lib/util/hash/BatchedHash.js +1 -0
- package/lib/util/hash/BulkUpdateHash.js +1 -0
- package/lib/util/hash/DebugHash.js +1 -0
- package/lib/util/hash/hash-digest.js +32 -15
- package/lib/util/hash/md4.js +1 -1
- package/lib/util/hash/wasm-hash.js +5 -0
- package/lib/util/hash/xxhash64.js +1 -1
- package/lib/util/identifier.js +118 -7
- package/lib/util/implicitTypeLoaderFallback.js +62 -0
- package/lib/util/internalSerializables.js +102 -60
- package/lib/util/magicComment.js +149 -7
- package/lib/util/makeSerializable.js +7 -0
- package/lib/util/memoize.js +2 -0
- package/lib/util/mimeTypes.js +176 -0
- package/lib/util/nonNumericOnlyHash.js +31 -1
- package/lib/util/numberHash.js +2 -2
- package/lib/util/parseJson.js +41 -0
- package/lib/util/processAsyncTree.js +8 -0
- package/lib/util/property.js +9 -2
- package/lib/util/publicPathPlaceholder.js +64 -0
- package/lib/util/registerExternalSerializer.js +24 -4
- package/lib/util/removeBOM.js +1 -0
- package/lib/util/runtime.js +32 -0
- package/lib/util/semver.js +15 -0
- package/lib/util/serialization.js +2 -0
- package/lib/util/smartGrouping.js +8 -0
- package/lib/util/source.js +23 -0
- package/lib/util/topologicalSort.js +69 -0
- package/lib/validateSchema.js +1 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +15 -1
- package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +25 -18
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +34 -22
- package/lib/wasm-async/AsyncWasmModule.js +77 -0
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -0
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +6 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +22 -126
- package/lib/wasm-async/AsyncWebAssemblyParser.js +3 -2
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +13 -2
- package/lib/wasm-sync/SyncWasmModule.js +39 -0
- package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +7 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +86 -19
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +4 -3
- package/lib/wasm-sync/WebAssemblyGenerator.js +27 -1
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +9 -3
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +4 -0
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +20 -1
- package/lib/wasm-sync/WebAssemblyParser.js +9 -3
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -0
- package/lib/web/FetchCompileAsyncWasmPlugin.js +29 -1
- package/lib/web/FetchCompileWasmPlugin.js +27 -1
- package/lib/web/JsonpChunkLoadingPlugin.js +11 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +58 -64
- package/lib/web/JsonpTemplatePlugin.js +2 -1
- package/lib/webpack.js +78 -1
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +10 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -10
- package/lib/webworker/WebWorkerTemplatePlugin.js +1 -1
- package/module.d.ts +21 -0
- package/package.json +79 -77
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +1173 -80
- package/schemas/plugins/{DllPlugin.check.d.ts → HtmlGeneratorOptions.check.d.ts} +1 -1
- package/schemas/plugins/HtmlGeneratorOptions.check.js +6 -0
- package/schemas/plugins/HtmlGeneratorOptions.json +3 -0
- package/schemas/plugins/{DllReferencePlugin.check.d.ts → HtmlParserOptions.check.d.ts} +1 -1
- package/schemas/plugins/HtmlParserOptions.check.js +6 -0
- package/schemas/plugins/HtmlParserOptions.json +3 -0
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.json +38 -0
- 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 +2 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.json +3 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/dll/DllPlugin.check.d.ts +7 -0
- package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +7 -0
- package/types.d.ts +11053 -3019
- package/lib/CaseSensitiveModulesWarning.js +0 -72
- package/lib/GraphHelpers.js +0 -46
- package/lib/ModuleParseError.js +0 -125
- package/lib/NoModeWarning.js +0 -23
- package/lib/css/CssMergeStyleSheetsRuntimeModule.js +0 -56
- package/lib/css/walkCssTokens.js +0 -1843
- package/lib/util/AppendOnlyStackedSet.js +0 -78
- /package/schemas/plugins/{DllPlugin.check.js → dll/DllPlugin.check.js} +0 -0
- /package/schemas/plugins/{DllPlugin.json → dll/DllPlugin.json} +0 -0
- /package/schemas/plugins/{DllReferencePlugin.check.js → dll/DllReferencePlugin.check.js} +0 -0
- /package/schemas/plugins/{DllReferencePlugin.json → dll/DllReferencePlugin.json} +0 -0
package/lib/RuntimeTemplate.js
CHANGED
|
@@ -6,20 +6,34 @@
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
8
|
const InitFragment = require("./InitFragment");
|
|
9
|
+
const {
|
|
10
|
+
JAVASCRIPT_TYPE,
|
|
11
|
+
RUNTIME_TYPE
|
|
12
|
+
} = require("./ModuleSourceTypeConstants");
|
|
13
|
+
const {
|
|
14
|
+
WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE,
|
|
15
|
+
WEBPACK_MODULE_TYPE_FALLBACK,
|
|
16
|
+
WEBPACK_MODULE_TYPE_PROVIDE,
|
|
17
|
+
WEBPACK_MODULE_TYPE_REMOTE
|
|
18
|
+
} = require("./ModuleTypeConstants");
|
|
9
19
|
const RuntimeGlobals = require("./RuntimeGlobals");
|
|
10
20
|
const Template = require("./Template");
|
|
11
21
|
const {
|
|
12
22
|
getOutgoingAsyncModules
|
|
13
23
|
} = require("./async-modules/AsyncModuleHelpers");
|
|
14
24
|
const { ImportPhaseUtils } = require("./dependencies/ImportPhase");
|
|
25
|
+
const { InlinedUsedName } = require("./optimize/InlineExports");
|
|
15
26
|
const {
|
|
27
|
+
getDeferredCycleModuleIds,
|
|
28
|
+
getDeferredCycleModules,
|
|
16
29
|
getMakeDeferredNamespaceModeFromExportsType,
|
|
17
30
|
getOptimizedDeferredModule
|
|
18
31
|
} = require("./runtime/MakeDeferredNamespaceObjectRuntime");
|
|
19
32
|
const { equals } = require("./util/ArrayHelpers");
|
|
20
33
|
const compileBooleanMatcher = require("./util/compileBooleanMatcher");
|
|
34
|
+
const { getUndoPath, toJsStringLiteral } = require("./util/identifier");
|
|
21
35
|
const memoize = require("./util/memoize");
|
|
22
|
-
const { propertyAccess } = require("./util/property");
|
|
36
|
+
const { propertyAccess, propertyName } = require("./util/property");
|
|
23
37
|
const { forEachRuntime, subtractRuntime } = require("./util/runtime");
|
|
24
38
|
|
|
25
39
|
const getHarmonyImportDependency = memoize(() =>
|
|
@@ -28,6 +42,28 @@ const getHarmonyImportDependency = memoize(() =>
|
|
|
28
42
|
const getImportDependency = memoize(() =>
|
|
29
43
|
require("./dependencies/ImportDependency")
|
|
30
44
|
);
|
|
45
|
+
const getJavascriptModulesPlugin = memoize(() =>
|
|
46
|
+
require("./javascript/JavascriptModulesPlugin")
|
|
47
|
+
);
|
|
48
|
+
const getModuleHotAcceptDependency = memoize(() =>
|
|
49
|
+
require("./dependencies/ModuleHotAcceptDependency")
|
|
50
|
+
);
|
|
51
|
+
const getAPIPlugin = memoize(() => require("./APIPlugin"));
|
|
52
|
+
|
|
53
|
+
// Module-federation module types whose chunks load through the federation runtime.
|
|
54
|
+
/** @type {Set<string>} */
|
|
55
|
+
const FEDERATION_MODULE_TYPES = new Set([
|
|
56
|
+
WEBPACK_MODULE_TYPE_REMOTE,
|
|
57
|
+
WEBPACK_MODULE_TYPE_PROVIDE,
|
|
58
|
+
WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE,
|
|
59
|
+
WEBPACK_MODULE_TYPE_FALLBACK
|
|
60
|
+
]);
|
|
61
|
+
|
|
62
|
+
// Any `[hash]`/`[fullhash]`/`[chunkhash]`/`[contenthash]` token, incl. a `:<length>`
|
|
63
|
+
// or `:<digest>[:<length>]` suffix (e.g. `[contenthash:base64:8]`). Its value is only
|
|
64
|
+
// resolved after code generation, so a filename using one can't be an inline literal.
|
|
65
|
+
const HASH_IN_FILENAME = /\[(?:full|chunk|content)?hash(?::[^\]]+)?\]/;
|
|
66
|
+
const HASH_IN_FILENAME_GLOBAL = /\[(?:full|chunk|content)?hash(?::[^\]]+)?\]/g;
|
|
31
67
|
|
|
32
68
|
/** @typedef {import("./config/defaults").OutputNormalizedWithDefaults} OutputOptions */
|
|
33
69
|
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
|
@@ -45,6 +81,7 @@ const getImportDependency = memoize(() =>
|
|
|
45
81
|
/** @typedef {import("./NormalModuleFactory").ModuleDependency} ModuleDependency */
|
|
46
82
|
|
|
47
83
|
/**
|
|
84
|
+
* No module id error message.
|
|
48
85
|
* @param {Module} module the module
|
|
49
86
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
|
50
87
|
* @returns {string} error message
|
|
@@ -63,14 +100,15 @@ It's in these chunks: ${
|
|
|
63
100
|
Module has these incoming connections: ${Array.from(
|
|
64
101
|
chunkGraph.moduleGraph.getIncomingConnections(module),
|
|
65
102
|
(connection) =>
|
|
66
|
-
`\n - ${
|
|
67
|
-
connection.
|
|
68
|
-
} ${
|
|
103
|
+
`\n - ${connection.originModule && connection.originModule.identifier()} ${
|
|
104
|
+
connection.dependency && connection.dependency.type
|
|
105
|
+
} ${
|
|
69
106
|
(connection.explanations && [...connection.explanations].join(", ")) || ""
|
|
70
107
|
}`
|
|
71
108
|
).join("")}`;
|
|
72
109
|
|
|
73
110
|
/**
|
|
111
|
+
* Gets global object.
|
|
74
112
|
* @param {string | undefined} definition global object definition
|
|
75
113
|
* @returns {string | undefined} save to use global object
|
|
76
114
|
*/
|
|
@@ -94,17 +132,22 @@ function getGlobalObject(definition) {
|
|
|
94
132
|
|
|
95
133
|
class RuntimeTemplate {
|
|
96
134
|
/**
|
|
135
|
+
* Creates an instance of RuntimeTemplate.
|
|
97
136
|
* @param {Compilation} compilation the compilation
|
|
98
137
|
* @param {OutputOptions} outputOptions the compilation output options
|
|
99
138
|
* @param {RequestShortener} requestShortener the request shortener
|
|
100
139
|
*/
|
|
101
140
|
constructor(compilation, outputOptions, requestShortener) {
|
|
141
|
+
/** @type {Compilation} */
|
|
102
142
|
this.compilation = compilation;
|
|
103
143
|
this.outputOptions = /** @type {OutputOptions} */ (outputOptions || {});
|
|
144
|
+
/** @type {RequestShortener} */
|
|
104
145
|
this.requestShortener = requestShortener;
|
|
146
|
+
/** @type {string} */
|
|
105
147
|
this.globalObject =
|
|
106
148
|
/** @type {string} */
|
|
107
149
|
(getGlobalObject(outputOptions.globalObject));
|
|
150
|
+
/** @type {string} */
|
|
108
151
|
this.contentHashReplacement = "X".repeat(outputOptions.hashDigestLength);
|
|
109
152
|
}
|
|
110
153
|
|
|
@@ -123,14 +166,59 @@ class RuntimeTemplate {
|
|
|
123
166
|
);
|
|
124
167
|
}
|
|
125
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Whether the bundle targets node and web at once (universal `["node", "web"]` + `output.module`), like `isUniversalTarget` in `WebpackOptionsApply`.
|
|
171
|
+
* @returns {boolean} true for a universal target
|
|
172
|
+
*/
|
|
173
|
+
isUniversalTarget() {
|
|
174
|
+
const { platform } = this.compilation.compiler;
|
|
175
|
+
return (
|
|
176
|
+
Boolean(this.outputOptions.module) &&
|
|
177
|
+
platform.node === null &&
|
|
178
|
+
platform.web === null
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Runtime expression that is truthy in browser-like environments (a DOM
|
|
184
|
+
* `document` or a worker `self`) and falsy in Node.js. Single source of
|
|
185
|
+
* truth for branching a universal ("node-or-web") target at runtime.
|
|
186
|
+
* @returns {string} runtime condition expression
|
|
187
|
+
*/
|
|
188
|
+
isWebLikePlatformExpression() {
|
|
189
|
+
return "typeof document !== 'undefined' || typeof self !== 'undefined'";
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Expression for the global registry that collects CSS server-side when there
|
|
194
|
+
* is no DOM (SSR). An SSR host reads it from `globalThis`; it is keyed by the
|
|
195
|
+
* style/chunk identifier and namespaced by `output.uniqueName`.
|
|
196
|
+
* @returns {string} runtime expression evaluating to the registry object
|
|
197
|
+
*/
|
|
198
|
+
cssServerStyleRegistry() {
|
|
199
|
+
const name = this.outputOptions.uniqueName;
|
|
200
|
+
const key = JSON.stringify(
|
|
201
|
+
name ? `__webpack_css__${name}` : "__webpack_css__"
|
|
202
|
+
);
|
|
203
|
+
return `(${this.assignOr(`globalThis[${key}]`, "{}")})`;
|
|
204
|
+
}
|
|
205
|
+
|
|
126
206
|
supportsConst() {
|
|
127
207
|
return this.outputOptions.environment.const;
|
|
128
208
|
}
|
|
129
209
|
|
|
210
|
+
supportsLet() {
|
|
211
|
+
return this.outputOptions.environment.let;
|
|
212
|
+
}
|
|
213
|
+
|
|
130
214
|
supportsMethodShorthand() {
|
|
131
215
|
return this.outputOptions.environment.methodShorthand;
|
|
132
216
|
}
|
|
133
217
|
|
|
218
|
+
supportsLogicalAssignment() {
|
|
219
|
+
return this.outputOptions.environment.logicalAssignment;
|
|
220
|
+
}
|
|
221
|
+
|
|
134
222
|
supportsArrowFunction() {
|
|
135
223
|
return this.outputOptions.environment.arrowFunction;
|
|
136
224
|
}
|
|
@@ -139,10 +227,26 @@ class RuntimeTemplate {
|
|
|
139
227
|
return this.outputOptions.environment.asyncFunction;
|
|
140
228
|
}
|
|
141
229
|
|
|
230
|
+
supportsGenerator() {
|
|
231
|
+
return this.outputOptions.environment.generator;
|
|
232
|
+
}
|
|
233
|
+
|
|
142
234
|
supportsOptionalChaining() {
|
|
143
235
|
return this.outputOptions.environment.optionalChaining;
|
|
144
236
|
}
|
|
145
237
|
|
|
238
|
+
supportsSpread() {
|
|
239
|
+
return this.outputOptions.environment.spread;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
supportsObjectHasOwn() {
|
|
243
|
+
return this.outputOptions.environment.hasOwn;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
supportsSymbol() {
|
|
247
|
+
return this.outputOptions.environment.symbol;
|
|
248
|
+
}
|
|
249
|
+
|
|
146
250
|
supportsForOf() {
|
|
147
251
|
return this.outputOptions.environment.forOf;
|
|
148
252
|
}
|
|
@@ -163,6 +267,24 @@ class RuntimeTemplate {
|
|
|
163
267
|
return this.outputOptions.environment.module;
|
|
164
268
|
}
|
|
165
269
|
|
|
270
|
+
supportsModulePreload() {
|
|
271
|
+
return this.outputOptions.environment.modulePreload;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
supportsAnalyzableEsm() {
|
|
275
|
+
// `eval` devtool wraps each module in `eval(...)`, where `import.meta` is a
|
|
276
|
+
// syntax error, so the literal `new URL(…, import.meta.url)` form can't be used.
|
|
277
|
+
const { devtool } = this.compilation.options;
|
|
278
|
+
return (
|
|
279
|
+
this.isModule() &&
|
|
280
|
+
this.supportsEcmaScriptModuleSyntax() &&
|
|
281
|
+
!(typeof devtool === "string" && devtool.includes("eval")) &&
|
|
282
|
+
// A runtime `__webpack_public_path__` override can't be reflected in a
|
|
283
|
+
// baked literal, so keep the runtime form that reads `__webpack_require__.p`.
|
|
284
|
+
!getAPIPlugin().usesRuntimePublicPathOverride(this.compilation)
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
166
288
|
supportTemplateLiteral() {
|
|
167
289
|
return this.outputOptions.environment.templateLiteral;
|
|
168
290
|
}
|
|
@@ -172,6 +294,7 @@ class RuntimeTemplate {
|
|
|
172
294
|
}
|
|
173
295
|
|
|
174
296
|
/**
|
|
297
|
+
* Renders node prefix for core module.
|
|
175
298
|
* @param {string} mod a module
|
|
176
299
|
* @returns {string} a module with `node:` prefix when supported, otherwise an original name
|
|
177
300
|
*/
|
|
@@ -182,13 +305,23 @@ class RuntimeTemplate {
|
|
|
182
305
|
}
|
|
183
306
|
|
|
184
307
|
/**
|
|
185
|
-
*
|
|
308
|
+
* Renders return const when it is supported, otherwise let when supported, otherwise var.
|
|
309
|
+
* @returns {"const" | "let" | "var"} return `const` when it is supported, otherwise `let` when supported, otherwise `var`
|
|
186
310
|
*/
|
|
187
311
|
renderConst() {
|
|
188
|
-
return this.supportsConst() ? "const" : "var";
|
|
312
|
+
return this.supportsConst() ? "const" : this.supportsLet() ? "let" : "var";
|
|
189
313
|
}
|
|
190
314
|
|
|
191
315
|
/**
|
|
316
|
+
* Renders return let when it is supported, otherwise var.
|
|
317
|
+
* @returns {"let" | "var"} return `let` when it is supported, otherwise `var`
|
|
318
|
+
*/
|
|
319
|
+
renderLet() {
|
|
320
|
+
return this.supportsLet() ? "let" : "var";
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Returning function.
|
|
192
325
|
* @param {string} returnValue return value
|
|
193
326
|
* @param {string} args arguments
|
|
194
327
|
* @returns {string} returning function
|
|
@@ -200,6 +333,7 @@ class RuntimeTemplate {
|
|
|
200
333
|
}
|
|
201
334
|
|
|
202
335
|
/**
|
|
336
|
+
* Returns basic function.
|
|
203
337
|
* @param {string} args arguments
|
|
204
338
|
* @param {string | string[]} body body
|
|
205
339
|
* @returns {string} basic function
|
|
@@ -211,6 +345,7 @@ class RuntimeTemplate {
|
|
|
211
345
|
}
|
|
212
346
|
|
|
213
347
|
/**
|
|
348
|
+
* Returns result expression.
|
|
214
349
|
* @param {(string | { expr: string })[]} args args
|
|
215
350
|
* @returns {string} result expression
|
|
216
351
|
*/
|
|
@@ -260,6 +395,7 @@ class RuntimeTemplate {
|
|
|
260
395
|
}
|
|
261
396
|
|
|
262
397
|
/**
|
|
398
|
+
* Returns result expression.
|
|
263
399
|
* @param {(string | { expr: string })[]} args args (len >= 2)
|
|
264
400
|
* @returns {string} result expression
|
|
265
401
|
* @private
|
|
@@ -277,6 +413,7 @@ class RuntimeTemplate {
|
|
|
277
413
|
}
|
|
278
414
|
|
|
279
415
|
/**
|
|
416
|
+
* Expression function.
|
|
280
417
|
* @param {string} expression expression
|
|
281
418
|
* @param {string} args arguments
|
|
282
419
|
* @returns {string} expression function code
|
|
@@ -288,6 +425,7 @@ class RuntimeTemplate {
|
|
|
288
425
|
}
|
|
289
426
|
|
|
290
427
|
/**
|
|
428
|
+
* Returns empty function code.
|
|
291
429
|
* @returns {string} empty function code
|
|
292
430
|
*/
|
|
293
431
|
emptyFunction() {
|
|
@@ -295,34 +433,113 @@ class RuntimeTemplate {
|
|
|
295
433
|
}
|
|
296
434
|
|
|
297
435
|
/**
|
|
436
|
+
* Guards an access/call on `object` with optional chaining when supported,
|
|
437
|
+
* otherwise an equivalent `&&` short-circuit. `object` is evaluated twice in
|
|
438
|
+
* the fallback, so it must be side-effect free.
|
|
439
|
+
* @param {string} object base expression (side-effect free)
|
|
440
|
+
* @param {string} access continuation after the optional point, e.g. `()`, `prop`, `method(arg)` or `[key]`
|
|
441
|
+
* @returns {string} guarded access expression
|
|
442
|
+
*/
|
|
443
|
+
optionalChaining(object, access) {
|
|
444
|
+
if (this.supportsOptionalChaining()) {
|
|
445
|
+
return `${object}?.${access}`;
|
|
446
|
+
}
|
|
447
|
+
const sep = access[0] === "(" || access[0] === "[" ? "" : ".";
|
|
448
|
+
return `${object} && ${object}${sep}${access}`;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Reads a node builtin via `process.getBuiltinModule()`, guarded to stay falsy off node so universal `["node", "web"]` bundles don't crash (also falsy on node <22.3).
|
|
453
|
+
* @param {string} request builtin module request as a JS string expression, e.g. from `renderNodePrefixForCoreModule`
|
|
454
|
+
* @param {string=} access member/call chain appended to the module, e.g. `.Worker` or `.createRequire(url)`
|
|
455
|
+
* @returns {string} guarded expression
|
|
456
|
+
*/
|
|
457
|
+
getBuiltinModule(request, access = "") {
|
|
458
|
+
const getter = `process.getBuiltinModule(${request})${access}`;
|
|
459
|
+
if (this.outputOptions.environment.nodeBuiltinModuleGetter) {
|
|
460
|
+
return `typeof process !== "undefined" && ${getter}`;
|
|
461
|
+
}
|
|
462
|
+
return `typeof process !== "undefined" && typeof process.getBuiltinModule === "function" && ${getter}`;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Renders an object-literal method, using method shorthand when supported
|
|
467
|
+
* and falling back to a `prop: function/arrow` property otherwise.
|
|
468
|
+
* @param {string} prop property name (or computed key like `[x]`)
|
|
469
|
+
* @param {string} args arguments
|
|
470
|
+
* @param {string | string[]} body body
|
|
471
|
+
* @returns {string} method code
|
|
472
|
+
*/
|
|
473
|
+
method(prop, args, body) {
|
|
474
|
+
return this.supportsMethodShorthand()
|
|
475
|
+
? `${prop}(${args}) {\n${Template.indent(body)}\n}`
|
|
476
|
+
: `${prop}: ${this.basicFunction(args, body)}`;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Returns an own-property check, using `Object.hasOwn` when supported and
|
|
481
|
+
* falling back to `Object.prototype.hasOwnProperty.call` otherwise.
|
|
482
|
+
* @param {string} object object expression
|
|
483
|
+
* @param {string} property property expression
|
|
484
|
+
* @returns {string} own-property check expression
|
|
485
|
+
*/
|
|
486
|
+
objectHasOwn(object, property) {
|
|
487
|
+
return this.supportsObjectHasOwn()
|
|
488
|
+
? `Object.hasOwn(${object}, ${property})`
|
|
489
|
+
: `Object.prototype.hasOwnProperty.call(${object}, ${property})`;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Returns a self-defaulting assignment, using the `||=` logical assignment
|
|
494
|
+
* operator when supported and falling back to `target = target || value`
|
|
495
|
+
* otherwise. `target` is evaluated twice in the fallback, so it must be
|
|
496
|
+
* side-effect free. The expression evaluates to the resulting value.
|
|
497
|
+
* Models `||` only, so `target` must never hold a legitimate falsy value
|
|
498
|
+
* (`0`, `""`, `false`) — it would be overwritten; use it for object/array defaults.
|
|
499
|
+
* @param {string} target assignment target (side-effect free)
|
|
500
|
+
* @param {string} value default value expression
|
|
501
|
+
* @returns {string} assignment expression
|
|
502
|
+
*/
|
|
503
|
+
assignOr(target, value) {
|
|
504
|
+
return this.supportsLogicalAssignment()
|
|
505
|
+
? `${target} ||= ${value}`
|
|
506
|
+
: `${target} = ${target} || ${value}`;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Returns destructure array code.
|
|
298
511
|
* @param {string[]} items items
|
|
299
512
|
* @param {string} value value
|
|
300
513
|
* @returns {string} destructure array code
|
|
301
514
|
*/
|
|
302
515
|
destructureArray(items, value) {
|
|
516
|
+
const decl = this.renderLet();
|
|
303
517
|
return this.supportsDestructuring()
|
|
304
|
-
?
|
|
518
|
+
? `${decl} [${items.join(", ")}] = ${value};`
|
|
305
519
|
: Template.asString(
|
|
306
|
-
items.map((item, i) =>
|
|
520
|
+
items.map((item, i) => `${decl} ${item} = ${value}[${i}];`)
|
|
307
521
|
);
|
|
308
522
|
}
|
|
309
523
|
|
|
310
524
|
/**
|
|
525
|
+
* Destructure object.
|
|
311
526
|
* @param {string[]} items items
|
|
312
527
|
* @param {string} value value
|
|
313
528
|
* @returns {string} destructure object code
|
|
314
529
|
*/
|
|
315
530
|
destructureObject(items, value) {
|
|
531
|
+
const decl = this.renderLet();
|
|
316
532
|
return this.supportsDestructuring()
|
|
317
|
-
?
|
|
533
|
+
? `${decl} {${items.join(", ")}} = ${value};`
|
|
318
534
|
: Template.asString(
|
|
319
535
|
items.map(
|
|
320
|
-
(item) =>
|
|
536
|
+
(item) => `${decl} ${item} = ${value}${propertyAccess([item])};`
|
|
321
537
|
)
|
|
322
538
|
);
|
|
323
539
|
}
|
|
324
540
|
|
|
325
541
|
/**
|
|
542
|
+
* Returns iIFE code.
|
|
326
543
|
* @param {string} args arguments
|
|
327
544
|
* @param {string} body body
|
|
328
545
|
* @returns {string} IIFE code
|
|
@@ -332,6 +549,7 @@ class RuntimeTemplate {
|
|
|
332
549
|
}
|
|
333
550
|
|
|
334
551
|
/**
|
|
552
|
+
* Returns for each code.
|
|
335
553
|
* @param {string} variable variable
|
|
336
554
|
* @param {string} array array
|
|
337
555
|
* @param {string | string[]} body body
|
|
@@ -346,7 +564,7 @@ class RuntimeTemplate {
|
|
|
346
564
|
}
|
|
347
565
|
|
|
348
566
|
/**
|
|
349
|
-
*
|
|
567
|
+
* Returns comment.
|
|
350
568
|
* @param {object} options Information content of the comment
|
|
351
569
|
* @param {string=} options.request request string used originally
|
|
352
570
|
* @param {(string | null)=} options.chunkName name of the chunk referenced
|
|
@@ -377,18 +595,20 @@ class RuntimeTemplate {
|
|
|
377
595
|
}
|
|
378
596
|
|
|
379
597
|
/**
|
|
598
|
+
* Throw missing module error block.
|
|
380
599
|
* @param {object} options generation options
|
|
381
600
|
* @param {string=} options.request request string used originally
|
|
382
601
|
* @returns {string} generated error block
|
|
383
602
|
*/
|
|
384
603
|
throwMissingModuleErrorBlock({ request }) {
|
|
385
604
|
const err = `Cannot find module '${request}'`;
|
|
386
|
-
return
|
|
605
|
+
return `${this.renderConst()} e = new Error(${JSON.stringify(
|
|
387
606
|
err
|
|
388
607
|
)}); e.code = 'MODULE_NOT_FOUND'; throw e;`;
|
|
389
608
|
}
|
|
390
609
|
|
|
391
610
|
/**
|
|
611
|
+
* Throw missing module error function.
|
|
392
612
|
* @param {object} options generation options
|
|
393
613
|
* @param {string=} options.request request string used originally
|
|
394
614
|
* @returns {string} generated error function
|
|
@@ -400,6 +620,7 @@ class RuntimeTemplate {
|
|
|
400
620
|
}
|
|
401
621
|
|
|
402
622
|
/**
|
|
623
|
+
* Returns generated error IIFE.
|
|
403
624
|
* @param {object} options generation options
|
|
404
625
|
* @param {string=} options.request request string used originally
|
|
405
626
|
* @returns {string} generated error IIFE
|
|
@@ -409,6 +630,7 @@ class RuntimeTemplate {
|
|
|
409
630
|
}
|
|
410
631
|
|
|
411
632
|
/**
|
|
633
|
+
* Missing module statement.
|
|
412
634
|
* @param {object} options generation options
|
|
413
635
|
* @param {string=} options.request request string used originally
|
|
414
636
|
* @returns {string} generated error statement
|
|
@@ -418,6 +640,7 @@ class RuntimeTemplate {
|
|
|
418
640
|
}
|
|
419
641
|
|
|
420
642
|
/**
|
|
643
|
+
* Missing module promise.
|
|
421
644
|
* @param {object} options generation options
|
|
422
645
|
* @param {string=} options.request request string used originally
|
|
423
646
|
* @returns {string} generated error code
|
|
@@ -429,6 +652,7 @@ class RuntimeTemplate {
|
|
|
429
652
|
}
|
|
430
653
|
|
|
431
654
|
/**
|
|
655
|
+
* Returns the code.
|
|
432
656
|
* @param {object} options options object
|
|
433
657
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
|
434
658
|
* @param {Module} options.module the module
|
|
@@ -448,9 +672,7 @@ class RuntimeTemplate {
|
|
|
448
672
|
`Module '${moduleId}' is not available (weak dependency)`
|
|
449
673
|
);
|
|
450
674
|
const comment = request ? `${Template.toNormalComment(request)} ` : "";
|
|
451
|
-
const errorStatements =
|
|
452
|
-
comment
|
|
453
|
-
}e.code = 'MODULE_NOT_FOUND'; throw e;`;
|
|
675
|
+
const errorStatements = `${this.renderConst()} e = new Error(${errorMessage}); ${comment}e.code = 'MODULE_NOT_FOUND'; throw e;`;
|
|
454
676
|
switch (type) {
|
|
455
677
|
case "statements":
|
|
456
678
|
return errorStatements;
|
|
@@ -465,6 +687,7 @@ class RuntimeTemplate {
|
|
|
465
687
|
}
|
|
466
688
|
|
|
467
689
|
/**
|
|
690
|
+
* Returns the expression.
|
|
468
691
|
* @param {object} options options object
|
|
469
692
|
* @param {Module} options.module the module
|
|
470
693
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
|
@@ -494,6 +717,7 @@ class RuntimeTemplate {
|
|
|
494
717
|
}
|
|
495
718
|
|
|
496
719
|
/**
|
|
720
|
+
* Returns the expression.
|
|
497
721
|
* @param {object} options options object
|
|
498
722
|
* @param {Module | null} options.module the module
|
|
499
723
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
|
@@ -537,6 +761,7 @@ class RuntimeTemplate {
|
|
|
537
761
|
}
|
|
538
762
|
|
|
539
763
|
/**
|
|
764
|
+
* Returns the expression.
|
|
540
765
|
* @param {object} options options object
|
|
541
766
|
* @param {Module | null} options.module the module
|
|
542
767
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
|
@@ -556,6 +781,7 @@ class RuntimeTemplate {
|
|
|
556
781
|
}
|
|
557
782
|
|
|
558
783
|
/**
|
|
784
|
+
* Returns the expression.
|
|
559
785
|
* @param {object} options options object
|
|
560
786
|
* @param {Module} options.module the module
|
|
561
787
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
|
@@ -625,6 +851,7 @@ class RuntimeTemplate {
|
|
|
625
851
|
}
|
|
626
852
|
|
|
627
853
|
/**
|
|
854
|
+
* Module namespace promise.
|
|
628
855
|
* @param {object} options options object
|
|
629
856
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
|
630
857
|
* @param {AsyncDependenciesBlock=} options.block the current dependencies block
|
|
@@ -635,6 +862,7 @@ class RuntimeTemplate {
|
|
|
635
862
|
* @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
|
|
636
863
|
* @param {Dependency} options.dependency dependency
|
|
637
864
|
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
|
865
|
+
* @param {Module=} options.originModule the module the `import()` is emitted into
|
|
638
866
|
* @returns {string} the promise expression
|
|
639
867
|
*/
|
|
640
868
|
moduleNamespacePromise({
|
|
@@ -646,7 +874,8 @@ class RuntimeTemplate {
|
|
|
646
874
|
strict,
|
|
647
875
|
weak,
|
|
648
876
|
dependency,
|
|
649
|
-
runtimeRequirements
|
|
877
|
+
runtimeRequirements,
|
|
878
|
+
originModule
|
|
650
879
|
}) {
|
|
651
880
|
if (!module) {
|
|
652
881
|
return this.missingModulePromise({
|
|
@@ -676,7 +905,8 @@ class RuntimeTemplate {
|
|
|
676
905
|
chunkGraph,
|
|
677
906
|
block,
|
|
678
907
|
message,
|
|
679
|
-
runtimeRequirements
|
|
908
|
+
runtimeRequirements,
|
|
909
|
+
originModule
|
|
680
910
|
});
|
|
681
911
|
|
|
682
912
|
/** @type {string} */
|
|
@@ -689,7 +919,7 @@ class RuntimeTemplate {
|
|
|
689
919
|
if (weak) {
|
|
690
920
|
if (idExpr.length > 8) {
|
|
691
921
|
// 'var x="nnnnnn";x,"+x+",x' vs '"nnnnnn",nnnnnn,"nnnnnn"'
|
|
692
|
-
header +=
|
|
922
|
+
header += `${this.renderConst()} id = ${idExpr}; `;
|
|
693
923
|
idExpr = "id";
|
|
694
924
|
}
|
|
695
925
|
runtimeRequirements.add(RuntimeGlobals.moduleFactories);
|
|
@@ -725,11 +955,17 @@ class RuntimeTemplate {
|
|
|
725
955
|
if (header) {
|
|
726
956
|
appending = `.then(${this.basicFunction(
|
|
727
957
|
"",
|
|
728
|
-
`${header}return ${
|
|
958
|
+
`${header}return ${
|
|
959
|
+
RuntimeGlobals.deferredModuleAsyncTransitiveDependencies
|
|
960
|
+
}(${JSON.stringify(asyncDeps)});`
|
|
729
961
|
)})`;
|
|
730
962
|
} else {
|
|
731
963
|
runtimeRequirements.add(RuntimeGlobals.require);
|
|
732
|
-
appending = `.then(${this.returningFunction(
|
|
964
|
+
appending = `.then(${this.returningFunction(
|
|
965
|
+
`${
|
|
966
|
+
RuntimeGlobals.deferredModuleAsyncTransitiveDependencies
|
|
967
|
+
}(${JSON.stringify(asyncDeps)})`
|
|
968
|
+
)})`;
|
|
733
969
|
}
|
|
734
970
|
appending += `.then(${RuntimeGlobals.makeDeferredNamespaceObject}.bind(${RuntimeGlobals.require}, ${comment}${idExpr}, ${mode}))`;
|
|
735
971
|
} else if (header) {
|
|
@@ -817,6 +1053,7 @@ class RuntimeTemplate {
|
|
|
817
1053
|
}
|
|
818
1054
|
|
|
819
1055
|
/**
|
|
1056
|
+
* Runtime condition expression.
|
|
820
1057
|
* @param {object} options options object
|
|
821
1058
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
|
822
1059
|
* @param {RuntimeSpec=} options.runtime runtime for which this code will be generated
|
|
@@ -854,6 +1091,7 @@ class RuntimeTemplate {
|
|
|
854
1091
|
}
|
|
855
1092
|
|
|
856
1093
|
/**
|
|
1094
|
+
* Returns the import statement and the compat statement.
|
|
857
1095
|
* @param {object} options options object
|
|
858
1096
|
* @param {boolean=} options.update whether a new variable should be created or the existing one updated
|
|
859
1097
|
* @param {Module} options.module the module
|
|
@@ -915,6 +1153,10 @@ class RuntimeTemplate {
|
|
|
915
1153
|
request,
|
|
916
1154
|
weak
|
|
917
1155
|
});
|
|
1156
|
+
// Harmony imports may be wrapped in runtime-condition `if` blocks
|
|
1157
|
+
// but referenced outside those blocks (e.g. by harmony reexport),
|
|
1158
|
+
// so they must remain function-scoped (`var`) rather than
|
|
1159
|
+
// block-scoped (`let`/`const`).
|
|
918
1160
|
const optDeclaration = update ? "" : "var ";
|
|
919
1161
|
|
|
920
1162
|
const exportsType = module.getExportsType(
|
|
@@ -941,6 +1183,10 @@ class RuntimeTemplate {
|
|
|
941
1183
|
moduleId,
|
|
942
1184
|
exportsType,
|
|
943
1185
|
Array.from(outgoingAsyncModules, (mod) => chunkGraph.getModuleId(mod)),
|
|
1186
|
+
getDeferredCycleModuleIds(
|
|
1187
|
+
getDeferredCycleModules(moduleGraph, module),
|
|
1188
|
+
(mod) => chunkGraph.getModuleId(mod)
|
|
1189
|
+
),
|
|
944
1190
|
runtimeRequirements
|
|
945
1191
|
)};\n`;
|
|
946
1192
|
|
|
@@ -959,6 +1205,7 @@ class RuntimeTemplate {
|
|
|
959
1205
|
}
|
|
960
1206
|
|
|
961
1207
|
/**
|
|
1208
|
+
* Export from import.
|
|
962
1209
|
* @template GenerateContext
|
|
963
1210
|
* @param {object} options options
|
|
964
1211
|
* @param {ModuleGraph} options.moduleGraph the module graph
|
|
@@ -976,6 +1223,7 @@ class RuntimeTemplate {
|
|
|
976
1223
|
* @param {RuntimeSpec} options.runtime runtime for which this code will be generated
|
|
977
1224
|
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
|
978
1225
|
* @param {ModuleDependency} options.dependency module dependency
|
|
1226
|
+
* @param {boolean=} options.mangleableNamespace true, when a whole-namespace value may use a decoupled namespace object that keeps the original export names
|
|
979
1227
|
* @returns {string} expression
|
|
980
1228
|
*/
|
|
981
1229
|
exportFromImport({
|
|
@@ -993,7 +1241,8 @@ class RuntimeTemplate {
|
|
|
993
1241
|
initFragments,
|
|
994
1242
|
runtime,
|
|
995
1243
|
runtimeRequirements,
|
|
996
|
-
dependency
|
|
1244
|
+
dependency,
|
|
1245
|
+
mangleableNamespace = false
|
|
997
1246
|
}) {
|
|
998
1247
|
if (!module) {
|
|
999
1248
|
return this.missingModule({
|
|
@@ -1028,7 +1277,14 @@ class RuntimeTemplate {
|
|
|
1028
1277
|
);
|
|
1029
1278
|
return `${comment} undefined`;
|
|
1030
1279
|
}
|
|
1031
|
-
|
|
1280
|
+
if (used instanceof InlinedUsedName) {
|
|
1281
|
+
throw new Error(
|
|
1282
|
+
"Can't inline the exports of defer imported module"
|
|
1283
|
+
);
|
|
1284
|
+
}
|
|
1285
|
+
const access = `${importVar}.a${propertyAccess(
|
|
1286
|
+
Array.isArray(used) ? used : [used]
|
|
1287
|
+
)}`;
|
|
1032
1288
|
if (isCall || asiSafe === undefined) {
|
|
1033
1289
|
return access;
|
|
1034
1290
|
}
|
|
@@ -1086,7 +1342,7 @@ class RuntimeTemplate {
|
|
|
1086
1342
|
runtimeRequirements.add(RuntimeGlobals.createFakeNamespaceObject);
|
|
1087
1343
|
initFragments.push(
|
|
1088
1344
|
new InitFragment(
|
|
1089
|
-
|
|
1345
|
+
`${this.renderLet()} ${importVar}_namespace_cache;\n`,
|
|
1090
1346
|
InitFragment.STAGE_CONSTANTS,
|
|
1091
1347
|
-1,
|
|
1092
1348
|
`${importVar}_namespace_cache`
|
|
@@ -1111,12 +1367,19 @@ class RuntimeTemplate {
|
|
|
1111
1367
|
);
|
|
1112
1368
|
return `${comment} undefined`;
|
|
1113
1369
|
}
|
|
1370
|
+
if (used instanceof InlinedUsedName) {
|
|
1371
|
+
return used.render(
|
|
1372
|
+
Template.toNormalComment(
|
|
1373
|
+
`inlined export ${propertyAccess(exportName)}`
|
|
1374
|
+
)
|
|
1375
|
+
);
|
|
1376
|
+
}
|
|
1114
1377
|
const comment = equals(used, exportName)
|
|
1115
1378
|
? ""
|
|
1116
1379
|
: `${Template.toNormalComment(propertyAccess(exportName))} `;
|
|
1117
1380
|
const access = `${importVar}${
|
|
1118
1381
|
isModuleDeferred ? ".a" : ""
|
|
1119
|
-
}${comment}${propertyAccess(used)}`;
|
|
1382
|
+
}${comment}${propertyAccess(Array.isArray(used) ? used : [used])}`;
|
|
1120
1383
|
if (isCall && callContext === false) {
|
|
1121
1384
|
return asiSafe
|
|
1122
1385
|
? `(0,${access})`
|
|
@@ -1129,7 +1392,7 @@ class RuntimeTemplate {
|
|
|
1129
1392
|
if (isModuleDeferred) {
|
|
1130
1393
|
initFragments.push(
|
|
1131
1394
|
new InitFragment(
|
|
1132
|
-
|
|
1395
|
+
`${this.renderLet()} ${importVar}_deferred_namespace_cache;\n`,
|
|
1133
1396
|
InitFragment.STAGE_CONSTANTS,
|
|
1134
1397
|
-1,
|
|
1135
1398
|
`${importVar}_deferred_namespace_cache`
|
|
@@ -1147,6 +1410,25 @@ class RuntimeTemplate {
|
|
|
1147
1410
|
asiSafe ? "" : asiSafe === false ? ";" : "Object"
|
|
1148
1411
|
}(${importVar}_deferred_namespace_cache || (${importVar}_deferred_namespace_cache = ${init}))`;
|
|
1149
1412
|
}
|
|
1413
|
+
// The whole namespace object is used as a value. If the module's exports
|
|
1414
|
+
// were mangled, importVar's keys are the mangled names, so we materialize
|
|
1415
|
+
// a decoupled namespace object that exposes the original names.
|
|
1416
|
+
if (
|
|
1417
|
+
exportsType === "namespace" &&
|
|
1418
|
+
mangleableNamespace &&
|
|
1419
|
+
this.compilation &&
|
|
1420
|
+
this.compilation.options.optimization.mangleExports
|
|
1421
|
+
) {
|
|
1422
|
+
const materialized = this._materializedNamespaceObject({
|
|
1423
|
+
moduleGraph,
|
|
1424
|
+
module,
|
|
1425
|
+
importVar,
|
|
1426
|
+
initFragments,
|
|
1427
|
+
runtime,
|
|
1428
|
+
runtimeRequirements
|
|
1429
|
+
});
|
|
1430
|
+
if (materialized !== undefined) return materialized;
|
|
1431
|
+
}
|
|
1150
1432
|
// if we hit here, the importVar is either
|
|
1151
1433
|
// - already a ES module namespace object
|
|
1152
1434
|
// - or imported by a way that does not need interop.
|
|
@@ -1154,14 +1436,92 @@ class RuntimeTemplate {
|
|
|
1154
1436
|
}
|
|
1155
1437
|
|
|
1156
1438
|
/**
|
|
1439
|
+
* Materializes a namespace object that keeps the original export names while
|
|
1440
|
+
* the module's own exports are mangled. Returns undefined when no export was
|
|
1441
|
+
* mangled (then the raw namespace object can be used as-is).
|
|
1442
|
+
* @template GenerateContext
|
|
1443
|
+
* @param {object} options options
|
|
1444
|
+
* @param {ModuleGraph} options.moduleGraph the module graph
|
|
1445
|
+
* @param {Module} options.module the imported module
|
|
1446
|
+
* @param {string} options.importVar the import variable referencing the module
|
|
1447
|
+
* @param {InitFragment<GenerateContext>[]} options.initFragments target array for init fragments
|
|
1448
|
+
* @param {RuntimeSpec} options.runtime the runtime
|
|
1449
|
+
* @param {RuntimeRequirements} options.runtimeRequirements runtime requirements
|
|
1450
|
+
* @returns {string | undefined} expression of the materialized namespace object, or undefined
|
|
1451
|
+
*/
|
|
1452
|
+
_materializedNamespaceObject({
|
|
1453
|
+
moduleGraph,
|
|
1454
|
+
module,
|
|
1455
|
+
importVar,
|
|
1456
|
+
initFragments,
|
|
1457
|
+
runtime,
|
|
1458
|
+
runtimeRequirements
|
|
1459
|
+
}) {
|
|
1460
|
+
const exportsInfo = moduleGraph.getExportsInfo(module);
|
|
1461
|
+
/** @type {string[]} */
|
|
1462
|
+
const definitions = [];
|
|
1463
|
+
let mangled = false;
|
|
1464
|
+
for (const exportInfo of exportsInfo.orderedExports) {
|
|
1465
|
+
if (exportInfo.provided === false) continue;
|
|
1466
|
+
const used = exportsInfo.getUsedName([exportInfo.name], runtime);
|
|
1467
|
+
if (!used) continue;
|
|
1468
|
+
if (used instanceof InlinedUsedName) {
|
|
1469
|
+
// An inlined export isn't reachable by name on the raw exports object,
|
|
1470
|
+
// so the decoupled object must expose the inlined value directly.
|
|
1471
|
+
mangled = true;
|
|
1472
|
+
definitions.push(
|
|
1473
|
+
`${propertyName(exportInfo.name)}: ${this.returningFunction(
|
|
1474
|
+
used.render(
|
|
1475
|
+
Template.toNormalComment(
|
|
1476
|
+
`inlined export ${propertyAccess([exportInfo.name])}`
|
|
1477
|
+
)
|
|
1478
|
+
)
|
|
1479
|
+
)}`
|
|
1480
|
+
);
|
|
1481
|
+
continue;
|
|
1482
|
+
}
|
|
1483
|
+
if (used[used.length - 1] !== exportInfo.name) mangled = true;
|
|
1484
|
+
definitions.push(
|
|
1485
|
+
`${propertyName(exportInfo.name)}: ${this.returningFunction(
|
|
1486
|
+
`${importVar}${propertyAccess(/** @type {string[]} */ (used))}`
|
|
1487
|
+
)}`
|
|
1488
|
+
);
|
|
1489
|
+
}
|
|
1490
|
+
if (!mangled) return;
|
|
1491
|
+
const name = `${importVar}_namespace_object`;
|
|
1492
|
+
runtimeRequirements.add(RuntimeGlobals.exports);
|
|
1493
|
+
runtimeRequirements.add(RuntimeGlobals.makeNamespaceObject);
|
|
1494
|
+
runtimeRequirements.add(RuntimeGlobals.definePropertyGetters);
|
|
1495
|
+
initFragments.push(
|
|
1496
|
+
new InitFragment(
|
|
1497
|
+
`var ${name} = {};\n${RuntimeGlobals.makeNamespaceObject}(${name});\n${
|
|
1498
|
+
RuntimeGlobals.definePropertyGetters
|
|
1499
|
+
}(${name}, {\n\t${definitions.join(",\n\t")}\n});\n`,
|
|
1500
|
+
InitFragment.STAGE_PROVIDES,
|
|
1501
|
+
0,
|
|
1502
|
+
name
|
|
1503
|
+
)
|
|
1504
|
+
);
|
|
1505
|
+
return name;
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
/**
|
|
1509
|
+
* Returns expression.
|
|
1157
1510
|
* @param {object} options options
|
|
1158
1511
|
* @param {AsyncDependenciesBlock | undefined} options.block the async block
|
|
1159
1512
|
* @param {string} options.message the message
|
|
1160
1513
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
|
1161
1514
|
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|
|
1515
|
+
* @param {Module=} options.originModule the module the `import()` is emitted into
|
|
1162
1516
|
* @returns {string} expression
|
|
1163
1517
|
*/
|
|
1164
|
-
blockPromise({
|
|
1518
|
+
blockPromise({
|
|
1519
|
+
block,
|
|
1520
|
+
message,
|
|
1521
|
+
chunkGraph,
|
|
1522
|
+
runtimeRequirements,
|
|
1523
|
+
originModule
|
|
1524
|
+
}) {
|
|
1165
1525
|
if (!block) {
|
|
1166
1526
|
const comment = this.comment({
|
|
1167
1527
|
message
|
|
@@ -1182,12 +1542,25 @@ class RuntimeTemplate {
|
|
|
1182
1542
|
message,
|
|
1183
1543
|
chunkName: block.chunkName
|
|
1184
1544
|
});
|
|
1545
|
+
// A `fetchPriority` hint rides on the runtime `ensureChunk(id, priority)` call;
|
|
1546
|
+
// the analyzable literal `import()` can't carry it, so keep the runtime form.
|
|
1547
|
+
const fetchPriority = chunkGroup.options.fetchPriority;
|
|
1185
1548
|
if (chunks.length === 1) {
|
|
1549
|
+
const analyzable = fetchPriority
|
|
1550
|
+
? null
|
|
1551
|
+
: this._analyzableChunkImport(
|
|
1552
|
+
chunks[0],
|
|
1553
|
+
comment,
|
|
1554
|
+
runtimeRequirements,
|
|
1555
|
+
originModule,
|
|
1556
|
+
chunkGraph
|
|
1557
|
+
);
|
|
1558
|
+
if (analyzable !== null) {
|
|
1559
|
+
return analyzable;
|
|
1560
|
+
}
|
|
1186
1561
|
const chunkId = JSON.stringify(chunks[0].id);
|
|
1187
1562
|
runtimeRequirements.add(RuntimeGlobals.ensureChunk);
|
|
1188
1563
|
|
|
1189
|
-
const fetchPriority = chunkGroup.options.fetchPriority;
|
|
1190
|
-
|
|
1191
1564
|
if (fetchPriority) {
|
|
1192
1565
|
runtimeRequirements.add(RuntimeGlobals.hasFetchPriority);
|
|
1193
1566
|
}
|
|
@@ -1196,30 +1569,234 @@ class RuntimeTemplate {
|
|
|
1196
1569
|
fetchPriority ? `, ${JSON.stringify(fetchPriority)}` : ""
|
|
1197
1570
|
})`;
|
|
1198
1571
|
} else if (chunks.length > 0) {
|
|
1199
|
-
runtimeRequirements.add(RuntimeGlobals.ensureChunk);
|
|
1200
|
-
|
|
1201
|
-
const fetchPriority = chunkGroup.options.fetchPriority;
|
|
1202
|
-
|
|
1203
1572
|
if (fetchPriority) {
|
|
1204
1573
|
runtimeRequirements.add(RuntimeGlobals.hasFetchPriority);
|
|
1205
1574
|
}
|
|
1206
1575
|
|
|
1576
|
+
let needEnsureChunk = false;
|
|
1207
1577
|
/**
|
|
1578
|
+
* Analyzable `import()` for a solely-owned JS chunk, else runtime ensureChunk.
|
|
1208
1579
|
* @param {Chunk} chunk chunk
|
|
1209
1580
|
* @returns {string} require chunk id code
|
|
1210
1581
|
*/
|
|
1211
|
-
const requireChunkId = (chunk) =>
|
|
1212
|
-
|
|
1582
|
+
const requireChunkId = (chunk) => {
|
|
1583
|
+
const analyzable = fetchPriority
|
|
1584
|
+
? null
|
|
1585
|
+
: this._analyzableChunkImport(
|
|
1586
|
+
chunk,
|
|
1587
|
+
"",
|
|
1588
|
+
runtimeRequirements,
|
|
1589
|
+
originModule,
|
|
1590
|
+
chunkGraph
|
|
1591
|
+
);
|
|
1592
|
+
if (analyzable !== null) return analyzable;
|
|
1593
|
+
needEnsureChunk = true;
|
|
1594
|
+
return `${RuntimeGlobals.ensureChunk}(${JSON.stringify(chunk.id)}${
|
|
1213
1595
|
fetchPriority ? `, ${JSON.stringify(fetchPriority)}` : ""
|
|
1214
1596
|
})`;
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1597
|
+
};
|
|
1598
|
+
const items = chunks.map(requireChunkId);
|
|
1599
|
+
if (needEnsureChunk) {
|
|
1600
|
+
runtimeRequirements.add(RuntimeGlobals.ensureChunk);
|
|
1601
|
+
}
|
|
1602
|
+
return `Promise.all(${comment.trim()}[${items.join(", ")}])`;
|
|
1218
1603
|
}
|
|
1219
1604
|
return `Promise.resolve(${comment.trim()})`;
|
|
1220
1605
|
}
|
|
1221
1606
|
|
|
1222
1607
|
/**
|
|
1608
|
+
* For ESM module output, load a single statically-named chunk through the
|
|
1609
|
+
* `analyzableChunkImport` helper — a literal `import("./chunk.js")` other bundlers
|
|
1610
|
+
* and webpack itself can follow, wrapped to keep `ensureChunk` timing and deduplication.
|
|
1611
|
+
* Returns `null` to fall back to the runtime `ensureChunk` form.
|
|
1612
|
+
* @param {Chunk} chunk the chunk to load
|
|
1613
|
+
* @param {string} comment leading comment (chunk name / message)
|
|
1614
|
+
* @param {RuntimeRequirements} runtimeRequirements runtime requirements
|
|
1615
|
+
* @param {Module=} originModule the module the `import()` is emitted into
|
|
1616
|
+
* @param {ChunkGraph=} chunkGraph the chunk graph
|
|
1617
|
+
* @returns {string | null} the import expression, or `null`
|
|
1618
|
+
*/
|
|
1619
|
+
_analyzableChunkImport(
|
|
1620
|
+
chunk,
|
|
1621
|
+
comment,
|
|
1622
|
+
runtimeRequirements,
|
|
1623
|
+
originModule,
|
|
1624
|
+
chunkGraph
|
|
1625
|
+
) {
|
|
1626
|
+
const { outputOptions } = this;
|
|
1627
|
+
if (
|
|
1628
|
+
!outputOptions.module ||
|
|
1629
|
+
outputOptions.chunkFormat !== "module" ||
|
|
1630
|
+
outputOptions.importFunctionName !== "import" ||
|
|
1631
|
+
chunk.id === null ||
|
|
1632
|
+
!originModule ||
|
|
1633
|
+
!chunkGraph
|
|
1634
|
+
) {
|
|
1635
|
+
return null;
|
|
1636
|
+
}
|
|
1637
|
+
// HMR wraps `ensureChunk` (`.e`) to track in-flight loads and relies on it being
|
|
1638
|
+
// present in the runtime; the analyzable `import()` (`.ei`) replaces `.e` and would
|
|
1639
|
+
// leave a lazy-compilation proxy's own `.e` call undefined, so keep the runtime form.
|
|
1640
|
+
// A runtime `__webpack_public_path__` override likewise can't reach a baked literal.
|
|
1641
|
+
if (
|
|
1642
|
+
this.compilation.dependencyFactories.has(
|
|
1643
|
+
getModuleHotAcceptDependency()
|
|
1644
|
+
) ||
|
|
1645
|
+
getAPIPlugin().usesRuntimePublicPathOverride(this.compilation)
|
|
1646
|
+
) {
|
|
1647
|
+
return null;
|
|
1648
|
+
}
|
|
1649
|
+
// A worker entry loads its own chunks through the worker runtime; keep that path.
|
|
1650
|
+
for (const originChunk of chunkGraph.getModuleChunksIterable(
|
|
1651
|
+
originModule
|
|
1652
|
+
)) {
|
|
1653
|
+
const entryOptions = originChunk.getEntryOptions();
|
|
1654
|
+
if (entryOptions && entryOptions.worker) {
|
|
1655
|
+
return null;
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
// Only a chunk that is loaded solely through this `import()` and holds pure JS:
|
|
1659
|
+
// a shared chunk (splitChunks / module federation) or one with css/wasm/other
|
|
1660
|
+
// assets needs the runtime's deduplication and per-type loaders, so keep it.
|
|
1661
|
+
if (chunk.getNumberOfGroups() !== 1) {
|
|
1662
|
+
return null;
|
|
1663
|
+
}
|
|
1664
|
+
// Prefetch/preload children (incl. CSS-only preload) are injected by the runtime
|
|
1665
|
+
// `.f` handlers when the chunk loads, which the analyzable `import()` bypasses —
|
|
1666
|
+
// keep the runtime form for them.
|
|
1667
|
+
if (
|
|
1668
|
+
chunk.hasChildByOrder(chunkGraph, "prefetch", true) ||
|
|
1669
|
+
chunk.hasChildByOrder(chunkGraph, "preload", true) ||
|
|
1670
|
+
chunk.hasChildByOrder(chunkGraph, "cssPreload", true)
|
|
1671
|
+
) {
|
|
1672
|
+
return null;
|
|
1673
|
+
}
|
|
1674
|
+
for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
|
|
1675
|
+
// Module federation (remote/shared/provide) loads through its own runtime.
|
|
1676
|
+
if (FEDERATION_MODULE_TYPES.has(module.type)) {
|
|
1677
|
+
return null;
|
|
1678
|
+
}
|
|
1679
|
+
for (const type of chunkGraph.getModuleSourceTypes(module)) {
|
|
1680
|
+
if (type !== JAVASCRIPT_TYPE && type !== RUNTIME_TYPE) {
|
|
1681
|
+
return null;
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
// Relative to the consuming chunk (`import.meta.url`) for `auto`, else an
|
|
1686
|
+
// absolute publicPath prefix.
|
|
1687
|
+
const specifier = this._getAnalyzableChunkSpecifier(
|
|
1688
|
+
undefined,
|
|
1689
|
+
chunk,
|
|
1690
|
+
originModule,
|
|
1691
|
+
chunkGraph
|
|
1692
|
+
);
|
|
1693
|
+
// `import()` needs a resolvable specifier — relative (`./`, `../`), absolute (`/`)
|
|
1694
|
+
// or a URL scheme. A bare one (empty/relative publicPath) is treated as a package,
|
|
1695
|
+
// so keep the runtime form. (`new URL(...)` callers accept bare, resolving vs base.)
|
|
1696
|
+
if (
|
|
1697
|
+
specifier === null ||
|
|
1698
|
+
!/^"(?:\.{0,2}\/|[a-zA-Z][\w+.-]*:)/.test(specifier)
|
|
1699
|
+
) {
|
|
1700
|
+
return null;
|
|
1701
|
+
}
|
|
1702
|
+
runtimeRequirements.add(RuntimeGlobals.analyzableChunkImport);
|
|
1703
|
+
// Drop-in for `ensureChunk(id)`: the literal `import()` can be statically
|
|
1704
|
+
// followed, the helper keeps webpack's install timing and deduplication.
|
|
1705
|
+
return `${RuntimeGlobals.analyzableChunkImport}(${JSON.stringify(
|
|
1706
|
+
chunk.id
|
|
1707
|
+
)}, () => import(${comment}${specifier}))`;
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
/**
|
|
1711
|
+
* Computes the `../`-path from the consuming module's chunk(s) back to the output
|
|
1712
|
+
* root, so a chunk or asset can be referenced relative to `import.meta.url`. Returns
|
|
1713
|
+
* `null` when the module lives in chunks of different depths (no single path works).
|
|
1714
|
+
* @param {Module} module the consuming module
|
|
1715
|
+
* @param {ChunkGraph} chunkGraph the chunk graph
|
|
1716
|
+
* @returns {string | null} relative undo path, or `null` when ambiguous
|
|
1717
|
+
*/
|
|
1718
|
+
_getModuleUndoPath(module, chunkGraph) {
|
|
1719
|
+
const { compilation } = this;
|
|
1720
|
+
const { outputOptions } = compilation;
|
|
1721
|
+
const outputPath = /** @type {string} */ (outputOptions.path);
|
|
1722
|
+
/** @type {string | null} */
|
|
1723
|
+
let result = null;
|
|
1724
|
+
let found = false;
|
|
1725
|
+
for (const chunk of chunkGraph.getModuleChunksIterable(module)) {
|
|
1726
|
+
const template = getJavascriptModulesPlugin().getChunkFilenameTemplate(
|
|
1727
|
+
chunk,
|
|
1728
|
+
outputOptions
|
|
1729
|
+
);
|
|
1730
|
+
const chunkName = compilation.getPath(
|
|
1731
|
+
// Hashes aren't known during code generation and only sit in the basename
|
|
1732
|
+
// (never a directory), so neutralize them — only the `../` depth matters.
|
|
1733
|
+
typeof template === "string"
|
|
1734
|
+
? template.replace(HASH_IN_FILENAME_GLOBAL, "x")
|
|
1735
|
+
: template,
|
|
1736
|
+
{ chunk, contentHashType: JAVASCRIPT_TYPE }
|
|
1737
|
+
);
|
|
1738
|
+
const undo = getUndoPath(chunkName, outputPath, true);
|
|
1739
|
+
if (!found) {
|
|
1740
|
+
result = undo;
|
|
1741
|
+
found = true;
|
|
1742
|
+
} else if (result !== undo) {
|
|
1743
|
+
return null;
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
return found ? result : null;
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
/**
|
|
1750
|
+
* Static literal specifier (already quoted) for a `new URL(<here>, import.meta.url)`
|
|
1751
|
+
* or `import(<here>)` pointing at `chunk`'s JS file, or `null` when it can't be known
|
|
1752
|
+
* statically — a content hash in the filename, or a dynamic/templated publicPath.
|
|
1753
|
+
* @param {string | undefined} overridePublicPath per-dependency public path (wins over `output.publicPath`)
|
|
1754
|
+
* @param {Chunk} chunk the chunk to reference
|
|
1755
|
+
* @param {Module} consumingModule the module the reference is emitted into
|
|
1756
|
+
* @param {ChunkGraph} chunkGraph the chunk graph
|
|
1757
|
+
* @returns {string | null} a JS string literal, or `null` to fall back to the runtime form
|
|
1758
|
+
*/
|
|
1759
|
+
_getAnalyzableChunkSpecifier(
|
|
1760
|
+
overridePublicPath,
|
|
1761
|
+
chunk,
|
|
1762
|
+
consumingModule,
|
|
1763
|
+
chunkGraph
|
|
1764
|
+
) {
|
|
1765
|
+
const { compilation } = this;
|
|
1766
|
+
const { outputOptions } = compilation;
|
|
1767
|
+
const filenameTemplate =
|
|
1768
|
+
getJavascriptModulesPlugin().getChunkFilenameTemplate(
|
|
1769
|
+
chunk,
|
|
1770
|
+
outputOptions
|
|
1771
|
+
);
|
|
1772
|
+
if (
|
|
1773
|
+
typeof filenameTemplate !== "string" ||
|
|
1774
|
+
HASH_IN_FILENAME.test(filenameTemplate)
|
|
1775
|
+
) {
|
|
1776
|
+
return null;
|
|
1777
|
+
}
|
|
1778
|
+
const filename = compilation.getPath(filenameTemplate, {
|
|
1779
|
+
chunk,
|
|
1780
|
+
contentHashType: JAVASCRIPT_TYPE
|
|
1781
|
+
});
|
|
1782
|
+
if (overridePublicPath) {
|
|
1783
|
+
return overridePublicPath.includes("[")
|
|
1784
|
+
? null
|
|
1785
|
+
: toJsStringLiteral(overridePublicPath + filename);
|
|
1786
|
+
}
|
|
1787
|
+
const { publicPath } = outputOptions;
|
|
1788
|
+
if (publicPath === "auto") {
|
|
1789
|
+
const undo = this._getModuleUndoPath(consumingModule, chunkGraph);
|
|
1790
|
+
return undo === null ? null : toJsStringLiteral(undo + filename);
|
|
1791
|
+
}
|
|
1792
|
+
if (typeof publicPath === "string" && !publicPath.includes("[")) {
|
|
1793
|
+
return toJsStringLiteral(publicPath + filename);
|
|
1794
|
+
}
|
|
1795
|
+
return null;
|
|
1796
|
+
}
|
|
1797
|
+
|
|
1798
|
+
/**
|
|
1799
|
+
* Async module factory.
|
|
1223
1800
|
* @param {object} options options
|
|
1224
1801
|
* @param {AsyncDependenciesBlock} options.block the async block
|
|
1225
1802
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
|
@@ -1252,6 +1829,7 @@ class RuntimeTemplate {
|
|
|
1252
1829
|
}
|
|
1253
1830
|
|
|
1254
1831
|
/**
|
|
1832
|
+
* Sync module factory.
|
|
1255
1833
|
* @param {object} options options
|
|
1256
1834
|
* @param {Dependency} options.dependency the dependency
|
|
1257
1835
|
* @param {ChunkGraph} options.chunkGraph the chunk graph
|
|
@@ -1273,6 +1851,7 @@ class RuntimeTemplate {
|
|
|
1273
1851
|
}
|
|
1274
1852
|
|
|
1275
1853
|
/**
|
|
1854
|
+
* Define es module flag statement.
|
|
1276
1855
|
* @param {object} options options
|
|
1277
1856
|
* @param {string} options.exportsArgument the name of the exports object
|
|
1278
1857
|
* @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
|