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