webpack 5.76.1 → 5.88.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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +10 -4
- package/bin/webpack.js +26 -2
- package/hot/dev-server.js +2 -1
- package/hot/lazy-compilation-node.js +10 -0
- package/hot/lazy-compilation-web.js +9 -0
- package/hot/log-apply-result.js +5 -0
- package/hot/log.js +22 -0
- package/hot/only-dev-server.js +2 -1
- package/hot/poll.js +3 -0
- package/hot/signal.js +4 -0
- package/lib/APIPlugin.js +174 -116
- package/lib/AsyncDependenciesBlock.js +13 -5
- package/lib/AutomaticPrefetchPlugin.js +1 -0
- package/lib/BannerPlugin.js +4 -0
- package/lib/CacheFacade.js +4 -0
- package/lib/CaseSensitiveModulesWarning.js +3 -1
- package/lib/Chunk.js +36 -18
- package/lib/ChunkGraph.js +4 -4
- package/lib/ChunkGroup.js +25 -10
- package/lib/CleanPlugin.js +30 -7
- package/lib/CodeGenerationResults.js +2 -2
- package/lib/CompatibilityPlugin.js +85 -46
- package/lib/Compilation.js +17 -8
- package/lib/Compiler.js +12 -8
- package/lib/ConcatenationScope.js +2 -2
- package/lib/ConditionalInitFragment.js +11 -1
- package/lib/ConstPlugin.js +79 -44
- package/lib/ContextModule.js +20 -6
- package/lib/ContextModuleFactory.js +2 -1
- package/lib/ContextReplacementPlugin.js +13 -0
- package/lib/CssModule.js +169 -0
- package/lib/DefinePlugin.js +152 -86
- package/lib/DelegatedModule.js +22 -4
- package/lib/DelegatedModuleFactoryPlugin.js +6 -0
- package/lib/DependenciesBlock.js +17 -1
- package/lib/Dependency.js +19 -5
- package/lib/DllEntryPlugin.js +16 -1
- package/lib/DllModule.js +17 -2
- package/lib/DllModuleFactory.js +1 -1
- package/lib/DllReferencePlugin.js +13 -1
- package/lib/Entrypoint.js +1 -1
- package/lib/ErrorHelpers.js +62 -22
- package/lib/EvalSourceMapDevToolPlugin.js +9 -2
- package/lib/ExportsInfo.js +20 -3
- package/lib/ExportsInfoApiPlugin.js +30 -14
- package/lib/ExternalModule.js +30 -9
- package/lib/FileSystemInfo.js +9 -1
- package/lib/FlagAllModulesAsUsedPlugin.js +27 -27
- package/lib/FlagDependencyExportsPlugin.js +336 -348
- package/lib/FlagDependencyUsagePlugin.js +9 -9
- package/lib/FlagEntryExportAsUsedPlugin.js +26 -23
- package/lib/HookWebpackError.js +1 -1
- package/lib/HotModuleReplacementPlugin.js +60 -46
- package/lib/IgnoreErrorModuleFactory.js +1 -1
- package/lib/InitFragment.js +28 -5
- package/lib/JavascriptMetaInfoPlugin.js +27 -15
- package/lib/LibManifestPlugin.js +22 -5
- package/lib/LoaderOptionsPlugin.js +12 -2
- package/lib/MainTemplate.js +2 -2
- package/lib/Module.js +44 -12
- package/lib/ModuleBuildError.js +9 -0
- package/lib/ModuleDependencyError.js +4 -2
- package/lib/ModuleDependencyWarning.js +4 -2
- package/lib/ModuleError.js +9 -0
- package/lib/ModuleFactory.js +1 -1
- package/lib/ModuleFilenameHelpers.js +114 -4
- package/lib/ModuleGraph.js +33 -23
- package/lib/ModuleGraphConnection.js +19 -6
- package/lib/ModuleInfoHeaderPlugin.js +9 -2
- package/lib/ModuleNotFoundError.js +5 -2
- package/lib/ModuleParseError.js +9 -0
- package/lib/ModuleProfile.js +1 -0
- package/lib/ModuleRestoreError.js +2 -0
- package/lib/ModuleStoreError.js +2 -1
- package/lib/ModuleTypeConstants.js +169 -0
- package/lib/ModuleWarning.js +9 -0
- package/lib/MultiWatching.js +4 -0
- package/lib/NodeStuffPlugin.js +65 -35
- package/lib/NormalModule.js +12 -2
- package/lib/NormalModuleFactory.js +56 -8
- package/lib/NormalModuleReplacementPlugin.js +5 -3
- package/lib/NullFactory.js +1 -1
- package/lib/PrefetchPlugin.js +4 -0
- package/lib/ProgressPlugin.js +71 -15
- package/lib/ProvidePlugin.js +30 -14
- package/lib/RawModule.js +13 -2
- package/lib/RecordIdsPlugin.js +4 -4
- package/lib/RequireJsStuffPlugin.js +22 -15
- package/lib/RuntimeGlobals.js +5 -0
- package/lib/RuntimeModule.js +12 -11
- package/lib/RuntimePlugin.js +10 -3
- package/lib/RuntimeTemplate.js +29 -11
- package/lib/SelfModuleFactory.js +12 -0
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
- package/lib/SourceMapDevToolPlugin.js +47 -11
- package/lib/Template.js +5 -3
- package/lib/UseStrictPlugin.js +29 -11
- package/lib/WarnCaseSensitiveModulesPlugin.js +12 -0
- package/lib/WarnDeprecatedOptionPlugin.js +7 -0
- package/lib/WatchIgnorePlugin.js +4 -0
- package/lib/WebpackError.js +14 -5
- package/lib/WebpackIsIncludedPlugin.js +22 -13
- package/lib/WebpackOptionsApply.js +41 -44
- package/lib/WebpackOptionsDefaulter.js +10 -3
- package/lib/asset/AssetGenerator.js +24 -9
- package/lib/asset/AssetModulesPlugin.js +28 -12
- package/lib/asset/AssetParser.js +15 -7
- package/lib/asset/AssetSourceParser.js +8 -3
- package/lib/asset/RawDataUrlModule.js +15 -4
- package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
- package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
- package/lib/cache/IdleFileCachePlugin.js +2 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +2 -0
- package/lib/cache/PackFileCacheStrategy.js +42 -15
- package/lib/cache/ResolverCachePlugin.js +3 -0
- package/lib/config/browserslistTargetHandler.js +10 -10
- package/lib/config/defaults.js +306 -105
- package/lib/config/normalization.js +110 -71
- package/lib/config/target.js +37 -10
- package/lib/container/ContainerEntryModule.js +11 -1
- package/lib/container/ContainerEntryModuleFactory.js +1 -1
- package/lib/container/ContainerExposedDependency.js +9 -0
- package/lib/container/ContainerPlugin.js +3 -1
- package/lib/container/FallbackDependency.js +13 -0
- package/lib/container/FallbackItemDependency.js +3 -0
- package/lib/container/FallbackModule.js +12 -2
- package/lib/container/FallbackModuleFactory.js +1 -1
- package/lib/container/RemoteModule.js +11 -1
- package/lib/container/RemoteRuntimeModule.js +3 -2
- package/lib/container/RemoteToExternalDependency.js +3 -0
- package/lib/css/CssExportsGenerator.js +9 -0
- package/lib/css/CssGenerator.js +5 -1
- package/lib/css/CssLoadingRuntimeModule.js +53 -22
- package/lib/css/CssModulesPlugin.js +253 -74
- package/lib/css/CssParser.js +697 -282
- package/lib/css/walkCssTokens.js +269 -138
- package/lib/debug/ProfilingPlugin.js +33 -12
- package/lib/dependencies/AMDDefineDependency.js +54 -10
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +13 -2
- package/lib/dependencies/AMDPlugin.js +33 -20
- package/lib/dependencies/AMDRequireArrayDependency.js +13 -0
- package/lib/dependencies/AMDRequireContextDependency.js +15 -0
- package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -2
- package/lib/dependencies/AMDRequireDependency.js +16 -1
- package/lib/dependencies/AMDRequireItemDependency.js +6 -0
- package/lib/dependencies/AMDRuntimeModules.js +2 -2
- package/lib/dependencies/CachedConstDependency.js +14 -0
- package/lib/dependencies/CommonJsDependencyHelpers.js +9 -0
- package/lib/dependencies/CommonJsExportRequireDependency.js +19 -0
- package/lib/dependencies/CommonJsExportsDependency.js +16 -0
- package/lib/dependencies/CommonJsExportsParserPlugin.js +77 -5
- package/lib/dependencies/CommonJsFullRequireDependency.js +10 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +174 -63
- package/lib/dependencies/CommonJsPlugin.js +51 -26
- package/lib/dependencies/CommonJsRequireContextDependency.js +17 -0
- package/lib/dependencies/CommonJsRequireDependency.js +7 -0
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +16 -0
- package/lib/dependencies/ConstDependency.js +11 -2
- package/lib/dependencies/ContextDependency.js +15 -2
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/ContextElementDependency.js +8 -0
- package/lib/dependencies/CreateScriptUrlDependency.js +10 -1
- package/lib/dependencies/CriticalDependencyWarning.js +3 -0
- package/lib/dependencies/CssExportDependency.js +8 -0
- package/lib/dependencies/CssImportDependency.js +55 -3
- package/lib/dependencies/CssLocalIdentifierDependency.js +15 -1
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +10 -1
- package/lib/dependencies/CssUrlDependency.js +46 -16
- package/lib/dependencies/DelegatedSourceDependency.js +3 -0
- package/lib/dependencies/DllEntryDependency.js +14 -0
- package/lib/dependencies/DynamicExports.js +10 -6
- package/lib/dependencies/ExportsInfoDependency.js +25 -4
- package/lib/dependencies/HarmonyAcceptDependency.js +10 -1
- package/lib/dependencies/HarmonyAcceptImportDependency.js +3 -0
- package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +22 -2
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +32 -6
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +5 -0
- package/lib/dependencies/HarmonyExportExpressionDependency.js +20 -3
- package/lib/dependencies/HarmonyExportHeaderDependency.js +13 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +22 -6
- package/lib/dependencies/HarmonyExportInitFragment.js +2 -1
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +12 -0
- package/lib/dependencies/HarmonyExports.js +11 -5
- package/lib/dependencies/HarmonyImportDependency.js +10 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +53 -22
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -2
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +139 -16
- package/lib/dependencies/HarmonyModulesPlugin.js +23 -5
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
- package/lib/dependencies/ImportContextDependency.js +15 -0
- package/lib/dependencies/ImportDependency.js +15 -4
- package/lib/dependencies/ImportEagerDependency.js +7 -4
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +51 -13
- package/lib/dependencies/ImportMetaContextPlugin.js +18 -5
- package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
- package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
- package/lib/dependencies/ImportMetaPlugin.js +103 -51
- package/lib/dependencies/ImportParserPlugin.js +83 -25
- package/lib/dependencies/ImportPlugin.js +21 -7
- package/lib/dependencies/ImportWeakDependency.js +7 -4
- package/lib/dependencies/JsonExportsDependency.js +9 -1
- package/lib/dependencies/LocalModule.js +16 -0
- package/lib/dependencies/LocalModuleDependency.js +15 -0
- package/lib/dependencies/LocalModulesHelpers.js +18 -0
- package/lib/dependencies/ModuleDecoratorDependency.js +8 -0
- package/lib/dependencies/ModuleDependency.js +9 -1
- 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 +14 -2
- package/lib/dependencies/PureExpressionDependency.js +10 -1
- package/lib/dependencies/RequireContextDependency.js +6 -0
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
- package/lib/dependencies/RequireContextPlugin.js +19 -6
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +7 -0
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
- 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 +5 -0
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +29 -5
- package/lib/dependencies/RequireIncludePlugin.js +25 -5
- package/lib/dependencies/RequireResolveContextDependency.js +17 -0
- package/lib/dependencies/RequireResolveDependency.js +6 -0
- package/lib/dependencies/RequireResolveHeaderDependency.js +18 -0
- package/lib/dependencies/RuntimeRequirementsDependency.js +8 -0
- package/lib/dependencies/StaticExportsDependency.js +8 -0
- package/lib/dependencies/SystemPlugin.js +48 -21
- package/lib/dependencies/SystemRuntimeModule.js +1 -1
- package/lib/dependencies/URLDependency.js +13 -4
- package/lib/dependencies/URLPlugin.js +31 -18
- 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 +5 -0
- package/lib/dependencies/WorkerDependency.js +47 -3
- package/lib/dependencies/WorkerPlugin.js +105 -32
- package/lib/dependencies/getFunctionExpression.js +7 -0
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +3 -2
- package/lib/esm/ModuleChunkFormatPlugin.js +21 -8
- package/lib/esm/ModuleChunkLoadingPlugin.js +9 -0
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +19 -12
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/hmr/LazyCompilationPlugin.js +14 -5
- package/lib/ids/ChunkModuleIdRangePlugin.js +11 -0
- package/lib/ids/DeterministicChunkIdsPlugin.js +11 -2
- package/lib/ids/DeterministicModuleIdsPlugin.js +11 -7
- package/lib/ids/HashedModuleIdsPlugin.js +9 -2
- package/lib/ids/IdHelpers.js +6 -0
- package/lib/ids/NamedChunkIdsPlugin.js +13 -1
- package/lib/ids/NamedModuleIdsPlugin.js +14 -3
- package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +3 -2
- package/lib/index.js +8 -0
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +3 -3
- package/lib/javascript/BasicEvaluatedExpression.js +137 -11
- package/lib/javascript/ChunkHelpers.js +2 -2
- package/lib/javascript/CommonJsChunkFormatPlugin.js +7 -3
- package/lib/javascript/EnableChunkLoadingPlugin.js +4 -0
- package/lib/javascript/JavascriptModulesPlugin.js +194 -194
- package/lib/javascript/JavascriptParser.js +941 -256
- package/lib/javascript/JavascriptParserHelpers.js +37 -15
- package/lib/javascript/StartupHelpers.js +2 -2
- package/lib/json/JsonData.js +26 -1
- package/lib/json/JsonGenerator.js +21 -7
- package/lib/json/JsonModulesPlugin.js +14 -5
- package/lib/json/JsonParser.js +27 -13
- package/lib/library/AbstractLibraryPlugin.js +4 -0
- package/lib/library/AmdLibraryPlugin.js +22 -6
- package/lib/library/AssignLibraryPlugin.js +6 -4
- package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
- package/lib/library/ModuleLibraryPlugin.js +8 -4
- package/lib/library/SystemLibraryPlugin.js +1 -0
- package/lib/library/UmdLibraryPlugin.js +4 -0
- package/lib/logging/runtime.js +1 -1
- package/lib/logging/truncateArgs.js +4 -0
- package/lib/node/CommonJsChunkLoadingPlugin.js +17 -2
- package/lib/node/NodeTargetPlugin.js +3 -0
- package/lib/node/NodeTemplatePlugin.js +10 -2
- package/lib/node/NodeWatchFileSystem.js +1 -1
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +18 -9
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +12 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +21 -3
- package/lib/node/RequireChunkLoadingRuntimeModule.js +15 -8
- package/lib/node/nodeConsole.js +2 -4
- package/lib/optimize/AggressiveMergingPlugin.js +8 -0
- package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
- package/lib/optimize/ConcatenatedModule.js +8 -6
- package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
- package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
- package/lib/optimize/InnerGraph.js +5 -5
- package/lib/optimize/InnerGraphPlugin.js +57 -48
- package/lib/optimize/LimitChunkCountPlugin.js +29 -4
- package/lib/optimize/MangleExportsPlugin.js +1 -1
- package/lib/optimize/MinMaxSizeWarning.js +5 -0
- package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
- package/lib/optimize/RealContentHashPlugin.js +86 -30
- package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
- package/lib/optimize/RuntimeChunkPlugin.js +9 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +53 -44
- package/lib/optimize/SplitChunksPlugin.js +71 -31
- package/lib/performance/SizeLimitsPlugin.js +7 -4
- package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
- package/lib/rules/BasicEffectRulePlugin.js +4 -0
- package/lib/rules/BasicMatcherRulePlugin.js +5 -0
- package/lib/rules/RuleSetCompiler.js +3 -3
- package/lib/rules/UseEffectRulePlugin.js +6 -4
- package/lib/runtime/AsyncModuleRuntimeModule.js +9 -6
- package/lib/runtime/AutoPublicPathRuntimeModule.js +16 -5
- package/lib/runtime/BaseUriRuntimeModule.js +8 -4
- 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 +5 -2
- package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
- package/lib/runtime/EnsureChunkRuntimeModule.js +18 -4
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +45 -26
- package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
- package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +27 -6
- package/lib/runtime/GlobalRuntimeModule.js +1 -1
- package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
- package/lib/runtime/LoadScriptRuntimeModule.js +65 -50
- package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
- package/lib/runtime/NonceRuntimeModule.js +1 -1
- 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 +13 -4
- package/lib/runtime/StartupEntrypointRuntimeModule.js +11 -7
- package/lib/runtime/SystemContextRuntimeModule.js +1 -1
- package/lib/schemes/DataUriPlugin.js +16 -3
- package/lib/schemes/HttpUriPlugin.js +38 -0
- package/lib/serialization/ArraySerializer.js +22 -6
- package/lib/serialization/BinaryMiddleware.js +164 -1
- package/lib/serialization/DateObjectSerializer.js +15 -4
- package/lib/serialization/ErrorObjectSerializer.js +23 -8
- package/lib/serialization/FileMiddleware.js +17 -0
- package/lib/serialization/MapObjectSerializer.js +24 -8
- package/lib/serialization/NullPrototypeObjectSerializer.js +25 -8
- package/lib/serialization/ObjectMiddleware.js +33 -2
- package/lib/serialization/PlainObjectSerializer.js +23 -12
- package/lib/serialization/RegExpObjectSerializer.js +16 -5
- package/lib/serialization/SetObjectSerializer.js +21 -6
- package/lib/serialization/types.js +1 -1
- package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
- package/lib/sharing/ConsumeSharedModule.js +13 -2
- package/lib/sharing/ConsumeSharedPlugin.js +4 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +22 -7
- package/lib/sharing/ProvideSharedDependency.js +17 -0
- package/lib/sharing/ProvideSharedModule.js +11 -1
- package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +22 -21
- package/lib/sharing/ShareRuntimeModule.js +19 -9
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/sharing/utils.js +320 -7
- package/lib/stats/DefaultStatsFactoryPlugin.js +105 -29
- package/lib/stats/DefaultStatsPresetPlugin.js +9 -0
- package/lib/stats/DefaultStatsPrinterPlugin.js +43 -0
- package/lib/util/AsyncQueue.js +4 -2
- package/lib/util/LazySet.js +10 -2
- package/lib/util/MapHelpers.js +19 -5
- package/lib/util/ParallelismFactorCalculator.js +10 -0
- package/lib/util/Semaphore.js +1 -1
- package/lib/util/StackedCacheMap.js +6 -0
- package/lib/util/StringXor.js +51 -0
- package/lib/util/binarySearchBounds.js +49 -0
- package/lib/util/compileBooleanMatcher.js +31 -0
- package/lib/util/createHash.js +35 -13
- package/lib/util/deprecation.js +18 -3
- package/lib/util/deterministicGrouping.js +50 -11
- package/lib/util/findGraphRoots.js +4 -2
- package/lib/util/hash/md4.js +2 -2
- package/lib/util/hash/xxhash64.js +1 -1
- package/lib/util/identifier.js +4 -0
- package/lib/util/internalSerializables.js +1 -0
- package/lib/util/makeSerializable.js +7 -0
- package/lib/util/memoize.js +3 -3
- package/lib/util/numberHash.js +75 -21
- package/lib/util/processAsyncTree.js +7 -1
- package/lib/util/propertyAccess.js +9 -54
- package/lib/util/propertyName.js +79 -0
- package/lib/util/registerExternalSerializer.js +1 -1
- package/lib/util/runtime.js +14 -1
- package/lib/util/semver.js +1 -1
- package/lib/util/serialization.js +10 -0
- package/lib/util/smartGrouping.js +1 -1
- package/lib/validateSchema.js +6 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +4 -0
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +15 -2
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +14 -3
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +28 -8
- package/lib/wasm-async/AsyncWebAssemblyParser.js +11 -4
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +39 -8
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +17 -6
- package/lib/wasm-sync/WebAssemblyGenerator.js +19 -5
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +53 -43
- package/lib/wasm-sync/WebAssemblyParser.js +15 -4
- package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
- 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 +26 -9
- package/lib/webpack.js +12 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +9 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +20 -17
- package/module.d.ts +55 -37
- package/package.json +59 -56
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +132 -5
- 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/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +8 -0
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +8 -0
- package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
- package/schemas/plugins/css/CssParserOptions.json +1 -1
- package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
- package/types.d.ts +1608 -667
package/lib/Module.js
CHANGED
@@ -28,11 +28,14 @@ const makeSerializable = require("./util/makeSerializable");
|
|
28
28
|
/** @typedef {import("./ExportsInfo").UsageStateType} UsageStateType */
|
29
29
|
/** @typedef {import("./FileSystemInfo")} FileSystemInfo */
|
30
30
|
/** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
|
31
|
+
/** @typedef {import("./ModuleTypeConstants").ModuleTypes} ModuleTypes */
|
31
32
|
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
|
32
33
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
33
34
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
34
35
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
35
36
|
/** @typedef {import("./WebpackError")} WebpackError */
|
37
|
+
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
38
|
+
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
36
39
|
/** @typedef {import("./util/Hash")} Hash */
|
37
40
|
/** @template T @typedef {import("./util/LazySet")<T>} LazySet<T> */
|
38
41
|
/** @template T @typedef {import("./util/SortableSet")<T>} SortableSet<T> */
|
@@ -104,6 +107,12 @@ const makeSerializable = require("./util/makeSerializable");
|
|
104
107
|
*/
|
105
108
|
|
106
109
|
/** @typedef {KnownBuildMeta & Record<string, any>} BuildMeta */
|
110
|
+
/** @typedef {Record<string, any>} BuildInfo */
|
111
|
+
|
112
|
+
/**
|
113
|
+
* @typedef {Object} FactoryMeta
|
114
|
+
* @property {boolean=} sideEffectFree
|
115
|
+
*/
|
107
116
|
|
108
117
|
const EMPTY_RESOLVE_OPTIONS = {};
|
109
118
|
|
@@ -113,6 +122,11 @@ const DEFAULT_TYPES_UNKNOWN = new Set(["unknown"]);
|
|
113
122
|
const DEFAULT_TYPES_JS = new Set(["javascript"]);
|
114
123
|
|
115
124
|
const deprecatedNeedRebuild = util.deprecate(
|
125
|
+
/**
|
126
|
+
* @param {Module} module the module
|
127
|
+
* @param {NeedBuildContext} context context info
|
128
|
+
* @returns {boolean} true, when rebuild is needed
|
129
|
+
*/
|
116
130
|
(module, context) => {
|
117
131
|
return module.needRebuild(
|
118
132
|
context.fileSystemInfo.getDeprecatedFileTimestamps(),
|
@@ -127,14 +141,14 @@ const deprecatedNeedRebuild = util.deprecate(
|
|
127
141
|
|
128
142
|
class Module extends DependenciesBlock {
|
129
143
|
/**
|
130
|
-
* @param {
|
131
|
-
* @param {string=} context an optional context
|
132
|
-
* @param {string=} layer an optional layer in which the module is
|
144
|
+
* @param {ModuleTypes | ""} type the module type, when deserializing the type is not known and is an empty string
|
145
|
+
* @param {(string | null)=} context an optional context
|
146
|
+
* @param {(string | null)=} layer an optional layer in which the module is
|
133
147
|
*/
|
134
148
|
constructor(type, context = null, layer = null) {
|
135
149
|
super();
|
136
150
|
|
137
|
-
/** @type {
|
151
|
+
/** @type {ModuleTypes} */
|
138
152
|
this.type = type;
|
139
153
|
/** @type {string | null} */
|
140
154
|
this.context = context;
|
@@ -148,9 +162,9 @@ class Module extends DependenciesBlock {
|
|
148
162
|
this.debugId = debugId++;
|
149
163
|
|
150
164
|
// Info from Factory
|
151
|
-
/** @type {ResolveOptions} */
|
165
|
+
/** @type {ResolveOptions | undefined} */
|
152
166
|
this.resolveOptions = EMPTY_RESOLVE_OPTIONS;
|
153
|
-
/** @type {
|
167
|
+
/** @type {FactoryMeta | undefined} */
|
154
168
|
this.factoryMeta = undefined;
|
155
169
|
// TODO refactor this -> options object filled from Factory
|
156
170
|
// TODO webpack 6: use an enum
|
@@ -164,9 +178,9 @@ class Module extends DependenciesBlock {
|
|
164
178
|
this._warnings = undefined;
|
165
179
|
/** @type {WebpackError[] | undefined} */
|
166
180
|
this._errors = undefined;
|
167
|
-
/** @type {BuildMeta} */
|
181
|
+
/** @type {BuildMeta | undefined} */
|
168
182
|
this.buildMeta = undefined;
|
169
|
-
/** @type {
|
183
|
+
/** @type {BuildInfo | undefined} */
|
170
184
|
this.buildInfo = undefined;
|
171
185
|
/** @type {Dependency[] | undefined} */
|
172
186
|
this.presentationalDependencies = undefined;
|
@@ -328,6 +342,10 @@ class Module extends DependenciesBlock {
|
|
328
342
|
);
|
329
343
|
}
|
330
344
|
|
345
|
+
/**
|
346
|
+
* @param {Chunk} chunk the chunk
|
347
|
+
* @returns {boolean} true, when the module was added
|
348
|
+
*/
|
331
349
|
addChunk(chunk) {
|
332
350
|
const chunkGraph = ChunkGraph.getChunkGraphForModule(
|
333
351
|
this,
|
@@ -339,6 +357,10 @@ class Module extends DependenciesBlock {
|
|
339
357
|
return true;
|
340
358
|
}
|
341
359
|
|
360
|
+
/**
|
361
|
+
* @param {Chunk} chunk the chunk
|
362
|
+
* @returns {void}
|
363
|
+
*/
|
342
364
|
removeChunk(chunk) {
|
343
365
|
return ChunkGraph.getChunkGraphForModule(
|
344
366
|
this,
|
@@ -347,6 +369,10 @@ class Module extends DependenciesBlock {
|
|
347
369
|
).disconnectChunkAndModule(chunk, this);
|
348
370
|
}
|
349
371
|
|
372
|
+
/**
|
373
|
+
* @param {Chunk} chunk the chunk
|
374
|
+
* @returns {boolean} true, when the module is in the chunk
|
375
|
+
*/
|
350
376
|
isInChunk(chunk) {
|
351
377
|
return ChunkGraph.getChunkGraphForModule(
|
352
378
|
this,
|
@@ -418,7 +444,7 @@ class Module extends DependenciesBlock {
|
|
418
444
|
|
419
445
|
/**
|
420
446
|
* @param {ModuleGraph} moduleGraph the module graph
|
421
|
-
* @param {boolean} strict the importing module is strict
|
447
|
+
* @param {boolean | undefined} strict the importing module is strict
|
422
448
|
* @returns {"namespace" | "default-only" | "default-with-named" | "dynamic"} export type
|
423
449
|
* "namespace": Exports is already a namespace object. namespace = exports.
|
424
450
|
* "dynamic": Check at runtime if __esModule is set. When set: namespace = { ...exports, default: exports }. When not set: namespace = { default: exports }.
|
@@ -432,7 +458,7 @@ class Module extends DependenciesBlock {
|
|
432
458
|
case "namespace":
|
433
459
|
return "namespace";
|
434
460
|
case "default":
|
435
|
-
switch (this.buildMeta.defaultObject) {
|
461
|
+
switch (/** @type {BuildMeta} */ (this.buildMeta).defaultObject) {
|
436
462
|
case "redirect":
|
437
463
|
return "default-with-named";
|
438
464
|
case "redirect-warn":
|
@@ -444,7 +470,7 @@ class Module extends DependenciesBlock {
|
|
444
470
|
if (strict) return "default-with-named";
|
445
471
|
// Try to figure out value of __esModule by following reexports
|
446
472
|
const handleDefault = () => {
|
447
|
-
switch (this.buildMeta.defaultObject) {
|
473
|
+
switch (/** @type {BuildMeta} */ (this.buildMeta).defaultObject) {
|
448
474
|
case "redirect":
|
449
475
|
case "redirect-warn":
|
450
476
|
return "default-with-named";
|
@@ -661,7 +687,7 @@ class Module extends DependenciesBlock {
|
|
661
687
|
] of moduleGraph.getIncomingConnectionsByOriginModule(this)) {
|
662
688
|
if (!connections.some(c => c.isTargetActive(chunk.runtime))) continue;
|
663
689
|
for (const originChunk of chunkGraph.getModuleChunksIterable(
|
664
|
-
fromModule
|
690
|
+
/** @type {Module} */ (fromModule)
|
665
691
|
)) {
|
666
692
|
// return true if module this is not reachable from originChunk when ignoring chunk
|
667
693
|
if (!this.isAccessibleInChunk(chunkGraph, originChunk, chunk))
|
@@ -976,6 +1002,9 @@ class Module extends DependenciesBlock {
|
|
976
1002
|
buildDependencies
|
977
1003
|
) {}
|
978
1004
|
|
1005
|
+
/**
|
1006
|
+
* @param {ObjectSerializerContext} context context
|
1007
|
+
*/
|
979
1008
|
serialize(context) {
|
980
1009
|
const { write } = context;
|
981
1010
|
write(this.type);
|
@@ -1002,6 +1031,9 @@ class Module extends DependenciesBlock {
|
|
1002
1031
|
super.serialize(context);
|
1003
1032
|
}
|
1004
1033
|
|
1034
|
+
/**
|
1035
|
+
* @param {ObjectDeserializerContext} context context
|
1036
|
+
*/
|
1005
1037
|
deserialize(context) {
|
1006
1038
|
const { read } = context;
|
1007
1039
|
this.type = read();
|
package/lib/ModuleBuildError.js
CHANGED
@@ -9,6 +9,9 @@ const { cutOffLoaderExecution } = require("./ErrorHelpers");
|
|
9
9
|
const WebpackError = require("./WebpackError");
|
10
10
|
const makeSerializable = require("./util/makeSerializable");
|
11
11
|
|
12
|
+
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
13
|
+
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
14
|
+
|
12
15
|
class ModuleBuildError extends WebpackError {
|
13
16
|
/**
|
14
17
|
* @param {string | Error&any} err error thrown
|
@@ -55,6 +58,9 @@ class ModuleBuildError extends WebpackError {
|
|
55
58
|
this.error = err;
|
56
59
|
}
|
57
60
|
|
61
|
+
/**
|
62
|
+
* @param {ObjectSerializerContext} context context
|
63
|
+
*/
|
58
64
|
serialize(context) {
|
59
65
|
const { write } = context;
|
60
66
|
|
@@ -63,6 +69,9 @@ class ModuleBuildError extends WebpackError {
|
|
63
69
|
super.serialize(context);
|
64
70
|
}
|
65
71
|
|
72
|
+
/**
|
73
|
+
* @param {ObjectDeserializerContext} context context
|
74
|
+
*/
|
66
75
|
deserialize(context) {
|
67
76
|
const { read } = context;
|
68
77
|
|
@@ -23,7 +23,7 @@ class ModuleDependencyError extends WebpackError {
|
|
23
23
|
this.name = "ModuleDependencyError";
|
24
24
|
this.details =
|
25
25
|
err && !(/** @type {any} */ (err).hideStack)
|
26
|
-
? err.stack.split("\n").slice(1).join("\n")
|
26
|
+
? /** @type {string} */ (err.stack).split("\n").slice(1).join("\n")
|
27
27
|
: undefined;
|
28
28
|
this.module = module;
|
29
29
|
this.loc = loc;
|
@@ -32,7 +32,9 @@ class ModuleDependencyError extends WebpackError {
|
|
32
32
|
|
33
33
|
if (err && /** @type {any} */ (err).hideStack) {
|
34
34
|
this.stack =
|
35
|
-
err.stack.split("\n").slice(1).join("\n") +
|
35
|
+
/** @type {string} */ (err.stack).split("\n").slice(1).join("\n") +
|
36
|
+
"\n\n" +
|
37
|
+
this.stack;
|
36
38
|
}
|
37
39
|
}
|
38
40
|
}
|
@@ -23,7 +23,7 @@ class ModuleDependencyWarning extends WebpackError {
|
|
23
23
|
this.name = "ModuleDependencyWarning";
|
24
24
|
this.details =
|
25
25
|
err && !(/** @type {any} */ (err).hideStack)
|
26
|
-
? err.stack.split("\n").slice(1).join("\n")
|
26
|
+
? /** @type {string} */ (err.stack).split("\n").slice(1).join("\n")
|
27
27
|
: undefined;
|
28
28
|
this.module = module;
|
29
29
|
this.loc = loc;
|
@@ -32,7 +32,9 @@ class ModuleDependencyWarning extends WebpackError {
|
|
32
32
|
|
33
33
|
if (err && /** @type {any} */ (err).hideStack) {
|
34
34
|
this.stack =
|
35
|
-
err.stack.split("\n").slice(1).join("\n") +
|
35
|
+
/** @type {string} */ (err.stack).split("\n").slice(1).join("\n") +
|
36
|
+
"\n\n" +
|
37
|
+
this.stack;
|
36
38
|
}
|
37
39
|
}
|
38
40
|
}
|
package/lib/ModuleError.js
CHANGED
@@ -9,6 +9,9 @@ const { cleanUp } = require("./ErrorHelpers");
|
|
9
9
|
const WebpackError = require("./WebpackError");
|
10
10
|
const makeSerializable = require("./util/makeSerializable");
|
11
11
|
|
12
|
+
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
13
|
+
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
14
|
+
|
12
15
|
class ModuleError extends WebpackError {
|
13
16
|
/**
|
14
17
|
* @param {Error} err error thrown
|
@@ -39,6 +42,9 @@ class ModuleError extends WebpackError {
|
|
39
42
|
: undefined;
|
40
43
|
}
|
41
44
|
|
45
|
+
/**
|
46
|
+
* @param {ObjectSerializerContext} context context
|
47
|
+
*/
|
42
48
|
serialize(context) {
|
43
49
|
const { write } = context;
|
44
50
|
|
@@ -47,6 +53,9 @@ class ModuleError extends WebpackError {
|
|
47
53
|
super.serialize(context);
|
48
54
|
}
|
49
55
|
|
56
|
+
/**
|
57
|
+
* @param {ObjectDeserializerContext} context context
|
58
|
+
*/
|
50
59
|
deserialize(context) {
|
51
60
|
const { read } = context;
|
52
61
|
|
package/lib/ModuleFactory.js
CHANGED
@@ -38,7 +38,7 @@ class ModuleFactory {
|
|
38
38
|
/**
|
39
39
|
* @abstract
|
40
40
|
* @param {ModuleFactoryCreateData} data data object
|
41
|
-
* @param {function(Error=, ModuleFactoryResult=): void} callback callback
|
41
|
+
* @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
|
42
42
|
* @returns {void}
|
43
43
|
*/
|
44
44
|
create(data, callback) {
|
@@ -14,6 +14,9 @@ const memoize = require("./util/memoize");
|
|
14
14
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
15
15
|
/** @typedef {typeof import("./util/Hash")} Hash */
|
16
16
|
|
17
|
+
/** @typedef {string | RegExp | (string | RegExp)[]} Matcher */
|
18
|
+
/** @typedef {{test?: Matcher, include?: Matcher, exclude?: Matcher }} MatchObject */
|
19
|
+
|
17
20
|
const ModuleFilenameHelpers = exports;
|
18
21
|
|
19
22
|
// TODO webpack 6: consider removing these
|
@@ -43,6 +46,12 @@ ModuleFilenameHelpers.REGEXP_HASH = /\[hash\]/gi;
|
|
43
46
|
ModuleFilenameHelpers.NAMESPACE = "[namespace]";
|
44
47
|
ModuleFilenameHelpers.REGEXP_NAMESPACE = /\[namespace\]/gi;
|
45
48
|
|
49
|
+
/**
|
50
|
+
* Returns a function that returns the part of the string after the token
|
51
|
+
* @param {() => string} strFn the function to get the string
|
52
|
+
* @param {string} token the token to search for
|
53
|
+
* @returns {() => string} a function that returns the part of the string after the token
|
54
|
+
*/
|
46
55
|
const getAfter = (strFn, token) => {
|
47
56
|
return () => {
|
48
57
|
const str = strFn();
|
@@ -51,6 +60,12 @@ const getAfter = (strFn, token) => {
|
|
51
60
|
};
|
52
61
|
};
|
53
62
|
|
63
|
+
/**
|
64
|
+
* Returns a function that returns the part of the string before the token
|
65
|
+
* @param {() => string} strFn the function to get the string
|
66
|
+
* @param {string} token the token to search for
|
67
|
+
* @returns {() => string} a function that returns the part of the string before the token
|
68
|
+
*/
|
54
69
|
const getBefore = (strFn, token) => {
|
55
70
|
return () => {
|
56
71
|
const str = strFn();
|
@@ -59,6 +74,12 @@ const getBefore = (strFn, token) => {
|
|
59
74
|
};
|
60
75
|
};
|
61
76
|
|
77
|
+
/**
|
78
|
+
* Returns a function that returns a hash of the string
|
79
|
+
* @param {() => string} strFn the function to get the string
|
80
|
+
* @param {string | Hash} hashFunction the hash function to use
|
81
|
+
* @returns {() => string} a function that returns the hash of the string
|
82
|
+
*/
|
62
83
|
const getHash = (strFn, hashFunction) => {
|
63
84
|
return () => {
|
64
85
|
const hash = createHash(hashFunction);
|
@@ -68,13 +89,35 @@ const getHash = (strFn, hashFunction) => {
|
|
68
89
|
};
|
69
90
|
};
|
70
91
|
|
92
|
+
/**
|
93
|
+
* Returns a function that returns the string with the token replaced with the replacement
|
94
|
+
* @param {string|RegExp} test A regular expression string or Regular Expression object
|
95
|
+
* @returns {RegExp} A regular expression object
|
96
|
+
* @example
|
97
|
+
* ```js
|
98
|
+
* const test = asRegExp("test");
|
99
|
+
* test.test("test"); // true
|
100
|
+
*
|
101
|
+
* const test2 = asRegExp(/test/);
|
102
|
+
* test2.test("test"); // true
|
103
|
+
* ```
|
104
|
+
*/
|
71
105
|
const asRegExp = test => {
|
72
106
|
if (typeof test === "string") {
|
107
|
+
// Escape special characters in the string to prevent them from being interpreted as special characters in a regular expression. Do this by
|
108
|
+
// adding a backslash before each special character
|
73
109
|
test = new RegExp("^" + test.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"));
|
74
110
|
}
|
75
111
|
return test;
|
76
112
|
};
|
77
113
|
|
114
|
+
/**
|
115
|
+
* @template T
|
116
|
+
* Returns a lazy object. The object is lazy in the sense that the properties are
|
117
|
+
* only evaluated when they are accessed. This is only obtained by setting a function as the value for each key.
|
118
|
+
* @param {Record<string, () => T>} obj the object to covert to a lazy access object
|
119
|
+
* @returns {Object} the lazy access object
|
120
|
+
*/
|
78
121
|
const lazyObject = obj => {
|
79
122
|
const newObj = {};
|
80
123
|
for (const key of Object.keys(obj)) {
|
@@ -95,7 +138,7 @@ const lazyObject = obj => {
|
|
95
138
|
return newObj;
|
96
139
|
};
|
97
140
|
|
98
|
-
const
|
141
|
+
const SQUARE_BRACKET_TAG_REGEXP = /\[\\*([\w-]+)\\*\]/gi;
|
99
142
|
|
100
143
|
/**
|
101
144
|
*
|
@@ -162,6 +205,7 @@ ModuleFilenameHelpers.createFilename = (
|
|
162
205
|
resource: resource,
|
163
206
|
resourcePath: memoize(resourcePath),
|
164
207
|
absoluteResourcePath: memoize(absoluteResourcePath),
|
208
|
+
loaders: memoize(loaders),
|
165
209
|
allLoaders: memoize(allLoaders),
|
166
210
|
query: memoize(query),
|
167
211
|
moduleId: memoize(moduleId),
|
@@ -211,7 +255,7 @@ ModuleFilenameHelpers.createFilename = (
|
|
211
255
|
ModuleFilenameHelpers.REGEXP_LOADERS_RESOURCE,
|
212
256
|
"[short-identifier]"
|
213
257
|
)
|
214
|
-
.replace(
|
258
|
+
.replace(SQUARE_BRACKET_TAG_REGEXP, (match, content) => {
|
215
259
|
if (content.length + 2 === match.length) {
|
216
260
|
const replacement = replacements.get(content.toLowerCase());
|
217
261
|
if (replacement !== undefined) {
|
@@ -224,9 +268,28 @@ ModuleFilenameHelpers.createFilename = (
|
|
224
268
|
});
|
225
269
|
};
|
226
270
|
|
271
|
+
/**
|
272
|
+
* Replaces duplicate items in an array with new values generated by a callback function.
|
273
|
+
* The callback function is called with the duplicate item, the index of the duplicate item, and the number of times the item has been replaced.
|
274
|
+
* The callback function should return the new value for the duplicate item.
|
275
|
+
*
|
276
|
+
* @template T
|
277
|
+
* @param {T[]} array the array with duplicates to be replaced
|
278
|
+
* @param {(duplicateItem: T, duplicateItemIndex: number, numberOfTimesReplaced: number) => T} fn callback function to generate new values for the duplicate items
|
279
|
+
* @param {(firstElement:T, nextElement:T) => -1 | 0 | 1} [comparator] optional comparator function to sort the duplicate items
|
280
|
+
* @returns {T[]} the array with duplicates replaced
|
281
|
+
*
|
282
|
+
* @example
|
283
|
+
* ```js
|
284
|
+
* const array = ["a", "b", "c", "a", "b", "a"];
|
285
|
+
* const result = ModuleFilenameHelpers.replaceDuplicates(array, (item, index, count) => `${item}-${count}`);
|
286
|
+
* // result: ["a-1", "b-1", "c", "a-2", "b-2", "a-3"]
|
287
|
+
* ```
|
288
|
+
*/
|
227
289
|
ModuleFilenameHelpers.replaceDuplicates = (array, fn, comparator) => {
|
228
290
|
const countMap = Object.create(null);
|
229
291
|
const posMap = Object.create(null);
|
292
|
+
|
230
293
|
array.forEach((item, idx) => {
|
231
294
|
countMap[item] = countMap[item] || [];
|
232
295
|
countMap[item].push(idx);
|
@@ -247,16 +310,63 @@ ModuleFilenameHelpers.replaceDuplicates = (array, fn, comparator) => {
|
|
247
310
|
});
|
248
311
|
};
|
249
312
|
|
313
|
+
/**
|
314
|
+
* Tests if a string matches a RegExp or an array of RegExp.
|
315
|
+
*
|
316
|
+
* @param {string} str string to test
|
317
|
+
* @param {Matcher} test value which will be used to match against the string
|
318
|
+
* @returns {boolean} true, when the RegExp matches
|
319
|
+
*
|
320
|
+
* @example
|
321
|
+
* ```js
|
322
|
+
* ModuleFilenameHelpers.matchPart("foo.js", "foo"); // true
|
323
|
+
* ModuleFilenameHelpers.matchPart("foo.js", "foo.js"); // true
|
324
|
+
* ModuleFilenameHelpers.matchPart("foo.js", "foo."); // false
|
325
|
+
* ModuleFilenameHelpers.matchPart("foo.js", "foo*"); // false
|
326
|
+
* ModuleFilenameHelpers.matchPart("foo.js", "foo.*"); // true
|
327
|
+
* ModuleFilenameHelpers.matchPart("foo.js", /^foo/); // true
|
328
|
+
* ModuleFilenameHelpers.matchPart("foo.js", [/^foo/, "bar"]); // true
|
329
|
+
* ModuleFilenameHelpers.matchPart("foo.js", [/^foo/, "bar"]); // true
|
330
|
+
* ModuleFilenameHelpers.matchPart("foo.js", [/^foo/, /^bar/]); // true
|
331
|
+
* ModuleFilenameHelpers.matchPart("foo.js", [/^baz/, /^bar/]); // false
|
332
|
+
* ```
|
333
|
+
*/
|
250
334
|
ModuleFilenameHelpers.matchPart = (str, test) => {
|
251
335
|
if (!test) return true;
|
252
|
-
|
336
|
+
|
253
337
|
if (Array.isArray(test)) {
|
254
338
|
return test.map(asRegExp).some(regExp => regExp.test(str));
|
255
339
|
} else {
|
256
|
-
return test.test(str);
|
340
|
+
return asRegExp(test).test(str);
|
257
341
|
}
|
258
342
|
};
|
259
343
|
|
344
|
+
/**
|
345
|
+
* Tests if a string matches a match object. The match object can have the following properties:
|
346
|
+
* - `test`: a RegExp or an array of RegExp
|
347
|
+
* - `include`: a RegExp or an array of RegExp
|
348
|
+
* - `exclude`: a RegExp or an array of RegExp
|
349
|
+
*
|
350
|
+
* The `test` property is tested first, then `include` and then `exclude`.
|
351
|
+
*
|
352
|
+
* @param {MatchObject} obj a match object to test against the string
|
353
|
+
* @param {string} str string to test against the matching object
|
354
|
+
* @returns {boolean} true, when the object matches
|
355
|
+
* @example
|
356
|
+
* ```js
|
357
|
+
* ModuleFilenameHelpers.matchObject({ test: "foo.js" }, "foo.js"); // true
|
358
|
+
* ModuleFilenameHelpers.matchObject({ test: /^foo/ }, "foo.js"); // true
|
359
|
+
* ModuleFilenameHelpers.matchObject({ test: [/^foo/, "bar"] }, "foo.js"); // true
|
360
|
+
* ModuleFilenameHelpers.matchObject({ test: [/^foo/, "bar"] }, "baz.js"); // false
|
361
|
+
* ModuleFilenameHelpers.matchObject({ include: "foo.js" }, "foo.js"); // true
|
362
|
+
* ModuleFilenameHelpers.matchObject({ include: "foo.js" }, "bar.js"); // false
|
363
|
+
* ModuleFilenameHelpers.matchObject({ include: /^foo/ }, "foo.js"); // true
|
364
|
+
* ModuleFilenameHelpers.matchObject({ include: [/^foo/, "bar"] }, "foo.js"); // true
|
365
|
+
* ModuleFilenameHelpers.matchObject({ include: [/^foo/, "bar"] }, "baz.js"); // false
|
366
|
+
* ModuleFilenameHelpers.matchObject({ exclude: "foo.js" }, "foo.js"); // false
|
367
|
+
* ModuleFilenameHelpers.matchObject({ exclude: [/^foo/, "bar"] }, "foo.js"); // false
|
368
|
+
* ```
|
369
|
+
*/
|
260
370
|
ModuleFilenameHelpers.matchObject = (obj, str) => {
|
261
371
|
if (obj.test) {
|
262
372
|
if (!ModuleFilenameHelpers.matchPart(str, obj.test)) {
|
package/lib/ModuleGraph.js
CHANGED
@@ -35,14 +35,15 @@ const getConnectionsByOriginModule = set => {
|
|
35
35
|
const map = new Map();
|
36
36
|
/** @type {Module | 0} */
|
37
37
|
let lastModule = 0;
|
38
|
-
/** @type {ModuleGraphConnection[]} */
|
38
|
+
/** @type {ModuleGraphConnection[] | undefined} */
|
39
39
|
let lastList = undefined;
|
40
40
|
for (const connection of set) {
|
41
41
|
const { originModule } = connection;
|
42
42
|
if (lastModule === originModule) {
|
43
|
-
|
43
|
+
/** @type {ModuleGraphConnection[]} */
|
44
|
+
(lastList).push(connection);
|
44
45
|
} else {
|
45
|
-
lastModule = originModule;
|
46
|
+
lastModule = /** @type {Module} */ (originModule);
|
46
47
|
const list = map.get(originModule);
|
47
48
|
if (list !== undefined) {
|
48
49
|
lastList = list;
|
@@ -65,12 +66,13 @@ const getConnectionsByModule = set => {
|
|
65
66
|
const map = new Map();
|
66
67
|
/** @type {Module | 0} */
|
67
68
|
let lastModule = 0;
|
68
|
-
/** @type {ModuleGraphConnection[]} */
|
69
|
+
/** @type {ModuleGraphConnection[] | undefined} */
|
69
70
|
let lastList = undefined;
|
70
71
|
for (const connection of set) {
|
71
72
|
const { module } = connection;
|
72
73
|
if (lastModule === module) {
|
73
|
-
|
74
|
+
/** @type {ModuleGraphConnection[]} */
|
75
|
+
(lastList).push(connection);
|
74
76
|
} else {
|
75
77
|
lastModule = module;
|
76
78
|
const list = map.get(module);
|
@@ -99,13 +101,13 @@ class ModuleGraphModule {
|
|
99
101
|
this.optimizationBailout = [];
|
100
102
|
/** @type {ExportsInfo} */
|
101
103
|
this.exports = new ExportsInfo();
|
102
|
-
/** @type {number} */
|
104
|
+
/** @type {number | null} */
|
103
105
|
this.preOrderIndex = null;
|
104
|
-
/** @type {number} */
|
106
|
+
/** @type {number | null} */
|
105
107
|
this.postOrderIndex = null;
|
106
|
-
/** @type {number} */
|
108
|
+
/** @type {number | null} */
|
107
109
|
this.depth = null;
|
108
|
-
/** @type {ModuleProfile} */
|
110
|
+
/** @type {ModuleProfile | undefined | null} */
|
109
111
|
this.profile = undefined;
|
110
112
|
/** @type {boolean} */
|
111
113
|
this.async = false;
|
@@ -116,18 +118,21 @@ class ModuleGraphModule {
|
|
116
118
|
|
117
119
|
class ModuleGraph {
|
118
120
|
constructor() {
|
119
|
-
/** @type {WeakMap<Dependency, ModuleGraphConnection>} */
|
121
|
+
/** @type {WeakMap<Dependency, ModuleGraphConnection | null>} */
|
120
122
|
this._dependencyMap = new WeakMap();
|
121
123
|
/** @type {Map<Module, ModuleGraphModule>} */
|
122
124
|
this._moduleMap = new Map();
|
123
125
|
/** @type {WeakMap<any, Object>} */
|
124
126
|
this._metaMap = new WeakMap();
|
125
127
|
|
126
|
-
/** @type {WeakTupleMap<any[], any>} */
|
128
|
+
/** @type {WeakTupleMap<any[], any> | undefined} */
|
127
129
|
this._cache = undefined;
|
128
130
|
|
129
131
|
/** @type {Map<Module, WeakTupleMap<any, any>>} */
|
130
132
|
this._moduleMemCaches = undefined;
|
133
|
+
|
134
|
+
/** @type {string | undefined} */
|
135
|
+
this._cacheStage = undefined;
|
131
136
|
}
|
132
137
|
|
133
138
|
/**
|
@@ -218,7 +223,9 @@ class ModuleGraph {
|
|
218
223
|
* @returns {void}
|
219
224
|
*/
|
220
225
|
updateModule(dependency, module) {
|
221
|
-
const connection =
|
226
|
+
const connection =
|
227
|
+
/** @type {ModuleGraphConnection} */
|
228
|
+
(this.getConnection(dependency));
|
222
229
|
if (connection.module === module) return;
|
223
230
|
const newConnection = connection.clone();
|
224
231
|
newConnection.module = module;
|
@@ -372,7 +379,7 @@ class ModuleGraph {
|
|
372
379
|
|
373
380
|
/**
|
374
381
|
* @param {Dependency} dependency the dependency to look for a referenced module
|
375
|
-
* @returns {Module} the referenced module
|
382
|
+
* @returns {Module | null} the referenced module
|
376
383
|
*/
|
377
384
|
getResolvedModule(dependency) {
|
378
385
|
const connection = this.getConnection(dependency);
|
@@ -395,7 +402,10 @@ class ModuleGraph {
|
|
395
402
|
) {
|
396
403
|
let foundConnection;
|
397
404
|
for (const connection of mgm._unassignedConnections) {
|
398
|
-
this._dependencyMap.set(
|
405
|
+
this._dependencyMap.set(
|
406
|
+
/** @type {Dependency} */ (connection.dependency),
|
407
|
+
connection
|
408
|
+
);
|
399
409
|
if (connection.dependency === dependency)
|
400
410
|
foundConnection = connection;
|
401
411
|
}
|
@@ -413,7 +423,7 @@ class ModuleGraph {
|
|
413
423
|
|
414
424
|
/**
|
415
425
|
* @param {Dependency} dependency the dependency to look for a referenced module
|
416
|
-
* @returns {Module} the referenced module
|
426
|
+
* @returns {Module | null} the referenced module
|
417
427
|
*/
|
418
428
|
getModule(dependency) {
|
419
429
|
const connection = this.getConnection(dependency);
|
@@ -422,7 +432,7 @@ class ModuleGraph {
|
|
422
432
|
|
423
433
|
/**
|
424
434
|
* @param {Dependency} dependency the dependency to look for a referencing module
|
425
|
-
* @returns {Module} the referencing module
|
435
|
+
* @returns {Module | null} the referencing module
|
426
436
|
*/
|
427
437
|
getOrigin(dependency) {
|
428
438
|
const connection = this.getConnection(dependency);
|
@@ -431,7 +441,7 @@ class ModuleGraph {
|
|
431
441
|
|
432
442
|
/**
|
433
443
|
* @param {Dependency} dependency the dependency to look for a referencing module
|
434
|
-
* @returns {Module} the original referencing module
|
444
|
+
* @returns {Module | null} the original referencing module
|
435
445
|
*/
|
436
446
|
getResolvedOrigin(dependency) {
|
437
447
|
const connection = this.getConnection(dependency);
|
@@ -601,7 +611,7 @@ class ModuleGraph {
|
|
601
611
|
|
602
612
|
/**
|
603
613
|
* @param {Module} module the module
|
604
|
-
* @returns {number} the index of the module
|
614
|
+
* @returns {number | null} the index of the module
|
605
615
|
*/
|
606
616
|
getPreOrderIndex(module) {
|
607
617
|
const mgm = this._getModuleGraphModule(module);
|
@@ -610,7 +620,7 @@ class ModuleGraph {
|
|
610
620
|
|
611
621
|
/**
|
612
622
|
* @param {Module} module the module
|
613
|
-
* @returns {number} the index of the module
|
623
|
+
* @returns {number | null} the index of the module
|
614
624
|
*/
|
615
625
|
getPostOrderIndex(module) {
|
616
626
|
const mgm = this._getModuleGraphModule(module);
|
@@ -667,7 +677,7 @@ class ModuleGraph {
|
|
667
677
|
|
668
678
|
/**
|
669
679
|
* @param {Module} module the module
|
670
|
-
* @returns {number} the depth of the module
|
680
|
+
* @returns {number | null} the depth of the module
|
671
681
|
*/
|
672
682
|
getDepth(module) {
|
673
683
|
const mgm = this._getModuleGraphModule(module);
|
@@ -724,14 +734,14 @@ class ModuleGraph {
|
|
724
734
|
let meta = this._metaMap.get(thing);
|
725
735
|
if (meta === undefined) {
|
726
736
|
meta = Object.create(null);
|
727
|
-
this._metaMap.set(thing, meta);
|
737
|
+
this._metaMap.set(thing, /** @type {Object} */ (meta));
|
728
738
|
}
|
729
|
-
return meta;
|
739
|
+
return /** @type {Object} */ (meta);
|
730
740
|
}
|
731
741
|
|
732
742
|
/**
|
733
743
|
* @param {any} thing any thing
|
734
|
-
* @returns {Object} metadata
|
744
|
+
* @returns {Object | undefined} metadata
|
735
745
|
*/
|
736
746
|
getMetaIfExisting(thing) {
|
737
747
|
return this._metaMap.get(thing);
|