webpack 5.99.8 → 5.100.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 +0 -3
- package/bin/webpack.js +8 -2
- package/hot/log.js +15 -15
- package/hot/poll.js +1 -0
- package/lib/APIPlugin.js +3 -3
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -0
- package/lib/BannerPlugin.js +1 -1
- package/lib/CacheFacade.js +2 -1
- package/lib/CaseSensitiveModulesWarning.js +4 -4
- package/lib/Chunk.js +6 -6
- package/lib/ChunkGraph.js +37 -32
- package/lib/ChunkGroup.js +17 -10
- package/lib/ChunkTemplate.js +1 -1
- package/lib/CleanPlugin.js +94 -17
- package/lib/CodeGenerationResults.js +1 -1
- package/lib/CompatibilityPlugin.js +5 -2
- package/lib/Compilation.js +77 -71
- package/lib/Compiler.js +46 -16
- package/lib/ConcatenationScope.js +15 -6
- package/lib/ConstPlugin.js +65 -45
- package/lib/ContextModule.js +16 -12
- package/lib/ContextModuleFactory.js +4 -3
- package/lib/ContextReplacementPlugin.js +4 -2
- package/lib/CssModule.js +2 -3
- package/lib/DefinePlugin.js +111 -3
- package/lib/DelegatedModuleFactoryPlugin.js +18 -18
- package/lib/Dependency.js +16 -12
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DllEntryPlugin.js +3 -1
- package/lib/DllPlugin.js +4 -3
- package/lib/DllReferencePlugin.js +2 -2
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EntryOptionPlugin.js +5 -0
- package/lib/ErrorHelpers.js +4 -4
- package/lib/EvalDevToolModulePlugin.js +3 -3
- package/lib/EvalSourceMapDevToolPlugin.js +7 -7
- package/lib/ExportsInfo.js +48 -39
- package/lib/ExternalModule.js +15 -11
- package/lib/ExternalModuleFactoryPlugin.js +5 -2
- package/lib/FileSystemInfo.js +51 -38
- package/lib/FlagDependencyExportsPlugin.js +14 -7
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +14 -1
- package/lib/HookWebpackError.js +1 -0
- package/lib/HotModuleReplacementPlugin.js +77 -50
- package/lib/IgnorePlugin.js +1 -1
- package/lib/InvalidDependenciesModuleWarning.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +0 -1
- package/lib/LibManifestPlugin.js +4 -2
- package/lib/LoaderOptionsPlugin.js +6 -4
- package/lib/MainTemplate.js +2 -2
- package/lib/Module.js +21 -6
- package/lib/ModuleFactory.js +1 -0
- package/lib/ModuleGraph.js +24 -2
- package/lib/ModuleGraphConnection.js +5 -5
- package/lib/ModuleInfoHeaderPlugin.js +2 -1
- package/lib/ModuleParseError.js +1 -0
- package/lib/ModuleSourceTypesConstants.js +12 -12
- package/lib/ModuleTemplate.js +1 -1
- package/lib/ModuleTypeConstants.js +21 -21
- package/lib/MultiCompiler.js +6 -6
- package/lib/NormalModule.js +61 -56
- package/lib/NormalModuleFactory.js +52 -37
- package/lib/NormalModuleReplacementPlugin.js +1 -1
- package/lib/NullFactory.js +1 -0
- package/lib/OptimizationStages.js +1 -1
- package/lib/Parser.js +1 -0
- package/lib/ProgressPlugin.js +12 -5
- package/lib/ProvidePlugin.js +5 -1
- package/lib/RecordIdsPlugin.js +3 -3
- package/lib/RuntimeGlobals.js +175 -155
- package/lib/RuntimeModule.js +1 -0
- package/lib/RuntimePlugin.js +34 -8
- package/lib/RuntimeTemplate.js +111 -11
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +15 -25
- package/lib/SourceMapDevToolPlugin.js +19 -17
- package/lib/Template.js +2 -2
- package/lib/TemplatedPathPlugin.js +1 -1
- package/lib/WarnDeprecatedOptionPlugin.js +7 -8
- package/lib/WatchIgnorePlugin.js +4 -3
- package/lib/WebpackIsIncludedPlugin.js +2 -1
- package/lib/WebpackOptionsApply.js +115 -27
- package/lib/asset/AssetGenerator.js +26 -21
- package/lib/asset/AssetModulesPlugin.js +19 -17
- package/lib/asset/AssetSourceGenerator.js +11 -9
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +1 -1
- package/lib/buildChunkGraph.js +6 -3
- package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
- package/lib/cache/IdleFileCachePlugin.js +7 -4
- package/lib/cache/MemoryCachePlugin.js +1 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +26 -20
- package/lib/cache/ResolverCachePlugin.js +16 -8
- package/lib/cli.js +15 -10
- package/lib/config/browserslistTargetHandler.js +3 -3
- package/lib/config/defaults.js +25 -17
- package/lib/config/normalization.js +2 -1
- package/lib/config/target.js +6 -5
- package/lib/container/ContainerPlugin.js +1 -1
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackModule.js +2 -1
- package/lib/container/HoistContainerReferencesPlugin.js +1 -1
- package/lib/container/ModuleFederationPlugin.js +2 -2
- package/lib/container/RemoteModule.js +1 -1
- package/lib/css/CssGenerator.js +9 -6
- package/lib/css/CssModulesPlugin.js +44 -31
- package/lib/css/CssParser.js +6 -4
- package/lib/css/walkCssTokens.js +33 -37
- package/lib/debug/ProfilingPlugin.js +6 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -8
- package/lib/dependencies/AMDPlugin.js +12 -8
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -26
- package/lib/dependencies/CachedConstDependency.js +1 -5
- package/lib/dependencies/CommonJsExportRequireDependency.js +6 -4
- package/lib/dependencies/CommonJsExportsParserPlugin.js +22 -25
- package/lib/dependencies/CommonJsFullRequireDependency.js +1 -9
- package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -114
- package/lib/dependencies/CommonJsPlugin.js +15 -16
- package/lib/dependencies/ContextDependencyHelpers.js +2 -1
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/CssUrlDependency.js +1 -1
- package/lib/dependencies/DynamicExports.js +9 -9
- package/lib/dependencies/ExportsInfoDependency.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +122 -101
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +95 -19
- package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
- package/lib/dependencies/HarmonyImportDependency.js +11 -5
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +238 -162
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +20 -9
- package/lib/dependencies/HarmonyModulesPlugin.js +23 -12
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
- package/lib/dependencies/ImportMetaPlugin.js +2 -2
- package/lib/dependencies/ImportParserPlugin.js +40 -9
- package/lib/dependencies/ImportPlugin.js +3 -1
- package/lib/dependencies/LoaderPlugin.js +1 -0
- package/lib/dependencies/ModuleDependency.js +1 -1
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +3 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +3 -0
- package/lib/dependencies/RequireEnsurePlugin.js +6 -6
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
- package/lib/dependencies/RequireIncludePlugin.js +1 -0
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/URLContextDependency.js +65 -0
- package/lib/dependencies/URLDependency.js +1 -1
- package/lib/dependencies/URLPlugin.js +17 -157
- package/lib/dependencies/WorkerPlugin.js +23 -10
- package/lib/dependencies/processExportInfo.js +2 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +269 -185
- package/lib/esm/ModuleChunkLoadingPlugin.js +39 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +73 -6
- package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
- package/lib/hmr/LazyCompilationPlugin.js +4 -2
- package/lib/hmr/lazyCompilationBackend.js +4 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +6 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +30 -35
- package/lib/ids/DeterministicModuleIdsPlugin.js +4 -3
- package/lib/ids/HashedModuleIdsPlugin.js +5 -4
- package/lib/ids/IdHelpers.js +21 -17
- package/lib/ids/NamedChunkIdsPlugin.js +5 -5
- package/lib/ids/NamedModuleIdsPlugin.js +4 -4
- package/lib/ids/NaturalChunkIdsPlugin.js +2 -1
- package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +3 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +1 -1
- package/lib/index.js +13 -3
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +113 -119
- package/lib/javascript/BasicEvaluatedExpression.js +2 -1
- package/lib/javascript/ChunkHelpers.js +1 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +121 -136
- package/lib/javascript/EnableChunkLoadingPlugin.js +6 -3
- package/lib/javascript/JavascriptGenerator.js +14 -2
- package/lib/javascript/JavascriptModulesPlugin.js +68 -27
- package/lib/javascript/JavascriptParser.js +136 -81
- package/lib/javascript/JavascriptParserHelpers.js +41 -41
- package/lib/javascript/StartupHelpers.js +17 -17
- package/lib/json/JsonGenerator.js +4 -2
- package/lib/json/JsonModulesPlugin.js +2 -2
- package/lib/json/JsonParser.js +1 -1
- package/lib/library/AbstractLibraryPlugin.js +6 -2
- package/lib/library/AssignLibraryPlugin.js +21 -6
- package/lib/library/EnableLibraryPlugin.js +23 -3
- package/lib/library/ModuleLibraryPlugin.js +4 -1
- package/lib/library/UmdLibraryPlugin.js +15 -6
- package/lib/logging/createConsoleLogger.js +3 -3
- package/lib/logging/runtime.js +9 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/nodeConsole.js +4 -2
- package/lib/optimize/AggressiveMergingPlugin.js +45 -46
- package/lib/optimize/AggressiveSplittingPlugin.js +13 -12
- package/lib/optimize/ConcatenatedModule.js +227 -57
- package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -1
- package/lib/optimize/InnerGraph.js +115 -112
- package/lib/optimize/InnerGraphPlugin.js +2 -2
- package/lib/optimize/LimitChunkCountPlugin.js +4 -2
- package/lib/optimize/MangleExportsPlugin.js +4 -3
- package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
- package/lib/optimize/MinChunkSizePlugin.js +6 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +31 -22
- package/lib/optimize/RealContentHashPlugin.js +26 -20
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
- package/lib/optimize/SplitChunksPlugin.js +16 -13
- package/lib/rules/BasicEffectRulePlugin.js +4 -2
- package/lib/rules/BasicMatcherRulePlugin.js +3 -1
- package/lib/rules/ObjectMatcherRulePlugin.js +3 -1
- package/lib/rules/RuleSetCompiler.js +7 -4
- package/lib/rules/UseEffectRulePlugin.js +3 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +64 -9
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +214 -0
- package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -7
- package/lib/schemes/DataUriPlugin.js +3 -1
- package/lib/schemes/FileUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +27 -19
- package/lib/schemes/VirtualUrlPlugin.js +222 -0
- package/lib/serialization/AggregateErrorSerializer.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +5 -4
- package/lib/serialization/FileMiddleware.js +7 -4
- package/lib/serialization/ObjectMiddleware.js +14 -8
- package/lib/serialization/Serializer.js +5 -3
- package/lib/serialization/SerializerMiddleware.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +3 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -2
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +6 -3
- package/lib/sharing/SharePlugin.js +2 -1
- package/lib/sharing/ShareRuntimeModule.js +3 -5
- package/lib/sharing/utils.js +34 -34
- package/lib/stats/DefaultStatsFactoryPlugin.js +49 -46
- package/lib/stats/DefaultStatsPresetPlugin.js +4 -2
- package/lib/stats/DefaultStatsPrinterPlugin.js +28 -22
- package/lib/stats/StatsFactory.js +4 -2
- package/lib/stats/StatsPrinter.js +3 -2
- package/lib/url/URLParserPlugin.js +266 -0
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Hash.js +2 -0
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +2 -1
- package/lib/util/LazySet.js +11 -6
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/SetHelpers.js +3 -3
- package/lib/util/SortableSet.js +2 -2
- package/lib/util/StackedCacheMap.js +3 -1
- package/lib/util/StackedMap.js +2 -2
- package/lib/util/StringXor.js +1 -0
- package/lib/util/TupleSet.js +1 -0
- package/lib/util/URLAbsoluteSpecifier.js +1 -1
- package/lib/util/cleverMerge.js +12 -8
- package/lib/util/comparators.js +154 -127
- package/lib/util/compileBooleanMatcher.js +8 -3
- package/lib/util/concatenate.js +8 -7
- package/lib/util/conventions.js +72 -73
- package/lib/util/create-schema-validation.js +2 -1
- package/lib/util/createHash.js +10 -4
- package/lib/util/deprecation.js +69 -66
- package/lib/util/deterministicGrouping.js +4 -2
- package/lib/util/extractUrlAndGlobal.js +1 -1
- package/lib/util/findGraphRoots.js +2 -2
- package/lib/util/fs.js +30 -23
- package/lib/util/hash/md4.js +2 -2
- package/lib/util/hash/wasm-hash.js +4 -2
- package/lib/util/identifier.js +13 -12
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/magicComment.js +5 -5
- package/lib/util/processAsyncTree.js +1 -1
- package/lib/util/propertyAccess.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -2
- package/lib/util/removeBOM.js +1 -1
- package/lib/util/runtime.js +29 -21
- package/lib/util/semver.js +1 -1
- package/lib/util/serialization.js +3 -0
- package/lib/util/source.js +3 -2
- package/lib/validateSchema.js +1 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +6 -3
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +46 -49
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +3 -2
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -0
- package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -22
- package/lib/webpack.js +4 -5
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -24
- package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
- package/package.json +121 -114
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +17 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
- package/types.d.ts +1261 -366
package/README.md
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
|
|
10
10
|
[![node][node]][node-url]
|
|
11
11
|
[![builds1][builds1]][builds1-url]
|
|
12
|
-
[![builds2][builds2]][builds2-url]
|
|
13
12
|
[![dependency-review][dependency-review]][dependency-review-url]
|
|
14
13
|
[![coverage][cover]][cover-url]
|
|
15
14
|
[![PR's welcome][prs]][prs-url]
|
|
@@ -672,8 +671,6 @@ Before we started using OpenCollective, donations were made anonymously. Now tha
|
|
|
672
671
|
[prs-url]: https://webpack.js.org/contribute/
|
|
673
672
|
[builds1]: https://github.com/webpack/webpack/actions/workflows/test.yml/badge.svg
|
|
674
673
|
[builds1-url]: https://github.com/webpack/webpack/actions/workflows/test.yml
|
|
675
|
-
[builds2]: https://dev.azure.com/webpack/webpack/_apis/build/status%2Fwebpack.webpack?branchName=main
|
|
676
|
-
[builds2-url]: https://dev.azure.com/webpack/webpack/_build/latest?definitionId=3&branchName=main
|
|
677
674
|
[dependency-review-url]: https://github.com/webpack/webpack/actions/workflows/dependency-review.yml
|
|
678
675
|
[dependency-review]: https://github.com/webpack/webpack/actions/workflows/dependency-review.yml/badge.svg
|
|
679
676
|
[cover]: https://codecov.io/gh/webpack/webpack/graph/badge.svg?token=mDP3mQJNnn
|
package/bin/webpack.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* @param {string} command process to run
|
|
5
7
|
* @param {string[]} args command line arguments
|
|
@@ -7,6 +9,7 @@
|
|
|
7
9
|
*/
|
|
8
10
|
const runCommand = (command, args) => {
|
|
9
11
|
const cp = require("child_process");
|
|
12
|
+
|
|
10
13
|
return new Promise((resolve, reject) => {
|
|
11
14
|
const executedCommand = cp.spawn(command, args, {
|
|
12
15
|
stdio: "inherit",
|
|
@@ -75,7 +78,9 @@ const isInstalled = packageName => {
|
|
|
75
78
|
*/
|
|
76
79
|
const runCli = cli => {
|
|
77
80
|
const path = require("path");
|
|
81
|
+
|
|
78
82
|
const pkgPath = require.resolve(`${cli.package}/package.json`);
|
|
83
|
+
|
|
79
84
|
const pkg = require(pkgPath);
|
|
80
85
|
|
|
81
86
|
if (pkg.type === "module" || /\.mjs/i.test(pkg.bin[cli.binName])) {
|
|
@@ -171,8 +176,9 @@ if (!cli.installed) {
|
|
|
171
176
|
);
|
|
172
177
|
|
|
173
178
|
runCommand(
|
|
174
|
-
/** @type {string} */
|
|
175
|
-
|
|
179
|
+
/** @type {string} */
|
|
180
|
+
(packageManager),
|
|
181
|
+
[...installOptions, cli.package]
|
|
176
182
|
)
|
|
177
183
|
.then(() => {
|
|
178
184
|
runCli(cli);
|
package/hot/log.js
CHANGED
|
@@ -45,6 +45,21 @@ module.exports = function (level, msg) {
|
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* @param {Error} err error
|
|
50
|
+
* @returns {string} formatted error
|
|
51
|
+
*/
|
|
52
|
+
module.exports.formatError = function (err) {
|
|
53
|
+
var message = err.message;
|
|
54
|
+
var stack = err.stack;
|
|
55
|
+
if (!stack) {
|
|
56
|
+
return message;
|
|
57
|
+
} else if (stack.indexOf(message) < 0) {
|
|
58
|
+
return message + "\n" + stack;
|
|
59
|
+
}
|
|
60
|
+
return stack;
|
|
61
|
+
};
|
|
62
|
+
|
|
48
63
|
var group = console.group || dummy;
|
|
49
64
|
var groupCollapsed = console.groupCollapsed || dummy;
|
|
50
65
|
var groupEnd = console.groupEnd || dummy;
|
|
@@ -61,18 +76,3 @@ module.exports.groupEnd = logGroup(groupEnd);
|
|
|
61
76
|
module.exports.setLogLevel = function (level) {
|
|
62
77
|
logLevel = level;
|
|
63
78
|
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @param {Error} err error
|
|
67
|
-
* @returns {string} formatted error
|
|
68
|
-
*/
|
|
69
|
-
module.exports.formatError = function (err) {
|
|
70
|
-
var message = err.message;
|
|
71
|
-
var stack = err.stack;
|
|
72
|
-
if (!stack) {
|
|
73
|
-
return message;
|
|
74
|
-
} else if (stack.indexOf(message) < 0) {
|
|
75
|
-
return message + "\n" + stack;
|
|
76
|
-
}
|
|
77
|
-
return stack;
|
|
78
|
-
};
|
package/hot/poll.js
CHANGED
package/lib/APIPlugin.js
CHANGED
|
@@ -17,8 +17,8 @@ const ConstDependency = require("./dependencies/ConstDependency");
|
|
|
17
17
|
const BasicEvaluatedExpression = require("./javascript/BasicEvaluatedExpression");
|
|
18
18
|
const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
|
|
19
19
|
const {
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
evaluateToString,
|
|
21
|
+
toConstantDependency
|
|
22
22
|
} = require("./javascript/JavascriptParserHelpers");
|
|
23
23
|
const ChunkNameRuntimeModule = require("./runtime/ChunkNameRuntimeModule");
|
|
24
24
|
const GetFullHashRuntimeModule = require("./runtime/GetFullHashRuntimeModule");
|
|
@@ -179,7 +179,7 @@ class APIPlugin {
|
|
|
179
179
|
|
|
180
180
|
compilation.hooks.runtimeRequirementInTree
|
|
181
181
|
.for(RuntimeGlobals.getFullHash)
|
|
182
|
-
.tap(PLUGIN_NAME, (chunk,
|
|
182
|
+
.tap(PLUGIN_NAME, (chunk, _set) => {
|
|
183
183
|
compilation.addRuntimeModule(chunk, new GetFullHashRuntimeModule());
|
|
184
184
|
return true;
|
|
185
185
|
});
|
package/lib/BannerPlugin.js
CHANGED
|
@@ -20,7 +20,7 @@ const createSchemaValidation = require("./util/create-schema-validation");
|
|
|
20
20
|
|
|
21
21
|
const validate = createSchemaValidation(
|
|
22
22
|
/** @type {((value: typeof import("../schemas/plugins/BannerPlugin.json")) => boolean)} */
|
|
23
|
-
(require("../schemas/plugins/BannerPlugin.check
|
|
23
|
+
(require("../schemas/plugins/BannerPlugin.check")),
|
|
24
24
|
() => require("../schemas/plugins/BannerPlugin.json"),
|
|
25
25
|
{
|
|
26
26
|
name: "Banner Plugin",
|
package/lib/CacheFacade.js
CHANGED
|
@@ -38,8 +38,9 @@ class MultiItemCache {
|
|
|
38
38
|
*/
|
|
39
39
|
constructor(items) {
|
|
40
40
|
this._items = items;
|
|
41
|
+
// @ts-expect-error expected - returns the single ItemCacheFacade when passed an array of length 1
|
|
41
42
|
// eslint-disable-next-line no-constructor-return
|
|
42
|
-
if (items.length === 1) return /** @type {
|
|
43
|
+
if (items.length === 1) return /** @type {ItemCacheFacade} */ (items[0]);
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
/**
|
|
@@ -35,9 +35,9 @@ const createModulesListMessage = (modules, moduleGraph) =>
|
|
|
35
35
|
modules
|
|
36
36
|
.map(m => {
|
|
37
37
|
let message = `* ${m.identifier()}`;
|
|
38
|
-
const validReasons =
|
|
39
|
-
moduleGraph.getIncomingConnectionsByOriginModule(m).keys()
|
|
40
|
-
|
|
38
|
+
const validReasons = [
|
|
39
|
+
...moduleGraph.getIncomingConnectionsByOriginModule(m).keys()
|
|
40
|
+
].filter(Boolean);
|
|
41
41
|
|
|
42
42
|
if (validReasons.length > 0) {
|
|
43
43
|
message += `\n Used by ${validReasons.length} module(s), i. e.`;
|
|
@@ -56,7 +56,7 @@ class CaseSensitiveModulesWarning extends WebpackError {
|
|
|
56
56
|
* @param {ModuleGraph} moduleGraph the module graph
|
|
57
57
|
*/
|
|
58
58
|
constructor(modules, moduleGraph) {
|
|
59
|
-
const sortedModules = sortModules(
|
|
59
|
+
const sortedModules = sortModules([...modules]);
|
|
60
60
|
const modulesList = createModulesListMessage(sortedModules, moduleGraph);
|
|
61
61
|
super(`There are multiple modules with names that only differ in casing.
|
|
62
62
|
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
|
package/lib/Chunk.js
CHANGED
|
@@ -11,9 +11,9 @@ const { intersect } = require("./util/SetHelpers");
|
|
|
11
11
|
const SortableSet = require("./util/SortableSet");
|
|
12
12
|
const StringXor = require("./util/StringXor");
|
|
13
13
|
const {
|
|
14
|
-
compareModulesByIdentifier,
|
|
15
14
|
compareChunkGroupsByIndex,
|
|
16
|
-
compareModulesById
|
|
15
|
+
compareModulesById,
|
|
16
|
+
compareModulesByIdentifier
|
|
17
17
|
} = require("./util/comparators");
|
|
18
18
|
const { createArrayToSetDeprecationSet } = require("./util/deprecation");
|
|
19
19
|
const { mergeRuntime } = require("./util/runtime");
|
|
@@ -116,13 +116,13 @@ class Chunk {
|
|
|
116
116
|
// TODO remove in webpack 6
|
|
117
117
|
// BACKWARD-COMPAT START
|
|
118
118
|
get entryModule() {
|
|
119
|
-
const entryModules =
|
|
120
|
-
ChunkGraph.getChunkGraphForChunk(
|
|
119
|
+
const entryModules = [
|
|
120
|
+
...ChunkGraph.getChunkGraphForChunk(
|
|
121
121
|
this,
|
|
122
122
|
"Chunk.entryModule",
|
|
123
123
|
"DEP_WEBPACK_CHUNK_ENTRY_MODULE"
|
|
124
124
|
).getChunkEntryModulesIterable(this)
|
|
125
|
-
|
|
125
|
+
];
|
|
126
126
|
if (entryModules.length === 0) {
|
|
127
127
|
return undefined;
|
|
128
128
|
} else if (entryModules.length === 1) {
|
|
@@ -747,7 +747,7 @@ class Chunk {
|
|
|
747
747
|
}
|
|
748
748
|
}
|
|
749
749
|
if (chunkIdSet.size > 0) {
|
|
750
|
-
result[name] =
|
|
750
|
+
result[name] = [...chunkIdSet];
|
|
751
751
|
}
|
|
752
752
|
}
|
|
753
753
|
return result;
|
package/lib/ChunkGraph.js
CHANGED
|
@@ -12,21 +12,21 @@ const { DEFAULTS } = require("./config/defaults");
|
|
|
12
12
|
const { first } = require("./util/SetHelpers");
|
|
13
13
|
const SortableSet = require("./util/SortableSet");
|
|
14
14
|
const {
|
|
15
|
-
|
|
15
|
+
compareIds,
|
|
16
16
|
compareIterables,
|
|
17
|
+
compareModulesById,
|
|
17
18
|
compareModulesByIdentifier,
|
|
18
|
-
concatComparators,
|
|
19
19
|
compareSelect,
|
|
20
|
-
|
|
20
|
+
concatComparators
|
|
21
21
|
} = require("./util/comparators");
|
|
22
22
|
const createHash = require("./util/createHash");
|
|
23
23
|
const findGraphRoots = require("./util/findGraphRoots");
|
|
24
24
|
const {
|
|
25
25
|
RuntimeSpecMap,
|
|
26
26
|
RuntimeSpecSet,
|
|
27
|
-
|
|
27
|
+
forEachRuntime,
|
|
28
28
|
mergeRuntime,
|
|
29
|
-
|
|
29
|
+
runtimeToString
|
|
30
30
|
} = require("./util/runtime");
|
|
31
31
|
|
|
32
32
|
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
|
@@ -76,7 +76,7 @@ class ModuleHashInfo {
|
|
|
76
76
|
* @param {SortableSet<T>} set the set
|
|
77
77
|
* @returns {T[]} set as array
|
|
78
78
|
*/
|
|
79
|
-
const getArray = set =>
|
|
79
|
+
const getArray = set => [...set];
|
|
80
80
|
|
|
81
81
|
/**
|
|
82
82
|
* @param {SortableSet<Chunk>} chunks the chunks
|
|
@@ -141,7 +141,7 @@ const createOrderedArrayFunction = comparator => {
|
|
|
141
141
|
if (fn !== undefined) return fn;
|
|
142
142
|
fn = set => {
|
|
143
143
|
set.sortWith(comparator);
|
|
144
|
-
return
|
|
144
|
+
return [...set];
|
|
145
145
|
};
|
|
146
146
|
createOrderedArrayFunctionMap.set(comparator, fn);
|
|
147
147
|
return fn;
|
|
@@ -310,8 +310,8 @@ class ChunkGraph {
|
|
|
310
310
|
*/
|
|
311
311
|
_getGraphRoots(set) {
|
|
312
312
|
const { moduleGraph } = this;
|
|
313
|
-
return
|
|
314
|
-
findGraphRoots(set, module => {
|
|
313
|
+
return [
|
|
314
|
+
...findGraphRoots(set, module => {
|
|
315
315
|
/** @type {Set<Module>} */
|
|
316
316
|
const set = new Set();
|
|
317
317
|
/**
|
|
@@ -332,7 +332,7 @@ class ChunkGraph {
|
|
|
332
332
|
addDependencies(module);
|
|
333
333
|
return set;
|
|
334
334
|
})
|
|
335
|
-
|
|
335
|
+
].sort(compareModulesByIdentifier);
|
|
336
336
|
}
|
|
337
337
|
|
|
338
338
|
/**
|
|
@@ -420,8 +420,9 @@ class ChunkGraph {
|
|
|
420
420
|
*/
|
|
421
421
|
attachDependentHashModules(chunk, modules) {
|
|
422
422
|
const cgc = this._getChunkGraphChunk(chunk);
|
|
423
|
-
if (cgc.dependentHashModules === undefined)
|
|
423
|
+
if (cgc.dependentHashModules === undefined) {
|
|
424
424
|
cgc.dependentHashModules = new Set();
|
|
425
|
+
}
|
|
425
426
|
for (const module of modules) {
|
|
426
427
|
cgc.dependentHashModules.add(module);
|
|
427
428
|
}
|
|
@@ -668,7 +669,6 @@ class ChunkGraph {
|
|
|
668
669
|
if (st === undefined) return;
|
|
669
670
|
if (!sourceTypes) {
|
|
670
671
|
sourceTypes = st;
|
|
671
|
-
continue;
|
|
672
672
|
} else if (!newSet) {
|
|
673
673
|
for (const type of st) {
|
|
674
674
|
if (!newSet) {
|
|
@@ -1022,9 +1022,10 @@ class ChunkGraph {
|
|
|
1022
1022
|
this.connectChunkAndModule(chunkA, module);
|
|
1023
1023
|
}
|
|
1024
1024
|
|
|
1025
|
-
for (const [
|
|
1026
|
-
|
|
1027
|
-
|
|
1025
|
+
for (const [
|
|
1026
|
+
module,
|
|
1027
|
+
chunkGroup
|
|
1028
|
+
] of this.getChunkEntryModulesWithChunkGroupIterable(chunkB)) {
|
|
1028
1029
|
this.disconnectChunkAndEntryModule(chunkB, module);
|
|
1029
1030
|
this.connectChunkAndEntryModule(
|
|
1030
1031
|
chunkA,
|
|
@@ -1118,8 +1119,9 @@ class ChunkGraph {
|
|
|
1118
1119
|
*/
|
|
1119
1120
|
addDependentHashModuleToChunk(chunk, module) {
|
|
1120
1121
|
const cgc = this._getChunkGraphChunk(chunk);
|
|
1121
|
-
if (cgc.dependentHashModules === undefined)
|
|
1122
|
+
if (cgc.dependentHashModules === undefined) {
|
|
1122
1123
|
cgc.dependentHashModules = new Set();
|
|
1124
|
+
}
|
|
1123
1125
|
cgc.dependentHashModules.add(module);
|
|
1124
1126
|
}
|
|
1125
1127
|
|
|
@@ -1267,7 +1269,7 @@ class ChunkGraph {
|
|
|
1267
1269
|
*/
|
|
1268
1270
|
getChunkRuntimeModulesInOrder(chunk) {
|
|
1269
1271
|
const cgc = this._getChunkGraphChunk(chunk);
|
|
1270
|
-
const array =
|
|
1272
|
+
const array = [...cgc.runtimeModules];
|
|
1271
1273
|
array.sort(
|
|
1272
1274
|
concatComparators(
|
|
1273
1275
|
compareSelect(r => /** @type {RuntimeModule} */ (r).stage, compareIds),
|
|
@@ -1647,8 +1649,9 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
|
1647
1649
|
const module = connection.module;
|
|
1648
1650
|
stateInfo += module.getExportsType(this.moduleGraph, strict);
|
|
1649
1651
|
// cspell:word Tnamespace
|
|
1650
|
-
if (stateInfo === "Tnamespace")
|
|
1651
|
-
|
|
1652
|
+
if (stateInfo === "Tnamespace") {
|
|
1653
|
+
activeNamespaceModules.add(module);
|
|
1654
|
+
} else {
|
|
1652
1655
|
const oldModule = connectedModules.get(stateInfo);
|
|
1653
1656
|
if (oldModule === undefined) {
|
|
1654
1657
|
connectedModules.set(stateInfo, module);
|
|
@@ -1688,11 +1691,12 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
|
1688
1691
|
}
|
|
1689
1692
|
}
|
|
1690
1693
|
// cspell:word Tnamespace
|
|
1691
|
-
if (activeNamespaceModules.size === 0 && connectedModules.size === 0)
|
|
1694
|
+
if (activeNamespaceModules.size === 0 && connectedModules.size === 0) {
|
|
1692
1695
|
return graphHash;
|
|
1696
|
+
}
|
|
1693
1697
|
const connectedModulesInOrder =
|
|
1694
1698
|
connectedModules.size > 1
|
|
1695
|
-
?
|
|
1699
|
+
? [...connectedModules].sort(([a], [b]) => (a < b ? -1 : 1))
|
|
1696
1700
|
: connectedModules;
|
|
1697
1701
|
const hash = createHash(this._hashFunction);
|
|
1698
1702
|
/**
|
|
@@ -1713,22 +1717,21 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
|
1713
1717
|
const addModulesToHash = modules => {
|
|
1714
1718
|
let xor = ZERO_BIG_INT;
|
|
1715
1719
|
for (const m of modules) {
|
|
1716
|
-
xor
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
runtime
|
|
1722
|
-
);
|
|
1720
|
+
xor ^= this._getModuleGraphHashBigInt(
|
|
1721
|
+
this._getChunkGraphModule(m),
|
|
1722
|
+
m,
|
|
1723
|
+
runtime
|
|
1724
|
+
);
|
|
1723
1725
|
}
|
|
1724
1726
|
hash.update(xor.toString(16));
|
|
1725
1727
|
};
|
|
1726
|
-
if (activeNamespaceModules.size === 1)
|
|
1728
|
+
if (activeNamespaceModules.size === 1) {
|
|
1727
1729
|
addModuleToHash(
|
|
1728
1730
|
/** @type {Module} */ (activeNamespaceModules.values().next().value)
|
|
1729
1731
|
);
|
|
1730
|
-
else if (activeNamespaceModules.size > 1)
|
|
1732
|
+
} else if (activeNamespaceModules.size > 1) {
|
|
1731
1733
|
addModulesToHash(activeNamespaceModules);
|
|
1734
|
+
}
|
|
1732
1735
|
for (const [stateInfo, modules] of connectedModulesInOrder) {
|
|
1733
1736
|
hash.update(stateInfo);
|
|
1734
1737
|
if (modules instanceof Set) {
|
|
@@ -1768,12 +1771,13 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
|
1768
1771
|
*/
|
|
1769
1772
|
module => {
|
|
1770
1773
|
const chunkGraph = chunkGraphForModuleMap.get(module);
|
|
1771
|
-
if (!chunkGraph)
|
|
1774
|
+
if (!chunkGraph) {
|
|
1772
1775
|
throw new Error(
|
|
1773
1776
|
`${
|
|
1774
1777
|
deprecateMessage
|
|
1775
1778
|
}: There was no ChunkGraph assigned to the Module for backward-compat (Use the new API)`
|
|
1776
1779
|
);
|
|
1780
|
+
}
|
|
1777
1781
|
return chunkGraph;
|
|
1778
1782
|
},
|
|
1779
1783
|
`${deprecateMessage}: Use new ChunkGraph API`,
|
|
@@ -1819,12 +1823,13 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
|
|
|
1819
1823
|
*/
|
|
1820
1824
|
chunk => {
|
|
1821
1825
|
const chunkGraph = chunkGraphForChunkMap.get(chunk);
|
|
1822
|
-
if (!chunkGraph)
|
|
1826
|
+
if (!chunkGraph) {
|
|
1823
1827
|
throw new Error(
|
|
1824
1828
|
`${
|
|
1825
1829
|
deprecateMessage
|
|
1826
1830
|
}There was no ChunkGraph assigned to the Chunk for backward-compat (Use the new API)`
|
|
1827
1831
|
);
|
|
1832
|
+
}
|
|
1828
1833
|
return chunkGraph;
|
|
1829
1834
|
},
|
|
1830
1835
|
`${deprecateMessage}: Use new ChunkGraph API`,
|
package/lib/ChunkGroup.js
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
const util = require("util");
|
|
9
9
|
const SortableSet = require("./util/SortableSet");
|
|
10
10
|
const {
|
|
11
|
-
compareLocations,
|
|
12
11
|
compareChunks,
|
|
13
|
-
compareIterables
|
|
12
|
+
compareIterables,
|
|
13
|
+
compareLocations
|
|
14
14
|
} = require("./util/comparators");
|
|
15
15
|
|
|
16
16
|
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
|
@@ -40,7 +40,7 @@ let debugId = 5000;
|
|
|
40
40
|
* @param {SortableSet<T>} set set to convert to array.
|
|
41
41
|
* @returns {T[]} the array format of existing set
|
|
42
42
|
*/
|
|
43
|
-
const getArray = set =>
|
|
43
|
+
const getArray = set => [...set];
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* A convenience method used to sort chunks based on their id's
|
|
@@ -115,16 +115,23 @@ class ChunkGroup {
|
|
|
115
115
|
*/
|
|
116
116
|
addOptions(options) {
|
|
117
117
|
for (const _key of Object.keys(options)) {
|
|
118
|
-
const key =
|
|
118
|
+
const key =
|
|
119
|
+
/** @type {keyof ChunkGroupOptions} */
|
|
120
|
+
(_key);
|
|
119
121
|
if (this.options[key] === undefined) {
|
|
120
|
-
/** @type {
|
|
122
|
+
/** @type {EXPECTED_ANY} */
|
|
121
123
|
(this.options)[key] = options[key];
|
|
122
124
|
} else if (this.options[key] !== options[key]) {
|
|
123
125
|
if (key.endsWith("Order")) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
const orderKey =
|
|
127
|
+
/** @type {Exclude<keyof ChunkGroupOptions, "name" | "fetchPriority">} */
|
|
128
|
+
(key);
|
|
129
|
+
|
|
130
|
+
this.options[orderKey] = Math.max(
|
|
131
|
+
/** @type {number} */
|
|
132
|
+
(this.options[orderKey]),
|
|
133
|
+
/** @type {number} */
|
|
134
|
+
(options[orderKey])
|
|
128
135
|
);
|
|
129
136
|
} else {
|
|
130
137
|
throw new Error(
|
|
@@ -429,7 +436,7 @@ class ChunkGroup {
|
|
|
429
436
|
}
|
|
430
437
|
}
|
|
431
438
|
|
|
432
|
-
return
|
|
439
|
+
return [...files];
|
|
433
440
|
}
|
|
434
441
|
|
|
435
442
|
/**
|
package/lib/ChunkTemplate.js
CHANGED
|
@@ -170,7 +170,7 @@ Object.defineProperty(ChunkTemplate.prototype, "outputOptions", {
|
|
|
170
170
|
* @this {ChunkTemplate}
|
|
171
171
|
* @returns {OutputOptions} output options
|
|
172
172
|
*/
|
|
173
|
-
function () {
|
|
173
|
+
function outputOptions() {
|
|
174
174
|
return this._outputOptions;
|
|
175
175
|
},
|
|
176
176
|
"ChunkTemplate.outputOptions is deprecated (use Compilation.outputOptions instead)",
|
package/lib/CleanPlugin.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
+
const path = require("path");
|
|
8
9
|
const asyncLib = require("neo-async");
|
|
9
10
|
const { SyncBailHook } = require("tapable");
|
|
10
11
|
const Compilation = require("./Compilation");
|
|
@@ -36,6 +37,7 @@ const validate = createSchemaValidation(
|
|
|
36
37
|
undefined,
|
|
37
38
|
() => {
|
|
38
39
|
const { definitions } = require("../schemas/WebpackOptions.json");
|
|
40
|
+
|
|
39
41
|
return {
|
|
40
42
|
definitions,
|
|
41
43
|
oneOf: [{ $ref: "#/definitions/CleanOptions" }]
|
|
@@ -61,6 +63,62 @@ const mergeAssets = (as1, as2) => {
|
|
|
61
63
|
}
|
|
62
64
|
};
|
|
63
65
|
|
|
66
|
+
/**
|
|
67
|
+
* @param {Map<string, number>} assets current assets
|
|
68
|
+
* @returns {Set<string>} Set of directory paths
|
|
69
|
+
*/
|
|
70
|
+
function getDirectories(assets) {
|
|
71
|
+
const directories = new Set();
|
|
72
|
+
/**
|
|
73
|
+
* @param {string} filename asset filename
|
|
74
|
+
*/
|
|
75
|
+
const addDirectory = filename => {
|
|
76
|
+
directories.add(path.dirname(filename));
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// get directories of assets
|
|
80
|
+
for (const [asset] of assets) {
|
|
81
|
+
addDirectory(asset);
|
|
82
|
+
}
|
|
83
|
+
// and all parent directories
|
|
84
|
+
for (const directory of directories) {
|
|
85
|
+
addDirectory(directory);
|
|
86
|
+
}
|
|
87
|
+
return directories;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @param {string} a First directory path to compare
|
|
92
|
+
* @param {string} b Second directory path to compare
|
|
93
|
+
* @returns {boolean} True if both paths have the same parent directory
|
|
94
|
+
*/
|
|
95
|
+
function isEqualPath(a, b) {
|
|
96
|
+
return path.normalize(a) === path.normalize(b);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @param {Map<string, number>|Set<string>} files Collection of files to check against
|
|
101
|
+
* @param {string} file File path to check
|
|
102
|
+
* @returns {boolean} True if the file or its parent exists in the collection
|
|
103
|
+
*/
|
|
104
|
+
function hasFile(files, file) {
|
|
105
|
+
if (files instanceof Set) {
|
|
106
|
+
for (const dir of files) {
|
|
107
|
+
if (isEqualPath(dir, file)) {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (files instanceof Map) {
|
|
113
|
+
for (const dir of files.keys()) {
|
|
114
|
+
if (isEqualPath(dir, file)) {
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
64
122
|
/** @typedef {Set<string>} Diff */
|
|
65
123
|
|
|
66
124
|
/**
|
|
@@ -71,15 +129,7 @@ const mergeAssets = (as1, as2) => {
|
|
|
71
129
|
* @returns {void}
|
|
72
130
|
*/
|
|
73
131
|
const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
|
|
74
|
-
const directories =
|
|
75
|
-
// get directories of assets
|
|
76
|
-
for (const [asset] of currentAssets) {
|
|
77
|
-
directories.add(asset.replace(/(^|\/)[^/]*$/, ""));
|
|
78
|
-
}
|
|
79
|
-
// and all parent directories
|
|
80
|
-
for (const directory of directories) {
|
|
81
|
-
directories.add(directory.replace(/(^|\/)[^/]*$/, ""));
|
|
82
|
-
}
|
|
132
|
+
const directories = getDirectories(currentAssets);
|
|
83
133
|
const diff = new Set();
|
|
84
134
|
asyncLib.forEachLimit(
|
|
85
135
|
directories,
|
|
@@ -98,7 +148,10 @@ const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
|
|
|
98
148
|
for (const entry of /** @type {string[]} */ (entries)) {
|
|
99
149
|
const file = entry;
|
|
100
150
|
const filename = directory ? `${directory}/${file}` : file;
|
|
101
|
-
if (
|
|
151
|
+
if (
|
|
152
|
+
!hasFile(directories, filename) &&
|
|
153
|
+
!hasFile(currentAssets, filename)
|
|
154
|
+
) {
|
|
102
155
|
diff.add(filename);
|
|
103
156
|
}
|
|
104
157
|
}
|
|
@@ -177,22 +230,43 @@ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
|
|
|
177
230
|
jobs,
|
|
178
231
|
10,
|
|
179
232
|
({ type, filename, parent }, push, callback) => {
|
|
233
|
+
const path = join(fs, outputPath, filename);
|
|
180
234
|
/**
|
|
181
235
|
* @param {Error & { code?: string }} err error
|
|
182
236
|
* @returns {void}
|
|
183
237
|
*/
|
|
184
238
|
const handleError = err => {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
239
|
+
const isAlreadyRemoved = () =>
|
|
240
|
+
new Promise(resolve => {
|
|
241
|
+
if (err.code === "ENOENT") {
|
|
242
|
+
resolve(true);
|
|
243
|
+
} else if (err.code === "EPERM") {
|
|
244
|
+
// https://github.com/isaacs/rimraf/blob/main/src/fix-eperm.ts#L37
|
|
245
|
+
// fs.existsSync(path) === false https://github.com/webpack/webpack/actions/runs/15493412975/job/43624272783?pr=19586
|
|
246
|
+
doStat(fs, path, err => {
|
|
247
|
+
if (err) {
|
|
248
|
+
resolve(err.code === "ENOENT");
|
|
249
|
+
} else {
|
|
250
|
+
resolve(false);
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
} else {
|
|
254
|
+
resolve(false);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
isAlreadyRemoved().then(isRemoved => {
|
|
259
|
+
if (isRemoved) {
|
|
260
|
+
log(`${filename} was removed during cleaning by something else`);
|
|
261
|
+
handleParent();
|
|
262
|
+
return callback();
|
|
263
|
+
}
|
|
264
|
+
return callback(err);
|
|
265
|
+
});
|
|
191
266
|
};
|
|
192
267
|
const handleParent = () => {
|
|
193
268
|
if (parent && --parent.remaining === 0) push(parent.job);
|
|
194
269
|
};
|
|
195
|
-
const path = join(fs, outputPath, filename);
|
|
196
270
|
switch (type) {
|
|
197
271
|
case "check":
|
|
198
272
|
if (isKept(filename)) {
|
|
@@ -443,3 +517,6 @@ class CleanPlugin {
|
|
|
443
517
|
}
|
|
444
518
|
|
|
445
519
|
module.exports = CleanPlugin;
|
|
520
|
+
module.exports._getDirectories = getDirectories;
|
|
521
|
+
module.exports._hasFile = hasFile;
|
|
522
|
+
module.exports._isEqualPath = isEqualPath;
|
|
@@ -9,7 +9,7 @@ const { DEFAULTS } = require("./config/defaults");
|
|
|
9
9
|
const { getOrInsert } = require("./util/MapHelpers");
|
|
10
10
|
const { first } = require("./util/SetHelpers");
|
|
11
11
|
const createHash = require("./util/createHash");
|
|
12
|
-
const {
|
|
12
|
+
const { RuntimeSpecMap, runtimeToString } = require("./util/runtime");
|
|
13
13
|
|
|
14
14
|
/** @typedef {import("webpack-sources").Source} Source */
|
|
15
15
|
/** @typedef {import("./Module")} Module */
|