From 4cbb354d0c4565bd8b997fee133c464de2ac315a Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Mon, 25 Jul 2022 15:59:58 +0530 Subject: [PATCH] refactor!: remove workarounds for the webpack v4 support (#3346) --- packages/configtest/src/index.ts | 9 +--- packages/webpack-cli/src/types.ts | 11 ---- packages/webpack-cli/src/webpack-cli.ts | 71 +++---------------------- 3 files changed, 9 insertions(+), 82 deletions(-) diff --git a/packages/configtest/src/index.ts b/packages/configtest/src/index.ts index ab698ef2bb5..53fa9c1ebc8 100644 --- a/packages/configtest/src/index.ts +++ b/packages/configtest/src/index.ts @@ -39,14 +39,7 @@ class ConfigTestCommand { cli.logger.info(`Validate '${Array.from(configPaths).join(" ,")}'.`); try { - // @ts-expect-error cli.webpack.validate returns void - const error: Error[] | undefined = cli.webpack.validate(config.options); - - // TODO remove this after drop webpack@4 - if (error && error.length > 0) { - // @ts-expect-error schema argument is missing - throw new cli.webpack.WebpackOptionsValidationError(error); - } + cli.webpack.validate(config.options); } catch (error) { if (cli.isValidationError(error as Error)) { cli.logger.error((error as Error).message); diff --git a/packages/webpack-cli/src/types.ts b/packages/webpack-cli/src/types.ts index c1875698f19..f61f8138b39 100644 --- a/packages/webpack-cli/src/types.ts +++ b/packages/webpack-cli/src/types.ts @@ -228,15 +228,6 @@ interface BasicPackageJsonContent { license: string; } -/** - * Webpack V4 - */ - -type WebpackV4LegacyStats = Required; -interface WebpackV4Compiler extends Compiler { - compiler: Compiler; -} - /** * Plugins and util types */ @@ -320,10 +311,8 @@ export { WebpackCLICommandOptions, WebpackCLIMainOption, WebpackCLILogger, - WebpackV4LegacyStats, WebpackDevServerOptions, WebpackRunOptions, - WebpackV4Compiler, WebpackCompiler, WebpackConfiguration, Argv, diff --git a/packages/webpack-cli/src/webpack-cli.ts b/packages/webpack-cli/src/webpack-cli.ts index ee0a6e669d6..36ef3eb947f 100644 --- a/packages/webpack-cli/src/webpack-cli.ts +++ b/packages/webpack-cli/src/webpack-cli.ts @@ -13,10 +13,8 @@ import { WebpackCLICommandOptions, WebpackCLIMainOption, WebpackCLILogger, - WebpackV4LegacyStats, WebpackDevServerOptions, WebpackRunOptions, - WebpackV4Compiler, WebpackCompiler, WebpackConfiguration, Argv, @@ -34,7 +32,6 @@ import { Instantiable, JsonExt, ModuleName, - MultipleCompilerStatsOptions, PackageInstallOptions, PackageManager, Path, @@ -2226,40 +2223,12 @@ class WebpackCLI implements IWebpackCLI { } // Setup stats - // TODO remove after drop webpack@4 - const statsForWebpack4 = - this.webpack.Stats && - (this.webpack.Stats as unknown as Partial).presetToOptions; - - if (statsForWebpack4) { - if (typeof item.stats === "undefined") { - item.stats = {}; - } else if (typeof item.stats === "boolean") { - item.stats = (this.webpack.Stats as unknown as WebpackV4LegacyStats).presetToOptions( - item.stats, - ); - } else if ( - typeof item.stats === "string" && - (item.stats === "none" || - item.stats === "verbose" || - item.stats === "detailed" || - item.stats === "normal" || - item.stats === "minimal" || - item.stats === "errors-only" || - item.stats === "errors-warnings") - ) { - item.stats = (this.webpack.Stats as unknown as WebpackV4LegacyStats).presetToOptions( - item.stats, - ); - } - } else { - if (typeof item.stats === "undefined") { - item.stats = { preset: "normal" }; - } else if (typeof item.stats === "boolean") { - item.stats = item.stats ? { preset: "normal" } : { preset: "none" }; - } else if (typeof item.stats === "string") { - item.stats = { preset: item.stats }; - } + if (typeof item.stats === "undefined") { + item.stats = { preset: "normal" }; + } else if (typeof item.stats === "boolean") { + item.stats = item.stats ? { preset: "normal" } : { preset: "none" }; + } else if (typeof item.stats === "string") { + item.stats = { preset: item.stats }; } let colors; @@ -2277,10 +2246,7 @@ class WebpackCLI implements IWebpackCLI { colors = Boolean(this.colors.isColorSupported); } - // TODO remove after drop webpack v4 - if (typeof item.stats === "object" && item.stats !== null) { - item.stats.colors = colors; - } + item.stats.colors = colors; // Apply CLI plugin if (!item.plugins) { @@ -2305,12 +2271,7 @@ class WebpackCLI implements IWebpackCLI { } isValidationError(error: Error): error is WebpackError { - // https://github.com/webpack/webpack/blob/master/lib/index.js#L267 - // https://github.com/webpack/webpack/blob/v4.44.2/lib/webpack.js#L90 - const ValidationError = - this.webpack.ValidationError || this.webpack.WebpackOptionsValidationError; - - return error instanceof ValidationError || error.name === "ValidationError"; + return error instanceof this.webpack.ValidationError || error.name === "ValidationError"; } async createCompiler( @@ -2350,11 +2311,6 @@ class WebpackCLI implements IWebpackCLI { process.exit(2); } - // TODO webpack@4 return Watching and MultiWatching instead Compiler and MultiCompiler, remove this after drop webpack@4 - if (compiler && (compiler as WebpackV4Compiler).compiler) { - compiler = (compiler as WebpackV4Compiler).compiler; - } - return compiler; } @@ -2406,17 +2362,6 @@ class WebpackCLI implements IWebpackCLI { ? compiler.options.stats : undefined; - // TODO webpack@4 doesn't support `{ children: [{ colors: true }, { colors: true }] }` for stats - const statsForWebpack4 = - this.webpack.Stats && - (this.webpack.Stats as unknown as Partial).presetToOptions; - - if (this.isMultipleCompiler(compiler) && statsForWebpack4) { - (statsOptions as StatsOptions).colors = ( - statsOptions as MultipleCompilerStatsOptions - ).children.some((child) => child.colors); - } - if (options.json && createJsonStringifyStream) { const handleWriteError = (error: WebpackError) => { this.logger.error(error);