@rspack-debug/cli 1.4.11 → 1.6.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.
- package/dist/{556.js → 0~361.js} +7 -7
- package/dist/{556.mjs → 1~361.mjs} +7 -6
- package/dist/cli.d.ts +15 -9
- package/dist/index.js +937 -379
- package/dist/index.mjs +928 -347
- 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/isTsFile.d.ts +1 -0
- package/dist/utils/loadConfig.d.ts +19 -4
- package/dist/utils/options.d.ts +23 -71
- package/dist/utils/rspackCore.d.ts +2 -0
- package/package.json +12 -15
package/dist/index.mjs
CHANGED
|
@@ -1,20 +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
|
|
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";
|
|
9
9
|
var __webpack_modules__ = {
|
|
10
|
-
"@
|
|
11
|
-
|
|
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__;
|
|
12
145
|
},
|
|
13
146
|
"node:fs": function(module) {
|
|
14
147
|
module.exports = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__;
|
|
15
148
|
},
|
|
16
149
|
"node:path": function(module) {
|
|
17
150
|
module.exports = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__;
|
|
151
|
+
},
|
|
152
|
+
path: function(module) {
|
|
153
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_path__;
|
|
18
154
|
}
|
|
19
155
|
};
|
|
20
156
|
var __webpack_module_cache__ = {};
|
|
@@ -22,9 +158,12 @@ function __webpack_require__(moduleId) {
|
|
|
22
158
|
var cachedModule = __webpack_module_cache__[moduleId];
|
|
23
159
|
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
24
160
|
var module = __webpack_module_cache__[moduleId] = {
|
|
161
|
+
id: moduleId,
|
|
162
|
+
loaded: false,
|
|
25
163
|
exports: {}
|
|
26
164
|
};
|
|
27
165
|
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
166
|
+
module.loaded = true;
|
|
28
167
|
return module.exports;
|
|
29
168
|
}
|
|
30
169
|
__webpack_require__.m = __webpack_modules__;
|
|
@@ -44,14 +183,21 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
44
183
|
}, []));
|
|
45
184
|
})();
|
|
46
185
|
(()=>{
|
|
47
|
-
__webpack_require__.u = (chunkId)=>"" + chunkId + ".mjs";
|
|
186
|
+
__webpack_require__.u = (chunkId)=>"1~" + chunkId + ".mjs";
|
|
48
187
|
})();
|
|
49
188
|
(()=>{
|
|
50
189
|
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
51
190
|
})();
|
|
191
|
+
(()=>{
|
|
192
|
+
__webpack_require__.nmd = (module)=>{
|
|
193
|
+
module.paths = [];
|
|
194
|
+
if (!module.children) module.children = [];
|
|
195
|
+
return module;
|
|
196
|
+
};
|
|
197
|
+
})();
|
|
52
198
|
(()=>{
|
|
53
199
|
var installedChunks = {
|
|
54
|
-
|
|
200
|
+
410: 0
|
|
55
201
|
};
|
|
56
202
|
var installChunk = (data)=>{
|
|
57
203
|
var __webpack_ids__ = data.__webpack_ids__;
|
|
@@ -87,72 +233,545 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
87
233
|
};
|
|
88
234
|
})();
|
|
89
235
|
var external_node_path_ = __webpack_require__("node:path");
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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]);
|
|
112
279
|
}
|
|
113
|
-
}
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
string: true,
|
|
139
|
-
describe: "env passed to config function"
|
|
140
|
-
},
|
|
141
|
-
devtool: {
|
|
142
|
-
type: "string",
|
|
143
|
-
describe: "Specify a developer tool for debugging. Defaults to `cheap-module-source-map` in development and `source-map` in production.",
|
|
144
|
-
alias: "d",
|
|
145
|
-
coerce: (arg)=>{
|
|
146
|
-
if ("true" === arg) return "source-map";
|
|
147
|
-
if ("false" === arg || "" === arg.trim()) return false;
|
|
148
|
-
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);
|
|
149
305
|
}
|
|
150
306
|
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
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) {
|
|
156
775
|
function parseValue(previous, value) {
|
|
157
776
|
const [allKeys, val] = value.split(/=(.+)/, 2);
|
|
158
777
|
const splitKeys = allKeys.split(/\.(?!$)/);
|
|
@@ -171,155 +790,84 @@ function normalizeEnv(argv) {
|
|
|
171
790
|
});
|
|
172
791
|
return previous;
|
|
173
792
|
}
|
|
174
|
-
|
|
175
|
-
argv.env = envObj;
|
|
176
|
-
}
|
|
177
|
-
function setBuiltinEnvArg(env, envNameSuffix, value) {
|
|
178
|
-
const envNames = [
|
|
179
|
-
`RSPACK_${envNameSuffix}`
|
|
180
|
-
];
|
|
181
|
-
for (const envName of envNames)if (!(envName in env)) env[envName] = value;
|
|
182
|
-
}
|
|
183
|
-
function ensureEnvObject(options) {
|
|
184
|
-
if (Array.isArray(options.env)) normalizeEnv(options);
|
|
185
|
-
options.env = options.env || {};
|
|
186
|
-
return options.env;
|
|
793
|
+
return (options.env ?? []).reduce(parseValue, {});
|
|
187
794
|
}
|
|
188
795
|
function setDefaultNodeEnv(options, defaultEnv) {
|
|
189
|
-
if (void 0
|
|
190
|
-
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;
|
|
191
797
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
default: false,
|
|
212
|
-
describe: "capture timing information for each module"
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
}, async (options)=>{
|
|
216
|
-
setDefaultNodeEnv(options, "production");
|
|
217
|
-
const env = ensureEnvObject(options);
|
|
218
|
-
if (options.watch) setBuiltinEnvArg(env, "WATCH", true);
|
|
219
|
-
else {
|
|
220
|
-
setBuiltinEnvArg(env, "BUNDLE", true);
|
|
221
|
-
setBuiltinEnvArg(env, "BUILD", true);
|
|
222
|
-
}
|
|
223
|
-
const logger = cli.getLogger();
|
|
224
|
-
let createJsonStringifyStream;
|
|
225
|
-
if (options.json) {
|
|
226
|
-
const jsonExt = await import("@discoveryjs/json-ext");
|
|
227
|
-
createJsonStringifyStream = jsonExt.default.stringifyStream;
|
|
228
|
-
}
|
|
229
|
-
const errorHandler = (error, stats)=>{
|
|
230
|
-
if (error) {
|
|
231
|
-
logger.error(error);
|
|
232
|
-
process.exit(2);
|
|
233
|
-
}
|
|
234
|
-
if (null == stats ? void 0 : stats.hasErrors()) process.exitCode = 1;
|
|
235
|
-
if (!compiler || !stats) return;
|
|
236
|
-
const statsOptions = cli.isMultipleCompiler(compiler) ? {
|
|
237
|
-
children: compiler.compilers.map((compiler)=>compiler.options ? compiler.options.stats : void 0)
|
|
238
|
-
} : compiler.options ? compiler.options.stats : void 0;
|
|
239
|
-
if (options.json && createJsonStringifyStream) {
|
|
240
|
-
const handleWriteError = (error)=>{
|
|
241
|
-
logger.error(error);
|
|
242
|
-
process.exit(2);
|
|
243
|
-
};
|
|
244
|
-
if (true === options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(process.stdout).on("error", handleWriteError).on("close", ()=>process.stdout.write("\n"));
|
|
245
|
-
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", ()=>{
|
|
246
|
-
process.stderr.write(`[rspack-cli] ${cli.colors.green(`stats are successfully stored as json to ${options.json}`)}\n`);
|
|
247
|
-
});
|
|
248
|
-
} else {
|
|
249
|
-
const printedStats = stats.toString(statsOptions);
|
|
250
|
-
if (printedStats) logger.raw(printedStats);
|
|
251
|
-
}
|
|
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)
|
|
252
817
|
};
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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);
|
|
258
825
|
};
|
|
259
|
-
|
|
260
|
-
if (
|
|
261
|
-
|
|
262
|
-
compiler.close((closeErr)=>{
|
|
263
|
-
if (closeErr) logger.error(closeErr);
|
|
264
|
-
errorHandler(error, stats);
|
|
265
|
-
});
|
|
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`);
|
|
266
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);
|
|
267
850
|
});
|
|
268
851
|
}
|
|
269
852
|
}
|
|
270
|
-
|
|
271
|
-
yargs.positional("dir", {
|
|
272
|
-
type: "string",
|
|
273
|
-
describe: "directory want to preview"
|
|
274
|
-
});
|
|
275
|
-
return commonOptions(yargs).options({
|
|
276
|
-
publicPath: {
|
|
277
|
-
type: "string",
|
|
278
|
-
describe: "static resource server path"
|
|
279
|
-
},
|
|
280
|
-
port: {
|
|
281
|
-
type: "number",
|
|
282
|
-
describe: "preview server port"
|
|
283
|
-
},
|
|
284
|
-
host: {
|
|
285
|
-
type: "string",
|
|
286
|
-
describe: "preview server host"
|
|
287
|
-
},
|
|
288
|
-
open: {
|
|
289
|
-
type: "boolean",
|
|
290
|
-
describe: "open browser"
|
|
291
|
-
},
|
|
292
|
-
server: {
|
|
293
|
-
type: "string",
|
|
294
|
-
describe: "Configuration items for the server."
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
};
|
|
298
|
-
const defaultRoot = "dist";
|
|
853
|
+
var rspackCore = __webpack_require__("./src/utils/rspackCore.ts");
|
|
299
854
|
class PreviewCommand {
|
|
300
855
|
async apply(cli) {
|
|
301
|
-
cli.program.command([
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
"p"
|
|
305
|
-
], "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)=>{
|
|
306
859
|
setDefaultNodeEnv(options, "production");
|
|
307
|
-
|
|
308
|
-
...options,
|
|
309
|
-
argv: {
|
|
310
|
-
...options
|
|
311
|
-
}
|
|
312
|
-
};
|
|
860
|
+
normalizeCommonOptions(options, "preview");
|
|
313
861
|
const { RspackDevServer } = await import("@rspack/dev-server");
|
|
314
|
-
let config = await cli.loadConfig(
|
|
315
|
-
config = await getPreviewConfig(config, options);
|
|
862
|
+
let { config } = await cli.loadConfig(options);
|
|
863
|
+
config = await getPreviewConfig(config, options, dir);
|
|
316
864
|
if (!Array.isArray(config)) config = [
|
|
317
865
|
config
|
|
318
866
|
];
|
|
319
|
-
|
|
320
|
-
const devServerOptions =
|
|
867
|
+
const singleConfig = config.find((item)=>item.devServer) || config[0];
|
|
868
|
+
const devServerOptions = singleConfig.devServer;
|
|
321
869
|
try {
|
|
322
|
-
const compiler = (0,
|
|
870
|
+
const compiler = (0, rspackCore.Z)({
|
|
323
871
|
entry: {}
|
|
324
872
|
});
|
|
325
873
|
if (!compiler) return;
|
|
@@ -333,62 +881,41 @@ class PreviewCommand {
|
|
|
333
881
|
});
|
|
334
882
|
}
|
|
335
883
|
}
|
|
336
|
-
async function getPreviewConfig(item, options) {
|
|
884
|
+
async function getPreviewConfig(item, options, dir) {
|
|
885
|
+
const DEFAULT_ROOT = "dist";
|
|
337
886
|
const internalPreviewConfig = async (item)=>{
|
|
338
|
-
var _item_output, _item_devServer, _item_devServer1, _item_devServer2, _item_devServer3, _item_devServer4;
|
|
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,
|
|
345
|
-
proxy:
|
|
346
|
-
host: options.host ??
|
|
347
|
-
open: options.open ??
|
|
348
|
-
server: options.server ??
|
|
349
|
-
historyApiFallback:
|
|
893
|
+
proxy: item.devServer?.proxy,
|
|
894
|
+
host: options.host ?? item.devServer?.host,
|
|
895
|
+
open: options.open ?? item.devServer?.open,
|
|
896
|
+
server: options.server ?? item.devServer?.server,
|
|
897
|
+
historyApiFallback: item.devServer?.historyApiFallback
|
|
350
898
|
};
|
|
351
899
|
return item;
|
|
352
900
|
};
|
|
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,19 +939,19 @@ 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);
|
|
420
947
|
return [
|
|
421
|
-
|
|
422
|
-
|
|
948
|
+
...finalMiddlewares,
|
|
949
|
+
lazyCompileMiddleware
|
|
423
950
|
];
|
|
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
|
-
return
|
|
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
|
}
|
|
@@ -499,44 +1025,92 @@ const DEFAULT_EXTENSIONS = [
|
|
|
499
1025
|
];
|
|
500
1026
|
const findConfig = (basePath)=>DEFAULT_EXTENSIONS.map((ext)=>basePath + ext).find(external_node_fs_["default"].existsSync);
|
|
501
1027
|
const utils_findConfig = findConfig;
|
|
502
|
-
const
|
|
1028
|
+
const TS_EXTENSION = [
|
|
1029
|
+
".ts",
|
|
1030
|
+
".cts",
|
|
1031
|
+
".mts"
|
|
1032
|
+
];
|
|
1033
|
+
const isTsFile = (configPath)=>{
|
|
503
1034
|
const ext = external_node_path_["default"].extname(configPath);
|
|
504
|
-
return
|
|
1035
|
+
return TS_EXTENSION.includes(ext);
|
|
1036
|
+
};
|
|
1037
|
+
const utils_isTsFile = isTsFile;
|
|
1038
|
+
const injectInlineSourceMap = ({ code, map })=>{
|
|
1039
|
+
if (map) {
|
|
1040
|
+
const base64Map = Buffer.from(map, "utf8").toString("base64");
|
|
1041
|
+
const sourceMapContent = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`;
|
|
1042
|
+
return `${code}\n${sourceMapContent}`;
|
|
1043
|
+
}
|
|
1044
|
+
return code;
|
|
505
1045
|
};
|
|
506
|
-
|
|
1046
|
+
function compile(sourcecode, filename) {
|
|
1047
|
+
const { code, map } = rspackCore.Z.experiments.swc.transformSync(sourcecode, {
|
|
1048
|
+
jsc: {
|
|
1049
|
+
parser: {
|
|
1050
|
+
syntax: "typescript",
|
|
1051
|
+
tsx: false,
|
|
1052
|
+
decorators: true,
|
|
1053
|
+
dynamicImport: true
|
|
1054
|
+
}
|
|
1055
|
+
},
|
|
1056
|
+
filename: filename,
|
|
1057
|
+
module: {
|
|
1058
|
+
type: "commonjs"
|
|
1059
|
+
},
|
|
1060
|
+
sourceMaps: true,
|
|
1061
|
+
isModule: true
|
|
1062
|
+
});
|
|
1063
|
+
return injectInlineSourceMap({
|
|
1064
|
+
code,
|
|
1065
|
+
map
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
507
1068
|
const loadConfig_DEFAULT_CONFIG_NAME = "rspack.config";
|
|
508
|
-
const registerLoader =
|
|
509
|
-
|
|
510
|
-
if (
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
rechoir.prepare(extensions, configPath);
|
|
517
|
-
} catch (error) {
|
|
518
|
-
const failures = null == error ? void 0 : error.failures;
|
|
519
|
-
if (failures) {
|
|
520
|
-
const messages = failures.map((failure)=>failure.error.message);
|
|
521
|
-
throw new Error(`${messages.join("\n")}`);
|
|
1069
|
+
const registerLoader = (configPath)=>{
|
|
1070
|
+
if (isEsmFile(configPath) && utils_isTsFile(configPath)) return;
|
|
1071
|
+
if (!utils_isTsFile(configPath)) throw new Error(`config file "${configPath}" is not supported.`);
|
|
1072
|
+
(0, lib.addHook)((code, filename)=>{
|
|
1073
|
+
try {
|
|
1074
|
+
return compile(code, filename);
|
|
1075
|
+
} catch (err) {
|
|
1076
|
+
throw new Error(`Failed to transform file "${filename}" when loading TypeScript config file:\n ${err instanceof Error ? err.message : String(err)}`);
|
|
522
1077
|
}
|
|
523
|
-
|
|
524
|
-
|
|
1078
|
+
}, {
|
|
1079
|
+
exts: TS_EXTENSION
|
|
1080
|
+
});
|
|
525
1081
|
};
|
|
526
1082
|
const checkIsMultiRspackOptions = (config)=>Array.isArray(config);
|
|
527
1083
|
async function loadExtendedConfig(config, configPath, cwd, options) {
|
|
528
1084
|
if (checkIsMultiRspackOptions(config)) {
|
|
529
|
-
const
|
|
1085
|
+
const resultPathMap = new WeakMap();
|
|
1086
|
+
const extendedConfigs = await Promise.all(config.map(async (item)=>{
|
|
1087
|
+
const { config, pathMap } = await loadExtendedConfig(item, configPath, cwd, options);
|
|
1088
|
+
resultPathMap.set(config, pathMap.get(config));
|
|
1089
|
+
return config;
|
|
1090
|
+
}));
|
|
530
1091
|
extendedConfigs.parallelism = config.parallelism;
|
|
531
|
-
return
|
|
1092
|
+
return {
|
|
1093
|
+
config: extendedConfigs,
|
|
1094
|
+
pathMap: resultPathMap
|
|
1095
|
+
};
|
|
532
1096
|
}
|
|
533
|
-
|
|
1097
|
+
const pathMap = new WeakMap();
|
|
1098
|
+
pathMap.set(config, [
|
|
1099
|
+
configPath
|
|
1100
|
+
]);
|
|
1101
|
+
if (!("extends" in config) || !config.extends) return {
|
|
1102
|
+
config,
|
|
1103
|
+
pathMap
|
|
1104
|
+
};
|
|
534
1105
|
const extendsList = Array.isArray(config.extends) ? config.extends : [
|
|
535
1106
|
config.extends
|
|
536
1107
|
];
|
|
537
1108
|
const { extends: _, ...configWithoutExtends } = config;
|
|
538
1109
|
const baseDir = external_node_path_["default"].dirname(configPath);
|
|
539
1110
|
let resultConfig = configWithoutExtends;
|
|
1111
|
+
pathMap.set(resultConfig, [
|
|
1112
|
+
configPath
|
|
1113
|
+
]);
|
|
540
1114
|
for (const extendPath of extendsList){
|
|
541
1115
|
let resolvedPath;
|
|
542
1116
|
if (extendPath.startsWith(".") || extendPath.startsWith("/") || extendPath.includes(":\\")) {
|
|
@@ -557,57 +1131,62 @@ async function loadExtendedConfig(config, configPath, cwd, options) {
|
|
|
557
1131
|
throw new Error(`Cannot find module '${extendPath}' to extend from.`);
|
|
558
1132
|
}
|
|
559
1133
|
if (!external_node_fs_["default"].existsSync(resolvedPath)) throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
|
|
560
|
-
if (
|
|
561
|
-
let
|
|
562
|
-
if ("function" == typeof
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
if ("function" == typeof extendedConfig.then) extendedConfig = await extendedConfig;
|
|
1134
|
+
if (utils_isTsFile(resolvedPath) && "register" === options.configLoader) registerLoader(resolvedPath);
|
|
1135
|
+
let loadedConfig = await crossImport(resolvedPath);
|
|
1136
|
+
if ("function" == typeof loadedConfig) {
|
|
1137
|
+
loadedConfig = loadedConfig(options.env, options);
|
|
1138
|
+
if ("function" == typeof loadedConfig.then) loadedConfig = await loadedConfig;
|
|
566
1139
|
}
|
|
567
|
-
extendedConfig = await loadExtendedConfig(
|
|
568
|
-
|
|
1140
|
+
const { config: extendedConfig, pathMap: extendedPathMap } = await loadExtendedConfig(loadedConfig, resolvedPath, cwd, options);
|
|
1141
|
+
const configPaths = [
|
|
1142
|
+
...pathMap.get(resultConfig) || [],
|
|
1143
|
+
...extendedPathMap.get(extendedConfig) || []
|
|
1144
|
+
];
|
|
1145
|
+
resultConfig = rspackCore.Z.util.cleverMerge(extendedConfig, resultConfig);
|
|
1146
|
+
pathMap.set(resultConfig, configPaths);
|
|
569
1147
|
}
|
|
570
|
-
return
|
|
1148
|
+
return {
|
|
1149
|
+
config: resultConfig,
|
|
1150
|
+
pathMap
|
|
1151
|
+
};
|
|
571
1152
|
}
|
|
572
1153
|
async function loadRspackConfig(options, cwd = process.cwd()) {
|
|
573
|
-
let configPath;
|
|
574
|
-
let loadedConfig;
|
|
1154
|
+
let configPath = "";
|
|
575
1155
|
if (options.config) {
|
|
576
1156
|
configPath = external_node_path_["default"].resolve(cwd, options.config);
|
|
577
1157
|
if (!external_node_fs_["default"].existsSync(configPath)) throw new Error(`config file "${configPath}" not found.`);
|
|
578
|
-
if (isTsFile(configPath) && "register" === options.configLoader) await registerLoader(configPath);
|
|
579
|
-
loadedConfig = await crossImport(configPath, cwd);
|
|
580
1158
|
} else {
|
|
581
1159
|
const defaultConfig = utils_findConfig(external_node_path_["default"].resolve(cwd, loadConfig_DEFAULT_CONFIG_NAME));
|
|
582
|
-
if (!defaultConfig) return
|
|
1160
|
+
if (!defaultConfig) return null;
|
|
583
1161
|
configPath = defaultConfig;
|
|
584
|
-
if (isTsFile(defaultConfig) && "register" === options.configLoader) await registerLoader(defaultConfig);
|
|
585
|
-
loadedConfig = await crossImport(defaultConfig, cwd);
|
|
586
1162
|
}
|
|
587
|
-
if ("
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
enumerable: true,
|
|
594
|
-
configurable: true,
|
|
595
|
-
writable: true
|
|
596
|
-
});
|
|
597
|
-
else obj[key] = value;
|
|
598
|
-
return obj;
|
|
1163
|
+
if (utils_isTsFile(configPath) && "register" === options.configLoader) registerLoader(configPath);
|
|
1164
|
+
const loadedConfig = await crossImport(configPath);
|
|
1165
|
+
return {
|
|
1166
|
+
loadedConfig,
|
|
1167
|
+
configPath
|
|
1168
|
+
};
|
|
599
1169
|
}
|
|
600
1170
|
class RspackCLI {
|
|
1171
|
+
colors;
|
|
1172
|
+
program;
|
|
1173
|
+
constructor(){
|
|
1174
|
+
const program = dist("rspack");
|
|
1175
|
+
this.colors = this.createColors();
|
|
1176
|
+
this.program = program;
|
|
1177
|
+
program.help();
|
|
1178
|
+
program.version("1.6.2");
|
|
1179
|
+
}
|
|
601
1180
|
async createCompiler(options, rspackCommand, callback) {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
config = await this.buildConfig(config, options, rspackCommand);
|
|
1181
|
+
let { config, pathMap } = await this.loadConfig(options);
|
|
1182
|
+
config = await this.buildConfig(config, pathMap, options, rspackCommand);
|
|
605
1183
|
const isWatch = Array.isArray(config) ? config.some((i)=>i.watch) : config.watch;
|
|
606
1184
|
let compiler;
|
|
607
1185
|
try {
|
|
608
|
-
compiler = (0,
|
|
1186
|
+
compiler = (0, rspackCore.Z)(config, isWatch ? callback : void 0);
|
|
1187
|
+
if (!isWatch && compiler) compiler.unsafeFastDrop = true;
|
|
609
1188
|
} catch (e) {
|
|
610
|
-
if (e instanceof
|
|
1189
|
+
if (e instanceof rspackCore.Z.ValidationError) {
|
|
611
1190
|
this.getLogger().error(e.message);
|
|
612
1191
|
process.exit(2);
|
|
613
1192
|
} else if (e instanceof Error) {
|
|
@@ -620,17 +1199,15 @@ class RspackCLI {
|
|
|
620
1199
|
return compiler;
|
|
621
1200
|
}
|
|
622
1201
|
createColors(useColor) {
|
|
623
|
-
const shouldUseColor = useColor || isColorSupported;
|
|
1202
|
+
const shouldUseColor = useColor || picocolors.isColorSupported;
|
|
624
1203
|
return {
|
|
625
|
-
...createColors(
|
|
626
|
-
useColor: shouldUseColor
|
|
627
|
-
}),
|
|
1204
|
+
...(0, picocolors.createColors)(shouldUseColor),
|
|
628
1205
|
isColorSupported: shouldUseColor
|
|
629
1206
|
};
|
|
630
1207
|
}
|
|
631
1208
|
getLogger() {
|
|
632
1209
|
return {
|
|
633
|
-
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))}`),
|
|
634
1211
|
warn: (val)=>console.warn(`[rspack-cli] ${this.colors.yellow(val)}`),
|
|
635
1212
|
info: (val)=>console.info(`[rspack-cli] ${this.colors.cyan(val)}`),
|
|
636
1213
|
success: (val)=>console.log(`[rspack-cli] ${this.colors.green(val)}`),
|
|
@@ -639,13 +1216,8 @@ class RspackCLI {
|
|
|
639
1216
|
};
|
|
640
1217
|
}
|
|
641
1218
|
async run(argv) {
|
|
642
|
-
this.
|
|
643
|
-
this.program.
|
|
644
|
-
this.program.scriptName("rspack");
|
|
645
|
-
this.program.strictCommands(true).strict(true);
|
|
646
|
-
this.program.middleware(normalizeEnv);
|
|
647
|
-
this.registerCommands();
|
|
648
|
-
await this.program.parseAsync(hideBin(argv));
|
|
1219
|
+
await this.registerCommands();
|
|
1220
|
+
this.program.parse(argv);
|
|
649
1221
|
}
|
|
650
1222
|
async registerCommands() {
|
|
651
1223
|
const builtinCommands = [
|
|
@@ -653,9 +1225,9 @@ class RspackCLI {
|
|
|
653
1225
|
new ServeCommand(),
|
|
654
1226
|
new PreviewCommand()
|
|
655
1227
|
];
|
|
656
|
-
for (const command of builtinCommands)command.apply(this);
|
|
1228
|
+
for (const command of builtinCommands)await command.apply(this);
|
|
657
1229
|
}
|
|
658
|
-
async buildConfig(item, options, command) {
|
|
1230
|
+
async buildConfig(item, pathMap, options, command) {
|
|
659
1231
|
const isBuild = "build" === command;
|
|
660
1232
|
const isServe = "serve" === command;
|
|
661
1233
|
const internalBuildConfig = async (item)=>{
|
|
@@ -677,7 +1249,7 @@ class RspackCLI {
|
|
|
677
1249
|
}
|
|
678
1250
|
if (options.profile) item.profile = true;
|
|
679
1251
|
if (process.env.RSPACK_PROFILE) {
|
|
680
|
-
const { applyProfile } = await __webpack_require__.e("
|
|
1252
|
+
const { applyProfile } = await __webpack_require__.e("361").then(__webpack_require__.bind(__webpack_require__, "./src/utils/profile.ts"));
|
|
681
1253
|
await applyProfile(process.env.RSPACK_PROFILE, process.env.RSPACK_TRACE_LAYER, process.env.RSPACK_TRACE_OUTPUT);
|
|
682
1254
|
}
|
|
683
1255
|
if (options.watch) item.watch = options.watch;
|
|
@@ -686,8 +1258,16 @@ class RspackCLI {
|
|
|
686
1258
|
if (void 0 === item.devtool) item.devtool = isBuild ? "source-map" : "cheap-module-source-map";
|
|
687
1259
|
if (void 0 !== options.devtool) item.devtool = options.devtool;
|
|
688
1260
|
if (isServe) {
|
|
689
|
-
const installed = (item.plugins ||= []).find((item)=>item instanceof
|
|
690
|
-
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());
|
|
1263
|
+
}
|
|
1264
|
+
const cacheOptions = item.experiments?.cache;
|
|
1265
|
+
if ("object" == typeof cacheOptions && "persistent" === cacheOptions.type) {
|
|
1266
|
+
const configPaths = pathMap.get(item);
|
|
1267
|
+
if (configPaths) cacheOptions.buildDependencies = [
|
|
1268
|
+
...configPaths,
|
|
1269
|
+
...cacheOptions.buildDependencies || []
|
|
1270
|
+
];
|
|
691
1271
|
}
|
|
692
1272
|
if (void 0 === item.stats) item.stats = {
|
|
693
1273
|
preset: "errors-warnings",
|
|
@@ -708,22 +1288,29 @@ class RspackCLI {
|
|
|
708
1288
|
return internalBuildConfig(item);
|
|
709
1289
|
}
|
|
710
1290
|
async loadConfig(options) {
|
|
711
|
-
|
|
1291
|
+
const config = await loadRspackConfig(options);
|
|
1292
|
+
if (!config) return {
|
|
1293
|
+
config: this.filterConfig(options, {}),
|
|
1294
|
+
pathMap: new WeakMap()
|
|
1295
|
+
};
|
|
1296
|
+
let { loadedConfig, configPath } = config;
|
|
712
1297
|
if ("function" == typeof loadedConfig) {
|
|
713
|
-
|
|
714
|
-
let functionResult = loadedConfig(null == (_options_argv = options.argv) ? void 0 : _options_argv.env, options.argv);
|
|
1298
|
+
let functionResult = loadedConfig(options.env, options);
|
|
715
1299
|
if ("function" == typeof functionResult.then) functionResult = await functionResult;
|
|
716
1300
|
loadedConfig = functionResult;
|
|
717
|
-
if ("extends" in loadedConfig && loadedConfig.extends) {
|
|
718
|
-
const tempConfigPath = external_node_path_["default"].resolve(process.cwd(), "rspack.config.js");
|
|
719
|
-
loadedConfig = await loadExtendedConfig(loadedConfig, tempConfigPath, process.cwd(), options);
|
|
720
|
-
}
|
|
721
1301
|
}
|
|
1302
|
+
const { config: extendedConfig, pathMap } = await loadExtendedConfig(loadedConfig, configPath, process.cwd(), options);
|
|
1303
|
+
return {
|
|
1304
|
+
config: this.filterConfig(options, extendedConfig),
|
|
1305
|
+
pathMap
|
|
1306
|
+
};
|
|
1307
|
+
}
|
|
1308
|
+
filterConfig(options, config) {
|
|
722
1309
|
if (options.configName) {
|
|
723
1310
|
const notFoundConfigNames = [];
|
|
724
|
-
|
|
1311
|
+
config = options.configName.map((configName)=>{
|
|
725
1312
|
let found;
|
|
726
|
-
found = Array.isArray(
|
|
1313
|
+
found = Array.isArray(config) ? config.find((options)=>options.name === configName) : config.name === configName ? config : void 0;
|
|
727
1314
|
if (!found) notFoundConfigNames.push(configName);
|
|
728
1315
|
return found;
|
|
729
1316
|
});
|
|
@@ -732,7 +1319,7 @@ class RspackCLI {
|
|
|
732
1319
|
process.exit(2);
|
|
733
1320
|
}
|
|
734
1321
|
}
|
|
735
|
-
return
|
|
1322
|
+
return config;
|
|
736
1323
|
}
|
|
737
1324
|
isMultipleCompiler(compiler) {
|
|
738
1325
|
return Boolean(compiler.compilers);
|
|
@@ -740,12 +1327,6 @@ class RspackCLI {
|
|
|
740
1327
|
isWatch(compiler) {
|
|
741
1328
|
return Boolean(this.isMultipleCompiler(compiler) ? compiler.compilers.some((compiler)=>compiler.options.watch) : compiler.options.watch);
|
|
742
1329
|
}
|
|
743
|
-
constructor(){
|
|
744
|
-
_define_property(this, "colors", void 0);
|
|
745
|
-
_define_property(this, "program", void 0);
|
|
746
|
-
this.colors = this.createColors();
|
|
747
|
-
this.program = yargs_0();
|
|
748
|
-
}
|
|
749
1330
|
}
|
|
750
1331
|
function defineConfig(config) {
|
|
751
1332
|
return config;
|