@rspack/cli 2.0.0-canary.20260120 → 2.0.0-rc.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.
@@ -1,80 +1,105 @@
1
- import * as __rspack_external_module from "module";
2
- import * as __rspack_external_path from "path";
3
- import { __webpack_require__ } from "./rslib-runtime.js";
4
1
  import node_path from "node:path";
5
2
  import node_util from "node:util";
6
3
  import { rspack } from "@rspack/core";
7
- import { EventEmitter } from "events";
8
4
  import node_fs from "node:fs";
9
5
  import { createRequire } from "node:module";
10
6
  import { pathToFileURL } from "node:url";
7
+ import { createRequire as __rspack_createRequire } from "node:module";
8
+ const __rspack_createRequire_require = __rspack_createRequire(import.meta.url);
9
+ var __webpack_modules__ = {};
10
+ var __webpack_module_cache__ = {};
11
+ function __webpack_require__(moduleId) {
12
+ var cachedModule = __webpack_module_cache__[moduleId];
13
+ if (void 0 !== cachedModule) return cachedModule.exports;
14
+ var module = __webpack_module_cache__[moduleId] = {
15
+ exports: {}
16
+ };
17
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
18
+ return module.exports;
19
+ }
20
+ __webpack_require__.m = __webpack_modules__;
21
+ (()=>{
22
+ var getProto = Object.getPrototypeOf ? (obj)=>Object.getPrototypeOf(obj) : (obj)=>obj.__proto__;
23
+ var leafPrototypes;
24
+ __webpack_require__.t = function(value, mode) {
25
+ if (1 & mode) value = this(value);
26
+ if (8 & mode) return value;
27
+ if ('object' == typeof value && value) {
28
+ if (4 & mode && value.__esModule) return value;
29
+ if (16 & mode && 'function' == typeof value.then) return value;
30
+ }
31
+ var ns = Object.create(null);
32
+ __webpack_require__.r(ns);
33
+ var def = {};
34
+ leafPrototypes = leafPrototypes || [
35
+ null,
36
+ getProto({}),
37
+ getProto([]),
38
+ getProto(getProto)
39
+ ];
40
+ for(var current = 2 & mode && value; ('object' == typeof current || 'function' == typeof current) && !~leafPrototypes.indexOf(current); current = getProto(current))Object.getOwnPropertyNames(current).forEach((key)=>{
41
+ def[key] = ()=>value[key];
42
+ });
43
+ def['default'] = ()=>value;
44
+ __webpack_require__.d(ns, def);
45
+ return ns;
46
+ };
47
+ })();
48
+ (()=>{
49
+ __webpack_require__.d = (exports, definition)=>{
50
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
51
+ enumerable: true,
52
+ get: definition[key]
53
+ });
54
+ };
55
+ })();
56
+ (()=>{
57
+ __webpack_require__.add = function(modules) {
58
+ Object.assign(__webpack_require__.m, modules);
59
+ };
60
+ })();
61
+ var __webpack_require__temp = __webpack_require__;
62
+ (()=>{
63
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
64
+ })();
65
+ (()=>{
66
+ __webpack_require__.r = (exports)=>{
67
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports, Symbol.toStringTag, {
68
+ value: 'Module'
69
+ });
70
+ Object.defineProperty(exports, '__esModule', {
71
+ value: true
72
+ });
73
+ };
74
+ })();
75
+ (()=>{
76
+ __webpack_require__.nmd = (module)=>{
77
+ module.paths = [];
78
+ if (!module.children) module.children = [];
79
+ return module;
80
+ };
81
+ })();
82
+ (()=>{
83
+ var installedChunks = {
84
+ 410: 0,
85
+ 697: 0
86
+ };
87
+ var installChunk = (data)=>{
88
+ var __rspack_esm_ids = data.__rspack_esm_ids;
89
+ var __webpack_modules__ = data.__webpack_modules__;
90
+ var __rspack_esm_runtime = data.__rspack_esm_runtime;
91
+ var moduleId, chunkId, i = 0;
92
+ for(moduleId in __webpack_modules__)if (__webpack_require__.o(__webpack_modules__, moduleId)) __webpack_require__.m[moduleId] = __webpack_modules__[moduleId];
93
+ if (__rspack_esm_runtime) __rspack_esm_runtime(__webpack_require__);
94
+ for(; i < __rspack_esm_ids.length; i++){
95
+ chunkId = __rspack_esm_ids[i];
96
+ if (__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) installedChunks[chunkId][0]();
97
+ installedChunks[__rspack_esm_ids[i]] = 0;
98
+ }
99
+ };
100
+ __webpack_require__.C = installChunk;
101
+ })();
11
102
  __webpack_require__.add({
12
- "../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js" (module) {
13
- let p = process || {}, argv = p.argv || [], env = p.env || {};
14
- let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || "win32" === p.platform || (p.stdout || {}).isTTY && "dumb" !== env.TERM || !!env.CI);
15
- let formatter = (open, close, replace = open)=>(input)=>{
16
- let string = "" + input, index = string.indexOf(close, open.length);
17
- return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
18
- };
19
- let replaceClose = (string, close, replace, index)=>{
20
- let result = "", cursor = 0;
21
- do {
22
- result += string.substring(cursor, index) + replace;
23
- cursor = index + close.length;
24
- index = string.indexOf(close, cursor);
25
- }while (~index);
26
- return result + string.substring(cursor);
27
- };
28
- let createColors = (enabled = isColorSupported)=>{
29
- let f = enabled ? formatter : ()=>String;
30
- return {
31
- isColorSupported: enabled,
32
- reset: f("\x1b[0m", "\x1b[0m"),
33
- bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
34
- dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
35
- italic: f("\x1b[3m", "\x1b[23m"),
36
- underline: f("\x1b[4m", "\x1b[24m"),
37
- inverse: f("\x1b[7m", "\x1b[27m"),
38
- hidden: f("\x1b[8m", "\x1b[28m"),
39
- strikethrough: f("\x1b[9m", "\x1b[29m"),
40
- black: f("\x1b[30m", "\x1b[39m"),
41
- red: f("\x1b[31m", "\x1b[39m"),
42
- green: f("\x1b[32m", "\x1b[39m"),
43
- yellow: f("\x1b[33m", "\x1b[39m"),
44
- blue: f("\x1b[34m", "\x1b[39m"),
45
- magenta: f("\x1b[35m", "\x1b[39m"),
46
- cyan: f("\x1b[36m", "\x1b[39m"),
47
- white: f("\x1b[37m", "\x1b[39m"),
48
- gray: f("\x1b[90m", "\x1b[39m"),
49
- bgBlack: f("\x1b[40m", "\x1b[49m"),
50
- bgRed: f("\x1b[41m", "\x1b[49m"),
51
- bgGreen: f("\x1b[42m", "\x1b[49m"),
52
- bgYellow: f("\x1b[43m", "\x1b[49m"),
53
- bgBlue: f("\x1b[44m", "\x1b[49m"),
54
- bgMagenta: f("\x1b[45m", "\x1b[49m"),
55
- bgCyan: f("\x1b[46m", "\x1b[49m"),
56
- bgWhite: f("\x1b[47m", "\x1b[49m"),
57
- blackBright: f("\x1b[90m", "\x1b[39m"),
58
- redBright: f("\x1b[91m", "\x1b[39m"),
59
- greenBright: f("\x1b[92m", "\x1b[39m"),
60
- yellowBright: f("\x1b[93m", "\x1b[39m"),
61
- blueBright: f("\x1b[94m", "\x1b[39m"),
62
- magentaBright: f("\x1b[95m", "\x1b[39m"),
63
- cyanBright: f("\x1b[96m", "\x1b[39m"),
64
- whiteBright: f("\x1b[97m", "\x1b[39m"),
65
- bgBlackBright: f("\x1b[100m", "\x1b[49m"),
66
- bgRedBright: f("\x1b[101m", "\x1b[49m"),
67
- bgGreenBright: f("\x1b[102m", "\x1b[49m"),
68
- bgYellowBright: f("\x1b[103m", "\x1b[49m"),
69
- bgBlueBright: f("\x1b[104m", "\x1b[49m"),
70
- bgMagentaBright: f("\x1b[105m", "\x1b[49m"),
71
- bgCyanBright: f("\x1b[106m", "\x1b[49m"),
72
- bgWhiteBright: f("\x1b[107m", "\x1b[49m")
73
- };
74
- };
75
- module.exports = createColors();
76
- module.exports.createColors = createColors;
77
- },
78
103
  "../../node_modules/.pnpm/pirates@4.0.7/node_modules/pirates/lib/index.js" (module, exports, __webpack_require__) {
79
104
  module = __webpack_require__.nmd(module);
80
105
  const BuiltinModule = __webpack_require__("module");
@@ -136,10 +161,16 @@ __webpack_require__.add({
136
161
  exports.addHook = addHook;
137
162
  },
138
163
  module (module) {
139
- module.exports = __rspack_external_module;
164
+ module.exports = __rspack_createRequire_require("module");
140
165
  },
141
166
  path (module) {
142
- module.exports = __rspack_external_path;
167
+ module.exports = __rspack_createRequire_require("path");
168
+ },
169
+ stream (module) {
170
+ module.exports = __rspack_createRequire_require("stream");
171
+ },
172
+ util (module) {
173
+ module.exports = __rspack_createRequire_require("util");
143
174
  }
144
175
  });
145
176
  function toArr(any) {
@@ -148,13 +179,13 @@ function toArr(any) {
148
179
  ];
149
180
  }
150
181
  function toVal(out, key, val, opts) {
151
- var x, old = out[key], nxt = ~opts.string.indexOf(key) ? null == val || true === val ? '' : String(val) : 'boolean' == typeof val ? val : ~opts.boolean.indexOf(key) ? 'false' === val ? false : 'true' === val || (out._.push((x = +val, 0 * x === 0) ? x : val), !!val) : (x = +val, 0 * x === 0) ? x : val;
182
+ var x, old = out[key], nxt = ~opts.string.indexOf(key) ? null == val || true === val ? "" : String(val) : "boolean" == typeof val ? val : ~opts.boolean.indexOf(key) ? "false" === val ? false : "true" === val || (out._.push((x = +val, 0 * x === 0) ? x : val), !!val) : (x = +val, 0 * x === 0) ? x : val;
152
183
  out[key] = null == old ? nxt : Array.isArray(old) ? old.concat(nxt) : [
153
184
  old,
154
185
  nxt
155
186
  ];
156
187
  }
157
- function mri2(args, opts) {
188
+ function lib_default(args, opts) {
158
189
  args = args || [];
159
190
  opts = opts || {};
160
191
  var k, arr, arg, name, val, out = {
@@ -190,26 +221,26 @@ function mri2(args, opts) {
190
221
  const keys = strict ? Object.keys(opts.alias) : [];
191
222
  for(i = 0; i < len; i++){
192
223
  arg = args[i];
193
- if ('--' === arg) {
224
+ if ("--" === arg) {
194
225
  out._ = out._.concat(args.slice(++i));
195
226
  break;
196
227
  }
197
228
  for(j = 0; j < arg.length && 45 === arg.charCodeAt(j); j++);
198
229
  if (0 === j) out._.push(arg);
199
- else if ('no-' === arg.substring(j, j + 3)) {
230
+ else if ("no-" === arg.substring(j, j + 3)) {
200
231
  name = arg.substring(j + 3);
201
232
  if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
202
233
  out[name] = false;
203
234
  } else {
204
235
  for(idx = j + 1; idx < arg.length && 61 !== arg.charCodeAt(idx); idx++);
205
236
  name = arg.substring(j, idx);
206
- val = arg.substring(++idx) || i + 1 === len || 45 === ('' + args[i + 1]).charCodeAt(0) || args[++i];
237
+ val = arg.substring(++idx) || i + 1 === len || 45 === ("" + args[i + 1]).charCodeAt(0) || args[++i];
207
238
  arr = 2 === j ? [
208
239
  name
209
240
  ] : name;
210
241
  for(idx = 0; idx < arr.length; idx++){
211
242
  name = arr[idx];
212
- if (strict && !~keys.indexOf(name)) return opts.unknown('-'.repeat(j) + name);
243
+ if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
213
244
  toVal(out, name, idx + 1 < arr.length || val, opts);
214
245
  }
215
246
  }
@@ -223,8 +254,10 @@ function mri2(args, opts) {
223
254
  }
224
255
  return out;
225
256
  }
226
- const removeBrackets = (v)=>v.replace(/[<[].+/, "").trim();
227
- const findAllBrackets = (v)=>{
257
+ function removeBrackets(v) {
258
+ return v.replace(/[<[].+/, "").trim();
259
+ }
260
+ function findAllBrackets(v) {
228
261
  const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
229
262
  const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
230
263
  const res = [];
@@ -246,8 +279,8 @@ const findAllBrackets = (v)=>{
246
279
  let squareMatch;
247
280
  while(squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v))res.push(parse(squareMatch));
248
281
  return res;
249
- };
250
- const getMriOptions = (options)=>{
282
+ }
283
+ function getMriOptions(options) {
251
284
  const result = {
252
285
  alias: {},
253
286
  boolean: []
@@ -255,53 +288,74 @@ const getMriOptions = (options)=>{
255
288
  for (const [index, option] of options.entries()){
256
289
  if (option.names.length > 1) result.alias[option.names[0]] = option.names.slice(1);
257
290
  if (option.isBoolean) if (option.negated) {
258
- const hasStringTypeOption = options.some((o, i)=>i !== index && o.names.some((name)=>option.names.includes(name)) && "boolean" == typeof o.required);
259
- if (!hasStringTypeOption) result.boolean.push(option.names[0]);
291
+ if (!options.some((o, i)=>i !== index && o.names.some((name)=>option.names.includes(name)) && "boolean" == typeof o.required)) result.boolean.push(option.names[0]);
260
292
  } else result.boolean.push(option.names[0]);
261
293
  }
262
294
  return result;
263
- };
264
- const findLongest = (arr)=>arr.sort((a, b)=>a.length > b.length ? -1 : 1)[0];
265
- const padRight = (str, length)=>str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
266
- const camelcase = (input)=>input.replace(/([a-z])-([a-z])/g, (_, p1, p2)=>p1 + p2.toUpperCase());
267
- const setDotProp = (obj, keys, val)=>{
268
- let i = 0;
269
- let length = keys.length;
270
- let t = obj;
271
- let x;
272
- for(; i < length; ++i){
273
- x = t[keys[i]];
274
- t = t[keys[i]] = i === length - 1 ? val : null != x ? x : !~keys[i + 1].indexOf(".") && +keys[i + 1] > -1 ? [] : {};
295
+ }
296
+ function findLongest(arr) {
297
+ return arr.sort((a, b)=>a.length > b.length ? -1 : 1)[0];
298
+ }
299
+ function padRight(str, length) {
300
+ return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
301
+ }
302
+ function camelcase(input) {
303
+ return input.replaceAll(/([a-z])-([a-z])/g, (_, p1, p2)=>p1 + p2.toUpperCase());
304
+ }
305
+ function setDotProp(obj, keys, val) {
306
+ let current = obj;
307
+ for(let i = 0; i < keys.length; i++){
308
+ const key = keys[i];
309
+ if (i === keys.length - 1) {
310
+ current[key] = val;
311
+ return;
312
+ }
313
+ if (null == current[key]) {
314
+ const nextKeyIsArrayIndex = +keys[i + 1] > -1;
315
+ current[key] = nextKeyIsArrayIndex ? [] : {};
316
+ }
317
+ current = current[key];
275
318
  }
276
- };
277
- const setByType = (obj, transforms)=>{
319
+ }
320
+ function setByType(obj, transforms) {
278
321
  for (const key of Object.keys(transforms)){
279
322
  const transform = transforms[key];
280
323
  if (transform.shouldTransform) {
281
- obj[key] = Array.prototype.concat.call([], obj[key]);
324
+ obj[key] = [
325
+ obj[key]
326
+ ].flat();
282
327
  if ("function" == typeof transform.transformFunction) obj[key] = obj[key].map(transform.transformFunction);
283
328
  }
284
329
  }
285
- };
286
- const getFileName = (input)=>{
287
- const m = /([^\\\/]+)$/.exec(input);
330
+ }
331
+ function getFileName(input) {
332
+ const m = /([^\\/]+)$/.exec(input);
288
333
  return m ? m[1] : "";
289
- };
290
- const camelcaseOptionName = (name)=>name.split(".").map((v, i)=>0 === i ? camelcase(v) : v).join(".");
291
- class CACError extends Error {
334
+ }
335
+ function camelcaseOptionName(name) {
336
+ return name.split(".").map((v, i)=>0 === i ? camelcase(v) : v).join(".");
337
+ }
338
+ var CACError = class extends Error {
292
339
  constructor(message){
293
340
  super(message);
294
- this.name = this.constructor.name;
295
- if ("function" == typeof Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
296
- else this.stack = new Error(message).stack;
341
+ this.name = "CACError";
342
+ if ("function" != typeof Error.captureStackTrace) this.stack = new Error(message).stack;
297
343
  }
298
- }
299
- class Option {
344
+ };
345
+ var Option = class {
346
+ rawName;
347
+ description;
348
+ name;
349
+ names;
350
+ isBoolean;
351
+ required;
352
+ config;
353
+ negated;
300
354
  constructor(rawName, description, config){
301
355
  this.rawName = rawName;
302
356
  this.description = description;
303
357
  this.config = Object.assign({}, config);
304
- rawName = rawName.replace(/\.\*/g, "");
358
+ rawName = rawName.replaceAll(".*", "");
305
359
  this.negated = false;
306
360
  this.names = removeBrackets(rawName).split(",").map((v)=>{
307
361
  let name = v.trim().replace(/^-{1,2}/, "");
@@ -311,16 +365,36 @@ class Option {
311
365
  }
312
366
  return camelcaseOptionName(name);
313
367
  }).sort((a, b)=>a.length > b.length ? 1 : -1);
314
- this.name = this.names[this.names.length - 1];
368
+ this.name = this.names.at(-1);
315
369
  if (this.negated && null == this.config.default) this.config.default = true;
316
370
  if (rawName.includes("<")) this.required = true;
317
371
  else if (rawName.includes("[")) this.required = false;
318
372
  else this.isBoolean = true;
319
373
  }
320
- }
321
- const processArgs = process.argv;
322
- const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
323
- class Command {
374
+ };
375
+ let runtimeProcessArgs;
376
+ let runtimeInfo;
377
+ if ("u" > typeof process) {
378
+ let runtimeName;
379
+ runtimeName = "u" > typeof Deno && "string" == typeof Deno.version?.deno ? "deno" : "u" > typeof Bun && "string" == typeof Bun.version ? "bun" : "node";
380
+ runtimeInfo = `${process.platform}-${process.arch} ${runtimeName}-${process.version}`;
381
+ runtimeProcessArgs = process.argv;
382
+ } else runtimeInfo = "u" < typeof navigator ? "unknown" : `${navigator.platform} ${navigator.userAgent}`;
383
+ var Command = class {
384
+ rawName;
385
+ description;
386
+ config;
387
+ cli;
388
+ options;
389
+ aliasNames;
390
+ name;
391
+ args;
392
+ commandAction;
393
+ usageText;
394
+ versionNumber;
395
+ examples;
396
+ helpCallback;
397
+ globalCommand;
324
398
  constructor(rawName, description, config = {}, cli){
325
399
  this.rawName = rawName;
326
400
  this.description = description;
@@ -391,14 +465,12 @@ class Command {
391
465
  title: "Usage",
392
466
  body: ` $ ${name} ${this.usageText || this.rawName}`
393
467
  });
394
- const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
395
- if (showCommands) {
468
+ if ((this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0) {
396
469
  const longestCommandName = findLongest(commands.map((command)=>command.rawName));
397
470
  sections.push({
398
471
  title: "Commands",
399
472
  body: commands.map((command)=>` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`).join("\n")
400
- });
401
- sections.push({
473
+ }, {
402
474
  title: "For more info, run any command with the `--help` flag",
403
475
  body: commands.map((command)=>` $ ${name}${"" === command.name ? "" : ` ${command.name}`} --help`).join("\n")
404
476
  });
@@ -423,13 +495,12 @@ class Command {
423
495
  }).join("\n")
424
496
  });
425
497
  if (helpCallback) sections = helpCallback(sections) || sections;
426
- console.log(sections.map((section)=>section.title ? `${section.title}:
427
- ${section.body}` : section.body).join("\n\n"));
498
+ console.info(sections.map((section)=>section.title ? `${section.title}:\n${section.body}` : section.body).join("\n\n"));
428
499
  }
429
500
  outputVersion() {
430
501
  const { name } = this.cli;
431
502
  const { versionNumber } = this.cli.globalCommand;
432
- if (versionNumber) console.log(`${name}/${versionNumber} ${platformInfo}`);
503
+ if (versionNumber) console.info(`${name}/${versionNumber} ${runtimeInfo}`);
433
504
  }
434
505
  checkRequiredArgs() {
435
506
  const minimalArgsCount = this.args.filter((arg)=>arg.required).length;
@@ -455,14 +526,27 @@ ${section.body}` : section.body).join("\n\n"));
455
526
  }
456
527
  }
457
528
  }
458
- }
459
- class GlobalCommand extends Command {
529
+ checkUnusedArgs() {
530
+ const maximumArgsCount = this.args.some((arg)=>arg.variadic) ? 1 / 0 : this.args.length;
531
+ if (maximumArgsCount < this.cli.args.length) throw new CACError(`Unused args: ${this.cli.args.slice(maximumArgsCount).map((arg)=>`\`${arg}\``).join(", ")}`);
532
+ }
533
+ };
534
+ var GlobalCommand = class extends Command {
460
535
  constructor(cli){
461
536
  super("@@global@@", "", {}, cli);
462
537
  }
463
- }
464
- var __assign = Object.assign;
465
- class CAC extends EventEmitter {
538
+ };
539
+ var CAC = class extends EventTarget {
540
+ name;
541
+ commands;
542
+ globalCommand;
543
+ matchedCommand;
544
+ matchedCommandName;
545
+ rawArgs;
546
+ args;
547
+ options;
548
+ showHelpOnExit;
549
+ showVersionOnExit;
466
550
  constructor(name = ""){
467
551
  super();
468
552
  this.name = name;
@@ -520,7 +604,11 @@ class CAC extends EventEmitter {
520
604
  this.matchedCommand = void 0;
521
605
  this.matchedCommandName = void 0;
522
606
  }
523
- parse(argv = processArgs, { run = true } = {}) {
607
+ parse(argv, { run = true } = {}) {
608
+ if (!argv) {
609
+ if (!runtimeProcessArgs) throw new Error("No argv provided and runtime process argv is not available.");
610
+ argv = runtimeProcessArgs;
611
+ }
524
612
  this.rawArgs = argv;
525
613
  if (!this.name) this.name = argv[1] ? getFileName(argv[1]) : "cli";
526
614
  let shouldParse = true;
@@ -529,19 +617,24 @@ class CAC extends EventEmitter {
529
617
  const commandName = parsed.args[0];
530
618
  if (command.isMatched(commandName)) {
531
619
  shouldParse = false;
532
- const parsedInfo = __assign(__assign({}, parsed), {
620
+ const parsedInfo = {
621
+ ...parsed,
533
622
  args: parsed.args.slice(1)
534
- });
623
+ };
535
624
  this.setParsedInfo(parsedInfo, command, commandName);
536
- this.emit(`command:${commandName}`, command);
625
+ this.dispatchEvent(new CustomEvent(`command:${commandName}`, {
626
+ detail: command
627
+ }));
537
628
  }
538
629
  }
539
630
  if (shouldParse) {
540
- for (const command of this.commands)if ("" === command.name) {
631
+ for (const command of this.commands)if (command.isDefaultCommand) {
541
632
  shouldParse = false;
542
633
  const parsed = this.mri(argv.slice(2), command);
543
634
  this.setParsedInfo(parsed, command);
544
- this.emit("command:!", command);
635
+ this.dispatchEvent(new CustomEvent("command:!", {
636
+ detail: command
637
+ }));
545
638
  }
546
639
  }
547
640
  if (shouldParse) {
@@ -563,7 +656,9 @@ class CAC extends EventEmitter {
563
656
  options: this.options
564
657
  };
565
658
  if (run) this.runMatchedCommand();
566
- if (!this.matchedCommand && this.args[0]) this.emit("command:*");
659
+ if (!this.matchedCommand && this.args[0]) this.dispatchEvent(new CustomEvent("command:*", {
660
+ detail: this.args[0]
661
+ }));
567
662
  return parsedArgv;
568
663
  }
569
664
  mri(argv, command) {
@@ -574,12 +669,13 @@ class CAC extends EventEmitter {
574
669
  const mriOptions = getMriOptions(cliOptions);
575
670
  let argsAfterDoubleDashes = [];
576
671
  const doubleDashesIndex = argv.indexOf("--");
577
- if (doubleDashesIndex > -1) {
672
+ if (-1 !== doubleDashesIndex) {
578
673
  argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
579
674
  argv = argv.slice(0, doubleDashesIndex);
580
675
  }
581
- let parsed = mri2(argv, mriOptions);
582
- parsed = Object.keys(parsed).reduce((res, name)=>__assign(__assign({}, res), {
676
+ let parsed = lib_default(argv, mriOptions);
677
+ parsed = Object.keys(parsed).reduce((res, name)=>({
678
+ ...res,
583
679
  [camelcaseOptionName(name)]: parsed[name]
584
680
  }), {
585
681
  _: []
@@ -589,20 +685,17 @@ class CAC extends EventEmitter {
589
685
  "--": argsAfterDoubleDashes
590
686
  };
591
687
  const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
592
- let transforms = Object.create(null);
688
+ const transforms = Object.create(null);
593
689
  for (const cliOption of cliOptions){
594
690
  if (!ignoreDefault && void 0 !== cliOption.config.default) for (const name of cliOption.names)options[name] = cliOption.config.default;
595
- if (Array.isArray(cliOption.config.type)) {
596
- if (void 0 === transforms[cliOption.name]) {
597
- transforms[cliOption.name] = Object.create(null);
598
- transforms[cliOption.name]["shouldTransform"] = true;
599
- transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
600
- }
691
+ if (Array.isArray(cliOption.config.type) && void 0 === transforms[cliOption.name]) {
692
+ transforms[cliOption.name] = Object.create(null);
693
+ transforms[cliOption.name].shouldTransform = true;
694
+ transforms[cliOption.name].transformFunction = cliOption.config.type[0];
601
695
  }
602
696
  }
603
697
  for (const key of Object.keys(parsed))if ("_" !== key) {
604
- const keys = key.split(".");
605
- setDotProp(options, keys, parsed[key]);
698
+ setDotProp(options, key.split("."), parsed[key]);
606
699
  setByType(options, transforms);
607
700
  }
608
701
  return {
@@ -616,6 +709,7 @@ class CAC extends EventEmitter {
616
709
  command.checkUnknownOptions();
617
710
  command.checkOptionValue();
618
711
  command.checkRequiredArgs();
712
+ command.checkUnusedArgs();
619
713
  const actionArgs = [];
620
714
  command.args.forEach((arg, index)=>{
621
715
  if (arg.variadic) actionArgs.push(args.slice(index));
@@ -624,9 +718,8 @@ class CAC extends EventEmitter {
624
718
  actionArgs.push(options);
625
719
  return command.commandAction.apply(this, actionArgs);
626
720
  }
627
- }
721
+ };
628
722
  const cac = (name = "")=>new CAC(name);
629
- const dist = cac;
630
723
  const commonOptions = (command)=>command.option('-c, --config <path>', 'config file').option('--config-name <name>', 'Name(s) of the configuration to use.', {
631
724
  type: [
632
725
  String
@@ -708,7 +801,7 @@ async function runBuild(cli, options) {
708
801
  const logger = cli.getLogger();
709
802
  let createJsonStringifyStream;
710
803
  if (options.json) {
711
- const jsonExt = await import("@discoveryjs/json-ext");
804
+ const jsonExt = await import("./json-ext.js").then(__webpack_require__.t.bind(__webpack_require__, "../../node_modules/.pnpm/@discoveryjs+json-ext@0.5.7/node_modules/@discoveryjs/json-ext/src/index.js", 23));
712
805
  createJsonStringifyStream = jsonExt.default.stringifyStream;
713
806
  }
714
807
  const errorHandler = (error, stats)=>{
@@ -753,16 +846,16 @@ class BuildCommand {
753
846
  async apply(cli) {
754
847
  const command = cli.program.command('', 'run the Rspack build').alias('build').alias('bundle').alias('b');
755
848
  commonOptionsForBuildAndServe(commonOptions(command)).option('--json [path]', 'emit stats json');
756
- command.action(async (options)=>{
849
+ command.action(cli.wrapAction(async (options)=>{
757
850
  await runBuild(cli, options);
758
- });
851
+ }));
759
852
  }
760
853
  }
761
854
  class PreviewCommand {
762
855
  async apply(cli) {
763
856
  const command = cli.program.command('preview [dir]', 'run the Rspack server for build output').alias('p');
764
857
  commonOptions(command).option('--public-path <path>', 'static resource server path').option('--port <port>', 'preview server port').option('--host <host>', 'preview server host').option('--open', 'open browser').option('--server <config>', 'Configuration items for the server.');
765
- command.action(async (dir, options)=>{
858
+ command.action(cli.wrapAction(async (dir, options)=>{
766
859
  setDefaultNodeEnv(options, 'production');
767
860
  normalizeCommonOptions(options, 'preview');
768
861
  let RspackDevServer;
@@ -794,23 +887,24 @@ class PreviewCommand {
794
887
  logger.error(error);
795
888
  process.exit(2);
796
889
  }
797
- });
890
+ }));
798
891
  }
799
892
  }
800
893
  async function getPreviewConfig(item, options, dir) {
801
894
  const DEFAULT_ROOT = 'dist';
802
895
  const internalPreviewConfig = async (item)=>{
896
+ const devServer = false === item.devServer ? void 0 : item.devServer;
803
897
  item.devServer = {
804
898
  static: {
805
899
  directory: dir ? node_path.join(item.context ?? process.cwd(), dir) : item.output?.path ?? node_path.join(item.context ?? process.cwd(), DEFAULT_ROOT),
806
900
  publicPath: options.publicPath ?? '/'
807
901
  },
808
902
  port: options.port ?? 8080,
809
- proxy: item.devServer?.proxy,
810
- host: options.host ?? item.devServer?.host,
811
- open: options.open ?? item.devServer?.open,
812
- server: options.server ?? item.devServer?.server,
813
- historyApiFallback: item.devServer?.historyApiFallback
903
+ proxy: devServer?.proxy,
904
+ host: options.host ?? devServer?.host,
905
+ open: options.open ?? devServer?.open,
906
+ server: options.server ?? devServer?.server,
907
+ historyApiFallback: devServer?.historyApiFallback
814
908
  };
815
909
  return item;
816
910
  };
@@ -826,7 +920,7 @@ class ServeCommand {
826
920
  async apply(cli) {
827
921
  const command = cli.program.command('serve', 'run the rspack dev server.').alias('server').alias('s').alias('dev');
828
922
  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');
829
- command.action(async (cliOptions)=>{
923
+ command.action(cli.wrapAction(async (cliOptions)=>{
830
924
  setDefaultNodeEnv(cliOptions, 'development');
831
925
  normalizeCommonOptions(cliOptions, 'serve');
832
926
  cliOptions.hot = normalizeHotOption(cliOptions.hot);
@@ -856,7 +950,9 @@ class ServeCommand {
856
950
  const compilerForDevServer = possibleCompilers.length > 0 ? possibleCompilers[0] : compilers[0];
857
951
  for (const [index, compiler] of compilers.entries()){
858
952
  const userConfig = userConfigs[index];
859
- const devServer = compiler.options.devServer ??= {};
953
+ const existingDevServer = compiler.options.devServer;
954
+ if (false === existingDevServer) continue;
955
+ const devServer = existingDevServer ?? (compiler.options.devServer = {});
860
956
  const isWebAppOnly = compiler.platform.web && !compiler.platform.node && !compiler.platform.nwjs && !compiler.platform.electron && !compiler.platform.webworker;
861
957
  if (isWebAppOnly && void 0 === userConfig.lazyCompilation) compiler.options.lazyCompilation = {
862
958
  imports: true,
@@ -874,7 +970,8 @@ class ServeCommand {
874
970
  };
875
971
  }
876
972
  }
877
- const devServerOptions = compilerForDevServer.options.devServer ??= {};
973
+ const compilerForDevServerOptions = compilerForDevServer.options.devServer;
974
+ const devServerOptions = false === compilerForDevServerOptions ? {} : compilerForDevServerOptions ?? (compilerForDevServer.options.devServer = {});
878
975
  const { setupMiddlewares } = devServerOptions;
879
976
  const lazyCompileMiddleware = rspack.lazyCompilationMiddleware(compiler);
880
977
  devServerOptions.setupMiddlewares = (middlewares, server)=>{
@@ -914,7 +1011,7 @@ class ServeCommand {
914
1011
  logger.error(error);
915
1012
  process.exit(2);
916
1013
  }
917
- });
1014
+ }));
918
1015
  }
919
1016
  }
920
1017
  const readPackageUp = (cwd = process.cwd())=>{
@@ -1104,16 +1201,45 @@ async function loadRspackConfig(options, cwd = process.cwd()) {
1104
1201
  configPath
1105
1202
  };
1106
1203
  }
1107
- const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
1204
+ function isEnvColorSupported() {
1205
+ if ("u" < typeof process) return false;
1206
+ const p = process;
1207
+ const argv = p.argv ?? [];
1208
+ const env = p.env ?? {};
1209
+ return !('NO_COLOR' in env || argv.includes('--no-color')) && ('FORCE_COLOR' in env || argv.includes('--color') || 'win32' === p.platform || p.stdout?.isTTY && 'dumb' !== env.TERM || 'CI' in env);
1210
+ }
1211
+ function createAnsiFormatter(open, close, replace = open) {
1212
+ const closeLength = close.length;
1213
+ return (input)=>{
1214
+ const string = String(input);
1215
+ let index = string.indexOf(close, open.length);
1216
+ if (-1 === index) return open + string + close;
1217
+ let result = '';
1218
+ let cursor = 0;
1219
+ do {
1220
+ result += string.substring(cursor, index) + replace;
1221
+ cursor = index + closeLength;
1222
+ index = string.indexOf(close, cursor);
1223
+ }while (-1 !== index);
1224
+ return open + result + string.substring(cursor) + close;
1225
+ };
1226
+ }
1108
1227
  class RspackCLI {
1109
1228
  colors;
1110
1229
  program;
1230
+ _actionPromise;
1111
1231
  constructor(){
1112
- const program = dist('rspack');
1232
+ const program = cac('rspack');
1113
1233
  this.colors = this.createColors();
1114
1234
  this.program = program;
1115
1235
  program.help();
1116
- program.version("2.0.0-canary.20260120");
1236
+ program.version("2.0.0-rc.1");
1237
+ }
1238
+ wrapAction(fn) {
1239
+ return (...args)=>{
1240
+ this._actionPromise = fn(...args);
1241
+ return this._actionPromise;
1242
+ };
1117
1243
  }
1118
1244
  async buildCompilerConfig(options, rspackCommand) {
1119
1245
  let { config, pathMap } = await this.loadConfig(options);
@@ -1140,10 +1266,24 @@ class RspackCLI {
1140
1266
  return compiler;
1141
1267
  }
1142
1268
  createColors(useColor) {
1143
- const shouldUseColor = useColor || picocolors.isColorSupported;
1269
+ const envSupported = isEnvColorSupported();
1270
+ const enabled = useColor ?? envSupported;
1271
+ if (!enabled) {
1272
+ const passthrough = (text)=>String(text);
1273
+ return {
1274
+ isColorSupported: false,
1275
+ red: passthrough,
1276
+ yellow: passthrough,
1277
+ cyan: passthrough,
1278
+ green: passthrough
1279
+ };
1280
+ }
1144
1281
  return {
1145
- ...(0, picocolors.createColors)(shouldUseColor),
1146
- isColorSupported: shouldUseColor
1282
+ isColorSupported: true,
1283
+ red: createAnsiFormatter('\x1b[31m', '\x1b[39m'),
1284
+ green: createAnsiFormatter('\x1b[32m', '\x1b[39m'),
1285
+ yellow: createAnsiFormatter('\x1b[33m', '\x1b[39m'),
1286
+ cyan: createAnsiFormatter('\x1b[36m', '\x1b[39m')
1147
1287
  };
1148
1288
  }
1149
1289
  getLogger() {
@@ -1159,6 +1299,7 @@ class RspackCLI {
1159
1299
  async run(argv) {
1160
1300
  await this.registerCommands();
1161
1301
  this.program.parse(argv);
1302
+ if (this._actionPromise) await this._actionPromise;
1162
1303
  }
1163
1304
  async registerCommands() {
1164
1305
  const builtinCommands = [
@@ -1178,15 +1319,13 @@ class RspackCLI {
1178
1319
  item.output = item.output || {};
1179
1320
  if (options.outputPath) item.output.path = node_path.resolve(process.cwd(), options.outputPath);
1180
1321
  if (process.env.RSPACK_PROFILE) {
1181
- const { applyProfile } = await import("./274.js").then((mod)=>({
1182
- applyProfile: mod.applyProfile
1183
- }));
1322
+ const { applyProfile } = await import("./profile.js");
1184
1323
  await applyProfile(process.env.RSPACK_PROFILE, process.env.RSPACK_TRACE_LAYER, process.env.RSPACK_TRACE_OUTPUT);
1185
1324
  }
1186
1325
  if (options.watch) item.watch = options.watch;
1187
1326
  if (!item.mode) item.mode = isBuild ? 'production' : 'development';
1188
1327
  if (options.mode) item.mode = options.mode;
1189
- if (void 0 === item.devtool) item.devtool = isBuild ? 'source-map' : 'cheap-module-source-map';
1328
+ if (void 0 === item.devtool) item.devtool = isBuild ? false : 'cheap-module-source-map';
1190
1329
  if (void 0 !== options.devtool) item.devtool = options.devtool;
1191
1330
  if (isServe) {
1192
1331
  const installed = (item.plugins ||= []).find((item)=>item instanceof rspack.ProgressPlugin);
@@ -1212,7 +1351,6 @@ class RspackCLI {
1212
1351
  else if ('string' == typeof item.stats) item.stats = {
1213
1352
  preset: item.stats
1214
1353
  };
1215
- if (this.colors.isColorSupported && void 0 === item.stats.colors) item.stats.colors = true;
1216
1354
  return item;
1217
1355
  };
1218
1356
  if (Array.isArray(item)) return Promise.all(item.map(internalBuildConfig));
@@ -1265,4 +1403,4 @@ function defineConfig(config) {
1265
1403
  function definePlugin(plugin) {
1266
1404
  return plugin;
1267
1405
  }
1268
- export { RspackCLI, defineConfig, definePlugin, node_fs, node_path, rspack };
1406
+ export { __webpack_require__temp as __webpack_require__, RspackCLI, defineConfig, definePlugin };