@depup/webpack 5.111.1-depup.2 → 5.112.0-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 +4 -8
- package/changes.json +3 -19
- package/lib/Chunk.js +3 -966
- package/lib/Compilation.js +224 -106
- package/lib/Compiler.js +19 -19
- package/lib/Dependency.js +3 -551
- package/lib/DependencyTemplate.js +3 -70
- package/lib/EntryPlugin.js +3 -68
- package/lib/Entrypoint.js +3 -121
- package/lib/ExternalsPlugin.js +3 -92
- package/lib/FileSystemInfo.js +3 -4629
- package/lib/InitFragment.js +3 -204
- package/lib/LibraryTemplatePlugin.js +3 -46
- package/lib/ModuleFilenameHelpers.js +3 -400
- package/lib/ModuleNotFoundError.js +2 -2
- package/lib/MultiCompiler.js +37 -8
- package/lib/NormalModule.js +3 -2242
- package/lib/NullFactory.js +3 -22
- package/lib/ProgressPlugin.js +3 -908
- package/lib/RawModule.js +3 -197
- package/lib/RequestShortener.js +3 -37
- package/lib/SingleEntryPlugin.js +1 -1
- package/lib/WebpackError.js +2 -2
- package/lib/asset/AssetBytesGenerator.js +8 -8
- package/lib/asset/AssetBytesParser.js +3 -3
- package/lib/asset/AssetGenerator.js +36 -22
- package/lib/asset/AssetModule.js +2 -2
- package/lib/asset/AssetModulesPlugin.js +6 -9
- package/lib/asset/AssetParser.js +3 -3
- package/lib/asset/AssetSourceGenerator.js +8 -8
- package/lib/asset/AssetSourceParser.js +3 -3
- package/lib/asset/RawDataUrlModule.js +17 -10
- package/lib/asset/WebManifestGenerator.js +7 -7
- package/lib/asset/WebManifestParser.js +5 -5
- package/lib/async-modules/AsyncModuleHelpers.js +6 -5
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
- package/lib/async-modules/InferAsyncModulesPlugin.js +4 -3
- package/lib/async-modules/isGeneratorLowered.js +3 -3
- package/lib/bun/BunTargetPlugin.js +1 -1
- package/lib/cache/AddBuildDependenciesPlugin.js +2 -19
- package/lib/{Cache.js → cache/Cache.js} +1 -1
- package/lib/{CacheFacade.js → cache/CacheFacade.js} +5 -5
- package/lib/cache/IdleFileCachePlugin.js +2 -2
- package/lib/cache/MemoryCachePlugin.js +2 -2
- package/lib/cache/MemoryWithGcCachePlugin.js +2 -2
- package/lib/cache/PackFileCacheStrategy.js +8 -10
- package/lib/cache/ResolverCachePlugin.js +8 -4
- package/lib/cache/mergeEtags.js +1 -1
- package/lib/{OptionsApply.js → config/OptionsApply.js} +3 -3
- package/lib/{PlatformPlugin.js → config/PlatformPlugin.js} +2 -2
- package/lib/{WebpackOptionsApply.js → config/WebpackOptionsApply.js} +217 -200
- package/lib/{WebpackOptionsDefaulter.js → config/WebpackOptionsDefaulter.js} +3 -3
- package/lib/config/browserslistTargetHandler.js +1 -1
- package/lib/{cli.js → config/cli.js} +5 -158
- package/lib/config/defaults.js +144 -48
- package/lib/config/getClaimedAssetTypes.js +21 -13
- package/lib/config/normalization.js +18 -7
- package/lib/config/target.js +10 -0
- package/lib/container/ContainerEntryDependency.js +1 -1
- package/lib/container/ContainerEntryModule.js +13 -11
- package/lib/container/ContainerEntryModuleFactory.js +2 -2
- package/lib/container/ContainerExposedDependency.js +1 -1
- package/lib/container/ContainerPlugin.js +178 -5
- package/lib/container/ContainerReferencePlugin.js +75 -14
- package/lib/container/FallbackDependency.js +1 -1
- package/lib/container/FallbackItemDependency.js +1 -1
- package/lib/container/FallbackModule.js +12 -10
- package/lib/container/FallbackModuleFactory.js +2 -2
- package/lib/container/HoistContainerReferencesPlugin.js +10 -11
- package/lib/container/ModuleFederationPlugin.js +306 -7
- package/lib/container/RemoteModule.js +14 -10
- package/lib/container/RemoteRuntimeModule.js +5 -5
- package/lib/container/RemoteToExternalDependency.js +1 -1
- package/lib/container/moduleFederationHooks.js +1 -1
- package/lib/context/ContextModule.js +36 -25
- package/lib/context/ContextModuleFactory.js +13 -10
- package/lib/context/ContextReplacementPlugin.js +3 -3
- package/lib/css/CssGenerator.js +38 -31
- package/lib/css/CssInjectStyleRuntimeModule.js +36 -30
- package/lib/css/CssLoadingRuntimeModule.js +77 -44
- package/lib/css/CssModule.js +27 -29
- package/lib/css/CssModulesPlugin.js +128 -44
- package/lib/css/CssParser.js +682 -291
- package/lib/css/CssServerStylesRuntimeModule.js +3 -3
- package/lib/css/cssMinify.js +110 -37
- package/lib/css/data.js +6985 -5125
- package/lib/css/syntax-parser.js +19873 -0
- package/lib/css/syntax-printer.js +6037 -0
- package/lib/css/syntax.js +37 -18686
- package/lib/debug/ProfilingPlugin.js +52 -19
- package/lib/{DefinePlugin.js → define/DefinePlugin.js} +407 -41
- package/lib/{DotenvPlugin.js → define/DotenvPlugin.js} +9 -9
- package/lib/{EnvironmentPlugin.js → define/EnvironmentPlugin.js} +2 -2
- package/lib/deno/DenoTargetPlugin.js +1 -1
- package/lib/dependencies/ConstDependency.js +3 -120
- package/lib/dependencies/ContextElementDependency.js +5 -172
- package/lib/dependencies/NullDependency.js +3 -37
- package/lib/dependencies/{AMDDefineDependency.js → amd/AMDDefineDependency.js} +12 -11
- package/lib/dependencies/{AMDDefineDependencyParserPlugin.js → amd/AMDDefineDependencyParserPlugin.js} +10 -10
- package/lib/dependencies/{AMDPlugin.js → amd/AMDPlugin.js} +11 -11
- package/lib/dependencies/{AMDRequireArrayDependency.js → amd/AMDRequireArrayDependency.js} +15 -13
- package/lib/dependencies/{AMDRequireContextDependency.js → amd/AMDRequireContextDependency.js} +11 -10
- package/lib/dependencies/{AMDRequireDependenciesBlock.js → amd/AMDRequireDependenciesBlock.js} +7 -6
- package/lib/dependencies/{AMDRequireDependenciesBlockParserPlugin.js → amd/AMDRequireDependenciesBlockParserPlugin.js} +10 -10
- package/lib/dependencies/{AMDRequireDependency.js → amd/AMDRequireDependency.js} +13 -12
- package/lib/dependencies/{AMDRequireItemDependency.js → amd/AMDRequireItemDependency.js} +8 -7
- package/lib/dependencies/{AMDRuntimeModules.js → amd/AMDRuntimeModules.js} +3 -3
- package/lib/dependencies/{LocalModule.js → amd/LocalModule.js} +8 -4
- package/lib/dependencies/{LocalModuleDependency.js → amd/LocalModuleDependency.js} +17 -10
- package/lib/dependencies/{LocalModulesHelpers.js → amd/LocalModulesHelpers.js} +1 -1
- package/lib/dependencies/{RequireJsStuffPlugin.js → amd/RequireJsStuffPlugin.js} +9 -9
- package/lib/dependencies/{UnsupportedDependency.js → amd/UnsupportedDependency.js} +11 -10
- package/lib/dependencies/{CommonJsDependencyHelpers.js → commonjs/CommonJsDependencyHelpers.js} +8 -9
- package/lib/dependencies/{CommonJsExportRequireDependency.js → commonjs/CommonJsExportRequireDependency.js} +166 -33
- package/lib/dependencies/{CommonJsExportsDependency.js → commonjs/CommonJsExportsDependency.js} +15 -14
- package/lib/dependencies/{CommonJsExportsParserPlugin.js → commonjs/CommonJsExportsParserPlugin.js} +138 -61
- package/lib/dependencies/{CommonJsFullRequireDependency.js → commonjs/CommonJsFullRequireDependency.js} +32 -24
- package/lib/dependencies/{CommonJsImportsParserPlugin.js → commonjs/CommonJsImportsParserPlugin.js} +35 -30
- package/lib/dependencies/{CommonJsObjectExportDependency.js → commonjs/CommonJsObjectExportDependency.js} +13 -12
- package/lib/dependencies/{CommonJsPlugin.js → commonjs/CommonJsPlugin.js} +47 -35
- package/lib/dependencies/{CommonJsRequireContextDependency.js → commonjs/CommonJsRequireContextDependency.js} +15 -14
- package/lib/dependencies/{CommonJsRequireDependency.js → commonjs/CommonJsRequireDependency.js} +33 -25
- package/lib/dependencies/{CommonJsSelfReferenceDependency.js → commonjs/CommonJsSelfReferenceDependency.js} +17 -16
- package/lib/dependencies/{ModuleDecoratorDependency.js → commonjs/ModuleDecoratorDependency.js} +16 -15
- package/lib/dependencies/{RequireEnsureDependenciesBlock.js → commonjs/RequireEnsureDependenciesBlock.js} +8 -7
- package/lib/dependencies/{RequireEnsureDependenciesBlockParserPlugin.js → commonjs/RequireEnsureDependenciesBlockParserPlugin.js} +5 -5
- package/lib/dependencies/{RequireEnsureDependency.js → commonjs/RequireEnsureDependency.js} +13 -12
- package/lib/dependencies/{RequireEnsureItemDependency.js → commonjs/RequireEnsureItemDependency.js} +7 -6
- package/lib/dependencies/{RequireEnsurePlugin.js → commonjs/RequireEnsurePlugin.js} +8 -8
- package/lib/dependencies/{RequireHeaderDependency.js → commonjs/RequireHeaderDependency.js} +14 -13
- package/lib/dependencies/{RequireIncludeDependency.js → commonjs/RequireIncludeDependency.js} +13 -12
- package/lib/dependencies/{RequireIncludeDependencyParserPlugin.js → commonjs/RequireIncludeDependencyParserPlugin.js} +3 -27
- package/lib/dependencies/{RequireIncludePlugin.js → commonjs/RequireIncludePlugin.js} +4 -4
- package/lib/dependencies/{RequireResolveContextDependency.js → commonjs/RequireResolveContextDependency.js} +11 -10
- package/lib/dependencies/{RequireResolveDependency.js → commonjs/RequireResolveDependency.js} +12 -11
- package/lib/dependencies/{RequireResolveHeaderDependency.js → commonjs/RequireResolveHeaderDependency.js} +13 -12
- package/lib/dependencies/commonjs/TopLevelThisParserPlugin.js +59 -0
- package/lib/dependencies/{ContextDependency.js → context/ContextDependency.js} +15 -14
- package/lib/dependencies/{ContextDependencyHelpers.js → context/ContextDependencyHelpers.js} +31 -9
- package/lib/dependencies/{ContextDependencyTemplateAsId.js → context/ContextDependencyTemplateAsId.js} +3 -3
- package/lib/dependencies/{ContextDependencyTemplateAsRequireCall.js → context/ContextDependencyTemplateAsRequireCall.js} +3 -3
- package/lib/dependencies/context/ContextElementDependency.js +198 -0
- package/lib/dependencies/{ImportMetaContextDependency.js → context/ImportMetaContextDependency.js} +7 -6
- package/lib/dependencies/{ImportMetaContextDependencyParserPlugin.js → context/ImportMetaContextDependencyParserPlugin.js} +9 -9
- package/lib/dependencies/{ImportMetaContextPlugin.js → context/ImportMetaContextPlugin.js} +5 -5
- package/lib/dependencies/{ImportMetaGlobDependency.js → context/ImportMetaGlobDependency.js} +7 -6
- package/lib/dependencies/{ImportMetaGlobDependencyParserPlugin.js → context/ImportMetaGlobDependencyParserPlugin.js} +4 -4
- package/lib/dependencies/{ImportMetaGlobHelpers.js → context/ImportMetaGlobHelpers.js} +9 -9
- package/lib/dependencies/{RequireContextDependency.js → context/RequireContextDependency.js} +7 -6
- package/lib/dependencies/{RequireContextDependencyParserPlugin.js → context/RequireContextDependencyParserPlugin.js} +2 -2
- package/lib/dependencies/{RequireContextPlugin.js → context/RequireContextPlugin.js} +5 -5
- package/lib/dependencies/{CachedConstDependency.js → core/CachedConstDependency.js} +12 -11
- package/lib/dependencies/core/ConstDependency.js +131 -0
- package/lib/dependencies/{ImportPhase.js → core/ImportPhase.js} +5 -4
- package/lib/dependencies/{ModuleDependency.js → core/ModuleDependency.js} +10 -7
- package/lib/dependencies/{ModuleDependencyTemplateAsId.js → core/ModuleDependencyTemplateAsId.js} +3 -3
- package/lib/dependencies/{ModuleDependencyTemplateAsRequireId.js → core/ModuleDependencyTemplateAsRequireId.js} +2 -2
- package/lib/dependencies/{ModuleInitFragmentDependency.js → core/ModuleInitFragmentDependency.js} +10 -9
- package/lib/dependencies/core/NullDependency.js +44 -0
- package/lib/dependencies/{RuntimeRequirementsDependency.js → core/RuntimeRequirementsDependency.js} +10 -9
- package/lib/dependencies/{StaticExportsDependency.js → core/StaticExportsDependency.js} +15 -8
- package/lib/dependencies/{CssIcssExportDependency.js → css/CssIcssExportDependency.js} +369 -92
- package/lib/dependencies/{CssIcssImportDependency.js → css/CssIcssImportDependency.js} +23 -16
- package/lib/dependencies/{CssIcssSymbolDependency.js → css/CssIcssSymbolDependency.js} +13 -12
- package/lib/dependencies/{CssImportDependency.js → css/CssImportDependency.js} +15 -11
- package/lib/dependencies/{CssUrlDependency.js → css/CssUrlDependency.js} +23 -16
- package/lib/dependencies/{CreateRequireParserPlugin.js → esm/CreateRequireParserPlugin.js} +9 -9
- package/lib/dependencies/{HarmonyAcceptDependency.js → esm/ESMAcceptDependency.js} +41 -38
- package/lib/dependencies/esm/ESMAcceptImportDependency.js +39 -0
- package/lib/dependencies/{HarmonyCompatibilityDependency.js → esm/ESMCompatibilityDependency.js} +29 -21
- package/lib/dependencies/{HarmonyDetectionParserPlugin.js → esm/ESMDetectionParserPlugin.js} +19 -17
- package/lib/dependencies/{HarmonyEvaluatedImportSpecifierDependency.js → esm/ESMEvaluatedImportSpecifierDependency.js} +33 -30
- package/lib/dependencies/{HarmonyExportDependencyParserPlugin.js → esm/ESMExportDependencyParserPlugin.js} +60 -89
- package/lib/dependencies/{HarmonyExportExpressionDependency.js → esm/ESMExportExpressionDependency.js} +80 -45
- package/lib/dependencies/{HarmonyExportHeaderDependency.js → esm/ESMExportHeaderDependency.js} +17 -15
- package/lib/dependencies/esm/ESMExportImportedSideEffectDependency.js +37 -0
- package/lib/dependencies/{HarmonyExportImportedSpecifierDependency.js → esm/ESMExportImportedSpecifierDependency.js} +133 -118
- package/lib/dependencies/{HarmonyExportInitFragment.js → esm/ESMExportInitFragment.js} +48 -30
- package/lib/dependencies/{HarmonyExportSpecifierDependency.js → esm/ESMExportSpecifierDependency.js} +60 -36
- package/lib/dependencies/{HarmonyExports.js → esm/ESMExports.js} +4 -4
- package/lib/dependencies/{HarmonyImportBareSideEffectDependency.js → esm/ESMImportBareSideEffectDependency.js} +21 -13
- package/lib/dependencies/{HarmonyImportDependency.js → esm/ESMImportDependency.js} +74 -71
- package/lib/dependencies/{HarmonyImportDependencyParserPlugin.js → esm/ESMImportDependencyParserPlugin.js} +99 -84
- package/lib/dependencies/{HarmonyImportGuard.js → esm/ESMImportGuard.js} +26 -29
- package/lib/dependencies/{HarmonyImportSideEffectDependency.js → esm/ESMImportSideEffectDependency.js} +83 -39
- package/lib/dependencies/{HarmonyImportSpecifierDependency.js → esm/ESMImportSpecifierDependency.js} +94 -59
- package/lib/dependencies/esm/ESMModulesPlugin.js +207 -0
- package/lib/dependencies/{HarmonyTopLevelThisParserPlugin.js → esm/ESMTopLevelThisParserPlugin.js} +7 -7
- package/lib/dependencies/{TopLevelAwaitDependency.js → esm/TopLevelAwaitDependency.js} +12 -11
- package/lib/dependencies/{DynamicExports.js → helpers/DynamicExports.js} +2 -2
- package/lib/{util → dependencies/helpers}/chainedImports.js +5 -5
- package/lib/dependencies/{processExportInfo.js → helpers/processExportInfo.js} +4 -4
- package/lib/{util → dependencies/helpers}/traverseDestructuringAssignmentProperties.js +1 -1
- package/lib/dependencies/{ImportMetaHotAcceptDependency.js → hmr/ImportMetaHotAcceptDependency.js} +8 -7
- package/lib/dependencies/{ImportMetaHotDeclineDependency.js → hmr/ImportMetaHotDeclineDependency.js} +8 -7
- package/lib/dependencies/{ModuleHotAcceptDependency.js → hmr/ModuleHotAcceptDependency.js} +8 -7
- package/lib/dependencies/{ModuleHotDeclineDependency.js → hmr/ModuleHotDeclineDependency.js} +8 -7
- package/lib/dependencies/{HtmlEntryDependency.js → html/HtmlEntryDependency.js} +51 -141
- package/lib/dependencies/{HtmlInlineHtmlDependency.js → html/HtmlInlineHtmlDependency.js} +13 -12
- package/lib/dependencies/{HtmlInlineScriptDependency.js → html/HtmlInlineScriptDependency.js} +69 -19
- package/lib/dependencies/{HtmlInlineStyleDependency.js → html/HtmlInlineStyleDependency.js} +50 -15
- package/lib/dependencies/{HtmlSourceDependency.js → html/HtmlSourceDependency.js} +23 -16
- package/lib/dependencies/{ImportContextDependency.js → import/ImportContextDependency.js} +24 -10
- package/lib/dependencies/{ImportDependency.js → import/ImportDependency.js} +26 -18
- package/lib/dependencies/{ImportEagerDependency.js → import/ImportEagerDependency.js} +18 -10
- package/lib/dependencies/{ImportParserPlugin.js → import/ImportParserPlugin.js} +20 -20
- package/lib/dependencies/{ImportPlugin.js → import/ImportPlugin.js} +4 -4
- package/lib/dependencies/{ImportWeakDependency.js → import/ImportWeakDependency.js} +18 -10
- package/lib/dependencies/{importOptionsCheck.js → import/importOptionsCheck.js} +2 -2
- package/lib/dependencies/{BuildTimeConstDependency.js → import-meta/BuildTimeConstDependency.js} +12 -11
- package/lib/dependencies/{ImportMetaMainDependency.js → import-meta/ImportMetaMainDependency.js} +12 -11
- package/lib/dependencies/{ImportMetaPlugin.js → import-meta/ImportMetaPlugin.js} +119 -98
- package/lib/dependencies/{SystemPlugin.js → system/SystemPlugin.js} +11 -38
- package/lib/dependencies/{SystemRuntimeModule.js → system/SystemRuntimeModule.js} +3 -3
- package/lib/dependencies/{ImportMetaResolveDependency.js → url/ImportMetaResolveDependency.js} +9 -8
- package/lib/dependencies/{URLContextDependency.js → url/URLContextDependency.js} +11 -10
- package/lib/dependencies/{URLDependency.js → url/URLDependency.js} +28 -20
- package/lib/{url → dependencies/url}/URLParserPlugin.js +16 -18
- package/lib/dependencies/{URLPlugin.js → url/URLPlugin.js} +6 -7
- package/lib/dependencies/{WebAssemblyExportImportedDependency.js → wasm/WebAssemblyExportImportedDependency.js} +18 -11
- package/lib/dependencies/{WebAssemblyImportDependency.js → wasm/WebAssemblyImportDependency.js} +19 -12
- package/lib/dependencies/{CreateScriptUrlDependency.js → worker/CreateScriptUrlDependency.js} +12 -11
- package/lib/dependencies/{WorkerAndWorkletPlugin.js → worker/WorkerAndWorkletPlugin.js} +31 -33
- package/lib/dependencies/{WorkerDependency.js → worker/WorkerDependency.js} +22 -15
- package/lib/dependencies/{WorkletDependency.js → worker/WorkletDependency.js} +19 -18
- package/lib/{EvalDevToolModulePlugin.js → devtool/EvalDevToolModulePlugin.js} +20 -6
- package/lib/{EvalSourceMapDevToolPlugin.js → devtool/EvalSourceMapDevToolPlugin.js} +32 -24
- package/lib/devtool/ModuleFilenameHelpers.js +413 -0
- package/lib/{SourceMapDevToolModuleOptionsPlugin.js → devtool/SourceMapDevToolModuleOptionsPlugin.js} +10 -3
- package/lib/{SourceMapDevToolPlugin.js → devtool/SourceMapDevToolPlugin.js} +154 -26
- package/lib/{util → devtool}/generateDebugId.js +1 -1
- package/lib/{IgnoreWarningsPlugin.js → diagnostics/IgnoreWarningsPlugin.js} +2 -2
- package/lib/{NoEmitOnErrorsPlugin.js → diagnostics/NoEmitOnErrorsPlugin.js} +1 -1
- package/lib/diagnostics/WarnCaseSensitiveModulesPlugin.js +64 -0
- package/lib/{WarnDeprecatedOptionPlugin.js → diagnostics/WarnDeprecatedOptionPlugin.js} +2 -22
- package/lib/diagnostics/WarnNoModeSetPlugin.js +27 -0
- package/lib/dll/DelegatedModule.js +20 -18
- package/lib/dll/DelegatedModuleFactoryPlugin.js +2 -2
- package/lib/dll/DelegatedPlugin.js +1 -1
- package/lib/{dependencies → dll}/DelegatedSourceDependency.js +5 -4
- package/lib/{dependencies → dll}/DllEntryDependency.js +6 -5
- package/lib/dll/DllEntryPlugin.js +3 -3
- package/lib/dll/DllModule.js +11 -9
- package/lib/dll/DllModuleFactory.js +3 -3
- package/lib/dll/DllPlugin.js +18 -6
- package/lib/dll/DllReferencePlugin.js +102 -26
- package/lib/dll/LibManifestPlugin.js +9 -7
- package/lib/electron/ElectronTargetPlugin.js +2 -2
- package/lib/{DynamicEntryPlugin.js → entry/DynamicEntryPlugin.js} +3 -3
- package/lib/{dependencies → entry}/EntryDependency.js +11 -2
- package/lib/{EntryOptionPlugin.js → entry/EntryOptionPlugin.js} +6 -6
- package/lib/entry/EntryPlugin.js +75 -0
- package/lib/{performance → errors}/AssetsOverSizeLimitWarning.js +2 -2
- package/lib/errors/AsyncDependencyToInitialChunkError.js +2 -2
- package/lib/errors/BuildCycleError.js +1 -1
- package/lib/{WarnCaseSensitiveModulesPlugin.js → errors/CaseSensitiveModulesWarning.js} +4 -56
- package/lib/errors/ChunkRenderError.js +1 -1
- package/lib/errors/CodeGenerationError.js +1 -1
- package/lib/errors/CommentCompilationWarning.js +1 -1
- package/lib/errors/ConflictingEntryExportsWarning.js +38 -0
- package/lib/{dependencies → errors}/CriticalDependencyWarning.js +4 -3
- package/lib/errors/DeprecatedOptionWarning.js +30 -0
- package/lib/errors/DllManifestError.js +26 -0
- package/lib/{performance → errors}/DuplicatePackagesWarning.js +6 -6
- package/lib/{dependencies/HarmonyLinkingError.js → errors/ESMLinkingError.js} +4 -4
- package/lib/{performance → errors}/EntrypointsOverSizeLimitWarning.js +2 -2
- package/lib/errors/EnvironmentNotSupportAsyncWarning.js +2 -2
- package/lib/{ErrorHelpers.js → errors/ErrorHelpers.js} +7 -5
- package/lib/errors/ExternalStarReexportError.js +2 -2
- package/lib/{library → errors}/FalseIIFEUmdWarning.js +1 -1
- package/lib/errors/HookWebpackError.js +4 -4
- package/lib/errors/IgnoreErrorModuleFactory.js +3 -3
- package/lib/errors/InvalidDependenciesModuleWarning.js +1 -1
- package/lib/{optimize → errors}/MinMaxSizeWarning.js +1 -1
- package/lib/errors/ModuleBuildError.js +1 -1
- package/lib/errors/ModuleDependencyError.js +2 -2
- package/lib/errors/ModuleDependencyWarning.js +2 -2
- package/lib/errors/ModuleError.js +1 -1
- package/lib/errors/ModuleHashingError.js +1 -1
- package/lib/errors/ModuleNotFoundError.js +3 -3
- package/lib/errors/ModuleParseError.js +1 -1
- package/lib/errors/ModuleRestoreError.js +1 -1
- package/lib/errors/ModuleStoreError.js +1 -1
- package/lib/errors/ModuleWarning.js +1 -1
- package/lib/{performance → errors}/NoAsyncChunksWarning.js +1 -1
- package/lib/{WarnNoModeSetPlugin.js → errors/NoModeWarning.js} +2 -19
- package/lib/errors/NodeStuffInWebError.js +7 -2
- package/lib/errors/PathVariableError.js +31 -0
- package/lib/errors/RequireIncludeDeprecationWarning.js +40 -0
- package/lib/{performance → errors}/RuntimeInLargeChunkWarning.js +1 -1
- package/lib/errors/RuntimeModuleGenerationError.js +51 -0
- package/lib/errors/SSRManifestAutoPublicPathWarning.js +24 -0
- package/lib/errors/SystemImportDeprecationWarning.js +43 -0
- package/lib/errors/UnmergeableEntryExportsError.js +34 -0
- package/lib/errors/UnsupportedFeatureWarning.js +1 -1
- package/lib/{wasm-sync → errors}/UnsupportedWebAssemblyFeatureError.js +1 -1
- package/lib/{wasm-sync → errors}/WebAssemblyInInitialChunkError.js +7 -5
- package/lib/errors/WebpackError.js +12 -3
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -2
- package/lib/esm/ModuleChunkFormatPlugin.js +19 -19
- package/lib/esm/ModuleChunkLoadingPlugin.js +3 -3
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +8 -8
- package/lib/{ExternalModule.js → externals/ExternalModule.js} +79 -55
- package/lib/{ExternalModuleFactoryPlugin.js → externals/ExternalModuleFactoryPlugin.js} +41 -39
- package/lib/externals/ExternalsPlugin.js +99 -0
- package/lib/fs/FileSystemInfo.js +4642 -0
- package/lib/{util → fs}/fs.js +22 -9
- package/lib/{AsyncDependenciesBlock.js → graph/AsyncDependenciesBlock.js} +27 -4
- package/lib/graph/Chunk.js +985 -0
- package/lib/{ChunkGraph.js → graph/ChunkGraph.js} +187 -80
- package/lib/{ChunkGroup.js → graph/ChunkGroup.js} +11 -3
- package/lib/{DependenciesBlock.js → graph/DependenciesBlock.js} +16 -4
- package/lib/graph/Dependency.js +628 -0
- package/lib/graph/Entrypoint.js +136 -0
- package/lib/{ExportsInfo.js → graph/ExportsInfo.js} +130 -82
- package/lib/{HotUpdateChunk.js → graph/HotUpdateChunk.js} +8 -0
- package/lib/{ModuleGraph.js → graph/ModuleGraph.js} +30 -30
- package/lib/{ModuleGraphConnection.js → graph/ModuleGraphConnection.js} +2 -2
- package/lib/{buildChunkGraph.js → graph/buildChunkGraph.js} +152 -57
- package/lib/{util → graph}/findGraphRoots.js +14 -8
- package/lib/graph/isDependencyKind.js +23 -0
- package/lib/hmr/HotModuleReplacement.runtime.js +2 -2
- package/lib/{HotModuleReplacementPlugin.js → hmr/HotModuleReplacementPlugin.js} +47 -47
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +3 -3
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +10 -8
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +2 -2
- package/lib/hmr/LazyCompilationPlugin.js +31 -21
- package/lib/html/HtmlGenerator.js +107 -43
- package/lib/html/HtmlModule.js +6 -2
- package/lib/html/HtmlModulesPlugin.js +172 -76
- package/lib/html/HtmlParser.js +503 -153
- package/lib/html/builtinEmbeddedRenderer.js +60 -13
- package/lib/html/data.js +2 -1
- package/lib/html/htmlMinify.js +111 -41
- package/lib/html/syntax-parser.js +15796 -0
- package/lib/html/syntax-printer.js +1034 -0
- package/lib/html/syntax.js +37 -13952
- package/lib/html/xmlMinify.js +67 -0
- package/lib/ids/ChunkModuleIdRangePlugin.js +2 -2
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +31 -4
- package/lib/ids/IdHelpers.js +4 -4
- package/lib/ids/NaturalChunkIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -5
- package/lib/ids/OccurrenceModuleIdsPlugin.js +6 -5
- package/lib/{RecordIdsPlugin.js → ids/RecordIdsPlugin.js} +5 -5
- package/lib/ids/SyncModuleIdsPlugin.js +3 -3
- package/lib/{util → ids}/numberHash.js +1 -1
- package/lib/index.js +303 -97
- package/lib/{APIPlugin.js → javascript/APIPlugin.js} +25 -25
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -5
- package/lib/javascript/BasicEvaluatedExpression.js +4 -4
- package/lib/javascript/ChunkHelpers.js +64 -4
- package/lib/javascript/CommonJsChunkFormatPlugin.js +4 -7
- package/lib/{CompatibilityPlugin.js → javascript/CompatibilityPlugin.js} +7 -7
- package/lib/{ConstPlugin.js → javascript/ConstPlugin.js} +74 -7
- package/lib/{ExportsInfoApiPlugin.js → javascript/ExportsInfoApiPlugin.js} +5 -5
- package/lib/{dependencies → javascript}/ExportsInfoDependency.js +10 -9
- package/lib/javascript/JavascriptGenerator.js +17 -17
- package/lib/{JavascriptMetaInfoPlugin.js → javascript/JavascriptMetaInfoPlugin.js} +7 -7
- package/lib/javascript/JavascriptModule.js +4 -3
- package/lib/javascript/JavascriptModulesPlugin.js +440 -211
- package/lib/javascript/JavascriptParser.js +220 -134
- package/lib/javascript/JavascriptParserHelpers.js +1 -1
- package/lib/javascript/MergedEntryExports.js +196 -0
- package/lib/javascript/ScopeAnalyzer.js +3840 -5
- package/lib/javascript/StartupHelpers.js +6 -6
- package/lib/{UseStrictPlugin.js → javascript/UseStrictPlugin.js} +12 -15
- package/lib/{dependencies → javascript}/WebpackIsIncludedDependency.js +10 -9
- package/lib/{WebpackIsIncludedPlugin.js → javascript/WebpackIsIncludedPlugin.js} +8 -8
- package/lib/javascript/data.js +533 -122
- package/lib/javascript/jsMinify.js +272 -0
- package/lib/javascript/regexp.js +67 -32
- package/lib/javascript/syntax-parser.js +18561 -0
- package/lib/javascript/syntax-printer-data.js +933 -0
- package/lib/javascript/syntax-printer.js +47106 -0
- package/lib/javascript/syntax.js +20 -11274
- package/lib/json/JsonData.js +1 -1
- package/lib/{dependencies → json}/JsonExportsDependency.js +8 -7
- package/lib/json/JsonGenerator.js +10 -10
- package/lib/json/JsonModule.js +2 -2
- package/lib/json/JsonModulesPlugin.js +1 -1
- package/lib/json/JsonParser.js +5 -5
- package/lib/json/jsonMinify.js +69 -0
- package/lib/library/AbstractLibraryPlugin.js +28 -15
- package/lib/library/AmdLibraryPlugin.js +4 -4
- package/lib/library/AssignLibraryPlugin.js +27 -11
- package/lib/library/EnableLibraryPlugin.js +1 -1
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -4
- package/lib/library/JsonpLibraryPlugin.js +1 -1
- package/lib/library/LibraryTemplatePlugin.js +53 -0
- package/lib/library/ModuleLibraryPlugin.js +160 -166
- package/lib/library/SystemLibraryPlugin.js +6 -8
- package/lib/library/UmdLibraryPlugin.js +3 -4
- package/lib/{dependencies → loaders}/LoaderDependency.js +3 -3
- package/lib/{dependencies → loaders}/LoaderImportDependency.js +9 -3
- package/lib/{LoaderOptionsPlugin.js → loaders/LoaderOptionsPlugin.js} +30 -12
- package/lib/{dependencies → loaders}/LoaderPlugin.js +2 -2
- package/lib/loaders/LoaderRunner.js +31 -21
- package/lib/{LoaderTargetPlugin.js → loaders/LoaderTargetPlugin.js} +2 -2
- package/lib/logging/Logger.js +7 -9
- package/lib/logging/ProgressPlugin.js +957 -0
- package/lib/{CodeGenerationResults.js → module/CodeGenerationResults.js} +7 -7
- package/lib/{Generator.js → module/Generator.js} +16 -14
- package/lib/{Module.js → module/Module.js} +119 -51
- package/lib/{ModuleFactory.js → module/ModuleFactory.js} +3 -3
- package/lib/module/NormalModule.js +2348 -0
- package/lib/{NormalModuleFactory.js → module/NormalModuleFactory.js} +53 -54
- package/lib/module/NullFactory.js +29 -0
- package/lib/{Parser.js → module/Parser.js} +3 -3
- package/lib/module/RawModule.js +208 -0
- package/lib/{SelfModuleFactory.js → module/SelfModuleFactory.js} +1 -1
- package/lib/{util → module}/extractSourceMap.js +2 -2
- package/lib/{util → module}/findCaseMismatch.js +2 -2
- package/lib/node/CommonJsChunkLoadingPlugin.js +3 -3
- package/lib/{dependencies → node}/ExternalModuleDependency.js +8 -7
- package/lib/{dependencies → node}/ExternalModuleInitFragment.js +6 -5
- package/lib/{dependencies → node}/ExternalModuleInitFragmentDependency.js +14 -9
- package/lib/node/NodeEnvironmentPlugin.js +11 -1
- package/lib/{NodeStuffPlugin.js → node/NodeStuffPlugin.js} +17 -17
- package/lib/node/NodeTargetPlugin.js +1 -1
- package/lib/node/NodeWatchFileSystem.js +58 -6
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +7 -7
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +9 -7
- package/lib/node/ReadFileCompileWasmPlugin.js +7 -5
- package/lib/node/RequireChunkLoadingRuntimeModule.js +7 -7
- package/lib/node/nodeConsole.js +2 -4
- package/lib/optimize/AggressiveMergingPlugin.js +2 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +12 -8
- package/lib/{CircularModulesPlugin.js → optimize/CircularModulesPlugin.js} +13 -13
- package/lib/optimize/ConcatenatedModule.js +229 -214
- package/lib/{ConcatenationScope.js → optimize/ConcatenationScope.js} +39 -6
- package/lib/optimize/ConstExportsPlugin.js +7 -7
- package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -3
- package/lib/{FlagAllModulesAsUsedPlugin.js → optimize/FlagAllModulesAsUsedPlugin.js} +3 -3
- package/lib/{FlagDependencyExportsPlugin.js → optimize/FlagDependencyExportsPlugin.js} +17 -17
- package/lib/{FlagDependencyUsagePlugin.js → optimize/FlagDependencyUsagePlugin.js} +17 -17
- package/lib/{FlagEntryExportAsUsedPlugin.js → optimize/FlagEntryExportAsUsedPlugin.js} +2 -2
- package/lib/optimize/FlagIncludedChunksPlugin.js +2 -2
- package/lib/optimize/InlineExports.js +11 -3
- package/lib/optimize/InnerGraph.js +5 -13
- package/lib/optimize/InnerGraphPlugin.js +10 -10
- package/lib/optimize/LazyBarrels.js +584 -0
- package/lib/{util → optimize}/LazyBucketSortedSet.js +2 -2
- package/lib/optimize/LimitChunkCountPlugin.js +16 -7
- package/lib/optimize/MangleExportsPlugin.js +5 -5
- package/lib/optimize/MergeDuplicateChunksPlugin.js +7 -6
- package/lib/optimize/MinChunkSizePlugin.js +9 -6
- package/lib/optimize/ModuleConcatenationPlugin.js +20 -12
- package/lib/{dependencies → optimize}/PureExpressionDependency.js +11 -10
- package/lib/optimize/RealContentHashPlugin.js +16 -7
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +4 -4
- package/lib/optimize/SideEffectsFlagPlugin.js +18 -18
- package/lib/optimize/SplitChunksPlugin.js +713 -155
- package/lib/{util → optimize}/TupleQueue.js +9 -9
- package/lib/optimize/chunkSetIntersections.js +437 -0
- package/lib/{util → optimize}/deterministicGrouping.js +17 -17
- package/lib/{BannerPlugin.js → output/BannerPlugin.js} +82 -14
- package/lib/{CleanPlugin.js → output/CleanPlugin.js} +66 -24
- package/lib/{CopyPlugin.js → output/CopyPlugin.js} +142 -67
- package/lib/{ManifestPlugin.js → output/ManifestPlugin.js} +91 -17
- package/lib/output/SSRManifestPlugin.js +349 -0
- package/lib/performance/AnalyzableBailoutsPlugin.js +1 -1
- package/lib/performance/AsyncChunkWaterfallsPlugin.js +1 -1
- package/lib/performance/BroadContextsPlugin.js +4 -4
- package/lib/performance/CacheEffectivenessPlugin.js +2 -3
- package/lib/performance/ConflictingResourceHintsPlugin.js +1 -1
- package/lib/performance/DuplicateModulesPlugin.js +3 -4
- package/lib/performance/DuplicatePackagesPlugin.js +3 -3
- package/lib/performance/DynamicExportsPlugin.js +2 -2
- package/lib/performance/EvalUsagePlugin.js +3 -3
- package/lib/performance/HotspotsPlugin.js +11 -10
- package/lib/performance/LargeModulesPlugin.js +2 -3
- package/lib/performance/LegacyJavascriptPlugin.js +1 -2
- package/lib/performance/MissingSideEffectsPlugin.js +2 -3
- package/lib/performance/MissingSourceMapsPlugin.js +5 -6
- package/lib/performance/PureAnnotationsPlugin.js +3 -3
- package/lib/performance/RedundantDynamicImportsPlugin.js +6 -8
- package/lib/performance/ScopeHoistingBailoutsPlugin.js +2 -2
- package/lib/performance/SizeLimitsPlugin.js +11 -12
- package/lib/performance/TopLevelThisPlugin.js +8 -7
- package/lib/performance/UnsplitVendorsPlugin.js +1 -2
- package/lib/performance/UnusedAliasesPlugin.js +6 -7
- package/lib/performance/UnusedAssetsPlugin.js +5 -5
- package/lib/performance/UnusedDefinesPlugin.js +2 -2
- package/lib/performance/UnusedExternalsPlugin.js +3 -4
- package/lib/performance/UnusedFederationPlugin.js +2 -4
- package/lib/performance/UnusedModulesPlugin.js +5 -4
- package/lib/performance/getModuleSize.js +1 -1
- package/lib/performance/hasOnlyUnusedExports.js +4 -4
- package/lib/performance/isOnlyReexported.js +7 -6
- package/lib/{AutomaticPrefetchPlugin.js → prefetch/AutomaticPrefetchPlugin.js} +4 -5
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +2 -2
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +1 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +4 -4
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -4
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -4
- package/lib/{dependencies → prefetch}/PrefetchDependency.js +1 -1
- package/lib/{PrefetchPlugin.js → prefetch/PrefetchPlugin.js} +2 -2
- package/lib/prefetch/ResourceHintPlugin.js +65 -44
- package/lib/prefetch/ResourceHintRuntimeModule.js +3 -3
- package/lib/prefetch/StartupAssetHintRuntimeModule.js +3 -3
- package/lib/prefetch/parseResourceHintOptions.js +4 -3
- package/lib/{ProvidePlugin.js → provide/ProvidePlugin.js} +7 -7
- package/lib/{dependencies → provide}/ProvidedDependency.js +14 -13
- package/lib/{IgnorePlugin.js → resolve/IgnorePlugin.js} +30 -13
- package/lib/{NormalModuleReplacementPlugin.js → resolve/NormalModuleReplacementPlugin.js} +4 -4
- package/lib/{ResolverFactory.js → resolve/ResolverFactory.js} +18 -5
- package/lib/resolve/getResolveOptionsKey.js +59 -0
- package/lib/rules/RuleSetCompiler.js +27 -46
- package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +2 -2
- package/lib/runtime/AsyncModuleRuntimeModule.js +7 -4
- package/lib/runtime/AutoPublicPathRuntimeModule.js +5 -5
- package/lib/runtime/BaseUriRuntimeModule.js +3 -3
- package/lib/runtime/ChunkNameRuntimeModule.js +2 -2
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +2 -2
- package/lib/runtime/CompatRuntimeModule.js +4 -4
- package/lib/runtime/ConcatenationWrapRuntimeModule.js +2 -2
- package/lib/runtime/ConstructRequireRuntimeModule.js +2 -2
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +2 -2
- package/lib/runtime/CreateScriptRuntimeModule.js +2 -2
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +2 -2
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +6 -6
- package/lib/runtime/EnsureChunkRuntimeModule.js +4 -4
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -6
- package/lib/runtime/GetFullHashRuntimeModule.js +2 -2
- package/lib/runtime/GetMainFilenameRuntimeModule.js +4 -4
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +3 -3
- package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +3 -3
- package/lib/runtime/GlobalRuntimeModule.js +3 -3
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +3 -3
- package/lib/runtime/HelperRuntimeModule.js +16 -1
- package/lib/runtime/LoadScriptRuntimeModule.js +3 -3
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +80 -17
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +2 -2
- package/lib/runtime/NonceRuntimeModule.js +2 -2
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
- package/lib/runtime/PublicPathRuntimeModule.js +2 -2
- package/lib/runtime/RelativeUrlRuntimeModule.js +2 -2
- package/lib/{RuntimeGlobals.js → runtime/RuntimeGlobals.js} +18 -1
- package/lib/runtime/RuntimeIdRuntimeModule.js +4 -4
- package/lib/{RuntimeModule.js → runtime/RuntimeModule.js} +36 -21
- package/lib/{RuntimePlugin.js → runtime/RuntimePlugin.js} +48 -50
- package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +2 -2
- package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +2 -2
- package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +5 -5
- package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -3
- package/lib/runtime/SystemContextRuntimeModule.js +2 -2
- package/lib/runtime/ToBinaryRuntimeModule.js +3 -3
- package/lib/runtime/WorkerRuntimeModule.js +1 -1
- package/lib/runtime/baseUri.js +1 -1
- package/lib/schemes/DataUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +67 -11
- package/lib/schemes/VirtualUrlPlugin.js +50 -16
- package/lib/serialization/AggregateErrorSerializer.js +2 -2
- package/lib/serialization/FileMiddleware.js +3 -3
- package/lib/serialization/ObjectMiddleware.js +47 -16
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/serialization/SingleItemMiddleware.js +4 -2
- package/lib/sharing/ConsumeSharedFallbackDependency.js +9 -1
- package/lib/sharing/ConsumeSharedModule.js +18 -14
- package/lib/sharing/ConsumeSharedPlugin.js +148 -42
- package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -8
- package/lib/sharing/ProvideForSharedDependency.js +9 -1
- package/lib/sharing/ProvideSharedDependency.js +1 -1
- package/lib/sharing/ProvideSharedModule.js +11 -9
- package/lib/sharing/ProvideSharedModuleFactory.js +2 -2
- package/lib/sharing/ProvideSharedPlugin.js +111 -20
- package/lib/sharing/SharePlugin.js +102 -9
- package/lib/sharing/ShareRuntimeModule.js +6 -6
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/{util → sharing}/semver.js +14 -16
- package/lib/sharing/utils.js +59 -2
- package/lib/stats/DefaultStatsFactoryPlugin.js +22 -19
- package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
- package/lib/stats/DefaultStatsPrinterPlugin.js +3 -3
- package/lib/{MultiStats.js → stats/MultiStats.js} +4 -4
- package/lib/{Stats.js → stats/Stats.js} +4 -4
- package/lib/stats/StatsFactory.js +14 -13
- package/lib/{ChunkTemplate.js → template/ChunkTemplate.js} +7 -7
- package/lib/{ConditionalInitFragment.js → template/ConditionalInitFragment.js} +3 -3
- package/lib/template/DependencyTemplate.js +77 -0
- package/lib/{DependencyTemplates.js → template/DependencyTemplates.js} +9 -4
- package/lib/template/InitFragment.js +223 -0
- package/lib/{MainTemplate.js → template/MainTemplate.js} +11 -11
- package/lib/{ModuleInfoHeaderPlugin.js → template/ModuleInfoHeaderPlugin.js} +30 -8
- package/lib/{ModuleTemplate.js → template/ModuleTemplate.js} +6 -6
- package/lib/{RuntimeTemplate.js → template/RuntimeTemplate.js} +145 -63
- package/lib/{Template.js → template/Template.js} +13 -11
- package/lib/{TemplatedPathPlugin.js → template/TemplatedPathPlugin.js} +19 -23
- package/lib/typescript/TypeScriptPlugin.js +3 -3
- package/lib/util/RequestShortener.js +44 -0
- package/lib/util/SortableSet.js +87 -22
- package/lib/util/SourceProcessor.js +349 -44
- package/lib/util/TupleSet.js +27 -27
- package/lib/util/WeakTupleMap.js +10 -12
- package/lib/util/buildDiagnostics.js +2 -2
- package/lib/util/comparators.js +10 -10
- package/lib/util/concatenate.js +28 -147
- package/lib/util/createMappings.js +111 -0
- package/lib/util/dataURL.js +94 -15
- package/lib/util/deprecation.js +1 -1
- package/lib/util/extractComments.js +118 -0
- package/lib/util/formatLocation.js +1 -1
- package/lib/util/globUtils.js +197 -16
- package/lib/util/haltVisitors.js +51 -0
- package/lib/util/handlerKeys.js +2 -2
- package/lib/util/identifier.js +117 -1
- package/lib/util/implicitTypeLoaderFallback.js +6 -4
- package/lib/util/internalSerializables.js +294 -102
- package/lib/util/magicComment.js +12 -7
- package/lib/util/makeSerializable.js +23 -4
- package/lib/util/parseJson.js +1 -1
- package/lib/util/preloadModuleType.js +5 -2
- package/lib/util/registerExternalSerializer.js +2 -2
- package/lib/util/removeBOM.js +1 -1
- package/lib/util/runtime.js +1 -1
- package/lib/util/serialization.js +4 -1
- package/lib/util/source.js +2 -2
- package/lib/util/terminalColors.js +161 -0
- package/lib/{wasm-async → wasm}/AsyncWasmCompileRuntimeModule.js +5 -5
- package/lib/{wasm-async → wasm}/AsyncWasmLoadingRuntimeModule.js +5 -5
- package/lib/{wasm-async → wasm}/AsyncWasmModule.js +9 -5
- package/lib/{wasm-async → wasm}/AsyncWebAssemblyGenerator.js +5 -5
- package/lib/{wasm-async → wasm}/AsyncWebAssemblyJavascriptGenerator.js +11 -10
- package/lib/{wasm-async → wasm}/AsyncWebAssemblyModulesPlugin.js +26 -10
- package/lib/{wasm-async → wasm}/AsyncWebAssemblyParser.js +8 -8
- package/lib/wasm/EnableWasmLoadingPlugin.js +1 -1
- package/lib/{wasm-async → wasm}/UniversalCompileAsyncWasmPlugin.js +9 -7
- package/lib/wasm/wasmModuleFilename.js +2 -2
- package/lib/wasm-sync/SyncWasmModule.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +8 -8
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -3
- package/lib/wasm-sync/WebAssemblyGenerator.js +9 -8
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +14 -15
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +9 -7
- package/lib/wasm-sync/WebAssemblyParser.js +6 -6
- package/lib/wasm-sync/WebAssemblyUtils.js +6 -5
- package/lib/{MultiWatching.js → watch/MultiWatching.js} +3 -3
- package/lib/{WatchIgnorePlugin.js → watch/WatchIgnorePlugin.js} +43 -9
- package/lib/{Watching.js → watch/Watching.js} +8 -8
- package/lib/web/FetchCompileAsyncWasmPlugin.js +8 -6
- package/lib/web/FetchCompileWasmPlugin.js +6 -4
- package/lib/web/JsonpChunkLoadingPlugin.js +3 -3
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
- package/lib/web/JsonpTemplatePlugin.js +1 -1
- package/lib/webpack.js +27 -17
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -3
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -6
- package/package.json +48 -41
- package/schemas/WebpackOptions.check.js +2 -1
- package/schemas/WebpackOptions.d.json.ts +2 -0
- package/schemas/WebpackOptions.json +294 -74
- package/schemas/plugins/BannerPlugin.check.js +2 -1
- package/schemas/plugins/BannerPlugin.json +29 -2
- package/schemas/plugins/HtmlGeneratorOptions.check.js +1 -0
- package/schemas/plugins/HtmlParserOptions.check.js +2 -1
- package/schemas/plugins/IgnorePlugin.check.js +1 -0
- package/schemas/plugins/IgnorePlugin.d.json.ts +2 -0
- package/schemas/plugins/IgnorePlugin.json +1 -1
- package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -0
- package/schemas/plugins/ManifestPlugin.check.js +1 -0
- package/schemas/plugins/ManifestPlugin.json +3 -3
- package/schemas/plugins/ProgressPlugin.check.js +2 -1
- package/schemas/plugins/ProgressPlugin.json +2 -7
- package/schemas/plugins/SSRManifestPlugin.check.js +7 -0
- package/schemas/plugins/SSRManifestPlugin.json +20 -0
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +2 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +44 -12
- package/schemas/plugins/WatchIgnorePlugin.check.js +2 -1
- package/schemas/plugins/WatchIgnorePlugin.json +12 -3
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -0
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -0
- package/schemas/plugins/asset/AssetParserOptions.check.js +1 -0
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -0
- package/schemas/plugins/container/ContainerPlugin.check.js +2 -1
- package/schemas/plugins/container/ContainerPlugin.json +8 -0
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -0
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +2 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +40 -0
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -0
- package/schemas/plugins/css/CssParserOptions.check.js +1 -0
- package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -0
- package/schemas/plugins/dll/DllPlugin.check.js +1 -0
- package/schemas/plugins/dll/DllReferencePlugin.check.js +2 -1
- package/schemas/plugins/dll/DllReferencePlugin.json +3 -18
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -0
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -0
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -0
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +1 -0
- package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -0
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -0
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -0
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -0
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +1 -0
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +2 -1
- package/schemas/plugins/sharing/ConsumeSharedPlugin.json +32 -0
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +2 -1
- package/schemas/plugins/sharing/ProvideSharedPlugin.json +32 -0
- package/schemas/plugins/sharing/SharePlugin.check.js +2 -1
- package/schemas/plugins/sharing/SharePlugin.json +32 -0
- package/types.d.ts +19355 -13873
- package/lib/LazyBarrel.js +0 -388
- package/lib/dependencies/HarmonyAcceptImportDependency.js +0 -39
- package/lib/dependencies/HarmonyModulesPlugin.js +0 -192
- package/lib/javascript/ChunkFormatHelpers.js +0 -72
- package/lib/javascript/grammar.js +0 -5546
- package/lib/javascript/parser.js +0 -1500
- package/lib/javascript/regexpData.js +0 -51
- package/lib/performance/getSourceModules.js +0 -22
- package/lib/util/Semaphore.js +0 -65
- package/lib/util/objectToMap.js +0 -15
- package/schemas/WebpackOptions.check.d.ts +0 -7
- package/schemas/_container.json +0 -155
- package/schemas/_sharing.json +0 -118
- package/schemas/plugins/BannerPlugin.check.d.ts +0 -7
- package/schemas/plugins/HtmlGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/HtmlParserOptions.check.d.ts +0 -7
- package/schemas/plugins/IgnorePlugin.check.d.ts +0 -7
- package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +0 -7
- package/schemas/plugins/ManifestPlugin.check.d.ts +0 -7
- package/schemas/plugins/ProgressPlugin.check.d.ts +0 -7
- package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +0 -7
- package/schemas/plugins/WatchIgnorePlugin.check.d.ts +0 -7
- package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/asset/AssetParserOptions.check.d.ts +0 -7
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/container/ContainerPlugin.check.d.ts +0 -7
- package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +0 -7
- package/schemas/plugins/container/ExternalsType.check.d.ts +0 -7
- package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +0 -7
- package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +0 -7
- package/schemas/plugins/css/CssParserOptions.check.d.ts +0 -7
- package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +0 -7
- package/schemas/plugins/dll/DllPlugin.check.d.ts +0 -7
- package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +0 -7
- package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +0 -7
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +0 -7
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +0 -7
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +0 -7
- package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +0 -7
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +0 -7
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +0 -7
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +0 -7
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +0 -7
- package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +0 -7
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +0 -7
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +0 -7
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +0 -7
- package/schemas/plugins/sharing/SharePlugin.check.d.ts +0 -7
- /package/lib/{validateSchema.js → config/validateSchema.js} +0 -0
- /package/lib/{util → css}/conventions.js +0 -0
- /package/lib/{util → css}/topologicalSort.js +0 -0
- /package/lib/dependencies/{getFunctionExpression.js → helpers/getFunctionExpression.js} +0 -0
- /package/lib/{util → externals}/extractUrlAndGlobal.js +0 -0
- /package/lib/{util → fs}/StackedCacheMap.js +0 -0
- /package/lib/{util → javascript}/StackedMap.js +0 -0
- /package/lib/{ModuleProfile.js → module/ModuleProfile.js} +0 -0
- /package/lib/{ModuleSourceTypeConstants.js → module/ModuleSourceTypeConstants.js} +0 -0
- /package/lib/{ModuleTypeConstants.js → module/ModuleTypeConstants.js} +0 -0
- /package/lib/{OptimizationStages.js → optimize/OptimizationStages.js} +0 -0
- /package/lib/{util → optimize}/Queue.js +0 -0
- /package/lib/{util → stats}/smartGrouping.js +0 -0
package/lib/NormalModule.js
CHANGED
|
@@ -5,2245 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
AsyncSeriesWaterfallHook,
|
|
12
|
-
HookMap,
|
|
13
|
-
SyncHook
|
|
14
|
-
} = require("tapable");
|
|
15
|
-
const {
|
|
16
|
-
CachedSource,
|
|
17
|
-
OriginalSource,
|
|
18
|
-
RawSource,
|
|
19
|
-
SourceMapSource
|
|
20
|
-
} = require("webpack-sources");
|
|
21
|
-
const Dependency = require("./Dependency");
|
|
22
|
-
const { toError } = require("./ErrorHelpers");
|
|
23
|
-
const Module = require("./Module");
|
|
24
|
-
const ModuleGraphConnection = require("./ModuleGraphConnection");
|
|
25
|
-
const { JAVASCRIPT_MODULE_TYPE_AUTO } = require("./ModuleTypeConstants");
|
|
26
|
-
const RuntimeGlobals = require("./RuntimeGlobals");
|
|
27
|
-
const HarmonyImportSideEffectDependency = require("./dependencies/HarmonyImportSideEffectDependency");
|
|
28
|
-
const HookWebpackError = require("./errors/HookWebpackError");
|
|
29
|
-
const {
|
|
30
|
-
createLoaderContext,
|
|
31
|
-
getContext,
|
|
32
|
-
runLoaders
|
|
33
|
-
} = require("./loaders/LoaderRunner");
|
|
34
|
-
const LazySet = require("./util/LazySet");
|
|
35
|
-
const { isSubset } = require("./util/SetHelpers");
|
|
36
|
-
const { getScheme } = require("./util/URLAbsoluteSpecifier");
|
|
37
|
-
const { getBuildDiagnostics } = require("./util/buildDiagnostics");
|
|
38
|
-
const {
|
|
39
|
-
concatComparators,
|
|
40
|
-
keepOriginalOrder,
|
|
41
|
-
sortWithSourceOrder
|
|
42
|
-
} = require("./util/comparators");
|
|
43
|
-
const createHash = require("./util/createHash");
|
|
44
|
-
const createHooksRegistry = require("./util/createHooksRegistry");
|
|
45
|
-
const { createFakeHook } = require("./util/deprecation");
|
|
46
|
-
const formatLocation = require("./util/formatLocation");
|
|
47
|
-
const { join } = require("./util/fs");
|
|
48
|
-
const {
|
|
49
|
-
ABSOLUTE_PATH_REGEXP,
|
|
50
|
-
absolutify,
|
|
51
|
-
contextify,
|
|
52
|
-
contextifySourceUrl
|
|
53
|
-
} = require("./util/identifier");
|
|
54
|
-
const makeSerializable = require("./util/makeSerializable");
|
|
55
|
-
const memoize = require("./util/memoize");
|
|
56
|
-
const parseJson = require("./util/parseJson");
|
|
57
|
-
|
|
58
|
-
const getValidate = memoize(() => require("schema-utils").validate);
|
|
59
|
-
|
|
60
|
-
const getGenerator = memoize(() => require("./Generator"));
|
|
61
|
-
|
|
62
|
-
const getExtractSourceMap = memoize(() => require("./util/extractSourceMap"));
|
|
63
|
-
|
|
64
|
-
const getInvalidDependenciesModuleWarning = memoize(() =>
|
|
65
|
-
require("./errors/InvalidDependenciesModuleWarning")
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
const getUnhandledSchemeError = memoize(() =>
|
|
69
|
-
require("./errors/UnhandledSchemeError")
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
const getModuleWarning = memoize(() => require("./errors/ModuleWarning"));
|
|
73
|
-
|
|
74
|
-
const getModuleParseError = memoize(() => require("./errors/ModuleParseError"));
|
|
75
|
-
|
|
76
|
-
const getModuleError = memoize(() => require("./errors/ModuleError"));
|
|
77
|
-
|
|
78
|
-
const getModuleBuildError = memoize(() => require("./errors/ModuleBuildError"));
|
|
79
|
-
|
|
80
|
-
/** @import { ResolveContext, ResolveRequest, Resolver } from "enhanced-resolve" */
|
|
81
|
-
/** @import { Source, RawSourceMap } from "webpack-sources" */
|
|
82
|
-
/**
|
|
83
|
-
* @import {
|
|
84
|
-
* ResolveOptions,
|
|
85
|
-
* NoParse,
|
|
86
|
-
* HashFunction,
|
|
87
|
-
* HashDigest,
|
|
88
|
-
* HashDigestLength,
|
|
89
|
-
* HashSalt
|
|
90
|
-
* } from "../declarations/WebpackOptions"
|
|
91
|
-
*/
|
|
92
|
-
/**
|
|
93
|
-
* @import Compilation, {
|
|
94
|
-
* AssetInfo,
|
|
95
|
-
* FileSystemDependencies,
|
|
96
|
-
* UnsafeCacheData
|
|
97
|
-
* } from "./Compilation"
|
|
98
|
-
*/
|
|
99
|
-
/**
|
|
100
|
-
* @import {
|
|
101
|
-
* WebpackOptionsNormalizedWithDefaults as WebpackOptions
|
|
102
|
-
* } from "./config/defaults"
|
|
103
|
-
*/
|
|
104
|
-
/** @import { UpdateHashContext } from "./Dependency" */
|
|
105
|
-
/** @import Generator, { GenerateErrorFn } from "./Generator" */
|
|
106
|
-
/** @import { Snapshot } from "./FileSystemInfo" */
|
|
107
|
-
/**
|
|
108
|
-
* @import {
|
|
109
|
-
* BuildInfo,
|
|
110
|
-
* ValueCacheVersions,
|
|
111
|
-
* BuildMeta,
|
|
112
|
-
* CodeGenerationContext,
|
|
113
|
-
* CodeGenerationResult,
|
|
114
|
-
* ConcatenationBailoutReasonContext,
|
|
115
|
-
* KnownBuildInfo,
|
|
116
|
-
* LibIdentOptions,
|
|
117
|
-
* LibIdent,
|
|
118
|
-
* NameForCondition,
|
|
119
|
-
* NeedBuildContext,
|
|
120
|
-
* NeedBuildCallback,
|
|
121
|
-
* BuildCallback,
|
|
122
|
-
* RuntimeRequirements,
|
|
123
|
-
* SourceType,
|
|
124
|
-
* SourceTypes
|
|
125
|
-
* } from "./Module"
|
|
126
|
-
*/
|
|
127
|
-
/** @import ModuleGraph from "./ModuleGraph" */
|
|
128
|
-
/** @import { ConnectionState } from "./ModuleGraphConnection" */
|
|
129
|
-
/**
|
|
130
|
-
* @import NormalModuleFactory, {
|
|
131
|
-
* NormalModuleTypes,
|
|
132
|
-
* ParserByType,
|
|
133
|
-
* ParserOptionsByType,
|
|
134
|
-
* GeneratorByType,
|
|
135
|
-
* GeneratorOptionsByType,
|
|
136
|
-
* ResourceSchemeData
|
|
137
|
-
* } from "./NormalModuleFactory"
|
|
138
|
-
*/
|
|
139
|
-
/** @import Parser, { PreparsedAst } from "./Parser" */
|
|
140
|
-
/** @import RequestShortener from "./RequestShortener" */
|
|
141
|
-
/** @import Compiler from "./Compiler" */
|
|
142
|
-
/** @import { Logger } from "./logging/Logger" */
|
|
143
|
-
/**
|
|
144
|
-
* @import {
|
|
145
|
-
* ResolverWithOptions,
|
|
146
|
-
* ResolveOptionsWithDependencyType
|
|
147
|
-
* } from "./ResolverFactory"
|
|
148
|
-
*/
|
|
149
|
-
/**
|
|
150
|
-
* @import {
|
|
151
|
-
* ObjectDeserializerContext,
|
|
152
|
-
* ObjectSerializerContext
|
|
153
|
-
* } from "./serialization/ObjectMiddleware"
|
|
154
|
-
*/
|
|
155
|
-
/** @import Hash from "./util/Hash" */
|
|
156
|
-
/** @import { InputFileSystem } from "./util/fs" */
|
|
157
|
-
/** @import { AssociatedObjectForCache } from "./util/identifier" */
|
|
158
|
-
/**
|
|
159
|
-
* @template T
|
|
160
|
-
* @typedef {import("./util/deprecation").FakeHook<T>} FakeHook
|
|
161
|
-
*/
|
|
162
|
-
|
|
163
|
-
/** @typedef {{ [k: string]: EXPECTED_ANY }} ParserOptions */
|
|
164
|
-
/** @typedef {{ [k: string]: EXPECTED_ANY }} GeneratorOptions */
|
|
165
|
-
|
|
166
|
-
/** @typedef {Parameters<Resolver["resolve"]>[4]} ResolveCallback */
|
|
167
|
-
/** @typedef {Parameters<typeof import("schema-utils").validate>[0]} Schema */
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* `getOptions` validates against a schema when given one, and TypeScript reads
|
|
171
|
-
* an intersection of call signatures as an overload set
|
|
172
|
-
* @template OptionsType
|
|
173
|
-
* @typedef {{ (): OptionsType } & { (schema: Schema): OptionsType }} GetOptionsMethod
|
|
174
|
-
*/
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* @typedef {((context: string, request: string, callback: ResolveCallback) => void) & ((context: string, request: string) => Promise<string>)} DualModeResolve
|
|
178
|
-
*/
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* @typedef {object} LoaderContextUtils
|
|
182
|
-
* @property {(context: string, request: string) => string} absolutify returns a new request string using absolute paths when possible
|
|
183
|
-
* @property {(context: string, request: string) => string} contextify returns a new request string avoiding absolute paths when possible
|
|
184
|
-
* @property {(algorithm?: string | typeof Hash) => Hash} createHash creates a hash with the compilation's function
|
|
185
|
-
*/
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* These properties are added by the NormalModule
|
|
189
|
-
* @template OptionsType
|
|
190
|
-
* @typedef {object} NormalModuleLoaderContext
|
|
191
|
-
* @property {number} version
|
|
192
|
-
* @property {GetOptionsMethod<OptionsType>} getOptions Extracts and parses the options of the current loader.
|
|
193
|
-
* Parses string options as JSON or a query string.
|
|
194
|
-
* @property {(warning: Error | string) => void} emitWarning Emits a warning for this module.
|
|
195
|
-
* The warning will be displayed to the user during compilation.
|
|
196
|
-
* @property {(error: Error | string) => void} emitError Emits an error for this module.
|
|
197
|
-
* The error will be displayed to the user and typically causes the compilation to fail.
|
|
198
|
-
* @property {(name?: string) => Logger} getLogger Gets a logger instance scoped to this loader and module.
|
|
199
|
-
* Useful for emitting debug or compilation information in a structured way.
|
|
200
|
-
* @property {(context: string, request: string, callback: ResolveCallback) => void} resolve Resolves a module request (e.g., a relative path or module name) to an absolute file path.
|
|
201
|
-
* It uses Webpack's internal resolver, taking into account configured aliases and extensions.
|
|
202
|
-
* @property {(options?: ResolveOptionsWithDependencyType) => DualModeResolve} getResolve Creates a resolve function with specific options.
|
|
203
|
-
* The returned function can be used as a Promise-based resolver or a callback-based resolver.
|
|
204
|
-
* @property {(name: string, content: string | Buffer, sourceMap?: string, assetInfo?: AssetInfo) => void} emitFile Emits a new file (asset) to the compilation output directory.
|
|
205
|
-
* This allows loaders to generate additional files alongside the main module output.
|
|
206
|
-
* @property {(dep: string) => void} addBuildDependency
|
|
207
|
-
* @property {LoaderContextUtils} utils
|
|
208
|
-
* @property {string} rootContext
|
|
209
|
-
* @property {InputFileSystem} fs
|
|
210
|
-
* @property {boolean=} sourceMap
|
|
211
|
-
* @property {"development" | "production" | "none"} mode
|
|
212
|
-
* @property {boolean=} webpack
|
|
213
|
-
* @property {HashFunction} hashFunction
|
|
214
|
-
* @property {HashDigest} hashDigest
|
|
215
|
-
* @property {HashDigestLength} hashDigestLength
|
|
216
|
-
* @property {HashSalt=} hashSalt
|
|
217
|
-
* @property {NormalModule=} _module
|
|
218
|
-
* @property {Compilation=} _compilation
|
|
219
|
-
* @property {Compiler=} _compiler
|
|
220
|
-
*/
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* @template T
|
|
224
|
-
* @typedef {NormalModuleLoaderContext<T> & import("./loaders/LoaderRunner").LoaderRunnerLoaderContext<T> & import("./dependencies/LoaderPlugin").LoaderPluginLoaderContext & import("./HotModuleReplacementPlugin").HotModuleReplacementPluginLoaderContext} LoaderContext
|
|
225
|
-
*/
|
|
226
|
-
|
|
227
|
-
/** @typedef {(content: string) => boolean} NoParseFn */
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* @param {NormalModule} mod the module
|
|
231
|
-
* @param {ModuleGraph} moduleGraph the module graph
|
|
232
|
-
* @param {Dependency} dep the dep that triggered the bailout
|
|
233
|
-
*/
|
|
234
|
-
const recordSideEffectsBailout = (mod, moduleGraph, dep) => {
|
|
235
|
-
if (mod._addedSideEffectsBailout === undefined) {
|
|
236
|
-
mod._addedSideEffectsBailout = new WeakSet();
|
|
237
|
-
} else if (mod._addedSideEffectsBailout.has(moduleGraph)) {
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
mod._addedSideEffectsBailout.add(moduleGraph);
|
|
241
|
-
moduleGraph
|
|
242
|
-
.getOptimizationBailout(mod)
|
|
243
|
-
.push(
|
|
244
|
-
() =>
|
|
245
|
-
`Dependency (${dep.type}) with side effects at ${formatLocation(
|
|
246
|
-
dep.loc
|
|
247
|
-
)}`
|
|
248
|
-
);
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Walks the `HarmonyImportSideEffectDependency` graph to decide how `rootMod`
|
|
253
|
-
* connects to a referrer when consumed for its side effects only.
|
|
254
|
-
*
|
|
255
|
-
* Iterative (explicit work stack) so deep import chains never approach V8's
|
|
256
|
-
* recursion limit — the overflow behind #20986 — with no separate recursive
|
|
257
|
-
* form or depth cap. Cycles use Tarjan's `index`/`lowlink`: a module's result
|
|
258
|
-
* is memoized on `_sideEffectsStateGraph` only when it is context-independent
|
|
259
|
-
* (cycle-free, or the root of its strongly-connected component), i.e. exactly
|
|
260
|
-
* when the result cannot depend on which ancestors are mid-walk.
|
|
261
|
-
*
|
|
262
|
-
* The previous walker disabled memoization for the whole walk the moment any
|
|
263
|
-
* cycle appeared (one global `circular` flag). With diamond-shaped graphs that
|
|
264
|
-
* made the walk exponential, so a single circular import could blow up an
|
|
265
|
-
* otherwise-linear graph. Per-module lowlink keeps the cycle-free majority
|
|
266
|
-
* memoized while a cycle exists elsewhere.
|
|
267
|
-
*
|
|
268
|
-
* Caching under `lowlink === index` is conservative: an imprecise lowlink can
|
|
269
|
-
* only skip caching (a later recompute yields the same value), never memoize a
|
|
270
|
-
* state that depended on stack context. `true` is monotonic and always cached.
|
|
271
|
-
* A non-`NormalModule` dependency (e.g. `ConcatenatedModule` re-entering this
|
|
272
|
-
* method) is treated as a taint so its chain is never memoized, and any module
|
|
273
|
-
* already flagged `_isEvaluatingSideEffects` (this walk or an outer re-entrant
|
|
274
|
-
* one) counts as circular, matching the previous walker.
|
|
275
|
-
* @param {NormalModule} rootMod the module being walked
|
|
276
|
-
* @param {ModuleGraph} moduleGraph the module graph
|
|
277
|
-
* @param {EXPECTED_ANY} SideEffectDep `HarmonyImportSideEffectDependency` constructor, resolved once at the entry
|
|
278
|
-
* @returns {ConnectionState} the side-effects connection state
|
|
279
|
-
*/
|
|
280
|
-
const walkSideEffects = (rootMod, moduleGraph, SideEffectDep) => {
|
|
281
|
-
// Context-independent state without descending; `undefined` => walk deps.
|
|
282
|
-
/**
|
|
283
|
-
* @param {NormalModule} mod module
|
|
284
|
-
* @returns {ConnectionState | undefined} resolved state or undefined
|
|
285
|
-
*/
|
|
286
|
-
const quick = (mod) => {
|
|
287
|
-
if (mod._sideEffectsStateGraph === moduleGraph) {
|
|
288
|
-
return /** @type {ConnectionState} */ (mod._sideEffectsStateValue);
|
|
289
|
-
}
|
|
290
|
-
const fm = mod.factoryMeta;
|
|
291
|
-
if (fm !== undefined) {
|
|
292
|
-
if (fm.sideEffectFree) return false;
|
|
293
|
-
if (fm.sideEffectFree === false) return true;
|
|
294
|
-
}
|
|
295
|
-
if (!(mod.buildMeta !== undefined && mod.buildMeta.sideEffectFree)) {
|
|
296
|
-
return true;
|
|
297
|
-
}
|
|
298
|
-
return undefined;
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
const q0 = quick(rootMod);
|
|
302
|
-
if (q0 !== undefined) return q0;
|
|
303
|
-
|
|
304
|
-
/** @type {Map<NormalModule, number>} module -> Tarjan index */
|
|
305
|
-
const indexOf = new Map();
|
|
306
|
-
/** @type {Map<NormalModule, number>} module -> Tarjan lowlink */
|
|
307
|
-
const lowOf = new Map();
|
|
308
|
-
// Parallel frame arrays, to avoid a per-frame object allocation.
|
|
309
|
-
/** @type {NormalModule[]} */
|
|
310
|
-
const fMod = [];
|
|
311
|
-
/** @type {Dependency[][]} */
|
|
312
|
-
const fDeps = [];
|
|
313
|
-
/** @type {number[]} */
|
|
314
|
-
const fIdx = [];
|
|
315
|
-
/** @type {ConnectionState[]} */
|
|
316
|
-
const fCur = [];
|
|
317
|
-
let counter = 0;
|
|
318
|
-
|
|
319
|
-
/**
|
|
320
|
-
* @param {NormalModule} mod module to push a frame for
|
|
321
|
-
*/
|
|
322
|
-
const enter = (mod) => {
|
|
323
|
-
indexOf.set(mod, counter);
|
|
324
|
-
lowOf.set(mod, counter);
|
|
325
|
-
counter++;
|
|
326
|
-
mod._isEvaluatingSideEffects = true;
|
|
327
|
-
fMod.push(mod);
|
|
328
|
-
fDeps.push(mod.dependencies);
|
|
329
|
-
fIdx.push(0);
|
|
330
|
-
fCur.push(false);
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
enter(rootMod);
|
|
334
|
-
/** @type {ConnectionState} the just-popped frame's result */
|
|
335
|
-
let result = false;
|
|
336
|
-
/**
|
|
337
|
-
* Result of a just-popped child frame, to apply to the new top's current
|
|
338
|
-
* dep. `undefined` means "no pending; advance normally".
|
|
339
|
-
* @type {ConnectionState | undefined}
|
|
340
|
-
*/
|
|
341
|
-
let pending;
|
|
342
|
-
|
|
343
|
-
while (fMod.length > 0) {
|
|
344
|
-
const top = fMod.length - 1;
|
|
345
|
-
const mod = fMod[top];
|
|
346
|
-
const deps = fDeps[top];
|
|
347
|
-
let i = fIdx[top];
|
|
348
|
-
let current = fCur[top];
|
|
349
|
-
|
|
350
|
-
// Apply a popped child's result to the dep that spawned it.
|
|
351
|
-
if (pending !== undefined) {
|
|
352
|
-
const state = pending;
|
|
353
|
-
pending = undefined;
|
|
354
|
-
const dep = deps[i];
|
|
355
|
-
if (state === true) {
|
|
356
|
-
recordSideEffectsBailout(mod, moduleGraph, dep);
|
|
357
|
-
mod._sideEffectsStateGraph = moduleGraph;
|
|
358
|
-
mod._sideEffectsStateValue = true;
|
|
359
|
-
mod._isEvaluatingSideEffects = false;
|
|
360
|
-
fMod.pop();
|
|
361
|
-
fDeps.pop();
|
|
362
|
-
fIdx.pop();
|
|
363
|
-
fCur.pop();
|
|
364
|
-
result = true;
|
|
365
|
-
pending = true;
|
|
366
|
-
continue;
|
|
367
|
-
}
|
|
368
|
-
if (state !== ModuleGraphConnection.CIRCULAR_CONNECTION) {
|
|
369
|
-
current = ModuleGraphConnection.addConnectionStates(current, state);
|
|
370
|
-
}
|
|
371
|
-
i++;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
let descended = false;
|
|
375
|
-
while (i < deps.length) {
|
|
376
|
-
const dep = deps[i];
|
|
377
|
-
/** @type {ConnectionState} */
|
|
378
|
-
let state;
|
|
379
|
-
|
|
380
|
-
if (dep instanceof SideEffectDep) {
|
|
381
|
-
const refModule = moduleGraph.getModule(dep);
|
|
382
|
-
if (!refModule) {
|
|
383
|
-
state = true;
|
|
384
|
-
} else if (refModule instanceof NormalModule) {
|
|
385
|
-
if (refModule._isEvaluatingSideEffects) {
|
|
386
|
-
// On the current stack (or an outer re-entrant walk) => cycle.
|
|
387
|
-
state = ModuleGraphConnection.CIRCULAR_CONNECTION;
|
|
388
|
-
const ri = indexOf.get(refModule);
|
|
389
|
-
lowOf.set(
|
|
390
|
-
mod,
|
|
391
|
-
Math.min(
|
|
392
|
-
/** @type {number} */ (lowOf.get(mod)),
|
|
393
|
-
ri === undefined ? -1 : ri
|
|
394
|
-
)
|
|
395
|
-
);
|
|
396
|
-
} else {
|
|
397
|
-
const q = quick(refModule);
|
|
398
|
-
if (q !== undefined) {
|
|
399
|
-
state = q;
|
|
400
|
-
} else {
|
|
401
|
-
// Descend: pause this frame, walk the child next.
|
|
402
|
-
fIdx[top] = i;
|
|
403
|
-
fCur[top] = current;
|
|
404
|
-
enter(refModule);
|
|
405
|
-
descended = true;
|
|
406
|
-
break;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
} else {
|
|
410
|
-
// A non-NormalModule resolves through a re-entrant walk that may read
|
|
411
|
-
// our in-progress modules as circular, so this chain is tainted and
|
|
412
|
-
// never memoized.
|
|
413
|
-
state = refModule.getSideEffectsConnectionState(moduleGraph);
|
|
414
|
-
lowOf.set(mod, -1);
|
|
415
|
-
}
|
|
416
|
-
} else {
|
|
417
|
-
state = dep.getModuleEvaluationSideEffectsState(moduleGraph);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
if (state === true) {
|
|
421
|
-
recordSideEffectsBailout(mod, moduleGraph, dep);
|
|
422
|
-
// `true` is monotonic — always safe to memoize.
|
|
423
|
-
mod._sideEffectsStateGraph = moduleGraph;
|
|
424
|
-
mod._sideEffectsStateValue = true;
|
|
425
|
-
mod._isEvaluatingSideEffects = false;
|
|
426
|
-
fMod.pop();
|
|
427
|
-
fDeps.pop();
|
|
428
|
-
fIdx.pop();
|
|
429
|
-
fCur.pop();
|
|
430
|
-
result = true;
|
|
431
|
-
pending = true;
|
|
432
|
-
descended = true;
|
|
433
|
-
break;
|
|
434
|
-
}
|
|
435
|
-
if (state !== ModuleGraphConnection.CIRCULAR_CONNECTION) {
|
|
436
|
-
current = ModuleGraphConnection.addConnectionStates(current, state);
|
|
437
|
-
}
|
|
438
|
-
i++;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
if (descended) continue;
|
|
442
|
-
|
|
443
|
-
// `mod` finished without a `true` bailout.
|
|
444
|
-
mod._isEvaluatingSideEffects = false;
|
|
445
|
-
// Memoize only when the result is context-independent: no back-edge in
|
|
446
|
-
// this subtree reached above `mod` (a cycle-free module or an SCC root).
|
|
447
|
-
if (lowOf.get(mod) === indexOf.get(mod)) {
|
|
448
|
-
mod._sideEffectsStateGraph = moduleGraph;
|
|
449
|
-
mod._sideEffectsStateValue = current;
|
|
450
|
-
}
|
|
451
|
-
fMod.pop();
|
|
452
|
-
fDeps.pop();
|
|
453
|
-
fIdx.pop();
|
|
454
|
-
fCur.pop();
|
|
455
|
-
result = current;
|
|
456
|
-
pending = current;
|
|
457
|
-
if (fMod.length > 0) {
|
|
458
|
-
const parent = fMod[fMod.length - 1];
|
|
459
|
-
lowOf.set(
|
|
460
|
-
parent,
|
|
461
|
-
Math.min(
|
|
462
|
-
/** @type {number} */ (lowOf.get(parent)),
|
|
463
|
-
/** @type {number} */ (lowOf.get(mod))
|
|
464
|
-
)
|
|
465
|
-
);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
return result;
|
|
470
|
-
};
|
|
471
|
-
|
|
472
|
-
/**
|
|
473
|
-
* @typedef {object} LoaderItem
|
|
474
|
-
* @property {string} loader
|
|
475
|
-
* @property {string | null | undefined | Record<string, EXPECTED_ANY>} options
|
|
476
|
-
* @property {string | null=} ident
|
|
477
|
-
* @property {string | null=} type
|
|
478
|
-
*/
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* @param {string} context absolute context path
|
|
482
|
-
* @param {string | RawSourceMap} sourceMap a source map
|
|
483
|
-
* @param {AssociatedObjectForCache=} associatedObjectForCache an object to which the cache will be attached
|
|
484
|
-
* @returns {string | RawSourceMap} new source map
|
|
485
|
-
*/
|
|
486
|
-
const contextifySourceMap = (context, sourceMap, associatedObjectForCache) => {
|
|
487
|
-
if (typeof sourceMap === "string" || !Array.isArray(sourceMap.sources)) {
|
|
488
|
-
return sourceMap;
|
|
489
|
-
}
|
|
490
|
-
const { sourceRoot } = sourceMap;
|
|
491
|
-
/** @type {(source: string) => string} */
|
|
492
|
-
const mapper = !sourceRoot
|
|
493
|
-
? (source) => source
|
|
494
|
-
: sourceRoot.endsWith("/")
|
|
495
|
-
? (source) =>
|
|
496
|
-
source.startsWith("/")
|
|
497
|
-
? `${sourceRoot.slice(0, -1)}${source}`
|
|
498
|
-
: `${sourceRoot}${source}`
|
|
499
|
-
: (source) =>
|
|
500
|
-
source.startsWith("/")
|
|
501
|
-
? `${sourceRoot}${source}`
|
|
502
|
-
: `${sourceRoot}/${source}`;
|
|
503
|
-
const newSources = sourceMap.sources.map((source) =>
|
|
504
|
-
contextifySourceUrl(context, mapper(source), associatedObjectForCache)
|
|
505
|
-
);
|
|
506
|
-
return {
|
|
507
|
-
...sourceMap,
|
|
508
|
-
file: "x",
|
|
509
|
-
sourceRoot: undefined,
|
|
510
|
-
sources: newSources
|
|
511
|
-
};
|
|
512
|
-
};
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
* @param {string | Buffer} input the input
|
|
516
|
-
* @returns {string} the converted string
|
|
517
|
-
*/
|
|
518
|
-
const asString = (input) => {
|
|
519
|
-
if (Buffer.isBuffer(input)) {
|
|
520
|
-
return input.toString("utf8");
|
|
521
|
-
}
|
|
522
|
-
return input;
|
|
523
|
-
};
|
|
524
|
-
|
|
525
|
-
/**
|
|
526
|
-
* @param {string | Buffer} input the input
|
|
527
|
-
* @returns {Buffer} the converted buffer
|
|
528
|
-
*/
|
|
529
|
-
const asBuffer = (input) => {
|
|
530
|
-
if (!Buffer.isBuffer(input)) {
|
|
531
|
-
return Buffer.from(input, "utf8");
|
|
532
|
-
}
|
|
533
|
-
return input;
|
|
534
|
-
};
|
|
535
|
-
|
|
536
|
-
/** @typedef {[string | Buffer, string | RawSourceMap | undefined, PreparsedAst | undefined]} Result */
|
|
537
|
-
|
|
538
|
-
/** @typedef {LoaderContext<EXPECTED_ANY>} AnyLoaderContext */
|
|
539
|
-
|
|
540
|
-
/**
|
|
541
|
-
* @deprecated Use the `readResource` hook instead.
|
|
542
|
-
* @typedef {HookMap<FakeHook<AsyncSeriesBailHook<[string, NormalModule], string | Buffer | null>>>} DeprecatedReadResourceForScheme
|
|
543
|
-
*/
|
|
544
|
-
|
|
545
|
-
const createCompilationHooks = () => {
|
|
546
|
-
/** @type {HookMap<AsyncSeriesBailHook<[AnyLoaderContext], string | Buffer | null>>} */
|
|
547
|
-
const readResource = new HookMap(
|
|
548
|
-
() => new AsyncSeriesBailHook(["loaderContext"])
|
|
549
|
-
);
|
|
550
|
-
return {
|
|
551
|
-
// TODO webpack 6 deprecate
|
|
552
|
-
/**
|
|
553
|
-
* @deprecated Use the `readResource` hook instead.
|
|
554
|
-
* @type {DeprecatedReadResourceForScheme}
|
|
555
|
-
*/
|
|
556
|
-
readResourceForScheme: new HookMap((scheme) => {
|
|
557
|
-
const hook = readResource.for(scheme);
|
|
558
|
-
return createFakeHook(
|
|
559
|
-
/** @type {AsyncSeriesBailHook<[string, NormalModule], string | Buffer | null>} */ ({
|
|
560
|
-
tap: (options, fn) =>
|
|
561
|
-
hook.tap(options, (loaderContext) =>
|
|
562
|
-
fn(
|
|
563
|
-
loaderContext.resource,
|
|
564
|
-
/** @type {NormalModule} */ (loaderContext._module)
|
|
565
|
-
)
|
|
566
|
-
),
|
|
567
|
-
tapAsync: (options, fn) =>
|
|
568
|
-
hook.tapAsync(options, (loaderContext, callback) =>
|
|
569
|
-
fn(
|
|
570
|
-
loaderContext.resource,
|
|
571
|
-
/** @type {NormalModule} */ (loaderContext._module),
|
|
572
|
-
callback
|
|
573
|
-
)
|
|
574
|
-
),
|
|
575
|
-
tapPromise: (options, fn) =>
|
|
576
|
-
hook.tapPromise(options, (loaderContext) =>
|
|
577
|
-
fn(
|
|
578
|
-
loaderContext.resource,
|
|
579
|
-
/** @type {NormalModule} */ (loaderContext._module)
|
|
580
|
-
)
|
|
581
|
-
)
|
|
582
|
-
})
|
|
583
|
-
);
|
|
584
|
-
}),
|
|
585
|
-
/**
|
|
586
|
-
* @since 5.58.0
|
|
587
|
-
*/
|
|
588
|
-
readResource,
|
|
589
|
-
/** @type {SyncHook<[AnyLoaderContext, NormalModule]>} */
|
|
590
|
-
loader: new SyncHook(["loaderContext", "module"]),
|
|
591
|
-
/** @type {SyncHook<[LoaderItem[], NormalModule, AnyLoaderContext]>} */
|
|
592
|
-
beforeLoaders: new SyncHook(["loaders", "module", "loaderContext"]),
|
|
593
|
-
/**
|
|
594
|
-
* @type {SyncHook<[NormalModule]>}
|
|
595
|
-
* @since 5.59.0
|
|
596
|
-
*/
|
|
597
|
-
beforeParse: new SyncHook(["module"]),
|
|
598
|
-
/**
|
|
599
|
-
* @type {SyncHook<[NormalModule]>}
|
|
600
|
-
* @since 5.59.0
|
|
601
|
-
*/
|
|
602
|
-
beforeSnapshot: new SyncHook(["module"]),
|
|
603
|
-
/**
|
|
604
|
-
* Async since 5.111.0, so a tap can await work of its own — minifying an
|
|
605
|
-
* asset, say, which before only a loader could do. `tap` keeps working.
|
|
606
|
-
* @type {AsyncSeriesWaterfallHook<[Result, NormalModule]>}
|
|
607
|
-
* @since 5.99.0
|
|
608
|
-
*/
|
|
609
|
-
processResult: new AsyncSeriesWaterfallHook(["result", "module"]),
|
|
610
|
-
/**
|
|
611
|
-
* @type {AsyncSeriesBailHook<[NormalModule, NeedBuildContext], boolean>}
|
|
612
|
-
* @since 5.49.0
|
|
613
|
-
*/
|
|
614
|
-
needBuild: new AsyncSeriesBailHook(["module", "context"])
|
|
615
|
-
};
|
|
616
|
-
};
|
|
617
|
-
|
|
618
|
-
/**
|
|
619
|
-
* @typedef {ReturnType<typeof createCompilationHooks>} NormalModuleCompilationHooks
|
|
620
|
-
*/
|
|
621
|
-
|
|
622
|
-
/**
|
|
623
|
-
* @template {NormalModuleTypes | ""} [T=NormalModuleTypes | ""]
|
|
624
|
-
* @typedef {object} NormalModuleCreateData
|
|
625
|
-
* @property {string=} layer an optional layer in which the module is
|
|
626
|
-
* @property {T} type module type. When deserializing, this is set to an empty string "".
|
|
627
|
-
* @property {string} request request string
|
|
628
|
-
* @property {string} userRequest request intended by user (without loaders from config)
|
|
629
|
-
* @property {string} rawRequest request without resolving
|
|
630
|
-
* @property {LoaderItem[]} loaders list of loaders
|
|
631
|
-
* @property {string} resource path + query of the real resource
|
|
632
|
-
* @property {(ResourceSchemeData & Partial<ResolveRequest>)=} resourceResolveData resource resolve data
|
|
633
|
-
* @property {string} context context directory for resolving
|
|
634
|
-
* @property {string=} matchResource path + query of the matched resource (virtual)
|
|
635
|
-
* @property {ParserByType[T]} parser the parser used
|
|
636
|
-
* @property {ParserOptionsByType[T]=} parserOptions the options of the parser used
|
|
637
|
-
* @property {GeneratorByType[T]} generator the generator used
|
|
638
|
-
* @property {GeneratorOptionsByType[T]=} generatorOptions the options of the generator used
|
|
639
|
-
* @property {ResolveOptions=} resolveOptions options used for resolving requests from this module
|
|
640
|
-
* @property {boolean} extractSourceMap enable/disable extracting source map
|
|
641
|
-
*/
|
|
642
|
-
|
|
643
|
-
/**
|
|
644
|
-
* @typedef {(resourcePath: string, getLoaderContext: (resourcePath: string) => AnyLoaderContext) => Promise<string | Buffer<ArrayBufferLike>>} ReadResource
|
|
645
|
-
*/
|
|
646
|
-
|
|
647
|
-
/**
|
|
648
|
-
* Defines the build info properties of normal modules (filesystem-backed, loader-processed).
|
|
649
|
-
* @typedef {object} KnownNormalModuleBuildInfo
|
|
650
|
-
* @property {boolean=} parsed
|
|
651
|
-
* @property {string=} hash
|
|
652
|
-
* @property {FileSystemDependencies=} fileDependencies
|
|
653
|
-
* @property {FileSystemDependencies=} contextDependencies
|
|
654
|
-
* @property {FileSystemDependencies=} missingDependencies
|
|
655
|
-
* @property {FileSystemDependencies=} buildDependencies
|
|
656
|
-
* @property {ValueCacheVersions=} valueDependencies
|
|
657
|
-
* @property {(InstanceType<Snapshot> | null)=} snapshot
|
|
658
|
-
* @property {string=} resourceIntegrity using in HttpUriPlugin
|
|
659
|
-
*/
|
|
660
|
-
|
|
661
|
-
/** @typedef {BuildInfo & KnownNormalModuleBuildInfo} NormalModuleBuildInfo */
|
|
662
|
-
|
|
663
|
-
const normalModuleHooksRegistry = createHooksRegistry(createCompilationHooks);
|
|
664
|
-
|
|
665
|
-
class NormalModule extends Module {
|
|
666
|
-
/**
|
|
667
|
-
* @param {Compilation} compilation the compilation
|
|
668
|
-
* @returns {NormalModuleCompilationHooks} the attached hooks
|
|
669
|
-
*/
|
|
670
|
-
static getCompilationHooks(compilation) {
|
|
671
|
-
return normalModuleHooksRegistry(compilation);
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
/**
|
|
675
|
-
* @param {NormalModuleCreateData} options options object
|
|
676
|
-
*/
|
|
677
|
-
constructor({
|
|
678
|
-
layer,
|
|
679
|
-
type,
|
|
680
|
-
request,
|
|
681
|
-
userRequest,
|
|
682
|
-
rawRequest,
|
|
683
|
-
loaders,
|
|
684
|
-
resource,
|
|
685
|
-
resourceResolveData,
|
|
686
|
-
context,
|
|
687
|
-
matchResource,
|
|
688
|
-
parser,
|
|
689
|
-
parserOptions,
|
|
690
|
-
generator,
|
|
691
|
-
generatorOptions,
|
|
692
|
-
resolveOptions,
|
|
693
|
-
extractSourceMap
|
|
694
|
-
}) {
|
|
695
|
-
super(type, context || getContext(resource), layer);
|
|
696
|
-
|
|
697
|
-
// Info from Factory
|
|
698
|
-
/** @type {NormalModuleCreateData['request']} */
|
|
699
|
-
this.request = request;
|
|
700
|
-
/** @type {NormalModuleCreateData['userRequest']} */
|
|
701
|
-
this.userRequest = userRequest;
|
|
702
|
-
/** @type {NormalModuleCreateData['rawRequest']} */
|
|
703
|
-
this.rawRequest = rawRequest;
|
|
704
|
-
/** @type {boolean} */
|
|
705
|
-
this.binary = /^(?:asset|webassembly)\b/.test(type);
|
|
706
|
-
/** @type {NormalModuleCreateData['parser'] | undefined} */
|
|
707
|
-
this.parser = parser;
|
|
708
|
-
/** @type {NormalModuleCreateData['parserOptions']} */
|
|
709
|
-
this.parserOptions = parserOptions;
|
|
710
|
-
/** @type {NormalModuleCreateData['generator'] | undefined} */
|
|
711
|
-
this.generator = generator;
|
|
712
|
-
/** @type {NormalModuleCreateData['generatorOptions']} */
|
|
713
|
-
this.generatorOptions = generatorOptions;
|
|
714
|
-
/** @type {NormalModuleCreateData['resource']} */
|
|
715
|
-
this.resource = resource;
|
|
716
|
-
/** @type {NormalModuleCreateData['resourceResolveData']} */
|
|
717
|
-
this.resourceResolveData = resourceResolveData;
|
|
718
|
-
/** @type {NormalModuleCreateData['matchResource']} */
|
|
719
|
-
this.matchResource = matchResource;
|
|
720
|
-
/** @type {NormalModuleCreateData['loaders']} */
|
|
721
|
-
this.loaders = loaders;
|
|
722
|
-
if (resolveOptions !== undefined) {
|
|
723
|
-
// already declared in super class
|
|
724
|
-
/** @type {NormalModuleCreateData['resolveOptions']} */
|
|
725
|
-
this.resolveOptions = resolveOptions;
|
|
726
|
-
}
|
|
727
|
-
/** @type {NormalModuleCreateData['extractSourceMap']} */
|
|
728
|
-
this.extractSourceMap = extractSourceMap;
|
|
729
|
-
|
|
730
|
-
// Set by HotModuleReplacementPlugin via NormalModuleFactory's `module` hook
|
|
731
|
-
/** @type {boolean} */
|
|
732
|
-
this.hot = false;
|
|
733
|
-
|
|
734
|
-
// Info from Build
|
|
735
|
-
// Redeclared with the normal module specific shape (see KnownNormalModuleBuildInfo)
|
|
736
|
-
/** @type {NormalModuleBuildInfo | undefined} */
|
|
737
|
-
this.buildInfo = undefined;
|
|
738
|
-
/** @type {Error | null} */
|
|
739
|
-
this.error = null;
|
|
740
|
-
/**
|
|
741
|
-
* @private
|
|
742
|
-
* @type {Source | null}
|
|
743
|
-
*/
|
|
744
|
-
this._source = null;
|
|
745
|
-
// Set at build time; declared here so the instance shape is fixed at construction
|
|
746
|
-
/**
|
|
747
|
-
* @private
|
|
748
|
-
* @type {PreparsedAst | null}
|
|
749
|
-
*/
|
|
750
|
-
this._ast = null;
|
|
751
|
-
/**
|
|
752
|
-
* @private
|
|
753
|
-
* @type {Map<undefined | SourceType, number> | undefined}
|
|
754
|
-
*/
|
|
755
|
-
this._sourceSizes = undefined;
|
|
756
|
-
/**
|
|
757
|
-
* @private
|
|
758
|
-
* @type {undefined | SourceTypes}
|
|
759
|
-
*/
|
|
760
|
-
this._sourceTypes = undefined;
|
|
761
|
-
// Cache
|
|
762
|
-
/**
|
|
763
|
-
* @private
|
|
764
|
-
* @type {BuildMeta}
|
|
765
|
-
*/
|
|
766
|
-
this._lastSuccessfulBuildMeta = {};
|
|
767
|
-
/**
|
|
768
|
-
* @private
|
|
769
|
-
* @type {boolean}
|
|
770
|
-
*/
|
|
771
|
-
this._forceBuild = true;
|
|
772
|
-
/**
|
|
773
|
-
* @type {boolean}
|
|
774
|
-
*/
|
|
775
|
-
this._isEvaluatingSideEffects = false;
|
|
776
|
-
/**
|
|
777
|
-
* @type {WeakSet<ModuleGraph> | undefined}
|
|
778
|
-
*/
|
|
779
|
-
this._addedSideEffectsBailout = undefined;
|
|
780
|
-
/**
|
|
781
|
-
* Memoizes the result of `getSideEffectsConnectionState`. The
|
|
782
|
-
* graph slot keys the cached value to the `ModuleGraph` it was
|
|
783
|
-
* computed against so stale values never leak across compilations
|
|
784
|
-
* — a walk that targets a different graph just overwrites both
|
|
785
|
-
* slots. Populated only for context-independent results (cycle-free
|
|
786
|
-
* or SCC-root modules; see `walkSideEffects`).
|
|
787
|
-
* @type {ModuleGraph | undefined}
|
|
788
|
-
*/
|
|
789
|
-
this._sideEffectsStateGraph = undefined;
|
|
790
|
-
/** @type {ConnectionState | undefined} */
|
|
791
|
-
this._sideEffectsStateValue = undefined;
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
/**
|
|
795
|
-
* Returns the unique identifier used to reference this module.
|
|
796
|
-
* @returns {string} a unique identifier of the module
|
|
797
|
-
*/
|
|
798
|
-
identifier() {
|
|
799
|
-
if (this.layer === null) {
|
|
800
|
-
if (this.type === JAVASCRIPT_MODULE_TYPE_AUTO) {
|
|
801
|
-
return this.request;
|
|
802
|
-
}
|
|
803
|
-
return `${this.type}|${this.request}`;
|
|
804
|
-
}
|
|
805
|
-
return `${this.type}|${this.request}|${this.layer}`;
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
/**
|
|
809
|
-
* Returns a human-readable identifier for this module.
|
|
810
|
-
* @param {RequestShortener} requestShortener the request shortener
|
|
811
|
-
* @returns {string} a user readable identifier of the module
|
|
812
|
-
*/
|
|
813
|
-
readableIdentifier(requestShortener) {
|
|
814
|
-
return /** @type {string} */ (requestShortener.shorten(this.userRequest));
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
/**
|
|
818
|
-
* @returns {string | null} return the resource path
|
|
819
|
-
*/
|
|
820
|
-
getResource() {
|
|
821
|
-
return this.matchResource || this.resource;
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
/**
|
|
825
|
-
* Gets the library identifier.
|
|
826
|
-
* @param {LibIdentOptions} options options
|
|
827
|
-
* @returns {LibIdent | null} an identifier for library inclusion
|
|
828
|
-
*/
|
|
829
|
-
libIdent(options) {
|
|
830
|
-
let ident = contextify(
|
|
831
|
-
options.context,
|
|
832
|
-
this.userRequest,
|
|
833
|
-
options.associatedObjectForCache
|
|
834
|
-
);
|
|
835
|
-
if (this.layer) ident = `(${this.layer})/${ident}`;
|
|
836
|
-
return ident;
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
/**
|
|
840
|
-
* Returns the path used when matching this module against rule conditions.
|
|
841
|
-
* @returns {NameForCondition | null} absolute path which should be used for condition matching (usually the resource path)
|
|
842
|
-
*/
|
|
843
|
-
nameForCondition() {
|
|
844
|
-
const resource = /** @type {string} */ (this.getResource());
|
|
845
|
-
const idx = resource.indexOf("?");
|
|
846
|
-
if (idx >= 0) return resource.slice(0, idx);
|
|
847
|
-
return resource;
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
/**
|
|
851
|
-
* Assuming this module is in the cache. Update the (cached) module with
|
|
852
|
-
* the fresh module from the factory. Usually updates internal references
|
|
853
|
-
* and properties.
|
|
854
|
-
* @param {Module} module fresh module
|
|
855
|
-
* @returns {void}
|
|
856
|
-
*/
|
|
857
|
-
updateCacheModule(module) {
|
|
858
|
-
super.updateCacheModule(module);
|
|
859
|
-
const m = /** @type {NormalModule} */ (module);
|
|
860
|
-
this.binary = m.binary;
|
|
861
|
-
this.request = m.request;
|
|
862
|
-
this.userRequest = m.userRequest;
|
|
863
|
-
this.rawRequest = m.rawRequest;
|
|
864
|
-
this.parser = m.parser;
|
|
865
|
-
this.parserOptions = m.parserOptions;
|
|
866
|
-
this.generator = m.generator;
|
|
867
|
-
this.generatorOptions = m.generatorOptions;
|
|
868
|
-
this.resource = m.resource;
|
|
869
|
-
this.resourceResolveData = m.resourceResolveData;
|
|
870
|
-
this.context = m.context;
|
|
871
|
-
this.matchResource = m.matchResource;
|
|
872
|
-
this.loaders = m.loaders;
|
|
873
|
-
this.extractSourceMap = m.extractSourceMap;
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
/**
|
|
877
|
-
* Assuming this module is in the cache. Remove internal references to allow freeing some memory.
|
|
878
|
-
*/
|
|
879
|
-
cleanupForCache() {
|
|
880
|
-
// Make sure to cache types and sizes before cleanup when this module has been built
|
|
881
|
-
// They are accessed by the stats and we don't want them to crash after cleanup
|
|
882
|
-
// TODO reconsider this for webpack 6
|
|
883
|
-
if (this.buildInfo) {
|
|
884
|
-
if (this._sourceTypes === undefined) this.getSourceTypes();
|
|
885
|
-
for (const type of /** @type {SourceTypes} */ (this._sourceTypes)) {
|
|
886
|
-
this.size(type);
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
super.cleanupForCache();
|
|
890
|
-
this.parser = undefined;
|
|
891
|
-
this.parserOptions = undefined;
|
|
892
|
-
this.generator = undefined;
|
|
893
|
-
this.generatorOptions = undefined;
|
|
894
|
-
// Drop the side-effects memoization so a long-lived module doesn't
|
|
895
|
-
// strong-reference a stale `ModuleGraph`/`Compilation` for graphs
|
|
896
|
-
// that never get re-queried with a fresh one.
|
|
897
|
-
this._sideEffectsStateGraph = undefined;
|
|
898
|
-
this._sideEffectsStateValue = undefined;
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
/**
|
|
902
|
-
* Releases the cached parser between incremental rebuilds so it doesn't keep
|
|
903
|
-
* the previous compilation alive.
|
|
904
|
-
* @returns {void}
|
|
905
|
-
*/
|
|
906
|
-
_cleanupParserForCache() {
|
|
907
|
-
this.parser = undefined;
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
/**
|
|
911
|
-
* Re-acquire factory-derived helpers (parser/generator) for an incremental
|
|
912
|
-
* rebuild so this compilation's plugin hooks apply.
|
|
913
|
-
* @param {NormalModuleFactory} normalModuleFactory the normal module factory
|
|
914
|
-
* @returns {void}
|
|
915
|
-
*/
|
|
916
|
-
_restoreParserAndGenerator(normalModuleFactory) {
|
|
917
|
-
this.parser = normalModuleFactory.getParser(this.type, this.parserOptions);
|
|
918
|
-
this.generator = normalModuleFactory.getGenerator(
|
|
919
|
-
this.type,
|
|
920
|
-
this.generatorOptions
|
|
921
|
-
);
|
|
922
|
-
}
|
|
923
|
-
|
|
924
|
-
/**
|
|
925
|
-
* Module should be unsafe cached. Get data that's needed for that.
|
|
926
|
-
* This data will be passed to restoreFromUnsafeCache later.
|
|
927
|
-
* @returns {UnsafeCacheData} cached data
|
|
928
|
-
*/
|
|
929
|
-
getUnsafeCacheData() {
|
|
930
|
-
const data = super.getUnsafeCacheData();
|
|
931
|
-
data.parserOptions = this.parserOptions;
|
|
932
|
-
data.generatorOptions = this.generatorOptions;
|
|
933
|
-
return data;
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
/**
|
|
937
|
-
* restore unsafe cache data
|
|
938
|
-
* @param {UnsafeCacheData} unsafeCacheData data from getUnsafeCacheData
|
|
939
|
-
* @param {NormalModuleFactory} normalModuleFactory the normal module factory handling the unsafe caching
|
|
940
|
-
*/
|
|
941
|
-
restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory) {
|
|
942
|
-
this._restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory);
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
/**
|
|
946
|
-
* restore unsafe cache data
|
|
947
|
-
* @param {UnsafeCacheData} unsafeCacheData data from getUnsafeCacheData
|
|
948
|
-
* @param {NormalModuleFactory} normalModuleFactory the normal module factory handling the unsafe caching
|
|
949
|
-
*/
|
|
950
|
-
_restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory) {
|
|
951
|
-
super._restoreFromUnsafeCache(unsafeCacheData, normalModuleFactory);
|
|
952
|
-
this.parserOptions = unsafeCacheData.parserOptions;
|
|
953
|
-
this.parser = normalModuleFactory.getParser(this.type, this.parserOptions);
|
|
954
|
-
this.generatorOptions = unsafeCacheData.generatorOptions;
|
|
955
|
-
this.generator = normalModuleFactory.getGenerator(
|
|
956
|
-
this.type,
|
|
957
|
-
this.generatorOptions
|
|
958
|
-
);
|
|
959
|
-
// we assume the generator behaves identically and keep cached sourceTypes/Sizes
|
|
960
|
-
}
|
|
961
|
-
|
|
962
|
-
/**
|
|
963
|
-
* @param {string} context the compilation context
|
|
964
|
-
* @param {string} name the asset name
|
|
965
|
-
* @param {string | Buffer} content the content
|
|
966
|
-
* @param {(string | RawSourceMap)=} sourceMap an optional source map
|
|
967
|
-
* @param {AssociatedObjectForCache=} associatedObjectForCache object for caching
|
|
968
|
-
* @returns {Source} the created source
|
|
969
|
-
*/
|
|
970
|
-
createSourceForAsset(
|
|
971
|
-
context,
|
|
972
|
-
name,
|
|
973
|
-
content,
|
|
974
|
-
sourceMap,
|
|
975
|
-
associatedObjectForCache
|
|
976
|
-
) {
|
|
977
|
-
if (sourceMap) {
|
|
978
|
-
if (
|
|
979
|
-
typeof sourceMap === "string" &&
|
|
980
|
-
(this.useSourceMap || this.useSimpleSourceMap)
|
|
981
|
-
) {
|
|
982
|
-
return new OriginalSource(
|
|
983
|
-
content,
|
|
984
|
-
contextifySourceUrl(context, sourceMap, associatedObjectForCache)
|
|
985
|
-
);
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
if (this.useSourceMap) {
|
|
989
|
-
return new SourceMapSource(
|
|
990
|
-
content,
|
|
991
|
-
name,
|
|
992
|
-
contextifySourceMap(
|
|
993
|
-
context,
|
|
994
|
-
/** @type {RawSourceMap} */
|
|
995
|
-
(sourceMap),
|
|
996
|
-
associatedObjectForCache
|
|
997
|
-
)
|
|
998
|
-
);
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
return new RawSource(content);
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
/**
|
|
1006
|
-
* @private
|
|
1007
|
-
* @template T
|
|
1008
|
-
* @param {ResolverWithOptions} resolver a resolver
|
|
1009
|
-
* @param {WebpackOptions} options webpack options
|
|
1010
|
-
* @param {Compilation} compilation the compilation
|
|
1011
|
-
* @param {InputFileSystem} fs file system from reading
|
|
1012
|
-
* @param {NormalModuleCompilationHooks} hooks the hooks
|
|
1013
|
-
* @returns {LoaderContext<T>} loader context
|
|
1014
|
-
*/
|
|
1015
|
-
_createLoaderContext(resolver, options, compilation, fs, hooks) {
|
|
1016
|
-
const { requestShortener } = compilation.runtimeTemplate;
|
|
1017
|
-
const getCurrentLoaderName = () => {
|
|
1018
|
-
const currentLoader = this.getCurrentLoader(
|
|
1019
|
-
/** @type {AnyLoaderContext} */
|
|
1020
|
-
(loaderContext)
|
|
1021
|
-
);
|
|
1022
|
-
if (!currentLoader) return "(not in loader scope)";
|
|
1023
|
-
return requestShortener.shorten(currentLoader.loader);
|
|
1024
|
-
};
|
|
1025
|
-
/**
|
|
1026
|
-
* @returns {ResolveContext} resolve context
|
|
1027
|
-
*/
|
|
1028
|
-
const getResolveContext = () => ({
|
|
1029
|
-
fileDependencies: {
|
|
1030
|
-
add: (d) =>
|
|
1031
|
-
/** @type {AnyLoaderContext} */
|
|
1032
|
-
(loaderContext).addDependency(d)
|
|
1033
|
-
},
|
|
1034
|
-
contextDependencies: {
|
|
1035
|
-
add: (d) =>
|
|
1036
|
-
/** @type {AnyLoaderContext} */
|
|
1037
|
-
(loaderContext).addContextDependency(d)
|
|
1038
|
-
},
|
|
1039
|
-
missingDependencies: {
|
|
1040
|
-
add: (d) =>
|
|
1041
|
-
/** @type {AnyLoaderContext} */
|
|
1042
|
-
(loaderContext).addMissingDependency(d)
|
|
1043
|
-
}
|
|
1044
|
-
});
|
|
1045
|
-
const getAbsolutify = memoize(() =>
|
|
1046
|
-
absolutify.bindCache(compilation.compiler.root)
|
|
1047
|
-
);
|
|
1048
|
-
const getAbsolutifyInContext = memoize(() =>
|
|
1049
|
-
absolutify.bindContextCache(
|
|
1050
|
-
/** @type {string} */
|
|
1051
|
-
(this.context),
|
|
1052
|
-
compilation.compiler.root
|
|
1053
|
-
)
|
|
1054
|
-
);
|
|
1055
|
-
const getContextify = memoize(() =>
|
|
1056
|
-
contextify.bindCache(compilation.compiler.root)
|
|
1057
|
-
);
|
|
1058
|
-
const getContextifyInContext = memoize(() =>
|
|
1059
|
-
contextify.bindContextCache(
|
|
1060
|
-
/** @type {string} */
|
|
1061
|
-
(this.context),
|
|
1062
|
-
compilation.compiler.root
|
|
1063
|
-
)
|
|
1064
|
-
);
|
|
1065
|
-
const utils = {
|
|
1066
|
-
/**
|
|
1067
|
-
* @param {string} context context
|
|
1068
|
-
* @param {string} request request
|
|
1069
|
-
* @returns {string} result
|
|
1070
|
-
*/
|
|
1071
|
-
absolutify: (context, request) =>
|
|
1072
|
-
context === this.context
|
|
1073
|
-
? getAbsolutifyInContext()(request)
|
|
1074
|
-
: getAbsolutify()(context, request),
|
|
1075
|
-
/**
|
|
1076
|
-
* @param {string} context context
|
|
1077
|
-
* @param {string} request request
|
|
1078
|
-
* @returns {string} result
|
|
1079
|
-
*/
|
|
1080
|
-
contextify: (context, request) =>
|
|
1081
|
-
context === this.context
|
|
1082
|
-
? getContextifyInContext()(request)
|
|
1083
|
-
: getContextify()(context, request),
|
|
1084
|
-
/**
|
|
1085
|
-
* @param {HashFunction=} type type
|
|
1086
|
-
* @returns {Hash} hash
|
|
1087
|
-
*/
|
|
1088
|
-
createHash: (type) =>
|
|
1089
|
-
createHash(type || compilation.outputOptions.hashFunction)
|
|
1090
|
-
};
|
|
1091
|
-
/** @type {NormalModuleLoaderContext<T>} */
|
|
1092
|
-
const loaderContext = {
|
|
1093
|
-
version: 2,
|
|
1094
|
-
/** @type {LoaderContext<EXPECTED_ANY>["getOptions"]} */
|
|
1095
|
-
getOptions: (/** @type {EXPECTED_ANY} */ schema = undefined) => {
|
|
1096
|
-
const loader = this.getCurrentLoader(
|
|
1097
|
-
/** @type {AnyLoaderContext} */
|
|
1098
|
-
(loaderContext)
|
|
1099
|
-
);
|
|
1100
|
-
|
|
1101
|
-
let { options } = /** @type {LoaderItem} */ (loader);
|
|
1102
|
-
|
|
1103
|
-
if (typeof options === "string") {
|
|
1104
|
-
if (options.startsWith("{") && options.endsWith("}")) {
|
|
1105
|
-
try {
|
|
1106
|
-
options =
|
|
1107
|
-
/** @type {LoaderItem["options"]} */
|
|
1108
|
-
(parseJson(options));
|
|
1109
|
-
} catch (err) {
|
|
1110
|
-
throw new Error(
|
|
1111
|
-
`Cannot parse string options: ${
|
|
1112
|
-
/** @type {Error} */ (err).message
|
|
1113
|
-
}`,
|
|
1114
|
-
{ cause: err }
|
|
1115
|
-
);
|
|
1116
|
-
}
|
|
1117
|
-
} else {
|
|
1118
|
-
options = querystring.parse(options, "&", "=", {
|
|
1119
|
-
maxKeys: 0
|
|
1120
|
-
});
|
|
1121
|
-
}
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
if (options === null || options === undefined) {
|
|
1125
|
-
options = {};
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
if (schema && compilation.options.validate) {
|
|
1129
|
-
let name = "Loader";
|
|
1130
|
-
let baseDataPath = "options";
|
|
1131
|
-
/** @type {RegExpExecArray | null} */
|
|
1132
|
-
let match;
|
|
1133
|
-
if (schema.title && (match = /^(.+) (.+)$/.exec(schema.title))) {
|
|
1134
|
-
[, name, baseDataPath] = match;
|
|
1135
|
-
}
|
|
1136
|
-
getValidate()(schema, /** @type {EXPECTED_OBJECT} */ (options), {
|
|
1137
|
-
name,
|
|
1138
|
-
baseDataPath
|
|
1139
|
-
});
|
|
1140
|
-
}
|
|
1141
|
-
|
|
1142
|
-
return /** @type {T} */ (options);
|
|
1143
|
-
},
|
|
1144
|
-
/** @type {LoaderContext<EXPECTED_ANY>["emitWarning"]} */
|
|
1145
|
-
emitWarning: (warning) => {
|
|
1146
|
-
this.addWarning(
|
|
1147
|
-
new (getModuleWarning())(toError(warning), {
|
|
1148
|
-
from: getCurrentLoaderName()
|
|
1149
|
-
})
|
|
1150
|
-
);
|
|
1151
|
-
},
|
|
1152
|
-
/** @type {LoaderContext<EXPECTED_ANY>["emitError"]} */
|
|
1153
|
-
emitError: (error) => {
|
|
1154
|
-
this.addError(
|
|
1155
|
-
new (getModuleError())(toError(error), {
|
|
1156
|
-
from: getCurrentLoaderName()
|
|
1157
|
-
})
|
|
1158
|
-
);
|
|
1159
|
-
},
|
|
1160
|
-
/** @type {LoaderContext<EXPECTED_ANY>["getLogger"]} */
|
|
1161
|
-
getLogger: (name) => {
|
|
1162
|
-
const currentLoader = this.getCurrentLoader(
|
|
1163
|
-
/** @type {AnyLoaderContext} */
|
|
1164
|
-
(loaderContext)
|
|
1165
|
-
);
|
|
1166
|
-
return compilation.getLogger(() =>
|
|
1167
|
-
[currentLoader && currentLoader.loader, name, this.identifier()]
|
|
1168
|
-
.filter(Boolean)
|
|
1169
|
-
.join("|")
|
|
1170
|
-
);
|
|
1171
|
-
},
|
|
1172
|
-
/** @type {LoaderContext<EXPECTED_ANY>["resolve"]} */
|
|
1173
|
-
resolve(context, request, callback) {
|
|
1174
|
-
resolver.resolve({}, context, request, getResolveContext(), callback);
|
|
1175
|
-
},
|
|
1176
|
-
/** @type {LoaderContext<EXPECTED_ANY>["getResolve"]} */
|
|
1177
|
-
getResolve(options) {
|
|
1178
|
-
const child = options ? resolver.withOptions(options) : resolver;
|
|
1179
|
-
return /** @type {ReturnType<NormalModuleLoaderContext<T>["getResolve"]>} */ (
|
|
1180
|
-
(context, request, callback) => {
|
|
1181
|
-
if (callback) {
|
|
1182
|
-
child.resolve(
|
|
1183
|
-
{},
|
|
1184
|
-
context,
|
|
1185
|
-
request,
|
|
1186
|
-
getResolveContext(),
|
|
1187
|
-
callback
|
|
1188
|
-
);
|
|
1189
|
-
} else {
|
|
1190
|
-
return new Promise((resolve, reject) => {
|
|
1191
|
-
child.resolve(
|
|
1192
|
-
{},
|
|
1193
|
-
context,
|
|
1194
|
-
request,
|
|
1195
|
-
getResolveContext(),
|
|
1196
|
-
(err, result) => {
|
|
1197
|
-
if (err) reject(err);
|
|
1198
|
-
else resolve(result);
|
|
1199
|
-
}
|
|
1200
|
-
);
|
|
1201
|
-
});
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
);
|
|
1205
|
-
},
|
|
1206
|
-
/** @type {LoaderContext<EXPECTED_ANY>["emitFile"]} */
|
|
1207
|
-
emitFile: (name, content, sourceMap, assetInfo) => {
|
|
1208
|
-
const buildInfo = /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
|
|
1209
|
-
|
|
1210
|
-
if (!buildInfo.assets) {
|
|
1211
|
-
buildInfo.assets = Object.create(null);
|
|
1212
|
-
buildInfo.assetsInfo = new Map();
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
const assets =
|
|
1216
|
-
/** @type {NonNullable<KnownBuildInfo["assets"]>} */
|
|
1217
|
-
(buildInfo.assets);
|
|
1218
|
-
const assetsInfo =
|
|
1219
|
-
/** @type {NonNullable<KnownBuildInfo["assetsInfo"]>} */
|
|
1220
|
-
(buildInfo.assetsInfo);
|
|
1221
|
-
|
|
1222
|
-
assets[name] = this.createSourceForAsset(
|
|
1223
|
-
options.context,
|
|
1224
|
-
name,
|
|
1225
|
-
content,
|
|
1226
|
-
sourceMap,
|
|
1227
|
-
compilation.compiler.root
|
|
1228
|
-
);
|
|
1229
|
-
assetsInfo.set(name, assetInfo);
|
|
1230
|
-
},
|
|
1231
|
-
addBuildDependency: (dep) => {
|
|
1232
|
-
const buildInfo = /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
|
|
1233
|
-
|
|
1234
|
-
if (buildInfo.buildDependencies === undefined) {
|
|
1235
|
-
buildInfo.buildDependencies = new LazySet();
|
|
1236
|
-
}
|
|
1237
|
-
buildInfo.buildDependencies.add(dep);
|
|
1238
|
-
},
|
|
1239
|
-
utils,
|
|
1240
|
-
rootContext: options.context,
|
|
1241
|
-
webpack: true,
|
|
1242
|
-
sourceMap: Boolean(this.useSourceMap),
|
|
1243
|
-
mode: options.mode || "production",
|
|
1244
|
-
hashFunction: options.output.hashFunction,
|
|
1245
|
-
hashDigest: options.output.hashDigest,
|
|
1246
|
-
hashDigestLength: options.output.hashDigestLength,
|
|
1247
|
-
hashSalt: options.output.hashSalt,
|
|
1248
|
-
_module: this,
|
|
1249
|
-
_compilation: compilation,
|
|
1250
|
-
_compiler: compilation.compiler,
|
|
1251
|
-
fs
|
|
1252
|
-
};
|
|
1253
|
-
|
|
1254
|
-
Object.assign(loaderContext, options.loader);
|
|
1255
|
-
createLoaderContext(loaderContext);
|
|
1256
|
-
|
|
1257
|
-
hooks.loader.call(
|
|
1258
|
-
/** @type {AnyLoaderContext} */
|
|
1259
|
-
(loaderContext),
|
|
1260
|
-
this
|
|
1261
|
-
);
|
|
1262
|
-
|
|
1263
|
-
return /** @type {AnyLoaderContext} */ (loaderContext);
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
/**
|
|
1267
|
-
* @param {AnyLoaderContext} loaderContext loader context
|
|
1268
|
-
* @param {number} index index
|
|
1269
|
-
* @returns {LoaderItem | null} loader
|
|
1270
|
-
*/
|
|
1271
|
-
getCurrentLoader(loaderContext, index = loaderContext.loaderIndex) {
|
|
1272
|
-
if (
|
|
1273
|
-
this.loaders &&
|
|
1274
|
-
this.loaders.length &&
|
|
1275
|
-
index < this.loaders.length &&
|
|
1276
|
-
index >= 0 &&
|
|
1277
|
-
this.loaders[index]
|
|
1278
|
-
) {
|
|
1279
|
-
return this.loaders[index];
|
|
1280
|
-
}
|
|
1281
|
-
return null;
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
/**
|
|
1285
|
-
* @param {string} context the compilation context
|
|
1286
|
-
* @param {string | Buffer} content the content
|
|
1287
|
-
* @param {(string | RawSourceMap | null)=} sourceMap an optional source map
|
|
1288
|
-
* @param {AssociatedObjectForCache=} associatedObjectForCache object for caching
|
|
1289
|
-
* @returns {Source} the created source
|
|
1290
|
-
*/
|
|
1291
|
-
createSource(context, content, sourceMap, associatedObjectForCache) {
|
|
1292
|
-
if (Buffer.isBuffer(content)) {
|
|
1293
|
-
return new RawSource(content);
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
// if there is no identifier return raw source
|
|
1297
|
-
if (!this.identifier) {
|
|
1298
|
-
return new RawSource(content);
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1301
|
-
// from here on we assume we have an identifier
|
|
1302
|
-
const identifier = this.identifier();
|
|
1303
|
-
|
|
1304
|
-
if (this.useSourceMap && sourceMap) {
|
|
1305
|
-
return new SourceMapSource(
|
|
1306
|
-
content,
|
|
1307
|
-
contextifySourceUrl(context, identifier, associatedObjectForCache),
|
|
1308
|
-
contextifySourceMap(context, sourceMap, associatedObjectForCache)
|
|
1309
|
-
);
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
if (this.useSourceMap || this.useSimpleSourceMap) {
|
|
1313
|
-
return new OriginalSource(
|
|
1314
|
-
content,
|
|
1315
|
-
contextifySourceUrl(context, identifier, associatedObjectForCache)
|
|
1316
|
-
);
|
|
1317
|
-
}
|
|
1318
|
-
|
|
1319
|
-
return new RawSource(content);
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
|
-
/**
|
|
1323
|
-
* @param {WebpackOptions} options webpack options
|
|
1324
|
-
* @param {Compilation} compilation the compilation
|
|
1325
|
-
* @param {ResolverWithOptions} resolver the resolver
|
|
1326
|
-
* @param {InputFileSystem} fs the file system
|
|
1327
|
-
* @param {NormalModuleCompilationHooks} hooks the hooks
|
|
1328
|
-
* @param {BuildCallback} callback callback function
|
|
1329
|
-
* @returns {void}
|
|
1330
|
-
*/
|
|
1331
|
-
_doBuild(options, compilation, resolver, fs, hooks, callback) {
|
|
1332
|
-
const loaderContext = this._createLoaderContext(
|
|
1333
|
-
resolver,
|
|
1334
|
-
options,
|
|
1335
|
-
compilation,
|
|
1336
|
-
fs,
|
|
1337
|
-
hooks
|
|
1338
|
-
);
|
|
1339
|
-
|
|
1340
|
-
/**
|
|
1341
|
-
* @param {Error | null} err err
|
|
1342
|
-
* @param {(Result | null)=} result_ result
|
|
1343
|
-
* @returns {void}
|
|
1344
|
-
*/
|
|
1345
|
-
const processResult = (err, result_) => {
|
|
1346
|
-
if (err) {
|
|
1347
|
-
const currentLoader = this.getCurrentLoader(loaderContext);
|
|
1348
|
-
const error = new (getModuleBuildError())(toError(err), {
|
|
1349
|
-
from:
|
|
1350
|
-
currentLoader &&
|
|
1351
|
-
compilation.runtimeTemplate.requestShortener.shorten(
|
|
1352
|
-
currentLoader.loader
|
|
1353
|
-
)
|
|
1354
|
-
});
|
|
1355
|
-
return callback(error);
|
|
1356
|
-
}
|
|
1357
|
-
hooks.processResult.callAsync(
|
|
1358
|
-
/** @type {Result} */
|
|
1359
|
-
(result_),
|
|
1360
|
-
this,
|
|
1361
|
-
(hookErr, hookResult) => {
|
|
1362
|
-
if (hookErr) {
|
|
1363
|
-
// Named, so a tap's failure is not read as a loader's.
|
|
1364
|
-
return callback(
|
|
1365
|
-
new (getModuleBuildError())(toError(hookErr), {
|
|
1366
|
-
from: "processResult hook"
|
|
1367
|
-
})
|
|
1368
|
-
);
|
|
1369
|
-
}
|
|
1370
|
-
|
|
1371
|
-
finishResult(/** @type {Result} */ (hookResult));
|
|
1372
|
-
}
|
|
1373
|
-
);
|
|
1374
|
-
};
|
|
1375
|
-
|
|
1376
|
-
/**
|
|
1377
|
-
* @param {Result} result the result the hook settled on
|
|
1378
|
-
* @returns {void}
|
|
1379
|
-
*/
|
|
1380
|
-
const finishResult = (result) => {
|
|
1381
|
-
const source = result[0];
|
|
1382
|
-
const sourceMap = result.length >= 1 ? result[1] : null;
|
|
1383
|
-
const extraInfo = result.length >= 2 ? result[2] : null;
|
|
1384
|
-
|
|
1385
|
-
if (!Buffer.isBuffer(source) && typeof source !== "string") {
|
|
1386
|
-
const currentLoader = this.getCurrentLoader(loaderContext, 0);
|
|
1387
|
-
const err = new Error(
|
|
1388
|
-
`Final loader (${
|
|
1389
|
-
currentLoader
|
|
1390
|
-
? compilation.runtimeTemplate.requestShortener.shorten(
|
|
1391
|
-
currentLoader.loader
|
|
1392
|
-
)
|
|
1393
|
-
: "unknown"
|
|
1394
|
-
}) didn't return a Buffer or String`
|
|
1395
|
-
);
|
|
1396
|
-
const error = new (getModuleBuildError())(err);
|
|
1397
|
-
return callback(error);
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
const isBinaryModule =
|
|
1401
|
-
this.generatorOptions && this.generatorOptions.binary !== undefined
|
|
1402
|
-
? this.generatorOptions.binary
|
|
1403
|
-
: this.binary;
|
|
1404
|
-
|
|
1405
|
-
this._source = this.createSource(
|
|
1406
|
-
options.context,
|
|
1407
|
-
isBinaryModule ? asBuffer(source) : asString(source),
|
|
1408
|
-
sourceMap,
|
|
1409
|
-
compilation.compiler.root
|
|
1410
|
-
);
|
|
1411
|
-
if (this._sourceSizes !== undefined) this._sourceSizes.clear();
|
|
1412
|
-
/** @type {PreparsedAst | null} */
|
|
1413
|
-
this._ast =
|
|
1414
|
-
typeof extraInfo === "object" &&
|
|
1415
|
-
extraInfo !== null &&
|
|
1416
|
-
extraInfo.webpackAST !== undefined
|
|
1417
|
-
? extraInfo.webpackAST
|
|
1418
|
-
: null;
|
|
1419
|
-
return callback();
|
|
1420
|
-
};
|
|
1421
|
-
|
|
1422
|
-
const buildInfo = /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
|
|
1423
|
-
|
|
1424
|
-
buildInfo.fileDependencies = new LazySet();
|
|
1425
|
-
buildInfo.contextDependencies = new LazySet();
|
|
1426
|
-
buildInfo.missingDependencies = new LazySet();
|
|
1427
|
-
buildInfo.cacheable = true;
|
|
1428
|
-
|
|
1429
|
-
try {
|
|
1430
|
-
hooks.beforeLoaders.call(
|
|
1431
|
-
this.loaders,
|
|
1432
|
-
this,
|
|
1433
|
-
/** @type {AnyLoaderContext} */
|
|
1434
|
-
(loaderContext)
|
|
1435
|
-
);
|
|
1436
|
-
} catch (err) {
|
|
1437
|
-
processResult(/** @type {Error} */ (err));
|
|
1438
|
-
return;
|
|
1439
|
-
}
|
|
1440
|
-
|
|
1441
|
-
if (this.loaders.length > 0) {
|
|
1442
|
-
/** @type {NormalModuleBuildInfo} */
|
|
1443
|
-
(this.buildInfo).buildDependencies = new LazySet();
|
|
1444
|
-
}
|
|
1445
|
-
|
|
1446
|
-
runLoaders(
|
|
1447
|
-
{
|
|
1448
|
-
resource: this.resource,
|
|
1449
|
-
loaders: this.loaders,
|
|
1450
|
-
context: loaderContext,
|
|
1451
|
-
/**
|
|
1452
|
-
* @param {AnyLoaderContext} loaderContext the loader context
|
|
1453
|
-
* @param {string} resourcePath the resource Path
|
|
1454
|
-
* @param {(err: Error | null, result?: string | Buffer, sourceMap?: Result[1]) => void} callback callback
|
|
1455
|
-
* @returns {Promise<void>}
|
|
1456
|
-
*/
|
|
1457
|
-
processResource: async (loaderContext, resourcePath, callback) => {
|
|
1458
|
-
/** @type {ReadResource} */
|
|
1459
|
-
const readResource = (resourcePath, getLoaderContext) => {
|
|
1460
|
-
const scheme = getScheme(resourcePath);
|
|
1461
|
-
return new Promise((resolve, reject) => {
|
|
1462
|
-
hooks.readResource
|
|
1463
|
-
.for(scheme)
|
|
1464
|
-
.callAsync(getLoaderContext(resourcePath), (err, result) => {
|
|
1465
|
-
if (err) {
|
|
1466
|
-
reject(err);
|
|
1467
|
-
} else {
|
|
1468
|
-
if (typeof result !== "string" && !result) {
|
|
1469
|
-
return reject(
|
|
1470
|
-
new (getUnhandledSchemeError())(
|
|
1471
|
-
/** @type {string} */
|
|
1472
|
-
(scheme),
|
|
1473
|
-
resourcePath
|
|
1474
|
-
)
|
|
1475
|
-
);
|
|
1476
|
-
}
|
|
1477
|
-
resolve(result);
|
|
1478
|
-
}
|
|
1479
|
-
});
|
|
1480
|
-
});
|
|
1481
|
-
};
|
|
1482
|
-
try {
|
|
1483
|
-
const result = await readResource(
|
|
1484
|
-
resourcePath,
|
|
1485
|
-
() => loaderContext
|
|
1486
|
-
);
|
|
1487
|
-
if (
|
|
1488
|
-
this.extractSourceMap &&
|
|
1489
|
-
(this.useSourceMap || this.useSimpleSourceMap)
|
|
1490
|
-
) {
|
|
1491
|
-
try {
|
|
1492
|
-
const { source, sourceMap } = await getExtractSourceMap()(
|
|
1493
|
-
result,
|
|
1494
|
-
resourcePath,
|
|
1495
|
-
/** @type {ReadResource} */
|
|
1496
|
-
(resourcePath) =>
|
|
1497
|
-
readResource(
|
|
1498
|
-
resourcePath,
|
|
1499
|
-
(resourcePath) =>
|
|
1500
|
-
/** @type {AnyLoaderContext} */
|
|
1501
|
-
({
|
|
1502
|
-
addDependency(dependency) {
|
|
1503
|
-
loaderContext.addDependency(dependency);
|
|
1504
|
-
},
|
|
1505
|
-
fs: loaderContext.fs,
|
|
1506
|
-
_module: undefined,
|
|
1507
|
-
resourcePath,
|
|
1508
|
-
resource: resourcePath
|
|
1509
|
-
})
|
|
1510
|
-
).catch((err) => {
|
|
1511
|
-
throw new Error(
|
|
1512
|
-
`Failed to parse source map. ${
|
|
1513
|
-
/** @type {Error} */ (err).message
|
|
1514
|
-
}`
|
|
1515
|
-
);
|
|
1516
|
-
})
|
|
1517
|
-
);
|
|
1518
|
-
return callback(null, source, sourceMap);
|
|
1519
|
-
} catch (err) {
|
|
1520
|
-
this.addWarning(
|
|
1521
|
-
new (getModuleWarning())(/** @type {Error} */ (err))
|
|
1522
|
-
);
|
|
1523
|
-
return callback(null, result);
|
|
1524
|
-
}
|
|
1525
|
-
}
|
|
1526
|
-
return callback(null, result);
|
|
1527
|
-
} catch (error) {
|
|
1528
|
-
return callback(/** @type {Error} */ (error));
|
|
1529
|
-
}
|
|
1530
|
-
}
|
|
1531
|
-
},
|
|
1532
|
-
(err, result) => {
|
|
1533
|
-
// Cleanup loaderContext to avoid leaking memory in ICs
|
|
1534
|
-
loaderContext._compilation =
|
|
1535
|
-
loaderContext._compiler =
|
|
1536
|
-
loaderContext._module =
|
|
1537
|
-
loaderContext.fs =
|
|
1538
|
-
/** @type {EXPECTED_ANY} */
|
|
1539
|
-
(undefined);
|
|
1540
|
-
|
|
1541
|
-
if (!result) {
|
|
1542
|
-
/** @type {NormalModuleBuildInfo} */
|
|
1543
|
-
(this.buildInfo).cacheable = false;
|
|
1544
|
-
return processResult(
|
|
1545
|
-
err || new Error("No result from loader-runner processing"),
|
|
1546
|
-
null
|
|
1547
|
-
);
|
|
1548
|
-
}
|
|
1549
|
-
|
|
1550
|
-
const buildInfo = /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
|
|
1551
|
-
|
|
1552
|
-
const fileDependencies =
|
|
1553
|
-
/** @type {NonNullable<KnownNormalModuleBuildInfo["fileDependencies"]>} */
|
|
1554
|
-
(buildInfo.fileDependencies);
|
|
1555
|
-
const contextDependencies =
|
|
1556
|
-
/** @type {NonNullable<KnownNormalModuleBuildInfo["contextDependencies"]>} */
|
|
1557
|
-
(buildInfo.contextDependencies);
|
|
1558
|
-
const missingDependencies =
|
|
1559
|
-
/** @type {NonNullable<KnownNormalModuleBuildInfo["missingDependencies"]>} */
|
|
1560
|
-
(buildInfo.missingDependencies);
|
|
1561
|
-
|
|
1562
|
-
fileDependencies.addAll(result.fileDependencies);
|
|
1563
|
-
contextDependencies.addAll(result.contextDependencies);
|
|
1564
|
-
missingDependencies.addAll(result.missingDependencies);
|
|
1565
|
-
for (const loader of this.loaders) {
|
|
1566
|
-
const buildDependencies =
|
|
1567
|
-
/** @type {NonNullable<KnownNormalModuleBuildInfo["buildDependencies"]>} */
|
|
1568
|
-
(buildInfo.buildDependencies);
|
|
1569
|
-
|
|
1570
|
-
buildDependencies.add(loader.loader);
|
|
1571
|
-
}
|
|
1572
|
-
buildInfo.cacheable = buildInfo.cacheable && result.cacheable;
|
|
1573
|
-
if (result.notCacheableReasons.length > 0) {
|
|
1574
|
-
getBuildDiagnostics(buildInfo).notCacheableReasons =
|
|
1575
|
-
result.notCacheableReasons;
|
|
1576
|
-
}
|
|
1577
|
-
processResult(err, result.result);
|
|
1578
|
-
}
|
|
1579
|
-
);
|
|
1580
|
-
}
|
|
1581
|
-
|
|
1582
|
-
/**
|
|
1583
|
-
* Marks the module as failed, so what it generates says so. A tap or a
|
|
1584
|
-
* loader may fail with anything, and what reads the failure expects an error.
|
|
1585
|
-
* @param {EXPECTED_ANY} error what the module failed with
|
|
1586
|
-
* @returns {void}
|
|
1587
|
-
*/
|
|
1588
|
-
markModuleAsErrored(error) {
|
|
1589
|
-
// Restore build meta from successful build to keep importing state
|
|
1590
|
-
this.buildMeta = { ...this._lastSuccessfulBuildMeta };
|
|
1591
|
-
this.error = toError(error);
|
|
1592
|
-
this.addError(this.error);
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
|
-
/**
|
|
1596
|
-
* @param {Exclude<NoParse, EXPECTED_ANY[]>} rule rule
|
|
1597
|
-
* @param {string} content content
|
|
1598
|
-
* @returns {boolean} result
|
|
1599
|
-
*/
|
|
1600
|
-
applyNoParseRule(rule, content) {
|
|
1601
|
-
// must start with "rule" if rule is a string
|
|
1602
|
-
if (typeof rule === "string") {
|
|
1603
|
-
return content.startsWith(rule);
|
|
1604
|
-
}
|
|
1605
|
-
|
|
1606
|
-
if (typeof rule === "function") {
|
|
1607
|
-
return rule(content);
|
|
1608
|
-
}
|
|
1609
|
-
// we assume rule is a regexp
|
|
1610
|
-
return rule.test(content);
|
|
1611
|
-
}
|
|
1612
|
-
|
|
1613
|
-
/**
|
|
1614
|
-
* @param {undefined | NoParse} noParseRule no parse rule
|
|
1615
|
-
* @param {string} request request
|
|
1616
|
-
* @returns {boolean} check if module should not be parsed, returns "true" if the module should !not! be parsed, returns "false" if the module !must! be parsed
|
|
1617
|
-
*/
|
|
1618
|
-
shouldPreventParsing(noParseRule, request) {
|
|
1619
|
-
// if no noParseRule exists, return false
|
|
1620
|
-
// the module !must! be parsed.
|
|
1621
|
-
if (!noParseRule) {
|
|
1622
|
-
return false;
|
|
1623
|
-
}
|
|
1624
|
-
|
|
1625
|
-
// we only have one rule to check
|
|
1626
|
-
if (!Array.isArray(noParseRule)) {
|
|
1627
|
-
// returns "true" if the module is !not! to be parsed
|
|
1628
|
-
return this.applyNoParseRule(noParseRule, request);
|
|
1629
|
-
}
|
|
1630
|
-
|
|
1631
|
-
for (let i = 0; i < noParseRule.length; i++) {
|
|
1632
|
-
const rule = noParseRule[i];
|
|
1633
|
-
// early exit on first truthy match
|
|
1634
|
-
// this module is !not! to be parsed
|
|
1635
|
-
if (this.applyNoParseRule(rule, request)) {
|
|
1636
|
-
return true;
|
|
1637
|
-
}
|
|
1638
|
-
}
|
|
1639
|
-
// no match found, so this module !should! be parsed
|
|
1640
|
-
return false;
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
/**
|
|
1644
|
-
* @param {Compilation} compilation compilation
|
|
1645
|
-
* @private
|
|
1646
|
-
*/
|
|
1647
|
-
_initBuildHash(compilation) {
|
|
1648
|
-
const hash = createHash(compilation.outputOptions.hashFunction);
|
|
1649
|
-
if (this._source) {
|
|
1650
|
-
hash.update("source");
|
|
1651
|
-
this._source.updateHash(hash);
|
|
1652
|
-
}
|
|
1653
|
-
hash.update("meta");
|
|
1654
|
-
hash.update(JSON.stringify(this.buildMeta));
|
|
1655
|
-
/** @type {NormalModuleBuildInfo} */
|
|
1656
|
-
(this.buildInfo).hash = hash.digest("hex");
|
|
1657
|
-
}
|
|
1658
|
-
|
|
1659
|
-
/**
|
|
1660
|
-
* Builds the module using the provided compilation context.
|
|
1661
|
-
* @param {WebpackOptions} options webpack options
|
|
1662
|
-
* @param {Compilation} compilation the compilation
|
|
1663
|
-
* @param {ResolverWithOptions} resolver the resolver
|
|
1664
|
-
* @param {InputFileSystem} fs the file system
|
|
1665
|
-
* @param {BuildCallback} callback callback function
|
|
1666
|
-
* @returns {void}
|
|
1667
|
-
*/
|
|
1668
|
-
build(options, compilation, resolver, fs, callback) {
|
|
1669
|
-
this._forceBuild = false;
|
|
1670
|
-
this._source = null;
|
|
1671
|
-
if (this._sourceSizes !== undefined) this._sourceSizes.clear();
|
|
1672
|
-
this._sourceTypes = undefined;
|
|
1673
|
-
this._ast = null;
|
|
1674
|
-
this.error = null;
|
|
1675
|
-
this.clearWarningsAndErrors();
|
|
1676
|
-
this.clearDependenciesAndBlocks();
|
|
1677
|
-
this.buildMeta = {
|
|
1678
|
-
exportsType: undefined,
|
|
1679
|
-
defaultObject: undefined,
|
|
1680
|
-
strictHarmonyModule: undefined,
|
|
1681
|
-
async: undefined
|
|
1682
|
-
};
|
|
1683
|
-
this.buildInfo = {
|
|
1684
|
-
cacheable: false,
|
|
1685
|
-
parsed: true,
|
|
1686
|
-
fileDependencies: undefined,
|
|
1687
|
-
contextDependencies: undefined,
|
|
1688
|
-
missingDependencies: undefined,
|
|
1689
|
-
buildDependencies: undefined,
|
|
1690
|
-
valueDependencies: undefined,
|
|
1691
|
-
hash: undefined,
|
|
1692
|
-
assets: undefined,
|
|
1693
|
-
assetsInfo: undefined,
|
|
1694
|
-
snapshot: undefined,
|
|
1695
|
-
strict: undefined,
|
|
1696
|
-
exportsArgument: undefined,
|
|
1697
|
-
moduleArgument: undefined,
|
|
1698
|
-
topLevelDeclarations: undefined,
|
|
1699
|
-
pureFunctions: undefined,
|
|
1700
|
-
inlineExports: undefined,
|
|
1701
|
-
moduleConcatenationBailout: undefined,
|
|
1702
|
-
moduleConcatenationRootBailout: undefined,
|
|
1703
|
-
diagnostics: undefined,
|
|
1704
|
-
needCreateRequire: undefined,
|
|
1705
|
-
usesTopLevelUsingDeclaration: undefined
|
|
1706
|
-
};
|
|
1707
|
-
|
|
1708
|
-
const startTime = compilation.compiler.fsStartTime || Date.now();
|
|
1709
|
-
|
|
1710
|
-
const hooks = NormalModule.getCompilationHooks(compilation);
|
|
1711
|
-
|
|
1712
|
-
return this._doBuild(options, compilation, resolver, fs, hooks, (err) => {
|
|
1713
|
-
// if we have an error mark module as failed and exit
|
|
1714
|
-
if (err) {
|
|
1715
|
-
this.markModuleAsErrored(err);
|
|
1716
|
-
this._initBuildHash(compilation);
|
|
1717
|
-
return callback();
|
|
1718
|
-
}
|
|
1719
|
-
|
|
1720
|
-
/**
|
|
1721
|
-
* @param {Error} e error
|
|
1722
|
-
* @returns {void}
|
|
1723
|
-
*/
|
|
1724
|
-
const handleParseError = (e) => {
|
|
1725
|
-
const source = /** @type {Source} */ (this._source).source();
|
|
1726
|
-
const loaders = this.loaders.map((item) =>
|
|
1727
|
-
contextify(options.context, item.loader, compilation.compiler.root)
|
|
1728
|
-
);
|
|
1729
|
-
const error = new (getModuleParseError())(
|
|
1730
|
-
source,
|
|
1731
|
-
e,
|
|
1732
|
-
loaders,
|
|
1733
|
-
this.type
|
|
1734
|
-
);
|
|
1735
|
-
this.markModuleAsErrored(error);
|
|
1736
|
-
this._initBuildHash(compilation);
|
|
1737
|
-
return callback();
|
|
1738
|
-
};
|
|
1739
|
-
|
|
1740
|
-
const handleParseResult = () => {
|
|
1741
|
-
this.dependencies.sort(
|
|
1742
|
-
concatComparators(
|
|
1743
|
-
Dependency.compareLocations,
|
|
1744
|
-
keepOriginalOrder(this.dependencies)
|
|
1745
|
-
)
|
|
1746
|
-
);
|
|
1747
|
-
sortWithSourceOrder(this.dependencies, new WeakMap());
|
|
1748
|
-
this._initBuildHash(compilation);
|
|
1749
|
-
this._lastSuccessfulBuildMeta =
|
|
1750
|
-
/** @type {BuildMeta} */
|
|
1751
|
-
(this.buildMeta);
|
|
1752
|
-
return handleBuildDone();
|
|
1753
|
-
};
|
|
1754
|
-
|
|
1755
|
-
const handleBuildDone = () => {
|
|
1756
|
-
try {
|
|
1757
|
-
hooks.beforeSnapshot.call(this);
|
|
1758
|
-
} catch (err) {
|
|
1759
|
-
this.markModuleAsErrored(err);
|
|
1760
|
-
return callback();
|
|
1761
|
-
}
|
|
1762
|
-
|
|
1763
|
-
const snapshotOptions = compilation.options.snapshot.module;
|
|
1764
|
-
const { cacheable } = /** @type {NormalModuleBuildInfo} */ (
|
|
1765
|
-
this.buildInfo
|
|
1766
|
-
);
|
|
1767
|
-
if (!cacheable || !snapshotOptions) {
|
|
1768
|
-
return callback();
|
|
1769
|
-
}
|
|
1770
|
-
// add warning for all non-absolute paths in fileDependencies, etc
|
|
1771
|
-
// This makes it easier to find problems with watching and/or caching
|
|
1772
|
-
/** @type {undefined | Set<string>} */
|
|
1773
|
-
let nonAbsoluteDependencies;
|
|
1774
|
-
/**
|
|
1775
|
-
* @param {FileSystemDependencies} deps deps
|
|
1776
|
-
*/
|
|
1777
|
-
const checkDependencies = (deps) => {
|
|
1778
|
-
for (const dep of deps) {
|
|
1779
|
-
if (!ABSOLUTE_PATH_REGEXP.test(dep)) {
|
|
1780
|
-
if (nonAbsoluteDependencies === undefined) {
|
|
1781
|
-
nonAbsoluteDependencies = new Set();
|
|
1782
|
-
}
|
|
1783
|
-
nonAbsoluteDependencies.add(dep);
|
|
1784
|
-
deps.delete(dep);
|
|
1785
|
-
try {
|
|
1786
|
-
const depWithoutGlob = dep.replace(/[\\/]?\*.*$/, "");
|
|
1787
|
-
const absolute = join(
|
|
1788
|
-
compilation.fileSystemInfo.fs,
|
|
1789
|
-
/** @type {string} */
|
|
1790
|
-
(this.context),
|
|
1791
|
-
depWithoutGlob
|
|
1792
|
-
);
|
|
1793
|
-
if (absolute !== dep && ABSOLUTE_PATH_REGEXP.test(absolute)) {
|
|
1794
|
-
(depWithoutGlob !== dep
|
|
1795
|
-
? /** @type {NonNullable<KnownNormalModuleBuildInfo["contextDependencies"]>} */
|
|
1796
|
-
(
|
|
1797
|
-
/** @type {NormalModuleBuildInfo} */
|
|
1798
|
-
(this.buildInfo).contextDependencies
|
|
1799
|
-
)
|
|
1800
|
-
: deps
|
|
1801
|
-
).add(absolute);
|
|
1802
|
-
}
|
|
1803
|
-
} catch (_err) {
|
|
1804
|
-
// ignore
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
};
|
|
1809
|
-
const buildInfo = /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
|
|
1810
|
-
const fileDependencies =
|
|
1811
|
-
/** @type {NonNullable<KnownNormalModuleBuildInfo["fileDependencies"]>} */
|
|
1812
|
-
(buildInfo.fileDependencies);
|
|
1813
|
-
const contextDependencies =
|
|
1814
|
-
/** @type {NonNullable<KnownNormalModuleBuildInfo["contextDependencies"]>} */
|
|
1815
|
-
(buildInfo.contextDependencies);
|
|
1816
|
-
const missingDependencies =
|
|
1817
|
-
/** @type {NonNullable<KnownNormalModuleBuildInfo["missingDependencies"]>} */
|
|
1818
|
-
(buildInfo.missingDependencies);
|
|
1819
|
-
checkDependencies(fileDependencies);
|
|
1820
|
-
checkDependencies(missingDependencies);
|
|
1821
|
-
checkDependencies(contextDependencies);
|
|
1822
|
-
if (nonAbsoluteDependencies !== undefined) {
|
|
1823
|
-
const InvalidDependenciesModuleWarning =
|
|
1824
|
-
getInvalidDependenciesModuleWarning();
|
|
1825
|
-
this.addWarning(
|
|
1826
|
-
new InvalidDependenciesModuleWarning(this, nonAbsoluteDependencies)
|
|
1827
|
-
);
|
|
1828
|
-
}
|
|
1829
|
-
// convert file/context/missingDependencies into filesystem snapshot
|
|
1830
|
-
compilation.fileSystemInfo.createSnapshot(
|
|
1831
|
-
startTime,
|
|
1832
|
-
fileDependencies,
|
|
1833
|
-
contextDependencies,
|
|
1834
|
-
missingDependencies,
|
|
1835
|
-
snapshotOptions,
|
|
1836
|
-
(err, snapshot) => {
|
|
1837
|
-
if (err) {
|
|
1838
|
-
this.markModuleAsErrored(err);
|
|
1839
|
-
return;
|
|
1840
|
-
}
|
|
1841
|
-
buildInfo.fileDependencies = undefined;
|
|
1842
|
-
buildInfo.contextDependencies = undefined;
|
|
1843
|
-
buildInfo.missingDependencies = undefined;
|
|
1844
|
-
buildInfo.snapshot = snapshot;
|
|
1845
|
-
return callback();
|
|
1846
|
-
}
|
|
1847
|
-
);
|
|
1848
|
-
};
|
|
1849
|
-
|
|
1850
|
-
try {
|
|
1851
|
-
hooks.beforeParse.call(this);
|
|
1852
|
-
} catch (err) {
|
|
1853
|
-
this.markModuleAsErrored(err);
|
|
1854
|
-
this._initBuildHash(compilation);
|
|
1855
|
-
return callback();
|
|
1856
|
-
}
|
|
1857
|
-
|
|
1858
|
-
// check if this module should !not! be parsed.
|
|
1859
|
-
// if so, exit here;
|
|
1860
|
-
const noParseRule = options.module && options.module.noParse;
|
|
1861
|
-
if (this.shouldPreventParsing(noParseRule, this.request)) {
|
|
1862
|
-
// We assume that we need module and exports
|
|
1863
|
-
/** @type {NormalModuleBuildInfo} */
|
|
1864
|
-
(this.buildInfo).parsed = false;
|
|
1865
|
-
this._initBuildHash(compilation);
|
|
1866
|
-
return handleBuildDone();
|
|
1867
|
-
}
|
|
1868
|
-
|
|
1869
|
-
try {
|
|
1870
|
-
const source = /** @type {Source} */ (this._source).source();
|
|
1871
|
-
/** @type {Parser} */
|
|
1872
|
-
(this.parser).parse(this._ast || source, {
|
|
1873
|
-
source,
|
|
1874
|
-
current: this,
|
|
1875
|
-
module: this,
|
|
1876
|
-
compilation,
|
|
1877
|
-
options,
|
|
1878
|
-
harmonyNamedExports: undefined,
|
|
1879
|
-
harmonyStarExports: undefined,
|
|
1880
|
-
lastHarmonyImportOrder: undefined,
|
|
1881
|
-
localModules: undefined
|
|
1882
|
-
});
|
|
1883
|
-
} catch (parseErr) {
|
|
1884
|
-
handleParseError(/** @type {Error} */ (parseErr));
|
|
1885
|
-
return;
|
|
1886
|
-
}
|
|
1887
|
-
handleParseResult();
|
|
1888
|
-
});
|
|
1889
|
-
}
|
|
1890
|
-
|
|
1891
|
-
/**
|
|
1892
|
-
* Returns the reason this module cannot be concatenated, when one exists.
|
|
1893
|
-
* @param {ConcatenationBailoutReasonContext} context context
|
|
1894
|
-
* @returns {string | undefined} reason why this module can't be concatenated, undefined when it can be concatenated
|
|
1895
|
-
*/
|
|
1896
|
-
getConcatenationBailoutReason(context) {
|
|
1897
|
-
return /** @type {Generator} */ (
|
|
1898
|
-
this.generator
|
|
1899
|
-
).getConcatenationBailoutReason(this, context);
|
|
1900
|
-
}
|
|
1901
|
-
|
|
1902
|
-
/**
|
|
1903
|
-
* Gets side effects connection state.
|
|
1904
|
-
* @param {ModuleGraph} moduleGraph the module graph
|
|
1905
|
-
* @returns {ConnectionState} how this module should be connected to referencing modules when consumed for side-effects only
|
|
1906
|
-
*/
|
|
1907
|
-
getSideEffectsConnectionState(moduleGraph) {
|
|
1908
|
-
// Each call owns its Tarjan bookkeeping; re-entrant calls (e.g.
|
|
1909
|
-
// `ConcatenatedModule.getSideEffectsConnectionState` delegating back
|
|
1910
|
-
// through here) can't clobber the outer walk.
|
|
1911
|
-
return walkSideEffects(
|
|
1912
|
-
this,
|
|
1913
|
-
moduleGraph,
|
|
1914
|
-
HarmonyImportSideEffectDependency
|
|
1915
|
-
);
|
|
1916
|
-
}
|
|
1917
|
-
|
|
1918
|
-
/**
|
|
1919
|
-
* Returns the source types this module can generate.
|
|
1920
|
-
* @returns {SourceTypes} types available (do not mutate)
|
|
1921
|
-
*/
|
|
1922
|
-
getSourceTypes() {
|
|
1923
|
-
if (this._sourceTypes === undefined) {
|
|
1924
|
-
this._sourceTypes = /** @type {Generator} */ (this.generator).getTypes(
|
|
1925
|
-
this
|
|
1926
|
-
);
|
|
1927
|
-
}
|
|
1928
|
-
return this._sourceTypes;
|
|
1929
|
-
}
|
|
1930
|
-
|
|
1931
|
-
/**
|
|
1932
|
-
* Freshly recomputed source types when they depend on incoming connections, for chunk-graph cache invalidation; undefined otherwise. #20800
|
|
1933
|
-
* @returns {SourceTypes | undefined} source types or undefined
|
|
1934
|
-
*/
|
|
1935
|
-
getReferencedSourceTypes() {
|
|
1936
|
-
const generator = /** @type {Generator} */ (this.generator);
|
|
1937
|
-
// Bypass the _sourceTypes cache: it may be stale when the module is not rebuilt.
|
|
1938
|
-
return generator.getTypesDependOnIncomingConnections()
|
|
1939
|
-
? generator.getTypes(this)
|
|
1940
|
-
: undefined;
|
|
1941
|
-
}
|
|
1942
|
-
|
|
1943
|
-
/**
|
|
1944
|
-
* Generates code and runtime requirements for this module.
|
|
1945
|
-
* @param {CodeGenerationContext} context context for code generation
|
|
1946
|
-
* @returns {CodeGenerationResult} result
|
|
1947
|
-
*/
|
|
1948
|
-
codeGeneration({
|
|
1949
|
-
dependencyTemplates,
|
|
1950
|
-
runtimeTemplate,
|
|
1951
|
-
moduleGraph,
|
|
1952
|
-
chunkGraph,
|
|
1953
|
-
runtime,
|
|
1954
|
-
concatenationScope,
|
|
1955
|
-
codeGenerationResults,
|
|
1956
|
-
sourceTypes
|
|
1957
|
-
}) {
|
|
1958
|
-
/** @type {RuntimeRequirements} */
|
|
1959
|
-
const runtimeRequirements = new Set();
|
|
1960
|
-
|
|
1961
|
-
const { parsed } = /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
|
|
1962
|
-
|
|
1963
|
-
if (!parsed) {
|
|
1964
|
-
runtimeRequirements.add(RuntimeGlobals.module);
|
|
1965
|
-
runtimeRequirements.add(RuntimeGlobals.exports);
|
|
1966
|
-
runtimeRequirements.add(RuntimeGlobals.thisAsExports);
|
|
1967
|
-
}
|
|
1968
|
-
|
|
1969
|
-
/** @type {CodeGenerationResult} */
|
|
1970
|
-
const resultEntry = {
|
|
1971
|
-
sources: new Map(),
|
|
1972
|
-
runtimeRequirements,
|
|
1973
|
-
data: undefined,
|
|
1974
|
-
hash: undefined
|
|
1975
|
-
};
|
|
1976
|
-
|
|
1977
|
-
const getData = () => {
|
|
1978
|
-
if (resultEntry.data === undefined) resultEntry.data = new Map();
|
|
1979
|
-
return resultEntry.data;
|
|
1980
|
-
};
|
|
1981
|
-
|
|
1982
|
-
for (const type of sourceTypes || chunkGraph.getModuleSourceTypes(this)) {
|
|
1983
|
-
// TODO webpack@6 make generateError required
|
|
1984
|
-
const generator =
|
|
1985
|
-
/** @type {Generator & { generateError?: GenerateErrorFn }} */
|
|
1986
|
-
(this.generator);
|
|
1987
|
-
const source = this.error
|
|
1988
|
-
? generator.generateError
|
|
1989
|
-
? generator.generateError(this.error, this, {
|
|
1990
|
-
dependencyTemplates,
|
|
1991
|
-
runtimeTemplate,
|
|
1992
|
-
moduleGraph,
|
|
1993
|
-
chunkGraph,
|
|
1994
|
-
runtimeRequirements,
|
|
1995
|
-
runtime,
|
|
1996
|
-
concatenationScope,
|
|
1997
|
-
codeGenerationResults,
|
|
1998
|
-
getData,
|
|
1999
|
-
type
|
|
2000
|
-
})
|
|
2001
|
-
: new RawSource(
|
|
2002
|
-
getGenerator().throwBuildErrorCode(
|
|
2003
|
-
this.error,
|
|
2004
|
-
undefined,
|
|
2005
|
-
runtimeTemplate.requestShortener
|
|
2006
|
-
)
|
|
2007
|
-
)
|
|
2008
|
-
: generator.generate(this, {
|
|
2009
|
-
dependencyTemplates,
|
|
2010
|
-
runtimeTemplate,
|
|
2011
|
-
moduleGraph,
|
|
2012
|
-
chunkGraph,
|
|
2013
|
-
runtimeRequirements,
|
|
2014
|
-
runtime,
|
|
2015
|
-
concatenationScope,
|
|
2016
|
-
codeGenerationResults,
|
|
2017
|
-
getData,
|
|
2018
|
-
type
|
|
2019
|
-
});
|
|
2020
|
-
|
|
2021
|
-
if (source) {
|
|
2022
|
-
resultEntry.sources.set(type, new CachedSource(source));
|
|
2023
|
-
}
|
|
2024
|
-
}
|
|
2025
|
-
|
|
2026
|
-
return resultEntry;
|
|
2027
|
-
}
|
|
2028
|
-
|
|
2029
|
-
/**
|
|
2030
|
-
* Gets the original source.
|
|
2031
|
-
* @returns {Source | null} the original source for the module before webpack transformation
|
|
2032
|
-
*/
|
|
2033
|
-
originalSource() {
|
|
2034
|
-
return this._source;
|
|
2035
|
-
}
|
|
2036
|
-
|
|
2037
|
-
/**
|
|
2038
|
-
* Invalidates the cached state associated with this value.
|
|
2039
|
-
* @returns {void}
|
|
2040
|
-
*/
|
|
2041
|
-
invalidateBuild() {
|
|
2042
|
-
this._forceBuild = true;
|
|
2043
|
-
}
|
|
2044
|
-
|
|
2045
|
-
/**
|
|
2046
|
-
* Checks whether the module needs to be rebuilt for the current build state.
|
|
2047
|
-
* @param {NeedBuildContext} context context info
|
|
2048
|
-
* @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild
|
|
2049
|
-
* @returns {void}
|
|
2050
|
-
*/
|
|
2051
|
-
needBuild(context, callback) {
|
|
2052
|
-
const { fileSystemInfo, compilation, valueCacheVersions } = context;
|
|
2053
|
-
// build if enforced
|
|
2054
|
-
if (this._forceBuild) return callback(null, true);
|
|
2055
|
-
|
|
2056
|
-
// always try to build in case of an error
|
|
2057
|
-
if (this.error) return callback(null, true);
|
|
2058
|
-
|
|
2059
|
-
const { cacheable, snapshot, valueDependencies } =
|
|
2060
|
-
/** @type {NormalModuleBuildInfo} */ (this.buildInfo);
|
|
2061
|
-
|
|
2062
|
-
// always build when module is not cacheable
|
|
2063
|
-
if (!cacheable) return callback(null, true);
|
|
2064
|
-
|
|
2065
|
-
// build when there is no snapshot to check
|
|
2066
|
-
if (!snapshot) return callback(null, true);
|
|
2067
|
-
|
|
2068
|
-
// build when valueDependencies have changed
|
|
2069
|
-
if (valueDependencies) {
|
|
2070
|
-
if (!valueCacheVersions) return callback(null, true);
|
|
2071
|
-
for (const [key, value] of valueDependencies) {
|
|
2072
|
-
if (value === undefined) return callback(null, true);
|
|
2073
|
-
const current = valueCacheVersions.get(key);
|
|
2074
|
-
if (
|
|
2075
|
-
value !== current &&
|
|
2076
|
-
(typeof value === "string" ||
|
|
2077
|
-
typeof current === "string" ||
|
|
2078
|
-
current === undefined ||
|
|
2079
|
-
!isSubset(value, current))
|
|
2080
|
-
) {
|
|
2081
|
-
return callback(null, true);
|
|
2082
|
-
}
|
|
2083
|
-
}
|
|
2084
|
-
}
|
|
2085
|
-
|
|
2086
|
-
// check snapshot for validity
|
|
2087
|
-
fileSystemInfo.checkSnapshotValid(snapshot, (err, valid) => {
|
|
2088
|
-
if (err) return callback(err);
|
|
2089
|
-
if (!valid) return callback(null, true);
|
|
2090
|
-
const hooks = NormalModule.getCompilationHooks(compilation);
|
|
2091
|
-
hooks.needBuild.callAsync(this, context, (err, needBuild) => {
|
|
2092
|
-
if (err) {
|
|
2093
|
-
return callback(
|
|
2094
|
-
HookWebpackError.makeWebpackError(
|
|
2095
|
-
err,
|
|
2096
|
-
"NormalModule.getCompilationHooks().needBuild"
|
|
2097
|
-
)
|
|
2098
|
-
);
|
|
2099
|
-
}
|
|
2100
|
-
callback(null, Boolean(needBuild));
|
|
2101
|
-
});
|
|
2102
|
-
});
|
|
2103
|
-
}
|
|
2104
|
-
|
|
2105
|
-
/**
|
|
2106
|
-
* Returns the estimated size for the requested source type.
|
|
2107
|
-
* @param {string=} type the source type for which the size should be estimated
|
|
2108
|
-
* @returns {number} the estimated size of the module (must be non-zero)
|
|
2109
|
-
*/
|
|
2110
|
-
size(type) {
|
|
2111
|
-
const cachedSize =
|
|
2112
|
-
this._sourceSizes === undefined ? undefined : this._sourceSizes.get(type);
|
|
2113
|
-
if (cachedSize !== undefined) {
|
|
2114
|
-
return cachedSize;
|
|
2115
|
-
}
|
|
2116
|
-
const size = Math.max(
|
|
2117
|
-
1,
|
|
2118
|
-
/** @type {Generator} */ (this.generator).getSize(this, type)
|
|
2119
|
-
);
|
|
2120
|
-
if (this._sourceSizes === undefined) {
|
|
2121
|
-
this._sourceSizes = new Map();
|
|
2122
|
-
}
|
|
2123
|
-
this._sourceSizes.set(type, size);
|
|
2124
|
-
return size;
|
|
2125
|
-
}
|
|
2126
|
-
|
|
2127
|
-
/**
|
|
2128
|
-
* Adds the provided file dependencies to the module.
|
|
2129
|
-
* @param {FileSystemDependencies} fileDependencies set where file dependencies are added to
|
|
2130
|
-
* @param {FileSystemDependencies} contextDependencies set where context dependencies are added to
|
|
2131
|
-
* @param {FileSystemDependencies} missingDependencies set where missing dependencies are added to
|
|
2132
|
-
* @param {FileSystemDependencies} buildDependencies set where build dependencies are added to
|
|
2133
|
-
*/
|
|
2134
|
-
addCacheDependencies(
|
|
2135
|
-
fileDependencies,
|
|
2136
|
-
contextDependencies,
|
|
2137
|
-
missingDependencies,
|
|
2138
|
-
buildDependencies
|
|
2139
|
-
) {
|
|
2140
|
-
const { snapshot, buildDependencies: buildDeps } =
|
|
2141
|
-
/** @type {NormalModuleBuildInfo} */ (this.buildInfo);
|
|
2142
|
-
if (snapshot) {
|
|
2143
|
-
fileDependencies.addAll(snapshot.getFileIterable());
|
|
2144
|
-
contextDependencies.addAll(snapshot.getContextIterable());
|
|
2145
|
-
missingDependencies.addAll(snapshot.getMissingIterable());
|
|
2146
|
-
} else {
|
|
2147
|
-
const {
|
|
2148
|
-
fileDependencies: fileDeps,
|
|
2149
|
-
contextDependencies: contextDeps,
|
|
2150
|
-
missingDependencies: missingDeps
|
|
2151
|
-
} = /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
|
|
2152
|
-
if (fileDeps !== undefined) fileDependencies.addAll(fileDeps);
|
|
2153
|
-
if (contextDeps !== undefined) contextDependencies.addAll(contextDeps);
|
|
2154
|
-
if (missingDeps !== undefined) missingDependencies.addAll(missingDeps);
|
|
2155
|
-
}
|
|
2156
|
-
if (buildDeps !== undefined) {
|
|
2157
|
-
buildDependencies.addAll(buildDeps);
|
|
2158
|
-
}
|
|
2159
|
-
}
|
|
2160
|
-
|
|
2161
|
-
/**
|
|
2162
|
-
* Updates the hash with the data contributed by this instance.
|
|
2163
|
-
* @param {Hash} hash the hash used to track dependencies
|
|
2164
|
-
* @param {UpdateHashContext} context context
|
|
2165
|
-
* @returns {void}
|
|
2166
|
-
*/
|
|
2167
|
-
updateHash(hash, context) {
|
|
2168
|
-
const buildInfo = /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
|
|
2169
|
-
hash.update(
|
|
2170
|
-
/** @type {string} */
|
|
2171
|
-
(buildInfo.hash)
|
|
2172
|
-
);
|
|
2173
|
-
// Recompute the source types, so a change in the incoming connections reaches
|
|
2174
|
-
// the hash and invalidates the code-generation cache.
|
|
2175
|
-
// https://github.com/webpack/webpack/issues/20800
|
|
2176
|
-
this._sourceTypes = undefined;
|
|
2177
|
-
for (const type of this.getSourceTypes()) {
|
|
2178
|
-
hash.update(type);
|
|
2179
|
-
}
|
|
2180
|
-
/** @type {Generator} */
|
|
2181
|
-
(this.generator).updateHash(hash, {
|
|
2182
|
-
module: this,
|
|
2183
|
-
...context
|
|
2184
|
-
});
|
|
2185
|
-
super.updateHash(hash, context);
|
|
2186
|
-
}
|
|
2187
|
-
|
|
2188
|
-
/**
|
|
2189
|
-
* Serializes this instance into the provided serializer context.
|
|
2190
|
-
* @param {ObjectSerializerContext} context context
|
|
2191
|
-
*/
|
|
2192
|
-
serialize(context) {
|
|
2193
|
-
const { write } = context;
|
|
2194
|
-
// deserialize
|
|
2195
|
-
write(this._source);
|
|
2196
|
-
write(this.error);
|
|
2197
|
-
write(this._lastSuccessfulBuildMeta);
|
|
2198
|
-
write(this._forceBuild);
|
|
2199
|
-
write(this.hot);
|
|
2200
|
-
super.serialize(context);
|
|
2201
|
-
}
|
|
2202
|
-
|
|
2203
|
-
/**
|
|
2204
|
-
* @param {ObjectDeserializerContext} context context
|
|
2205
|
-
* @returns {NormalModule} module
|
|
2206
|
-
*/
|
|
2207
|
-
static deserialize(context) {
|
|
2208
|
-
// `new this` so subclasses without extra constructor options inherit this method
|
|
2209
|
-
const obj = new this({
|
|
2210
|
-
// will be deserialized by Module
|
|
2211
|
-
layer: /** @type {EXPECTED_ANY} */ (null),
|
|
2212
|
-
type: "",
|
|
2213
|
-
// will be filled by updateCacheModule
|
|
2214
|
-
resource: "",
|
|
2215
|
-
context: "",
|
|
2216
|
-
request: /** @type {EXPECTED_ANY} */ (null),
|
|
2217
|
-
userRequest: /** @type {EXPECTED_ANY} */ (null),
|
|
2218
|
-
rawRequest: /** @type {EXPECTED_ANY} */ (null),
|
|
2219
|
-
loaders: /** @type {EXPECTED_ANY} */ (null),
|
|
2220
|
-
matchResource: /** @type {EXPECTED_ANY} */ (null),
|
|
2221
|
-
parser: /** @type {EXPECTED_ANY} */ (null),
|
|
2222
|
-
parserOptions: /** @type {EXPECTED_ANY} */ (null),
|
|
2223
|
-
generator: /** @type {EXPECTED_ANY} */ (null),
|
|
2224
|
-
generatorOptions: /** @type {EXPECTED_ANY} */ (null),
|
|
2225
|
-
resolveOptions: undefined,
|
|
2226
|
-
extractSourceMap: /** @type {EXPECTED_ANY} */ (null)
|
|
2227
|
-
});
|
|
2228
|
-
obj.deserialize(context);
|
|
2229
|
-
return obj;
|
|
2230
|
-
}
|
|
2231
|
-
|
|
2232
|
-
/**
|
|
2233
|
-
* Restores this instance from the provided deserializer context.
|
|
2234
|
-
* @param {ObjectDeserializerContext} context context
|
|
2235
|
-
*/
|
|
2236
|
-
deserialize(context) {
|
|
2237
|
-
const { read } = context;
|
|
2238
|
-
this._source = read();
|
|
2239
|
-
this.error = read();
|
|
2240
|
-
this._lastSuccessfulBuildMeta = read();
|
|
2241
|
-
this._forceBuild = read();
|
|
2242
|
-
this.hot = read();
|
|
2243
|
-
super.deserialize(context);
|
|
2244
|
-
}
|
|
2245
|
-
}
|
|
2246
|
-
|
|
2247
|
-
makeSerializable(NormalModule, "webpack/lib/NormalModule");
|
|
2248
|
-
|
|
2249
|
-
module.exports = NormalModule;
|
|
8
|
+
// TODO in the next major release: remove
|
|
9
|
+
// Some old plugins use `require("webpack/lib/NormalModule")`, in the next major release developer should migrate to `compiler.webpack.NormalModule`
|
|
10
|
+
module.exports = require("./module/NormalModule");
|