webpack 5.92.1 → 5.94.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +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 +36 -21
- package/lib/ContextModuleFactory.js +89 -44
- package/lib/ContextReplacementPlugin.js +10 -9
- package/lib/DefinePlugin.js +76 -69
- 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 +5 -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 +104 -64
- 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 +132 -70
- 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 +12 -10
- package/lib/UseStrictPlugin.js +8 -1
- package/lib/WarnDeprecatedOptionPlugin.js +0 -1
- package/lib/WatchIgnorePlugin.js +26 -9
- package/lib/Watching.js +10 -5
- package/lib/WebpackOptionsApply.js +89 -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 +14 -19
- 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 +31 -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 +39 -40
- package/lib/css/CssGenerator.js +11 -14
- 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 +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +31 -34
- package/lib/dependencies/ContextElementDependency.js +2 -2
- package/lib/dependencies/CriticalDependencyWarning.js +1 -1
- package/lib/dependencies/CssExportDependency.js +72 -9
- package/lib/dependencies/CssImportDependency.js +0 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +68 -21
- 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 +41 -16
- 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 +11 -12
- 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 +6 -4
- package/lib/javascript/BasicEvaluatedExpression.js +4 -19
- package/lib/javascript/ChunkHelpers.js +1 -1
- package/lib/javascript/CommonJsChunkFormatPlugin.js +10 -11
- package/lib/javascript/EnableChunkLoadingPlugin.js +7 -6
- package/lib/javascript/JavascriptGenerator.js +23 -7
- package/lib/javascript/JavascriptModulesPlugin.js +97 -70
- 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 +9 -11
- package/lib/library/EnableLibraryPlugin.js +25 -15
- package/lib/library/ExportPropertyLibraryPlugin.js +8 -2
- package/lib/library/JsonpLibraryPlugin.js +2 -1
- package/lib/library/ModernModuleLibraryPlugin.js +144 -0
- 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 +144 -61
- 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/MinMaxSizeWarning.js +1 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +56 -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/ChunkPrefetchPreloadPlugin.js +1 -0
- 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/ConsumeSharedModule.js +19 -14
- package/lib/sharing/ConsumeSharedPlugin.js +116 -97
- package/lib/sharing/ConsumeSharedRuntimeModule.js +108 -141
- 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 +1 -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 +10 -13
- 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 +31 -31
- 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 +103 -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 +17 -16
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +17 -0
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- 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 +682 -347
package/lib/cli.js
CHANGED
@@ -8,6 +8,8 @@
|
|
8
8
|
const path = require("path");
|
9
9
|
const webpackSchema = require("../schemas/WebpackOptions.json");
|
10
10
|
|
11
|
+
/** @typedef {TODO & { absolutePath: boolean, instanceof: string, cli: { helper?: boolean, exclude?: boolean } }} Schema */
|
12
|
+
|
11
13
|
// TODO add originPath to PathItem for better errors
|
12
14
|
/**
|
13
15
|
* @typedef {object} PathItem
|
@@ -36,7 +38,7 @@ const webpackSchema = require("../schemas/WebpackOptions.json");
|
|
36
38
|
|
37
39
|
/**
|
38
40
|
* @typedef {object} ArgumentConfig
|
39
|
-
* @property {string} description
|
41
|
+
* @property {string | undefined} description
|
40
42
|
* @property {string} [negatedDescription]
|
41
43
|
* @property {string} path
|
42
44
|
* @property {boolean} multiple
|
@@ -44,24 +46,34 @@ const webpackSchema = require("../schemas/WebpackOptions.json");
|
|
44
46
|
* @property {any[]=} values
|
45
47
|
*/
|
46
48
|
|
49
|
+
/** @typedef {"string" | "number" | "boolean"} SimpleType */
|
50
|
+
|
47
51
|
/**
|
48
52
|
* @typedef {object} Argument
|
49
|
-
* @property {string} description
|
50
|
-
* @property {
|
53
|
+
* @property {string | undefined} description
|
54
|
+
* @property {SimpleType} simpleType
|
51
55
|
* @property {boolean} multiple
|
52
56
|
* @property {ArgumentConfig[]} configs
|
53
57
|
*/
|
54
58
|
|
59
|
+
/** @typedef {string | number | boolean | RegExp | (string | number | boolean | RegExp)} Value */
|
60
|
+
|
61
|
+
/** @typedef {Record<string, Argument>} Flags */
|
62
|
+
|
55
63
|
/**
|
56
|
-
* @param {
|
57
|
-
* @returns {
|
64
|
+
* @param {Schema=} schema a json schema to create arguments for (by default webpack schema is used)
|
65
|
+
* @returns {Flags} object of arguments
|
58
66
|
*/
|
59
67
|
const getArguments = (schema = webpackSchema) => {
|
60
|
-
/** @type {
|
68
|
+
/** @type {Flags} */
|
61
69
|
const flags = {};
|
62
70
|
|
63
|
-
|
64
|
-
|
71
|
+
/**
|
72
|
+
* @param {string} input input
|
73
|
+
* @returns {string} result
|
74
|
+
*/
|
75
|
+
const pathToArgumentName = input =>
|
76
|
+
input
|
65
77
|
.replace(/\./g, "-")
|
66
78
|
.replace(/\[\]/g, "")
|
67
79
|
.replace(
|
@@ -70,8 +82,11 @@ const getArguments = (schema = webpackSchema) => {
|
|
70
82
|
)
|
71
83
|
.replace(/-?[^\p{Uppercase_Letter}\p{Lowercase_Letter}\d]+/gu, "-")
|
72
84
|
.toLowerCase();
|
73
|
-
};
|
74
85
|
|
86
|
+
/**
|
87
|
+
* @param {string} path path
|
88
|
+
* @returns {Schema} schema part
|
89
|
+
*/
|
75
90
|
const getSchemaPart = path => {
|
76
91
|
const newPath = path.split("/");
|
77
92
|
|
@@ -91,7 +106,6 @@ const getArguments = (schema = webpackSchema) => {
|
|
91
106
|
};
|
92
107
|
|
93
108
|
/**
|
94
|
-
*
|
95
109
|
* @param {PathItem[]} path path in the schema
|
96
110
|
* @returns {string | undefined} description
|
97
111
|
*/
|
@@ -106,7 +120,6 @@ const getArguments = (schema = webpackSchema) => {
|
|
106
120
|
};
|
107
121
|
|
108
122
|
/**
|
109
|
-
*
|
110
123
|
* @param {PathItem[]} path path in the schema
|
111
124
|
* @returns {string | undefined} negative description
|
112
125
|
*/
|
@@ -120,7 +133,6 @@ const getArguments = (schema = webpackSchema) => {
|
|
120
133
|
};
|
121
134
|
|
122
135
|
/**
|
123
|
-
*
|
124
136
|
* @param {PathItem[]} path path in the schema
|
125
137
|
* @returns {string | undefined} reset description
|
126
138
|
*/
|
@@ -134,9 +146,8 @@ const getArguments = (schema = webpackSchema) => {
|
|
134
146
|
};
|
135
147
|
|
136
148
|
/**
|
137
|
-
*
|
138
|
-
* @
|
139
|
-
* @returns {Pick<ArgumentConfig, "type"|"values">} partial argument config
|
149
|
+
* @param {Schema} schemaPart schema
|
150
|
+
* @returns {Pick<ArgumentConfig, "type"|"values"> | undefined} partial argument config
|
140
151
|
*/
|
141
152
|
const schemaToArgumentConfig = schemaPart => {
|
142
153
|
if (schemaPart.enum) {
|
@@ -189,8 +200,10 @@ const getArguments = (schema = webpackSchema) => {
|
|
189
200
|
}
|
190
201
|
],
|
191
202
|
description: undefined,
|
192
|
-
simpleType:
|
193
|
-
|
203
|
+
simpleType:
|
204
|
+
/** @type {SimpleType} */
|
205
|
+
(/** @type {unknown} */ (undefined)),
|
206
|
+
multiple: /** @type {boolean} */ (/** @type {unknown} */ (undefined))
|
194
207
|
};
|
195
208
|
};
|
196
209
|
|
@@ -221,8 +234,10 @@ const getArguments = (schema = webpackSchema) => {
|
|
221
234
|
flags[name] = {
|
222
235
|
configs: [],
|
223
236
|
description: undefined,
|
224
|
-
simpleType:
|
225
|
-
|
237
|
+
simpleType:
|
238
|
+
/** @type {SimpleType} */
|
239
|
+
(/** @type {unknown} */ (undefined)),
|
240
|
+
multiple: /** @type {boolean} */ (/** @type {unknown} */ (undefined))
|
226
241
|
};
|
227
242
|
}
|
228
243
|
|
@@ -255,8 +270,7 @@ const getArguments = (schema = webpackSchema) => {
|
|
255
270
|
// TODO support `not` and `if/then/else`
|
256
271
|
// TODO support `const`, but we don't use it on our schema
|
257
272
|
/**
|
258
|
-
*
|
259
|
-
* @param {object} schemaPart the current schema
|
273
|
+
* @param {Schema} schemaPart the current schema
|
260
274
|
* @param {string} schemaPath the current path in the schema
|
261
275
|
* @param {{schema: object, path: string}[]} path all previous visited schemaParts
|
262
276
|
* @param {string | null} inArray if inside of an array, the path to the array
|
@@ -281,13 +295,14 @@ const getArguments = (schema = webpackSchema) => {
|
|
281
295
|
|
282
296
|
let addedArguments = 0;
|
283
297
|
|
284
|
-
addedArguments += addFlag(fullPath,
|
298
|
+
addedArguments += addFlag(fullPath, Boolean(inArray));
|
285
299
|
|
286
300
|
if (schemaPart.type === "object") {
|
287
301
|
if (schemaPart.properties) {
|
288
302
|
for (const property of Object.keys(schemaPart.properties)) {
|
289
303
|
addedArguments += traverse(
|
290
|
-
|
304
|
+
/** @type {Schema} */
|
305
|
+
(schemaPart.properties[property]),
|
291
306
|
schemaPath ? `${schemaPath}.${property}` : property,
|
292
307
|
fullPath,
|
293
308
|
inArray
|
@@ -303,10 +318,11 @@ const getArguments = (schema = webpackSchema) => {
|
|
303
318
|
return 0;
|
304
319
|
}
|
305
320
|
if (Array.isArray(schemaPart.items)) {
|
306
|
-
|
321
|
+
const i = 0;
|
307
322
|
for (const item of schemaPart.items) {
|
308
323
|
addedArguments += traverse(
|
309
|
-
|
324
|
+
/** @type {Schema} */
|
325
|
+
(item),
|
310
326
|
`${schemaPath}.${i}`,
|
311
327
|
fullPath,
|
312
328
|
schemaPath
|
@@ -317,7 +333,8 @@ const getArguments = (schema = webpackSchema) => {
|
|
317
333
|
}
|
318
334
|
|
319
335
|
addedArguments += traverse(
|
320
|
-
|
336
|
+
/** @type {Schema} */
|
337
|
+
(schemaPart.items),
|
321
338
|
`${schemaPath}[]`,
|
322
339
|
fullPath,
|
323
340
|
schemaPath
|
@@ -337,7 +354,13 @@ const getArguments = (schema = webpackSchema) => {
|
|
337
354
|
const items = maybeOf;
|
338
355
|
|
339
356
|
for (let i = 0; i < items.length; i++) {
|
340
|
-
addedArguments += traverse(
|
357
|
+
addedArguments += traverse(
|
358
|
+
/** @type {Schema} */
|
359
|
+
(items[i]),
|
360
|
+
schemaPath,
|
361
|
+
fullPath,
|
362
|
+
inArray
|
363
|
+
);
|
341
364
|
}
|
342
365
|
|
343
366
|
return addedArguments;
|
@@ -350,6 +373,7 @@ const getArguments = (schema = webpackSchema) => {
|
|
350
373
|
|
351
374
|
// Summarize flags
|
352
375
|
for (const name of Object.keys(flags)) {
|
376
|
+
/** @type {Argument} */
|
353
377
|
const argument = flags[name];
|
354
378
|
argument.description = argument.configs.reduce((desc, { description }) => {
|
355
379
|
if (!desc) return description;
|
@@ -357,27 +381,34 @@ const getArguments = (schema = webpackSchema) => {
|
|
357
381
|
if (desc.includes(description)) return desc;
|
358
382
|
return `${desc} ${description}`;
|
359
383
|
}, /** @type {string | undefined} */ (undefined));
|
360
|
-
argument.simpleType =
|
361
|
-
/** @type {
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
type = "
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
384
|
+
argument.simpleType =
|
385
|
+
/** @type {SimpleType} */
|
386
|
+
(
|
387
|
+
argument.configs.reduce((t, argConfig) => {
|
388
|
+
/** @type {SimpleType} */
|
389
|
+
let type = "string";
|
390
|
+
switch (argConfig.type) {
|
391
|
+
case "number":
|
392
|
+
type = "number";
|
393
|
+
break;
|
394
|
+
case "reset":
|
395
|
+
case "boolean":
|
396
|
+
type = "boolean";
|
397
|
+
break;
|
398
|
+
case "enum": {
|
399
|
+
const values =
|
400
|
+
/** @type {NonNullable<ArgumentConfig["values"]>} */
|
401
|
+
(argConfig.values);
|
402
|
+
|
403
|
+
if (values.every(v => typeof v === "boolean")) type = "boolean";
|
404
|
+
if (values.every(v => typeof v === "number")) type = "number";
|
405
|
+
break;
|
406
|
+
}
|
407
|
+
}
|
408
|
+
if (t === undefined) return type;
|
409
|
+
return t === type ? t : "string";
|
410
|
+
}, /** @type {SimpleType | undefined} */ (undefined))
|
411
|
+
);
|
381
412
|
argument.multiple = argument.configs.some(c => c.multiple);
|
382
413
|
}
|
383
414
|
|
@@ -386,16 +417,18 @@ const getArguments = (schema = webpackSchema) => {
|
|
386
417
|
|
387
418
|
const cliAddedItems = new WeakMap();
|
388
419
|
|
420
|
+
/** @typedef {string | number} Property */
|
421
|
+
|
389
422
|
/**
|
390
|
-
* @param {
|
423
|
+
* @param {Configuration} config configuration
|
391
424
|
* @param {string} schemaPath path in the config
|
392
425
|
* @param {number | undefined} index index of value when multiple values are provided, otherwise undefined
|
393
|
-
* @returns {{ problem?: LocalProblem, object?: any, property?:
|
426
|
+
* @returns {{ problem?: LocalProblem, object?: any, property?: Property, value?: any }} problem or object with property and value
|
394
427
|
*/
|
395
428
|
const getObjectAndProperty = (config, schemaPath, index = 0) => {
|
396
429
|
if (!schemaPath) return { value: config };
|
397
430
|
const parts = schemaPath.split(".");
|
398
|
-
|
431
|
+
const property = /** @type {string} */ (parts.pop());
|
399
432
|
let current = config;
|
400
433
|
let i = 0;
|
401
434
|
for (const part of parts) {
|
@@ -434,22 +467,20 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => {
|
|
434
467
|
}
|
435
468
|
value = value[x];
|
436
469
|
}
|
437
|
-
} else {
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
};
|
447
|
-
}
|
470
|
+
} else if (value === undefined) {
|
471
|
+
value = current[name] = {};
|
472
|
+
} else if (value === null || typeof value !== "object") {
|
473
|
+
return {
|
474
|
+
problem: {
|
475
|
+
type: "unexpected-non-object-in-path",
|
476
|
+
path: parts.slice(0, i).join(".")
|
477
|
+
}
|
478
|
+
};
|
448
479
|
}
|
449
480
|
current = value;
|
450
481
|
i++;
|
451
482
|
}
|
452
|
-
|
483
|
+
const value = current[property];
|
453
484
|
if (property.endsWith("[]")) {
|
454
485
|
const name = property.slice(0, -2);
|
455
486
|
const value = current[name];
|
@@ -461,36 +492,35 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => {
|
|
461
492
|
current[name] = [value, ...Array.from({ length: index }), undefined];
|
462
493
|
cliAddedItems.set(current[name], index + 1);
|
463
494
|
return { object: current[name], property: index + 1, value: undefined };
|
464
|
-
}
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
return {
|
476
|
-
problem: {
|
477
|
-
type: "unexpected-non-object-in-path",
|
478
|
-
path: schemaPath
|
479
|
-
}
|
480
|
-
};
|
481
|
-
}
|
495
|
+
}
|
496
|
+
let addedItems = cliAddedItems.get(value) || 0;
|
497
|
+
while (addedItems <= index) {
|
498
|
+
value.push(undefined);
|
499
|
+
addedItems++;
|
500
|
+
}
|
501
|
+
cliAddedItems.set(value, addedItems);
|
502
|
+
const x = value.length - addedItems + index;
|
503
|
+
if (value[x] === undefined) {
|
504
|
+
value[x] = {};
|
505
|
+
} else if (value[x] === null || typeof value[x] !== "object") {
|
482
506
|
return {
|
483
|
-
|
484
|
-
|
485
|
-
|
507
|
+
problem: {
|
508
|
+
type: "unexpected-non-object-in-path",
|
509
|
+
path: schemaPath
|
510
|
+
}
|
486
511
|
};
|
487
512
|
}
|
513
|
+
return {
|
514
|
+
object: value,
|
515
|
+
property: x,
|
516
|
+
value: value[x]
|
517
|
+
};
|
488
518
|
}
|
489
519
|
return { object: current, property, value };
|
490
520
|
};
|
491
521
|
|
492
522
|
/**
|
493
|
-
* @param {
|
523
|
+
* @param {Configuration} config configuration
|
494
524
|
* @param {string} schemaPath path in the config
|
495
525
|
* @param {any} value parsed value
|
496
526
|
* @param {number | undefined} index index of value when multiple values are provided, otherwise undefined
|
@@ -503,14 +533,14 @@ const setValue = (config, schemaPath, value, index) => {
|
|
503
533
|
index
|
504
534
|
);
|
505
535
|
if (problem) return problem;
|
506
|
-
object[property] = value;
|
536
|
+
object[/** @type {Property} */ (property)] = value;
|
507
537
|
return null;
|
508
538
|
};
|
509
539
|
|
510
540
|
/**
|
511
541
|
* @param {ArgumentConfig} argConfig processing instructions
|
512
|
-
* @param {
|
513
|
-
* @param {
|
542
|
+
* @param {Configuration} config configuration
|
543
|
+
* @param {Value} value the value
|
514
544
|
* @param {number | undefined} index the index if multiple values provided
|
515
545
|
* @returns {LocalProblem | null} a problem if any
|
516
546
|
*/
|
@@ -540,22 +570,26 @@ const processArgumentConfig = (argConfig, config, value, index) => {
|
|
540
570
|
*/
|
541
571
|
const getExpectedValue = argConfig => {
|
542
572
|
switch (argConfig.type) {
|
543
|
-
default:
|
544
|
-
return argConfig.type;
|
545
573
|
case "boolean":
|
546
574
|
return "true | false";
|
547
575
|
case "RegExp":
|
548
576
|
return "regular expression (example: /ab?c*/)";
|
549
577
|
case "enum":
|
550
|
-
return
|
578
|
+
return /** @type {NonNullable<ArgumentConfig["values"]>} */ (
|
579
|
+
argConfig.values
|
580
|
+
)
|
581
|
+
.map(v => `${v}`)
|
582
|
+
.join(" | ");
|
551
583
|
case "reset":
|
552
584
|
return "true (will reset the previous value to an empty array)";
|
585
|
+
default:
|
586
|
+
return argConfig.type;
|
553
587
|
}
|
554
588
|
};
|
555
589
|
|
556
590
|
/**
|
557
591
|
* @param {ArgumentConfig} argConfig processing instructions
|
558
|
-
* @param {
|
592
|
+
* @param {Value} value the value
|
559
593
|
* @returns {any | undefined} parsed value
|
560
594
|
*/
|
561
595
|
const parseValueForArgumentConfig = (argConfig, value) => {
|
@@ -573,8 +607,8 @@ const parseValueForArgumentConfig = (argConfig, value) => {
|
|
573
607
|
case "number":
|
574
608
|
if (typeof value === "number") return value;
|
575
609
|
if (typeof value === "string" && /^[+-]?\d*(\.\d*)[eE]\d+$/) {
|
576
|
-
const n =
|
577
|
-
if (!isNaN(n)) return n;
|
610
|
+
const n = Number(value);
|
611
|
+
if (!Number.isNaN(n)) return n;
|
578
612
|
}
|
579
613
|
break;
|
580
614
|
case "boolean":
|
@@ -591,22 +625,28 @@ const parseValueForArgumentConfig = (argConfig, value) => {
|
|
591
625
|
return new RegExp(match[1], match[2]);
|
592
626
|
}
|
593
627
|
break;
|
594
|
-
case "enum":
|
595
|
-
|
596
|
-
|
628
|
+
case "enum": {
|
629
|
+
const values =
|
630
|
+
/** @type {NonNullable<ArgumentConfig["values"]>} */
|
631
|
+
(argConfig.values);
|
632
|
+
if (values.includes(value)) return value;
|
633
|
+
for (const item of values) {
|
597
634
|
if (`${item}` === value) return item;
|
598
635
|
}
|
599
636
|
break;
|
637
|
+
}
|
600
638
|
case "reset":
|
601
639
|
if (value === true) return [];
|
602
640
|
break;
|
603
641
|
}
|
604
642
|
};
|
605
643
|
|
644
|
+
/** @typedef {any} Configuration */
|
645
|
+
|
606
646
|
/**
|
607
|
-
* @param {
|
608
|
-
* @param {
|
609
|
-
* @param {Record<string,
|
647
|
+
* @param {Flags} args object of arguments
|
648
|
+
* @param {Configuration} config configuration
|
649
|
+
* @param {Record<string, Value[]>} values object with values
|
610
650
|
* @returns {Problem[] | null} problems or null for success
|
611
651
|
*/
|
612
652
|
const processArguments = (args, config, values) => {
|
@@ -622,6 +662,10 @@ const processArguments = (args, config, values) => {
|
|
622
662
|
});
|
623
663
|
continue;
|
624
664
|
}
|
665
|
+
/**
|
666
|
+
* @param {Value} value value
|
667
|
+
* @param {number | undefined} i index
|
668
|
+
*/
|
625
669
|
const processValue = (value, i) => {
|
626
670
|
const currentProblems = [];
|
627
671
|
for (const argConfig of arg.configs) {
|
@@ -632,13 +676,13 @@ const processArguments = (args, config, values) => {
|
|
632
676
|
currentProblems.push({
|
633
677
|
...problem,
|
634
678
|
argument: key,
|
635
|
-
value
|
679
|
+
value,
|
636
680
|
index: i
|
637
681
|
});
|
638
682
|
}
|
639
683
|
problems.push(...currentProblems);
|
640
684
|
};
|
641
|
-
|
685
|
+
const value = values[key];
|
642
686
|
if (Array.isArray(value)) {
|
643
687
|
for (let i = 0; i < value.length; i++) {
|
644
688
|
processValue(value[i], i);
|
@@ -651,5 +695,5 @@ const processArguments = (args, config, values) => {
|
|
651
695
|
return problems;
|
652
696
|
};
|
653
697
|
|
654
|
-
exports.getArguments = getArguments;
|
655
|
-
exports.processArguments = processArguments;
|
698
|
+
module.exports.getArguments = getArguments;
|
699
|
+
module.exports.processArguments = processArguments;
|
@@ -57,14 +57,14 @@ const load = (input, context) => {
|
|
57
57
|
// if a query is specified, then use it, else
|
58
58
|
// if a path to a config is specified then load it, else
|
59
59
|
// find a nearest config
|
60
|
-
const config =
|
61
|
-
|
62
|
-
|
60
|
+
const config =
|
61
|
+
query ||
|
62
|
+
(configPath
|
63
63
|
? browserslist.loadConfig({
|
64
64
|
config: configPath,
|
65
65
|
env
|
66
66
|
})
|
67
|
-
: browserslist.loadConfig({ path: context, env });
|
67
|
+
: browserslist.loadConfig({ path: context, env }));
|
68
68
|
|
69
69
|
if (!config) return;
|
70
70
|
return browserslist(config);
|
@@ -80,8 +80,8 @@ const resolve = browsers => {
|
|
80
80
|
* @param {Record<string, number | [number, number]>} versions first supported version
|
81
81
|
* @returns {boolean} true if supports
|
82
82
|
*/
|
83
|
-
const rawChecker = versions =>
|
84
|
-
|
83
|
+
const rawChecker = versions =>
|
84
|
+
browsers.every(v => {
|
85
85
|
const [name, parsedVersion] = v.split(" ");
|
86
86
|
if (!name) return false;
|
87
87
|
const requiredVersion = versions[name];
|
@@ -94,19 +94,19 @@ const resolve = browsers => {
|
|
94
94
|
? parsedVersion.split("-")[0].split(".")
|
95
95
|
: parsedVersion.split(".");
|
96
96
|
if (typeof requiredVersion === "number") {
|
97
|
-
return
|
97
|
+
return Number(parsedMajor) >= requiredVersion;
|
98
98
|
}
|
99
|
-
return requiredVersion[0] ===
|
100
|
-
?
|
101
|
-
:
|
99
|
+
return requiredVersion[0] === Number(parsedMajor)
|
100
|
+
? Number(parserMinor) >= requiredVersion[1]
|
101
|
+
: Number(parsedMajor) > requiredVersion[0];
|
102
102
|
});
|
103
|
-
|
104
|
-
const anyNode = browsers.some(b => /^node /.test(b));
|
103
|
+
const anyNode = browsers.some(b => b.startsWith("node "));
|
105
104
|
const anyBrowser = browsers.some(b => /^(?!node)/.test(b));
|
106
105
|
const browserProperty = !anyBrowser ? false : anyNode ? null : true;
|
107
106
|
const nodeProperty = !anyNode ? false : anyBrowser ? null : true;
|
108
107
|
// Internet Explorer Mobile, Blackberry browser and Opera Mini are very old browsers, they do not support new features
|
109
108
|
const es6DynamicImport = rawChecker({
|
109
|
+
/* eslint-disable camelcase */
|
110
110
|
chrome: 63,
|
111
111
|
and_chr: 63,
|
112
112
|
edge: 79,
|
@@ -124,9 +124,11 @@ const resolve = browsers => {
|
|
124
124
|
and_uc: [15, 5],
|
125
125
|
kaios: [3, 0],
|
126
126
|
node: [12, 17]
|
127
|
+
/* eslint-enable camelcase */
|
127
128
|
});
|
128
129
|
|
129
130
|
return {
|
131
|
+
/* eslint-disable camelcase */
|
130
132
|
const: rawChecker({
|
131
133
|
chrome: 49,
|
132
134
|
and_chr: 49,
|
@@ -331,6 +333,7 @@ const resolve = browsers => {
|
|
331
333
|
kaios: 3,
|
332
334
|
node: [7, 6]
|
333
335
|
}),
|
336
|
+
/* eslint-enable camelcase */
|
334
337
|
browser: browserProperty,
|
335
338
|
electron: false,
|
336
339
|
node: nodeProperty,
|
@@ -346,7 +349,7 @@ const resolve = browsers => {
|
|
346
349
|
nodeBuiltins: nodeProperty,
|
347
350
|
nodePrefixForCoreModules:
|
348
351
|
nodeProperty &&
|
349
|
-
!browsers.some(b =>
|
352
|
+
!browsers.some(b => b.startsWith("node 15")) &&
|
350
353
|
rawChecker({
|
351
354
|
node: [14, 18]
|
352
355
|
}),
|