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
@@ -20,17 +20,25 @@ const {
|
|
20
20
|
/** @typedef {import("../../declarations/WebpackOptions").SnapshotOptions} SnapshotOptions */
|
21
21
|
/** @typedef {import("../Cache").Etag} Etag */
|
22
22
|
/** @typedef {import("../Compiler")} Compiler */
|
23
|
+
/** @typedef {import("../FileSystemInfo").ResolveBuildDependenciesResult} ResolveBuildDependenciesResult */
|
23
24
|
/** @typedef {import("../FileSystemInfo").Snapshot} Snapshot */
|
24
25
|
/** @typedef {import("../logging/Logger").Logger} Logger */
|
26
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
27
|
+
/** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
25
28
|
/** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
|
26
29
|
|
30
|
+
/** @typedef {Map<string, string | false>} ResolveResults */
|
31
|
+
/** @typedef {Set<string>} Items */
|
32
|
+
/** @typedef {Set<string>} BuildDependencies */
|
33
|
+
/** @typedef {Map<string, PackItemInfo>} ItemInfo */
|
34
|
+
|
27
35
|
class PackContainer {
|
28
36
|
/**
|
29
|
-
* @param {
|
37
|
+
* @param {object} data stored data
|
30
38
|
* @param {string} version version identifier
|
31
39
|
* @param {Snapshot} buildSnapshot snapshot of all build dependencies
|
32
|
-
* @param {
|
33
|
-
* @param {
|
40
|
+
* @param {BuildDependencies} buildDependencies list of all unresolved build dependencies captured
|
41
|
+
* @param {ResolveResults} resolveResults result of the resolved build dependencies
|
34
42
|
* @param {Snapshot} resolveBuildDependenciesSnapshot snapshot of the dependencies of the build dependencies resolving
|
35
43
|
*/
|
36
44
|
constructor(
|
@@ -49,15 +57,22 @@ class PackContainer {
|
|
49
57
|
this.resolveBuildDependenciesSnapshot = resolveBuildDependenciesSnapshot;
|
50
58
|
}
|
51
59
|
|
60
|
+
/**
|
61
|
+
* @param {ObjectSerializerContext} context context
|
62
|
+
*/
|
52
63
|
serialize({ write, writeLazy }) {
|
53
64
|
write(this.version);
|
54
65
|
write(this.buildSnapshot);
|
55
66
|
write(this.buildDependencies);
|
56
67
|
write(this.resolveResults);
|
57
68
|
write(this.resolveBuildDependenciesSnapshot);
|
58
|
-
writeLazy
|
69
|
+
/** @type {NonNullable<ObjectSerializerContext["writeLazy"]>} */
|
70
|
+
(writeLazy)(this.data);
|
59
71
|
}
|
60
72
|
|
73
|
+
/**
|
74
|
+
* @param {ObjectDeserializerContext} context context
|
75
|
+
*/
|
61
76
|
deserialize({ read }) {
|
62
77
|
this.version = read();
|
63
78
|
this.buildSnapshot = read();
|
@@ -96,13 +111,17 @@ class PackItemInfo {
|
|
96
111
|
}
|
97
112
|
|
98
113
|
class Pack {
|
114
|
+
/**
|
115
|
+
* @param {Logger} logger a logger
|
116
|
+
* @param {number} maxAge max age of cache items
|
117
|
+
*/
|
99
118
|
constructor(logger, maxAge) {
|
100
|
-
/** @type {
|
119
|
+
/** @type {ItemInfo} */
|
101
120
|
this.itemInfo = new Map();
|
102
|
-
/** @type {string[]} */
|
121
|
+
/** @type {(string | undefined)[]} */
|
103
122
|
this.requests = [];
|
104
123
|
this.requestsTimeout = undefined;
|
105
|
-
/** @type {
|
124
|
+
/** @type {ItemInfo} */
|
106
125
|
this.freshContent = new Map();
|
107
126
|
/** @type {(undefined | PackContent)[]} */
|
108
127
|
this.content = [];
|
@@ -111,6 +130,9 @@ class Pack {
|
|
111
130
|
this.maxAge = maxAge;
|
112
131
|
}
|
113
132
|
|
133
|
+
/**
|
134
|
+
* @param {string} identifier identifier
|
135
|
+
*/
|
114
136
|
_addRequest(identifier) {
|
115
137
|
this.requests.push(identifier);
|
116
138
|
if (this.requestsTimeout === undefined) {
|
@@ -138,19 +160,18 @@ class Pack {
|
|
138
160
|
const info = this.itemInfo.get(identifier);
|
139
161
|
this._addRequest(identifier);
|
140
162
|
if (info === undefined) {
|
141
|
-
return
|
163
|
+
return;
|
142
164
|
}
|
143
165
|
if (info.etag !== etag) return null;
|
144
166
|
info.lastAccess = Date.now();
|
145
167
|
const loc = info.location;
|
146
168
|
if (loc === -1) {
|
147
169
|
return info.freshValue;
|
148
|
-
} else {
|
149
|
-
if (!this.content[loc]) {
|
150
|
-
return undefined;
|
151
|
-
}
|
152
|
-
return this.content[loc].get(identifier);
|
153
170
|
}
|
171
|
+
if (!this.content[loc]) {
|
172
|
+
return;
|
173
|
+
}
|
174
|
+
return /** @type {PackContent} */ (this.content[loc]).get(identifier);
|
154
175
|
}
|
155
176
|
|
156
177
|
/**
|
@@ -175,7 +196,7 @@ class Pack {
|
|
175
196
|
if (loc >= 0) {
|
176
197
|
this._addRequest(identifier);
|
177
198
|
this.freshContent.set(identifier, info);
|
178
|
-
const content = this.content[loc];
|
199
|
+
const content = /** @type {PackContent} */ (this.content[loc]);
|
179
200
|
content.delete(identifier);
|
180
201
|
if (content.items.size === 0) {
|
181
202
|
this.content[loc] = undefined;
|
@@ -213,12 +234,18 @@ class Pack {
|
|
213
234
|
return i;
|
214
235
|
}
|
215
236
|
|
237
|
+
/**
|
238
|
+
* @private
|
239
|
+
* @param {Items} items items
|
240
|
+
* @param {Items} usedItems used items
|
241
|
+
* @param {number} newLoc new location
|
242
|
+
*/
|
216
243
|
_gcAndUpdateLocation(items, usedItems, newLoc) {
|
217
244
|
let count = 0;
|
218
245
|
let lastGC;
|
219
246
|
const now = Date.now();
|
220
247
|
for (const identifier of items) {
|
221
|
-
const info = this.itemInfo.get(identifier);
|
248
|
+
const info = /** @type {PackItemInfo} */ (this.itemInfo.get(identifier));
|
222
249
|
if (now - info.lastAccess > this.maxAge) {
|
223
250
|
this.itemInfo.delete(identifier);
|
224
251
|
items.delete(identifier);
|
@@ -252,7 +279,7 @@ class Pack {
|
|
252
279
|
const loc = this._findLocation();
|
253
280
|
this.content[loc] = null; // reserve
|
254
281
|
const pack = {
|
255
|
-
/** @type {
|
282
|
+
/** @type {Items} */
|
256
283
|
items: new Set(),
|
257
284
|
/** @type {Map<string, any>} */
|
258
285
|
map: new Map(),
|
@@ -351,20 +378,21 @@ class Pack {
|
|
351
378
|
mergedIndices = smallUnusedContents;
|
352
379
|
} else return;
|
353
380
|
|
381
|
+
/** @type {PackContent[] } */
|
354
382
|
const mergedContent = [];
|
355
383
|
|
356
384
|
// 3. Remove old content entries
|
357
385
|
for (const i of mergedIndices) {
|
358
|
-
mergedContent.push(this.content[i]);
|
386
|
+
mergedContent.push(/** @type {PackContent} */ (this.content[i]));
|
359
387
|
this.content[i] = undefined;
|
360
388
|
}
|
361
389
|
|
362
390
|
// 4. Determine merged items
|
363
|
-
/** @type {
|
391
|
+
/** @type {Items} */
|
364
392
|
const mergedItems = new Set();
|
365
|
-
/** @type {
|
393
|
+
/** @type {Items} */
|
366
394
|
const mergedUsedItems = new Set();
|
367
|
-
/** @type {(function(Map<string, any>): Promise)[]} */
|
395
|
+
/** @type {(function(Map<string, any>): Promise<void>)[]} */
|
368
396
|
const addToMergedMap = [];
|
369
397
|
for (const content of mergedContent) {
|
370
398
|
for (const identifier of content.items) {
|
@@ -498,17 +526,20 @@ class Pack {
|
|
498
526
|
* Only runs for one content to avoid large invalidation.
|
499
527
|
*/
|
500
528
|
_gcOldestContent() {
|
501
|
-
/** @type {PackItemInfo} */
|
502
|
-
let oldest
|
529
|
+
/** @type {PackItemInfo | undefined} */
|
530
|
+
let oldest;
|
503
531
|
for (const info of this.itemInfo.values()) {
|
504
532
|
if (oldest === undefined || info.lastAccess < oldest.lastAccess) {
|
505
533
|
oldest = info;
|
506
534
|
}
|
507
535
|
}
|
508
|
-
if (
|
509
|
-
|
536
|
+
if (
|
537
|
+
Date.now() - /** @type {PackItemInfo} */ (oldest).lastAccess >
|
538
|
+
this.maxAge
|
539
|
+
) {
|
540
|
+
const loc = /** @type {PackItemInfo} */ (oldest).location;
|
510
541
|
if (loc < 0) return;
|
511
|
-
const content = this.content[loc];
|
542
|
+
const content = /** @type {PackContent} */ (this.content[loc]);
|
512
543
|
const items = new Set(content.items);
|
513
544
|
const usedItems = new Set(content.used);
|
514
545
|
this._gcAndUpdateLocation(items, usedItems, loc);
|
@@ -524,11 +555,14 @@ class Pack {
|
|
524
555
|
map.set(identifier, content.content.get(identifier));
|
525
556
|
}
|
526
557
|
return new PackContentItems(map);
|
527
|
-
|
558
|
+
})
|
528
559
|
: undefined;
|
529
560
|
}
|
530
561
|
}
|
531
562
|
|
563
|
+
/**
|
564
|
+
* @param {ObjectSerializerContext} context context
|
565
|
+
*/
|
532
566
|
serialize({ write, writeSeparate }) {
|
533
567
|
this._persistFreshContent();
|
534
568
|
this._optimizeSmallContent();
|
@@ -556,6 +590,9 @@ class Pack {
|
|
556
590
|
write(null); // null as marker of the end of items
|
557
591
|
}
|
558
592
|
|
593
|
+
/**
|
594
|
+
* @param {ObjectDeserializerContext & { logger: Logger }} context context
|
595
|
+
*/
|
559
596
|
deserialize({ read, logger }) {
|
560
597
|
this.logger = logger;
|
561
598
|
{
|
@@ -614,6 +651,9 @@ class PackContentItems {
|
|
614
651
|
this.map = map;
|
615
652
|
}
|
616
653
|
|
654
|
+
/**
|
655
|
+
* @param {ObjectSerializerContext & { snapshot: TODO, rollback: TODO, logger: Logger, profile: boolean | undefined }} context context
|
656
|
+
*/
|
617
657
|
serialize({ write, snapshot, rollback, logger, profile }) {
|
618
658
|
if (profile) {
|
619
659
|
write(false);
|
@@ -636,13 +676,17 @@ class PackContentItems {
|
|
636
676
|
logger.log(`Serialization of '${key}': ${duration} ms`);
|
637
677
|
else logger.debug(`Serialization of '${key}': ${duration} ms`);
|
638
678
|
}
|
639
|
-
} catch (
|
679
|
+
} catch (err) {
|
640
680
|
rollback(s);
|
641
|
-
if (
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
681
|
+
if (err === NOT_SERIALIZABLE) continue;
|
682
|
+
const msg = "Skipped not serializable cache item";
|
683
|
+
if (err.message.includes("ModuleBuildError")) {
|
684
|
+
logger.log(`${msg} (in build error): ${err.message}`);
|
685
|
+
logger.debug(`${msg} '${key}' (in build error): ${err.stack}`);
|
686
|
+
} else {
|
687
|
+
logger.warn(`${msg}: ${err.message}`);
|
688
|
+
logger.debug(`${msg} '${key}': ${err.stack}`);
|
689
|
+
}
|
646
690
|
}
|
647
691
|
}
|
648
692
|
write(null);
|
@@ -653,7 +697,7 @@ class PackContentItems {
|
|
653
697
|
try {
|
654
698
|
write(true);
|
655
699
|
write(this.map);
|
656
|
-
} catch (
|
700
|
+
} catch (_err) {
|
657
701
|
rollback(s);
|
658
702
|
|
659
703
|
// Try to serialize each item on it's own
|
@@ -663,19 +707,22 @@ class PackContentItems {
|
|
663
707
|
try {
|
664
708
|
write(key);
|
665
709
|
write(value);
|
666
|
-
} catch (
|
710
|
+
} catch (err) {
|
667
711
|
rollback(s);
|
668
|
-
if (
|
712
|
+
if (err === NOT_SERIALIZABLE) continue;
|
669
713
|
logger.warn(
|
670
|
-
`Skipped not serializable cache item '${key}': ${
|
714
|
+
`Skipped not serializable cache item '${key}': ${err.message}`
|
671
715
|
);
|
672
|
-
logger.debug(
|
716
|
+
logger.debug(err.stack);
|
673
717
|
}
|
674
718
|
}
|
675
719
|
write(null);
|
676
720
|
}
|
677
721
|
}
|
678
722
|
|
723
|
+
/**
|
724
|
+
* @param {ObjectDeserializerContext & { logger: Logger, profile: boolean | undefined }} context context
|
725
|
+
*/
|
679
726
|
deserialize({ read, logger, profile }) {
|
680
727
|
if (read()) {
|
681
728
|
this.map = read();
|
@@ -741,17 +788,17 @@ class PackContent {
|
|
741
788
|
*/
|
742
789
|
|
743
790
|
/**
|
744
|
-
* @param {
|
745
|
-
* @param {
|
791
|
+
* @param {Items} items keys
|
792
|
+
* @param {Items} usedItems used keys
|
746
793
|
* @param {PackContentItems | function(): Promise<PackContentItems>} dataOrFn sync or async content
|
747
794
|
* @param {Logger=} logger logger for logging
|
748
795
|
* @param {string=} lazyName name of dataOrFn for logging
|
749
796
|
*/
|
750
797
|
constructor(items, usedItems, dataOrFn, logger, lazyName) {
|
751
798
|
this.items = items;
|
752
|
-
/** @type {function(): Promise<PackContentItems> | PackContentItems} */
|
799
|
+
/** @type {(function(): Promise<PackContentItems> | PackContentItems) | undefined} */
|
753
800
|
this.lazy = typeof dataOrFn === "function" ? dataOrFn : undefined;
|
754
|
-
/** @type {Map<string, any>} */
|
801
|
+
/** @type {Map<string, any> | undefined} */
|
755
802
|
this.content = typeof dataOrFn === "function" ? undefined : dataOrFn.map;
|
756
803
|
this.outdated = false;
|
757
804
|
this.used = usedItems;
|
@@ -759,14 +806,20 @@ class PackContent {
|
|
759
806
|
this.lazyName = lazyName;
|
760
807
|
}
|
761
808
|
|
809
|
+
/**
|
810
|
+
* @param {string} identifier identifier
|
811
|
+
* @returns {string | Promise<string>} result
|
812
|
+
*/
|
762
813
|
get(identifier) {
|
763
814
|
this.used.add(identifier);
|
764
815
|
if (this.content) {
|
765
816
|
return this.content.get(identifier);
|
766
817
|
}
|
767
818
|
|
819
|
+
const logger = /** @type {Logger} */ (this.logger);
|
768
820
|
// We are in state B
|
769
821
|
const { lazyName } = this;
|
822
|
+
/** @type {string | undefined} */
|
770
823
|
let timeMessage;
|
771
824
|
if (lazyName) {
|
772
825
|
// only log once
|
@@ -774,47 +827,49 @@ class PackContent {
|
|
774
827
|
timeMessage = `restore cache content ${lazyName} (${formatSize(
|
775
828
|
this.getSize()
|
776
829
|
)})`;
|
777
|
-
|
830
|
+
logger.log(
|
778
831
|
`starting to restore cache content ${lazyName} (${formatSize(
|
779
832
|
this.getSize()
|
780
833
|
)}) because of request to: ${identifier}`
|
781
834
|
);
|
782
|
-
|
835
|
+
logger.time(timeMessage);
|
783
836
|
}
|
784
837
|
const value = this.lazy();
|
785
|
-
if (
|
838
|
+
if ("then" in value) {
|
786
839
|
return value.then(data => {
|
787
840
|
const map = data.map;
|
788
841
|
if (timeMessage) {
|
789
|
-
|
842
|
+
logger.timeEnd(timeMessage);
|
790
843
|
}
|
791
844
|
// Move to state C
|
792
845
|
this.content = map;
|
793
846
|
this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy);
|
794
847
|
return map.get(identifier);
|
795
848
|
});
|
796
|
-
} else {
|
797
|
-
const map = value.map;
|
798
|
-
if (timeMessage) {
|
799
|
-
this.logger.timeEnd(timeMessage);
|
800
|
-
}
|
801
|
-
// Move to state C
|
802
|
-
this.content = map;
|
803
|
-
this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy);
|
804
|
-
return map.get(identifier);
|
805
849
|
}
|
850
|
+
|
851
|
+
const map = value.map;
|
852
|
+
if (timeMessage) {
|
853
|
+
logger.timeEnd(timeMessage);
|
854
|
+
}
|
855
|
+
// Move to state C
|
856
|
+
this.content = map;
|
857
|
+
this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy);
|
858
|
+
return map.get(identifier);
|
806
859
|
}
|
807
860
|
|
808
861
|
/**
|
809
862
|
* @param {string} reason explanation why unpack is necessary
|
810
|
-
* @returns {void | Promise} maybe a promise if lazy
|
863
|
+
* @returns {void | Promise<void>} maybe a promise if lazy
|
811
864
|
*/
|
812
865
|
unpack(reason) {
|
813
866
|
if (this.content) return;
|
814
867
|
|
868
|
+
const logger = /** @type {Logger} */ (this.logger);
|
815
869
|
// Move from state B to C
|
816
870
|
if (this.lazy) {
|
817
871
|
const { lazyName } = this;
|
872
|
+
/** @type {string | undefined} */
|
818
873
|
let timeMessage;
|
819
874
|
if (lazyName) {
|
820
875
|
// only log once
|
@@ -822,27 +877,26 @@ class PackContent {
|
|
822
877
|
timeMessage = `unpack cache content ${lazyName} (${formatSize(
|
823
878
|
this.getSize()
|
824
879
|
)})`;
|
825
|
-
|
880
|
+
logger.log(
|
826
881
|
`starting to unpack cache content ${lazyName} (${formatSize(
|
827
882
|
this.getSize()
|
828
883
|
)}) because ${reason}`
|
829
884
|
);
|
830
|
-
|
885
|
+
logger.time(timeMessage);
|
831
886
|
}
|
832
887
|
const value = this.lazy();
|
833
|
-
if (
|
888
|
+
if ("then" in value) {
|
834
889
|
return value.then(data => {
|
835
890
|
if (timeMessage) {
|
836
|
-
|
891
|
+
logger.timeEnd(timeMessage);
|
837
892
|
}
|
838
893
|
this.content = data.map;
|
839
894
|
});
|
840
|
-
} else {
|
841
|
-
if (timeMessage) {
|
842
|
-
this.logger.timeEnd(timeMessage);
|
843
|
-
}
|
844
|
-
this.content = value.map;
|
845
895
|
}
|
896
|
+
if (timeMessage) {
|
897
|
+
logger.timeEnd(timeMessage);
|
898
|
+
}
|
899
|
+
this.content = value.map;
|
846
900
|
}
|
847
901
|
}
|
848
902
|
|
@@ -858,6 +912,9 @@ class PackContent {
|
|
858
912
|
return size;
|
859
913
|
}
|
860
914
|
|
915
|
+
/**
|
916
|
+
* @param {string} identifier identifier
|
917
|
+
*/
|
861
918
|
delete(identifier) {
|
862
919
|
this.items.delete(identifier);
|
863
920
|
this.used.delete(identifier);
|
@@ -900,8 +957,10 @@ class PackContent {
|
|
900
957
|
);
|
901
958
|
return;
|
902
959
|
}
|
960
|
+
const logger = /** @type {Logger} */ (this.logger);
|
903
961
|
// State B2
|
904
962
|
const { lazyName } = this;
|
963
|
+
/** @type {string | undefined} */
|
905
964
|
let timeMessage;
|
906
965
|
if (lazyName) {
|
907
966
|
// only log once
|
@@ -909,21 +968,21 @@ class PackContent {
|
|
909
968
|
timeMessage = `unpack cache content ${lazyName} (${formatSize(
|
910
969
|
this.getSize()
|
911
970
|
)})`;
|
912
|
-
|
971
|
+
logger.log(
|
913
972
|
`starting to unpack cache content ${lazyName} (${formatSize(
|
914
973
|
this.getSize()
|
915
974
|
)}) because it's outdated and need to be serialized`
|
916
975
|
);
|
917
|
-
|
976
|
+
logger.time(timeMessage);
|
918
977
|
}
|
919
978
|
const value = this.lazy();
|
920
979
|
this.outdated = false;
|
921
|
-
if (
|
980
|
+
if ("then" in value) {
|
922
981
|
// Move to state B1
|
923
982
|
this.lazy = write(() =>
|
924
983
|
value.then(data => {
|
925
984
|
if (timeMessage) {
|
926
|
-
|
985
|
+
logger.timeEnd(timeMessage);
|
927
986
|
}
|
928
987
|
const oldMap = data.map;
|
929
988
|
/** @type {Map<string, any>} */
|
@@ -941,7 +1000,7 @@ class PackContent {
|
|
941
1000
|
} else {
|
942
1001
|
// Move to state C1
|
943
1002
|
if (timeMessage) {
|
944
|
-
|
1003
|
+
logger.timeEnd(timeMessage);
|
945
1004
|
}
|
946
1005
|
const oldMap = value.map;
|
947
1006
|
/** @type {Map<string, any>} */
|
@@ -955,6 +1014,10 @@ class PackContent {
|
|
955
1014
|
}
|
956
1015
|
}
|
957
1016
|
|
1017
|
+
/**
|
1018
|
+
* @param {Buffer} buf buffer
|
1019
|
+
* @returns {Buffer} buffer that can be collected
|
1020
|
+
*/
|
958
1021
|
const allowCollectingMemory = buf => {
|
959
1022
|
const wasted = buf.buffer.byteLength - buf.byteLength;
|
960
1023
|
if (wasted > 8192 && (wasted > 1048576 || wasted > buf.byteLength)) {
|
@@ -965,7 +1028,7 @@ const allowCollectingMemory = buf => {
|
|
965
1028
|
|
966
1029
|
class PackFileCacheStrategy {
|
967
1030
|
/**
|
968
|
-
* @param {
|
1031
|
+
* @param {object} options options
|
969
1032
|
* @param {Compiler} options.compiler the compiler
|
970
1033
|
* @param {IntermediateFileSystem} options.fs the filesystem
|
971
1034
|
* @param {string} options.context the context directory
|
@@ -974,9 +1037,10 @@ class PackFileCacheStrategy {
|
|
974
1037
|
* @param {Logger} options.logger a logger
|
975
1038
|
* @param {SnapshotOptions} options.snapshot options regarding snapshotting
|
976
1039
|
* @param {number} options.maxAge max age of cache items
|
977
|
-
* @param {boolean} options.profile track and log detailed timing information for individual cache items
|
978
|
-
* @param {boolean} options.allowCollectingMemory allow to collect unused memory created during deserialization
|
979
|
-
* @param {false | "gzip" | "brotli"} options.compression compression used
|
1040
|
+
* @param {boolean | undefined} options.profile track and log detailed timing information for individual cache items
|
1041
|
+
* @param {boolean | undefined} options.allowCollectingMemory allow to collect unused memory created during deserialization
|
1042
|
+
* @param {false | "gzip" | "brotli" | undefined} options.compression compression used
|
1043
|
+
* @param {boolean | undefined} options.readonly disable storing cache into filesystem
|
980
1044
|
*/
|
981
1045
|
constructor({
|
982
1046
|
compiler,
|
@@ -989,9 +1053,13 @@ class PackFileCacheStrategy {
|
|
989
1053
|
maxAge,
|
990
1054
|
profile,
|
991
1055
|
allowCollectingMemory,
|
992
|
-
compression
|
1056
|
+
compression,
|
1057
|
+
readonly
|
993
1058
|
}) {
|
994
|
-
this.fileSerializer = createFileSerializer(
|
1059
|
+
this.fileSerializer = createFileSerializer(
|
1060
|
+
fs,
|
1061
|
+
compiler.options.output.hashFunction
|
1062
|
+
);
|
995
1063
|
this.fileSystemInfo = new FileSystemInfo(fs, {
|
996
1064
|
managedPaths: snapshot.managedPaths,
|
997
1065
|
immutablePaths: snapshot.immutablePaths,
|
@@ -1005,30 +1073,34 @@ class PackFileCacheStrategy {
|
|
1005
1073
|
this.logger = logger;
|
1006
1074
|
this.maxAge = maxAge;
|
1007
1075
|
this.profile = profile;
|
1076
|
+
this.readonly = readonly;
|
1008
1077
|
this.allowCollectingMemory = allowCollectingMemory;
|
1009
1078
|
this.compression = compression;
|
1010
1079
|
this._extension =
|
1011
1080
|
compression === "brotli"
|
1012
1081
|
? ".pack.br"
|
1013
1082
|
: compression === "gzip"
|
1014
|
-
|
1015
|
-
|
1083
|
+
? ".pack.gz"
|
1084
|
+
: ".pack";
|
1016
1085
|
this.snapshot = snapshot;
|
1017
|
-
/** @type {
|
1086
|
+
/** @type {BuildDependencies} */
|
1018
1087
|
this.buildDependencies = new Set();
|
1019
1088
|
/** @type {LazySet<string>} */
|
1020
1089
|
this.newBuildDependencies = new LazySet();
|
1021
|
-
/** @type {Snapshot} */
|
1090
|
+
/** @type {Snapshot | undefined} */
|
1022
1091
|
this.resolveBuildDependenciesSnapshot = undefined;
|
1023
|
-
/** @type {
|
1092
|
+
/** @type {ResolveResults | undefined} */
|
1024
1093
|
this.resolveResults = undefined;
|
1025
|
-
/** @type {Snapshot} */
|
1094
|
+
/** @type {Snapshot | undefined} */
|
1026
1095
|
this.buildSnapshot = undefined;
|
1027
|
-
/** @type {Promise<Pack>} */
|
1096
|
+
/** @type {Promise<Pack> | undefined} */
|
1028
1097
|
this.packPromise = this._openPack();
|
1029
1098
|
this.storePromise = Promise.resolve();
|
1030
1099
|
}
|
1031
1100
|
|
1101
|
+
/**
|
1102
|
+
* @returns {Promise<Pack>} pack
|
1103
|
+
*/
|
1032
1104
|
_getPack() {
|
1033
1105
|
if (this.packPromise === undefined) {
|
1034
1106
|
this.packPromise = this.storePromise.then(() => this._openPack());
|
@@ -1043,13 +1115,13 @@ class PackFileCacheStrategy {
|
|
1043
1115
|
const { logger, profile, cacheLocation, version } = this;
|
1044
1116
|
/** @type {Snapshot} */
|
1045
1117
|
let buildSnapshot;
|
1046
|
-
/** @type {
|
1118
|
+
/** @type {BuildDependencies} */
|
1047
1119
|
let buildDependencies;
|
1048
|
-
/** @type {
|
1120
|
+
/** @type {BuildDependencies} */
|
1049
1121
|
let newBuildDependencies;
|
1050
1122
|
/** @type {Snapshot} */
|
1051
1123
|
let resolveBuildDependenciesSnapshot;
|
1052
|
-
/** @type {
|
1124
|
+
/** @type {ResolveResults | undefined} */
|
1053
1125
|
let resolveResults;
|
1054
1126
|
logger.time("restore cache container");
|
1055
1127
|
return this.fileSerializer
|
@@ -1077,19 +1149,19 @@ class PackFileCacheStrategy {
|
|
1077
1149
|
})
|
1078
1150
|
.then(packContainer => {
|
1079
1151
|
logger.timeEnd("restore cache container");
|
1080
|
-
if (!packContainer) return
|
1152
|
+
if (!packContainer) return;
|
1081
1153
|
if (!(packContainer instanceof PackContainer)) {
|
1082
1154
|
logger.warn(
|
1083
1155
|
`Restored pack from ${cacheLocation}${this._extension}, but contained content is unexpected.`,
|
1084
1156
|
packContainer
|
1085
1157
|
);
|
1086
|
-
return
|
1158
|
+
return;
|
1087
1159
|
}
|
1088
1160
|
if (packContainer.version !== version) {
|
1089
1161
|
logger.log(
|
1090
1162
|
`Restored pack from ${cacheLocation}${this._extension}, but version doesn't match.`
|
1091
1163
|
);
|
1092
|
-
return
|
1164
|
+
return;
|
1093
1165
|
}
|
1094
1166
|
logger.time("check build dependencies");
|
1095
1167
|
return Promise.all([
|
@@ -1206,6 +1278,8 @@ class PackFileCacheStrategy {
|
|
1206
1278
|
* @returns {Promise<void>} promise
|
1207
1279
|
*/
|
1208
1280
|
store(identifier, etag, data) {
|
1281
|
+
if (this.readonly) return Promise.resolve();
|
1282
|
+
|
1209
1283
|
return this._getPack().then(pack => {
|
1210
1284
|
pack.set(identifier, etag === null ? null : etag.toString(), data);
|
1211
1285
|
});
|
@@ -1231,7 +1305,11 @@ class PackFileCacheStrategy {
|
|
1231
1305
|
});
|
1232
1306
|
}
|
1233
1307
|
|
1308
|
+
/**
|
1309
|
+
* @param {LazySet<string> | Iterable<string>} dependencies dependencies to store
|
1310
|
+
*/
|
1234
1311
|
storeBuildDependencies(dependencies) {
|
1312
|
+
if (this.readonly) return;
|
1235
1313
|
this.newBuildDependencies.addAll(dependencies);
|
1236
1314
|
}
|
1237
1315
|
|
@@ -1244,7 +1322,7 @@ class PackFileCacheStrategy {
|
|
1244
1322
|
pack.stopCapturingRequests();
|
1245
1323
|
if (!pack.invalid) return;
|
1246
1324
|
this.packPromise = undefined;
|
1247
|
-
this.logger.log(
|
1325
|
+
this.logger.log("Storing pack...");
|
1248
1326
|
let promise;
|
1249
1327
|
const newBuildDependencies = new Set();
|
1250
1328
|
for (const dep of this.newBuildDependencies) {
|
@@ -1275,7 +1353,7 @@ class PackFileCacheStrategy {
|
|
1275
1353
|
missing,
|
1276
1354
|
resolveResults,
|
1277
1355
|
resolveDependencies
|
1278
|
-
} = result;
|
1356
|
+
} = /** @type {ResolveBuildDependenciesResult} */ (result);
|
1279
1357
|
if (this.resolveResults) {
|
1280
1358
|
for (const [key, value] of resolveResults) {
|
1281
1359
|
this.resolveResults.set(key, value);
|
@@ -1362,7 +1440,7 @@ class PackFileCacheStrategy {
|
|
1362
1440
|
}
|
1363
1441
|
return promise.then(() => {
|
1364
1442
|
if (reportProgress) reportProgress(0.8, "serialize pack");
|
1365
|
-
this.logger.time(
|
1443
|
+
this.logger.time("store pack");
|
1366
1444
|
const updatedBuildDependencies = new Set(this.buildDependencies);
|
1367
1445
|
for (const dep of newBuildDependencies) {
|
1368
1446
|
updatedBuildDependencies.add(dep);
|
@@ -1370,7 +1448,7 @@ class PackFileCacheStrategy {
|
|
1370
1448
|
const content = new PackContainer(
|
1371
1449
|
pack,
|
1372
1450
|
this.version,
|
1373
|
-
this.buildSnapshot,
|
1451
|
+
/** @type {Snapshot} */ (this.buildSnapshot),
|
1374
1452
|
updatedBuildDependencies,
|
1375
1453
|
this.resolveResults,
|
1376
1454
|
this.resolveBuildDependenciesSnapshot
|
@@ -1387,7 +1465,7 @@ class PackFileCacheStrategy {
|
|
1387
1465
|
this.buildDependencies.add(dep);
|
1388
1466
|
}
|
1389
1467
|
this.newBuildDependencies.clear();
|
1390
|
-
this.logger.timeEnd(
|
1468
|
+
this.logger.timeEnd("store pack");
|
1391
1469
|
const stats = pack.getContentStats();
|
1392
1470
|
this.logger.log(
|
1393
1471
|
"Stored pack (%d items, %d files, %d MiB)",
|
@@ -1397,7 +1475,7 @@ class PackFileCacheStrategy {
|
|
1397
1475
|
);
|
1398
1476
|
})
|
1399
1477
|
.catch(err => {
|
1400
|
-
this.logger.timeEnd(
|
1478
|
+
this.logger.timeEnd("store pack");
|
1401
1479
|
this.logger.warn(`Caching failed for pack: ${err}`);
|
1402
1480
|
this.logger.debug(err.stack);
|
1403
1481
|
});
|