webpack 5.93.0 → 5.95.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 +8 -5
- package/bin/webpack.js +6 -7
- package/hot/log.js +1 -2
- package/hot/only-dev-server.js +1 -1
- package/hot/poll.js +1 -1
- package/hot/signal.js +1 -1
- package/lib/APIPlugin.js +4 -3
- package/lib/AbstractMethodError.js +10 -5
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +12 -6
- package/lib/Cache.js +8 -10
- package/lib/CacheFacade.js +3 -3
- package/lib/CaseSensitiveModulesWarning.js +5 -7
- package/lib/Chunk.js +14 -11
- package/lib/ChunkGraph.js +58 -36
- package/lib/ChunkGroup.js +2 -3
- package/lib/ChunkTemplate.js +43 -0
- package/lib/CleanPlugin.js +10 -11
- package/lib/CodeGenerationResults.js +6 -5
- package/lib/CommentCompilationWarning.js +0 -1
- package/lib/Compilation.js +223 -191
- package/lib/Compiler.js +81 -82
- package/lib/ConcatenationScope.js +3 -6
- package/lib/ConditionalInitFragment.js +6 -7
- package/lib/ConstPlugin.js +7 -15
- package/lib/ContextExclusionPlugin.js +3 -3
- package/lib/ContextModule.js +33 -20
- package/lib/ContextModuleFactory.js +89 -44
- package/lib/ContextReplacementPlugin.js +10 -9
- package/lib/DefinePlugin.js +75 -68
- package/lib/DelegatedModule.js +7 -3
- package/lib/DelegatedModuleFactoryPlugin.js +36 -22
- package/lib/DelegatedPlugin.js +4 -0
- package/lib/DependenciesBlock.js +0 -1
- package/lib/Dependency.js +10 -14
- package/lib/DllEntryPlugin.js +4 -2
- package/lib/DllModuleFactory.js +1 -0
- package/lib/DllPlugin.js +9 -7
- package/lib/DllReferencePlugin.js +30 -15
- package/lib/EntryPlugin.js +1 -3
- package/lib/EnvironmentPlugin.js +6 -2
- package/lib/ErrorHelpers.js +11 -12
- package/lib/EvalDevToolModulePlugin.js +10 -12
- package/lib/EvalSourceMapDevToolPlugin.js +15 -13
- package/lib/ExportsInfo.js +185 -120
- package/lib/ExternalModule.js +41 -15
- package/lib/ExternalModuleFactoryPlugin.js +23 -10
- package/lib/FileSystemInfo.js +791 -422
- package/lib/FlagAllModulesAsUsedPlugin.js +1 -1
- package/lib/FlagDependencyExportsPlugin.js +12 -11
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +2 -5
- package/lib/GraphHelpers.js +3 -2
- package/lib/HookWebpackError.js +8 -10
- package/lib/HotModuleReplacementPlugin.js +78 -64
- package/lib/IgnoreErrorModuleFactory.js +3 -3
- package/lib/IgnorePlugin.js +1 -3
- package/lib/IgnoreWarningsPlugin.js +6 -9
- package/lib/InitFragment.js +2 -3
- package/lib/LibManifestPlugin.js +4 -3
- package/lib/MainTemplate.js +72 -19
- package/lib/Module.js +25 -9
- package/lib/ModuleBuildError.js +4 -11
- package/lib/ModuleDependencyError.js +5 -5
- package/lib/ModuleDependencyWarning.js +5 -5
- package/lib/ModuleError.js +1 -5
- package/lib/ModuleFilenameHelpers.js +29 -46
- package/lib/ModuleGraph.js +7 -6
- package/lib/ModuleGraphConnection.js +6 -6
- package/lib/ModuleInfoHeaderPlugin.js +82 -30
- package/lib/ModuleParseError.js +8 -9
- package/lib/ModuleRestoreError.js +1 -1
- package/lib/ModuleStoreError.js +1 -1
- package/lib/ModuleTemplate.js +33 -1
- package/lib/ModuleTypeConstants.js +21 -22
- package/lib/ModuleWarning.js +1 -5
- package/lib/MultiCompiler.js +24 -26
- package/lib/MultiStats.js +73 -31
- package/lib/MultiWatching.js +1 -1
- package/lib/NormalModule.js +130 -69
- package/lib/NormalModuleFactory.js +53 -49
- package/lib/OptimizationStages.js +3 -3
- package/lib/ProgressPlugin.js +9 -9
- package/lib/ProvidePlugin.js +4 -4
- package/lib/RuntimeGlobals.js +71 -70
- package/lib/RuntimeModule.js +1 -1
- package/lib/RuntimePlugin.js +24 -12
- package/lib/RuntimeTemplate.js +40 -44
- package/lib/SizeFormatHelpers.js +2 -4
- package/lib/SourceMapDevToolPlugin.js +42 -34
- package/lib/Stats.js +5 -11
- package/lib/Template.js +18 -24
- package/lib/TemplatedPathPlugin.js +21 -13
- package/lib/WarnDeprecatedOptionPlugin.js +0 -1
- package/lib/WatchIgnorePlugin.js +26 -9
- package/lib/Watching.js +10 -5
- package/lib/WebpackOptionsApply.js +84 -62
- package/lib/asset/AssetGenerator.js +107 -42
- package/lib/asset/AssetModulesPlugin.js +29 -23
- package/lib/asset/AssetSourceGenerator.js +2 -7
- package/lib/async-modules/AwaitDependenciesInitFragment.js +6 -7
- package/lib/buildChunkGraph.js +93 -81
- package/lib/cache/IdleFileCachePlugin.js +4 -4
- package/lib/cache/MemoryWithGcCachePlugin.js +5 -5
- package/lib/cache/PackFileCacheStrategy.js +51 -50
- package/lib/cache/ResolverCachePlugin.js +6 -6
- package/lib/cache/mergeEtags.js +16 -21
- package/lib/cli.js +148 -104
- package/lib/config/browserslistTargetHandler.js +16 -13
- package/lib/config/defaults.js +32 -28
- package/lib/config/normalization.js +335 -344
- package/lib/config/target.js +42 -52
- package/lib/container/ContainerEntryModule.js +2 -2
- package/lib/container/ContainerPlugin.js +1 -1
- package/lib/container/RemoteRuntimeModule.js +11 -8
- package/lib/container/options.js +18 -4
- package/lib/css/CssExportsGenerator.js +26 -24
- package/lib/css/CssGenerator.js +9 -4
- package/lib/css/CssLoadingRuntimeModule.js +10 -10
- package/lib/css/CssModulesPlugin.js +127 -47
- package/lib/css/CssParser.js +20 -18
- package/lib/css/walkCssTokens.js +80 -95
- package/lib/debug/ProfilingPlugin.js +19 -20
- package/lib/dependencies/AMDDefineDependency.js +1 -1
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +83 -47
- package/lib/dependencies/AMDRequireArrayDependency.js +9 -10
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +22 -16
- package/lib/dependencies/AMDRuntimeModules.js +2 -2
- package/lib/dependencies/CommonJsDependencyHelpers.js +6 -2
- package/lib/dependencies/CommonJsExportRequireDependency.js +37 -41
- package/lib/dependencies/CommonJsExportsDependency.js +0 -1
- package/lib/dependencies/CommonJsExportsParserPlugin.js +19 -23
- package/lib/dependencies/CommonJsFullRequireDependency.js +1 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +52 -61
- package/lib/dependencies/CommonJsSelfReferenceDependency.js +6 -8
- package/lib/dependencies/ConstDependency.js +1 -1
- package/lib/dependencies/ContextDependency.js +7 -2
- package/lib/dependencies/ContextDependencyHelpers.js +31 -34
- package/lib/dependencies/ContextElementDependency.js +35 -8
- package/lib/dependencies/CriticalDependencyWarning.js +1 -1
- package/lib/dependencies/CssExportDependency.js +7 -7
- package/lib/dependencies/CssImportDependency.js +0 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +3 -3
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/CssUrlDependency.js +4 -5
- package/lib/dependencies/DynamicExports.js +5 -5
- package/lib/dependencies/ExportsInfoDependency.js +1 -2
- package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -1
- package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -5
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +27 -16
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +107 -64
- package/lib/dependencies/HarmonyExports.js +2 -2
- package/lib/dependencies/HarmonyImportDependency.js +2 -4
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -15
- package/lib/dependencies/ImportDependency.js +1 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +5 -5
- package/lib/dependencies/ImportMetaPlugin.js +11 -13
- package/lib/dependencies/ImportParserPlugin.js +39 -44
- package/lib/dependencies/JsonExportsDependency.js +22 -18
- package/lib/dependencies/LoaderPlugin.js +47 -36
- package/lib/dependencies/LocalModule.js +1 -1
- package/lib/dependencies/LocalModulesHelpers.js +4 -4
- package/lib/dependencies/ModuleDecoratorDependency.js +1 -1
- package/lib/dependencies/ProvidedDependency.js +1 -1
- package/lib/dependencies/PureExpressionDependency.js +6 -6
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/URLDependency.js +3 -3
- package/lib/dependencies/URLPlugin.js +66 -12
- package/lib/dependencies/WorkerPlugin.js +25 -24
- package/lib/dependencies/processExportInfo.js +3 -1
- package/lib/electron/ElectronTargetPlugin.js +1 -0
- package/lib/esm/ModuleChunkFormatPlugin.js +3 -3
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -3
- package/lib/formatLocation.js +1 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +4 -5
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +9 -12
- package/lib/hmr/LazyCompilationPlugin.js +27 -12
- package/lib/hmr/lazyCompilationBackend.js +64 -40
- package/lib/ids/ChunkModuleIdRangePlugin.js +1 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +2 -4
- package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
- package/lib/ids/HashedModuleIdsPlugin.js +5 -1
- package/lib/ids/IdHelpers.js +29 -39
- package/lib/ids/SyncModuleIdsPlugin.js +7 -2
- package/lib/index.js +1 -5
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +5 -4
- package/lib/javascript/BasicEvaluatedExpression.js +4 -19
- package/lib/javascript/ChunkHelpers.js +1 -1
- package/lib/javascript/CommonJsChunkFormatPlugin.js +3 -2
- package/lib/javascript/EnableChunkLoadingPlugin.js +7 -6
- package/lib/javascript/JavascriptGenerator.js +23 -7
- package/lib/javascript/JavascriptModulesPlugin.js +133 -86
- package/lib/javascript/JavascriptParser.js +179 -200
- package/lib/javascript/JavascriptParserHelpers.js +20 -21
- package/lib/javascript/StartupHelpers.js +41 -13
- package/lib/json/JsonGenerator.js +7 -13
- package/lib/json/JsonModulesPlugin.js +1 -4
- package/lib/json/JsonParser.js +5 -3
- package/lib/library/AmdLibraryPlugin.js +12 -16
- package/lib/library/AssignLibraryPlugin.js +8 -10
- package/lib/library/EnableLibraryPlugin.js +15 -14
- package/lib/library/JsonpLibraryPlugin.js +2 -1
- package/lib/library/ModernModuleLibraryPlugin.js +8 -6
- package/lib/library/ModuleLibraryPlugin.js +2 -1
- package/lib/library/SystemLibraryPlugin.js +2 -1
- package/lib/library/UmdLibraryPlugin.js +66 -92
- package/lib/logging/Logger.js +32 -4
- package/lib/logging/createConsoleLogger.js +12 -13
- package/lib/logging/runtime.js +7 -8
- package/lib/logging/truncateArgs.js +5 -8
- package/lib/node/NodeWatchFileSystem.js +3 -18
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
- package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -2
- package/lib/node/nodeConsole.js +22 -22
- package/lib/optimize/AggressiveMergingPlugin.js +2 -4
- package/lib/optimize/AggressiveSplittingPlugin.js +16 -19
- package/lib/optimize/ConcatenatedModule.js +81 -51
- package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -3
- package/lib/optimize/InnerGraph.js +17 -17
- package/lib/optimize/InnerGraphPlugin.js +8 -7
- package/lib/optimize/LimitChunkCountPlugin.js +2 -3
- package/lib/optimize/MangleExportsPlugin.js +1 -0
- package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
- package/lib/optimize/MinMaxSizeWarning.js +1 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +54 -78
- package/lib/optimize/RealContentHashPlugin.js +7 -10
- package/lib/optimize/RemoveParentModulesPlugin.js +3 -3
- package/lib/optimize/SideEffectsFlagPlugin.js +6 -2
- package/lib/optimize/SplitChunksPlugin.js +34 -30
- package/lib/performance/SizeLimitsPlugin.js +2 -2
- package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -1
- package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -1
- package/lib/rules/BasicEffectRulePlugin.js +3 -1
- package/lib/rules/BasicMatcherRulePlugin.js +3 -1
- package/lib/rules/ObjectMatcherRulePlugin.js +4 -1
- package/lib/rules/RuleSetCompiler.js +41 -22
- package/lib/rules/UseEffectRulePlugin.js +36 -32
- package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
- package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +2 -2
- package/lib/runtime/DefinePropertyGettersRuntimeModule.js +1 -1
- package/lib/runtime/EnsureChunkRuntimeModule.js +10 -11
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +11 -17
- package/lib/runtime/LoadScriptRuntimeModule.js +17 -18
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -3
- package/lib/schemes/DataUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +241 -126
- package/lib/serialization/BinaryMiddleware.js +44 -28
- package/lib/serialization/DateObjectSerializer.js +1 -0
- package/lib/serialization/ErrorObjectSerializer.js +2 -0
- package/lib/serialization/FileMiddleware.js +154 -106
- package/lib/serialization/MapObjectSerializer.js +2 -1
- package/lib/serialization/NullPrototypeObjectSerializer.js +3 -2
- package/lib/serialization/ObjectMiddleware.js +52 -56
- package/lib/serialization/PlainObjectSerializer.js +32 -6
- package/lib/serialization/RegExpObjectSerializer.js +1 -0
- package/lib/serialization/Serializer.js +4 -5
- package/lib/serialization/SerializerMiddleware.js +6 -6
- package/lib/serialization/SetObjectSerializer.js +2 -1
- package/lib/sharing/ConsumeSharedPlugin.js +116 -97
- package/lib/sharing/ConsumeSharedRuntimeModule.js +4 -4
- package/lib/sharing/ProvideForSharedDependency.js +0 -1
- package/lib/sharing/ProvideSharedPlugin.js +2 -2
- package/lib/sharing/resolveMatchedConfigs.js +2 -1
- package/lib/sharing/utils.js +15 -27
- package/lib/stats/DefaultStatsFactoryPlugin.js +424 -281
- package/lib/stats/DefaultStatsPresetPlugin.js +73 -18
- package/lib/stats/DefaultStatsPrinterPlugin.js +370 -101
- package/lib/stats/StatsFactory.js +127 -56
- package/lib/stats/StatsPrinter.js +75 -44
- package/lib/util/ArrayHelpers.js +8 -4
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +31 -12
- package/lib/util/IterableHelpers.js +3 -4
- package/lib/util/LazyBucketSortedSet.js +60 -44
- package/lib/util/LazySet.js +13 -0
- package/lib/util/MapHelpers.js +1 -3
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/Queue.js +1 -1
- package/lib/util/Semaphore.js +4 -7
- package/lib/util/SetHelpers.js +5 -5
- package/lib/util/SortableSet.js +4 -3
- package/lib/util/StackedCacheMap.js +4 -6
- package/lib/util/StackedMap.js +1 -3
- package/lib/util/StringXor.js +0 -5
- package/lib/util/TupleQueue.js +1 -1
- package/lib/util/TupleSet.js +15 -5
- package/lib/util/URLAbsoluteSpecifier.js +7 -7
- package/lib/util/WeakTupleMap.js +19 -21
- package/lib/util/binarySearchBounds.js +5 -12
- package/lib/util/chainedImports.js +1 -1
- package/lib/util/cleverMerge.js +21 -19
- package/lib/util/comparators.js +57 -52
- package/lib/util/compileBooleanMatcher.js +3 -6
- package/lib/util/conventions.js +8 -11
- package/lib/util/createHash.js +9 -6
- package/lib/util/deprecation.js +22 -12
- package/lib/util/deterministicGrouping.js +19 -26
- package/lib/util/findGraphRoots.js +2 -2
- package/lib/util/fs.js +32 -32
- package/lib/util/hash/md4.js +2 -2
- package/lib/util/hash/wasm-hash.js +7 -7
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/identifier.js +81 -59
- package/lib/util/memoize.js +8 -10
- package/lib/util/mergeScope.js +6 -9
- package/lib/util/nonNumericOnlyHash.js +2 -2
- package/lib/util/numberHash.js +1 -6
- package/lib/util/objectToMap.js +0 -1
- package/lib/util/propertyAccess.js +2 -5
- package/lib/util/propertyName.js +1 -3
- package/lib/util/registerExternalSerializer.js +1 -1
- package/lib/util/runtime.js +109 -113
- package/lib/util/semver.js +29 -27
- package/lib/util/serialization.js +16 -1
- package/lib/util/smartGrouping.js +5 -5
- package/lib/util/source.js +1 -1
- package/lib/wasm/EnableWasmLoadingPlugin.js +5 -4
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -6
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +20 -19
- package/lib/wasm-sync/WebAssemblyGenerator.js +14 -29
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-sync/WebAssemblyUtils.js +2 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -3
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +18 -17
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +5 -0
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +1 -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 +1 -0
- package/types.d.ts +681 -355
package/lib/ChunkGraph.js
CHANGED
@@ -30,6 +30,7 @@ const {
|
|
30
30
|
|
31
31
|
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
32
32
|
/** @typedef {import("./Chunk")} Chunk */
|
33
|
+
/** @typedef {import("./Chunk").ChunkId} ChunkId */
|
33
34
|
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
34
35
|
/** @typedef {import("./Module")} Module */
|
35
36
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
@@ -73,9 +74,7 @@ class ModuleHashInfo {
|
|
73
74
|
* @param {SortableSet<T>} set the set
|
74
75
|
* @returns {T[]} set as array
|
75
76
|
*/
|
76
|
-
const getArray = set =>
|
77
|
-
return Array.from(set);
|
78
|
-
};
|
77
|
+
const getArray = set => Array.from(set);
|
79
78
|
|
80
79
|
/**
|
81
80
|
* @param {SortableSet<Chunk>} chunks the chunks
|
@@ -159,7 +158,7 @@ const getModulesSize = modules => {
|
|
159
158
|
* @returns {Record<string, number>} the sizes of the modules
|
160
159
|
*/
|
161
160
|
const getModulesSizes = modules => {
|
162
|
-
|
161
|
+
const sizes = Object.create(null);
|
163
162
|
for (const module of modules) {
|
164
163
|
for (const type of module.getSourceTypes()) {
|
165
164
|
sizes[type] = (sizes[type] || 0) + module.size(type);
|
@@ -199,7 +198,7 @@ class ChunkGraphModule {
|
|
199
198
|
this.runtimeInChunks = undefined;
|
200
199
|
/** @type {RuntimeSpecMap<ModuleHashInfo> | undefined} */
|
201
200
|
this.hashes = undefined;
|
202
|
-
/** @type {
|
201
|
+
/** @type {ModuleId | null} */
|
203
202
|
this.id = null;
|
204
203
|
/** @type {RuntimeSpecMap<Set<string>> | undefined} */
|
205
204
|
this.runtimeRequirements = undefined;
|
@@ -702,7 +701,7 @@ class ChunkGraph {
|
|
702
701
|
const modulesWithSourceType = cgc.modules
|
703
702
|
.getFromUnorderedCache(cgc._modulesBySourceType)
|
704
703
|
.get(sourceType);
|
705
|
-
if (modulesWithSourceType === undefined) return
|
704
|
+
if (modulesWithSourceType === undefined) return;
|
706
705
|
modulesWithSourceType.sortWith(comparator);
|
707
706
|
return modulesWithSourceType;
|
708
707
|
}
|
@@ -749,9 +748,9 @@ class ChunkGraph {
|
|
749
748
|
if (filterFn(module)) {
|
750
749
|
if (array === undefined) {
|
751
750
|
array = [];
|
752
|
-
chunkModuleIdMap[asyncChunk.id] = array;
|
751
|
+
chunkModuleIdMap[/** @type {ChunkId} */ (asyncChunk.id)] = array;
|
753
752
|
}
|
754
|
-
const moduleId = this.getModuleId(module);
|
753
|
+
const moduleId = /** @type {ModuleId} */ (this.getModuleId(module));
|
755
754
|
array.push(moduleId);
|
756
755
|
}
|
757
756
|
}
|
@@ -773,13 +772,15 @@ class ChunkGraph {
|
|
773
772
|
hashLength = 0,
|
774
773
|
includeAllChunks = false
|
775
774
|
) {
|
776
|
-
/** @type {Record<
|
775
|
+
/** @type {Record<ChunkId, Record<string|number, string>>} */
|
777
776
|
const chunkModuleHashMap = Object.create(null);
|
778
777
|
|
778
|
+
/** @typedef {Record<string|number, string>} IdToHashMap */
|
779
|
+
|
779
780
|
for (const asyncChunk of includeAllChunks
|
780
781
|
? chunk.getAllReferencedChunks()
|
781
782
|
: chunk.getAllAsyncChunks()) {
|
782
|
-
/** @type {
|
783
|
+
/** @type {IdToHashMap | undefined} */
|
783
784
|
let idToHashMap;
|
784
785
|
for (const module of this.getOrderedChunkModulesIterable(
|
785
786
|
asyncChunk,
|
@@ -788,11 +789,15 @@ class ChunkGraph {
|
|
788
789
|
if (filterFn(module)) {
|
789
790
|
if (idToHashMap === undefined) {
|
790
791
|
idToHashMap = Object.create(null);
|
791
|
-
chunkModuleHashMap[asyncChunk.id] =
|
792
|
+
chunkModuleHashMap[/** @type {ChunkId} */ (asyncChunk.id)] =
|
793
|
+
/** @type {IdToHashMap} */ (idToHashMap);
|
792
794
|
}
|
793
795
|
const moduleId = this.getModuleId(module);
|
794
796
|
const hash = this.getRenderedModuleHash(module, asyncChunk.runtime);
|
795
|
-
|
797
|
+
/** @type {IdToHashMap} */
|
798
|
+
(idToHashMap)[/** @type {ModuleId} */ (moduleId)] = hashLength
|
799
|
+
? hash.slice(0, hashLength)
|
800
|
+
: hash;
|
796
801
|
}
|
797
802
|
}
|
798
803
|
}
|
@@ -808,7 +813,7 @@ class ChunkGraph {
|
|
808
813
|
getChunkConditionMap(chunk, filterFn) {
|
809
814
|
const map = Object.create(null);
|
810
815
|
for (const c of chunk.getAllReferencedChunks()) {
|
811
|
-
map[c.id] = filterFn(c, this);
|
816
|
+
map[/** @type {ChunkId} */ (c.id)] = filterFn(c, this);
|
812
817
|
}
|
813
818
|
return map;
|
814
819
|
}
|
@@ -916,7 +921,7 @@ class ChunkGraph {
|
|
916
921
|
const cgcB = this._getChunkGraphChunk(chunkB);
|
917
922
|
const allModules = new Set(cgcA.modules);
|
918
923
|
for (const m of cgcB.modules) allModules.add(m);
|
919
|
-
|
924
|
+
const modulesSize = getModulesSize(allModules);
|
920
925
|
const chunkOverhead =
|
921
926
|
typeof options.chunkOverhead === "number" ? options.chunkOverhead : 10000;
|
922
927
|
const entryChunkMultiplicator =
|
@@ -950,9 +955,9 @@ class ChunkGraph {
|
|
950
955
|
return isAvailableChunk(chunkA, chunkB);
|
951
956
|
} else if (hasRuntimeB) {
|
952
957
|
return isAvailableChunk(chunkB, chunkA);
|
953
|
-
} else {
|
954
|
-
return false;
|
955
958
|
}
|
959
|
+
|
960
|
+
return false;
|
956
961
|
}
|
957
962
|
|
958
963
|
if (
|
@@ -1011,7 +1016,12 @@ class ChunkGraph {
|
|
1011
1016
|
this.getChunkEntryModulesWithChunkGroupIterable(chunkB)
|
1012
1017
|
)) {
|
1013
1018
|
this.disconnectChunkAndEntryModule(chunkB, module);
|
1014
|
-
this.connectChunkAndEntryModule(
|
1019
|
+
this.connectChunkAndEntryModule(
|
1020
|
+
chunkA,
|
1021
|
+
module,
|
1022
|
+
/** @type {Entrypoint} */
|
1023
|
+
(chunkGroup)
|
1024
|
+
);
|
1015
1025
|
}
|
1016
1026
|
|
1017
1027
|
for (const chunkGroup of chunkB.groupsIterable) {
|
@@ -1052,7 +1062,7 @@ class ChunkGraph {
|
|
1052
1062
|
/**
|
1053
1063
|
* @param {Chunk} chunk the new chunk
|
1054
1064
|
* @param {Module} module the entry module
|
1055
|
-
* @param {Entrypoint
|
1065
|
+
* @param {Entrypoint} entrypoint the chunk group which must be loaded before the module is executed
|
1056
1066
|
* @returns {void}
|
1057
1067
|
*/
|
1058
1068
|
connectChunkAndEntryModule(chunk, module, entrypoint) {
|
@@ -1111,8 +1121,9 @@ class ChunkGraph {
|
|
1111
1121
|
disconnectChunkAndEntryModule(chunk, module) {
|
1112
1122
|
const cgm = this._getChunkGraphModule(module);
|
1113
1123
|
const cgc = this._getChunkGraphChunk(chunk);
|
1114
|
-
|
1115
|
-
|
1124
|
+
/** @type {EntryInChunks} */
|
1125
|
+
(cgm.entryInChunks).delete(chunk);
|
1126
|
+
if (/** @type {EntryInChunks} */ (cgm.entryInChunks).size === 0) {
|
1116
1127
|
cgm.entryInChunks = undefined;
|
1117
1128
|
}
|
1118
1129
|
cgc.entryModules.delete(module);
|
@@ -1126,8 +1137,9 @@ class ChunkGraph {
|
|
1126
1137
|
disconnectChunkAndRuntimeModule(chunk, module) {
|
1127
1138
|
const cgm = this._getChunkGraphModule(module);
|
1128
1139
|
const cgc = this._getChunkGraphChunk(chunk);
|
1129
|
-
|
1130
|
-
|
1140
|
+
/** @type {RuntimeInChunks} */
|
1141
|
+
(cgm.runtimeInChunks).delete(chunk);
|
1142
|
+
if (/** @type {RuntimeInChunks} */ (cgm.runtimeInChunks).size === 0) {
|
1131
1143
|
cgm.runtimeInChunks = undefined;
|
1132
1144
|
}
|
1133
1145
|
cgc.runtimeModules.delete(module);
|
@@ -1154,8 +1166,9 @@ class ChunkGraph {
|
|
1154
1166
|
const cgc = this._getChunkGraphChunk(chunk);
|
1155
1167
|
for (const module of cgc.entryModules.keys()) {
|
1156
1168
|
const cgm = this._getChunkGraphModule(module);
|
1157
|
-
|
1158
|
-
|
1169
|
+
/** @type {EntryInChunks} */
|
1170
|
+
(cgm.entryInChunks).delete(chunk);
|
1171
|
+
if (/** @type {EntryInChunks} */ (cgm.entryInChunks).size === 0) {
|
1159
1172
|
cgm.entryInChunks = undefined;
|
1160
1173
|
}
|
1161
1174
|
}
|
@@ -1322,7 +1335,7 @@ class ChunkGraph {
|
|
1322
1335
|
|
1323
1336
|
/**
|
1324
1337
|
* @param {Module} module the module
|
1325
|
-
* @returns {ModuleId} the id of the module
|
1338
|
+
* @returns {ModuleId | null} the id of the module
|
1326
1339
|
*/
|
1327
1340
|
getModuleId(module) {
|
1328
1341
|
const cgm = this._getChunkGraphModule(module);
|
@@ -1344,7 +1357,7 @@ class ChunkGraph {
|
|
1344
1357
|
* @returns {string | number} the id of the runtime
|
1345
1358
|
*/
|
1346
1359
|
getRuntimeId(runtime) {
|
1347
|
-
return this._runtimeIds.get(runtime);
|
1360
|
+
return /** @type {string | number} */ (this._runtimeIds.get(runtime));
|
1348
1361
|
}
|
1349
1362
|
|
1350
1363
|
/**
|
@@ -1474,10 +1487,10 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1474
1487
|
} else if (!transferOwnership || runtimeRequirements.size >= items.size) {
|
1475
1488
|
for (const item of items) runtimeRequirements.add(item);
|
1476
1489
|
return runtimeRequirements;
|
1477
|
-
} else {
|
1478
|
-
for (const item of runtimeRequirements) items.add(item);
|
1479
|
-
return items;
|
1480
1490
|
}
|
1491
|
+
|
1492
|
+
for (const item of runtimeRequirements) items.add(item);
|
1493
|
+
return items;
|
1481
1494
|
});
|
1482
1495
|
}
|
1483
1496
|
|
@@ -1593,6 +1606,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1593
1606
|
if (cgm.graphHashesWithConnections === undefined) {
|
1594
1607
|
cgm.graphHashesWithConnections = new RuntimeSpecMap();
|
1595
1608
|
}
|
1609
|
+
|
1596
1610
|
/**
|
1597
1611
|
* @param {ConnectionState} state state
|
1598
1612
|
* @returns {"F" | "T" | "O"} result
|
@@ -1615,6 +1629,10 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1615
1629
|
const activeNamespaceModules = new Set();
|
1616
1630
|
/** @type {Map<string, Module | Set<Module>>} */
|
1617
1631
|
const connectedModules = new Map();
|
1632
|
+
/**
|
1633
|
+
* @param {ModuleGraphConnection} connection connection
|
1634
|
+
* @param {string} stateInfo state info
|
1635
|
+
*/
|
1618
1636
|
const processConnection = (connection, stateInfo) => {
|
1619
1637
|
const module = connection.module;
|
1620
1638
|
stateInfo += module.getExportsType(this.moduleGraph, strict);
|
@@ -1696,7 +1714,9 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1696
1714
|
hash.update(xor.toString(16));
|
1697
1715
|
};
|
1698
1716
|
if (activeNamespaceModules.size === 1)
|
1699
|
-
addModuleToHash(
|
1717
|
+
addModuleToHash(
|
1718
|
+
/** @type {Module} */ (activeNamespaceModules.values().next().value)
|
1719
|
+
);
|
1700
1720
|
else if (activeNamespaceModules.size > 1)
|
1701
1721
|
addModulesToHash(activeNamespaceModules);
|
1702
1722
|
for (const [stateInfo, modules] of connectedModulesInOrder) {
|
@@ -1740,12 +1760,13 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1740
1760
|
const chunkGraph = chunkGraphForModuleMap.get(module);
|
1741
1761
|
if (!chunkGraph)
|
1742
1762
|
throw new Error(
|
1743
|
-
|
1744
|
-
|
1763
|
+
`${
|
1764
|
+
deprecateMessage
|
1765
|
+
}: There was no ChunkGraph assigned to the Module for backward-compat (Use the new API)`
|
1745
1766
|
);
|
1746
1767
|
return chunkGraph;
|
1747
1768
|
},
|
1748
|
-
deprecateMessage
|
1769
|
+
`${deprecateMessage}: Use new ChunkGraph API`,
|
1749
1770
|
deprecationCode
|
1750
1771
|
);
|
1751
1772
|
deprecateGetChunkGraphForModuleMap.set(deprecateMessage, newFn);
|
@@ -1790,12 +1811,13 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
1790
1811
|
const chunkGraph = chunkGraphForChunkMap.get(chunk);
|
1791
1812
|
if (!chunkGraph)
|
1792
1813
|
throw new Error(
|
1793
|
-
|
1794
|
-
|
1814
|
+
`${
|
1815
|
+
deprecateMessage
|
1816
|
+
}There was no ChunkGraph assigned to the Chunk for backward-compat (Use the new API)`
|
1795
1817
|
);
|
1796
1818
|
return chunkGraph;
|
1797
1819
|
},
|
1798
|
-
deprecateMessage
|
1820
|
+
`${deprecateMessage}: Use new ChunkGraph API`,
|
1799
1821
|
deprecationCode
|
1800
1822
|
);
|
1801
1823
|
deprecateGetChunkGraphForChunkMap.set(deprecateMessage, newFn);
|
package/lib/ChunkGroup.js
CHANGED
@@ -22,7 +22,7 @@ const {
|
|
22
22
|
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
23
23
|
|
24
24
|
/** @typedef {{id: number}} HasId */
|
25
|
-
/** @typedef {{module: Module, loc: DependencyLocation, request: string}} OriginRecord */
|
25
|
+
/** @typedef {{module: Module | null, loc: DependencyLocation, request: string}} OriginRecord */
|
26
26
|
|
27
27
|
/**
|
28
28
|
* @typedef {object} RawChunkGroupOptions
|
@@ -404,7 +404,7 @@ class ChunkGroup {
|
|
404
404
|
}
|
405
405
|
|
406
406
|
/**
|
407
|
-
* @param {Module} module origin module
|
407
|
+
* @param {Module | null} module origin module
|
408
408
|
* @param {DependencyLocation} loc location of the reference in the origin module
|
409
409
|
* @param {string} request request name of the reference
|
410
410
|
* @returns {void}
|
@@ -478,7 +478,6 @@ class ChunkGroup {
|
|
478
478
|
/**
|
479
479
|
* Sorting predicate which allows current ChunkGroup to be compared against another.
|
480
480
|
* Sorting values are based off of number of chunks in ChunkGroup.
|
481
|
-
*
|
482
481
|
* @param {ChunkGraph} chunkGraph the chunk graph
|
483
482
|
* @param {ChunkGroup} otherGroup the chunkGroup to compare this against
|
484
483
|
* @returns {-1|0|1} sort position for comparison
|
package/lib/ChunkTemplate.js
CHANGED
@@ -8,8 +8,21 @@
|
|
8
8
|
const util = require("util");
|
9
9
|
const memoize = require("./util/memoize");
|
10
10
|
|
11
|
+
/** @typedef {import("tapable").Tap} Tap */
|
11
12
|
/** @typedef {import("../declarations/WebpackOptions").Output} OutputOptions */
|
13
|
+
/** @typedef {import("./Chunk")} Chunk */
|
12
14
|
/** @typedef {import("./Compilation")} Compilation */
|
15
|
+
/** @typedef {import("./Compilation").ChunkHashContext} ChunkHashContext */
|
16
|
+
/** @typedef {import("./Compilation").Hash} Hash */
|
17
|
+
/** @typedef {import("./Compilation").RenderManifestEntry} RenderManifestEntry */
|
18
|
+
/** @typedef {import("./Compilation").RenderManifestOptions} RenderManifestOptions */
|
19
|
+
/** @typedef {import("./Compilation").Source} Source */
|
20
|
+
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
21
|
+
/** @typedef {import("./javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
|
22
|
+
/**
|
23
|
+
* @template T
|
24
|
+
* @typedef {import("tapable").IfSet<T>} IfSet
|
25
|
+
*/
|
13
26
|
|
14
27
|
const getJavascriptModulesPlugin = memoize(() =>
|
15
28
|
require("./javascript/JavascriptModulesPlugin")
|
@@ -26,6 +39,11 @@ class ChunkTemplate {
|
|
26
39
|
this.hooks = Object.freeze({
|
27
40
|
renderManifest: {
|
28
41
|
tap: util.deprecate(
|
42
|
+
/**
|
43
|
+
* @template AdditionalOptions
|
44
|
+
* @param {string | Tap & IfSet<AdditionalOptions>} options options
|
45
|
+
* @param {function(RenderManifestEntry[], RenderManifestOptions): RenderManifestEntry[]} fn function
|
46
|
+
*/
|
29
47
|
(options, fn) => {
|
30
48
|
compilation.hooks.renderManifest.tap(
|
31
49
|
options,
|
@@ -41,6 +59,11 @@ class ChunkTemplate {
|
|
41
59
|
},
|
42
60
|
modules: {
|
43
61
|
tap: util.deprecate(
|
62
|
+
/**
|
63
|
+
* @template AdditionalOptions
|
64
|
+
* @param {string | Tap & IfSet<AdditionalOptions>} options options
|
65
|
+
* @param {function(Source, ModuleTemplate, RenderContext): Source} fn function
|
66
|
+
*/
|
44
67
|
(options, fn) => {
|
45
68
|
getJavascriptModulesPlugin()
|
46
69
|
.getCompilationHooks(compilation)
|
@@ -58,6 +81,11 @@ class ChunkTemplate {
|
|
58
81
|
},
|
59
82
|
render: {
|
60
83
|
tap: util.deprecate(
|
84
|
+
/**
|
85
|
+
* @template AdditionalOptions
|
86
|
+
* @param {string | Tap & IfSet<AdditionalOptions>} options options
|
87
|
+
* @param {function(Source, ModuleTemplate, RenderContext): Source} fn function
|
88
|
+
*/
|
61
89
|
(options, fn) => {
|
62
90
|
getJavascriptModulesPlugin()
|
63
91
|
.getCompilationHooks(compilation)
|
@@ -75,6 +103,11 @@ class ChunkTemplate {
|
|
75
103
|
},
|
76
104
|
renderWithEntry: {
|
77
105
|
tap: util.deprecate(
|
106
|
+
/**
|
107
|
+
* @template AdditionalOptions
|
108
|
+
* @param {string | Tap & IfSet<AdditionalOptions>} options options
|
109
|
+
* @param {function(Source, Chunk): Source} fn function
|
110
|
+
*/
|
78
111
|
(options, fn) => {
|
79
112
|
getJavascriptModulesPlugin()
|
80
113
|
.getCompilationHooks(compilation)
|
@@ -96,6 +129,11 @@ class ChunkTemplate {
|
|
96
129
|
},
|
97
130
|
hash: {
|
98
131
|
tap: util.deprecate(
|
132
|
+
/**
|
133
|
+
* @template AdditionalOptions
|
134
|
+
* @param {string | Tap & IfSet<AdditionalOptions>} options options
|
135
|
+
* @param {function(Hash): void} fn function
|
136
|
+
*/
|
99
137
|
(options, fn) => {
|
100
138
|
compilation.hooks.fullHash.tap(options, fn);
|
101
139
|
},
|
@@ -105,6 +143,11 @@ class ChunkTemplate {
|
|
105
143
|
},
|
106
144
|
hashForChunk: {
|
107
145
|
tap: util.deprecate(
|
146
|
+
/**
|
147
|
+
* @template AdditionalOptions
|
148
|
+
* @param {string | Tap & IfSet<AdditionalOptions>} options options
|
149
|
+
* @param {function(Hash, Chunk, ChunkHashContext): void} fn function
|
150
|
+
*/
|
108
151
|
(options, fn) => {
|
109
152
|
getJavascriptModulesPlugin()
|
110
153
|
.getCompilationHooks(compilation)
|
package/lib/CleanPlugin.js
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
const asyncLib = require("neo-async");
|
9
9
|
const { SyncBailHook } = require("tapable");
|
10
|
-
const Compilation = require("
|
10
|
+
const Compilation = require("./Compilation");
|
11
11
|
const createSchemaValidation = require("./util/create-schema-validation");
|
12
12
|
const { join } = require("./util/fs");
|
13
13
|
const processAsyncTree = require("./util/processAsyncTree");
|
@@ -28,6 +28,12 @@ const processAsyncTree = require("./util/processAsyncTree");
|
|
28
28
|
* @property {SyncBailHook<[string], boolean>} keep when returning true the file/directory will be kept during cleaning, returning false will clean it and ignore the following plugins and config
|
29
29
|
*/
|
30
30
|
|
31
|
+
/**
|
32
|
+
* @callback KeepFn
|
33
|
+
* @param {string} path path
|
34
|
+
* @returns {boolean} true, if the path should be kept
|
35
|
+
*/
|
36
|
+
|
31
37
|
const validate = createSchemaValidation(
|
32
38
|
undefined,
|
33
39
|
() => {
|
@@ -326,21 +332,14 @@ class CleanPlugin {
|
|
326
332
|
apply(compiler) {
|
327
333
|
const { dry, keep } = this.options;
|
328
334
|
|
335
|
+
/** @type {KeepFn} */
|
329
336
|
const keepFn =
|
330
337
|
typeof keep === "function"
|
331
338
|
? keep
|
332
339
|
: typeof keep === "string"
|
333
|
-
?
|
334
|
-
* @param {string} path path
|
335
|
-
* @returns {boolean} true, if the path should be kept
|
336
|
-
*/
|
337
|
-
path => path.startsWith(keep)
|
340
|
+
? path => path.startsWith(keep)
|
338
341
|
: typeof keep === "object" && keep.test
|
339
|
-
?
|
340
|
-
* @param {string} path path
|
341
|
-
* @returns {boolean} true, if the path should be kept
|
342
|
-
*/
|
343
|
-
path => keep.test(path)
|
342
|
+
? path => keep.test(path)
|
344
343
|
: () => false;
|
345
344
|
|
346
345
|
// We assume that no external modification happens while the compiler is active
|
@@ -42,7 +42,9 @@ class CodeGenerationResults {
|
|
42
42
|
);
|
43
43
|
}
|
44
44
|
if (runtime === undefined) {
|
45
|
-
if (
|
45
|
+
if (
|
46
|
+
/** @type {RuntimeSpecMap<CodeGenerationResult>} */ (entry).size > 1
|
47
|
+
) {
|
46
48
|
const results = new Set(entry.values());
|
47
49
|
if (results.size !== 1) {
|
48
50
|
throw new Error(
|
@@ -53,9 +55,9 @@ class CodeGenerationResults {
|
|
53
55
|
Caller might not support runtime-dependent code generation (opt-out via optimization.usedExports: "global").`
|
54
56
|
);
|
55
57
|
}
|
56
|
-
return first(results);
|
58
|
+
return /** @type {CodeGenerationResult} */ (first(results));
|
57
59
|
}
|
58
|
-
return entry.values().next().value;
|
60
|
+
return /** @type {CodeGenerationResult} */ (entry.values().next().value);
|
59
61
|
}
|
60
62
|
const result = entry.get(runtime);
|
61
63
|
if (result === undefined) {
|
@@ -86,9 +88,8 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
86
88
|
} else if (entry.size > 1) {
|
87
89
|
const results = new Set(entry.values());
|
88
90
|
return results.size === 1;
|
89
|
-
} else {
|
90
|
-
return entry.size === 1;
|
91
91
|
}
|
92
|
+
return entry.size === 1;
|
92
93
|
}
|
93
94
|
|
94
95
|
/**
|