Skip to content

Commit 4cbb354

Browse files
snitin315alexander-akait
authored andcommitted
refactor!: remove workarounds for the webpack v4 support (#3346)
1 parent deb8843 commit 4cbb354

File tree

3 files changed

+9
-82
lines changed

3 files changed

+9
-82
lines changed

packages/configtest/src/index.ts

+1-8
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,7 @@ class ConfigTestCommand {
3939
cli.logger.info(`Validate '${Array.from(configPaths).join(" ,")}'.`);
4040

4141
try {
42-
// @ts-expect-error cli.webpack.validate returns void
43-
const error: Error[] | undefined = cli.webpack.validate(config.options);
44-
45-
// TODO remove this after drop webpack@4
46-
if (error && error.length > 0) {
47-
// @ts-expect-error schema argument is missing
48-
throw new cli.webpack.WebpackOptionsValidationError(error);
49-
}
42+
cli.webpack.validate(config.options);
5043
} catch (error) {
5144
if (cli.isValidationError(error as Error)) {
5245
cli.logger.error((error as Error).message);

packages/webpack-cli/src/types.ts

-11
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,6 @@ interface BasicPackageJsonContent {
228228
license: string;
229229
}
230230

231-
/**
232-
* Webpack V4
233-
*/
234-
235-
type WebpackV4LegacyStats = Required<WebpackCLIStats>;
236-
interface WebpackV4Compiler extends Compiler {
237-
compiler: Compiler;
238-
}
239-
240231
/**
241232
* Plugins and util types
242233
*/
@@ -320,10 +311,8 @@ export {
320311
WebpackCLICommandOptions,
321312
WebpackCLIMainOption,
322313
WebpackCLILogger,
323-
WebpackV4LegacyStats,
324314
WebpackDevServerOptions,
325315
WebpackRunOptions,
326-
WebpackV4Compiler,
327316
WebpackCompiler,
328317
WebpackConfiguration,
329318
Argv,

packages/webpack-cli/src/webpack-cli.ts

+8-63
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ import {
1313
WebpackCLICommandOptions,
1414
WebpackCLIMainOption,
1515
WebpackCLILogger,
16-
WebpackV4LegacyStats,
1716
WebpackDevServerOptions,
1817
WebpackRunOptions,
19-
WebpackV4Compiler,
2018
WebpackCompiler,
2119
WebpackConfiguration,
2220
Argv,
@@ -34,7 +32,6 @@ import {
3432
Instantiable,
3533
JsonExt,
3634
ModuleName,
37-
MultipleCompilerStatsOptions,
3835
PackageInstallOptions,
3936
PackageManager,
4037
Path,
@@ -2226,40 +2223,12 @@ class WebpackCLI implements IWebpackCLI {
22262223
}
22272224

22282225
// Setup stats
2229-
// TODO remove after drop webpack@4
2230-
const statsForWebpack4 =
2231-
this.webpack.Stats &&
2232-
(this.webpack.Stats as unknown as Partial<WebpackV4LegacyStats>).presetToOptions;
2233-
2234-
if (statsForWebpack4) {
2235-
if (typeof item.stats === "undefined") {
2236-
item.stats = {};
2237-
} else if (typeof item.stats === "boolean") {
2238-
item.stats = (this.webpack.Stats as unknown as WebpackV4LegacyStats).presetToOptions(
2239-
item.stats,
2240-
);
2241-
} else if (
2242-
typeof item.stats === "string" &&
2243-
(item.stats === "none" ||
2244-
item.stats === "verbose" ||
2245-
item.stats === "detailed" ||
2246-
item.stats === "normal" ||
2247-
item.stats === "minimal" ||
2248-
item.stats === "errors-only" ||
2249-
item.stats === "errors-warnings")
2250-
) {
2251-
item.stats = (this.webpack.Stats as unknown as WebpackV4LegacyStats).presetToOptions(
2252-
item.stats,
2253-
);
2254-
}
2255-
} else {
2256-
if (typeof item.stats === "undefined") {
2257-
item.stats = { preset: "normal" };
2258-
} else if (typeof item.stats === "boolean") {
2259-
item.stats = item.stats ? { preset: "normal" } : { preset: "none" };
2260-
} else if (typeof item.stats === "string") {
2261-
item.stats = { preset: item.stats };
2262-
}
2226+
if (typeof item.stats === "undefined") {
2227+
item.stats = { preset: "normal" };
2228+
} else if (typeof item.stats === "boolean") {
2229+
item.stats = item.stats ? { preset: "normal" } : { preset: "none" };
2230+
} else if (typeof item.stats === "string") {
2231+
item.stats = { preset: item.stats };
22632232
}
22642233

22652234
let colors;
@@ -2277,10 +2246,7 @@ class WebpackCLI implements IWebpackCLI {
22772246
colors = Boolean(this.colors.isColorSupported);
22782247
}
22792248

2280-
// TODO remove after drop webpack v4
2281-
if (typeof item.stats === "object" && item.stats !== null) {
2282-
item.stats.colors = colors;
2283-
}
2249+
item.stats.colors = colors;
22842250

22852251
// Apply CLI plugin
22862252
if (!item.plugins) {
@@ -2305,12 +2271,7 @@ class WebpackCLI implements IWebpackCLI {
23052271
}
23062272

23072273
isValidationError(error: Error): error is WebpackError {
2308-
// https://github.com/webpack/webpack/blob/master/lib/index.js#L267
2309-
// https://github.com/webpack/webpack/blob/v4.44.2/lib/webpack.js#L90
2310-
const ValidationError =
2311-
this.webpack.ValidationError || this.webpack.WebpackOptionsValidationError;
2312-
2313-
return error instanceof ValidationError || error.name === "ValidationError";
2274+
return error instanceof this.webpack.ValidationError || error.name === "ValidationError";
23142275
}
23152276

23162277
async createCompiler(
@@ -2350,11 +2311,6 @@ class WebpackCLI implements IWebpackCLI {
23502311
process.exit(2);
23512312
}
23522313

2353-
// TODO webpack@4 return Watching and MultiWatching instead Compiler and MultiCompiler, remove this after drop webpack@4
2354-
if (compiler && (compiler as WebpackV4Compiler).compiler) {
2355-
compiler = (compiler as WebpackV4Compiler).compiler;
2356-
}
2357-
23582314
return compiler;
23592315
}
23602316

@@ -2406,17 +2362,6 @@ class WebpackCLI implements IWebpackCLI {
24062362
? compiler.options.stats
24072363
: undefined;
24082364

2409-
// TODO webpack@4 doesn't support `{ children: [{ colors: true }, { colors: true }] }` for stats
2410-
const statsForWebpack4 =
2411-
this.webpack.Stats &&
2412-
(this.webpack.Stats as unknown as Partial<WebpackV4LegacyStats>).presetToOptions;
2413-
2414-
if (this.isMultipleCompiler(compiler) && statsForWebpack4) {
2415-
(statsOptions as StatsOptions).colors = (
2416-
statsOptions as MultipleCompilerStatsOptions
2417-
).children.some((child) => child.colors);
2418-
}
2419-
24202365
if (options.json && createJsonStringifyStream) {
24212366
const handleWriteError = (error: WebpackError) => {
24222367
this.logger.error(error);

0 commit comments

Comments
 (0)