@rspack-debug/cli 2.0.0-canary.20260120 → 2.0.0-rc.2

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,145 +1,100 @@
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";
11
- __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
- "../../node_modules/.pnpm/pirates@4.0.7/node_modules/pirates/lib/index.js" (module, exports, __webpack_require__) {
79
- module = __webpack_require__.nmd(module);
80
- const BuiltinModule = __webpack_require__("module");
81
- const path = __webpack_require__("path");
82
- const nodeModulesRegex = /^(?:.*[\\/])?node_modules(?:[\\/].*)?$/;
83
- const Module = module.constructor.length > 1 ? module.constructor : BuiltinModule;
84
- const HOOK_RETURNED_NOTHING_ERROR_MESSAGE = "[Pirates] A hook returned a non-string, or nothing at all! This is a violation of intergalactic law!\n--------------------\nIf you have no idea what this means or what Pirates is, let me explain: Pirates is a module that makes it easy to implement require hooks. One of the require hooks you're using uses it. One of these require hooks didn't return anything from it's handler, so we don't know what to do. You might want to debug this.";
85
- function shouldCompile(filename, exts, matcher, ignoreNodeModules) {
86
- if ('string' != typeof filename) return false;
87
- if (-1 === exts.indexOf(path.extname(filename))) return false;
88
- const resolvedFilename = path.resolve(filename);
89
- if (ignoreNodeModules && nodeModulesRegex.test(resolvedFilename)) return false;
90
- if (matcher && 'function' == typeof matcher) return !!matcher(resolvedFilename);
91
- return true;
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;
92
30
  }
93
- function addHook(hook, opts = {}) {
94
- let reverted = false;
95
- const loaders = [];
96
- const oldLoaders = [];
97
- let exts;
98
- const originalJSLoader = Module._extensions['.js'];
99
- const matcher = opts.matcher || null;
100
- const ignoreNodeModules = false !== opts.ignoreNodeModules;
101
- exts = opts.extensions || opts.exts || opts.extension || opts.ext || [
102
- '.js'
103
- ];
104
- if (!Array.isArray(exts)) exts = [
105
- exts
106
- ];
107
- exts.forEach((ext)=>{
108
- if ('string' != typeof ext) throw new TypeError(`Invalid Extension: ${ext}`);
109
- const oldLoader = Module._extensions[ext] || originalJSLoader;
110
- oldLoaders[ext] = Module._extensions[ext];
111
- loaders[ext] = Module._extensions[ext] = function(mod, filename) {
112
- let compile;
113
- if (!reverted) {
114
- if (shouldCompile(filename, exts, matcher, ignoreNodeModules)) {
115
- compile = mod._compile;
116
- mod._compile = function(code) {
117
- mod._compile = compile;
118
- const newCode = hook(code, filename);
119
- if ('string' != typeof newCode) throw new Error(HOOK_RETURNED_NOTHING_ERROR_MESSAGE);
120
- return mod._compile(newCode, filename);
121
- };
122
- }
123
- }
124
- oldLoader(mod, filename);
125
- };
126
- });
127
- return function() {
128
- if (reverted) return;
129
- reverted = true;
130
- exts.forEach((ext)=>{
131
- if (Module._extensions[ext] === loaders[ext]) if (oldLoaders[ext]) Module._extensions[ext] = oldLoaders[ext];
132
- else delete Module._extensions[ext];
133
- });
134
- };
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
+ var installedChunks = {
77
+ 162: 0,
78
+ 410: 0
79
+ };
80
+ var installChunk = (data)=>{
81
+ var __rspack_esm_ids = data.__rspack_esm_ids;
82
+ var __webpack_modules__ = data.__webpack_modules__;
83
+ var __rspack_esm_runtime = data.__rspack_esm_runtime;
84
+ var moduleId, chunkId, i = 0;
85
+ for(moduleId in __webpack_modules__)if (__webpack_require__.o(__webpack_modules__, moduleId)) __webpack_require__.m[moduleId] = __webpack_modules__[moduleId];
86
+ if (__rspack_esm_runtime) __rspack_esm_runtime(__webpack_require__);
87
+ for(; i < __rspack_esm_ids.length; i++){
88
+ chunkId = __rspack_esm_ids[i];
89
+ if (__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) installedChunks[chunkId][0]();
90
+ installedChunks[__rspack_esm_ids[i]] = 0;
135
91
  }
136
- exports.addHook = addHook;
137
- },
138
- module (module) {
139
- module.exports = __rspack_external_module;
140
- },
141
- path (module) {
142
- module.exports = __rspack_external_path;
92
+ };
93
+ __webpack_require__.C = installChunk;
94
+ })();
95
+ __webpack_require__.add({
96
+ stream (module) {
97
+ module.exports = __rspack_createRequire_require("stream");
143
98
  }
144
99
  });
145
100
  function toArr(any) {
@@ -148,13 +103,13 @@ function toArr(any) {
148
103
  ];
149
104
  }
150
105
  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;
106
+ 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
107
  out[key] = null == old ? nxt : Array.isArray(old) ? old.concat(nxt) : [
153
108
  old,
154
109
  nxt
155
110
  ];
156
111
  }
157
- function mri2(args, opts) {
112
+ function lib_default(args, opts) {
158
113
  args = args || [];
159
114
  opts = opts || {};
160
115
  var k, arr, arg, name, val, out = {
@@ -190,26 +145,26 @@ function mri2(args, opts) {
190
145
  const keys = strict ? Object.keys(opts.alias) : [];
191
146
  for(i = 0; i < len; i++){
192
147
  arg = args[i];
193
- if ('--' === arg) {
148
+ if ("--" === arg) {
194
149
  out._ = out._.concat(args.slice(++i));
195
150
  break;
196
151
  }
197
152
  for(j = 0; j < arg.length && 45 === arg.charCodeAt(j); j++);
198
153
  if (0 === j) out._.push(arg);
199
- else if ('no-' === arg.substring(j, j + 3)) {
154
+ else if ("no-" === arg.substring(j, j + 3)) {
200
155
  name = arg.substring(j + 3);
201
156
  if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
202
157
  out[name] = false;
203
158
  } else {
204
159
  for(idx = j + 1; idx < arg.length && 61 !== arg.charCodeAt(idx); idx++);
205
160
  name = arg.substring(j, idx);
206
- val = arg.substring(++idx) || i + 1 === len || 45 === ('' + args[i + 1]).charCodeAt(0) || args[++i];
161
+ val = arg.substring(++idx) || i + 1 === len || 45 === ("" + args[i + 1]).charCodeAt(0) || args[++i];
207
162
  arr = 2 === j ? [
208
163
  name
209
164
  ] : name;
210
165
  for(idx = 0; idx < arr.length; idx++){
211
166
  name = arr[idx];
212
- if (strict && !~keys.indexOf(name)) return opts.unknown('-'.repeat(j) + name);
167
+ if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
213
168
  toVal(out, name, idx + 1 < arr.length || val, opts);
214
169
  }
215
170
  }
@@ -223,8 +178,10 @@ function mri2(args, opts) {
223
178
  }
224
179
  return out;
225
180
  }
226
- const removeBrackets = (v)=>v.replace(/[<[].+/, "").trim();
227
- const findAllBrackets = (v)=>{
181
+ function removeBrackets(v) {
182
+ return v.replace(/[<[].+/, "").trim();
183
+ }
184
+ function findAllBrackets(v) {
228
185
  const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
229
186
  const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
230
187
  const res = [];
@@ -246,8 +203,8 @@ const findAllBrackets = (v)=>{
246
203
  let squareMatch;
247
204
  while(squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v))res.push(parse(squareMatch));
248
205
  return res;
249
- };
250
- const getMriOptions = (options)=>{
206
+ }
207
+ function getMriOptions(options) {
251
208
  const result = {
252
209
  alias: {},
253
210
  boolean: []
@@ -255,53 +212,74 @@ const getMriOptions = (options)=>{
255
212
  for (const [index, option] of options.entries()){
256
213
  if (option.names.length > 1) result.alias[option.names[0]] = option.names.slice(1);
257
214
  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]);
215
+ 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
216
  } else result.boolean.push(option.names[0]);
261
217
  }
262
218
  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 ? [] : {};
219
+ }
220
+ function findLongest(arr) {
221
+ return arr.sort((a, b)=>a.length > b.length ? -1 : 1)[0];
222
+ }
223
+ function padRight(str, length) {
224
+ return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
225
+ }
226
+ function camelcase(input) {
227
+ return input.replaceAll(/([a-z])-([a-z])/g, (_, p1, p2)=>p1 + p2.toUpperCase());
228
+ }
229
+ function setDotProp(obj, keys, val) {
230
+ let current = obj;
231
+ for(let i = 0; i < keys.length; i++){
232
+ const key = keys[i];
233
+ if (i === keys.length - 1) {
234
+ current[key] = val;
235
+ return;
236
+ }
237
+ if (null == current[key]) {
238
+ const nextKeyIsArrayIndex = +keys[i + 1] > -1;
239
+ current[key] = nextKeyIsArrayIndex ? [] : {};
240
+ }
241
+ current = current[key];
275
242
  }
276
- };
277
- const setByType = (obj, transforms)=>{
243
+ }
244
+ function setByType(obj, transforms) {
278
245
  for (const key of Object.keys(transforms)){
279
246
  const transform = transforms[key];
280
247
  if (transform.shouldTransform) {
281
- obj[key] = Array.prototype.concat.call([], obj[key]);
248
+ obj[key] = [
249
+ obj[key]
250
+ ].flat();
282
251
  if ("function" == typeof transform.transformFunction) obj[key] = obj[key].map(transform.transformFunction);
283
252
  }
284
253
  }
285
- };
286
- const getFileName = (input)=>{
287
- const m = /([^\\\/]+)$/.exec(input);
254
+ }
255
+ function getFileName(input) {
256
+ const m = /([^\\/]+)$/.exec(input);
288
257
  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 {
258
+ }
259
+ function camelcaseOptionName(name) {
260
+ return name.split(".").map((v, i)=>0 === i ? camelcase(v) : v).join(".");
261
+ }
262
+ var CACError = class extends Error {
292
263
  constructor(message){
293
264
  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;
265
+ this.name = "CACError";
266
+ if ("function" != typeof Error.captureStackTrace) this.stack = new Error(message).stack;
297
267
  }
298
- }
299
- class Option {
268
+ };
269
+ var Option = class {
270
+ rawName;
271
+ description;
272
+ name;
273
+ names;
274
+ isBoolean;
275
+ required;
276
+ config;
277
+ negated;
300
278
  constructor(rawName, description, config){
301
279
  this.rawName = rawName;
302
280
  this.description = description;
303
281
  this.config = Object.assign({}, config);
304
- rawName = rawName.replace(/\.\*/g, "");
282
+ rawName = rawName.replaceAll(".*", "");
305
283
  this.negated = false;
306
284
  this.names = removeBrackets(rawName).split(",").map((v)=>{
307
285
  let name = v.trim().replace(/^-{1,2}/, "");
@@ -311,16 +289,36 @@ class Option {
311
289
  }
312
290
  return camelcaseOptionName(name);
313
291
  }).sort((a, b)=>a.length > b.length ? 1 : -1);
314
- this.name = this.names[this.names.length - 1];
292
+ this.name = this.names.at(-1);
315
293
  if (this.negated && null == this.config.default) this.config.default = true;
316
294
  if (rawName.includes("<")) this.required = true;
317
295
  else if (rawName.includes("[")) this.required = false;
318
296
  else this.isBoolean = true;
319
297
  }
320
- }
321
- const processArgs = process.argv;
322
- const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
323
- class Command {
298
+ };
299
+ let runtimeProcessArgs;
300
+ let runtimeInfo;
301
+ if ("u" > typeof process) {
302
+ let runtimeName;
303
+ runtimeName = "u" > typeof Deno && "string" == typeof Deno.version?.deno ? "deno" : "u" > typeof Bun && "string" == typeof Bun.version ? "bun" : "node";
304
+ runtimeInfo = `${process.platform}-${process.arch} ${runtimeName}-${process.version}`;
305
+ runtimeProcessArgs = process.argv;
306
+ } else runtimeInfo = "u" < typeof navigator ? "unknown" : `${navigator.platform} ${navigator.userAgent}`;
307
+ var Command = class {
308
+ rawName;
309
+ description;
310
+ config;
311
+ cli;
312
+ options;
313
+ aliasNames;
314
+ name;
315
+ args;
316
+ commandAction;
317
+ usageText;
318
+ versionNumber;
319
+ examples;
320
+ helpCallback;
321
+ globalCommand;
324
322
  constructor(rawName, description, config = {}, cli){
325
323
  this.rawName = rawName;
326
324
  this.description = description;
@@ -391,14 +389,12 @@ class Command {
391
389
  title: "Usage",
392
390
  body: ` $ ${name} ${this.usageText || this.rawName}`
393
391
  });
394
- const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
395
- if (showCommands) {
392
+ if ((this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0) {
396
393
  const longestCommandName = findLongest(commands.map((command)=>command.rawName));
397
394
  sections.push({
398
395
  title: "Commands",
399
396
  body: commands.map((command)=>` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`).join("\n")
400
- });
401
- sections.push({
397
+ }, {
402
398
  title: "For more info, run any command with the `--help` flag",
403
399
  body: commands.map((command)=>` $ ${name}${"" === command.name ? "" : ` ${command.name}`} --help`).join("\n")
404
400
  });
@@ -423,13 +419,12 @@ class Command {
423
419
  }).join("\n")
424
420
  });
425
421
  if (helpCallback) sections = helpCallback(sections) || sections;
426
- console.log(sections.map((section)=>section.title ? `${section.title}:
427
- ${section.body}` : section.body).join("\n\n"));
422
+ console.info(sections.map((section)=>section.title ? `${section.title}:\n${section.body}` : section.body).join("\n\n"));
428
423
  }
429
424
  outputVersion() {
430
425
  const { name } = this.cli;
431
426
  const { versionNumber } = this.cli.globalCommand;
432
- if (versionNumber) console.log(`${name}/${versionNumber} ${platformInfo}`);
427
+ if (versionNumber) console.info(`${name}/${versionNumber} ${runtimeInfo}`);
433
428
  }
434
429
  checkRequiredArgs() {
435
430
  const minimalArgsCount = this.args.filter((arg)=>arg.required).length;
@@ -455,14 +450,27 @@ ${section.body}` : section.body).join("\n\n"));
455
450
  }
456
451
  }
457
452
  }
458
- }
459
- class GlobalCommand extends Command {
453
+ checkUnusedArgs() {
454
+ const maximumArgsCount = this.args.some((arg)=>arg.variadic) ? 1 / 0 : this.args.length;
455
+ if (maximumArgsCount < this.cli.args.length) throw new CACError(`Unused args: ${this.cli.args.slice(maximumArgsCount).map((arg)=>`\`${arg}\``).join(", ")}`);
456
+ }
457
+ };
458
+ var GlobalCommand = class extends Command {
460
459
  constructor(cli){
461
460
  super("@@global@@", "", {}, cli);
462
461
  }
463
- }
464
- var __assign = Object.assign;
465
- class CAC extends EventEmitter {
462
+ };
463
+ var CAC = class extends EventTarget {
464
+ name;
465
+ commands;
466
+ globalCommand;
467
+ matchedCommand;
468
+ matchedCommandName;
469
+ rawArgs;
470
+ args;
471
+ options;
472
+ showHelpOnExit;
473
+ showVersionOnExit;
466
474
  constructor(name = ""){
467
475
  super();
468
476
  this.name = name;
@@ -520,7 +528,11 @@ class CAC extends EventEmitter {
520
528
  this.matchedCommand = void 0;
521
529
  this.matchedCommandName = void 0;
522
530
  }
523
- parse(argv = processArgs, { run = true } = {}) {
531
+ parse(argv, { run = true } = {}) {
532
+ if (!argv) {
533
+ if (!runtimeProcessArgs) throw new Error("No argv provided and runtime process argv is not available.");
534
+ argv = runtimeProcessArgs;
535
+ }
524
536
  this.rawArgs = argv;
525
537
  if (!this.name) this.name = argv[1] ? getFileName(argv[1]) : "cli";
526
538
  let shouldParse = true;
@@ -529,19 +541,24 @@ class CAC extends EventEmitter {
529
541
  const commandName = parsed.args[0];
530
542
  if (command.isMatched(commandName)) {
531
543
  shouldParse = false;
532
- const parsedInfo = __assign(__assign({}, parsed), {
544
+ const parsedInfo = {
545
+ ...parsed,
533
546
  args: parsed.args.slice(1)
534
- });
547
+ };
535
548
  this.setParsedInfo(parsedInfo, command, commandName);
536
- this.emit(`command:${commandName}`, command);
549
+ this.dispatchEvent(new CustomEvent(`command:${commandName}`, {
550
+ detail: command
551
+ }));
537
552
  }
538
553
  }
539
554
  if (shouldParse) {
540
- for (const command of this.commands)if ("" === command.name) {
555
+ for (const command of this.commands)if (command.isDefaultCommand) {
541
556
  shouldParse = false;
542
557
  const parsed = this.mri(argv.slice(2), command);
543
558
  this.setParsedInfo(parsed, command);
544
- this.emit("command:!", command);
559
+ this.dispatchEvent(new CustomEvent("command:!", {
560
+ detail: command
561
+ }));
545
562
  }
546
563
  }
547
564
  if (shouldParse) {
@@ -563,7 +580,9 @@ class CAC extends EventEmitter {
563
580
  options: this.options
564
581
  };
565
582
  if (run) this.runMatchedCommand();
566
- if (!this.matchedCommand && this.args[0]) this.emit("command:*");
583
+ if (!this.matchedCommand && this.args[0]) this.dispatchEvent(new CustomEvent("command:*", {
584
+ detail: this.args[0]
585
+ }));
567
586
  return parsedArgv;
568
587
  }
569
588
  mri(argv, command) {
@@ -574,12 +593,13 @@ class CAC extends EventEmitter {
574
593
  const mriOptions = getMriOptions(cliOptions);
575
594
  let argsAfterDoubleDashes = [];
576
595
  const doubleDashesIndex = argv.indexOf("--");
577
- if (doubleDashesIndex > -1) {
596
+ if (-1 !== doubleDashesIndex) {
578
597
  argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
579
598
  argv = argv.slice(0, doubleDashesIndex);
580
599
  }
581
- let parsed = mri2(argv, mriOptions);
582
- parsed = Object.keys(parsed).reduce((res, name)=>__assign(__assign({}, res), {
600
+ let parsed = lib_default(argv, mriOptions);
601
+ parsed = Object.keys(parsed).reduce((res, name)=>({
602
+ ...res,
583
603
  [camelcaseOptionName(name)]: parsed[name]
584
604
  }), {
585
605
  _: []
@@ -589,20 +609,17 @@ class CAC extends EventEmitter {
589
609
  "--": argsAfterDoubleDashes
590
610
  };
591
611
  const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
592
- let transforms = Object.create(null);
612
+ const transforms = Object.create(null);
593
613
  for (const cliOption of cliOptions){
594
614
  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
- }
615
+ if (Array.isArray(cliOption.config.type) && void 0 === transforms[cliOption.name]) {
616
+ transforms[cliOption.name] = Object.create(null);
617
+ transforms[cliOption.name].shouldTransform = true;
618
+ transforms[cliOption.name].transformFunction = cliOption.config.type[0];
601
619
  }
602
620
  }
603
621
  for (const key of Object.keys(parsed))if ("_" !== key) {
604
- const keys = key.split(".");
605
- setDotProp(options, keys, parsed[key]);
622
+ setDotProp(options, key.split("."), parsed[key]);
606
623
  setByType(options, transforms);
607
624
  }
608
625
  return {
@@ -616,6 +633,7 @@ class CAC extends EventEmitter {
616
633
  command.checkUnknownOptions();
617
634
  command.checkOptionValue();
618
635
  command.checkRequiredArgs();
636
+ command.checkUnusedArgs();
619
637
  const actionArgs = [];
620
638
  command.args.forEach((arg, index)=>{
621
639
  if (arg.variadic) actionArgs.push(args.slice(index));
@@ -624,16 +642,15 @@ class CAC extends EventEmitter {
624
642
  actionArgs.push(options);
625
643
  return command.commandAction.apply(this, actionArgs);
626
644
  }
627
- }
645
+ };
628
646
  const cac = (name = "")=>new CAC(name);
629
- const dist = cac;
630
647
  const commonOptions = (command)=>command.option('-c, --config <path>', 'config file').option('--config-name <name>', 'Name(s) of the configuration to use.', {
631
648
  type: [
632
649
  String
633
650
  ],
634
651
  default: []
635
- }).option('--config-loader <loader>', 'Specify the loader to load the config file, can be `native` or `register`.', {
636
- default: 'register'
652
+ }).option('--config-loader <loader>', 'Specify the loader to load the config file, can be `auto`, `jiti` or `native`.', {
653
+ default: 'auto'
637
654
  }).option('--env <env>', 'env passed to config function', {
638
655
  type: [
639
656
  String
@@ -708,7 +725,7 @@ async function runBuild(cli, options) {
708
725
  const logger = cli.getLogger();
709
726
  let createJsonStringifyStream;
710
727
  if (options.json) {
711
- const jsonExt = await import("@discoveryjs/json-ext");
728
+ 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
729
  createJsonStringifyStream = jsonExt.default.stringifyStream;
713
730
  }
714
731
  const errorHandler = (error, stats)=>{
@@ -753,16 +770,16 @@ class BuildCommand {
753
770
  async apply(cli) {
754
771
  const command = cli.program.command('', 'run the Rspack build').alias('build').alias('bundle').alias('b');
755
772
  commonOptionsForBuildAndServe(commonOptions(command)).option('--json [path]', 'emit stats json');
756
- command.action(async (options)=>{
773
+ command.action(cli.wrapAction(async (options)=>{
757
774
  await runBuild(cli, options);
758
- });
775
+ }));
759
776
  }
760
777
  }
761
778
  class PreviewCommand {
762
779
  async apply(cli) {
763
780
  const command = cli.program.command('preview [dir]', 'run the Rspack server for build output').alias('p');
764
781
  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)=>{
782
+ command.action(cli.wrapAction(async (dir, options)=>{
766
783
  setDefaultNodeEnv(options, 'production');
767
784
  normalizeCommonOptions(options, 'preview');
768
785
  let RspackDevServer;
@@ -794,23 +811,25 @@ class PreviewCommand {
794
811
  logger.error(error);
795
812
  process.exit(2);
796
813
  }
797
- });
814
+ }));
798
815
  }
799
816
  }
800
817
  async function getPreviewConfig(item, options, dir) {
801
818
  const DEFAULT_ROOT = 'dist';
802
819
  const internalPreviewConfig = async (item)=>{
820
+ const devServer = false === item.devServer ? void 0 : item.devServer;
803
821
  item.devServer = {
804
822
  static: {
805
823
  directory: dir ? node_path.join(item.context ?? process.cwd(), dir) : item.output?.path ?? node_path.join(item.context ?? process.cwd(), DEFAULT_ROOT),
806
824
  publicPath: options.publicPath ?? '/'
807
825
  },
826
+ hot: false,
808
827
  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
828
+ proxy: devServer?.proxy,
829
+ host: options.host ?? devServer?.host,
830
+ open: options.open ?? devServer?.open,
831
+ server: options.server ?? devServer?.server,
832
+ historyApiFallback: devServer?.historyApiFallback
814
833
  };
815
834
  return item;
816
835
  };
@@ -826,7 +845,7 @@ class ServeCommand {
826
845
  async apply(cli) {
827
846
  const command = cli.program.command('serve', 'run the rspack dev server.').alias('server').alias('s').alias('dev');
828
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');
829
- command.action(async (cliOptions)=>{
848
+ command.action(cli.wrapAction(async (cliOptions)=>{
830
849
  setDefaultNodeEnv(cliOptions, 'development');
831
850
  normalizeCommonOptions(cliOptions, 'serve');
832
851
  cliOptions.hot = normalizeHotOption(cliOptions.hot);
@@ -856,7 +875,9 @@ class ServeCommand {
856
875
  const compilerForDevServer = possibleCompilers.length > 0 ? possibleCompilers[0] : compilers[0];
857
876
  for (const [index, compiler] of compilers.entries()){
858
877
  const userConfig = userConfigs[index];
859
- const devServer = compiler.options.devServer ??= {};
878
+ const existingDevServer = compiler.options.devServer;
879
+ if (false === existingDevServer) continue;
880
+ const devServer = existingDevServer ?? (compiler.options.devServer = {});
860
881
  const isWebAppOnly = compiler.platform.web && !compiler.platform.node && !compiler.platform.nwjs && !compiler.platform.electron && !compiler.platform.webworker;
861
882
  if (isWebAppOnly && void 0 === userConfig.lazyCompilation) compiler.options.lazyCompilation = {
862
883
  imports: true,
@@ -874,7 +895,8 @@ class ServeCommand {
874
895
  };
875
896
  }
876
897
  }
877
- const devServerOptions = compilerForDevServer.options.devServer ??= {};
898
+ const compilerForDevServerOptions = compilerForDevServer.options.devServer;
899
+ const devServerOptions = false === compilerForDevServerOptions ? {} : compilerForDevServerOptions ?? (compilerForDevServer.options.devServer = {});
878
900
  const { setupMiddlewares } = devServerOptions;
879
901
  const lazyCompileMiddleware = rspack.lazyCompilationMiddleware(compiler);
880
902
  devServerOptions.setupMiddlewares = (middlewares, server)=>{
@@ -914,108 +936,86 @@ class ServeCommand {
914
936
  logger.error(error);
915
937
  process.exit(2);
916
938
  }
917
- });
939
+ }));
918
940
  }
919
941
  }
920
- const readPackageUp = (cwd = process.cwd())=>{
921
- let currentDir = node_path.resolve(cwd);
922
- let packageJsonPath = node_path.join(currentDir, 'package.json');
923
- while(!node_fs.existsSync(packageJsonPath)){
924
- const parentDir = node_path.dirname(currentDir);
925
- if (parentDir === currentDir) return null;
926
- currentDir = parentDir;
927
- packageJsonPath = node_path.join(currentDir, 'package.json');
928
- }
929
- try {
930
- return JSON.parse(node_fs.readFileSync(packageJsonPath, 'utf8'));
931
- } catch {
932
- return null;
933
- }
934
- };
935
- const utils_readPackageUp = readPackageUp;
936
- const isEsmFile = (filePath)=>{
937
- if (/\.(mjs|mts)$/.test(filePath)) return true;
938
- if (/\.(cjs|cts)$/.test(filePath)) return false;
939
- const packageJson = utils_readPackageUp(node_path.dirname(filePath));
940
- return packageJson?.type === 'module';
941
- };
942
- const crossImport_require = createRequire(import.meta.url);
943
- const crossImport = async (path)=>{
944
- if (isEsmFile(path)) {
945
- const url = pathToFileURL(path).href;
946
- const { default: config } = await import(url);
947
- return config;
948
- }
949
- let result = crossImport_require(path);
950
- if (result && 'object' == typeof result && 'default' in result) result = result.default || {};
951
- return result;
952
- };
953
942
  const DEFAULT_EXTENSIONS = [
954
- '.js',
955
943
  '.ts',
956
- '.mjs',
944
+ '.js',
957
945
  '.mts',
958
- '.cjs',
959
- '.cts'
946
+ '.mjs',
947
+ '.cts',
948
+ '.cjs'
960
949
  ];
961
950
  const findConfig = (basePath)=>DEFAULT_EXTENSIONS.map((ext)=>basePath + ext).find(node_fs.existsSync);
962
951
  const utils_findConfig = findConfig;
963
- const TS_EXTENSION = [
964
- '.ts',
965
- '.cts',
966
- '.mts'
952
+ const loadConfig_require = createRequire(import.meta.url);
953
+ const loadConfig_DEFAULT_CONFIG_NAME = 'rspack.config';
954
+ const JS_CONFIG_EXTENSION_REGEXP = /\.(?:js|mjs|cjs)$/;
955
+ const CONFIG_LOADER_VALUES = [
956
+ 'auto',
957
+ 'jiti',
958
+ 'native'
967
959
  ];
968
- const isTsFile = (configPath)=>{
969
- const ext = node_path.extname(configPath);
970
- return TS_EXTENSION.includes(ext);
960
+ const PREBUNDLED_JITI_PATH = new URL('../compiled/jiti/index.js', import.meta.url).href;
961
+ const supportsNativeTypeScript = ()=>{
962
+ const features = process.features;
963
+ return Boolean(features.typescript || process.versions.bun || process.versions.deno);
971
964
  };
972
- const utils_isTsFile = isTsFile;
973
- const lib = __webpack_require__("../../node_modules/.pnpm/pirates@4.0.7/node_modules/pirates/lib/index.js");
974
- const loadConfig_require = createRequire(import.meta.url);
975
- const injectInlineSourceMap = ({ code, map })=>{
976
- if (map) {
977
- const base64Map = Buffer.from(map, 'utf8').toString('base64');
978
- const sourceMapContent = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`;
979
- return `${code}\n${sourceMapContent}`;
980
- }
981
- return code;
965
+ const normalizeConfigLoader = (configLoader)=>{
966
+ const normalizedLoader = configLoader ?? 'auto';
967
+ if (CONFIG_LOADER_VALUES.includes(normalizedLoader)) return normalizedLoader;
968
+ throw new Error(`config loader "${normalizedLoader}" is not supported. Expected one of: ${CONFIG_LOADER_VALUES.join(', ')}.`);
982
969
  };
983
- function compile(sourcecode, filename) {
984
- const { code, map } = rspack.experiments.swc.transformSync(sourcecode, {
985
- jsc: {
986
- parser: {
987
- syntax: "typescript",
988
- tsx: false,
989
- decorators: true,
990
- dynamicImport: true
991
- }
992
- },
993
- filename: filename,
994
- module: {
995
- type: 'commonjs'
996
- },
997
- sourceMaps: true,
998
- isModule: true
999
- });
1000
- return injectInlineSourceMap({
1001
- code,
1002
- map
970
+ const resolveDefaultExport = (result)=>result && 'object' == typeof result && 'default' in result ? result.default : result;
971
+ const loadConfigWithNativeLoader = async (configPath)=>{
972
+ const configFileURL = pathToFileURL(configPath).href;
973
+ const loadedModule = await import(`${configFileURL}?t=${Date.now()}`);
974
+ return resolveDefaultExport(loadedModule);
975
+ };
976
+ let jitiInstancePromise;
977
+ const getJiti = async ()=>{
978
+ if (!jitiInstancePromise) jitiInstancePromise = import(PREBUNDLED_JITI_PATH).then((module)=>{
979
+ const createJiti = 'createJiti' in module ? module.createJiti : module.default;
980
+ return createJiti(import.meta.filename, {
981
+ moduleCache: false,
982
+ interopDefault: true,
983
+ nativeModules: [
984
+ "typescript"
985
+ ]
986
+ });
1003
987
  });
1004
- }
1005
- const loadConfig_DEFAULT_CONFIG_NAME = 'rspack.config';
1006
- const registerLoader = (configPath)=>{
1007
- if (isEsmFile(configPath) && utils_isTsFile(configPath)) return;
1008
- if (!utils_isTsFile(configPath)) throw new Error(`config file "${configPath}" is not supported.`);
1009
- (0, lib.addHook)((code, filename)=>{
1010
- try {
1011
- return compile(code, filename);
1012
- } catch (err) {
1013
- throw new Error(`Failed to transform file "${filename}" when loading TypeScript config file:\n ${err instanceof Error ? err.message : String(err)}`);
1014
- }
1015
- }, {
1016
- exts: TS_EXTENSION
988
+ return jitiInstancePromise;
989
+ };
990
+ const loadConfigWithJiti = async (configPath)=>{
991
+ const jiti = await getJiti();
992
+ return jiti.import(configPath, {
993
+ default: true
1017
994
  });
1018
995
  };
996
+ const loadConfigByPath = async (configPath, options)=>{
997
+ const configLoader = normalizeConfigLoader(options.configLoader);
998
+ const useNative = Boolean('native' === configLoader || 'auto' === configLoader && supportsNativeTypeScript());
999
+ if (useNative || JS_CONFIG_EXTENSION_REGEXP.test(configPath)) try {
1000
+ return await loadConfigWithNativeLoader(configPath);
1001
+ } catch (error) {
1002
+ if ('native' === configLoader) throw error;
1003
+ }
1004
+ return loadConfigWithJiti(configPath);
1005
+ };
1006
+ const isConfigObject = (value)=>Boolean(value) && 'object' == typeof value && !Array.isArray(value);
1007
+ const isRspackConfig = (value)=>Array.isArray(value) || isConfigObject(value);
1008
+ const resolveRspackConfigExport = async (configExport, options)=>{
1009
+ let loadedConfig = configExport;
1010
+ if ('function' == typeof loadedConfig) {
1011
+ let functionResult = loadedConfig(options.env, options);
1012
+ if ('function' == typeof functionResult.then) functionResult = await functionResult;
1013
+ if (void 0 === functionResult) throw new Error('[rspack-cli:loadConfig] The config function must return a config object.');
1014
+ loadedConfig = functionResult;
1015
+ }
1016
+ if (!isRspackConfig(loadedConfig)) throw new Error(`[rspack-cli:loadConfig] The config must be an object, an array, or a function that returns one, get ${String(loadedConfig)}`);
1017
+ return loadedConfig;
1018
+ };
1019
1019
  const checkIsMultiRspackOptions = (config)=>Array.isArray(config);
1020
1020
  async function loadExtendedConfig(config, configPath, cwd, options) {
1021
1021
  if (checkIsMultiRspackOptions(config)) {
@@ -1068,13 +1068,9 @@ async function loadExtendedConfig(config, configPath, cwd, options) {
1068
1068
  throw new Error(`Cannot find module '${extendPath}' to extend from.`);
1069
1069
  }
1070
1070
  if (!node_fs.existsSync(resolvedPath)) throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
1071
- if (utils_isTsFile(resolvedPath) && 'register' === options.configLoader) registerLoader(resolvedPath);
1072
- let loadedConfig = await crossImport(resolvedPath);
1073
- if ('function' == typeof loadedConfig) {
1074
- loadedConfig = loadedConfig(options.env, options);
1075
- if ('function' == typeof loadedConfig.then) loadedConfig = await loadedConfig;
1076
- }
1077
- const { config: extendedConfig, pathMap: extendedPathMap } = await loadExtendedConfig(loadedConfig, resolvedPath, cwd, options);
1071
+ const loadedConfig = await loadConfigByPath(resolvedPath, options);
1072
+ const resolvedConfig = await resolveRspackConfigExport(loadedConfig, options);
1073
+ const { config: extendedConfig, pathMap: extendedPathMap } = await loadExtendedConfig(resolvedConfig, resolvedPath, cwd, options);
1078
1074
  const configPaths = [
1079
1075
  ...pathMap.get(resultConfig) || [],
1080
1076
  ...extendedPathMap.get(extendedConfig) || []
@@ -1097,23 +1093,51 @@ async function loadRspackConfig(options, cwd = process.cwd()) {
1097
1093
  if (!defaultConfig) return null;
1098
1094
  configPath = defaultConfig;
1099
1095
  }
1100
- if (utils_isTsFile(configPath) && 'register' === options.configLoader) registerLoader(configPath);
1101
- const loadedConfig = await crossImport(configPath);
1096
+ const loadedConfig = await loadConfigByPath(configPath, options);
1102
1097
  return {
1103
1098
  loadedConfig,
1104
1099
  configPath
1105
1100
  };
1106
1101
  }
1107
- const picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
1102
+ function isEnvColorSupported() {
1103
+ if ("u" < typeof process) return false;
1104
+ const p = process;
1105
+ const argv = p.argv ?? [];
1106
+ const env = p.env ?? {};
1107
+ 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);
1108
+ }
1109
+ function createAnsiFormatter(open, close, replace = open) {
1110
+ const closeLength = close.length;
1111
+ return (input)=>{
1112
+ const string = String(input);
1113
+ let index = string.indexOf(close, open.length);
1114
+ if (-1 === index) return open + string + close;
1115
+ let result = '';
1116
+ let cursor = 0;
1117
+ do {
1118
+ result += string.substring(cursor, index) + replace;
1119
+ cursor = index + closeLength;
1120
+ index = string.indexOf(close, cursor);
1121
+ }while (-1 !== index);
1122
+ return open + result + string.substring(cursor) + close;
1123
+ };
1124
+ }
1108
1125
  class RspackCLI {
1109
1126
  colors;
1110
1127
  program;
1128
+ _actionPromise;
1111
1129
  constructor(){
1112
- const program = dist('rspack');
1130
+ const program = cac('rspack');
1113
1131
  this.colors = this.createColors();
1114
1132
  this.program = program;
1115
1133
  program.help();
1116
- program.version("2.0.0-canary.20260120");
1134
+ program.version("2.0.0-rc.2");
1135
+ }
1136
+ wrapAction(fn) {
1137
+ return (...args)=>{
1138
+ this._actionPromise = fn(...args);
1139
+ return this._actionPromise;
1140
+ };
1117
1141
  }
1118
1142
  async buildCompilerConfig(options, rspackCommand) {
1119
1143
  let { config, pathMap } = await this.loadConfig(options);
@@ -1140,10 +1164,24 @@ class RspackCLI {
1140
1164
  return compiler;
1141
1165
  }
1142
1166
  createColors(useColor) {
1143
- const shouldUseColor = useColor || picocolors.isColorSupported;
1167
+ const envSupported = isEnvColorSupported();
1168
+ const enabled = useColor ?? envSupported;
1169
+ if (!enabled) {
1170
+ const passthrough = (text)=>String(text);
1171
+ return {
1172
+ isColorSupported: false,
1173
+ red: passthrough,
1174
+ yellow: passthrough,
1175
+ cyan: passthrough,
1176
+ green: passthrough
1177
+ };
1178
+ }
1144
1179
  return {
1145
- ...(0, picocolors.createColors)(shouldUseColor),
1146
- isColorSupported: shouldUseColor
1180
+ isColorSupported: true,
1181
+ red: createAnsiFormatter('\x1b[31m', '\x1b[39m'),
1182
+ green: createAnsiFormatter('\x1b[32m', '\x1b[39m'),
1183
+ yellow: createAnsiFormatter('\x1b[33m', '\x1b[39m'),
1184
+ cyan: createAnsiFormatter('\x1b[36m', '\x1b[39m')
1147
1185
  };
1148
1186
  }
1149
1187
  getLogger() {
@@ -1159,6 +1197,7 @@ class RspackCLI {
1159
1197
  async run(argv) {
1160
1198
  await this.registerCommands();
1161
1199
  this.program.parse(argv);
1200
+ if (this._actionPromise) await this._actionPromise;
1162
1201
  }
1163
1202
  async registerCommands() {
1164
1203
  const builtinCommands = [
@@ -1178,15 +1217,13 @@ class RspackCLI {
1178
1217
  item.output = item.output || {};
1179
1218
  if (options.outputPath) item.output.path = node_path.resolve(process.cwd(), options.outputPath);
1180
1219
  if (process.env.RSPACK_PROFILE) {
1181
- const { applyProfile } = await import("./274.js").then((mod)=>({
1182
- applyProfile: mod.applyProfile
1183
- }));
1220
+ const { applyProfile } = await import("./profile.js");
1184
1221
  await applyProfile(process.env.RSPACK_PROFILE, process.env.RSPACK_TRACE_LAYER, process.env.RSPACK_TRACE_OUTPUT);
1185
1222
  }
1186
1223
  if (options.watch) item.watch = options.watch;
1187
1224
  if (!item.mode) item.mode = isBuild ? 'production' : 'development';
1188
1225
  if (options.mode) item.mode = options.mode;
1189
- if (void 0 === item.devtool) item.devtool = isBuild ? 'source-map' : 'cheap-module-source-map';
1226
+ if (void 0 === item.devtool) item.devtool = isBuild ? false : 'cheap-module-source-map';
1190
1227
  if (void 0 !== options.devtool) item.devtool = options.devtool;
1191
1228
  if (isServe) {
1192
1229
  const installed = (item.plugins ||= []).find((item)=>item instanceof rspack.ProgressPlugin);
@@ -1212,7 +1249,6 @@ class RspackCLI {
1212
1249
  else if ('string' == typeof item.stats) item.stats = {
1213
1250
  preset: item.stats
1214
1251
  };
1215
- if (this.colors.isColorSupported && void 0 === item.stats.colors) item.stats.colors = true;
1216
1252
  return item;
1217
1253
  };
1218
1254
  if (Array.isArray(item)) return Promise.all(item.map(internalBuildConfig));
@@ -1224,13 +1260,9 @@ class RspackCLI {
1224
1260
  config: this.filterConfig(options, {}),
1225
1261
  pathMap: new WeakMap()
1226
1262
  };
1227
- let { loadedConfig, configPath } = config;
1228
- if ('function' == typeof loadedConfig) {
1229
- let functionResult = loadedConfig(options.env, options);
1230
- if ('function' == typeof functionResult.then) functionResult = await functionResult;
1231
- loadedConfig = functionResult;
1232
- }
1233
- const { config: extendedConfig, pathMap } = await loadExtendedConfig(loadedConfig, configPath, process.cwd(), options);
1263
+ const { loadedConfig, configPath } = config;
1264
+ const resolvedConfig = await resolveRspackConfigExport(loadedConfig, options);
1265
+ const { config: extendedConfig, pathMap } = await loadExtendedConfig(resolvedConfig, configPath, process.cwd(), options);
1234
1266
  return {
1235
1267
  config: this.filterConfig(options, extendedConfig),
1236
1268
  pathMap
@@ -1265,4 +1297,4 @@ function defineConfig(config) {
1265
1297
  function definePlugin(plugin) {
1266
1298
  return plugin;
1267
1299
  }
1268
- export { RspackCLI, defineConfig, definePlugin, node_fs, node_path, rspack };
1300
+ export { __webpack_require__temp as __webpack_require__, RspackCLI, defineConfig, definePlugin };