@rspack/cli 2.0.0-rc.3 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/162.js CHANGED
@@ -824,7 +824,7 @@ async function getPreviewConfig(item, options, dir) {
824
824
  publicPath: options.publicPath ?? '/'
825
825
  },
826
826
  hot: false,
827
- port: options.port ?? 8080,
827
+ port: options.port ?? devServer?.port ?? 8080,
828
828
  proxy: devServer?.proxy,
829
829
  host: options.host ?? devServer?.host,
830
830
  open: options.open ?? devServer?.open,
@@ -844,7 +844,7 @@ function normalizeHotOption(value) {
844
844
  class ServeCommand {
845
845
  async apply(cli) {
846
846
  const command = cli.program.command('serve', 'run the rspack dev server.').alias('server').alias('s').alias('dev');
847
- commonOptionsForBuildAndServe(commonOptions(command)).option('--hot [mode]', 'enables hot module replacement').option('--port <port>', 'allows to specify a port to use').option('--host <host>', 'allows to specify a hostname to use');
847
+ commonOptionsForBuildAndServe(commonOptions(command)).option('--hot [mode]', 'enables hot module replacement').option('--port <port>', 'allows to specify a port to use').option('--host <host>', 'allows to specify a hostname to use').option('--open [value]', 'open browser on server start; pass --no-open to disable, or --open <url> to open a specific URL');
848
848
  command.action(cli.wrapAction(async (cliOptions)=>{
849
849
  setDefaultNodeEnv(cliOptions, 'development');
850
850
  normalizeCommonOptions(cliOptions, 'serve');
@@ -910,6 +910,7 @@ class ServeCommand {
910
910
  devServerOptions.hot = cliOptions.hot ?? devServerOptions.hot ?? true;
911
911
  devServerOptions.host = cliOptions.host || devServerOptions.host;
912
912
  devServerOptions.port = cliOptions.port ?? devServerOptions.port;
913
+ if (void 0 !== cliOptions.open) devServerOptions.open = cliOptions.open;
913
914
  if (false !== devServerOptions.client) {
914
915
  if (true === devServerOptions.client || null == devServerOptions.client) devServerOptions.client = {};
915
916
  devServerOptions.client = {
@@ -1131,7 +1132,7 @@ class RspackCLI {
1131
1132
  this.colors = this.createColors();
1132
1133
  this.program = program;
1133
1134
  program.help();
1134
- program.version("2.0.0-rc.3");
1135
+ program.version("2.0.1");
1135
1136
  }
1136
1137
  wrapAction(fn) {
1137
1138
  return (...args)=>{
package/dist/index.d.ts CHANGED
@@ -1,2 +1,301 @@
1
- export { defineConfig, definePlugin, RspackCLI } from './cli';
2
- export * from './types';
1
+ import type { Compiler } from '@rspack/core';
2
+ import { Configuration } from '@rspack/core';
3
+ import type { MultiCompiler } from '@rspack/core';
4
+ import type { MultiRspackOptions } from '@rspack/core';
5
+ import type { MultiStats } from '@rspack/core';
6
+ import type { RspackOptions } from '@rspack/core';
7
+ import type { RspackPluginFunction } from '@rspack/core';
8
+ import type { RspackPluginInstance } from '@rspack/core';
9
+ import type { Stats } from '@rspack/core';
10
+
11
+ declare class CAC extends EventTarget {
12
+ /** The program name to display in help and version message */
13
+ name: string;
14
+ commands: Command[];
15
+ globalCommand: GlobalCommand;
16
+ matchedCommand?: Command;
17
+ matchedCommandName?: string;
18
+ /**
19
+ * Raw CLI arguments
20
+ */
21
+ rawArgs: string[];
22
+ /**
23
+ * Parsed CLI arguments
24
+ */
25
+ args: ParsedArgv["args"];
26
+ /**
27
+ * Parsed CLI options, camelCased
28
+ */
29
+ options: ParsedArgv["options"];
30
+ showHelpOnExit?: boolean;
31
+ showVersionOnExit?: boolean;
32
+ /**
33
+ * @param name The program name to display in help and version message
34
+ */
35
+ constructor(name?: string);
36
+ /**
37
+ * Add a global usage text.
38
+ *
39
+ * This is not used by sub-commands.
40
+ */
41
+ usage(text: string): this;
42
+ /**
43
+ * Add a sub-command
44
+ */
45
+ command(rawName: string, description?: string, config?: CommandConfig): Command;
46
+ /**
47
+ * Add a global CLI option.
48
+ *
49
+ * Which is also applied to sub-commands.
50
+ */
51
+ option(rawName: string, description: string, config?: OptionConfig): this;
52
+ /**
53
+ * Show help message when `-h, --help` flags appear.
54
+ *
55
+ */
56
+ help(callback?: HelpCallback): this;
57
+ /**
58
+ * Show version number when `-v, --version` flags appear.
59
+ *
60
+ */
61
+ version(version: string, customFlags?: string): this;
62
+ /**
63
+ * Add a global example.
64
+ *
65
+ * This example added here will not be used by sub-commands.
66
+ */
67
+ example(example: CommandExample): this;
68
+ /**
69
+ * Output the corresponding help message
70
+ * When a sub-command is matched, output the help message for the command
71
+ * Otherwise output the global one.
72
+ *
73
+ */
74
+ outputHelp(): void;
75
+ /**
76
+ * Output the version number.
77
+ *
78
+ */
79
+ outputVersion(): void;
80
+ private setParsedInfo;
81
+ unsetMatchedCommand(): void;
82
+ /**
83
+ * Parse argv
84
+ */
85
+ parse(argv?: string[], {
86
+ run
87
+ }?: {
88
+ /** Whether to run the action for matched command */run?: boolean | undefined;
89
+ }): ParsedArgv;
90
+ private mri;
91
+ runMatchedCommand(): any;
92
+ }
93
+
94
+ declare class Command {
95
+ rawName: string;
96
+ description: string;
97
+ config: CommandConfig;
98
+ cli: CAC;
99
+ options: Option_2[];
100
+ aliasNames: string[];
101
+ name: string;
102
+ args: CommandArg[];
103
+ commandAction?: (...args: any[]) => any;
104
+ usageText?: string;
105
+ versionNumber?: string;
106
+ examples: CommandExample[];
107
+ helpCallback?: HelpCallback;
108
+ globalCommand?: GlobalCommand;
109
+ constructor(rawName: string, description: string, config: CommandConfig | undefined, cli: CAC);
110
+ usage(text: string): this;
111
+ allowUnknownOptions(): this;
112
+ ignoreOptionDefaultValue(): this;
113
+ version(version: string, customFlags?: string): this;
114
+ example(example: CommandExample): this;
115
+ /**
116
+ * Add a option for this command
117
+ * @param rawName Raw option name(s)
118
+ * @param description Option description
119
+ * @param config Option config
120
+ */
121
+ option(rawName: string, description: string, config?: OptionConfig): this;
122
+ alias(name: string): this;
123
+ action(callback: (...args: any[]) => any): this;
124
+ /**
125
+ * Check if a command name is matched by this command
126
+ * @param name Command name
127
+ */
128
+ isMatched(name: string): boolean;
129
+ get isDefaultCommand(): boolean;
130
+ get isGlobalCommand(): boolean;
131
+ /**
132
+ * Check if an option is registered in this command
133
+ * @param name Option name
134
+ */
135
+ hasOption(name: string): Option_2 | undefined;
136
+ outputHelp(): void;
137
+ outputVersion(): void;
138
+ checkRequiredArgs(): void;
139
+ /**
140
+ * Check if the parsed options contain any unknown options
141
+ *
142
+ * Exit and output error when true
143
+ */
144
+ checkUnknownOptions(): void;
145
+ /**
146
+ * Check if the required string-type options exist
147
+ */
148
+ checkOptionValue(): void;
149
+ /**
150
+ * Check if the number of args is more than expected
151
+ */
152
+ checkUnusedArgs(): void;
153
+ }
154
+
155
+ declare type Command_2 = 'serve' | 'build';
156
+
157
+ declare interface CommandArg {
158
+ required: boolean;
159
+ value: string;
160
+ variadic: boolean;
161
+ }
162
+
163
+ declare interface CommandConfig {
164
+ allowUnknownOptions?: boolean;
165
+ ignoreOptionDefaultValue?: boolean;
166
+ }
167
+
168
+ declare type CommandExample = ((bin: string) => string) | string;
169
+
170
+ declare type CommonOptions = {
171
+ config?: string;
172
+ configName?: string[];
173
+ configLoader?: ConfigLoader;
174
+ env?: Record<string, unknown> | string[];
175
+ nodeEnv?: string;
176
+ };
177
+
178
+ declare type CommonOptionsForBuildAndServe = CommonOptions & {
179
+ devtool?: string | boolean;
180
+ entry?: string[];
181
+ mode?: string;
182
+ outputPath?: string;
183
+ watch?: boolean;
184
+ };
185
+
186
+ declare type ConfigLoader = 'auto' | 'jiti' | 'native';
187
+
188
+ export { Configuration }
189
+
190
+ /**
191
+ * This function helps you to autocomplete configuration types.
192
+ * It accepts a Rspack config object, or a function that returns a config.
193
+ */
194
+ export declare function defineConfig(config: RspackOptions): RspackOptions;
195
+
196
+ export declare function defineConfig(config: MultiRspackOptions): MultiRspackOptions;
197
+
198
+ export declare function defineConfig(config: RspackConfigFn): RspackConfigFn;
199
+
200
+ export declare function defineConfig(config: RspackConfigAsyncFn): RspackConfigAsyncFn;
201
+
202
+ export declare function defineConfig(config: RspackConfigExport): RspackConfigExport;
203
+
204
+ export declare function definePlugin(plugin: RspackPluginFunction): RspackPluginFunction;
205
+
206
+ export declare function definePlugin(plugin: RspackPluginInstance): RspackPluginInstance;
207
+
208
+ declare class GlobalCommand extends Command {
209
+ constructor(cli: CAC);
210
+ }
211
+
212
+ declare type HelpCallback = (sections: HelpSection[]) => void | HelpSection[];
213
+
214
+ declare interface HelpSection {
215
+ title?: string;
216
+ body: string;
217
+ }
218
+
219
+ export declare type LogHandler = (value: any) => void;
220
+
221
+ declare class Option_2 {
222
+ rawName: string;
223
+ description: string;
224
+ /** Option name */
225
+ name: string;
226
+ /** Option name and aliases */
227
+ names: string[];
228
+ isBoolean?: boolean;
229
+ required?: boolean;
230
+ config: OptionConfig;
231
+ negated: boolean;
232
+ constructor(rawName: string, description: string, config?: OptionConfig);
233
+ }
234
+
235
+ declare interface OptionConfig {
236
+ default?: any;
237
+ type?: any[];
238
+ }
239
+
240
+ declare interface ParsedArgv {
241
+ args: ReadonlyArray<string>;
242
+ options: {
243
+ [k: string]: any;
244
+ };
245
+ }
246
+
247
+ export declare class RspackCLI {
248
+ colors: RspackCLIColors;
249
+ program: CAC;
250
+ _actionPromise: Promise<void> | undefined;
251
+ constructor();
252
+ /**
253
+ * Wraps an async action handler so its promise is captured and can be
254
+ * awaited in `run()`. CAC's `parse()` does not await async actions,
255
+ * so without this wrapper, rejections become unhandled.
256
+ */
257
+ wrapAction<T extends (...args: any[]) => Promise<void>>(fn: T): T;
258
+ buildCompilerConfig(options: CommonOptionsForBuildAndServe, rspackCommand: Command_2): Promise<RspackOptions | MultiRspackOptions>;
259
+ createCompiler(config: RspackOptions | MultiRspackOptions, callback?: (e: Error | null, res?: Stats | MultiStats) => void): Promise<MultiCompiler | Compiler | null>;
260
+ private createColors;
261
+ getLogger(): RspackCLILogger;
262
+ run(argv: string[]): Promise<void>;
263
+ private registerCommands;
264
+ private buildConfig;
265
+ loadConfig(options: CommonOptions): Promise<{
266
+ config: RspackOptions | MultiRspackOptions;
267
+ pathMap: WeakMap<RspackOptions, string[]>;
268
+ }>;
269
+ private filterConfig;
270
+ isMultipleCompiler(compiler: Compiler | MultiCompiler): compiler is MultiCompiler;
271
+ isWatch(compiler: Compiler | MultiCompiler): boolean;
272
+ }
273
+
274
+ export declare interface RspackCLIColors {
275
+ isColorSupported: boolean;
276
+ red(text: string): string;
277
+ yellow(text: string): string;
278
+ cyan(text: string): string;
279
+ green(text: string): string;
280
+ }
281
+
282
+ export declare interface RspackCLILogger {
283
+ error: LogHandler;
284
+ warn: LogHandler;
285
+ info: LogHandler;
286
+ success: LogHandler;
287
+ log: LogHandler;
288
+ raw: LogHandler;
289
+ }
290
+
291
+ export declare interface RspackCommand {
292
+ apply(cli: RspackCLI): Promise<void>;
293
+ }
294
+
295
+ declare type RspackConfigAsyncFn = (env: Record<string, any>, argv: Record<string, any>) => Promise<RspackOptions | MultiRspackOptions>;
296
+
297
+ declare type RspackConfigExport = RspackOptions | MultiRspackOptions | RspackConfigFn | RspackConfigAsyncFn;
298
+
299
+ declare type RspackConfigFn = (env: Record<string, any>, argv: Record<string, any>) => RspackOptions | MultiRspackOptions;
300
+
301
+ export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/cli",
3
- "version": "2.0.0-rc.3",
3
+ "version": "2.0.1",
4
4
  "description": "CLI for rspack",
5
5
  "homepage": "https://rspack.rs",
6
6
  "bugs": "https://github.com/web-infra-dev/rspack/issues",
@@ -29,8 +29,9 @@
29
29
  ],
30
30
  "devDependencies": {
31
31
  "@discoveryjs/json-ext": "^0.5.7",
32
- "@rslib/core": "0.21.0",
33
- "@rspack/dev-server": "2.0.0-rc.2",
32
+ "@microsoft/api-extractor": "^7.58.7",
33
+ "@rslib/core": "0.21.3",
34
+ "@rspack/dev-server": "^2.0.1",
34
35
  "cac": "^7.0.0",
35
36
  "concat-stream": "^2.0.0",
36
37
  "cross-env": "^10.1.0",
@@ -38,9 +39,9 @@
38
39
  "exit-hook": "^4.0.0",
39
40
  "jiti": "^2.6.1",
40
41
  "prebundle": "^1.6.4",
41
- "typescript": "^6.0.2",
42
- "@rspack/test-tools": "2.0.0-rc.3",
43
- "@rspack/core": "2.0.0-rc.3"
42
+ "typescript": "^6.0.3",
43
+ "@rspack/core": "2.0.1",
44
+ "@rspack/test-tools": "2.0.1"
44
45
  },
45
46
  "peerDependencies": {
46
47
  "@rspack/core": "^2.0.0-0",
package/dist/cli.d.ts DELETED
@@ -1,49 +0,0 @@
1
- import type { Compiler, MultiCompiler, MultiRspackOptions, MultiStats, RspackOptions, RspackPluginFunction, RspackPluginInstance, Stats } from '@rspack/core';
2
- import { type CAC } from 'cac';
3
- import type { RspackCLIColors, RspackCLILogger } from './types';
4
- import type { CommonOptions, CommonOptionsForBuildAndServe } from './utils/options';
5
- type Command = 'serve' | 'build';
6
- declare global {
7
- const RSPACK_CLI_VERSION: string;
8
- }
9
- export declare class RspackCLI {
10
- colors: RspackCLIColors;
11
- program: CAC;
12
- _actionPromise: Promise<void> | undefined;
13
- constructor();
14
- /**
15
- * Wraps an async action handler so its promise is captured and can be
16
- * awaited in `run()`. CAC's `parse()` does not await async actions,
17
- * so without this wrapper, rejections become unhandled.
18
- */
19
- wrapAction<T extends (...args: any[]) => Promise<void>>(fn: T): T;
20
- buildCompilerConfig(options: CommonOptionsForBuildAndServe, rspackCommand: Command): Promise<RspackOptions | MultiRspackOptions>;
21
- createCompiler(config: RspackOptions | MultiRspackOptions, callback?: (e: Error | null, res?: Stats | MultiStats) => void): Promise<MultiCompiler | Compiler | null>;
22
- private createColors;
23
- getLogger(): RspackCLILogger;
24
- run(argv: string[]): Promise<void>;
25
- private registerCommands;
26
- private buildConfig;
27
- loadConfig(options: CommonOptions): Promise<{
28
- config: RspackOptions | MultiRspackOptions;
29
- pathMap: WeakMap<RspackOptions, string[]>;
30
- }>;
31
- private filterConfig;
32
- isMultipleCompiler(compiler: Compiler | MultiCompiler): compiler is MultiCompiler;
33
- isWatch(compiler: Compiler | MultiCompiler): boolean;
34
- }
35
- export type RspackConfigFn = (env: Record<string, any>, argv: Record<string, any>) => RspackOptions | MultiRspackOptions;
36
- export type RspackConfigAsyncFn = (env: Record<string, any>, argv: Record<string, any>) => Promise<RspackOptions | MultiRspackOptions>;
37
- export type RspackConfigExport = RspackOptions | MultiRspackOptions | RspackConfigFn | RspackConfigAsyncFn;
38
- /**
39
- * This function helps you to autocomplete configuration types.
40
- * It accepts a Rspack config object, or a function that returns a config.
41
- */
42
- export declare function defineConfig(config: RspackOptions): RspackOptions;
43
- export declare function defineConfig(config: MultiRspackOptions): MultiRspackOptions;
44
- export declare function defineConfig(config: RspackConfigFn): RspackConfigFn;
45
- export declare function defineConfig(config: RspackConfigAsyncFn): RspackConfigAsyncFn;
46
- export declare function defineConfig(config: RspackConfigExport): RspackConfigExport;
47
- export declare function definePlugin(plugin: RspackPluginFunction): RspackPluginFunction;
48
- export declare function definePlugin(plugin: RspackPluginInstance): RspackPluginInstance;
49
- export {};
@@ -1,5 +0,0 @@
1
- import type { RspackCLI } from '../cli';
2
- import type { RspackCommand } from '../types';
3
- export declare class BuildCommand implements RspackCommand {
4
- apply(cli: RspackCLI): Promise<void>;
5
- }
@@ -1,5 +0,0 @@
1
- import type { RspackCLI } from '../cli';
2
- import type { RspackCommand } from '../types';
3
- export declare class PreviewCommand implements RspackCommand {
4
- apply(cli: RspackCLI): Promise<void>;
5
- }
@@ -1,5 +0,0 @@
1
- import type { RspackCLI } from '../cli';
2
- import type { RspackCommand } from '../types';
3
- export declare class ServeCommand implements RspackCommand {
4
- apply(cli: RspackCLI): Promise<void>;
5
- }
@@ -1,3 +0,0 @@
1
- export declare const DEFAULT_CONFIG_NAME: "rspack.config";
2
- export declare const DEFAULT_EXTENSIONS: readonly [".ts", ".js", ".mts", ".mjs", ".cts", ".cjs"];
3
- export declare const DEFAULT_SERVER_HOT = true;
package/dist/types.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import type { RspackCLI } from './cli';
2
- export type { Configuration } from '@rspack/core';
3
- export type LogHandler = (value: any) => void;
4
- export interface RspackCLIColors {
5
- isColorSupported: boolean;
6
- red(text: string): string;
7
- yellow(text: string): string;
8
- cyan(text: string): string;
9
- green(text: string): string;
10
- }
11
- export interface RspackCLILogger {
12
- error: LogHandler;
13
- warn: LogHandler;
14
- info: LogHandler;
15
- success: LogHandler;
16
- log: LogHandler;
17
- raw: LogHandler;
18
- }
19
- export interface RspackCommand {
20
- apply(cli: RspackCLI): Promise<void>;
21
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * Takes a basePath like `webpack.config`, return `webpack.config.{ext}` if
3
- * exists. returns undefined if none of them exists
4
- */
5
- declare const findConfig: (basePath: string) => string | undefined;
6
- export default findConfig;
@@ -1,3 +0,0 @@
1
- export declare const TS_EXTENSION: string[];
2
- declare const isTsFile: (configPath: string) => boolean;
3
- export default isTsFile;
@@ -1,28 +0,0 @@
1
- import type { MultiRspackOptions, RspackOptions } from '@rspack/core';
2
- import type { CommonOptions } from './options';
3
- export type LoadedRspackConfig = undefined | RspackOptions | MultiRspackOptions | ((env: Record<string, any>, argv?: Record<string, any>) => RspackOptions | MultiRspackOptions | Promise<RspackOptions | MultiRspackOptions>);
4
- export declare const resolveRspackConfigExport: (configExport: LoadedRspackConfig, options: CommonOptions) => Promise<RspackOptions | MultiRspackOptions>;
5
- /**
6
- * Loads and merges configurations from the 'extends' property
7
- * @param config The configuration object that may contain an 'extends' property
8
- * @param configPath The path to the configuration file
9
- * @param cwd The current working directory
10
- * @param options CLI options
11
- * @returns The merged configuration
12
- */
13
- export declare function loadExtendedConfig(config: RspackOptions, configPath: string, cwd: string, options: CommonOptions): Promise<{
14
- config: RspackOptions;
15
- pathMap: WeakMap<RspackOptions, string[]>;
16
- }>;
17
- export declare function loadExtendedConfig(config: MultiRspackOptions, configPath: string, cwd: string, options: CommonOptions): Promise<{
18
- config: MultiRspackOptions;
19
- pathMap: WeakMap<RspackOptions, string[]>;
20
- }>;
21
- export declare function loadExtendedConfig(config: RspackOptions | MultiRspackOptions, configPath: string, cwd: string, options: CommonOptions): Promise<{
22
- config: RspackOptions | MultiRspackOptions;
23
- pathMap: WeakMap<RspackOptions, string[]>;
24
- }>;
25
- export declare function loadRspackConfig(options: CommonOptions, cwd?: string): Promise<{
26
- loadedConfig: LoadedRspackConfig;
27
- configPath: string;
28
- } | null>;
@@ -1,28 +0,0 @@
1
- import type { Command } from 'cac';
2
- export type ConfigLoader = 'auto' | 'jiti' | 'native';
3
- /**
4
- * Apply common options for all commands
5
- */
6
- export declare const commonOptions: (command: Command) => Command;
7
- export type CommonOptions = {
8
- config?: string;
9
- configName?: string[];
10
- configLoader?: ConfigLoader;
11
- env?: Record<string, unknown> | string[];
12
- nodeEnv?: string;
13
- };
14
- export declare const normalizeCommonOptions: (options: CommonOptions | CommonOptionsForBuildAndServe, action: "serve" | "build" | "preview") => void;
15
- /**
16
- * Apply common options for `build` and `serve` commands
17
- */
18
- export declare const commonOptionsForBuildAndServe: (command: Command) => Command;
19
- export type CommonOptionsForBuildAndServe = CommonOptions & {
20
- devtool?: string | boolean;
21
- entry?: string[];
22
- mode?: string;
23
- outputPath?: string;
24
- watch?: boolean;
25
- };
26
- export declare function setDefaultNodeEnv(options: {
27
- nodeEnv?: unknown;
28
- }, defaultEnv: string): void;
@@ -1 +0,0 @@
1
- export declare function applyProfile(filterValue: string, traceLayer?: string, traceOutput?: string): Promise<void>;