@rspack/cli 1.6.0-beta.0 → 1.6.0
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/0~361.js +5 -5
- package/dist/1~361.mjs +5 -5
- package/dist/cli.d.ts +11 -9
- package/dist/index.js +808 -276
- package/dist/index.mjs +799 -278
- package/dist/types.d.ts +2 -33
- package/dist/utils/crossImport.d.ts +1 -1
- package/dist/utils/isEsmFile.d.ts +1 -2
- package/dist/utils/loadConfig.d.ts +6 -6
- package/dist/utils/options.d.ts +23 -71
- package/dist/utils/rspackCore.d.ts +2 -0
- package/package.json +9 -10
package/dist/index.mjs
CHANGED
|
@@ -1,21 +1,156 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_module__ from "module";
|
|
2
2
|
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
|
|
3
3
|
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { pathToFileURL } from "node:url";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_util_1b29d436__ from "node:util";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE_events__ from "events";
|
|
7
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__ from "node:module";
|
|
8
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
|
|
10
9
|
var __webpack_modules__ = {
|
|
11
|
-
"@
|
|
12
|
-
|
|
10
|
+
"../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js": function(module) {
|
|
11
|
+
let p = process || {}, argv = p.argv || [], env = p.env || {};
|
|
12
|
+
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);
|
|
13
|
+
let formatter = (open, close, replace = open)=>(input)=>{
|
|
14
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
15
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
16
|
+
};
|
|
17
|
+
let replaceClose = (string, close, replace, index)=>{
|
|
18
|
+
let result = "", cursor = 0;
|
|
19
|
+
do {
|
|
20
|
+
result += string.substring(cursor, index) + replace;
|
|
21
|
+
cursor = index + close.length;
|
|
22
|
+
index = string.indexOf(close, cursor);
|
|
23
|
+
}while (~index);
|
|
24
|
+
return result + string.substring(cursor);
|
|
25
|
+
};
|
|
26
|
+
let createColors = (enabled = isColorSupported)=>{
|
|
27
|
+
let f = enabled ? formatter : ()=>String;
|
|
28
|
+
return {
|
|
29
|
+
isColorSupported: enabled,
|
|
30
|
+
reset: f("\x1b[0m", "\x1b[0m"),
|
|
31
|
+
bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
|
|
32
|
+
dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
|
|
33
|
+
italic: f("\x1b[3m", "\x1b[23m"),
|
|
34
|
+
underline: f("\x1b[4m", "\x1b[24m"),
|
|
35
|
+
inverse: f("\x1b[7m", "\x1b[27m"),
|
|
36
|
+
hidden: f("\x1b[8m", "\x1b[28m"),
|
|
37
|
+
strikethrough: f("\x1b[9m", "\x1b[29m"),
|
|
38
|
+
black: f("\x1b[30m", "\x1b[39m"),
|
|
39
|
+
red: f("\x1b[31m", "\x1b[39m"),
|
|
40
|
+
green: f("\x1b[32m", "\x1b[39m"),
|
|
41
|
+
yellow: f("\x1b[33m", "\x1b[39m"),
|
|
42
|
+
blue: f("\x1b[34m", "\x1b[39m"),
|
|
43
|
+
magenta: f("\x1b[35m", "\x1b[39m"),
|
|
44
|
+
cyan: f("\x1b[36m", "\x1b[39m"),
|
|
45
|
+
white: f("\x1b[37m", "\x1b[39m"),
|
|
46
|
+
gray: f("\x1b[90m", "\x1b[39m"),
|
|
47
|
+
bgBlack: f("\x1b[40m", "\x1b[49m"),
|
|
48
|
+
bgRed: f("\x1b[41m", "\x1b[49m"),
|
|
49
|
+
bgGreen: f("\x1b[42m", "\x1b[49m"),
|
|
50
|
+
bgYellow: f("\x1b[43m", "\x1b[49m"),
|
|
51
|
+
bgBlue: f("\x1b[44m", "\x1b[49m"),
|
|
52
|
+
bgMagenta: f("\x1b[45m", "\x1b[49m"),
|
|
53
|
+
bgCyan: f("\x1b[46m", "\x1b[49m"),
|
|
54
|
+
bgWhite: f("\x1b[47m", "\x1b[49m"),
|
|
55
|
+
blackBright: f("\x1b[90m", "\x1b[39m"),
|
|
56
|
+
redBright: f("\x1b[91m", "\x1b[39m"),
|
|
57
|
+
greenBright: f("\x1b[92m", "\x1b[39m"),
|
|
58
|
+
yellowBright: f("\x1b[93m", "\x1b[39m"),
|
|
59
|
+
blueBright: f("\x1b[94m", "\x1b[39m"),
|
|
60
|
+
magentaBright: f("\x1b[95m", "\x1b[39m"),
|
|
61
|
+
cyanBright: f("\x1b[96m", "\x1b[39m"),
|
|
62
|
+
whiteBright: f("\x1b[97m", "\x1b[39m"),
|
|
63
|
+
bgBlackBright: f("\x1b[100m", "\x1b[49m"),
|
|
64
|
+
bgRedBright: f("\x1b[101m", "\x1b[49m"),
|
|
65
|
+
bgGreenBright: f("\x1b[102m", "\x1b[49m"),
|
|
66
|
+
bgYellowBright: f("\x1b[103m", "\x1b[49m"),
|
|
67
|
+
bgBlueBright: f("\x1b[104m", "\x1b[49m"),
|
|
68
|
+
bgMagentaBright: f("\x1b[105m", "\x1b[49m"),
|
|
69
|
+
bgCyanBright: f("\x1b[106m", "\x1b[49m"),
|
|
70
|
+
bgWhiteBright: f("\x1b[107m", "\x1b[49m")
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
module.exports = createColors();
|
|
74
|
+
module.exports.createColors = createColors;
|
|
75
|
+
},
|
|
76
|
+
"../../node_modules/.pnpm/pirates@4.0.7/node_modules/pirates/lib/index.js": function(module, exports, __webpack_require__) {
|
|
77
|
+
module = __webpack_require__.nmd(module);
|
|
78
|
+
const BuiltinModule = __webpack_require__("module");
|
|
79
|
+
const path = __webpack_require__("path");
|
|
80
|
+
const nodeModulesRegex = /^(?:.*[\\/])?node_modules(?:[\\/].*)?$/;
|
|
81
|
+
const Module = module.constructor.length > 1 ? module.constructor : BuiltinModule;
|
|
82
|
+
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.";
|
|
83
|
+
function shouldCompile(filename, exts, matcher, ignoreNodeModules) {
|
|
84
|
+
if ('string' != typeof filename) return false;
|
|
85
|
+
if (-1 === exts.indexOf(path.extname(filename))) return false;
|
|
86
|
+
const resolvedFilename = path.resolve(filename);
|
|
87
|
+
if (ignoreNodeModules && nodeModulesRegex.test(resolvedFilename)) return false;
|
|
88
|
+
if (matcher && 'function' == typeof matcher) return !!matcher(resolvedFilename);
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
function addHook(hook, opts = {}) {
|
|
92
|
+
let reverted = false;
|
|
93
|
+
const loaders = [];
|
|
94
|
+
const oldLoaders = [];
|
|
95
|
+
let exts;
|
|
96
|
+
const originalJSLoader = Module._extensions['.js'];
|
|
97
|
+
const matcher = opts.matcher || null;
|
|
98
|
+
const ignoreNodeModules = false !== opts.ignoreNodeModules;
|
|
99
|
+
exts = opts.extensions || opts.exts || opts.extension || opts.ext || [
|
|
100
|
+
'.js'
|
|
101
|
+
];
|
|
102
|
+
if (!Array.isArray(exts)) exts = [
|
|
103
|
+
exts
|
|
104
|
+
];
|
|
105
|
+
exts.forEach((ext)=>{
|
|
106
|
+
if ('string' != typeof ext) throw new TypeError(`Invalid Extension: ${ext}`);
|
|
107
|
+
const oldLoader = Module._extensions[ext] || originalJSLoader;
|
|
108
|
+
oldLoaders[ext] = Module._extensions[ext];
|
|
109
|
+
loaders[ext] = Module._extensions[ext] = function(mod, filename) {
|
|
110
|
+
let compile;
|
|
111
|
+
if (!reverted) {
|
|
112
|
+
if (shouldCompile(filename, exts, matcher, ignoreNodeModules)) {
|
|
113
|
+
compile = mod._compile;
|
|
114
|
+
mod._compile = function(code) {
|
|
115
|
+
mod._compile = compile;
|
|
116
|
+
const newCode = hook(code, filename);
|
|
117
|
+
if ('string' != typeof newCode) throw new Error(HOOK_RETURNED_NOTHING_ERROR_MESSAGE);
|
|
118
|
+
return mod._compile(newCode, filename);
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
oldLoader(mod, filename);
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
return function() {
|
|
126
|
+
if (reverted) return;
|
|
127
|
+
reverted = true;
|
|
128
|
+
exts.forEach((ext)=>{
|
|
129
|
+
if (Module._extensions[ext] === loaders[ext]) if (oldLoaders[ext]) Module._extensions[ext] = oldLoaders[ext];
|
|
130
|
+
else delete Module._extensions[ext];
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
exports.addHook = addHook;
|
|
135
|
+
},
|
|
136
|
+
"./src/utils/rspackCore.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
137
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
138
|
+
Z: ()=>rspack
|
|
139
|
+
});
|
|
140
|
+
const rspackCore_require = (0, __WEBPACK_EXTERNAL_MODULE_node_module_ab9f2194__.createRequire)(import.meta.url);
|
|
141
|
+
const rspack = rspackCore_require("@rspack/core");
|
|
142
|
+
},
|
|
143
|
+
module: function(module) {
|
|
144
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_module__;
|
|
13
145
|
},
|
|
14
146
|
"node:fs": function(module) {
|
|
15
147
|
module.exports = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__;
|
|
16
148
|
},
|
|
17
149
|
"node:path": function(module) {
|
|
18
150
|
module.exports = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__;
|
|
151
|
+
},
|
|
152
|
+
path: function(module) {
|
|
153
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_path__;
|
|
19
154
|
}
|
|
20
155
|
};
|
|
21
156
|
var __webpack_module_cache__ = {};
|
|
@@ -23,9 +158,12 @@ function __webpack_require__(moduleId) {
|
|
|
23
158
|
var cachedModule = __webpack_module_cache__[moduleId];
|
|
24
159
|
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
25
160
|
var module = __webpack_module_cache__[moduleId] = {
|
|
161
|
+
id: moduleId,
|
|
162
|
+
loaded: false,
|
|
26
163
|
exports: {}
|
|
27
164
|
};
|
|
28
165
|
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
166
|
+
module.loaded = true;
|
|
29
167
|
return module.exports;
|
|
30
168
|
}
|
|
31
169
|
__webpack_require__.m = __webpack_modules__;
|
|
@@ -50,6 +188,13 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
50
188
|
(()=>{
|
|
51
189
|
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
52
190
|
})();
|
|
191
|
+
(()=>{
|
|
192
|
+
__webpack_require__.nmd = (module)=>{
|
|
193
|
+
module.paths = [];
|
|
194
|
+
if (!module.children) module.children = [];
|
|
195
|
+
return module;
|
|
196
|
+
};
|
|
197
|
+
})();
|
|
53
198
|
(()=>{
|
|
54
199
|
var installedChunks = {
|
|
55
200
|
410: 0
|
|
@@ -88,72 +233,545 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
88
233
|
};
|
|
89
234
|
})();
|
|
90
235
|
var external_node_path_ = __webpack_require__("node:path");
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
236
|
+
function toArr(any) {
|
|
237
|
+
return null == any ? [] : Array.isArray(any) ? any : [
|
|
238
|
+
any
|
|
239
|
+
];
|
|
240
|
+
}
|
|
241
|
+
function toVal(out, key, val, opts) {
|
|
242
|
+
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;
|
|
243
|
+
out[key] = null == old ? nxt : Array.isArray(old) ? old.concat(nxt) : [
|
|
244
|
+
old,
|
|
245
|
+
nxt
|
|
246
|
+
];
|
|
247
|
+
}
|
|
248
|
+
function mri2(args, opts) {
|
|
249
|
+
args = args || [];
|
|
250
|
+
opts = opts || {};
|
|
251
|
+
var k, arr, arg, name, val, out = {
|
|
252
|
+
_: []
|
|
253
|
+
};
|
|
254
|
+
var i = 0, j = 0, idx = 0, len = args.length;
|
|
255
|
+
const alibi = void 0 !== opts.alias;
|
|
256
|
+
const strict = void 0 !== opts.unknown;
|
|
257
|
+
const defaults = void 0 !== opts.default;
|
|
258
|
+
opts.alias = opts.alias || {};
|
|
259
|
+
opts.string = toArr(opts.string);
|
|
260
|
+
opts.boolean = toArr(opts.boolean);
|
|
261
|
+
if (alibi) for(k in opts.alias){
|
|
262
|
+
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
263
|
+
for(i = 0; i < arr.length; i++)(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
264
|
+
}
|
|
265
|
+
for(i = opts.boolean.length; i-- > 0;){
|
|
266
|
+
arr = opts.alias[opts.boolean[i]] || [];
|
|
267
|
+
for(j = arr.length; j-- > 0;)opts.boolean.push(arr[j]);
|
|
268
|
+
}
|
|
269
|
+
for(i = opts.string.length; i-- > 0;){
|
|
270
|
+
arr = opts.alias[opts.string[i]] || [];
|
|
271
|
+
for(j = arr.length; j-- > 0;)opts.string.push(arr[j]);
|
|
272
|
+
}
|
|
273
|
+
if (defaults) for(k in opts.default){
|
|
274
|
+
name = typeof opts.default[k];
|
|
275
|
+
arr = opts.alias[k] = opts.alias[k] || [];
|
|
276
|
+
if (void 0 !== opts[name]) {
|
|
277
|
+
opts[name].push(k);
|
|
278
|
+
for(i = 0; i < arr.length; i++)opts[name].push(arr[i]);
|
|
113
279
|
}
|
|
114
|
-
}
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
string: true,
|
|
140
|
-
describe: "env passed to config function"
|
|
141
|
-
},
|
|
142
|
-
devtool: {
|
|
143
|
-
type: "string",
|
|
144
|
-
describe: "Specify a developer tool for debugging. Defaults to `cheap-module-source-map` in development and `source-map` in production.",
|
|
145
|
-
alias: "d",
|
|
146
|
-
coerce: (arg)=>{
|
|
147
|
-
if ("true" === arg) return "source-map";
|
|
148
|
-
if ("false" === arg || "" === arg.trim()) return false;
|
|
149
|
-
return arg;
|
|
280
|
+
}
|
|
281
|
+
const keys = strict ? Object.keys(opts.alias) : [];
|
|
282
|
+
for(i = 0; i < len; i++){
|
|
283
|
+
arg = args[i];
|
|
284
|
+
if ('--' === arg) {
|
|
285
|
+
out._ = out._.concat(args.slice(++i));
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
for(j = 0; j < arg.length && 45 === arg.charCodeAt(j); j++);
|
|
289
|
+
if (0 === j) out._.push(arg);
|
|
290
|
+
else if ('no-' === arg.substring(j, j + 3)) {
|
|
291
|
+
name = arg.substring(j + 3);
|
|
292
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
|
|
293
|
+
out[name] = false;
|
|
294
|
+
} else {
|
|
295
|
+
for(idx = j + 1; idx < arg.length && 61 !== arg.charCodeAt(idx); idx++);
|
|
296
|
+
name = arg.substring(j, idx);
|
|
297
|
+
val = arg.substring(++idx) || i + 1 === len || 45 === ('' + args[i + 1]).charCodeAt(0) || args[++i];
|
|
298
|
+
arr = 2 === j ? [
|
|
299
|
+
name
|
|
300
|
+
] : name;
|
|
301
|
+
for(idx = 0; idx < arr.length; idx++){
|
|
302
|
+
name = arr[idx];
|
|
303
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown('-'.repeat(j) + name);
|
|
304
|
+
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
150
305
|
}
|
|
151
306
|
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
307
|
+
}
|
|
308
|
+
if (defaults) {
|
|
309
|
+
for(k in opts.default)if (void 0 === out[k]) out[k] = opts.default[k];
|
|
310
|
+
}
|
|
311
|
+
if (alibi) for(k in out){
|
|
312
|
+
arr = opts.alias[k] || [];
|
|
313
|
+
while(arr.length > 0)out[arr.shift()] = out[k];
|
|
314
|
+
}
|
|
315
|
+
return out;
|
|
316
|
+
}
|
|
317
|
+
const removeBrackets = (v)=>v.replace(/[<[].+/, "").trim();
|
|
318
|
+
const findAllBrackets = (v)=>{
|
|
319
|
+
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
|
320
|
+
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
|
321
|
+
const res = [];
|
|
322
|
+
const parse = (match)=>{
|
|
323
|
+
let variadic = false;
|
|
324
|
+
let value = match[1];
|
|
325
|
+
if (value.startsWith("...")) {
|
|
326
|
+
value = value.slice(3);
|
|
327
|
+
variadic = true;
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
required: match[0].startsWith("<"),
|
|
331
|
+
value,
|
|
332
|
+
variadic
|
|
333
|
+
};
|
|
334
|
+
};
|
|
335
|
+
let angledMatch;
|
|
336
|
+
while(angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v))res.push(parse(angledMatch));
|
|
337
|
+
let squareMatch;
|
|
338
|
+
while(squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v))res.push(parse(squareMatch));
|
|
339
|
+
return res;
|
|
340
|
+
};
|
|
341
|
+
const getMriOptions = (options)=>{
|
|
342
|
+
const result = {
|
|
343
|
+
alias: {},
|
|
344
|
+
boolean: []
|
|
345
|
+
};
|
|
346
|
+
for (const [index, option] of options.entries()){
|
|
347
|
+
if (option.names.length > 1) result.alias[option.names[0]] = option.names.slice(1);
|
|
348
|
+
if (option.isBoolean) if (option.negated) {
|
|
349
|
+
const hasStringTypeOption = options.some((o, i)=>i !== index && o.names.some((name)=>option.names.includes(name)) && "boolean" == typeof o.required);
|
|
350
|
+
if (!hasStringTypeOption) result.boolean.push(option.names[0]);
|
|
351
|
+
} else result.boolean.push(option.names[0]);
|
|
352
|
+
}
|
|
353
|
+
return result;
|
|
354
|
+
};
|
|
355
|
+
const findLongest = (arr)=>arr.sort((a, b)=>a.length > b.length ? -1 : 1)[0];
|
|
356
|
+
const padRight = (str, length)=>str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
|
357
|
+
const camelcase = (input)=>input.replace(/([a-z])-([a-z])/g, (_, p1, p2)=>p1 + p2.toUpperCase());
|
|
358
|
+
const setDotProp = (obj, keys, val)=>{
|
|
359
|
+
let i = 0;
|
|
360
|
+
let length = keys.length;
|
|
361
|
+
let t = obj;
|
|
362
|
+
let x;
|
|
363
|
+
for(; i < length; ++i){
|
|
364
|
+
x = t[keys[i]];
|
|
365
|
+
t = t[keys[i]] = i === length - 1 ? val : null != x ? x : !~keys[i + 1].indexOf(".") && +keys[i + 1] > -1 ? [] : {};
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
const setByType = (obj, transforms)=>{
|
|
369
|
+
for (const key of Object.keys(transforms)){
|
|
370
|
+
const transform = transforms[key];
|
|
371
|
+
if (transform.shouldTransform) {
|
|
372
|
+
obj[key] = Array.prototype.concat.call([], obj[key]);
|
|
373
|
+
if ("function" == typeof transform.transformFunction) obj[key] = obj[key].map(transform.transformFunction);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
const getFileName = (input)=>{
|
|
378
|
+
const m = /([^\\\/]+)$/.exec(input);
|
|
379
|
+
return m ? m[1] : "";
|
|
380
|
+
};
|
|
381
|
+
const camelcaseOptionName = (name)=>name.split(".").map((v, i)=>0 === i ? camelcase(v) : v).join(".");
|
|
382
|
+
class CACError extends Error {
|
|
383
|
+
constructor(message){
|
|
384
|
+
super(message);
|
|
385
|
+
this.name = this.constructor.name;
|
|
386
|
+
if ("function" == typeof Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
|
|
387
|
+
else this.stack = new Error(message).stack;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
class Option {
|
|
391
|
+
constructor(rawName, description, config){
|
|
392
|
+
this.rawName = rawName;
|
|
393
|
+
this.description = description;
|
|
394
|
+
this.config = Object.assign({}, config);
|
|
395
|
+
rawName = rawName.replace(/\.\*/g, "");
|
|
396
|
+
this.negated = false;
|
|
397
|
+
this.names = removeBrackets(rawName).split(",").map((v)=>{
|
|
398
|
+
let name = v.trim().replace(/^-{1,2}/, "");
|
|
399
|
+
if (name.startsWith("no-")) {
|
|
400
|
+
this.negated = true;
|
|
401
|
+
name = name.replace(/^no-/, "");
|
|
402
|
+
}
|
|
403
|
+
return camelcaseOptionName(name);
|
|
404
|
+
}).sort((a, b)=>a.length > b.length ? 1 : -1);
|
|
405
|
+
this.name = this.names[this.names.length - 1];
|
|
406
|
+
if (this.negated && null == this.config.default) this.config.default = true;
|
|
407
|
+
if (rawName.includes("<")) this.required = true;
|
|
408
|
+
else if (rawName.includes("[")) this.required = false;
|
|
409
|
+
else this.isBoolean = true;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
const processArgs = process.argv;
|
|
413
|
+
const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
|
|
414
|
+
class Command {
|
|
415
|
+
constructor(rawName, description, config = {}, cli){
|
|
416
|
+
this.rawName = rawName;
|
|
417
|
+
this.description = description;
|
|
418
|
+
this.config = config;
|
|
419
|
+
this.cli = cli;
|
|
420
|
+
this.options = [];
|
|
421
|
+
this.aliasNames = [];
|
|
422
|
+
this.name = removeBrackets(rawName);
|
|
423
|
+
this.args = findAllBrackets(rawName);
|
|
424
|
+
this.examples = [];
|
|
425
|
+
}
|
|
426
|
+
usage(text) {
|
|
427
|
+
this.usageText = text;
|
|
428
|
+
return this;
|
|
429
|
+
}
|
|
430
|
+
allowUnknownOptions() {
|
|
431
|
+
this.config.allowUnknownOptions = true;
|
|
432
|
+
return this;
|
|
433
|
+
}
|
|
434
|
+
ignoreOptionDefaultValue() {
|
|
435
|
+
this.config.ignoreOptionDefaultValue = true;
|
|
436
|
+
return this;
|
|
437
|
+
}
|
|
438
|
+
version(version, customFlags = "-v, --version") {
|
|
439
|
+
this.versionNumber = version;
|
|
440
|
+
this.option(customFlags, "Display version number");
|
|
441
|
+
return this;
|
|
442
|
+
}
|
|
443
|
+
example(example) {
|
|
444
|
+
this.examples.push(example);
|
|
445
|
+
return this;
|
|
446
|
+
}
|
|
447
|
+
option(rawName, description, config) {
|
|
448
|
+
const option = new Option(rawName, description, config);
|
|
449
|
+
this.options.push(option);
|
|
450
|
+
return this;
|
|
451
|
+
}
|
|
452
|
+
alias(name) {
|
|
453
|
+
this.aliasNames.push(name);
|
|
454
|
+
return this;
|
|
455
|
+
}
|
|
456
|
+
action(callback) {
|
|
457
|
+
this.commandAction = callback;
|
|
458
|
+
return this;
|
|
459
|
+
}
|
|
460
|
+
isMatched(name) {
|
|
461
|
+
return this.name === name || this.aliasNames.includes(name);
|
|
462
|
+
}
|
|
463
|
+
get isDefaultCommand() {
|
|
464
|
+
return "" === this.name || this.aliasNames.includes("!");
|
|
465
|
+
}
|
|
466
|
+
get isGlobalCommand() {
|
|
467
|
+
return this instanceof GlobalCommand;
|
|
468
|
+
}
|
|
469
|
+
hasOption(name) {
|
|
470
|
+
name = name.split(".")[0];
|
|
471
|
+
return this.options.find((option)=>option.names.includes(name));
|
|
472
|
+
}
|
|
473
|
+
outputHelp() {
|
|
474
|
+
const { name, commands } = this.cli;
|
|
475
|
+
const { versionNumber, options: globalOptions, helpCallback } = this.cli.globalCommand;
|
|
476
|
+
let sections = [
|
|
477
|
+
{
|
|
478
|
+
body: `${name}${versionNumber ? `/${versionNumber}` : ""}`
|
|
479
|
+
}
|
|
480
|
+
];
|
|
481
|
+
sections.push({
|
|
482
|
+
title: "Usage",
|
|
483
|
+
body: ` $ ${name} ${this.usageText || this.rawName}`
|
|
484
|
+
});
|
|
485
|
+
const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
|
|
486
|
+
if (showCommands) {
|
|
487
|
+
const longestCommandName = findLongest(commands.map((command)=>command.rawName));
|
|
488
|
+
sections.push({
|
|
489
|
+
title: "Commands",
|
|
490
|
+
body: commands.map((command)=>` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`).join("\n")
|
|
491
|
+
});
|
|
492
|
+
sections.push({
|
|
493
|
+
title: "For more info, run any command with the `--help` flag",
|
|
494
|
+
body: commands.map((command)=>` $ ${name}${"" === command.name ? "" : ` ${command.name}`} --help`).join("\n")
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
let options = this.isGlobalCommand ? globalOptions : [
|
|
498
|
+
...this.options,
|
|
499
|
+
...globalOptions || []
|
|
500
|
+
];
|
|
501
|
+
if (!this.isGlobalCommand && !this.isDefaultCommand) options = options.filter((option)=>"version" !== option.name);
|
|
502
|
+
if (options.length > 0) {
|
|
503
|
+
const longestOptionName = findLongest(options.map((option)=>option.rawName));
|
|
504
|
+
sections.push({
|
|
505
|
+
title: "Options",
|
|
506
|
+
body: options.map((option)=>` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${void 0 === option.config.default ? "" : `(default: ${option.config.default})`}`).join("\n")
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
if (this.examples.length > 0) sections.push({
|
|
510
|
+
title: "Examples",
|
|
511
|
+
body: this.examples.map((example)=>{
|
|
512
|
+
if ("function" == typeof example) return example(name);
|
|
513
|
+
return example;
|
|
514
|
+
}).join("\n")
|
|
515
|
+
});
|
|
516
|
+
if (helpCallback) sections = helpCallback(sections) || sections;
|
|
517
|
+
console.log(sections.map((section)=>section.title ? `${section.title}:
|
|
518
|
+
${section.body}` : section.body).join("\n\n"));
|
|
519
|
+
}
|
|
520
|
+
outputVersion() {
|
|
521
|
+
const { name } = this.cli;
|
|
522
|
+
const { versionNumber } = this.cli.globalCommand;
|
|
523
|
+
if (versionNumber) console.log(`${name}/${versionNumber} ${platformInfo}`);
|
|
524
|
+
}
|
|
525
|
+
checkRequiredArgs() {
|
|
526
|
+
const minimalArgsCount = this.args.filter((arg)=>arg.required).length;
|
|
527
|
+
if (this.cli.args.length < minimalArgsCount) throw new CACError(`missing required args for command \`${this.rawName}\``);
|
|
528
|
+
}
|
|
529
|
+
checkUnknownOptions() {
|
|
530
|
+
const { options, globalCommand } = this.cli;
|
|
531
|
+
if (!this.config.allowUnknownOptions) {
|
|
532
|
+
for (const name of Object.keys(options))if ("--" !== name && !this.hasOption(name) && !globalCommand.hasOption(name)) throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
checkOptionValue() {
|
|
536
|
+
const { options: parsedOptions, globalCommand } = this.cli;
|
|
537
|
+
const options = [
|
|
538
|
+
...globalCommand.options,
|
|
539
|
+
...this.options
|
|
540
|
+
];
|
|
541
|
+
for (const option of options){
|
|
542
|
+
const value = parsedOptions[option.name.split(".")[0]];
|
|
543
|
+
if (option.required) {
|
|
544
|
+
const hasNegated = options.some((o)=>o.negated && o.names.includes(option.name));
|
|
545
|
+
if (true === value || false === value && !hasNegated) throw new CACError(`option \`${option.rawName}\` value is missing`);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
class GlobalCommand extends Command {
|
|
551
|
+
constructor(cli){
|
|
552
|
+
super("@@global@@", "", {}, cli);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
var __assign = Object.assign;
|
|
556
|
+
class CAC extends __WEBPACK_EXTERNAL_MODULE_events__.EventEmitter {
|
|
557
|
+
constructor(name = ""){
|
|
558
|
+
super();
|
|
559
|
+
this.name = name;
|
|
560
|
+
this.commands = [];
|
|
561
|
+
this.rawArgs = [];
|
|
562
|
+
this.args = [];
|
|
563
|
+
this.options = {};
|
|
564
|
+
this.globalCommand = new GlobalCommand(this);
|
|
565
|
+
this.globalCommand.usage("<command> [options]");
|
|
566
|
+
}
|
|
567
|
+
usage(text) {
|
|
568
|
+
this.globalCommand.usage(text);
|
|
569
|
+
return this;
|
|
570
|
+
}
|
|
571
|
+
command(rawName, description, config) {
|
|
572
|
+
const command = new Command(rawName, description || "", config, this);
|
|
573
|
+
command.globalCommand = this.globalCommand;
|
|
574
|
+
this.commands.push(command);
|
|
575
|
+
return command;
|
|
576
|
+
}
|
|
577
|
+
option(rawName, description, config) {
|
|
578
|
+
this.globalCommand.option(rawName, description, config);
|
|
579
|
+
return this;
|
|
580
|
+
}
|
|
581
|
+
help(callback) {
|
|
582
|
+
this.globalCommand.option("-h, --help", "Display this message");
|
|
583
|
+
this.globalCommand.helpCallback = callback;
|
|
584
|
+
this.showHelpOnExit = true;
|
|
585
|
+
return this;
|
|
586
|
+
}
|
|
587
|
+
version(version, customFlags = "-v, --version") {
|
|
588
|
+
this.globalCommand.version(version, customFlags);
|
|
589
|
+
this.showVersionOnExit = true;
|
|
590
|
+
return this;
|
|
591
|
+
}
|
|
592
|
+
example(example) {
|
|
593
|
+
this.globalCommand.example(example);
|
|
594
|
+
return this;
|
|
595
|
+
}
|
|
596
|
+
outputHelp() {
|
|
597
|
+
if (this.matchedCommand) this.matchedCommand.outputHelp();
|
|
598
|
+
else this.globalCommand.outputHelp();
|
|
599
|
+
}
|
|
600
|
+
outputVersion() {
|
|
601
|
+
this.globalCommand.outputVersion();
|
|
602
|
+
}
|
|
603
|
+
setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
|
|
604
|
+
this.args = args;
|
|
605
|
+
this.options = options;
|
|
606
|
+
if (matchedCommand) this.matchedCommand = matchedCommand;
|
|
607
|
+
if (matchedCommandName) this.matchedCommandName = matchedCommandName;
|
|
608
|
+
return this;
|
|
609
|
+
}
|
|
610
|
+
unsetMatchedCommand() {
|
|
611
|
+
this.matchedCommand = void 0;
|
|
612
|
+
this.matchedCommandName = void 0;
|
|
613
|
+
}
|
|
614
|
+
parse(argv = processArgs, { run = true } = {}) {
|
|
615
|
+
this.rawArgs = argv;
|
|
616
|
+
if (!this.name) this.name = argv[1] ? getFileName(argv[1]) : "cli";
|
|
617
|
+
let shouldParse = true;
|
|
618
|
+
for (const command of this.commands){
|
|
619
|
+
const parsed = this.mri(argv.slice(2), command);
|
|
620
|
+
const commandName = parsed.args[0];
|
|
621
|
+
if (command.isMatched(commandName)) {
|
|
622
|
+
shouldParse = false;
|
|
623
|
+
const parsedInfo = __assign(__assign({}, parsed), {
|
|
624
|
+
args: parsed.args.slice(1)
|
|
625
|
+
});
|
|
626
|
+
this.setParsedInfo(parsedInfo, command, commandName);
|
|
627
|
+
this.emit(`command:${commandName}`, command);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
if (shouldParse) {
|
|
631
|
+
for (const command of this.commands)if ("" === command.name) {
|
|
632
|
+
shouldParse = false;
|
|
633
|
+
const parsed = this.mri(argv.slice(2), command);
|
|
634
|
+
this.setParsedInfo(parsed, command);
|
|
635
|
+
this.emit("command:!", command);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
if (shouldParse) {
|
|
639
|
+
const parsed = this.mri(argv.slice(2));
|
|
640
|
+
this.setParsedInfo(parsed);
|
|
641
|
+
}
|
|
642
|
+
if (this.options.help && this.showHelpOnExit) {
|
|
643
|
+
this.outputHelp();
|
|
644
|
+
run = false;
|
|
645
|
+
this.unsetMatchedCommand();
|
|
646
|
+
}
|
|
647
|
+
if (this.options.version && this.showVersionOnExit && null == this.matchedCommandName) {
|
|
648
|
+
this.outputVersion();
|
|
649
|
+
run = false;
|
|
650
|
+
this.unsetMatchedCommand();
|
|
651
|
+
}
|
|
652
|
+
const parsedArgv = {
|
|
653
|
+
args: this.args,
|
|
654
|
+
options: this.options
|
|
655
|
+
};
|
|
656
|
+
if (run) this.runMatchedCommand();
|
|
657
|
+
if (!this.matchedCommand && this.args[0]) this.emit("command:*");
|
|
658
|
+
return parsedArgv;
|
|
659
|
+
}
|
|
660
|
+
mri(argv, command) {
|
|
661
|
+
const cliOptions = [
|
|
662
|
+
...this.globalCommand.options,
|
|
663
|
+
...command ? command.options : []
|
|
664
|
+
];
|
|
665
|
+
const mriOptions = getMriOptions(cliOptions);
|
|
666
|
+
let argsAfterDoubleDashes = [];
|
|
667
|
+
const doubleDashesIndex = argv.indexOf("--");
|
|
668
|
+
if (doubleDashesIndex > -1) {
|
|
669
|
+
argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
|
|
670
|
+
argv = argv.slice(0, doubleDashesIndex);
|
|
671
|
+
}
|
|
672
|
+
let parsed = mri2(argv, mriOptions);
|
|
673
|
+
parsed = Object.keys(parsed).reduce((res, name)=>__assign(__assign({}, res), {
|
|
674
|
+
[camelcaseOptionName(name)]: parsed[name]
|
|
675
|
+
}), {
|
|
676
|
+
_: []
|
|
677
|
+
});
|
|
678
|
+
const args = parsed._;
|
|
679
|
+
const options = {
|
|
680
|
+
"--": argsAfterDoubleDashes
|
|
681
|
+
};
|
|
682
|
+
const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
|
|
683
|
+
let transforms = Object.create(null);
|
|
684
|
+
for (const cliOption of cliOptions){
|
|
685
|
+
if (!ignoreDefault && void 0 !== cliOption.config.default) for (const name of cliOption.names)options[name] = cliOption.config.default;
|
|
686
|
+
if (Array.isArray(cliOption.config.type)) {
|
|
687
|
+
if (void 0 === transforms[cliOption.name]) {
|
|
688
|
+
transforms[cliOption.name] = Object.create(null);
|
|
689
|
+
transforms[cliOption.name]["shouldTransform"] = true;
|
|
690
|
+
transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
for (const key of Object.keys(parsed))if ("_" !== key) {
|
|
695
|
+
const keys = key.split(".");
|
|
696
|
+
setDotProp(options, keys, parsed[key]);
|
|
697
|
+
setByType(options, transforms);
|
|
698
|
+
}
|
|
699
|
+
return {
|
|
700
|
+
args,
|
|
701
|
+
options
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
runMatchedCommand() {
|
|
705
|
+
const { args, options, matchedCommand: command } = this;
|
|
706
|
+
if (!command || !command.commandAction) return;
|
|
707
|
+
command.checkUnknownOptions();
|
|
708
|
+
command.checkOptionValue();
|
|
709
|
+
command.checkRequiredArgs();
|
|
710
|
+
const actionArgs = [];
|
|
711
|
+
command.args.forEach((arg, index)=>{
|
|
712
|
+
if (arg.variadic) actionArgs.push(args.slice(index));
|
|
713
|
+
else actionArgs.push(args[index]);
|
|
714
|
+
});
|
|
715
|
+
actionArgs.push(options);
|
|
716
|
+
return command.commandAction.apply(this, actionArgs);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
const cac = (name = "")=>new CAC(name);
|
|
720
|
+
const dist = cac;
|
|
721
|
+
var picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
|
|
722
|
+
var external_node_fs_ = __webpack_require__("node:fs");
|
|
723
|
+
const commonOptions = (command)=>command.option("-c, --config <path>", "config file").option("--config-name <name>", "Name(s) of the configuration to use.", {
|
|
724
|
+
type: [
|
|
725
|
+
String
|
|
726
|
+
],
|
|
727
|
+
default: []
|
|
728
|
+
}).option("--config-loader <loader>", "Specify the loader to load the config file, can be `native` or `register`.", {
|
|
729
|
+
default: "register"
|
|
730
|
+
}).option("--env <env>", "env passed to config function", {
|
|
731
|
+
type: [
|
|
732
|
+
String
|
|
733
|
+
],
|
|
734
|
+
default: []
|
|
735
|
+
}).option("--node-env <value>", "sets `process.env.NODE_ENV` to be specified value");
|
|
736
|
+
function normalizeDevtoolOption(value) {
|
|
737
|
+
if ("string" == typeof value) {
|
|
738
|
+
const trimmed = value.trim();
|
|
739
|
+
if ("" === trimmed || "false" === trimmed) return false;
|
|
740
|
+
if ("true" === trimmed) return "source-map";
|
|
741
|
+
return trimmed;
|
|
742
|
+
}
|
|
743
|
+
if ("boolean" == typeof value) return value ? "source-map" : false;
|
|
744
|
+
}
|
|
745
|
+
const normalizeCommonOptions = (options, action)=>{
|
|
746
|
+
const isEmptyArray = (arr)=>Array.isArray(arr) && 0 === arr.length;
|
|
747
|
+
for (const key of [
|
|
748
|
+
"entry",
|
|
749
|
+
"configName"
|
|
750
|
+
]){
|
|
751
|
+
const val = options[key];
|
|
752
|
+
if (isEmptyArray(val)) options[key] = void 0;
|
|
753
|
+
}
|
|
754
|
+
const env = Array.isArray(options.env) ? normalizeEnvToObject(options) : {};
|
|
755
|
+
options.env = env;
|
|
756
|
+
if ("serve" === action) setBuiltinEnvArg(env, "SERVE", true);
|
|
757
|
+
else if ("build" === action) if (options.watch) setBuiltinEnvArg(env, "WATCH", true);
|
|
758
|
+
else {
|
|
759
|
+
setBuiltinEnvArg(env, "BUNDLE", true);
|
|
760
|
+
setBuiltinEnvArg(env, "BUILD", true);
|
|
761
|
+
}
|
|
762
|
+
if ("devtool" in options) options.devtool = normalizeDevtoolOption(options.devtool);
|
|
763
|
+
};
|
|
764
|
+
const commonOptionsForBuildAndServe = (command)=>command.option("--analyze", "analyze").option("-d, --devtool <value>", "specify a developer tool for debugging. Defaults to `cheap-module-source-map` in development and `source-map` in production.").option("--entry <entry>", "entry file", {
|
|
765
|
+
type: [
|
|
766
|
+
String
|
|
767
|
+
],
|
|
768
|
+
default: []
|
|
769
|
+
}).option("-m, --mode <mode>", "mode").option("-o, --output-path <dir>", "output path dir").option("--profile", "capture timing information for each module").option("-w, --watch", "watch");
|
|
770
|
+
function setBuiltinEnvArg(env, envNameSuffix, value) {
|
|
771
|
+
const envName = `RSPACK_${envNameSuffix}`;
|
|
772
|
+
if (!(envName in env)) env[envName] = value;
|
|
773
|
+
}
|
|
774
|
+
function normalizeEnvToObject(options) {
|
|
157
775
|
function parseValue(previous, value) {
|
|
158
776
|
const [allKeys, val] = value.split(/=(.+)/, 2);
|
|
159
777
|
const splitKeys = allKeys.split(/\.(?!$)/);
|
|
@@ -172,155 +790,84 @@ function normalizeEnv(argv) {
|
|
|
172
790
|
});
|
|
173
791
|
return previous;
|
|
174
792
|
}
|
|
175
|
-
|
|
176
|
-
argv.env = envObj;
|
|
177
|
-
}
|
|
178
|
-
function setBuiltinEnvArg(env, envNameSuffix, value) {
|
|
179
|
-
const envNames = [
|
|
180
|
-
`RSPACK_${envNameSuffix}`
|
|
181
|
-
];
|
|
182
|
-
for (const envName of envNames)if (!(envName in env)) env[envName] = value;
|
|
183
|
-
}
|
|
184
|
-
function ensureEnvObject(options) {
|
|
185
|
-
if (Array.isArray(options.env)) normalizeEnv(options);
|
|
186
|
-
options.env = options.env || {};
|
|
187
|
-
return options.env;
|
|
793
|
+
return (options.env ?? []).reduce(parseValue, {});
|
|
188
794
|
}
|
|
189
795
|
function setDefaultNodeEnv(options, defaultEnv) {
|
|
190
|
-
if (void 0
|
|
191
|
-
process.env.NODE_ENV = "string" == typeof options.nodeEnv ? options.nodeEnv : defaultEnv;
|
|
796
|
+
if (void 0 === process.env.NODE_ENV) process.env.NODE_ENV = "string" == typeof options.nodeEnv ? options.nodeEnv : defaultEnv;
|
|
192
797
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
default: false,
|
|
213
|
-
describe: "capture timing information for each module"
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
}, async (options)=>{
|
|
217
|
-
setDefaultNodeEnv(options, "production");
|
|
218
|
-
const env = ensureEnvObject(options);
|
|
219
|
-
if (options.watch) setBuiltinEnvArg(env, "WATCH", true);
|
|
220
|
-
else {
|
|
221
|
-
setBuiltinEnvArg(env, "BUNDLE", true);
|
|
222
|
-
setBuiltinEnvArg(env, "BUILD", true);
|
|
223
|
-
}
|
|
224
|
-
const logger = cli.getLogger();
|
|
225
|
-
let createJsonStringifyStream;
|
|
226
|
-
if (options.json) {
|
|
227
|
-
const jsonExt = await import("@discoveryjs/json-ext");
|
|
228
|
-
createJsonStringifyStream = jsonExt.default.stringifyStream;
|
|
229
|
-
}
|
|
230
|
-
const errorHandler = (error, stats)=>{
|
|
231
|
-
if (error) {
|
|
232
|
-
logger.error(error);
|
|
233
|
-
process.exit(2);
|
|
234
|
-
}
|
|
235
|
-
if (stats?.hasErrors()) process.exitCode = 1;
|
|
236
|
-
if (!compiler || !stats) return;
|
|
237
|
-
const statsOptions = cli.isMultipleCompiler(compiler) ? {
|
|
238
|
-
children: compiler.compilers.map((compiler)=>compiler.options ? compiler.options.stats : void 0)
|
|
239
|
-
} : compiler.options ? compiler.options.stats : void 0;
|
|
240
|
-
if (options.json && createJsonStringifyStream) {
|
|
241
|
-
const handleWriteError = (error)=>{
|
|
242
|
-
logger.error(error);
|
|
243
|
-
process.exit(2);
|
|
244
|
-
};
|
|
245
|
-
if (true === options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(process.stdout).on("error", handleWriteError).on("close", ()=>process.stdout.write("\n"));
|
|
246
|
-
else if ("string" == typeof options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(external_node_fs_.createWriteStream(options.json)).on("error", handleWriteError).on("close", ()=>{
|
|
247
|
-
process.stderr.write(`[rspack-cli] ${cli.colors.green(`stats are successfully stored as json to ${options.json}`)}\n`);
|
|
248
|
-
});
|
|
249
|
-
} else {
|
|
250
|
-
const printedStats = stats.toString(statsOptions);
|
|
251
|
-
if (printedStats) logger.raw(printedStats);
|
|
252
|
-
}
|
|
798
|
+
async function runBuild(cli, options) {
|
|
799
|
+
setDefaultNodeEnv(options, "production");
|
|
800
|
+
normalizeCommonOptions(options, "build");
|
|
801
|
+
const logger = cli.getLogger();
|
|
802
|
+
let createJsonStringifyStream;
|
|
803
|
+
if (options.json) {
|
|
804
|
+
const jsonExt = await import("@discoveryjs/json-ext");
|
|
805
|
+
createJsonStringifyStream = jsonExt.default.stringifyStream;
|
|
806
|
+
}
|
|
807
|
+
const errorHandler = (error, stats)=>{
|
|
808
|
+
if (error) {
|
|
809
|
+
logger.error(error);
|
|
810
|
+
process.exit(2);
|
|
811
|
+
}
|
|
812
|
+
if (stats?.hasErrors()) process.exitCode = 1;
|
|
813
|
+
if (!compiler || !stats) return;
|
|
814
|
+
const getStatsOptions = ()=>{
|
|
815
|
+
if (cli.isMultipleCompiler(compiler)) return {
|
|
816
|
+
children: compiler.compilers.map((item)=>item.options ? item.options.stats : void 0)
|
|
253
817
|
};
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
818
|
+
return compiler.options?.stats;
|
|
819
|
+
};
|
|
820
|
+
const statsOptions = getStatsOptions();
|
|
821
|
+
if (options.json && createJsonStringifyStream) {
|
|
822
|
+
const handleWriteError = (error)=>{
|
|
823
|
+
logger.error(error);
|
|
824
|
+
process.exit(2);
|
|
259
825
|
};
|
|
260
|
-
|
|
261
|
-
if (
|
|
262
|
-
|
|
263
|
-
compiler.close((closeErr)=>{
|
|
264
|
-
if (closeErr) logger.error(closeErr);
|
|
265
|
-
errorHandler(error, stats);
|
|
266
|
-
});
|
|
826
|
+
if (true === options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(process.stdout).on("error", handleWriteError).on("close", ()=>process.stdout.write("\n"));
|
|
827
|
+
else if ("string" == typeof options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(external_node_fs_["default"].createWriteStream(options.json)).on("error", handleWriteError).on("close", ()=>{
|
|
828
|
+
process.stderr.write(`[rspack-cli] ${cli.colors.green(`stats are successfully stored as json to ${options.json}`)}\n`);
|
|
267
829
|
});
|
|
830
|
+
} else {
|
|
831
|
+
const printedStats = stats.toString(statsOptions);
|
|
832
|
+
if (printedStats) logger.raw(printedStats);
|
|
833
|
+
}
|
|
834
|
+
};
|
|
835
|
+
const compiler = await cli.createCompiler(options, "build", errorHandler);
|
|
836
|
+
if (!compiler || cli.isWatch(compiler)) return;
|
|
837
|
+
compiler.run((error, stats)=>{
|
|
838
|
+
compiler.close((closeErr)=>{
|
|
839
|
+
if (closeErr) logger.error(closeErr);
|
|
840
|
+
errorHandler(error, stats);
|
|
841
|
+
});
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
class BuildCommand {
|
|
845
|
+
async apply(cli) {
|
|
846
|
+
const command = cli.program.command("", "run the Rspack build").alias("build").alias("bundle").alias("b");
|
|
847
|
+
commonOptionsForBuildAndServe(commonOptions(command)).option("--json [path]", "emit stats json");
|
|
848
|
+
command.action(async (options)=>{
|
|
849
|
+
await runBuild(cli, options);
|
|
268
850
|
});
|
|
269
851
|
}
|
|
270
852
|
}
|
|
271
|
-
|
|
272
|
-
yargs.positional("dir", {
|
|
273
|
-
type: "string",
|
|
274
|
-
describe: "directory want to preview"
|
|
275
|
-
});
|
|
276
|
-
return commonOptions(yargs).options({
|
|
277
|
-
publicPath: {
|
|
278
|
-
type: "string",
|
|
279
|
-
describe: "static resource server path"
|
|
280
|
-
},
|
|
281
|
-
port: {
|
|
282
|
-
type: "number",
|
|
283
|
-
describe: "preview server port"
|
|
284
|
-
},
|
|
285
|
-
host: {
|
|
286
|
-
type: "string",
|
|
287
|
-
describe: "preview server host"
|
|
288
|
-
},
|
|
289
|
-
open: {
|
|
290
|
-
type: "boolean",
|
|
291
|
-
describe: "open browser"
|
|
292
|
-
},
|
|
293
|
-
server: {
|
|
294
|
-
type: "string",
|
|
295
|
-
describe: "Configuration items for the server."
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
};
|
|
299
|
-
const defaultRoot = "dist";
|
|
853
|
+
var rspackCore = __webpack_require__("./src/utils/rspackCore.ts");
|
|
300
854
|
class PreviewCommand {
|
|
301
855
|
async apply(cli) {
|
|
302
|
-
cli.program.command([
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
"p"
|
|
306
|
-
], "run the rspack server for build output", previewOptions, async (options)=>{
|
|
856
|
+
const command = cli.program.command("preview [dir]", "run the Rspack server for build output").alias("p");
|
|
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.");
|
|
858
|
+
command.action(async (dir, options)=>{
|
|
307
859
|
setDefaultNodeEnv(options, "production");
|
|
308
|
-
|
|
309
|
-
...options,
|
|
310
|
-
argv: {
|
|
311
|
-
...options
|
|
312
|
-
}
|
|
313
|
-
};
|
|
860
|
+
normalizeCommonOptions(options, "preview");
|
|
314
861
|
const { RspackDevServer } = await import("@rspack/dev-server");
|
|
315
|
-
let { config } = await cli.loadConfig(
|
|
316
|
-
config = await getPreviewConfig(config, options);
|
|
862
|
+
let { config } = await cli.loadConfig(options);
|
|
863
|
+
config = await getPreviewConfig(config, options, dir);
|
|
317
864
|
if (!Array.isArray(config)) config = [
|
|
318
865
|
config
|
|
319
866
|
];
|
|
320
|
-
|
|
321
|
-
const devServerOptions =
|
|
867
|
+
const singleConfig = config.find((item)=>item.devServer) || config[0];
|
|
868
|
+
const devServerOptions = singleConfig.devServer;
|
|
322
869
|
try {
|
|
323
|
-
const compiler = (0,
|
|
870
|
+
const compiler = (0, rspackCore.Z)({
|
|
324
871
|
entry: {}
|
|
325
872
|
});
|
|
326
873
|
if (!compiler) return;
|
|
@@ -334,11 +881,12 @@ class PreviewCommand {
|
|
|
334
881
|
});
|
|
335
882
|
}
|
|
336
883
|
}
|
|
337
|
-
async function getPreviewConfig(item, options) {
|
|
884
|
+
async function getPreviewConfig(item, options, dir) {
|
|
885
|
+
const DEFAULT_ROOT = "dist";
|
|
338
886
|
const internalPreviewConfig = async (item)=>{
|
|
339
887
|
item.devServer = {
|
|
340
888
|
static: {
|
|
341
|
-
directory:
|
|
889
|
+
directory: dir ? external_node_path_["default"].join(item.context ?? process.cwd(), dir) : item.output?.path ?? external_node_path_["default"].join(item.context ?? process.cwd(), DEFAULT_ROOT),
|
|
342
890
|
publicPath: options.publicPath ?? "/"
|
|
343
891
|
},
|
|
344
892
|
port: options.port ?? 8080,
|
|
@@ -353,42 +901,21 @@ async function getPreviewConfig(item, options) {
|
|
|
353
901
|
if (Array.isArray(item)) return Promise.all(item.map(internalPreviewConfig));
|
|
354
902
|
return internalPreviewConfig(item);
|
|
355
903
|
}
|
|
904
|
+
function normalizeHotOption(value) {
|
|
905
|
+
if ("boolean" == typeof value || "only" === value) return value;
|
|
906
|
+
if ("false" === value) return false;
|
|
907
|
+
return true;
|
|
908
|
+
}
|
|
356
909
|
class ServeCommand {
|
|
357
910
|
async apply(cli) {
|
|
358
|
-
cli.program.command(
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
"s",
|
|
362
|
-
"dev"
|
|
363
|
-
], "run the rspack dev server.", (yargs)=>commonOptionsForBuildAndServe(commonOptions(yargs)).options({
|
|
364
|
-
hot: {
|
|
365
|
-
coerce: (arg)=>{
|
|
366
|
-
if ("boolean" == typeof arg || "only" === arg) return arg;
|
|
367
|
-
if ("false" === arg) return false;
|
|
368
|
-
return true;
|
|
369
|
-
},
|
|
370
|
-
describe: "enables hot module replacement"
|
|
371
|
-
},
|
|
372
|
-
port: {
|
|
373
|
-
type: "number",
|
|
374
|
-
coerce: (arg)=>Number.isInteger(arg) ? arg : void 0,
|
|
375
|
-
describe: "allows to specify a port to use"
|
|
376
|
-
},
|
|
377
|
-
host: {
|
|
378
|
-
type: "string",
|
|
379
|
-
describe: "allows to specify a hostname to use"
|
|
380
|
-
}
|
|
381
|
-
}), async (options)=>{
|
|
911
|
+
const command = cli.program.command("serve", "run the rspack dev server.").alias("server").alias("s").alias("dev");
|
|
912
|
+
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");
|
|
913
|
+
command.action(async (options)=>{
|
|
382
914
|
setDefaultNodeEnv(options, "development");
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
...options,
|
|
386
|
-
argv: {
|
|
387
|
-
...options
|
|
388
|
-
}
|
|
389
|
-
};
|
|
915
|
+
normalizeCommonOptions(options, "serve");
|
|
916
|
+
options.hot = normalizeHotOption(options.hot);
|
|
390
917
|
const { RspackDevServer } = await import("@rspack/dev-server");
|
|
391
|
-
const compiler = await cli.createCompiler(
|
|
918
|
+
const compiler = await cli.createCompiler(options, "serve");
|
|
392
919
|
if (!compiler) return;
|
|
393
920
|
const compilers = cli.isMultipleCompiler(compiler) ? compiler.compilers : [
|
|
394
921
|
compiler
|
|
@@ -412,8 +939,8 @@ class ServeCommand {
|
|
|
412
939
|
}
|
|
413
940
|
}
|
|
414
941
|
const result = compilerForDevServer.options.devServer ??= {};
|
|
415
|
-
const setupMiddlewares = result
|
|
416
|
-
const lazyCompileMiddleware =
|
|
942
|
+
const { setupMiddlewares } = result;
|
|
943
|
+
const lazyCompileMiddleware = rspackCore.Z.experiments.lazyCompilationMiddleware(compiler);
|
|
417
944
|
result.setupMiddlewares = (middlewares, server)=>{
|
|
418
945
|
let finalMiddlewares = middlewares;
|
|
419
946
|
if (setupMiddlewares) finalMiddlewares = setupMiddlewares(finalMiddlewares, server);
|
|
@@ -424,7 +951,7 @@ class ServeCommand {
|
|
|
424
951
|
};
|
|
425
952
|
result.hot = options.hot ?? result.hot ?? true;
|
|
426
953
|
result.host = options.host || result.host;
|
|
427
|
-
result.port = options.port
|
|
954
|
+
result.port = options.port ?? result.port;
|
|
428
955
|
if (false !== result.client) {
|
|
429
956
|
if (true === result.client || null == result.client) result.client = {};
|
|
430
957
|
result.client = {
|
|
@@ -455,6 +982,7 @@ class ServeCommand {
|
|
|
455
982
|
});
|
|
456
983
|
}
|
|
457
984
|
}
|
|
985
|
+
var lib = __webpack_require__("../../node_modules/.pnpm/pirates@4.0.7/node_modules/pirates/lib/index.js");
|
|
458
986
|
const readPackageUp = (cwd = process.cwd())=>{
|
|
459
987
|
let currentDir = external_node_path_["default"].resolve(cwd);
|
|
460
988
|
let packageJsonPath = external_node_path_["default"].join(currentDir, "package.json");
|
|
@@ -471,17 +999,15 @@ const readPackageUp = (cwd = process.cwd())=>{
|
|
|
471
999
|
}
|
|
472
1000
|
};
|
|
473
1001
|
const utils_readPackageUp = readPackageUp;
|
|
474
|
-
const isEsmFile = (filePath
|
|
475
|
-
|
|
476
|
-
if (/\.(
|
|
477
|
-
if (/\.(cjs|cts)/.test(ext)) return false;
|
|
1002
|
+
const isEsmFile = (filePath)=>{
|
|
1003
|
+
if (/\.(mjs|mts)$/.test(filePath)) return true;
|
|
1004
|
+
if (/\.(cjs|cts)$/.test(filePath)) return false;
|
|
478
1005
|
const packageJson = utils_readPackageUp(external_node_path_["default"].dirname(filePath));
|
|
479
1006
|
return packageJson?.type === "module";
|
|
480
1007
|
};
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
const url = pathToFileURL(path).href;
|
|
1008
|
+
const crossImport = async (path)=>{
|
|
1009
|
+
if (isEsmFile(path)) {
|
|
1010
|
+
const url = (0, __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.pathToFileURL)(path).href;
|
|
485
1011
|
const { default: config } = await import(url);
|
|
486
1012
|
return config;
|
|
487
1013
|
}
|
|
@@ -509,7 +1035,7 @@ const isTsFile_isTsFile = (configPath)=>{
|
|
|
509
1035
|
return TS_EXTENSION.includes(ext);
|
|
510
1036
|
};
|
|
511
1037
|
const isTsFile = isTsFile_isTsFile;
|
|
512
|
-
const injectInlineSourceMap = ({
|
|
1038
|
+
const injectInlineSourceMap = ({ code, map })=>{
|
|
513
1039
|
if (map) {
|
|
514
1040
|
const base64Map = Buffer.from(map, "utf8").toString("base64");
|
|
515
1041
|
const sourceMapContent = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`;
|
|
@@ -518,7 +1044,7 @@ const injectInlineSourceMap = ({ filename, code, map })=>{
|
|
|
518
1044
|
return code;
|
|
519
1045
|
};
|
|
520
1046
|
function compile(sourcecode, filename) {
|
|
521
|
-
const { code, map } =
|
|
1047
|
+
const { code, map } = rspackCore.Z.experiments.swc.transformSync(sourcecode, {
|
|
522
1048
|
jsc: {
|
|
523
1049
|
parser: {
|
|
524
1050
|
syntax: "typescript",
|
|
@@ -535,16 +1061,15 @@ function compile(sourcecode, filename) {
|
|
|
535
1061
|
isModule: true
|
|
536
1062
|
});
|
|
537
1063
|
return injectInlineSourceMap({
|
|
538
|
-
filename,
|
|
539
1064
|
code,
|
|
540
1065
|
map
|
|
541
1066
|
});
|
|
542
1067
|
}
|
|
543
1068
|
const loadConfig_DEFAULT_CONFIG_NAME = "rspack.config";
|
|
544
1069
|
const registerLoader = (configPath)=>{
|
|
545
|
-
if (
|
|
1070
|
+
if (isEsmFile(configPath) && isTsFile(configPath)) return;
|
|
546
1071
|
if (!isTsFile(configPath)) throw new Error(`config file "${configPath}" is not supported.`);
|
|
547
|
-
addHook((code, filename)=>{
|
|
1072
|
+
(0, lib.addHook)((code, filename)=>{
|
|
548
1073
|
try {
|
|
549
1074
|
return compile(code, filename);
|
|
550
1075
|
} catch (err) {
|
|
@@ -607,9 +1132,9 @@ async function loadExtendedConfig(config, configPath, cwd, options) {
|
|
|
607
1132
|
}
|
|
608
1133
|
if (!external_node_fs_["default"].existsSync(resolvedPath)) throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
|
|
609
1134
|
if (isTsFile(resolvedPath) && "register" === options.configLoader) registerLoader(resolvedPath);
|
|
610
|
-
let loadedConfig = await crossImport(resolvedPath
|
|
1135
|
+
let loadedConfig = await crossImport(resolvedPath);
|
|
611
1136
|
if ("function" == typeof loadedConfig) {
|
|
612
|
-
loadedConfig = loadedConfig(options.
|
|
1137
|
+
loadedConfig = loadedConfig(options.env, options);
|
|
613
1138
|
if ("function" == typeof loadedConfig.then) loadedConfig = await loadedConfig;
|
|
614
1139
|
}
|
|
615
1140
|
const { config: extendedConfig, pathMap: extendedPathMap } = await loadExtendedConfig(loadedConfig, resolvedPath, cwd, options);
|
|
@@ -617,7 +1142,7 @@ async function loadExtendedConfig(config, configPath, cwd, options) {
|
|
|
617
1142
|
...pathMap.get(resultConfig) || [],
|
|
618
1143
|
...extendedPathMap.get(extendedConfig) || []
|
|
619
1144
|
];
|
|
620
|
-
resultConfig =
|
|
1145
|
+
resultConfig = rspackCore.Z.util.cleverMerge(extendedConfig, resultConfig);
|
|
621
1146
|
pathMap.set(resultConfig, configPaths);
|
|
622
1147
|
}
|
|
623
1148
|
return {
|
|
@@ -636,7 +1161,7 @@ async function loadRspackConfig(options, cwd = process.cwd()) {
|
|
|
636
1161
|
configPath = defaultConfig;
|
|
637
1162
|
}
|
|
638
1163
|
if (isTsFile(configPath) && "register" === options.configLoader) registerLoader(configPath);
|
|
639
|
-
const loadedConfig = await crossImport(configPath
|
|
1164
|
+
const loadedConfig = await crossImport(configPath);
|
|
640
1165
|
return {
|
|
641
1166
|
loadedConfig,
|
|
642
1167
|
configPath
|
|
@@ -646,19 +1171,22 @@ class RspackCLI {
|
|
|
646
1171
|
colors;
|
|
647
1172
|
program;
|
|
648
1173
|
constructor(){
|
|
1174
|
+
const program = dist("rspack");
|
|
649
1175
|
this.colors = this.createColors();
|
|
650
|
-
this.program =
|
|
1176
|
+
this.program = program;
|
|
1177
|
+
program.help();
|
|
1178
|
+
program.version("1.6.0");
|
|
651
1179
|
}
|
|
652
1180
|
async createCompiler(options, rspackCommand, callback) {
|
|
653
|
-
process.env.RSPACK_CONFIG_VALIDATE ??= "loose";
|
|
654
1181
|
let { config, pathMap } = await this.loadConfig(options);
|
|
655
1182
|
config = await this.buildConfig(config, pathMap, options, rspackCommand);
|
|
656
1183
|
const isWatch = Array.isArray(config) ? config.some((i)=>i.watch) : config.watch;
|
|
657
1184
|
let compiler;
|
|
658
1185
|
try {
|
|
659
|
-
compiler = (0,
|
|
1186
|
+
compiler = (0, rspackCore.Z)(config, isWatch ? callback : void 0);
|
|
1187
|
+
if (!isWatch && compiler) compiler.unsafeFastDrop = true;
|
|
660
1188
|
} catch (e) {
|
|
661
|
-
if (e instanceof
|
|
1189
|
+
if (e instanceof rspackCore.Z.ValidationError) {
|
|
662
1190
|
this.getLogger().error(e.message);
|
|
663
1191
|
process.exit(2);
|
|
664
1192
|
} else if (e instanceof Error) {
|
|
@@ -671,17 +1199,15 @@ class RspackCLI {
|
|
|
671
1199
|
return compiler;
|
|
672
1200
|
}
|
|
673
1201
|
createColors(useColor) {
|
|
674
|
-
const shouldUseColor = useColor || isColorSupported;
|
|
1202
|
+
const shouldUseColor = useColor || picocolors.isColorSupported;
|
|
675
1203
|
return {
|
|
676
|
-
...createColors(
|
|
677
|
-
useColor: shouldUseColor
|
|
678
|
-
}),
|
|
1204
|
+
...(0, picocolors.createColors)(shouldUseColor),
|
|
679
1205
|
isColorSupported: shouldUseColor
|
|
680
1206
|
};
|
|
681
1207
|
}
|
|
682
1208
|
getLogger() {
|
|
683
1209
|
return {
|
|
684
|
-
error: (val)=>console.error(`[rspack-cli] ${this.colors.red(
|
|
1210
|
+
error: (val)=>console.error(`[rspack-cli] ${this.colors.red(__WEBPACK_EXTERNAL_MODULE_node_util_1b29d436__["default"].format(val))}`),
|
|
685
1211
|
warn: (val)=>console.warn(`[rspack-cli] ${this.colors.yellow(val)}`),
|
|
686
1212
|
info: (val)=>console.info(`[rspack-cli] ${this.colors.cyan(val)}`),
|
|
687
1213
|
success: (val)=>console.log(`[rspack-cli] ${this.colors.green(val)}`),
|
|
@@ -690,13 +1216,8 @@ class RspackCLI {
|
|
|
690
1216
|
};
|
|
691
1217
|
}
|
|
692
1218
|
async run(argv) {
|
|
693
|
-
this.
|
|
694
|
-
this.program.
|
|
695
|
-
this.program.scriptName("rspack");
|
|
696
|
-
this.program.strictCommands(true).strict(true);
|
|
697
|
-
this.program.middleware(normalizeEnv);
|
|
698
|
-
this.registerCommands();
|
|
699
|
-
await this.program.parseAsync(hideBin(argv));
|
|
1219
|
+
await this.registerCommands();
|
|
1220
|
+
this.program.parse(argv);
|
|
700
1221
|
}
|
|
701
1222
|
async registerCommands() {
|
|
702
1223
|
const builtinCommands = [
|
|
@@ -704,7 +1225,7 @@ class RspackCLI {
|
|
|
704
1225
|
new ServeCommand(),
|
|
705
1226
|
new PreviewCommand()
|
|
706
1227
|
];
|
|
707
|
-
for (const command of builtinCommands)command.apply(this);
|
|
1228
|
+
for (const command of builtinCommands)await command.apply(this);
|
|
708
1229
|
}
|
|
709
1230
|
async buildConfig(item, pathMap, options, command) {
|
|
710
1231
|
const isBuild = "build" === command;
|
|
@@ -737,8 +1258,8 @@ class RspackCLI {
|
|
|
737
1258
|
if (void 0 === item.devtool) item.devtool = isBuild ? "source-map" : "cheap-module-source-map";
|
|
738
1259
|
if (void 0 !== options.devtool) item.devtool = options.devtool;
|
|
739
1260
|
if (isServe) {
|
|
740
|
-
const installed = (item.plugins ||= []).find((item)=>item instanceof
|
|
741
|
-
if (!installed) (item.plugins ??= []).push(new
|
|
1261
|
+
const installed = (item.plugins ||= []).find((item)=>item instanceof rspackCore.Z.ProgressPlugin);
|
|
1262
|
+
if (!installed) (item.plugins ??= []).push(new rspackCore.Z.ProgressPlugin());
|
|
742
1263
|
}
|
|
743
1264
|
const cacheOptions = item.experiments?.cache;
|
|
744
1265
|
if ("object" == typeof cacheOptions && "persistent" === cacheOptions.type) {
|
|
@@ -774,7 +1295,7 @@ class RspackCLI {
|
|
|
774
1295
|
};
|
|
775
1296
|
let { loadedConfig, configPath } = config;
|
|
776
1297
|
if ("function" == typeof loadedConfig) {
|
|
777
|
-
let functionResult = loadedConfig(options.
|
|
1298
|
+
let functionResult = loadedConfig(options.env, options);
|
|
778
1299
|
if ("function" == typeof functionResult.then) functionResult = await functionResult;
|
|
779
1300
|
loadedConfig = functionResult;
|
|
780
1301
|
}
|