Skip to content

Commit 90ad18b

Browse files
refactor: types
1 parent effdd25 commit 90ad18b

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

packages/webpack-cli/src/types.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
type EntryOptions,
1010
type FileCacheOptions,
1111
type MultiCompiler,
12+
type MultiCompilerOptions,
1213
type MultiStats,
1314
type Stats,
1415
type WebpackError,
@@ -25,6 +26,8 @@ import {
2526
* Webpack CLI
2627
*/
2728

29+
type WebpackCallback = Callback<[Error | undefined, Stats | MultiStats | undefined]>;
30+
2831
interface IWebpackCLI {
2932
colors: WebpackCLIColors;
3033
logger: WebpackCLILogger;
@@ -67,7 +70,7 @@ interface IWebpackCLI {
6770
isValidationError(error: Error): error is WebpackError;
6871
createCompiler(
6972
options: Partial<WebpackDevServerOptions>,
70-
callback?: Callback<[Error | undefined, Stats | MultiStats | undefined]>,
73+
callback?: WebpackCallback,
7174
): Promise<WebpackCompiler>;
7275
needWatchStdin(compiler: Compiler | MultiCompiler): boolean;
7376
runWebpack(options: WebpackRunOptions, isWatchCommand: boolean): Promise<void>;
@@ -91,7 +94,7 @@ interface WebpackCLICommandOption extends CommanderOption {
9194
}
9295

9396
interface WebpackCLIConfig {
94-
options: WebpackConfiguration | WebpackConfiguration[];
97+
options: WebpackConfiguration | (WebpackConfiguration[] & MultiCompilerOptions);
9598
path: WeakMap<object, string[]>;
9699
}
97100

@@ -308,7 +311,6 @@ export {
308311
type BasicPrimitive,
309312
type CLIPluginOptions,
310313
type CallableWebpackConfiguration,
311-
type Callback,
312314
type CommandAction,
313315
type CommanderOption,
314316
type DynamicImport,
@@ -340,6 +342,7 @@ export {
340342
type WebpackCLILogger,
341343
type WebpackCLIMainOption,
342344
type WebpackCLIOptions,
345+
type WebpackCallback,
343346
type WebpackCompiler,
344347
type WebpackConfiguration,
345348
type WebpackDevServerOptions,

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { type Help, type ParseOptions } from "commander";
33
import {
44
type Compiler,
55
type MultiCompiler,
6-
type MultiStats,
7-
type Stats,
6+
type MultiStatsOptions,
87
type StatsOptions,
98
type WebpackError,
109
default as webpack,
@@ -18,7 +17,6 @@ import {
1817
type BasicPrimitive,
1918
type CLIPluginOptions,
2019
type CallableWebpackConfiguration,
21-
type Callback,
2220
type CommandAction,
2321
type DynamicImport,
2422
type EnumValue,
@@ -50,6 +48,7 @@ import {
5048
type WebpackCLILogger,
5149
type WebpackCLIMainOption,
5250
type WebpackCLIOptions,
51+
type WebpackCallback,
5352
type WebpackCompiler,
5453
type WebpackConfiguration,
5554
type WebpackDevServerOptions,
@@ -547,10 +546,7 @@ class WebpackCLI implements IWebpackCLI {
547546
}) as WebpackCLICommand;
548547

549548
if (commandOptions.description) {
550-
command.description(
551-
commandOptions.description,
552-
commandOptions.argsDescription as Record<string, string>,
553-
);
549+
command.description(commandOptions.description, commandOptions.argsDescription!);
554550
}
555551

556552
if (commandOptions.usage) {
@@ -2338,7 +2334,7 @@ class WebpackCLI implements IWebpackCLI {
23382334

23392335
async createCompiler(
23402336
options: Partial<WebpackDevServerOptions>,
2341-
callback?: Callback<[Error | undefined, Stats | MultiStats | undefined]>,
2337+
callback?: WebpackCallback,
23422338
): Promise<WebpackCompiler> {
23432339
if (typeof options.configNodeEnv === "string") {
23442340
process.env.NODE_ENV = options.configNodeEnv;
@@ -2353,7 +2349,7 @@ class WebpackCLI implements IWebpackCLI {
23532349

23542350
try {
23552351
compiler = this.webpack(
2356-
config.options as WebpackConfiguration,
2352+
config.options,
23572353
callback
23582354
? (error, stats) => {
23592355
if (error && this.isValidationError(error)) {
@@ -2399,7 +2395,7 @@ class WebpackCLI implements IWebpackCLI {
23992395
createStringifyChunked = jsonExt.stringifyChunked;
24002396
}
24012397

2402-
const callback = (error: Error | undefined, stats: Stats | MultiStats | undefined): void => {
2398+
const callback: WebpackCallback = (error, stats): void => {
24032399
if (error) {
24042400
this.logger.error(error);
24052401
process.exit(2);
@@ -2414,13 +2410,13 @@ class WebpackCLI implements IWebpackCLI {
24142410
}
24152411

24162412
const statsOptions = this.isMultipleCompiler(compiler)
2417-
? {
2413+
? ({
24182414
children: compiler.compilers.map((compiler) =>
24192415
compiler.options ? compiler.options.stats : undefined,
24202416
),
2421-
}
2417+
} as MultiStatsOptions)
24222418
: compiler.options
2423-
? compiler.options.stats
2419+
? (compiler.options.stats as StatsOptions)
24242420
: undefined;
24252421

24262422
if (options.json && createStringifyChunked) {

0 commit comments

Comments
 (0)