@rspack-debug/cli 1.4.9 → 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.js
CHANGED
|
@@ -1,43 +1,158 @@
|
|
|
1
|
-
|
|
1
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
|
|
2
|
+
return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
3
|
+
}();
|
|
2
4
|
var __webpack_modules__ = {
|
|
3
|
-
"@
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
"../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js": function(module) {
|
|
6
|
+
let p = process || {}, argv = p.argv || [], env = p.env || {};
|
|
7
|
+
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);
|
|
8
|
+
let formatter = (open, close, replace = open)=>(input)=>{
|
|
9
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
10
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
11
|
+
};
|
|
12
|
+
let replaceClose = (string, close, replace, index)=>{
|
|
13
|
+
let result = "", cursor = 0;
|
|
14
|
+
do {
|
|
15
|
+
result += string.substring(cursor, index) + replace;
|
|
16
|
+
cursor = index + close.length;
|
|
17
|
+
index = string.indexOf(close, cursor);
|
|
18
|
+
}while (~index);
|
|
19
|
+
return result + string.substring(cursor);
|
|
20
|
+
};
|
|
21
|
+
let createColors = (enabled = isColorSupported)=>{
|
|
22
|
+
let f = enabled ? formatter : ()=>String;
|
|
23
|
+
return {
|
|
24
|
+
isColorSupported: enabled,
|
|
25
|
+
reset: f("\x1b[0m", "\x1b[0m"),
|
|
26
|
+
bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
|
|
27
|
+
dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
|
|
28
|
+
italic: f("\x1b[3m", "\x1b[23m"),
|
|
29
|
+
underline: f("\x1b[4m", "\x1b[24m"),
|
|
30
|
+
inverse: f("\x1b[7m", "\x1b[27m"),
|
|
31
|
+
hidden: f("\x1b[8m", "\x1b[28m"),
|
|
32
|
+
strikethrough: f("\x1b[9m", "\x1b[29m"),
|
|
33
|
+
black: f("\x1b[30m", "\x1b[39m"),
|
|
34
|
+
red: f("\x1b[31m", "\x1b[39m"),
|
|
35
|
+
green: f("\x1b[32m", "\x1b[39m"),
|
|
36
|
+
yellow: f("\x1b[33m", "\x1b[39m"),
|
|
37
|
+
blue: f("\x1b[34m", "\x1b[39m"),
|
|
38
|
+
magenta: f("\x1b[35m", "\x1b[39m"),
|
|
39
|
+
cyan: f("\x1b[36m", "\x1b[39m"),
|
|
40
|
+
white: f("\x1b[37m", "\x1b[39m"),
|
|
41
|
+
gray: f("\x1b[90m", "\x1b[39m"),
|
|
42
|
+
bgBlack: f("\x1b[40m", "\x1b[49m"),
|
|
43
|
+
bgRed: f("\x1b[41m", "\x1b[49m"),
|
|
44
|
+
bgGreen: f("\x1b[42m", "\x1b[49m"),
|
|
45
|
+
bgYellow: f("\x1b[43m", "\x1b[49m"),
|
|
46
|
+
bgBlue: f("\x1b[44m", "\x1b[49m"),
|
|
47
|
+
bgMagenta: f("\x1b[45m", "\x1b[49m"),
|
|
48
|
+
bgCyan: f("\x1b[46m", "\x1b[49m"),
|
|
49
|
+
bgWhite: f("\x1b[47m", "\x1b[49m"),
|
|
50
|
+
blackBright: f("\x1b[90m", "\x1b[39m"),
|
|
51
|
+
redBright: f("\x1b[91m", "\x1b[39m"),
|
|
52
|
+
greenBright: f("\x1b[92m", "\x1b[39m"),
|
|
53
|
+
yellowBright: f("\x1b[93m", "\x1b[39m"),
|
|
54
|
+
blueBright: f("\x1b[94m", "\x1b[39m"),
|
|
55
|
+
magentaBright: f("\x1b[95m", "\x1b[39m"),
|
|
56
|
+
cyanBright: f("\x1b[96m", "\x1b[39m"),
|
|
57
|
+
whiteBright: f("\x1b[97m", "\x1b[39m"),
|
|
58
|
+
bgBlackBright: f("\x1b[100m", "\x1b[49m"),
|
|
59
|
+
bgRedBright: f("\x1b[101m", "\x1b[49m"),
|
|
60
|
+
bgGreenBright: f("\x1b[102m", "\x1b[49m"),
|
|
61
|
+
bgYellowBright: f("\x1b[103m", "\x1b[49m"),
|
|
62
|
+
bgBlueBright: f("\x1b[104m", "\x1b[49m"),
|
|
63
|
+
bgMagentaBright: f("\x1b[105m", "\x1b[49m"),
|
|
64
|
+
bgCyanBright: f("\x1b[106m", "\x1b[49m"),
|
|
65
|
+
bgWhiteBright: f("\x1b[107m", "\x1b[49m")
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
module.exports = createColors();
|
|
69
|
+
module.exports.createColors = createColors;
|
|
11
70
|
},
|
|
12
|
-
"@
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
71
|
+
"../../node_modules/.pnpm/pirates@4.0.7/node_modules/pirates/lib/index.js": function(module, exports1, __webpack_require__) {
|
|
72
|
+
"use strict";
|
|
73
|
+
module = __webpack_require__.nmd(module);
|
|
74
|
+
const BuiltinModule = __webpack_require__("module");
|
|
75
|
+
const path = __webpack_require__("path");
|
|
76
|
+
const nodeModulesRegex = /^(?:.*[\\/])?node_modules(?:[\\/].*)?$/;
|
|
77
|
+
const Module = module.constructor.length > 1 ? module.constructor : BuiltinModule;
|
|
78
|
+
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.";
|
|
79
|
+
function shouldCompile(filename, exts, matcher, ignoreNodeModules) {
|
|
80
|
+
if ('string' != typeof filename) return false;
|
|
81
|
+
if (-1 === exts.indexOf(path.extname(filename))) return false;
|
|
82
|
+
const resolvedFilename = path.resolve(filename);
|
|
83
|
+
if (ignoreNodeModules && nodeModulesRegex.test(resolvedFilename)) return false;
|
|
84
|
+
if (matcher && 'function' == typeof matcher) return !!matcher(resolvedFilename);
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
function addHook(hook, opts = {}) {
|
|
88
|
+
let reverted = false;
|
|
89
|
+
const loaders = [];
|
|
90
|
+
const oldLoaders = [];
|
|
91
|
+
let exts;
|
|
92
|
+
const originalJSLoader = Module._extensions['.js'];
|
|
93
|
+
const matcher = opts.matcher || null;
|
|
94
|
+
const ignoreNodeModules = false !== opts.ignoreNodeModules;
|
|
95
|
+
exts = opts.extensions || opts.exts || opts.extension || opts.ext || [
|
|
96
|
+
'.js'
|
|
97
|
+
];
|
|
98
|
+
if (!Array.isArray(exts)) exts = [
|
|
99
|
+
exts
|
|
100
|
+
];
|
|
101
|
+
exts.forEach((ext)=>{
|
|
102
|
+
if ('string' != typeof ext) throw new TypeError(`Invalid Extension: ${ext}`);
|
|
103
|
+
const oldLoader = Module._extensions[ext] || originalJSLoader;
|
|
104
|
+
oldLoaders[ext] = Module._extensions[ext];
|
|
105
|
+
loaders[ext] = Module._extensions[ext] = function(mod, filename) {
|
|
106
|
+
let compile;
|
|
107
|
+
if (!reverted) {
|
|
108
|
+
if (shouldCompile(filename, exts, matcher, ignoreNodeModules)) {
|
|
109
|
+
compile = mod._compile;
|
|
110
|
+
mod._compile = function(code) {
|
|
111
|
+
mod._compile = compile;
|
|
112
|
+
const newCode = hook(code, filename);
|
|
113
|
+
if ('string' != typeof newCode) throw new Error(HOOK_RETURNED_NOTHING_ERROR_MESSAGE);
|
|
114
|
+
return mod._compile(newCode, filename);
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
oldLoader(mod, filename);
|
|
119
|
+
};
|
|
120
|
+
});
|
|
121
|
+
return function() {
|
|
122
|
+
if (reverted) return;
|
|
123
|
+
reverted = true;
|
|
124
|
+
exts.forEach((ext)=>{
|
|
125
|
+
if (Module._extensions[ext] === loaders[ext]) if (oldLoaders[ext]) Module._extensions[ext] = oldLoaders[ext];
|
|
126
|
+
else delete Module._extensions[ext];
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
exports1.addHook = addHook;
|
|
16
131
|
},
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
132
|
+
"./src/utils/rspackCore.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
133
|
+
"use strict";
|
|
134
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
135
|
+
Z: ()=>rspack
|
|
20
136
|
});
|
|
137
|
+
const external_node_module_namespaceObject = require("node:module");
|
|
138
|
+
const rspackCore_require = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
|
|
139
|
+
const rspack = rspackCore_require("@rspack/core");
|
|
21
140
|
},
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
141
|
+
module: function(module) {
|
|
142
|
+
"use strict";
|
|
143
|
+
module.exports = require("module");
|
|
26
144
|
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
145
|
+
"node:fs": function(module) {
|
|
146
|
+
"use strict";
|
|
147
|
+
module.exports = require("node:fs");
|
|
31
148
|
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
149
|
+
"node:path": function(module) {
|
|
150
|
+
"use strict";
|
|
151
|
+
module.exports = require("node:path");
|
|
36
152
|
},
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
153
|
+
path: function(module) {
|
|
154
|
+
"use strict";
|
|
155
|
+
module.exports = require("path");
|
|
41
156
|
}
|
|
42
157
|
};
|
|
43
158
|
var __webpack_module_cache__ = {};
|
|
@@ -45,9 +160,12 @@ function __webpack_require__(moduleId) {
|
|
|
45
160
|
var cachedModule = __webpack_module_cache__[moduleId];
|
|
46
161
|
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
47
162
|
var module = __webpack_module_cache__[moduleId] = {
|
|
163
|
+
id: moduleId,
|
|
164
|
+
loaded: false,
|
|
48
165
|
exports: {}
|
|
49
166
|
};
|
|
50
167
|
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
168
|
+
module.loaded = true;
|
|
51
169
|
return module.exports;
|
|
52
170
|
}
|
|
53
171
|
__webpack_require__.m = __webpack_modules__;
|
|
@@ -76,7 +194,7 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
76
194
|
}, []));
|
|
77
195
|
})();
|
|
78
196
|
(()=>{
|
|
79
|
-
__webpack_require__.u = (chunkId)=>"" + chunkId + ".js";
|
|
197
|
+
__webpack_require__.u = (chunkId)=>"0~" + chunkId + ".js";
|
|
80
198
|
})();
|
|
81
199
|
(()=>{
|
|
82
200
|
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
@@ -91,9 +209,16 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
91
209
|
});
|
|
92
210
|
};
|
|
93
211
|
})();
|
|
212
|
+
(()=>{
|
|
213
|
+
__webpack_require__.nmd = (module)=>{
|
|
214
|
+
module.paths = [];
|
|
215
|
+
if (!module.children) module.children = [];
|
|
216
|
+
return module;
|
|
217
|
+
};
|
|
218
|
+
})();
|
|
94
219
|
(()=>{
|
|
95
220
|
var installedChunks = {
|
|
96
|
-
|
|
221
|
+
410: 1
|
|
97
222
|
};
|
|
98
223
|
var installChunk = (chunk)=>{
|
|
99
224
|
var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;
|
|
@@ -107,87 +232,558 @@ __webpack_require__.m = __webpack_modules__;
|
|
|
107
232
|
})();
|
|
108
233
|
var __webpack_exports__ = {};
|
|
109
234
|
(()=>{
|
|
235
|
+
"use strict";
|
|
110
236
|
__webpack_require__.r(__webpack_exports__);
|
|
111
237
|
__webpack_require__.d(__webpack_exports__, {
|
|
112
|
-
defineConfig: ()=>defineConfig,
|
|
113
238
|
definePlugin: ()=>definePlugin,
|
|
114
|
-
RspackCLI: ()=>RspackCLI
|
|
239
|
+
RspackCLI: ()=>RspackCLI,
|
|
240
|
+
defineConfig: ()=>defineConfig
|
|
115
241
|
});
|
|
116
242
|
var external_node_path_ = __webpack_require__("node:path");
|
|
117
243
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_);
|
|
118
244
|
const external_node_util_namespaceObject = require("node:util");
|
|
119
245
|
var external_node_util_default = /*#__PURE__*/ __webpack_require__.n(external_node_util_namespaceObject);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
246
|
+
const external_events_namespaceObject = require("events");
|
|
247
|
+
function toArr(any) {
|
|
248
|
+
return null == any ? [] : Array.isArray(any) ? any : [
|
|
249
|
+
any
|
|
250
|
+
];
|
|
251
|
+
}
|
|
252
|
+
function toVal(out, key, val, opts) {
|
|
253
|
+
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;
|
|
254
|
+
out[key] = null == old ? nxt : Array.isArray(old) ? old.concat(nxt) : [
|
|
255
|
+
old,
|
|
256
|
+
nxt
|
|
257
|
+
];
|
|
258
|
+
}
|
|
259
|
+
function mri2(args, opts) {
|
|
260
|
+
args = args || [];
|
|
261
|
+
opts = opts || {};
|
|
262
|
+
var k, arr, arg, name, val, out = {
|
|
263
|
+
_: []
|
|
264
|
+
};
|
|
265
|
+
var i = 0, j = 0, idx = 0, len = args.length;
|
|
266
|
+
const alibi = void 0 !== opts.alias;
|
|
267
|
+
const strict = void 0 !== opts.unknown;
|
|
268
|
+
const defaults = void 0 !== opts.default;
|
|
269
|
+
opts.alias = opts.alias || {};
|
|
270
|
+
opts.string = toArr(opts.string);
|
|
271
|
+
opts.boolean = toArr(opts.boolean);
|
|
272
|
+
if (alibi) for(k in opts.alias){
|
|
273
|
+
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
274
|
+
for(i = 0; i < arr.length; i++)(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
275
|
+
}
|
|
276
|
+
for(i = opts.boolean.length; i-- > 0;){
|
|
277
|
+
arr = opts.alias[opts.boolean[i]] || [];
|
|
278
|
+
for(j = arr.length; j-- > 0;)opts.boolean.push(arr[j]);
|
|
279
|
+
}
|
|
280
|
+
for(i = opts.string.length; i-- > 0;){
|
|
281
|
+
arr = opts.alias[opts.string[i]] || [];
|
|
282
|
+
for(j = arr.length; j-- > 0;)opts.string.push(arr[j]);
|
|
283
|
+
}
|
|
284
|
+
if (defaults) for(k in opts.default){
|
|
285
|
+
name = typeof opts.default[k];
|
|
286
|
+
arr = opts.alias[k] = opts.alias[k] || [];
|
|
287
|
+
if (void 0 !== opts[name]) {
|
|
288
|
+
opts[name].push(k);
|
|
289
|
+
for(i = 0; i < arr.length; i++)opts[name].push(arr[i]);
|
|
147
290
|
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
string: true,
|
|
174
|
-
describe: "env passed to config function"
|
|
175
|
-
},
|
|
176
|
-
devtool: {
|
|
177
|
-
type: "string",
|
|
178
|
-
describe: "Specify a developer tool for debugging. Defaults to `cheap-module-source-map` in development and `source-map` in production.",
|
|
179
|
-
alias: "d",
|
|
180
|
-
coerce: (arg)=>{
|
|
181
|
-
if ("true" === arg) return "source-map";
|
|
182
|
-
if ("false" === arg || "" === arg.trim()) return false;
|
|
183
|
-
return arg;
|
|
291
|
+
}
|
|
292
|
+
const keys = strict ? Object.keys(opts.alias) : [];
|
|
293
|
+
for(i = 0; i < len; i++){
|
|
294
|
+
arg = args[i];
|
|
295
|
+
if ('--' === arg) {
|
|
296
|
+
out._ = out._.concat(args.slice(++i));
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
for(j = 0; j < arg.length && 45 === arg.charCodeAt(j); j++);
|
|
300
|
+
if (0 === j) out._.push(arg);
|
|
301
|
+
else if ('no-' === arg.substring(j, j + 3)) {
|
|
302
|
+
name = arg.substring(j + 3);
|
|
303
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
|
|
304
|
+
out[name] = false;
|
|
305
|
+
} else {
|
|
306
|
+
for(idx = j + 1; idx < arg.length && 61 !== arg.charCodeAt(idx); idx++);
|
|
307
|
+
name = arg.substring(j, idx);
|
|
308
|
+
val = arg.substring(++idx) || i + 1 === len || 45 === ('' + args[i + 1]).charCodeAt(0) || args[++i];
|
|
309
|
+
arr = 2 === j ? [
|
|
310
|
+
name
|
|
311
|
+
] : name;
|
|
312
|
+
for(idx = 0; idx < arr.length; idx++){
|
|
313
|
+
name = arr[idx];
|
|
314
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown('-'.repeat(j) + name);
|
|
315
|
+
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
184
316
|
}
|
|
185
317
|
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
318
|
+
}
|
|
319
|
+
if (defaults) {
|
|
320
|
+
for(k in opts.default)if (void 0 === out[k]) out[k] = opts.default[k];
|
|
321
|
+
}
|
|
322
|
+
if (alibi) for(k in out){
|
|
323
|
+
arr = opts.alias[k] || [];
|
|
324
|
+
while(arr.length > 0)out[arr.shift()] = out[k];
|
|
325
|
+
}
|
|
326
|
+
return out;
|
|
327
|
+
}
|
|
328
|
+
const removeBrackets = (v)=>v.replace(/[<[].+/, "").trim();
|
|
329
|
+
const findAllBrackets = (v)=>{
|
|
330
|
+
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
|
331
|
+
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
|
332
|
+
const res = [];
|
|
333
|
+
const parse = (match)=>{
|
|
334
|
+
let variadic = false;
|
|
335
|
+
let value = match[1];
|
|
336
|
+
if (value.startsWith("...")) {
|
|
337
|
+
value = value.slice(3);
|
|
338
|
+
variadic = true;
|
|
339
|
+
}
|
|
340
|
+
return {
|
|
341
|
+
required: match[0].startsWith("<"),
|
|
342
|
+
value,
|
|
343
|
+
variadic
|
|
344
|
+
};
|
|
345
|
+
};
|
|
346
|
+
let angledMatch;
|
|
347
|
+
while(angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v))res.push(parse(angledMatch));
|
|
348
|
+
let squareMatch;
|
|
349
|
+
while(squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v))res.push(parse(squareMatch));
|
|
350
|
+
return res;
|
|
351
|
+
};
|
|
352
|
+
const getMriOptions = (options)=>{
|
|
353
|
+
const result = {
|
|
354
|
+
alias: {},
|
|
355
|
+
boolean: []
|
|
356
|
+
};
|
|
357
|
+
for (const [index, option] of options.entries()){
|
|
358
|
+
if (option.names.length > 1) result.alias[option.names[0]] = option.names.slice(1);
|
|
359
|
+
if (option.isBoolean) if (option.negated) {
|
|
360
|
+
const hasStringTypeOption = options.some((o, i)=>i !== index && o.names.some((name)=>option.names.includes(name)) && "boolean" == typeof o.required);
|
|
361
|
+
if (!hasStringTypeOption) result.boolean.push(option.names[0]);
|
|
362
|
+
} else result.boolean.push(option.names[0]);
|
|
363
|
+
}
|
|
364
|
+
return result;
|
|
365
|
+
};
|
|
366
|
+
const findLongest = (arr)=>arr.sort((a, b)=>a.length > b.length ? -1 : 1)[0];
|
|
367
|
+
const padRight = (str, length)=>str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
|
368
|
+
const camelcase = (input)=>input.replace(/([a-z])-([a-z])/g, (_, p1, p2)=>p1 + p2.toUpperCase());
|
|
369
|
+
const setDotProp = (obj, keys, val)=>{
|
|
370
|
+
let i = 0;
|
|
371
|
+
let length = keys.length;
|
|
372
|
+
let t = obj;
|
|
373
|
+
let x;
|
|
374
|
+
for(; i < length; ++i){
|
|
375
|
+
x = t[keys[i]];
|
|
376
|
+
t = t[keys[i]] = i === length - 1 ? val : null != x ? x : !~keys[i + 1].indexOf(".") && +keys[i + 1] > -1 ? [] : {};
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
const setByType = (obj, transforms)=>{
|
|
380
|
+
for (const key of Object.keys(transforms)){
|
|
381
|
+
const transform = transforms[key];
|
|
382
|
+
if (transform.shouldTransform) {
|
|
383
|
+
obj[key] = Array.prototype.concat.call([], obj[key]);
|
|
384
|
+
if ("function" == typeof transform.transformFunction) obj[key] = obj[key].map(transform.transformFunction);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
const getFileName = (input)=>{
|
|
389
|
+
const m = /([^\\\/]+)$/.exec(input);
|
|
390
|
+
return m ? m[1] : "";
|
|
391
|
+
};
|
|
392
|
+
const camelcaseOptionName = (name)=>name.split(".").map((v, i)=>0 === i ? camelcase(v) : v).join(".");
|
|
393
|
+
class CACError extends Error {
|
|
394
|
+
constructor(message){
|
|
395
|
+
super(message);
|
|
396
|
+
this.name = this.constructor.name;
|
|
397
|
+
if ("function" == typeof Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
|
|
398
|
+
else this.stack = new Error(message).stack;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
class Option {
|
|
402
|
+
constructor(rawName, description, config){
|
|
403
|
+
this.rawName = rawName;
|
|
404
|
+
this.description = description;
|
|
405
|
+
this.config = Object.assign({}, config);
|
|
406
|
+
rawName = rawName.replace(/\.\*/g, "");
|
|
407
|
+
this.negated = false;
|
|
408
|
+
this.names = removeBrackets(rawName).split(",").map((v)=>{
|
|
409
|
+
let name = v.trim().replace(/^-{1,2}/, "");
|
|
410
|
+
if (name.startsWith("no-")) {
|
|
411
|
+
this.negated = true;
|
|
412
|
+
name = name.replace(/^no-/, "");
|
|
413
|
+
}
|
|
414
|
+
return camelcaseOptionName(name);
|
|
415
|
+
}).sort((a, b)=>a.length > b.length ? 1 : -1);
|
|
416
|
+
this.name = this.names[this.names.length - 1];
|
|
417
|
+
if (this.negated && null == this.config.default) this.config.default = true;
|
|
418
|
+
if (rawName.includes("<")) this.required = true;
|
|
419
|
+
else if (rawName.includes("[")) this.required = false;
|
|
420
|
+
else this.isBoolean = true;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
const processArgs = process.argv;
|
|
424
|
+
const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
|
|
425
|
+
class Command {
|
|
426
|
+
constructor(rawName, description, config = {}, cli){
|
|
427
|
+
this.rawName = rawName;
|
|
428
|
+
this.description = description;
|
|
429
|
+
this.config = config;
|
|
430
|
+
this.cli = cli;
|
|
431
|
+
this.options = [];
|
|
432
|
+
this.aliasNames = [];
|
|
433
|
+
this.name = removeBrackets(rawName);
|
|
434
|
+
this.args = findAllBrackets(rawName);
|
|
435
|
+
this.examples = [];
|
|
436
|
+
}
|
|
437
|
+
usage(text) {
|
|
438
|
+
this.usageText = text;
|
|
439
|
+
return this;
|
|
440
|
+
}
|
|
441
|
+
allowUnknownOptions() {
|
|
442
|
+
this.config.allowUnknownOptions = true;
|
|
443
|
+
return this;
|
|
444
|
+
}
|
|
445
|
+
ignoreOptionDefaultValue() {
|
|
446
|
+
this.config.ignoreOptionDefaultValue = true;
|
|
447
|
+
return this;
|
|
448
|
+
}
|
|
449
|
+
version(version, customFlags = "-v, --version") {
|
|
450
|
+
this.versionNumber = version;
|
|
451
|
+
this.option(customFlags, "Display version number");
|
|
452
|
+
return this;
|
|
453
|
+
}
|
|
454
|
+
example(example) {
|
|
455
|
+
this.examples.push(example);
|
|
456
|
+
return this;
|
|
457
|
+
}
|
|
458
|
+
option(rawName, description, config) {
|
|
459
|
+
const option = new Option(rawName, description, config);
|
|
460
|
+
this.options.push(option);
|
|
461
|
+
return this;
|
|
462
|
+
}
|
|
463
|
+
alias(name) {
|
|
464
|
+
this.aliasNames.push(name);
|
|
465
|
+
return this;
|
|
466
|
+
}
|
|
467
|
+
action(callback) {
|
|
468
|
+
this.commandAction = callback;
|
|
469
|
+
return this;
|
|
470
|
+
}
|
|
471
|
+
isMatched(name) {
|
|
472
|
+
return this.name === name || this.aliasNames.includes(name);
|
|
473
|
+
}
|
|
474
|
+
get isDefaultCommand() {
|
|
475
|
+
return "" === this.name || this.aliasNames.includes("!");
|
|
476
|
+
}
|
|
477
|
+
get isGlobalCommand() {
|
|
478
|
+
return this instanceof GlobalCommand;
|
|
479
|
+
}
|
|
480
|
+
hasOption(name) {
|
|
481
|
+
name = name.split(".")[0];
|
|
482
|
+
return this.options.find((option)=>option.names.includes(name));
|
|
483
|
+
}
|
|
484
|
+
outputHelp() {
|
|
485
|
+
const { name, commands } = this.cli;
|
|
486
|
+
const { versionNumber, options: globalOptions, helpCallback } = this.cli.globalCommand;
|
|
487
|
+
let sections = [
|
|
488
|
+
{
|
|
489
|
+
body: `${name}${versionNumber ? `/${versionNumber}` : ""}`
|
|
490
|
+
}
|
|
491
|
+
];
|
|
492
|
+
sections.push({
|
|
493
|
+
title: "Usage",
|
|
494
|
+
body: ` $ ${name} ${this.usageText || this.rawName}`
|
|
495
|
+
});
|
|
496
|
+
const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
|
|
497
|
+
if (showCommands) {
|
|
498
|
+
const longestCommandName = findLongest(commands.map((command)=>command.rawName));
|
|
499
|
+
sections.push({
|
|
500
|
+
title: "Commands",
|
|
501
|
+
body: commands.map((command)=>` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`).join("\n")
|
|
502
|
+
});
|
|
503
|
+
sections.push({
|
|
504
|
+
title: "For more info, run any command with the `--help` flag",
|
|
505
|
+
body: commands.map((command)=>` $ ${name}${"" === command.name ? "" : ` ${command.name}`} --help`).join("\n")
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
let options = this.isGlobalCommand ? globalOptions : [
|
|
509
|
+
...this.options,
|
|
510
|
+
...globalOptions || []
|
|
511
|
+
];
|
|
512
|
+
if (!this.isGlobalCommand && !this.isDefaultCommand) options = options.filter((option)=>"version" !== option.name);
|
|
513
|
+
if (options.length > 0) {
|
|
514
|
+
const longestOptionName = findLongest(options.map((option)=>option.rawName));
|
|
515
|
+
sections.push({
|
|
516
|
+
title: "Options",
|
|
517
|
+
body: options.map((option)=>` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${void 0 === option.config.default ? "" : `(default: ${option.config.default})`}`).join("\n")
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
if (this.examples.length > 0) sections.push({
|
|
521
|
+
title: "Examples",
|
|
522
|
+
body: this.examples.map((example)=>{
|
|
523
|
+
if ("function" == typeof example) return example(name);
|
|
524
|
+
return example;
|
|
525
|
+
}).join("\n")
|
|
526
|
+
});
|
|
527
|
+
if (helpCallback) sections = helpCallback(sections) || sections;
|
|
528
|
+
console.log(sections.map((section)=>section.title ? `${section.title}:
|
|
529
|
+
${section.body}` : section.body).join("\n\n"));
|
|
530
|
+
}
|
|
531
|
+
outputVersion() {
|
|
532
|
+
const { name } = this.cli;
|
|
533
|
+
const { versionNumber } = this.cli.globalCommand;
|
|
534
|
+
if (versionNumber) console.log(`${name}/${versionNumber} ${platformInfo}`);
|
|
535
|
+
}
|
|
536
|
+
checkRequiredArgs() {
|
|
537
|
+
const minimalArgsCount = this.args.filter((arg)=>arg.required).length;
|
|
538
|
+
if (this.cli.args.length < minimalArgsCount) throw new CACError(`missing required args for command \`${this.rawName}\``);
|
|
539
|
+
}
|
|
540
|
+
checkUnknownOptions() {
|
|
541
|
+
const { options, globalCommand } = this.cli;
|
|
542
|
+
if (!this.config.allowUnknownOptions) {
|
|
543
|
+
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}`}\``);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
checkOptionValue() {
|
|
547
|
+
const { options: parsedOptions, globalCommand } = this.cli;
|
|
548
|
+
const options = [
|
|
549
|
+
...globalCommand.options,
|
|
550
|
+
...this.options
|
|
551
|
+
];
|
|
552
|
+
for (const option of options){
|
|
553
|
+
const value = parsedOptions[option.name.split(".")[0]];
|
|
554
|
+
if (option.required) {
|
|
555
|
+
const hasNegated = options.some((o)=>o.negated && o.names.includes(option.name));
|
|
556
|
+
if (true === value || false === value && !hasNegated) throw new CACError(`option \`${option.rawName}\` value is missing`);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
class GlobalCommand extends Command {
|
|
562
|
+
constructor(cli){
|
|
563
|
+
super("@@global@@", "", {}, cli);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
var __assign = Object.assign;
|
|
567
|
+
class CAC extends external_events_namespaceObject.EventEmitter {
|
|
568
|
+
constructor(name = ""){
|
|
569
|
+
super();
|
|
570
|
+
this.name = name;
|
|
571
|
+
this.commands = [];
|
|
572
|
+
this.rawArgs = [];
|
|
573
|
+
this.args = [];
|
|
574
|
+
this.options = {};
|
|
575
|
+
this.globalCommand = new GlobalCommand(this);
|
|
576
|
+
this.globalCommand.usage("<command> [options]");
|
|
577
|
+
}
|
|
578
|
+
usage(text) {
|
|
579
|
+
this.globalCommand.usage(text);
|
|
580
|
+
return this;
|
|
581
|
+
}
|
|
582
|
+
command(rawName, description, config) {
|
|
583
|
+
const command = new Command(rawName, description || "", config, this);
|
|
584
|
+
command.globalCommand = this.globalCommand;
|
|
585
|
+
this.commands.push(command);
|
|
586
|
+
return command;
|
|
587
|
+
}
|
|
588
|
+
option(rawName, description, config) {
|
|
589
|
+
this.globalCommand.option(rawName, description, config);
|
|
590
|
+
return this;
|
|
591
|
+
}
|
|
592
|
+
help(callback) {
|
|
593
|
+
this.globalCommand.option("-h, --help", "Display this message");
|
|
594
|
+
this.globalCommand.helpCallback = callback;
|
|
595
|
+
this.showHelpOnExit = true;
|
|
596
|
+
return this;
|
|
597
|
+
}
|
|
598
|
+
version(version, customFlags = "-v, --version") {
|
|
599
|
+
this.globalCommand.version(version, customFlags);
|
|
600
|
+
this.showVersionOnExit = true;
|
|
601
|
+
return this;
|
|
602
|
+
}
|
|
603
|
+
example(example) {
|
|
604
|
+
this.globalCommand.example(example);
|
|
605
|
+
return this;
|
|
606
|
+
}
|
|
607
|
+
outputHelp() {
|
|
608
|
+
if (this.matchedCommand) this.matchedCommand.outputHelp();
|
|
609
|
+
else this.globalCommand.outputHelp();
|
|
610
|
+
}
|
|
611
|
+
outputVersion() {
|
|
612
|
+
this.globalCommand.outputVersion();
|
|
613
|
+
}
|
|
614
|
+
setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
|
|
615
|
+
this.args = args;
|
|
616
|
+
this.options = options;
|
|
617
|
+
if (matchedCommand) this.matchedCommand = matchedCommand;
|
|
618
|
+
if (matchedCommandName) this.matchedCommandName = matchedCommandName;
|
|
619
|
+
return this;
|
|
620
|
+
}
|
|
621
|
+
unsetMatchedCommand() {
|
|
622
|
+
this.matchedCommand = void 0;
|
|
623
|
+
this.matchedCommandName = void 0;
|
|
624
|
+
}
|
|
625
|
+
parse(argv = processArgs, { run = true } = {}) {
|
|
626
|
+
this.rawArgs = argv;
|
|
627
|
+
if (!this.name) this.name = argv[1] ? getFileName(argv[1]) : "cli";
|
|
628
|
+
let shouldParse = true;
|
|
629
|
+
for (const command of this.commands){
|
|
630
|
+
const parsed = this.mri(argv.slice(2), command);
|
|
631
|
+
const commandName = parsed.args[0];
|
|
632
|
+
if (command.isMatched(commandName)) {
|
|
633
|
+
shouldParse = false;
|
|
634
|
+
const parsedInfo = __assign(__assign({}, parsed), {
|
|
635
|
+
args: parsed.args.slice(1)
|
|
636
|
+
});
|
|
637
|
+
this.setParsedInfo(parsedInfo, command, commandName);
|
|
638
|
+
this.emit(`command:${commandName}`, command);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
if (shouldParse) {
|
|
642
|
+
for (const command of this.commands)if ("" === command.name) {
|
|
643
|
+
shouldParse = false;
|
|
644
|
+
const parsed = this.mri(argv.slice(2), command);
|
|
645
|
+
this.setParsedInfo(parsed, command);
|
|
646
|
+
this.emit("command:!", command);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
if (shouldParse) {
|
|
650
|
+
const parsed = this.mri(argv.slice(2));
|
|
651
|
+
this.setParsedInfo(parsed);
|
|
652
|
+
}
|
|
653
|
+
if (this.options.help && this.showHelpOnExit) {
|
|
654
|
+
this.outputHelp();
|
|
655
|
+
run = false;
|
|
656
|
+
this.unsetMatchedCommand();
|
|
657
|
+
}
|
|
658
|
+
if (this.options.version && this.showVersionOnExit && null == this.matchedCommandName) {
|
|
659
|
+
this.outputVersion();
|
|
660
|
+
run = false;
|
|
661
|
+
this.unsetMatchedCommand();
|
|
662
|
+
}
|
|
663
|
+
const parsedArgv = {
|
|
664
|
+
args: this.args,
|
|
665
|
+
options: this.options
|
|
666
|
+
};
|
|
667
|
+
if (run) this.runMatchedCommand();
|
|
668
|
+
if (!this.matchedCommand && this.args[0]) this.emit("command:*");
|
|
669
|
+
return parsedArgv;
|
|
670
|
+
}
|
|
671
|
+
mri(argv, command) {
|
|
672
|
+
const cliOptions = [
|
|
673
|
+
...this.globalCommand.options,
|
|
674
|
+
...command ? command.options : []
|
|
675
|
+
];
|
|
676
|
+
const mriOptions = getMriOptions(cliOptions);
|
|
677
|
+
let argsAfterDoubleDashes = [];
|
|
678
|
+
const doubleDashesIndex = argv.indexOf("--");
|
|
679
|
+
if (doubleDashesIndex > -1) {
|
|
680
|
+
argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
|
|
681
|
+
argv = argv.slice(0, doubleDashesIndex);
|
|
682
|
+
}
|
|
683
|
+
let parsed = mri2(argv, mriOptions);
|
|
684
|
+
parsed = Object.keys(parsed).reduce((res, name)=>__assign(__assign({}, res), {
|
|
685
|
+
[camelcaseOptionName(name)]: parsed[name]
|
|
686
|
+
}), {
|
|
687
|
+
_: []
|
|
688
|
+
});
|
|
689
|
+
const args = parsed._;
|
|
690
|
+
const options = {
|
|
691
|
+
"--": argsAfterDoubleDashes
|
|
692
|
+
};
|
|
693
|
+
const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
|
|
694
|
+
let transforms = Object.create(null);
|
|
695
|
+
for (const cliOption of cliOptions){
|
|
696
|
+
if (!ignoreDefault && void 0 !== cliOption.config.default) for (const name of cliOption.names)options[name] = cliOption.config.default;
|
|
697
|
+
if (Array.isArray(cliOption.config.type)) {
|
|
698
|
+
if (void 0 === transforms[cliOption.name]) {
|
|
699
|
+
transforms[cliOption.name] = Object.create(null);
|
|
700
|
+
transforms[cliOption.name]["shouldTransform"] = true;
|
|
701
|
+
transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
for (const key of Object.keys(parsed))if ("_" !== key) {
|
|
706
|
+
const keys = key.split(".");
|
|
707
|
+
setDotProp(options, keys, parsed[key]);
|
|
708
|
+
setByType(options, transforms);
|
|
709
|
+
}
|
|
710
|
+
return {
|
|
711
|
+
args,
|
|
712
|
+
options
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
runMatchedCommand() {
|
|
716
|
+
const { args, options, matchedCommand: command } = this;
|
|
717
|
+
if (!command || !command.commandAction) return;
|
|
718
|
+
command.checkUnknownOptions();
|
|
719
|
+
command.checkOptionValue();
|
|
720
|
+
command.checkRequiredArgs();
|
|
721
|
+
const actionArgs = [];
|
|
722
|
+
command.args.forEach((arg, index)=>{
|
|
723
|
+
if (arg.variadic) actionArgs.push(args.slice(index));
|
|
724
|
+
else actionArgs.push(args[index]);
|
|
725
|
+
});
|
|
726
|
+
actionArgs.push(options);
|
|
727
|
+
return command.commandAction.apply(this, actionArgs);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
const cac = (name = "")=>new CAC(name);
|
|
731
|
+
const dist = cac;
|
|
732
|
+
var picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
|
|
733
|
+
var external_node_fs_ = __webpack_require__("node:fs");
|
|
734
|
+
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_);
|
|
735
|
+
const commonOptions = (command)=>command.option("-c, --config <path>", "config file").option("--config-name <name>", "Name(s) of the configuration to use.", {
|
|
736
|
+
type: [
|
|
737
|
+
String
|
|
738
|
+
],
|
|
739
|
+
default: []
|
|
740
|
+
}).option("--config-loader <loader>", "Specify the loader to load the config file, can be `native` or `register`.", {
|
|
741
|
+
default: "register"
|
|
742
|
+
}).option("--env <env>", "env passed to config function", {
|
|
743
|
+
type: [
|
|
744
|
+
String
|
|
745
|
+
],
|
|
746
|
+
default: []
|
|
747
|
+
}).option("--node-env <value>", "sets `process.env.NODE_ENV` to be specified value");
|
|
748
|
+
function normalizeDevtoolOption(value) {
|
|
749
|
+
if ("string" == typeof value) {
|
|
750
|
+
const trimmed = value.trim();
|
|
751
|
+
if ("" === trimmed || "false" === trimmed) return false;
|
|
752
|
+
if ("true" === trimmed) return "source-map";
|
|
753
|
+
return trimmed;
|
|
754
|
+
}
|
|
755
|
+
if ("boolean" == typeof value) return value ? "source-map" : false;
|
|
756
|
+
}
|
|
757
|
+
const normalizeCommonOptions = (options, action)=>{
|
|
758
|
+
const isEmptyArray = (arr)=>Array.isArray(arr) && 0 === arr.length;
|
|
759
|
+
for (const key of [
|
|
760
|
+
"entry",
|
|
761
|
+
"configName"
|
|
762
|
+
]){
|
|
763
|
+
const val = options[key];
|
|
764
|
+
if (isEmptyArray(val)) options[key] = void 0;
|
|
765
|
+
}
|
|
766
|
+
const env = Array.isArray(options.env) ? normalizeEnvToObject(options) : {};
|
|
767
|
+
options.env = env;
|
|
768
|
+
if ("serve" === action) setBuiltinEnvArg(env, "SERVE", true);
|
|
769
|
+
else if ("build" === action) if (options.watch) setBuiltinEnvArg(env, "WATCH", true);
|
|
770
|
+
else {
|
|
771
|
+
setBuiltinEnvArg(env, "BUNDLE", true);
|
|
772
|
+
setBuiltinEnvArg(env, "BUILD", true);
|
|
773
|
+
}
|
|
774
|
+
if ("devtool" in options) options.devtool = normalizeDevtoolOption(options.devtool);
|
|
775
|
+
};
|
|
776
|
+
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", {
|
|
777
|
+
type: [
|
|
778
|
+
String
|
|
779
|
+
],
|
|
780
|
+
default: []
|
|
781
|
+
}).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");
|
|
782
|
+
function setBuiltinEnvArg(env, envNameSuffix, value) {
|
|
783
|
+
const envName = `RSPACK_${envNameSuffix}`;
|
|
784
|
+
if (!(envName in env)) env[envName] = value;
|
|
785
|
+
}
|
|
786
|
+
function normalizeEnvToObject(options) {
|
|
191
787
|
function parseValue(previous, value) {
|
|
192
788
|
const [allKeys, val] = value.split(/=(.+)/, 2);
|
|
193
789
|
const splitKeys = allKeys.split(/\.(?!$)/);
|
|
@@ -206,155 +802,84 @@ var __webpack_exports__ = {};
|
|
|
206
802
|
});
|
|
207
803
|
return previous;
|
|
208
804
|
}
|
|
209
|
-
|
|
210
|
-
argv.env = envObj;
|
|
211
|
-
}
|
|
212
|
-
function setBuiltinEnvArg(env, envNameSuffix, value) {
|
|
213
|
-
const envNames = [
|
|
214
|
-
`RSPACK_${envNameSuffix}`
|
|
215
|
-
];
|
|
216
|
-
for (const envName of envNames)if (!(envName in env)) env[envName] = value;
|
|
217
|
-
}
|
|
218
|
-
function ensureEnvObject(options) {
|
|
219
|
-
if (Array.isArray(options.env)) normalizeEnv(options);
|
|
220
|
-
options.env = options.env || {};
|
|
221
|
-
return options.env;
|
|
805
|
+
return (options.env ?? []).reduce(parseValue, {});
|
|
222
806
|
}
|
|
223
807
|
function setDefaultNodeEnv(options, defaultEnv) {
|
|
224
|
-
if (void 0
|
|
225
|
-
process.env.NODE_ENV = "string" == typeof options.nodeEnv ? options.nodeEnv : defaultEnv;
|
|
808
|
+
if (void 0 === process.env.NODE_ENV) process.env.NODE_ENV = "string" == typeof options.nodeEnv ? options.nodeEnv : defaultEnv;
|
|
226
809
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
default: false,
|
|
247
|
-
describe: "capture timing information for each module"
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
}, async (options)=>{
|
|
251
|
-
setDefaultNodeEnv(options, "production");
|
|
252
|
-
const env = ensureEnvObject(options);
|
|
253
|
-
if (options.watch) setBuiltinEnvArg(env, "WATCH", true);
|
|
254
|
-
else {
|
|
255
|
-
setBuiltinEnvArg(env, "BUNDLE", true);
|
|
256
|
-
setBuiltinEnvArg(env, "BUILD", true);
|
|
257
|
-
}
|
|
258
|
-
const logger = cli.getLogger();
|
|
259
|
-
let createJsonStringifyStream;
|
|
260
|
-
if (options.json) {
|
|
261
|
-
const jsonExt = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@discoveryjs/json-ext"));
|
|
262
|
-
createJsonStringifyStream = jsonExt.default.stringifyStream;
|
|
263
|
-
}
|
|
264
|
-
const errorHandler = (error, stats)=>{
|
|
265
|
-
if (error) {
|
|
266
|
-
logger.error(error);
|
|
267
|
-
process.exit(2);
|
|
268
|
-
}
|
|
269
|
-
if (null == stats ? void 0 : stats.hasErrors()) process.exitCode = 1;
|
|
270
|
-
if (!compiler || !stats) return;
|
|
271
|
-
const statsOptions = cli.isMultipleCompiler(compiler) ? {
|
|
272
|
-
children: compiler.compilers.map((compiler)=>compiler.options ? compiler.options.stats : void 0)
|
|
273
|
-
} : compiler.options ? compiler.options.stats : void 0;
|
|
274
|
-
if (options.json && createJsonStringifyStream) {
|
|
275
|
-
const handleWriteError = (error)=>{
|
|
276
|
-
logger.error(error);
|
|
277
|
-
process.exit(2);
|
|
278
|
-
};
|
|
279
|
-
if (true === options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(process.stdout).on("error", handleWriteError).on("close", ()=>process.stdout.write("\n"));
|
|
280
|
-
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", ()=>{
|
|
281
|
-
process.stderr.write(`[rspack-cli] ${cli.colors.green(`stats are successfully stored as json to ${options.json}`)}\n`);
|
|
282
|
-
});
|
|
283
|
-
} else {
|
|
284
|
-
const printedStats = stats.toString(statsOptions);
|
|
285
|
-
if (printedStats) logger.raw(printedStats);
|
|
286
|
-
}
|
|
810
|
+
async function runBuild(cli, options) {
|
|
811
|
+
setDefaultNodeEnv(options, "production");
|
|
812
|
+
normalizeCommonOptions(options, "build");
|
|
813
|
+
const logger = cli.getLogger();
|
|
814
|
+
let createJsonStringifyStream;
|
|
815
|
+
if (options.json) {
|
|
816
|
+
const jsonExt = await import("@discoveryjs/json-ext");
|
|
817
|
+
createJsonStringifyStream = jsonExt.default.stringifyStream;
|
|
818
|
+
}
|
|
819
|
+
const errorHandler = (error, stats)=>{
|
|
820
|
+
if (error) {
|
|
821
|
+
logger.error(error);
|
|
822
|
+
process.exit(2);
|
|
823
|
+
}
|
|
824
|
+
if (stats?.hasErrors()) process.exitCode = 1;
|
|
825
|
+
if (!compiler || !stats) return;
|
|
826
|
+
const getStatsOptions = ()=>{
|
|
827
|
+
if (cli.isMultipleCompiler(compiler)) return {
|
|
828
|
+
children: compiler.compilers.map((item)=>item.options ? item.options.stats : void 0)
|
|
287
829
|
};
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
830
|
+
return compiler.options?.stats;
|
|
831
|
+
};
|
|
832
|
+
const statsOptions = getStatsOptions();
|
|
833
|
+
if (options.json && createJsonStringifyStream) {
|
|
834
|
+
const handleWriteError = (error)=>{
|
|
835
|
+
logger.error(error);
|
|
836
|
+
process.exit(2);
|
|
293
837
|
};
|
|
294
|
-
|
|
295
|
-
if (
|
|
296
|
-
|
|
297
|
-
compiler.close((closeErr)=>{
|
|
298
|
-
if (closeErr) logger.error(closeErr);
|
|
299
|
-
errorHandler(error, stats);
|
|
300
|
-
});
|
|
838
|
+
if (true === options.json) createJsonStringifyStream(stats.toJson(statsOptions)).on("error", handleWriteError).pipe(process.stdout).on("error", handleWriteError).on("close", ()=>process.stdout.write("\n"));
|
|
839
|
+
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", ()=>{
|
|
840
|
+
process.stderr.write(`[rspack-cli] ${cli.colors.green(`stats are successfully stored as json to ${options.json}`)}\n`);
|
|
301
841
|
});
|
|
842
|
+
} else {
|
|
843
|
+
const printedStats = stats.toString(statsOptions);
|
|
844
|
+
if (printedStats) logger.raw(printedStats);
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
const compiler = await cli.createCompiler(options, "build", errorHandler);
|
|
848
|
+
if (!compiler || cli.isWatch(compiler)) return;
|
|
849
|
+
compiler.run((error, stats)=>{
|
|
850
|
+
compiler.close((closeErr)=>{
|
|
851
|
+
if (closeErr) logger.error(closeErr);
|
|
852
|
+
errorHandler(error, stats);
|
|
853
|
+
});
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
class BuildCommand {
|
|
857
|
+
async apply(cli) {
|
|
858
|
+
const command = cli.program.command("", "run the Rspack build").alias("build").alias("bundle").alias("b");
|
|
859
|
+
commonOptionsForBuildAndServe(commonOptions(command)).option("--json [path]", "emit stats json");
|
|
860
|
+
command.action(async (options)=>{
|
|
861
|
+
await runBuild(cli, options);
|
|
302
862
|
});
|
|
303
863
|
}
|
|
304
864
|
}
|
|
305
|
-
|
|
306
|
-
yargs.positional("dir", {
|
|
307
|
-
type: "string",
|
|
308
|
-
describe: "directory want to preview"
|
|
309
|
-
});
|
|
310
|
-
return commonOptions(yargs).options({
|
|
311
|
-
publicPath: {
|
|
312
|
-
type: "string",
|
|
313
|
-
describe: "static resource server path"
|
|
314
|
-
},
|
|
315
|
-
port: {
|
|
316
|
-
type: "number",
|
|
317
|
-
describe: "preview server port"
|
|
318
|
-
},
|
|
319
|
-
host: {
|
|
320
|
-
type: "string",
|
|
321
|
-
describe: "preview server host"
|
|
322
|
-
},
|
|
323
|
-
open: {
|
|
324
|
-
type: "boolean",
|
|
325
|
-
describe: "open browser"
|
|
326
|
-
},
|
|
327
|
-
server: {
|
|
328
|
-
type: "string",
|
|
329
|
-
describe: "Configuration items for the server."
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
};
|
|
333
|
-
const defaultRoot = "dist";
|
|
865
|
+
var rspackCore = __webpack_require__("./src/utils/rspackCore.ts");
|
|
334
866
|
class PreviewCommand {
|
|
335
867
|
async apply(cli) {
|
|
336
|
-
cli.program.command([
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
"p"
|
|
340
|
-
], "run the rspack server for build output", previewOptions, async (options)=>{
|
|
868
|
+
const command = cli.program.command("preview [dir]", "run the Rspack server for build output").alias("p");
|
|
869
|
+
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.");
|
|
870
|
+
command.action(async (dir, options)=>{
|
|
341
871
|
setDefaultNodeEnv(options, "production");
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
const { RspackDevServer } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspack/dev-server"));
|
|
349
|
-
let config = await cli.loadConfig(rspackOptions);
|
|
350
|
-
config = await getPreviewConfig(config, options);
|
|
872
|
+
normalizeCommonOptions(options, "preview");
|
|
873
|
+
const { RspackDevServer } = await import("@rspack/dev-server");
|
|
874
|
+
let { config } = await cli.loadConfig(options);
|
|
875
|
+
config = await getPreviewConfig(config, options, dir);
|
|
351
876
|
if (!Array.isArray(config)) config = [
|
|
352
877
|
config
|
|
353
878
|
];
|
|
354
|
-
|
|
355
|
-
const devServerOptions =
|
|
879
|
+
const singleConfig = config.find((item)=>item.devServer) || config[0];
|
|
880
|
+
const devServerOptions = singleConfig.devServer;
|
|
356
881
|
try {
|
|
357
|
-
const compiler = (0,
|
|
882
|
+
const compiler = (0, rspackCore.Z)({
|
|
358
883
|
entry: {}
|
|
359
884
|
});
|
|
360
885
|
if (!compiler) return;
|
|
@@ -368,62 +893,41 @@ var __webpack_exports__ = {};
|
|
|
368
893
|
});
|
|
369
894
|
}
|
|
370
895
|
}
|
|
371
|
-
async function getPreviewConfig(item, options) {
|
|
896
|
+
async function getPreviewConfig(item, options, dir) {
|
|
897
|
+
const DEFAULT_ROOT = "dist";
|
|
372
898
|
const internalPreviewConfig = async (item)=>{
|
|
373
|
-
var _item_output, _item_devServer, _item_devServer1, _item_devServer2, _item_devServer3, _item_devServer4;
|
|
374
899
|
item.devServer = {
|
|
375
900
|
static: {
|
|
376
|
-
directory:
|
|
901
|
+
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),
|
|
377
902
|
publicPath: options.publicPath ?? "/"
|
|
378
903
|
},
|
|
379
904
|
port: options.port ?? 8080,
|
|
380
|
-
proxy:
|
|
381
|
-
host: options.host ??
|
|
382
|
-
open: options.open ??
|
|
383
|
-
server: options.server ??
|
|
384
|
-
historyApiFallback:
|
|
905
|
+
proxy: item.devServer?.proxy,
|
|
906
|
+
host: options.host ?? item.devServer?.host,
|
|
907
|
+
open: options.open ?? item.devServer?.open,
|
|
908
|
+
server: options.server ?? item.devServer?.server,
|
|
909
|
+
historyApiFallback: item.devServer?.historyApiFallback
|
|
385
910
|
};
|
|
386
911
|
return item;
|
|
387
912
|
};
|
|
388
913
|
if (Array.isArray(item)) return Promise.all(item.map(internalPreviewConfig));
|
|
389
914
|
return internalPreviewConfig(item);
|
|
390
915
|
}
|
|
916
|
+
function normalizeHotOption(value) {
|
|
917
|
+
if ("boolean" == typeof value || "only" === value) return value;
|
|
918
|
+
if ("false" === value) return false;
|
|
919
|
+
return true;
|
|
920
|
+
}
|
|
391
921
|
class ServeCommand {
|
|
392
922
|
async apply(cli) {
|
|
393
|
-
cli.program.command(
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
"s",
|
|
397
|
-
"dev"
|
|
398
|
-
], "run the rspack dev server.", (yargs)=>commonOptionsForBuildAndServe(commonOptions(yargs)).options({
|
|
399
|
-
hot: {
|
|
400
|
-
coerce: (arg)=>{
|
|
401
|
-
if ("boolean" == typeof arg || "only" === arg) return arg;
|
|
402
|
-
if ("false" === arg) return false;
|
|
403
|
-
return true;
|
|
404
|
-
},
|
|
405
|
-
describe: "enables hot module replacement"
|
|
406
|
-
},
|
|
407
|
-
port: {
|
|
408
|
-
type: "number",
|
|
409
|
-
coerce: (arg)=>Number.isInteger(arg) ? arg : void 0,
|
|
410
|
-
describe: "allows to specify a port to use"
|
|
411
|
-
},
|
|
412
|
-
host: {
|
|
413
|
-
type: "string",
|
|
414
|
-
describe: "allows to specify a hostname to use"
|
|
415
|
-
}
|
|
416
|
-
}), async (options)=>{
|
|
923
|
+
const command = cli.program.command("serve", "run the rspack dev server.").alias("server").alias("s").alias("dev");
|
|
924
|
+
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");
|
|
925
|
+
command.action(async (options)=>{
|
|
417
926
|
setDefaultNodeEnv(options, "development");
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
...options
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
const { RspackDevServer } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspack/dev-server"));
|
|
426
|
-
const compiler = await cli.createCompiler(rspackOptions, "serve");
|
|
927
|
+
normalizeCommonOptions(options, "serve");
|
|
928
|
+
options.hot = normalizeHotOption(options.hot);
|
|
929
|
+
const { RspackDevServer } = await import("@rspack/dev-server");
|
|
930
|
+
const compiler = await cli.createCompiler(options, "serve");
|
|
427
931
|
if (!compiler) return;
|
|
428
932
|
const compilers = cli.isMultipleCompiler(compiler) ? compiler.compilers : [
|
|
429
933
|
compiler
|
|
@@ -447,19 +951,19 @@ var __webpack_exports__ = {};
|
|
|
447
951
|
}
|
|
448
952
|
}
|
|
449
953
|
const result = compilerForDevServer.options.devServer ??= {};
|
|
450
|
-
const setupMiddlewares = result
|
|
451
|
-
const lazyCompileMiddleware =
|
|
954
|
+
const { setupMiddlewares } = result;
|
|
955
|
+
const lazyCompileMiddleware = rspackCore.Z.experiments.lazyCompilationMiddleware(compiler);
|
|
452
956
|
result.setupMiddlewares = (middlewares, server)=>{
|
|
453
957
|
let finalMiddlewares = middlewares;
|
|
454
958
|
if (setupMiddlewares) finalMiddlewares = setupMiddlewares(finalMiddlewares, server);
|
|
455
959
|
return [
|
|
456
|
-
|
|
457
|
-
|
|
960
|
+
...finalMiddlewares,
|
|
961
|
+
lazyCompileMiddleware
|
|
458
962
|
];
|
|
459
963
|
};
|
|
460
964
|
result.hot = options.hot ?? result.hot ?? true;
|
|
461
965
|
result.host = options.host || result.host;
|
|
462
|
-
result.port = options.port
|
|
966
|
+
result.port = options.port ?? result.port;
|
|
463
967
|
if (false !== result.client) {
|
|
464
968
|
if (true === result.client || null == result.client) result.client = {};
|
|
465
969
|
result.client = {
|
|
@@ -490,6 +994,7 @@ var __webpack_exports__ = {};
|
|
|
490
994
|
});
|
|
491
995
|
}
|
|
492
996
|
}
|
|
997
|
+
var lib = __webpack_require__("../../node_modules/.pnpm/pirates@4.0.7/node_modules/pirates/lib/index.js");
|
|
493
998
|
const external_node_url_namespaceObject = require("node:url");
|
|
494
999
|
const readPackageUp = (cwd = process.cwd())=>{
|
|
495
1000
|
let currentDir = external_node_path_default().resolve(cwd);
|
|
@@ -507,16 +1012,14 @@ var __webpack_exports__ = {};
|
|
|
507
1012
|
}
|
|
508
1013
|
};
|
|
509
1014
|
const utils_readPackageUp = readPackageUp;
|
|
510
|
-
const isEsmFile = (filePath
|
|
511
|
-
|
|
512
|
-
if (/\.(
|
|
513
|
-
if (/\.(cjs|cts)/.test(ext)) return false;
|
|
1015
|
+
const isEsmFile = (filePath)=>{
|
|
1016
|
+
if (/\.(mjs|mts)$/.test(filePath)) return true;
|
|
1017
|
+
if (/\.(cjs|cts)$/.test(filePath)) return false;
|
|
514
1018
|
const packageJson = utils_readPackageUp(external_node_path_default().dirname(filePath));
|
|
515
|
-
return
|
|
1019
|
+
return packageJson?.type === "module";
|
|
516
1020
|
};
|
|
517
|
-
const
|
|
518
|
-
|
|
519
|
-
if (utils_isEsmFile(path, cwd)) {
|
|
1021
|
+
const crossImport = async (path)=>{
|
|
1022
|
+
if (isEsmFile(path)) {
|
|
520
1023
|
const url = (0, external_node_url_namespaceObject.pathToFileURL)(path).href;
|
|
521
1024
|
const { default: config } = await import(url);
|
|
522
1025
|
return config;
|
|
@@ -535,44 +1038,92 @@ var __webpack_exports__ = {};
|
|
|
535
1038
|
];
|
|
536
1039
|
const findConfig = (basePath)=>DEFAULT_EXTENSIONS.map((ext)=>basePath + ext).find(external_node_fs_default().existsSync);
|
|
537
1040
|
const utils_findConfig = findConfig;
|
|
538
|
-
const
|
|
1041
|
+
const TS_EXTENSION = [
|
|
1042
|
+
".ts",
|
|
1043
|
+
".cts",
|
|
1044
|
+
".mts"
|
|
1045
|
+
];
|
|
1046
|
+
const isTsFile = (configPath)=>{
|
|
539
1047
|
const ext = external_node_path_default().extname(configPath);
|
|
540
|
-
return
|
|
1048
|
+
return TS_EXTENSION.includes(ext);
|
|
541
1049
|
};
|
|
542
|
-
const
|
|
1050
|
+
const utils_isTsFile = isTsFile;
|
|
1051
|
+
const injectInlineSourceMap = ({ code, map })=>{
|
|
1052
|
+
if (map) {
|
|
1053
|
+
const base64Map = Buffer.from(map, "utf8").toString("base64");
|
|
1054
|
+
const sourceMapContent = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`;
|
|
1055
|
+
return `${code}\n${sourceMapContent}`;
|
|
1056
|
+
}
|
|
1057
|
+
return code;
|
|
1058
|
+
};
|
|
1059
|
+
function compile(sourcecode, filename) {
|
|
1060
|
+
const { code, map } = rspackCore.Z.experiments.swc.transformSync(sourcecode, {
|
|
1061
|
+
jsc: {
|
|
1062
|
+
parser: {
|
|
1063
|
+
syntax: "typescript",
|
|
1064
|
+
tsx: false,
|
|
1065
|
+
decorators: true,
|
|
1066
|
+
dynamicImport: true
|
|
1067
|
+
}
|
|
1068
|
+
},
|
|
1069
|
+
filename: filename,
|
|
1070
|
+
module: {
|
|
1071
|
+
type: "commonjs"
|
|
1072
|
+
},
|
|
1073
|
+
sourceMaps: true,
|
|
1074
|
+
isModule: true
|
|
1075
|
+
});
|
|
1076
|
+
return injectInlineSourceMap({
|
|
1077
|
+
code,
|
|
1078
|
+
map
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
543
1081
|
const loadConfig_DEFAULT_CONFIG_NAME = "rspack.config";
|
|
544
|
-
const registerLoader =
|
|
545
|
-
|
|
546
|
-
if (
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
rechoir.prepare(extensions, configPath);
|
|
553
|
-
} catch (error) {
|
|
554
|
-
const failures = null == error ? void 0 : error.failures;
|
|
555
|
-
if (failures) {
|
|
556
|
-
const messages = failures.map((failure)=>failure.error.message);
|
|
557
|
-
throw new Error(`${messages.join("\n")}`);
|
|
1082
|
+
const registerLoader = (configPath)=>{
|
|
1083
|
+
if (isEsmFile(configPath) && utils_isTsFile(configPath)) return;
|
|
1084
|
+
if (!utils_isTsFile(configPath)) throw new Error(`config file "${configPath}" is not supported.`);
|
|
1085
|
+
(0, lib.addHook)((code, filename)=>{
|
|
1086
|
+
try {
|
|
1087
|
+
return compile(code, filename);
|
|
1088
|
+
} catch (err) {
|
|
1089
|
+
throw new Error(`Failed to transform file "${filename}" when loading TypeScript config file:\n ${err instanceof Error ? err.message : String(err)}`);
|
|
558
1090
|
}
|
|
559
|
-
|
|
560
|
-
|
|
1091
|
+
}, {
|
|
1092
|
+
exts: TS_EXTENSION
|
|
1093
|
+
});
|
|
561
1094
|
};
|
|
562
1095
|
const checkIsMultiRspackOptions = (config)=>Array.isArray(config);
|
|
563
1096
|
async function loadExtendedConfig(config, configPath, cwd, options) {
|
|
564
1097
|
if (checkIsMultiRspackOptions(config)) {
|
|
565
|
-
const
|
|
1098
|
+
const resultPathMap = new WeakMap();
|
|
1099
|
+
const extendedConfigs = await Promise.all(config.map(async (item)=>{
|
|
1100
|
+
const { config, pathMap } = await loadExtendedConfig(item, configPath, cwd, options);
|
|
1101
|
+
resultPathMap.set(config, pathMap.get(config));
|
|
1102
|
+
return config;
|
|
1103
|
+
}));
|
|
566
1104
|
extendedConfigs.parallelism = config.parallelism;
|
|
567
|
-
return
|
|
1105
|
+
return {
|
|
1106
|
+
config: extendedConfigs,
|
|
1107
|
+
pathMap: resultPathMap
|
|
1108
|
+
};
|
|
568
1109
|
}
|
|
569
|
-
|
|
1110
|
+
const pathMap = new WeakMap();
|
|
1111
|
+
pathMap.set(config, [
|
|
1112
|
+
configPath
|
|
1113
|
+
]);
|
|
1114
|
+
if (!("extends" in config) || !config.extends) return {
|
|
1115
|
+
config,
|
|
1116
|
+
pathMap
|
|
1117
|
+
};
|
|
570
1118
|
const extendsList = Array.isArray(config.extends) ? config.extends : [
|
|
571
1119
|
config.extends
|
|
572
1120
|
];
|
|
573
1121
|
const { extends: _, ...configWithoutExtends } = config;
|
|
574
1122
|
const baseDir = external_node_path_default().dirname(configPath);
|
|
575
1123
|
let resultConfig = configWithoutExtends;
|
|
1124
|
+
pathMap.set(resultConfig, [
|
|
1125
|
+
configPath
|
|
1126
|
+
]);
|
|
576
1127
|
for (const extendPath of extendsList){
|
|
577
1128
|
let resolvedPath;
|
|
578
1129
|
if (extendPath.startsWith(".") || extendPath.startsWith("/") || extendPath.includes(":\\")) {
|
|
@@ -593,57 +1144,62 @@ var __webpack_exports__ = {};
|
|
|
593
1144
|
throw new Error(`Cannot find module '${extendPath}' to extend from.`);
|
|
594
1145
|
}
|
|
595
1146
|
if (!external_node_fs_default().existsSync(resolvedPath)) throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
|
|
596
|
-
if (
|
|
597
|
-
let
|
|
598
|
-
if ("function" == typeof
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
if ("function" == typeof extendedConfig.then) extendedConfig = await extendedConfig;
|
|
1147
|
+
if (utils_isTsFile(resolvedPath) && "register" === options.configLoader) registerLoader(resolvedPath);
|
|
1148
|
+
let loadedConfig = await crossImport(resolvedPath);
|
|
1149
|
+
if ("function" == typeof loadedConfig) {
|
|
1150
|
+
loadedConfig = loadedConfig(options.env, options);
|
|
1151
|
+
if ("function" == typeof loadedConfig.then) loadedConfig = await loadedConfig;
|
|
602
1152
|
}
|
|
603
|
-
extendedConfig = await loadExtendedConfig(
|
|
604
|
-
|
|
1153
|
+
const { config: extendedConfig, pathMap: extendedPathMap } = await loadExtendedConfig(loadedConfig, resolvedPath, cwd, options);
|
|
1154
|
+
const configPaths = [
|
|
1155
|
+
...pathMap.get(resultConfig) || [],
|
|
1156
|
+
...extendedPathMap.get(extendedConfig) || []
|
|
1157
|
+
];
|
|
1158
|
+
resultConfig = rspackCore.Z.util.cleverMerge(extendedConfig, resultConfig);
|
|
1159
|
+
pathMap.set(resultConfig, configPaths);
|
|
605
1160
|
}
|
|
606
|
-
return
|
|
1161
|
+
return {
|
|
1162
|
+
config: resultConfig,
|
|
1163
|
+
pathMap
|
|
1164
|
+
};
|
|
607
1165
|
}
|
|
608
1166
|
async function loadRspackConfig(options, cwd = process.cwd()) {
|
|
609
|
-
let configPath;
|
|
610
|
-
let loadedConfig;
|
|
1167
|
+
let configPath = "";
|
|
611
1168
|
if (options.config) {
|
|
612
1169
|
configPath = external_node_path_default().resolve(cwd, options.config);
|
|
613
1170
|
if (!external_node_fs_default().existsSync(configPath)) throw new Error(`config file "${configPath}" not found.`);
|
|
614
|
-
if (isTsFile(configPath) && "register" === options.configLoader) await registerLoader(configPath);
|
|
615
|
-
loadedConfig = await crossImport(configPath, cwd);
|
|
616
1171
|
} else {
|
|
617
1172
|
const defaultConfig = utils_findConfig(external_node_path_default().resolve(cwd, loadConfig_DEFAULT_CONFIG_NAME));
|
|
618
|
-
if (!defaultConfig) return
|
|
1173
|
+
if (!defaultConfig) return null;
|
|
619
1174
|
configPath = defaultConfig;
|
|
620
|
-
if (isTsFile(defaultConfig) && "register" === options.configLoader) await registerLoader(defaultConfig);
|
|
621
|
-
loadedConfig = await crossImport(defaultConfig, cwd);
|
|
622
1175
|
}
|
|
623
|
-
if ("
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
enumerable: true,
|
|
630
|
-
configurable: true,
|
|
631
|
-
writable: true
|
|
632
|
-
});
|
|
633
|
-
else obj[key] = value;
|
|
634
|
-
return obj;
|
|
1176
|
+
if (utils_isTsFile(configPath) && "register" === options.configLoader) registerLoader(configPath);
|
|
1177
|
+
const loadedConfig = await crossImport(configPath);
|
|
1178
|
+
return {
|
|
1179
|
+
loadedConfig,
|
|
1180
|
+
configPath
|
|
1181
|
+
};
|
|
635
1182
|
}
|
|
636
1183
|
class RspackCLI {
|
|
1184
|
+
colors;
|
|
1185
|
+
program;
|
|
1186
|
+
constructor(){
|
|
1187
|
+
const program = dist("rspack");
|
|
1188
|
+
this.colors = this.createColors();
|
|
1189
|
+
this.program = program;
|
|
1190
|
+
program.help();
|
|
1191
|
+
program.version("1.6.2");
|
|
1192
|
+
}
|
|
637
1193
|
async createCompiler(options, rspackCommand, callback) {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
config = await this.buildConfig(config, options, rspackCommand);
|
|
1194
|
+
let { config, pathMap } = await this.loadConfig(options);
|
|
1195
|
+
config = await this.buildConfig(config, pathMap, options, rspackCommand);
|
|
641
1196
|
const isWatch = Array.isArray(config) ? config.some((i)=>i.watch) : config.watch;
|
|
642
1197
|
let compiler;
|
|
643
1198
|
try {
|
|
644
|
-
compiler = (0,
|
|
1199
|
+
compiler = (0, rspackCore.Z)(config, isWatch ? callback : void 0);
|
|
1200
|
+
if (!isWatch && compiler) compiler.unsafeFastDrop = true;
|
|
645
1201
|
} catch (e) {
|
|
646
|
-
if (e instanceof
|
|
1202
|
+
if (e instanceof rspackCore.Z.ValidationError) {
|
|
647
1203
|
this.getLogger().error(e.message);
|
|
648
1204
|
process.exit(2);
|
|
649
1205
|
} else if (e instanceof Error) {
|
|
@@ -656,11 +1212,9 @@ var __webpack_exports__ = {};
|
|
|
656
1212
|
return compiler;
|
|
657
1213
|
}
|
|
658
1214
|
createColors(useColor) {
|
|
659
|
-
const shouldUseColor = useColor ||
|
|
1215
|
+
const shouldUseColor = useColor || picocolors.isColorSupported;
|
|
660
1216
|
return {
|
|
661
|
-
...(0,
|
|
662
|
-
useColor: shouldUseColor
|
|
663
|
-
}),
|
|
1217
|
+
...(0, picocolors.createColors)(shouldUseColor),
|
|
664
1218
|
isColorSupported: shouldUseColor
|
|
665
1219
|
};
|
|
666
1220
|
}
|
|
@@ -675,13 +1229,8 @@ var __webpack_exports__ = {};
|
|
|
675
1229
|
};
|
|
676
1230
|
}
|
|
677
1231
|
async run(argv) {
|
|
678
|
-
this.
|
|
679
|
-
this.program.
|
|
680
|
-
this.program.scriptName("rspack");
|
|
681
|
-
this.program.strictCommands(true).strict(true);
|
|
682
|
-
this.program.middleware(normalizeEnv);
|
|
683
|
-
this.registerCommands();
|
|
684
|
-
await this.program.parseAsync((0, helpers_namespaceObject.hideBin)(argv));
|
|
1232
|
+
await this.registerCommands();
|
|
1233
|
+
this.program.parse(argv);
|
|
685
1234
|
}
|
|
686
1235
|
async registerCommands() {
|
|
687
1236
|
const builtinCommands = [
|
|
@@ -689,9 +1238,9 @@ var __webpack_exports__ = {};
|
|
|
689
1238
|
new ServeCommand(),
|
|
690
1239
|
new PreviewCommand()
|
|
691
1240
|
];
|
|
692
|
-
for (const command of builtinCommands)command.apply(this);
|
|
1241
|
+
for (const command of builtinCommands)await command.apply(this);
|
|
693
1242
|
}
|
|
694
|
-
async buildConfig(item, options, command) {
|
|
1243
|
+
async buildConfig(item, pathMap, options, command) {
|
|
695
1244
|
const isBuild = "build" === command;
|
|
696
1245
|
const isServe = "serve" === command;
|
|
697
1246
|
const internalBuildConfig = async (item)=>{
|
|
@@ -701,7 +1250,7 @@ var __webpack_exports__ = {};
|
|
|
701
1250
|
item.output = item.output || {};
|
|
702
1251
|
if (options.outputPath) item.output.path = external_node_path_default().resolve(process.cwd(), options.outputPath);
|
|
703
1252
|
if (options.analyze) {
|
|
704
|
-
const { BundleAnalyzerPlugin } = await
|
|
1253
|
+
const { BundleAnalyzerPlugin } = await import("webpack-bundle-analyzer");
|
|
705
1254
|
(item.plugins ??= []).push({
|
|
706
1255
|
name: "rspack-bundle-analyzer",
|
|
707
1256
|
apply (compiler) {
|
|
@@ -713,7 +1262,7 @@ var __webpack_exports__ = {};
|
|
|
713
1262
|
}
|
|
714
1263
|
if (options.profile) item.profile = true;
|
|
715
1264
|
if (process.env.RSPACK_PROFILE) {
|
|
716
|
-
const { applyProfile } = await __webpack_require__.e("
|
|
1265
|
+
const { applyProfile } = await __webpack_require__.e("361").then(__webpack_require__.bind(__webpack_require__, "./src/utils/profile.ts"));
|
|
717
1266
|
await applyProfile(process.env.RSPACK_PROFILE, process.env.RSPACK_TRACE_LAYER, process.env.RSPACK_TRACE_OUTPUT);
|
|
718
1267
|
}
|
|
719
1268
|
if (options.watch) item.watch = options.watch;
|
|
@@ -722,8 +1271,16 @@ var __webpack_exports__ = {};
|
|
|
722
1271
|
if (void 0 === item.devtool) item.devtool = isBuild ? "source-map" : "cheap-module-source-map";
|
|
723
1272
|
if (void 0 !== options.devtool) item.devtool = options.devtool;
|
|
724
1273
|
if (isServe) {
|
|
725
|
-
const installed = (item.plugins ||= []).find((item)=>item instanceof
|
|
726
|
-
if (!installed) (item.plugins ??= []).push(new
|
|
1274
|
+
const installed = (item.plugins ||= []).find((item)=>item instanceof rspackCore.Z.ProgressPlugin);
|
|
1275
|
+
if (!installed) (item.plugins ??= []).push(new rspackCore.Z.ProgressPlugin());
|
|
1276
|
+
}
|
|
1277
|
+
const cacheOptions = item.experiments?.cache;
|
|
1278
|
+
if ("object" == typeof cacheOptions && "persistent" === cacheOptions.type) {
|
|
1279
|
+
const configPaths = pathMap.get(item);
|
|
1280
|
+
if (configPaths) cacheOptions.buildDependencies = [
|
|
1281
|
+
...configPaths,
|
|
1282
|
+
...cacheOptions.buildDependencies || []
|
|
1283
|
+
];
|
|
727
1284
|
}
|
|
728
1285
|
if (void 0 === item.stats) item.stats = {
|
|
729
1286
|
preset: "errors-warnings",
|
|
@@ -744,22 +1301,29 @@ var __webpack_exports__ = {};
|
|
|
744
1301
|
return internalBuildConfig(item);
|
|
745
1302
|
}
|
|
746
1303
|
async loadConfig(options) {
|
|
747
|
-
|
|
1304
|
+
const config = await loadRspackConfig(options);
|
|
1305
|
+
if (!config) return {
|
|
1306
|
+
config: this.filterConfig(options, {}),
|
|
1307
|
+
pathMap: new WeakMap()
|
|
1308
|
+
};
|
|
1309
|
+
let { loadedConfig, configPath } = config;
|
|
748
1310
|
if ("function" == typeof loadedConfig) {
|
|
749
|
-
|
|
750
|
-
let functionResult = loadedConfig(null == (_options_argv = options.argv) ? void 0 : _options_argv.env, options.argv);
|
|
1311
|
+
let functionResult = loadedConfig(options.env, options);
|
|
751
1312
|
if ("function" == typeof functionResult.then) functionResult = await functionResult;
|
|
752
1313
|
loadedConfig = functionResult;
|
|
753
|
-
if ("extends" in loadedConfig && loadedConfig.extends) {
|
|
754
|
-
const tempConfigPath = external_node_path_default().resolve(process.cwd(), "rspack.config.js");
|
|
755
|
-
loadedConfig = await loadExtendedConfig(loadedConfig, tempConfigPath, process.cwd(), options);
|
|
756
|
-
}
|
|
757
1314
|
}
|
|
1315
|
+
const { config: extendedConfig, pathMap } = await loadExtendedConfig(loadedConfig, configPath, process.cwd(), options);
|
|
1316
|
+
return {
|
|
1317
|
+
config: this.filterConfig(options, extendedConfig),
|
|
1318
|
+
pathMap
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
filterConfig(options, config) {
|
|
758
1322
|
if (options.configName) {
|
|
759
1323
|
const notFoundConfigNames = [];
|
|
760
|
-
|
|
1324
|
+
config = options.configName.map((configName)=>{
|
|
761
1325
|
let found;
|
|
762
|
-
found = Array.isArray(
|
|
1326
|
+
found = Array.isArray(config) ? config.find((options)=>options.name === configName) : config.name === configName ? config : void 0;
|
|
763
1327
|
if (!found) notFoundConfigNames.push(configName);
|
|
764
1328
|
return found;
|
|
765
1329
|
});
|
|
@@ -768,7 +1332,7 @@ var __webpack_exports__ = {};
|
|
|
768
1332
|
process.exit(2);
|
|
769
1333
|
}
|
|
770
1334
|
}
|
|
771
|
-
return
|
|
1335
|
+
return config;
|
|
772
1336
|
}
|
|
773
1337
|
isMultipleCompiler(compiler) {
|
|
774
1338
|
return Boolean(compiler.compilers);
|
|
@@ -776,12 +1340,6 @@ var __webpack_exports__ = {};
|
|
|
776
1340
|
isWatch(compiler) {
|
|
777
1341
|
return Boolean(this.isMultipleCompiler(compiler) ? compiler.compilers.some((compiler)=>compiler.options.watch) : compiler.options.watch);
|
|
778
1342
|
}
|
|
779
|
-
constructor(){
|
|
780
|
-
_define_property(this, "colors", void 0);
|
|
781
|
-
_define_property(this, "program", void 0);
|
|
782
|
-
this.colors = this.createColors();
|
|
783
|
-
this.program = external_yargs_default()();
|
|
784
|
-
}
|
|
785
1343
|
}
|
|
786
1344
|
function defineConfig(config) {
|
|
787
1345
|
return config;
|