WXL
2025-12-27 05e6b08007a86b5b10c680babc9c3bcc3a1a201b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import type { EntryOptions, Stats, MultiStats, Configuration, WebpackError, WebpackOptionsNormalized, Compiler, MultiCompiler, Problem, Argument, AssetEmittedInfo, FileCacheOptions } from "webpack";
import type webpack from "webpack";
import type { ClientConfiguration, Configuration as DevServerConfig } from "webpack-dev-server";
import { type Colorette } from "colorette";
import { type Command, type CommandOptions, type Option, type ParseOptions } from "commander";
import { type prepare } from "rechoir";
import { type stringifyChunked } from "@discoveryjs/json-ext";
/**
 * Webpack CLI
 */
interface IWebpackCLI {
    colors: WebpackCLIColors;
    logger: WebpackCLILogger;
    isColorSupportChanged: boolean | undefined;
    webpack: typeof webpack;
    builtInOptionsCache: WebpackCLIBuiltInOption[] | undefined;
    program: WebpackCLICommand;
    isMultipleCompiler(compiler: WebpackCompiler): compiler is MultiCompiler;
    isPromise<T>(value: Promise<T>): value is Promise<T>;
    isFunction(value: unknown): value is CallableFunction;
    getLogger(): WebpackCLILogger;
    createColors(useColors?: boolean): WebpackCLIColors;
    toKebabCase: StringFormatter;
    capitalizeFirstLetter: StringFormatter;
    checkPackageExists(packageName: string): boolean;
    getAvailablePackageManagers(): PackageManager[];
    getDefaultPackageManager(): PackageManager | undefined;
    doInstall(packageName: string, options?: PackageInstallOptions): Promise<string>;
    loadJSONFile<T = unknown>(path: Path, handleError: boolean): Promise<T>;
    tryRequireThenImport<T = unknown>(module: ModuleName, handleError: boolean): Promise<T>;
    getInfoOptions(): WebpackCLIBuiltInOption[];
    getInfoOutput(options: {
        output: string;
        additionalPackage: string[];
    }): Promise<string>;
    makeCommand(commandOptions: WebpackCLIOptions, options: WebpackCLICommandOptions, action: CommandAction): Promise<WebpackCLICommand | undefined>;
    makeOption(command: WebpackCLICommand, option: WebpackCLIBuiltInOption): void;
    run(args: Parameters<WebpackCLICommand["parseOptions"]>[0], parseOptions?: ParseOptions): Promise<void>;
    getBuiltInOptions(): WebpackCLIBuiltInOption[];
    loadWebpack(handleError?: boolean): Promise<typeof webpack>;
    loadConfig(options: Partial<WebpackDevServerOptions>): Promise<WebpackCLIConfig>;
    buildConfig(config: WebpackCLIConfig, options: WebpackDevServerOptions): Promise<WebpackCLIConfig>;
    isValidationError(error: Error): error is WebpackError;
    createCompiler(options: Partial<WebpackDevServerOptions>, callback?: Callback<[Error | undefined, Stats | MultiStats | undefined]>): Promise<WebpackCompiler>;
    needWatchStdin(compiler: Compiler | MultiCompiler): boolean;
    runWebpack(options: WebpackRunOptions, isWatchCommand: boolean): Promise<void>;
}
interface WebpackCLIColors extends Colorette {
    isColorSupported: boolean;
}
interface WebpackCLILogger {
    error: LogHandler;
    warn: LogHandler;
    info: LogHandler;
    success: LogHandler;
    log: LogHandler;
    raw: LogHandler;
}
interface WebpackCLICommandOption extends CommanderOption {
    helpLevel?: "minimum" | "verbose";
}
interface WebpackCLIConfig {
    options: WebpackConfiguration | WebpackConfiguration[];
    path: WeakMap<object, string[]>;
}
interface WebpackCLICommand extends Command {
    pkg: string | undefined;
    forHelp: boolean | undefined;
    _args: WebpackCLICommandOption[];
}
type WebpackCLIMainOption = Pick<WebpackCLIBuiltInOption, "valueName" | "description" | "defaultValue" | "multiple"> & {
    flags: string;
    type: Set<BooleanConstructor | StringConstructor | NumberConstructor>;
};
interface WebpackCLIOptions extends CommandOptions {
    name: string;
    alias: string | string[];
    description?: string;
    usage?: string;
    dependencies?: string[];
    pkg?: string;
    argsDescription?: {
        [argName: string]: string;
    };
}
type WebpackCLICommandOptions = WebpackCLIBuiltInOption[] | (() => Promise<WebpackCLIBuiltInOption[]>);
interface WebpackCLIBuiltInFlag {
    name: string;
    alias?: string;
    type?: (value: string, previous: Record<string, BasicPrimitive | object>) => Record<string, BasicPrimitive | object>;
    configs?: Partial<FlagConfig>[];
    negative?: boolean;
    multiple?: boolean;
    valueName?: string;
    description?: string;
    describe?: string;
    negatedDescription?: string;
    defaultValue?: string;
    helpLevel: "minimum" | "verbose";
}
interface WebpackCLIBuiltInOption extends WebpackCLIBuiltInFlag {
    hidden?: boolean;
    group?: "core";
}
type WebpackCLIExternalCommandInfo = Pick<WebpackCLIOptions, "name" | "alias" | "description"> & {
    pkg: string;
};
/**
 * Webpack dev server
 */
type WebpackDevServerOptions = DevServerConfig & WebpackConfiguration & ClientConfiguration & AssetEmittedInfo & WebpackOptionsNormalized & FileCacheOptions & Argv & {
    nodeEnv?: "string";
    watchOptionsStdin?: boolean;
    progress?: boolean | "profile" | undefined;
    analyze?: boolean;
    prefetch?: string;
    json?: boolean;
    entry: EntryOptions;
    merge?: boolean;
    config: string[];
    configName?: string[];
    disableInterpret?: boolean;
    extends?: string[];
    argv: Argv;
};
type Callback<T extends unknown[]> = (...args: T) => void;
/**
 * Webpack
 */
type WebpackConfiguration = Configuration;
type LoadableWebpackConfiguration = PotentialPromise<WebpackConfiguration | CallableWebpackConfiguration>;
type CallableWebpackConfiguration = (env: Env | undefined, argv: Argv) => WebpackConfiguration;
type WebpackCompiler = Compiler | MultiCompiler;
type FlagType = boolean | "enum" | "string" | "path" | "number" | "boolean" | "RegExp" | "reset";
type FlagConfig = {
    negatedDescription: string;
    type: FlagType;
    values: FlagType[];
};
type FileSystemCacheOptions = WebpackConfiguration & {
    cache: FileCacheOptions & {
        defaultConfig: string[];
    };
};
type ProcessedArguments = Record<string, (BasicPrimitive | RegExp)[]>;
type CommandAction = Parameters<WebpackCLICommand["action"]>[0];
interface WebpackRunOptions extends WebpackOptionsNormalized {
    progress?: boolean | "profile";
    json?: boolean;
    argv?: Argv;
    env: Env;
    failOnWarnings?: boolean;
    isWatchingLikeCommand?: boolean;
}
/**
 * Package management
 */
type PackageManager = "pnpm" | "yarn" | "npm";
interface PackageInstallOptions {
    preMessage?: () => void;
}
/**
 * Plugins and util types
 */
interface CLIPluginOptions {
    isMultiCompiler?: boolean;
    configPath?: string[];
    helpfulOutput: boolean;
    hot?: boolean | "only";
    progress?: boolean | "profile";
    prefetch?: string;
    analyze?: boolean;
}
type BasicPrimitive = string | boolean | number;
type Instantiable<InstanceType = unknown, ConstructorParameters extends unknown[] = unknown[]> = {
    new (...args: ConstructorParameters): InstanceType;
};
type PotentialPromise<T> = T | Promise<T>;
type ModuleName = string;
type Path = string;
type LogHandler = (value: any) => void;
type StringFormatter = (value: string) => string;
interface Argv extends Record<string, any> {
    env?: Env;
}
interface Env {
    WEBPACK_BUNDLE?: boolean;
    WEBPACK_BUILD?: boolean;
    WEBPACK_WATCH?: boolean;
    WEBPACK_SERVE?: boolean;
    WEBPACK_PACKAGE?: string;
    WEBPACK_DEV_SERVER_PACKAGE?: string;
}
type DynamicImport<T> = (url: string) => Promise<{
    default: T;
}>;
interface ImportLoaderError extends Error {
    code?: string;
}
/**
 * External libraries types
 */
type OptionConstructor = new (flags: string, description?: string) => Option;
type CommanderOption = InstanceType<OptionConstructor>;
interface Rechoir {
    prepare: typeof prepare;
}
interface JsonExt {
    stringifyChunked: typeof stringifyChunked;
}
interface RechoirError extends Error {
    failures: RechoirError[];
    error: Error;
}
interface PromptOptions {
    message: string;
    defaultResponse: string;
    stream: NodeJS.WritableStream;
}
export { IWebpackCLI, WebpackCLICommandOption, WebpackCLIBuiltInOption, WebpackCLIBuiltInFlag, WebpackCLIColors, WebpackCLIConfig, WebpackCLIExternalCommandInfo, WebpackCLIOptions, WebpackCLICommand, WebpackCLICommandOptions, WebpackCLIMainOption, WebpackCLILogger, WebpackDevServerOptions, WebpackRunOptions, WebpackCompiler, WebpackConfiguration, Argv, Argument, BasicPrimitive, CallableWebpackConfiguration, Callback, CLIPluginOptions, CommandAction, CommanderOption, CommandOptions, LoadableWebpackConfiguration, DynamicImport, FileSystemCacheOptions, FlagConfig, ImportLoaderError, Instantiable, JsonExt, ModuleName, PackageInstallOptions, PackageManager, Path, ProcessedArguments, PromptOptions, Problem, PotentialPromise, Rechoir, RechoirError, };