webpack 5.59.0 → 5.94.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -38
- package/bin/webpack.js +34 -10
- package/hot/dev-server.js +19 -5
- package/hot/lazy-compilation-node.js +13 -1
- package/hot/lazy-compilation-web.js +9 -0
- package/hot/log-apply-result.js +5 -0
- package/hot/log.js +23 -4
- package/hot/only-dev-server.js +3 -2
- package/hot/poll.js +5 -2
- package/hot/signal.js +6 -2
- package/lib/APIPlugin.js +226 -122
- package/lib/AbstractMethodError.js +10 -5
- package/lib/AsyncDependenciesBlock.js +13 -5
- package/lib/AutomaticPrefetchPlugin.js +2 -1
- package/lib/BannerPlugin.js +33 -12
- package/lib/Cache.js +16 -12
- package/lib/CacheFacade.js +13 -16
- package/lib/CaseSensitiveModulesWarning.js +8 -8
- package/lib/Chunk.js +60 -33
- package/lib/ChunkGraph.js +207 -72
- package/lib/ChunkGroup.js +40 -20
- package/lib/ChunkTemplate.js +43 -0
- package/lib/CleanPlugin.js +117 -32
- package/lib/CodeGenerationResults.js +8 -7
- package/lib/CommentCompilationWarning.js +0 -1
- package/lib/CompatibilityPlugin.js +85 -46
- package/lib/Compilation.js +712 -392
- package/lib/Compiler.js +393 -172
- package/lib/ConcatenationScope.js +10 -13
- package/lib/ConditionalInitFragment.js +22 -14
- package/lib/ConstPlugin.js +104 -64
- package/lib/ContextExclusionPlugin.js +3 -3
- package/lib/ContextModule.js +283 -108
- package/lib/ContextModuleFactory.js +151 -63
- package/lib/ContextReplacementPlugin.js +25 -10
- package/lib/CssModule.js +166 -0
- package/lib/DefinePlugin.js +254 -148
- package/lib/DelegatedModule.js +29 -6
- package/lib/DelegatedModuleFactoryPlugin.js +42 -22
- package/lib/DelegatedPlugin.js +4 -0
- package/lib/DependenciesBlock.js +17 -2
- package/lib/Dependency.js +58 -29
- package/lib/DependencyTemplate.js +24 -3
- package/lib/DependencyTemplates.js +2 -2
- package/lib/DllEntryPlugin.js +18 -1
- package/lib/DllModule.js +21 -4
- package/lib/DllModuleFactory.js +2 -1
- package/lib/DllPlugin.js +9 -7
- package/lib/DllReferencePlugin.js +50 -19
- package/lib/EntryOptionPlugin.js +6 -1
- package/lib/EntryPlugin.js +7 -4
- package/lib/Entrypoint.js +2 -2
- package/lib/EnvironmentNotSupportAsyncWarning.js +52 -0
- package/lib/EnvironmentPlugin.js +5 -2
- package/lib/ErrorHelpers.js +65 -26
- package/lib/EvalDevToolModulePlugin.js +37 -13
- package/lib/EvalSourceMapDevToolPlugin.js +50 -20
- package/lib/ExportsInfo.js +234 -133
- package/lib/ExportsInfoApiPlugin.js +31 -15
- package/lib/ExternalModule.js +391 -129
- package/lib/ExternalModuleFactoryPlugin.js +65 -17
- package/lib/FileSystemInfo.js +1038 -523
- package/lib/FlagAllModulesAsUsedPlugin.js +27 -27
- package/lib/FlagDependencyExportsPlugin.js +352 -349
- package/lib/FlagDependencyUsagePlugin.js +10 -10
- package/lib/FlagEntryExportAsUsedPlugin.js +26 -23
- package/lib/Generator.js +16 -8
- package/lib/GraphHelpers.js +3 -2
- package/lib/HookWebpackError.js +11 -13
- package/lib/HotModuleReplacementPlugin.js +221 -128
- package/lib/IgnoreErrorModuleFactory.js +4 -4
- package/lib/IgnorePlugin.js +5 -4
- package/lib/IgnoreWarningsPlugin.js +6 -9
- package/lib/InitFragment.js +39 -15
- package/lib/JavascriptMetaInfoPlugin.js +27 -15
- package/lib/LibManifestPlugin.js +45 -16
- package/lib/LoaderOptionsPlugin.js +13 -3
- package/lib/MainTemplate.js +74 -21
- package/lib/Module.js +155 -34
- package/lib/ModuleBuildError.js +13 -11
- package/lib/ModuleDependencyError.js +6 -4
- package/lib/ModuleDependencyWarning.js +6 -4
- package/lib/ModuleError.js +10 -5
- package/lib/ModuleFactory.js +4 -4
- package/lib/ModuleFilenameHelpers.js +164 -54
- package/lib/ModuleGraph.js +93 -53
- package/lib/ModuleGraphConnection.js +27 -13
- package/lib/ModuleHashingError.js +29 -0
- package/lib/ModuleInfoHeaderPlugin.js +92 -33
- package/lib/ModuleNotFoundError.js +5 -2
- package/lib/ModuleParseError.js +17 -9
- package/lib/ModuleProfile.js +1 -0
- package/lib/ModuleRestoreError.js +3 -1
- package/lib/ModuleStoreError.js +3 -2
- package/lib/ModuleTemplate.js +33 -1
- package/lib/ModuleTypeConstants.js +168 -0
- package/lib/ModuleWarning.js +10 -5
- package/lib/MultiCompiler.js +115 -38
- package/lib/MultiStats.js +75 -33
- package/lib/MultiWatching.js +6 -2
- package/lib/NodeStuffPlugin.js +136 -37
- package/lib/NormalModule.js +437 -194
- package/lib/NormalModuleFactory.js +313 -116
- package/lib/NormalModuleReplacementPlugin.js +10 -4
- package/lib/NullFactory.js +1 -1
- package/lib/OptimizationStages.js +3 -3
- package/lib/Parser.js +1 -1
- package/lib/PlatformPlugin.js +39 -0
- package/lib/PrefetchPlugin.js +4 -0
- package/lib/ProgressPlugin.js +83 -28
- package/lib/ProvidePlugin.js +37 -19
- package/lib/RawModule.js +18 -5
- package/lib/RecordIdsPlugin.js +8 -8
- package/lib/RequireJsStuffPlugin.js +22 -15
- package/lib/ResolverFactory.js +8 -4
- package/lib/RuntimeGlobals.js +99 -65
- package/lib/RuntimeModule.js +17 -15
- package/lib/RuntimePlugin.js +116 -13
- package/lib/RuntimeTemplate.js +304 -102
- package/lib/SelfModuleFactory.js +12 -0
- package/lib/SizeFormatHelpers.js +2 -4
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
- package/lib/SourceMapDevToolPlugin.js +89 -42
- package/lib/Stats.js +12 -7
- package/lib/Template.js +30 -33
- package/lib/TemplatedPathPlugin.js +102 -34
- package/lib/UseStrictPlugin.js +37 -12
- package/lib/WarnCaseSensitiveModulesPlugin.js +12 -0
- package/lib/WarnDeprecatedOptionPlugin.js +6 -0
- package/lib/WatchIgnorePlugin.js +46 -13
- package/lib/Watching.js +139 -76
- package/lib/WebpackError.js +14 -5
- package/lib/WebpackIsIncludedPlugin.js +22 -13
- package/lib/WebpackOptionsApply.js +162 -56
- package/lib/WebpackOptionsDefaulter.js +10 -3
- package/lib/asset/AssetGenerator.js +351 -99
- package/lib/asset/AssetModulesPlugin.js +57 -33
- package/lib/asset/AssetParser.js +15 -6
- package/lib/asset/AssetSourceGenerator.js +30 -10
- package/lib/asset/AssetSourceParser.js +8 -2
- package/lib/asset/RawDataUrlModule.js +162 -0
- package/lib/async-modules/AwaitDependenciesInitFragment.js +16 -13
- package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
- package/lib/buildChunkGraph.js +376 -420
- package/lib/cache/AddManagedPathsPlugin.js +6 -1
- package/lib/cache/IdleFileCachePlugin.js +26 -13
- package/lib/cache/MemoryCachePlugin.js +1 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +13 -7
- package/lib/cache/PackFileCacheStrategy.js +172 -94
- package/lib/cache/ResolverCachePlugin.js +115 -43
- package/lib/cache/getLazyHashedEtag.js +2 -2
- package/lib/cache/mergeEtags.js +16 -21
- package/lib/cli.js +195 -110
- package/lib/config/browserslistTargetHandler.js +106 -41
- package/lib/config/defaults.js +572 -154
- package/lib/config/normalization.js +361 -322
- package/lib/config/target.js +105 -66
- package/lib/container/ContainerEntryDependency.js +2 -1
- package/lib/container/ContainerEntryModule.js +27 -11
- package/lib/container/ContainerEntryModuleFactory.js +1 -1
- package/lib/container/ContainerExposedDependency.js +9 -0
- package/lib/container/ContainerPlugin.js +18 -12
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackDependency.js +13 -0
- package/lib/container/FallbackItemDependency.js +3 -0
- package/lib/container/FallbackModule.js +19 -8
- package/lib/container/FallbackModuleFactory.js +1 -1
- package/lib/container/ModuleFederationPlugin.js +2 -0
- package/lib/container/RemoteModule.js +17 -4
- package/lib/container/RemoteRuntimeModule.js +31 -17
- package/lib/container/RemoteToExternalDependency.js +3 -0
- package/lib/container/options.js +18 -4
- package/lib/css/CssExportsGenerator.js +203 -0
- package/lib/css/CssGenerator.js +151 -0
- package/lib/css/CssLoadingRuntimeModule.js +592 -0
- package/lib/css/CssModulesPlugin.js +888 -0
- package/lib/css/CssParser.js +1049 -0
- package/lib/css/walkCssTokens.js +775 -0
- package/lib/debug/ProfilingPlugin.js +102 -54
- package/lib/dependencies/AMDDefineDependency.js +54 -10
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +204 -61
- package/lib/dependencies/AMDPlugin.js +44 -24
- package/lib/dependencies/AMDRequireArrayDependency.js +34 -10
- package/lib/dependencies/AMDRequireContextDependency.js +15 -0
- package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +185 -54
- package/lib/dependencies/AMDRequireDependency.js +21 -6
- package/lib/dependencies/AMDRequireItemDependency.js +6 -0
- package/lib/dependencies/AMDRuntimeModules.js +4 -4
- package/lib/dependencies/CachedConstDependency.js +22 -1
- package/lib/dependencies/CommonJsDependencyHelpers.js +16 -2
- package/lib/dependencies/CommonJsExportRequireDependency.js +77 -47
- package/lib/dependencies/CommonJsExportsDependency.js +28 -5
- package/lib/dependencies/CommonJsExportsParserPlugin.js +111 -39
- package/lib/dependencies/CommonJsFullRequireDependency.js +42 -8
- package/lib/dependencies/CommonJsImportsParserPlugin.js +530 -130
- package/lib/dependencies/CommonJsPlugin.js +51 -26
- package/lib/dependencies/CommonJsRequireContextDependency.js +23 -2
- package/lib/dependencies/CommonJsRequireDependency.js +9 -1
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -8
- package/lib/dependencies/ConstDependency.js +12 -3
- package/lib/dependencies/ContextDependency.js +32 -5
- package/lib/dependencies/ContextDependencyHelpers.js +92 -62
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
- package/lib/dependencies/ContextElementDependency.js +41 -4
- package/lib/dependencies/CreateScriptUrlDependency.js +22 -1
- package/lib/dependencies/CriticalDependencyWarning.js +4 -1
- package/lib/dependencies/CssExportDependency.js +156 -0
- package/lib/dependencies/CssImportDependency.js +125 -0
- package/lib/dependencies/CssLocalIdentifierDependency.js +245 -0
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +111 -0
- package/lib/dependencies/CssUrlDependency.js +164 -0
- package/lib/dependencies/DelegatedSourceDependency.js +3 -0
- package/lib/dependencies/DllEntryDependency.js +14 -0
- package/lib/dependencies/DynamicExports.js +15 -11
- package/lib/dependencies/ExportsInfoDependency.js +26 -5
- package/lib/dependencies/ExternalModuleDependency.js +109 -0
- package/lib/dependencies/ExternalModuleInitFragment.js +133 -0
- package/lib/dependencies/HarmonyAcceptDependency.js +11 -2
- package/lib/dependencies/HarmonyAcceptImportDependency.js +9 -4
- package/lib/dependencies/HarmonyCompatibilityDependency.js +6 -5
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +29 -3
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +152 -0
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +96 -51
- package/lib/dependencies/HarmonyExportExpressionDependency.js +21 -4
- package/lib/dependencies/HarmonyExportHeaderDependency.js +13 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +216 -108
- package/lib/dependencies/HarmonyExportInitFragment.js +21 -9
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +12 -0
- package/lib/dependencies/HarmonyExports.js +13 -7
- package/lib/dependencies/HarmonyImportDependency.js +65 -19
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +268 -74
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +11 -5
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +180 -36
- package/lib/dependencies/HarmonyModulesPlugin.js +33 -5
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
- package/lib/dependencies/ImportContextDependency.js +15 -2
- package/lib/dependencies/ImportDependency.js +50 -12
- package/lib/dependencies/ImportEagerDependency.js +11 -6
- package/lib/dependencies/ImportMetaContextDependency.js +42 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +301 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +72 -0
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
- package/lib/dependencies/ImportMetaPlugin.js +128 -59
- package/lib/dependencies/ImportParserPlugin.js +153 -83
- package/lib/dependencies/ImportPlugin.js +21 -7
- package/lib/dependencies/ImportWeakDependency.js +11 -6
- package/lib/dependencies/JsonExportsDependency.js +38 -30
- package/lib/dependencies/LoaderDependency.js +14 -0
- package/lib/dependencies/LoaderImportDependency.js +14 -0
- package/lib/dependencies/LoaderPlugin.js +54 -40
- package/lib/dependencies/LocalModule.js +17 -1
- package/lib/dependencies/LocalModuleDependency.js +15 -0
- package/lib/dependencies/LocalModulesHelpers.js +22 -4
- package/lib/dependencies/ModuleDecoratorDependency.js +9 -1
- package/lib/dependencies/ModuleDependency.js +24 -7
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
- package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
- package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
- package/lib/dependencies/PrefetchDependency.js +3 -0
- package/lib/dependencies/ProvidedDependency.js +43 -8
- package/lib/dependencies/PureExpressionDependency.js +73 -39
- package/lib/dependencies/RequireContextDependency.js +6 -16
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +14 -6
- package/lib/dependencies/RequireContextPlugin.js +20 -7
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +7 -0
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +29 -12
- package/lib/dependencies/RequireEnsureDependency.js +16 -2
- package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
- package/lib/dependencies/RequireEnsurePlugin.js +27 -7
- package/lib/dependencies/RequireHeaderDependency.js +14 -1
- package/lib/dependencies/RequireIncludeDependency.js +6 -1
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +29 -5
- package/lib/dependencies/RequireIncludePlugin.js +25 -5
- package/lib/dependencies/RequireResolveContextDependency.js +19 -2
- package/lib/dependencies/RequireResolveDependency.js +8 -1
- package/lib/dependencies/RequireResolveHeaderDependency.js +18 -0
- package/lib/dependencies/RuntimeRequirementsDependency.js +9 -1
- package/lib/dependencies/StaticExportsDependency.js +8 -0
- package/lib/dependencies/SystemPlugin.js +49 -22
- package/lib/dependencies/SystemRuntimeModule.js +1 -1
- package/lib/dependencies/URLDependency.js +20 -13
- package/lib/dependencies/URLPlugin.js +115 -27
- package/lib/dependencies/UnsupportedDependency.js +13 -0
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +14 -0
- package/lib/dependencies/WebAssemblyImportDependency.js +9 -1
- package/lib/dependencies/WebpackIsIncludedDependency.js +6 -1
- package/lib/dependencies/WorkerDependency.js +47 -3
- package/lib/dependencies/WorkerPlugin.js +143 -59
- package/lib/dependencies/getFunctionExpression.js +9 -0
- package/lib/dependencies/processExportInfo.js +3 -1
- package/lib/electron/ElectronTargetPlugin.js +1 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +3 -2
- package/lib/esm/ModuleChunkFormatPlugin.js +92 -55
- package/lib/esm/ModuleChunkLoadingPlugin.js +12 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +141 -25
- package/lib/formatLocation.js +1 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +37 -25
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +2 -1
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +13 -15
- package/lib/hmr/LazyCompilationPlugin.js +94 -41
- package/lib/hmr/lazyCompilationBackend.js +107 -44
- package/lib/ids/ChunkModuleIdRangePlugin.js +12 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +13 -6
- package/lib/ids/DeterministicModuleIdsPlugin.js +59 -35
- package/lib/ids/HashedModuleIdsPlugin.js +24 -16
- package/lib/ids/IdHelpers.js +59 -49
- package/lib/ids/NamedChunkIdsPlugin.js +13 -1
- package/lib/ids/NamedModuleIdsPlugin.js +20 -12
- package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
- package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +14 -11
- package/lib/ids/SyncModuleIdsPlugin.js +146 -0
- package/lib/index.js +44 -5
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +9 -7
- package/lib/javascript/BasicEvaluatedExpression.js +133 -19
- package/lib/javascript/ChunkHelpers.js +33 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +18 -15
- package/lib/javascript/EnableChunkLoadingPlugin.js +11 -6
- package/lib/javascript/JavascriptGenerator.js +37 -6
- package/lib/javascript/JavascriptModulesPlugin.js +523 -295
- package/lib/javascript/JavascriptParser.js +1591 -574
- package/lib/javascript/JavascriptParserHelpers.js +58 -37
- package/lib/javascript/StartupHelpers.js +69 -47
- package/lib/json/JsonData.js +33 -0
- package/lib/json/JsonGenerator.js +29 -21
- package/lib/json/JsonModulesPlugin.js +13 -7
- package/lib/json/JsonParser.js +30 -16
- package/lib/library/AbstractLibraryPlugin.js +6 -2
- package/lib/library/AmdLibraryPlugin.js +34 -18
- package/lib/library/AssignLibraryPlugin.js +68 -32
- package/lib/library/EnableLibraryPlugin.js +39 -14
- package/lib/library/ExportPropertyLibraryPlugin.js +14 -5
- package/lib/library/JsonpLibraryPlugin.js +4 -3
- package/lib/library/ModernModuleLibraryPlugin.js +144 -0
- package/lib/library/ModuleLibraryPlugin.js +12 -7
- package/lib/library/SystemLibraryPlugin.js +6 -4
- package/lib/library/UmdLibraryPlugin.js +119 -100
- package/lib/logging/Logger.js +59 -6
- package/lib/logging/createConsoleLogger.js +25 -40
- package/lib/logging/runtime.js +8 -9
- package/lib/logging/truncateArgs.js +9 -8
- package/lib/node/CommonJsChunkLoadingPlugin.js +18 -2
- package/lib/node/NodeEnvironmentPlugin.js +14 -8
- package/lib/node/NodeTargetPlugin.js +7 -0
- package/lib/node/NodeTemplatePlugin.js +10 -2
- package/lib/node/NodeWatchFileSystem.js +100 -50
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +51 -26
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +13 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +21 -3
- package/lib/node/RequireChunkLoadingRuntimeModule.js +49 -26
- package/lib/node/nodeConsole.js +48 -31
- package/lib/optimize/AggressiveMergingPlugin.js +10 -4
- package/lib/optimize/AggressiveSplittingPlugin.js +26 -21
- package/lib/optimize/ConcatenatedModule.js +353 -212
- package/lib/optimize/EnsureChunkConditionsPlugin.js +4 -1
- package/lib/optimize/FlagIncludedChunksPlugin.js +14 -8
- package/lib/optimize/InnerGraph.js +30 -25
- package/lib/optimize/InnerGraphPlugin.js +105 -64
- package/lib/optimize/LimitChunkCountPlugin.js +32 -9
- package/lib/optimize/MangleExportsPlugin.js +7 -2
- package/lib/optimize/MinMaxSizeWarning.js +6 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +150 -83
- package/lib/optimize/RealContentHashPlugin.js +99 -43
- package/lib/optimize/RemoveParentModulesPlugin.js +131 -48
- package/lib/optimize/RuntimeChunkPlugin.js +15 -2
- package/lib/optimize/SideEffectsFlagPlugin.js +119 -63
- package/lib/optimize/SplitChunksPlugin.js +129 -78
- package/lib/performance/SizeLimitsPlugin.js +22 -8
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +4 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +8 -5
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +5 -3
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +5 -3
- package/lib/rules/BasicEffectRulePlugin.js +7 -1
- package/lib/rules/BasicMatcherRulePlugin.js +8 -1
- package/lib/rules/ObjectMatcherRulePlugin.js +19 -2
- package/lib/rules/RuleSetCompiler.js +53 -32
- package/lib/rules/UseEffectRulePlugin.js +42 -36
- package/lib/runtime/AsyncModuleRuntimeModule.js +56 -69
- package/lib/runtime/AutoPublicPathRuntimeModule.js +25 -9
- package/lib/runtime/BaseUriRuntimeModule.js +35 -0
- package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
- package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
- package/lib/runtime/CompatRuntimeModule.js +7 -2
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +7 -4
- package/lib/runtime/CreateScriptRuntimeModule.js +38 -0
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +13 -36
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +6 -3
- package/lib/runtime/EnsureChunkRuntimeModule.js +29 -15
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +56 -43
- package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
- package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +98 -0
- package/lib/runtime/GlobalRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
- package/lib/runtime/LoadScriptRuntimeModule.js +61 -45
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
- package/lib/runtime/NonceRuntimeModule.js +24 -0
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
- package/lib/runtime/PublicPathRuntimeModule.js +9 -2
- package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
- package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
- package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +36 -28
- package/lib/runtime/StartupEntrypointRuntimeModule.js +13 -9
- package/lib/runtime/SystemContextRuntimeModule.js +1 -1
- package/lib/schemes/DataUriPlugin.js +16 -3
- package/lib/schemes/HttpUriPlugin.js +336 -120
- package/lib/serialization/ArraySerializer.js +22 -6
- package/lib/serialization/BinaryMiddleware.js +212 -33
- package/lib/serialization/DateObjectSerializer.js +16 -4
- package/lib/serialization/ErrorObjectSerializer.js +23 -6
- package/lib/serialization/FileMiddleware.js +187 -86
- package/lib/serialization/MapObjectSerializer.js +25 -8
- package/lib/serialization/NullPrototypeObjectSerializer.js +26 -8
- package/lib/serialization/ObjectMiddleware.js +96 -66
- package/lib/serialization/PlainObjectSerializer.js +51 -14
- package/lib/serialization/RegExpObjectSerializer.js +17 -5
- package/lib/serialization/Serializer.js +23 -5
- package/lib/serialization/SerializerMiddleware.js +8 -8
- package/lib/serialization/SetObjectSerializer.js +22 -6
- package/lib/serialization/SingleItemMiddleware.js +2 -2
- package/lib/serialization/types.js +2 -2
- package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
- package/lib/sharing/ConsumeSharedModule.js +40 -17
- package/lib/sharing/ConsumeSharedPlugin.js +139 -102
- package/lib/sharing/ConsumeSharedRuntimeModule.js +144 -130
- package/lib/sharing/ProvideForSharedDependency.js +0 -1
- package/lib/sharing/ProvideSharedDependency.js +17 -0
- package/lib/sharing/ProvideSharedModule.js +19 -6
- package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +37 -30
- package/lib/sharing/SharePlugin.js +2 -2
- package/lib/sharing/ShareRuntimeModule.js +20 -10
- package/lib/sharing/resolveMatchedConfigs.js +6 -5
- package/lib/sharing/utils.js +338 -34
- package/lib/stats/DefaultStatsFactoryPlugin.js +660 -396
- package/lib/stats/DefaultStatsPresetPlugin.js +85 -25
- package/lib/stats/DefaultStatsPrinterPlugin.js +525 -145
- package/lib/stats/StatsFactory.js +128 -57
- package/lib/stats/StatsPrinter.js +77 -46
- package/lib/util/ArrayHelpers.js +35 -1
- package/lib/util/ArrayQueue.js +15 -22
- package/lib/util/AsyncQueue.js +37 -16
- package/lib/util/IterableHelpers.js +3 -4
- package/lib/util/LazyBucketSortedSet.js +60 -44
- package/lib/util/LazySet.js +11 -2
- package/lib/util/MapHelpers.js +17 -5
- package/lib/util/ParallelismFactorCalculator.js +11 -1
- package/lib/util/Queue.js +9 -3
- package/lib/util/Semaphore.js +4 -7
- package/lib/util/SetHelpers.js +5 -5
- package/lib/util/SortableSet.js +19 -6
- package/lib/util/StackedCacheMap.js +33 -3
- package/lib/util/StackedMap.js +1 -3
- package/lib/util/StringXor.js +46 -0
- package/lib/util/TupleQueue.js +9 -3
- package/lib/util/TupleSet.js +15 -5
- package/lib/util/URLAbsoluteSpecifier.js +8 -8
- package/lib/util/WeakTupleMap.js +70 -28
- package/lib/util/binarySearchBounds.js +51 -9
- package/lib/util/chainedImports.js +97 -0
- package/lib/util/cleverMerge.js +51 -36
- package/lib/util/comparators.js +146 -83
- package/lib/util/compileBooleanMatcher.js +35 -7
- package/lib/util/conventions.js +126 -0
- package/lib/util/create-schema-validation.js +9 -2
- package/lib/util/createHash.js +49 -14
- package/lib/util/deprecation.js +48 -15
- package/lib/util/deterministicGrouping.js +71 -39
- package/lib/util/extractUrlAndGlobal.js +3 -0
- package/lib/util/findGraphRoots.js +7 -5
- package/lib/util/fs.js +419 -94
- package/lib/util/hash/BatchedHash.js +10 -4
- package/lib/util/hash/md4.js +20 -0
- package/lib/util/hash/wasm-hash.js +163 -0
- package/lib/util/hash/xxhash64.js +7 -141
- package/lib/util/identifier.js +140 -93
- package/lib/util/internalSerializables.js +22 -0
- package/lib/util/makeSerializable.js +7 -0
- package/lib/util/memoize.js +10 -10
- package/lib/util/mergeScope.js +76 -0
- package/lib/util/nonNumericOnlyHash.js +22 -0
- package/lib/util/numberHash.js +84 -34
- package/lib/util/objectToMap.js +0 -1
- package/lib/util/processAsyncTree.js +7 -1
- package/lib/util/propertyAccess.js +7 -55
- package/lib/util/propertyName.js +77 -0
- package/lib/util/registerExternalSerializer.js +2 -2
- package/lib/util/runtime.js +188 -133
- package/lib/util/semver.js +64 -56
- package/lib/util/serialization.js +26 -1
- package/lib/util/smartGrouping.js +10 -10
- package/lib/util/source.js +1 -1
- package/lib/validateSchema.js +6 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +9 -4
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +70 -30
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +34 -16
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +32 -12
- package/lib/wasm-async/AsyncWebAssemblyParser.js +17 -4
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +72 -31
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +17 -6
- package/lib/wasm-sync/WebAssemblyGenerator.js +72 -52
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -4
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +53 -43
- package/lib/wasm-sync/WebAssemblyParser.js +23 -9
- package/lib/wasm-sync/WebAssemblyUtils.js +5 -4
- package/lib/web/FetchCompileAsyncWasmPlugin.js +11 -1
- package/lib/web/FetchCompileWasmPlugin.js +59 -42
- package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +71 -41
- package/lib/webpack.js +43 -12
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +15 -12
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +55 -40
- package/module.d.ts +233 -0
- package/package.json +85 -139
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +679 -47
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/BannerPlugin.json +9 -1
- package/schemas/plugins/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +10 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +2 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +12 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssAutoParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssAutoParserOptions.json +3 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGlobalGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssGlobalParserOptions.json +3 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssParserOptions.json +3 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
- package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
- package/types.d.ts +5026 -1756
package/lib/Compiler.js
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
-
const parseJson = require("json-parse-better-errors");
|
8
|
+
const parseJson = require("json-parse-even-better-errors");
|
9
9
|
const asyncLib = require("neo-async");
|
10
10
|
const {
|
11
11
|
SyncHook,
|
@@ -14,7 +14,7 @@ const {
|
|
14
14
|
AsyncSeriesHook
|
15
15
|
} = require("tapable");
|
16
16
|
const { SizeOnlySource } = require("webpack-sources");
|
17
|
-
const webpack = require("
|
17
|
+
const webpack = require(".");
|
18
18
|
const Cache = require("./Cache");
|
19
19
|
const CacheFacade = require("./CacheFacade");
|
20
20
|
const ChunkGraph = require("./ChunkGraph");
|
@@ -40,37 +40,54 @@ const { isSourceEqual } = require("./util/source");
|
|
40
40
|
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
41
41
|
/** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
|
42
42
|
/** @typedef {import("./Chunk")} Chunk */
|
43
|
+
/** @typedef {import("./Compilation").References} References */
|
43
44
|
/** @typedef {import("./Dependency")} Dependency */
|
44
45
|
/** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
|
45
46
|
/** @typedef {import("./Module")} Module */
|
46
|
-
/** @typedef {import("./
|
47
|
+
/** @typedef {import("./Module").BuildInfo} BuildInfo */
|
48
|
+
/** @typedef {import("./config/target").PlatformTargetProperties} PlatformTargetProperties */
|
49
|
+
/** @typedef {import("./logging/createConsoleLogger").LoggingFunction} LoggingFunction */
|
50
|
+
/** @typedef {import("./util/fs").IStats} IStats */
|
47
51
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
48
52
|
/** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
49
53
|
/** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
|
50
54
|
/** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */
|
51
55
|
|
52
56
|
/**
|
53
|
-
* @
|
57
|
+
* @template {any[]} T
|
58
|
+
* @template V
|
59
|
+
* @typedef {import("./util/WeakTupleMap")<T, V>} WeakTupleMap
|
60
|
+
*/
|
61
|
+
|
62
|
+
/**
|
63
|
+
* @typedef {object} CompilationParams
|
54
64
|
* @property {NormalModuleFactory} normalModuleFactory
|
55
65
|
* @property {ContextModuleFactory} contextModuleFactory
|
56
66
|
*/
|
57
67
|
|
68
|
+
/**
|
69
|
+
* @template T
|
70
|
+
* @callback RunCallback
|
71
|
+
* @param {Error | null} err
|
72
|
+
* @param {T=} result
|
73
|
+
*/
|
74
|
+
|
58
75
|
/**
|
59
76
|
* @template T
|
60
77
|
* @callback Callback
|
61
|
-
* @param {Error=} err
|
78
|
+
* @param {(Error | null)=} err
|
62
79
|
* @param {T=} result
|
63
80
|
*/
|
64
81
|
|
65
82
|
/**
|
66
83
|
* @callback RunAsChildCallback
|
67
|
-
* @param {Error
|
84
|
+
* @param {Error | null} err
|
68
85
|
* @param {Chunk[]=} entries
|
69
86
|
* @param {Compilation=} compilation
|
70
87
|
*/
|
71
88
|
|
72
89
|
/**
|
73
|
-
* @typedef {
|
90
|
+
* @typedef {object} AssetEmittedInfo
|
74
91
|
* @property {Buffer} content
|
75
92
|
* @property {Source} source
|
76
93
|
* @property {Compilation} compilation
|
@@ -78,6 +95,9 @@ const { isSourceEqual } = require("./util/source");
|
|
78
95
|
* @property {string} targetPath
|
79
96
|
*/
|
80
97
|
|
98
|
+
/** @typedef {{ sizeOnlySource: SizeOnlySource | undefined, writtenTo: Map<string, number> }} CacheEntry */
|
99
|
+
/** @typedef {{ path: string, source: Source, size: number | undefined, waiting: ({ cacheEntry: any, file: string }[] | undefined) }} SimilarEntry */
|
100
|
+
|
81
101
|
/**
|
82
102
|
* @param {string[]} array an array
|
83
103
|
* @returns {boolean} true, if the array is sorted
|
@@ -90,11 +110,12 @@ const isSorted = array => {
|
|
90
110
|
};
|
91
111
|
|
92
112
|
/**
|
93
|
-
* @param {
|
113
|
+
* @param {{[key: string]: any}} obj an object
|
94
114
|
* @param {string[]} keys the keys of the object
|
95
|
-
* @returns {
|
115
|
+
* @returns {{[key: string]: any}} the object with properties sorted by property name
|
96
116
|
*/
|
97
117
|
const sortObject = (obj, keys) => {
|
118
|
+
/** @type {{[key: string]: any}} */
|
98
119
|
const o = {};
|
99
120
|
for (const k of keys.sort()) {
|
100
121
|
o[k] = obj[k];
|
@@ -111,21 +132,21 @@ const includesHash = (filename, hashes) => {
|
|
111
132
|
if (!hashes) return false;
|
112
133
|
if (Array.isArray(hashes)) {
|
113
134
|
return hashes.some(hash => filename.includes(hash));
|
114
|
-
} else {
|
115
|
-
return filename.includes(hashes);
|
116
135
|
}
|
136
|
+
return filename.includes(hashes);
|
117
137
|
};
|
118
138
|
|
119
139
|
class Compiler {
|
120
140
|
/**
|
121
141
|
* @param {string} context the compilation path
|
142
|
+
* @param {WebpackOptions} options options
|
122
143
|
*/
|
123
|
-
constructor(context) {
|
144
|
+
constructor(context, options = /** @type {WebpackOptions} */ ({})) {
|
124
145
|
this.hooks = Object.freeze({
|
125
146
|
/** @type {SyncHook<[]>} */
|
126
147
|
initialize: new SyncHook([]),
|
127
148
|
|
128
|
-
/** @type {SyncBailHook<[Compilation], boolean>} */
|
149
|
+
/** @type {SyncBailHook<[Compilation], boolean | undefined>} */
|
129
150
|
shouldEmit: new SyncBailHook(["compilation"]),
|
130
151
|
/** @type {AsyncSeriesHook<[Stats]>} */
|
131
152
|
done: new AsyncSeriesHook(["stats"]),
|
@@ -164,6 +185,11 @@ class Compiler {
|
|
164
185
|
/** @type {AsyncSeriesHook<[Compilation]>} */
|
165
186
|
afterCompile: new AsyncSeriesHook(["compilation"]),
|
166
187
|
|
188
|
+
/** @type {AsyncSeriesHook<[]>} */
|
189
|
+
readRecords: new AsyncSeriesHook([]),
|
190
|
+
/** @type {AsyncSeriesHook<[]>} */
|
191
|
+
emitRecords: new AsyncSeriesHook([]),
|
192
|
+
|
167
193
|
/** @type {AsyncSeriesHook<[Compiler]>} */
|
168
194
|
watchRun: new AsyncSeriesHook(["compiler"]),
|
169
195
|
/** @type {SyncHook<[Error]>} */
|
@@ -175,7 +201,7 @@ class Compiler {
|
|
175
201
|
/** @type {AsyncSeriesHook<[]>} */
|
176
202
|
shutdown: new AsyncSeriesHook([]),
|
177
203
|
|
178
|
-
/** @type {SyncBailHook<[string, string, any[]], true>} */
|
204
|
+
/** @type {SyncBailHook<[string, string, any[] | undefined], true>} */
|
179
205
|
infrastructureLog: new SyncBailHook(["origin", "type", "args"]),
|
180
206
|
|
181
207
|
// TODO the following hooks are weirdly located here
|
@@ -194,54 +220,67 @@ class Compiler {
|
|
194
220
|
|
195
221
|
this.webpack = webpack;
|
196
222
|
|
197
|
-
/** @type {string
|
223
|
+
/** @type {string | undefined} */
|
198
224
|
this.name = undefined;
|
199
|
-
/** @type {Compilation
|
225
|
+
/** @type {Compilation | undefined} */
|
200
226
|
this.parentCompilation = undefined;
|
201
227
|
/** @type {Compiler} */
|
202
228
|
this.root = this;
|
203
229
|
/** @type {string} */
|
204
230
|
this.outputPath = "";
|
205
|
-
/** @type {Watching} */
|
231
|
+
/** @type {Watching | undefined} */
|
206
232
|
this.watching = undefined;
|
207
233
|
|
208
|
-
/** @type {OutputFileSystem} */
|
234
|
+
/** @type {OutputFileSystem | null} */
|
209
235
|
this.outputFileSystem = null;
|
210
|
-
/** @type {IntermediateFileSystem} */
|
236
|
+
/** @type {IntermediateFileSystem | null} */
|
211
237
|
this.intermediateFileSystem = null;
|
212
|
-
/** @type {InputFileSystem} */
|
238
|
+
/** @type {InputFileSystem | null} */
|
213
239
|
this.inputFileSystem = null;
|
214
|
-
/** @type {WatchFileSystem} */
|
240
|
+
/** @type {WatchFileSystem | null} */
|
215
241
|
this.watchFileSystem = null;
|
216
242
|
|
217
243
|
/** @type {string|null} */
|
218
244
|
this.recordsInputPath = null;
|
219
245
|
/** @type {string|null} */
|
220
246
|
this.recordsOutputPath = null;
|
247
|
+
/** @type {Record<string, TODO>} */
|
221
248
|
this.records = {};
|
222
249
|
/** @type {Set<string | RegExp>} */
|
223
250
|
this.managedPaths = new Set();
|
224
251
|
/** @type {Set<string | RegExp>} */
|
252
|
+
this.unmanagedPaths = new Set();
|
253
|
+
/** @type {Set<string | RegExp>} */
|
225
254
|
this.immutablePaths = new Set();
|
226
255
|
|
227
|
-
/** @type {ReadonlySet<string>} */
|
256
|
+
/** @type {ReadonlySet<string> | undefined} */
|
228
257
|
this.modifiedFiles = undefined;
|
229
|
-
/** @type {ReadonlySet<string>} */
|
258
|
+
/** @type {ReadonlySet<string> | undefined} */
|
230
259
|
this.removedFiles = undefined;
|
231
|
-
/** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>} */
|
260
|
+
/** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null> | undefined} */
|
232
261
|
this.fileTimestamps = undefined;
|
233
|
-
/** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>} */
|
262
|
+
/** @type {ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null> | undefined} */
|
234
263
|
this.contextTimestamps = undefined;
|
235
|
-
/** @type {number} */
|
264
|
+
/** @type {number | undefined} */
|
236
265
|
this.fsStartTime = undefined;
|
237
266
|
|
238
267
|
/** @type {ResolverFactory} */
|
239
268
|
this.resolverFactory = new ResolverFactory();
|
240
269
|
|
270
|
+
/** @type {LoggingFunction | undefined} */
|
241
271
|
this.infrastructureLogger = undefined;
|
242
272
|
|
243
|
-
/** @type {
|
244
|
-
this.
|
273
|
+
/** @type {Readonly<PlatformTargetProperties>} */
|
274
|
+
this.platform = {
|
275
|
+
web: null,
|
276
|
+
browser: null,
|
277
|
+
webworker: null,
|
278
|
+
node: null,
|
279
|
+
nwjs: null,
|
280
|
+
electron: null
|
281
|
+
};
|
282
|
+
|
283
|
+
this.options = options;
|
245
284
|
|
246
285
|
this.context = context;
|
247
286
|
|
@@ -249,7 +288,7 @@ class Compiler {
|
|
249
288
|
|
250
289
|
this.cache = new Cache();
|
251
290
|
|
252
|
-
/** @type {Map<Module, { buildInfo:
|
291
|
+
/** @type {Map<Module, { buildInfo: BuildInfo, references: References | undefined, memCache: WeakTupleMap<any, any> }> | undefined} */
|
253
292
|
this.moduleMemCaches = undefined;
|
254
293
|
|
255
294
|
this.compilerPath = "";
|
@@ -263,16 +302,27 @@ class Compiler {
|
|
263
302
|
/** @type {boolean} */
|
264
303
|
this.watchMode = false;
|
265
304
|
|
266
|
-
|
305
|
+
this._backCompat = this.options.experiments.backCompat !== false;
|
306
|
+
|
307
|
+
/** @type {Compilation | undefined} */
|
267
308
|
this._lastCompilation = undefined;
|
268
|
-
/** @type {NormalModuleFactory} */
|
309
|
+
/** @type {NormalModuleFactory | undefined} */
|
269
310
|
this._lastNormalModuleFactory = undefined;
|
270
311
|
|
271
|
-
/**
|
312
|
+
/**
|
313
|
+
* @private
|
314
|
+
* @type {WeakMap<Source, CacheEntry>}
|
315
|
+
*/
|
272
316
|
this._assetEmittingSourceCache = new WeakMap();
|
273
|
-
/**
|
317
|
+
/**
|
318
|
+
* @private
|
319
|
+
* @type {Map<string, number>}
|
320
|
+
*/
|
274
321
|
this._assetEmittingWrittenFiles = new Map();
|
275
|
-
/**
|
322
|
+
/**
|
323
|
+
* @private
|
324
|
+
* @type {Set<string>}
|
325
|
+
*/
|
276
326
|
this._assetEmittingPreviousFiles = new Set();
|
277
327
|
}
|
278
328
|
|
@@ -308,10 +358,11 @@ class Compiler {
|
|
308
358
|
);
|
309
359
|
}
|
310
360
|
}
|
311
|
-
if (
|
312
|
-
|
313
|
-
|
314
|
-
|
361
|
+
if (
|
362
|
+
this.hooks.infrastructureLog.call(name, type, args) === undefined &&
|
363
|
+
this.infrastructureLogger !== undefined
|
364
|
+
) {
|
365
|
+
this.infrastructureLogger(name, type, args);
|
315
366
|
}
|
316
367
|
},
|
317
368
|
childName => {
|
@@ -336,36 +387,33 @@ class Compiler {
|
|
336
387
|
}
|
337
388
|
return `${name}/${childName}`;
|
338
389
|
});
|
339
|
-
} else {
|
340
|
-
return this.getInfrastructureLogger(() => {
|
341
|
-
if (typeof name === "function") {
|
342
|
-
name = name();
|
343
|
-
if (!name) {
|
344
|
-
throw new TypeError(
|
345
|
-
"Compiler.getInfrastructureLogger(name) called with a function not returning a name"
|
346
|
-
);
|
347
|
-
}
|
348
|
-
}
|
349
|
-
return `${name}/${childName}`;
|
350
|
-
});
|
351
390
|
}
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
if (
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
"Logger.getChildLogger(name) called with a function not returning a name"
|
360
|
-
);
|
361
|
-
}
|
391
|
+
return this.getInfrastructureLogger(() => {
|
392
|
+
if (typeof name === "function") {
|
393
|
+
name = name();
|
394
|
+
if (!name) {
|
395
|
+
throw new TypeError(
|
396
|
+
"Compiler.getInfrastructureLogger(name) called with a function not returning a name"
|
397
|
+
);
|
362
398
|
}
|
363
|
-
|
364
|
-
}
|
365
|
-
}
|
366
|
-
return this.getInfrastructureLogger(`${name}/${childName}`);
|
367
|
-
}
|
399
|
+
}
|
400
|
+
return `${name}/${childName}`;
|
401
|
+
});
|
368
402
|
}
|
403
|
+
if (typeof childName === "function") {
|
404
|
+
return this.getInfrastructureLogger(() => {
|
405
|
+
if (typeof childName === "function") {
|
406
|
+
childName = childName();
|
407
|
+
if (!childName) {
|
408
|
+
throw new TypeError(
|
409
|
+
"Logger.getChildLogger(name) called with a function not returning a name"
|
410
|
+
);
|
411
|
+
}
|
412
|
+
}
|
413
|
+
return `${name}/${childName}`;
|
414
|
+
});
|
415
|
+
}
|
416
|
+
return this.getInfrastructureLogger(`${name}/${childName}`);
|
369
417
|
}
|
370
418
|
);
|
371
419
|
}
|
@@ -374,6 +422,17 @@ class Compiler {
|
|
374
422
|
// e.g. move compilation specific info from Modules into ModuleGraph
|
375
423
|
_cleanupLastCompilation() {
|
376
424
|
if (this._lastCompilation !== undefined) {
|
425
|
+
for (const childCompilation of this._lastCompilation.children) {
|
426
|
+
for (const module of childCompilation.modules) {
|
427
|
+
ChunkGraph.clearChunkGraphForModule(module);
|
428
|
+
ModuleGraph.clearModuleGraphForModule(module);
|
429
|
+
module.cleanupForCache();
|
430
|
+
}
|
431
|
+
for (const chunk of childCompilation.chunks) {
|
432
|
+
ChunkGraph.clearChunkGraphForChunk(chunk);
|
433
|
+
}
|
434
|
+
}
|
435
|
+
|
377
436
|
for (const module of this._lastCompilation.modules) {
|
378
437
|
ChunkGraph.clearChunkGraphForModule(module);
|
379
438
|
ModuleGraph.clearModuleGraphForModule(module);
|
@@ -396,7 +455,7 @@ class Compiler {
|
|
396
455
|
|
397
456
|
/**
|
398
457
|
* @param {WatchOptions} watchOptions the watcher's options
|
399
|
-
* @param {
|
458
|
+
* @param {RunCallback<Stats>} handler signals when the call finishes
|
400
459
|
* @returns {Watching} a compiler watcher
|
401
460
|
*/
|
402
461
|
watch(watchOptions, handler) {
|
@@ -411,7 +470,7 @@ class Compiler {
|
|
411
470
|
}
|
412
471
|
|
413
472
|
/**
|
414
|
-
* @param {
|
473
|
+
* @param {RunCallback<Stats>} callback signals when the call finishes
|
415
474
|
* @returns {void}
|
416
475
|
*/
|
417
476
|
run(callback) {
|
@@ -419,8 +478,13 @@ class Compiler {
|
|
419
478
|
return callback(new ConcurrentCompilationError());
|
420
479
|
}
|
421
480
|
|
481
|
+
/** @type {Logger | undefined} */
|
422
482
|
let logger;
|
423
483
|
|
484
|
+
/**
|
485
|
+
* @param {Error | null} err error
|
486
|
+
* @param {Stats=} stats stats
|
487
|
+
*/
|
424
488
|
const finalCallback = (err, stats) => {
|
425
489
|
if (logger) logger.time("beginIdle");
|
426
490
|
this.idle = true;
|
@@ -432,16 +496,23 @@ class Compiler {
|
|
432
496
|
this.hooks.failed.call(err);
|
433
497
|
}
|
434
498
|
if (callback !== undefined) callback(err, stats);
|
435
|
-
this.hooks.afterDone.call(stats);
|
499
|
+
this.hooks.afterDone.call(/** @type {Stats} */ (stats));
|
436
500
|
};
|
437
501
|
|
438
502
|
const startTime = Date.now();
|
439
503
|
|
440
504
|
this.running = true;
|
441
505
|
|
442
|
-
|
506
|
+
/**
|
507
|
+
* @param {Error | null} err error
|
508
|
+
* @param {Compilation=} _compilation compilation
|
509
|
+
* @returns {void}
|
510
|
+
*/
|
511
|
+
const onCompiled = (err, _compilation) => {
|
443
512
|
if (err) return finalCallback(err);
|
444
513
|
|
514
|
+
const compilation = /** @type {Compilation} */ (_compilation);
|
515
|
+
|
445
516
|
if (this.hooks.shouldEmit.call(compilation) === false) {
|
446
517
|
compilation.startTime = startTime;
|
447
518
|
compilation.endTime = Date.now();
|
@@ -457,7 +528,8 @@ class Compiler {
|
|
457
528
|
logger = compilation.getLogger("webpack.Compiler");
|
458
529
|
logger.time("emitAssets");
|
459
530
|
this.emitAssets(compilation, err => {
|
460
|
-
|
531
|
+
/** @type {Logger} */
|
532
|
+
(logger).timeEnd("emitAssets");
|
461
533
|
if (err) return finalCallback(err);
|
462
534
|
|
463
535
|
if (compilation.hooks.needAdditionalPass.call()) {
|
@@ -465,10 +537,12 @@ class Compiler {
|
|
465
537
|
|
466
538
|
compilation.startTime = startTime;
|
467
539
|
compilation.endTime = Date.now();
|
468
|
-
|
540
|
+
/** @type {Logger} */
|
541
|
+
(logger).time("done hook");
|
469
542
|
const stats = new Stats(compilation);
|
470
543
|
this.hooks.done.callAsync(stats, err => {
|
471
|
-
|
544
|
+
/** @type {Logger} */
|
545
|
+
(logger).timeEnd("done hook");
|
472
546
|
if (err) return finalCallback(err);
|
473
547
|
|
474
548
|
this.hooks.additionalPass.callAsync(err => {
|
@@ -479,17 +553,21 @@ class Compiler {
|
|
479
553
|
return;
|
480
554
|
}
|
481
555
|
|
482
|
-
|
556
|
+
/** @type {Logger} */
|
557
|
+
(logger).time("emitRecords");
|
483
558
|
this.emitRecords(err => {
|
484
|
-
|
559
|
+
/** @type {Logger} */
|
560
|
+
(logger).timeEnd("emitRecords");
|
485
561
|
if (err) return finalCallback(err);
|
486
562
|
|
487
563
|
compilation.startTime = startTime;
|
488
564
|
compilation.endTime = Date.now();
|
489
|
-
|
565
|
+
/** @type {Logger} */
|
566
|
+
(logger).time("done hook");
|
490
567
|
const stats = new Stats(compilation);
|
491
568
|
this.hooks.done.callAsync(stats, err => {
|
492
|
-
|
569
|
+
/** @type {Logger} */
|
570
|
+
(logger).timeEnd("done hook");
|
493
571
|
if (err) return finalCallback(err);
|
494
572
|
this.cache.storeBuildDependencies(
|
495
573
|
compilation.buildDependencies,
|
@@ -538,15 +616,42 @@ class Compiler {
|
|
538
616
|
*/
|
539
617
|
runAsChild(callback) {
|
540
618
|
const startTime = Date.now();
|
541
|
-
this.compile((err, compilation) => {
|
542
|
-
if (err) return callback(err);
|
543
619
|
|
544
|
-
|
620
|
+
/**
|
621
|
+
* @param {Error | null} err error
|
622
|
+
* @param {Chunk[]=} entries entries
|
623
|
+
* @param {Compilation=} compilation compilation
|
624
|
+
*/
|
625
|
+
const finalCallback = (err, entries, compilation) => {
|
626
|
+
try {
|
627
|
+
callback(err, entries, compilation);
|
628
|
+
} catch (runAsChildErr) {
|
629
|
+
const err = new WebpackError(
|
630
|
+
`compiler.runAsChild callback error: ${runAsChildErr}`
|
631
|
+
);
|
632
|
+
err.details = /** @type {Error} */ (runAsChildErr).stack;
|
633
|
+
/** @type {Compilation} */
|
634
|
+
(this.parentCompilation).errors.push(err);
|
635
|
+
}
|
636
|
+
};
|
637
|
+
|
638
|
+
this.compile((err, _compilation) => {
|
639
|
+
if (err) return finalCallback(err);
|
640
|
+
|
641
|
+
const compilation = /** @type {Compilation} */ (_compilation);
|
642
|
+
const parentCompilation = /** @type {Compilation} */ (
|
643
|
+
this.parentCompilation
|
644
|
+
);
|
645
|
+
|
646
|
+
parentCompilation.children.push(compilation);
|
647
|
+
|
545
648
|
for (const { name, source, info } of compilation.getAssets()) {
|
546
|
-
|
649
|
+
parentCompilation.emitAsset(name, source, info);
|
547
650
|
}
|
548
651
|
|
652
|
+
/** @type {Chunk[]} */
|
549
653
|
const entries = [];
|
654
|
+
|
550
655
|
for (const ep of compilation.entrypoints.values()) {
|
551
656
|
entries.push(...ep.chunks);
|
552
657
|
}
|
@@ -554,7 +659,7 @@ class Compiler {
|
|
554
659
|
compilation.startTime = startTime;
|
555
660
|
compilation.endTime = Date.now();
|
556
661
|
|
557
|
-
return
|
662
|
+
return finalCallback(null, entries, compilation);
|
558
663
|
});
|
559
664
|
}
|
560
665
|
|
@@ -570,14 +675,19 @@ class Compiler {
|
|
570
675
|
* @returns {void}
|
571
676
|
*/
|
572
677
|
emitAssets(compilation, callback) {
|
678
|
+
/** @type {string} */
|
573
679
|
let outputPath;
|
574
680
|
|
681
|
+
/**
|
682
|
+
* @param {Error=} err error
|
683
|
+
* @returns {void}
|
684
|
+
*/
|
575
685
|
const emitFiles = err => {
|
576
686
|
if (err) return callback(err);
|
577
687
|
|
578
688
|
const assets = compilation.getAssets();
|
579
689
|
compilation.assets = { ...compilation.assets };
|
580
|
-
/** @type {Map<string,
|
690
|
+
/** @type {Map<string, SimilarEntry>} */
|
581
691
|
const caseInsensitiveMap = new Map();
|
582
692
|
/** @type {Set<string>} */
|
583
693
|
const allTargetPaths = new Set();
|
@@ -589,7 +699,7 @@ class Compiler {
|
|
589
699
|
let immutable = info.immutable;
|
590
700
|
const queryStringIdx = targetFile.indexOf("?");
|
591
701
|
if (queryStringIdx >= 0) {
|
592
|
-
targetFile = targetFile.
|
702
|
+
targetFile = targetFile.slice(0, queryStringIdx);
|
593
703
|
// We may remove the hash, which is in the query string
|
594
704
|
// So we recheck if the file is immutable
|
595
705
|
// This doesn't cover all cases, but immutable is only a performance optimization anyway
|
@@ -601,10 +711,15 @@ class Compiler {
|
|
601
711
|
includesHash(targetFile, info.fullhash));
|
602
712
|
}
|
603
713
|
|
714
|
+
/**
|
715
|
+
* @param {Error=} err error
|
716
|
+
* @returns {void}
|
717
|
+
*/
|
604
718
|
const writeOut = err => {
|
605
719
|
if (err) return callback(err);
|
606
720
|
const targetPath = join(
|
607
|
-
|
721
|
+
/** @type {OutputFileSystem} */
|
722
|
+
(this.outputFileSystem),
|
608
723
|
outputPath,
|
609
724
|
targetFile
|
610
725
|
);
|
@@ -624,6 +739,7 @@ class Compiler {
|
|
624
739
|
this._assetEmittingSourceCache.set(source, cacheEntry);
|
625
740
|
}
|
626
741
|
|
742
|
+
/** @type {SimilarEntry | undefined} */
|
627
743
|
let similarEntry;
|
628
744
|
|
629
745
|
const checkSimilarFile = () => {
|
@@ -651,18 +767,17 @@ ${other}`);
|
|
651
767
|
callback(err);
|
652
768
|
}
|
653
769
|
return true;
|
654
|
-
} else {
|
655
|
-
caseInsensitiveMap.set(
|
656
|
-
caseInsensitiveTargetPath,
|
657
|
-
(similarEntry = {
|
658
|
-
path: targetPath,
|
659
|
-
source,
|
660
|
-
size: undefined,
|
661
|
-
waiting: undefined
|
662
|
-
})
|
663
|
-
);
|
664
|
-
return false;
|
665
770
|
}
|
771
|
+
caseInsensitiveMap.set(
|
772
|
+
caseInsensitiveTargetPath,
|
773
|
+
(similarEntry = /** @type {SimilarEntry} */ ({
|
774
|
+
path: targetPath,
|
775
|
+
source,
|
776
|
+
size: undefined,
|
777
|
+
waiting: undefined
|
778
|
+
}))
|
779
|
+
);
|
780
|
+
return false;
|
666
781
|
};
|
667
782
|
|
668
783
|
/**
|
@@ -672,14 +787,12 @@ ${other}`);
|
|
672
787
|
const getContent = () => {
|
673
788
|
if (typeof source.buffer === "function") {
|
674
789
|
return source.buffer();
|
675
|
-
} else {
|
676
|
-
const bufferOrString = source.source();
|
677
|
-
if (Buffer.isBuffer(bufferOrString)) {
|
678
|
-
return bufferOrString;
|
679
|
-
} else {
|
680
|
-
return Buffer.from(bufferOrString, "utf8");
|
681
|
-
}
|
682
790
|
}
|
791
|
+
const bufferOrString = source.source();
|
792
|
+
if (Buffer.isBuffer(bufferOrString)) {
|
793
|
+
return bufferOrString;
|
794
|
+
}
|
795
|
+
return Buffer.from(bufferOrString, "utf8");
|
683
796
|
};
|
684
797
|
|
685
798
|
const alreadyWritten = () => {
|
@@ -687,9 +800,11 @@ ${other}`);
|
|
687
800
|
if (targetFileGeneration === undefined) {
|
688
801
|
const newGeneration = 1;
|
689
802
|
this._assetEmittingWrittenFiles.set(targetPath, newGeneration);
|
690
|
-
|
803
|
+
/** @type {CacheEntry} */
|
804
|
+
(cacheEntry).writtenTo.set(targetPath, newGeneration);
|
691
805
|
} else {
|
692
|
-
|
806
|
+
/** @type {CacheEntry} */
|
807
|
+
(cacheEntry).writtenTo.set(targetPath, targetFileGeneration);
|
693
808
|
}
|
694
809
|
callback();
|
695
810
|
};
|
@@ -700,7 +815,8 @@ ${other}`);
|
|
700
815
|
* @returns {void}
|
701
816
|
*/
|
702
817
|
const doWrite = content => {
|
703
|
-
|
818
|
+
/** @type {OutputFileSystem} */
|
819
|
+
(this.outputFileSystem).writeFile(targetPath, content, err => {
|
704
820
|
if (err) return callback(err);
|
705
821
|
|
706
822
|
// information marker that the asset has been emitted
|
@@ -711,7 +827,8 @@ ${other}`);
|
|
711
827
|
targetFileGeneration === undefined
|
712
828
|
? 1
|
713
829
|
: targetFileGeneration + 1;
|
714
|
-
|
830
|
+
/** @type {CacheEntry} */
|
831
|
+
(cacheEntry).writtenTo.set(targetPath, newGeneration);
|
715
832
|
this._assetEmittingWrittenFiles.set(targetPath, newGeneration);
|
716
833
|
this.hooks.assetEmitted.callAsync(
|
717
834
|
file,
|
@@ -727,16 +844,33 @@ ${other}`);
|
|
727
844
|
});
|
728
845
|
};
|
729
846
|
|
847
|
+
/**
|
848
|
+
* @param {number} size size
|
849
|
+
*/
|
730
850
|
const updateWithReplacementSource = size => {
|
731
|
-
updateFileWithReplacementSource(
|
732
|
-
|
733
|
-
|
734
|
-
|
851
|
+
updateFileWithReplacementSource(
|
852
|
+
file,
|
853
|
+
/** @type {CacheEntry} */ (cacheEntry),
|
854
|
+
size
|
855
|
+
);
|
856
|
+
/** @type {SimilarEntry} */
|
857
|
+
(similarEntry).size = size;
|
858
|
+
if (
|
859
|
+
/** @type {SimilarEntry} */ (similarEntry).waiting !== undefined
|
860
|
+
) {
|
861
|
+
for (const { file, cacheEntry } of /** @type {SimilarEntry} */ (
|
862
|
+
similarEntry
|
863
|
+
).waiting) {
|
735
864
|
updateFileWithReplacementSource(file, cacheEntry, size);
|
736
865
|
}
|
737
866
|
}
|
738
867
|
};
|
739
868
|
|
869
|
+
/**
|
870
|
+
* @param {string} file file
|
871
|
+
* @param {CacheEntry} cacheEntry cache entry
|
872
|
+
* @param {number} size size
|
873
|
+
*/
|
740
874
|
const updateFileWithReplacementSource = (
|
741
875
|
file,
|
742
876
|
cacheEntry,
|
@@ -753,10 +887,14 @@ ${other}`);
|
|
753
887
|
});
|
754
888
|
};
|
755
889
|
|
890
|
+
/**
|
891
|
+
* @param {IStats} stats stats
|
892
|
+
* @returns {void}
|
893
|
+
*/
|
756
894
|
const processExistingFile = stats => {
|
757
895
|
// skip emitting if it's already there and an immutable file
|
758
896
|
if (immutable) {
|
759
|
-
updateWithReplacementSource(stats.size);
|
897
|
+
updateWithReplacementSource(/** @type {number} */ (stats.size));
|
760
898
|
return alreadyWritten();
|
761
899
|
}
|
762
900
|
|
@@ -770,19 +908,17 @@ ${other}`);
|
|
770
908
|
// for a fast negative match file size is compared first
|
771
909
|
if (content.length === stats.size) {
|
772
910
|
compilation.comparedForEmitAssets.add(file);
|
773
|
-
return
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
} else {
|
782
|
-
return alreadyWritten();
|
783
|
-
}
|
911
|
+
return /** @type {OutputFileSystem} */ (
|
912
|
+
this.outputFileSystem
|
913
|
+
).readFile(targetPath, (err, existingContent) => {
|
914
|
+
if (
|
915
|
+
err ||
|
916
|
+
!content.equals(/** @type {Buffer} */ (existingContent))
|
917
|
+
) {
|
918
|
+
return doWrite(content);
|
784
919
|
}
|
785
|
-
|
920
|
+
return alreadyWritten();
|
921
|
+
});
|
786
922
|
}
|
787
923
|
|
788
924
|
return doWrite(content);
|
@@ -799,23 +935,28 @@ ${other}`);
|
|
799
935
|
// if the target file has already been written
|
800
936
|
if (targetFileGeneration !== undefined) {
|
801
937
|
// check if the Source has been written to this target file
|
802
|
-
const writtenGeneration =
|
938
|
+
const writtenGeneration = /** @type {CacheEntry} */ (
|
939
|
+
cacheEntry
|
940
|
+
).writtenTo.get(targetPath);
|
803
941
|
if (writtenGeneration === targetFileGeneration) {
|
804
942
|
// if yes, we may skip writing the file
|
805
943
|
// if it's already there
|
806
944
|
// (we assume one doesn't modify files while the Compiler is running, other then removing them)
|
807
945
|
|
808
946
|
if (this._assetEmittingPreviousFiles.has(targetPath)) {
|
947
|
+
const sizeOnlySource = /** @type {SizeOnlySource} */ (
|
948
|
+
/** @type {CacheEntry} */ (cacheEntry).sizeOnlySource
|
949
|
+
);
|
950
|
+
|
809
951
|
// We assume that assets from the last compilation say intact on disk (they are not removed)
|
810
|
-
compilation.updateAsset(file,
|
811
|
-
size:
|
952
|
+
compilation.updateAsset(file, sizeOnlySource, {
|
953
|
+
size: sizeOnlySource.size()
|
812
954
|
});
|
813
955
|
|
814
956
|
return callback();
|
815
|
-
} else {
|
816
|
-
// Settings immutable will make it accept file content without comparing when file exist
|
817
|
-
immutable = true;
|
818
957
|
}
|
958
|
+
// Settings immutable will make it accept file content without comparing when file exist
|
959
|
+
immutable = true;
|
819
960
|
} else if (!immutable) {
|
820
961
|
if (checkSimilarFile()) return;
|
821
962
|
// We wrote to this file before which has very likely a different content
|
@@ -827,11 +968,12 @@ ${other}`);
|
|
827
968
|
|
828
969
|
if (checkSimilarFile()) return;
|
829
970
|
if (this.options.output.compareBeforeEmit) {
|
830
|
-
|
831
|
-
|
971
|
+
/** @type {OutputFileSystem} */
|
972
|
+
(this.outputFileSystem).stat(targetPath, (err, stats) => {
|
973
|
+
const exists = !err && /** @type {IStats} */ (stats).isFile();
|
832
974
|
|
833
975
|
if (exists) {
|
834
|
-
processExistingFile(stats);
|
976
|
+
processExistingFile(/** @type {IStats} */ (stats));
|
835
977
|
} else {
|
836
978
|
processMissingFile();
|
837
979
|
}
|
@@ -841,8 +983,8 @@ ${other}`);
|
|
841
983
|
}
|
842
984
|
};
|
843
985
|
|
844
|
-
if (targetFile
|
845
|
-
const fs = this.outputFileSystem;
|
986
|
+
if (/\/|\\/.test(targetFile)) {
|
987
|
+
const fs = /** @type {OutputFileSystem} */ (this.outputFileSystem);
|
846
988
|
const dir = dirname(fs, join(fs, outputPath, targetFile));
|
847
989
|
mkdirp(fs, dir, writeOut);
|
848
990
|
} else {
|
@@ -871,7 +1013,11 @@ ${other}`);
|
|
871
1013
|
this.hooks.emit.callAsync(compilation, err => {
|
872
1014
|
if (err) return callback(err);
|
873
1015
|
outputPath = compilation.getPath(this.outputPath, {});
|
874
|
-
mkdirp(
|
1016
|
+
mkdirp(
|
1017
|
+
/** @type {OutputFileSystem} */ (this.outputFileSystem),
|
1018
|
+
outputPath,
|
1019
|
+
emitFiles
|
1020
|
+
);
|
875
1021
|
});
|
876
1022
|
}
|
877
1023
|
|
@@ -880,11 +1026,34 @@ ${other}`);
|
|
880
1026
|
* @returns {void}
|
881
1027
|
*/
|
882
1028
|
emitRecords(callback) {
|
883
|
-
if (
|
1029
|
+
if (this.hooks.emitRecords.isUsed()) {
|
1030
|
+
if (this.recordsOutputPath) {
|
1031
|
+
asyncLib.parallel(
|
1032
|
+
[
|
1033
|
+
cb => this.hooks.emitRecords.callAsync(cb),
|
1034
|
+
this._emitRecords.bind(this)
|
1035
|
+
],
|
1036
|
+
err => callback(err)
|
1037
|
+
);
|
1038
|
+
} else {
|
1039
|
+
this.hooks.emitRecords.callAsync(callback);
|
1040
|
+
}
|
1041
|
+
} else if (this.recordsOutputPath) {
|
1042
|
+
this._emitRecords(callback);
|
1043
|
+
} else {
|
1044
|
+
callback();
|
1045
|
+
}
|
1046
|
+
}
|
884
1047
|
|
1048
|
+
/**
|
1049
|
+
* @param {Callback<void>} callback signals when the call finishes
|
1050
|
+
* @returns {void}
|
1051
|
+
*/
|
1052
|
+
_emitRecords(callback) {
|
885
1053
|
const writeFile = () => {
|
886
|
-
|
887
|
-
|
1054
|
+
/** @type {OutputFileSystem} */
|
1055
|
+
(this.outputFileSystem).writeFile(
|
1056
|
+
/** @type {string} */ (this.recordsOutputPath),
|
888
1057
|
JSON.stringify(
|
889
1058
|
this.records,
|
890
1059
|
(n, value) => {
|
@@ -907,16 +1076,20 @@ ${other}`);
|
|
907
1076
|
};
|
908
1077
|
|
909
1078
|
const recordsOutputPathDirectory = dirname(
|
910
|
-
this.outputFileSystem,
|
911
|
-
this.recordsOutputPath
|
1079
|
+
/** @type {OutputFileSystem} */ (this.outputFileSystem),
|
1080
|
+
/** @type {string} */ (this.recordsOutputPath)
|
912
1081
|
);
|
913
1082
|
if (!recordsOutputPathDirectory) {
|
914
1083
|
return writeFile();
|
915
1084
|
}
|
916
|
-
mkdirp(
|
917
|
-
|
918
|
-
|
919
|
-
|
1085
|
+
mkdirp(
|
1086
|
+
/** @type {OutputFileSystem} */ (this.outputFileSystem),
|
1087
|
+
recordsOutputPathDirectory,
|
1088
|
+
err => {
|
1089
|
+
if (err) return callback(err);
|
1090
|
+
writeFile();
|
1091
|
+
}
|
1092
|
+
);
|
920
1093
|
}
|
921
1094
|
|
922
1095
|
/**
|
@@ -924,27 +1097,63 @@ ${other}`);
|
|
924
1097
|
* @returns {void}
|
925
1098
|
*/
|
926
1099
|
readRecords(callback) {
|
1100
|
+
if (this.hooks.readRecords.isUsed()) {
|
1101
|
+
if (this.recordsInputPath) {
|
1102
|
+
asyncLib.parallel(
|
1103
|
+
[
|
1104
|
+
cb => this.hooks.readRecords.callAsync(cb),
|
1105
|
+
this._readRecords.bind(this)
|
1106
|
+
],
|
1107
|
+
err => callback(err)
|
1108
|
+
);
|
1109
|
+
} else {
|
1110
|
+
this.records = {};
|
1111
|
+
this.hooks.readRecords.callAsync(callback);
|
1112
|
+
}
|
1113
|
+
} else if (this.recordsInputPath) {
|
1114
|
+
this._readRecords(callback);
|
1115
|
+
} else {
|
1116
|
+
this.records = {};
|
1117
|
+
callback();
|
1118
|
+
}
|
1119
|
+
}
|
1120
|
+
|
1121
|
+
/**
|
1122
|
+
* @param {Callback<void>} callback signals when the call finishes
|
1123
|
+
* @returns {void}
|
1124
|
+
*/
|
1125
|
+
_readRecords(callback) {
|
927
1126
|
if (!this.recordsInputPath) {
|
928
1127
|
this.records = {};
|
929
1128
|
return callback();
|
930
1129
|
}
|
931
|
-
|
1130
|
+
/** @type {InputFileSystem} */
|
1131
|
+
(this.inputFileSystem).stat(this.recordsInputPath, err => {
|
932
1132
|
// It doesn't exist
|
933
1133
|
// We can ignore this.
|
934
1134
|
if (err) return callback();
|
935
1135
|
|
936
|
-
|
937
|
-
|
1136
|
+
/** @type {InputFileSystem} */
|
1137
|
+
(this.inputFileSystem).readFile(
|
1138
|
+
/** @type {string} */ (this.recordsInputPath),
|
1139
|
+
(err, content) => {
|
1140
|
+
if (err) return callback(err);
|
938
1141
|
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
1142
|
+
try {
|
1143
|
+
this.records = parseJson(
|
1144
|
+
/** @type {Buffer} */ (content).toString("utf-8")
|
1145
|
+
);
|
1146
|
+
} catch (parseErr) {
|
1147
|
+
return callback(
|
1148
|
+
new Error(
|
1149
|
+
`Cannot parse records: ${/** @type {Error} */ (parseErr).message}`
|
1150
|
+
)
|
1151
|
+
);
|
1152
|
+
}
|
945
1153
|
|
946
|
-
|
947
|
-
|
1154
|
+
return callback();
|
1155
|
+
}
|
1156
|
+
);
|
948
1157
|
});
|
949
1158
|
}
|
950
1159
|
|
@@ -963,7 +1172,13 @@ ${other}`);
|
|
963
1172
|
outputOptions,
|
964
1173
|
plugins
|
965
1174
|
) {
|
966
|
-
const childCompiler = new Compiler(this.context
|
1175
|
+
const childCompiler = new Compiler(this.context, {
|
1176
|
+
...this.options,
|
1177
|
+
output: {
|
1178
|
+
...this.options.output,
|
1179
|
+
...outputOptions
|
1180
|
+
}
|
1181
|
+
});
|
967
1182
|
childCompiler.name = compilerName;
|
968
1183
|
childCompiler.outputPath = this.outputPath;
|
969
1184
|
childCompiler.inputFileSystem = this.inputFileSystem;
|
@@ -976,6 +1191,7 @@ ${other}`);
|
|
976
1191
|
childCompiler.fsStartTime = this.fsStartTime;
|
977
1192
|
childCompiler.cache = this.cache;
|
978
1193
|
childCompiler.compilerPath = `${this.compilerPath}${compilerName}|${compilerIndex}|`;
|
1194
|
+
childCompiler._backCompat = this._backCompat;
|
979
1195
|
|
980
1196
|
const relativeCompilerName = makePathsRelative(
|
981
1197
|
this.context,
|
@@ -991,18 +1207,13 @@ ${other}`);
|
|
991
1207
|
this.records[relativeCompilerName].push((childCompiler.records = {}));
|
992
1208
|
}
|
993
1209
|
|
994
|
-
childCompiler.options = {
|
995
|
-
...this.options,
|
996
|
-
output: {
|
997
|
-
...this.options.output,
|
998
|
-
...outputOptions
|
999
|
-
}
|
1000
|
-
};
|
1001
1210
|
childCompiler.parentCompilation = compilation;
|
1002
1211
|
childCompiler.root = this.root;
|
1003
1212
|
if (Array.isArray(plugins)) {
|
1004
1213
|
for (const plugin of plugins) {
|
1005
|
-
plugin
|
1214
|
+
if (plugin) {
|
1215
|
+
plugin.apply(childCompiler);
|
1216
|
+
}
|
1006
1217
|
}
|
1007
1218
|
}
|
1008
1219
|
for (const name in this.hooks) {
|
@@ -1015,11 +1226,17 @@ ${other}`);
|
|
1015
1226
|
"invalid",
|
1016
1227
|
"done",
|
1017
1228
|
"thisCompilation"
|
1018
|
-
].includes(name)
|
1229
|
+
].includes(name) &&
|
1230
|
+
childCompiler.hooks[/** @type {keyof Compiler["hooks"]} */ (name)]
|
1019
1231
|
) {
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1232
|
+
childCompiler.hooks[
|
1233
|
+
/** @type {keyof Compiler["hooks"]} */
|
1234
|
+
(name)
|
1235
|
+
].taps =
|
1236
|
+
this.hooks[
|
1237
|
+
/** @type {keyof Compiler["hooks"]} */
|
1238
|
+
(name)
|
1239
|
+
].taps.slice();
|
1023
1240
|
}
|
1024
1241
|
}
|
1025
1242
|
|
@@ -1033,9 +1250,13 @@ ${other}`);
|
|
1033
1250
|
}
|
1034
1251
|
|
1035
1252
|
isChild() {
|
1036
|
-
return
|
1253
|
+
return Boolean(this.parentCompilation);
|
1037
1254
|
}
|
1038
1255
|
|
1256
|
+
/**
|
1257
|
+
* @param {CompilationParams} params the compilation parameters
|
1258
|
+
* @returns {Compilation} compilation
|
1259
|
+
*/
|
1039
1260
|
createCompilation(params) {
|
1040
1261
|
this._cleanupLastCompilation();
|
1041
1262
|
return (this._lastCompilation = new Compilation(this, params));
|
@@ -1058,7 +1279,7 @@ ${other}`);
|
|
1058
1279
|
this._cleanupLastNormalModuleFactory();
|
1059
1280
|
const normalModuleFactory = new NormalModuleFactory({
|
1060
1281
|
context: this.options.context,
|
1061
|
-
fs: this.inputFileSystem,
|
1282
|
+
fs: /** @type {InputFileSystem} */ (this.inputFileSystem),
|
1062
1283
|
resolverFactory: this.resolverFactory,
|
1063
1284
|
options: this.options.module,
|
1064
1285
|
associatedObjectForCache: this.root,
|
@@ -1084,7 +1305,7 @@ ${other}`);
|
|
1084
1305
|
}
|
1085
1306
|
|
1086
1307
|
/**
|
1087
|
-
* @param {
|
1308
|
+
* @param {RunCallback<Compilation>} callback signals when the compilation finishes
|
1088
1309
|
* @returns {void}
|
1089
1310
|
*/
|
1090
1311
|
compile(callback) {
|
@@ -1135,7 +1356,7 @@ ${other}`);
|
|
1135
1356
|
}
|
1136
1357
|
|
1137
1358
|
/**
|
1138
|
-
* @param {
|
1359
|
+
* @param {RunCallback<void>} callback signals when the compiler closes
|
1139
1360
|
* @returns {void}
|
1140
1361
|
*/
|
1141
1362
|
close(callback) {
|