@rspack/cli 1.7.2 → 2.0.0-canary-20260116
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/README.md +24 -0
- package/bin/rspack.js +2 -2
- package/dist/{131.mjs → 131.js} +31 -24
- package/dist/{1~274.mjs → 274.js} +1 -1
- package/dist/index.js +1 -1375
- package/dist/utils/options.d.ts +0 -2
- package/package.json +14 -11
- package/dist/0~274.js +0 -42
- package/dist/index.mjs +0 -1
- package/dist/utils/rspackCore.d.ts +0 -2
- /package/dist/{rslib-runtime.mjs → rslib-runtime.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,1375 +1 @@
|
|
|
1
|
-
|
|
2
|
-
return "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
|
|
3
|
-
}();
|
|
4
|
-
var __webpack_modules__ = {
|
|
5
|
-
"../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js" (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;
|
|
70
|
-
},
|
|
71
|
-
"../../node_modules/.pnpm/pirates@4.0.7/node_modules/pirates/lib/index.js" (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;
|
|
131
|
-
},
|
|
132
|
-
"./src/utils/rspackCore.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
|
|
133
|
-
"use strict";
|
|
134
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
135
|
-
Z: ()=>rspack
|
|
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');
|
|
140
|
-
},
|
|
141
|
-
module (module) {
|
|
142
|
-
"use strict";
|
|
143
|
-
module.exports = require("module");
|
|
144
|
-
},
|
|
145
|
-
"node:fs" (module) {
|
|
146
|
-
"use strict";
|
|
147
|
-
module.exports = require("node:fs");
|
|
148
|
-
},
|
|
149
|
-
"node:path" (module) {
|
|
150
|
-
"use strict";
|
|
151
|
-
module.exports = require("node:path");
|
|
152
|
-
},
|
|
153
|
-
path (module) {
|
|
154
|
-
"use strict";
|
|
155
|
-
module.exports = require("path");
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
var __webpack_module_cache__ = {};
|
|
159
|
-
function __webpack_require__(moduleId) {
|
|
160
|
-
var cachedModule = __webpack_module_cache__[moduleId];
|
|
161
|
-
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
162
|
-
var module = __webpack_module_cache__[moduleId] = {
|
|
163
|
-
id: moduleId,
|
|
164
|
-
loaded: false,
|
|
165
|
-
exports: {}
|
|
166
|
-
};
|
|
167
|
-
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
168
|
-
module.loaded = true;
|
|
169
|
-
return module.exports;
|
|
170
|
-
}
|
|
171
|
-
__webpack_require__.m = __webpack_modules__;
|
|
172
|
-
(()=>{
|
|
173
|
-
__webpack_require__.n = (module)=>{
|
|
174
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
175
|
-
__webpack_require__.d(getter, {
|
|
176
|
-
a: getter
|
|
177
|
-
});
|
|
178
|
-
return getter;
|
|
179
|
-
};
|
|
180
|
-
})();
|
|
181
|
-
(()=>{
|
|
182
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
183
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
184
|
-
enumerable: true,
|
|
185
|
-
get: definition[key]
|
|
186
|
-
});
|
|
187
|
-
};
|
|
188
|
-
})();
|
|
189
|
-
(()=>{
|
|
190
|
-
__webpack_require__.f = {};
|
|
191
|
-
__webpack_require__.e = (chunkId)=>Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key)=>{
|
|
192
|
-
__webpack_require__.f[key](chunkId, promises);
|
|
193
|
-
return promises;
|
|
194
|
-
}, []));
|
|
195
|
-
})();
|
|
196
|
-
(()=>{
|
|
197
|
-
__webpack_require__.u = (chunkId)=>"0~" + chunkId + ".js";
|
|
198
|
-
})();
|
|
199
|
-
(()=>{
|
|
200
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
201
|
-
})();
|
|
202
|
-
(()=>{
|
|
203
|
-
__webpack_require__.r = (exports1)=>{
|
|
204
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
205
|
-
value: 'Module'
|
|
206
|
-
});
|
|
207
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
208
|
-
value: true
|
|
209
|
-
});
|
|
210
|
-
};
|
|
211
|
-
})();
|
|
212
|
-
(()=>{
|
|
213
|
-
__webpack_require__.nmd = (module)=>{
|
|
214
|
-
module.paths = [];
|
|
215
|
-
if (!module.children) module.children = [];
|
|
216
|
-
return module;
|
|
217
|
-
};
|
|
218
|
-
})();
|
|
219
|
-
(()=>{
|
|
220
|
-
var installedChunks = {
|
|
221
|
-
410: 1
|
|
222
|
-
};
|
|
223
|
-
var installChunk = (chunk)=>{
|
|
224
|
-
var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;
|
|
225
|
-
for(var moduleId in moreModules)if (__webpack_require__.o(moreModules, moduleId)) __webpack_require__.m[moduleId] = moreModules[moduleId];
|
|
226
|
-
if (runtime) runtime(__webpack_require__);
|
|
227
|
-
for(var i = 0; i < chunkIds.length; i++)installedChunks[chunkIds[i]] = 1;
|
|
228
|
-
};
|
|
229
|
-
__webpack_require__.f.require = (chunkId, promises)=>{
|
|
230
|
-
if (!installedChunks[chunkId]) installChunk(require("./" + __webpack_require__.u(chunkId)));
|
|
231
|
-
};
|
|
232
|
-
})();
|
|
233
|
-
var __webpack_exports__ = {};
|
|
234
|
-
(()=>{
|
|
235
|
-
"use strict";
|
|
236
|
-
__webpack_require__.r(__webpack_exports__);
|
|
237
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
238
|
-
definePlugin: ()=>definePlugin,
|
|
239
|
-
RspackCLI: ()=>RspackCLI,
|
|
240
|
-
defineConfig: ()=>defineConfig
|
|
241
|
-
});
|
|
242
|
-
var external_node_path_ = __webpack_require__("node:path");
|
|
243
|
-
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_);
|
|
244
|
-
const external_node_util_namespaceObject = require("node:util");
|
|
245
|
-
var external_node_util_default = /*#__PURE__*/ __webpack_require__.n(external_node_util_namespaceObject);
|
|
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]);
|
|
290
|
-
}
|
|
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);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
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) {
|
|
787
|
-
function parseValue(previous, value) {
|
|
788
|
-
const [allKeys, val] = value.split(/=(.+)/, 2);
|
|
789
|
-
const splitKeys = allKeys.split(/\.(?!$)/);
|
|
790
|
-
let prevRef = previous;
|
|
791
|
-
splitKeys.forEach((key, index)=>{
|
|
792
|
-
let someKey = key;
|
|
793
|
-
if (someKey.endsWith('=')) {
|
|
794
|
-
someKey = someKey.slice(0, -1);
|
|
795
|
-
prevRef[someKey] = void 0;
|
|
796
|
-
return;
|
|
797
|
-
}
|
|
798
|
-
if (!prevRef[someKey] || 'string' == typeof prevRef[someKey]) prevRef[someKey] = {};
|
|
799
|
-
if (index === splitKeys.length - 1) if ('string' == typeof val) prevRef[someKey] = val;
|
|
800
|
-
else prevRef[someKey] = true;
|
|
801
|
-
prevRef = prevRef[someKey];
|
|
802
|
-
});
|
|
803
|
-
return previous;
|
|
804
|
-
}
|
|
805
|
-
return (options.env ?? []).reduce(parseValue, {});
|
|
806
|
-
}
|
|
807
|
-
function setDefaultNodeEnv(options, defaultEnv) {
|
|
808
|
-
if (void 0 === process.env.NODE_ENV) process.env.NODE_ENV = 'string' == typeof options.nodeEnv ? options.nodeEnv : defaultEnv;
|
|
809
|
-
}
|
|
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)
|
|
829
|
-
};
|
|
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);
|
|
837
|
-
};
|
|
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`);
|
|
841
|
-
});
|
|
842
|
-
} else {
|
|
843
|
-
const printedStats = stats.toString(statsOptions);
|
|
844
|
-
if (printedStats) logger.raw(printedStats);
|
|
845
|
-
}
|
|
846
|
-
};
|
|
847
|
-
const userOption = await cli.buildCompilerConfig(options, 'build');
|
|
848
|
-
const compiler = await cli.createCompiler(userOption, errorHandler);
|
|
849
|
-
if (!compiler || cli.isWatch(compiler)) return;
|
|
850
|
-
compiler.run((error, stats)=>{
|
|
851
|
-
compiler.close((closeErr)=>{
|
|
852
|
-
if (closeErr) logger.error(closeErr);
|
|
853
|
-
errorHandler(error, stats);
|
|
854
|
-
});
|
|
855
|
-
});
|
|
856
|
-
}
|
|
857
|
-
class BuildCommand {
|
|
858
|
-
async apply(cli) {
|
|
859
|
-
const command = cli.program.command('', 'run the Rspack build').alias('build').alias('bundle').alias('b');
|
|
860
|
-
commonOptionsForBuildAndServe(commonOptions(command)).option('--json [path]', 'emit stats json');
|
|
861
|
-
command.action(async (options)=>{
|
|
862
|
-
await runBuild(cli, options);
|
|
863
|
-
});
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
var rspackCore = __webpack_require__("./src/utils/rspackCore.ts");
|
|
867
|
-
class PreviewCommand {
|
|
868
|
-
async apply(cli) {
|
|
869
|
-
const command = cli.program.command('preview [dir]', 'run the Rspack server for build output').alias('p');
|
|
870
|
-
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.');
|
|
871
|
-
command.action(async (dir, options)=>{
|
|
872
|
-
setDefaultNodeEnv(options, 'production');
|
|
873
|
-
normalizeCommonOptions(options, 'preview');
|
|
874
|
-
const { RspackDevServer } = await import("@rspack/dev-server");
|
|
875
|
-
let { config } = await cli.loadConfig(options);
|
|
876
|
-
config = await getPreviewConfig(config, options, dir);
|
|
877
|
-
if (!Array.isArray(config)) config = [
|
|
878
|
-
config
|
|
879
|
-
];
|
|
880
|
-
const singleConfig = config.find((item)=>item.devServer) || config[0];
|
|
881
|
-
const devServerOptions = singleConfig.devServer;
|
|
882
|
-
try {
|
|
883
|
-
const compiler = (0, rspackCore.Z)({
|
|
884
|
-
entry: {}
|
|
885
|
-
});
|
|
886
|
-
if (!compiler) return;
|
|
887
|
-
const server = new RspackDevServer(devServerOptions, compiler);
|
|
888
|
-
await server.start();
|
|
889
|
-
} catch (error) {
|
|
890
|
-
const logger = cli.getLogger();
|
|
891
|
-
logger.error(error);
|
|
892
|
-
process.exit(2);
|
|
893
|
-
}
|
|
894
|
-
});
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
async function getPreviewConfig(item, options, dir) {
|
|
898
|
-
const DEFAULT_ROOT = 'dist';
|
|
899
|
-
const internalPreviewConfig = async (item)=>{
|
|
900
|
-
item.devServer = {
|
|
901
|
-
static: {
|
|
902
|
-
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),
|
|
903
|
-
publicPath: options.publicPath ?? '/'
|
|
904
|
-
},
|
|
905
|
-
port: options.port ?? 8080,
|
|
906
|
-
proxy: item.devServer?.proxy,
|
|
907
|
-
host: options.host ?? item.devServer?.host,
|
|
908
|
-
open: options.open ?? item.devServer?.open,
|
|
909
|
-
server: options.server ?? item.devServer?.server,
|
|
910
|
-
historyApiFallback: item.devServer?.historyApiFallback
|
|
911
|
-
};
|
|
912
|
-
return item;
|
|
913
|
-
};
|
|
914
|
-
if (Array.isArray(item)) return Promise.all(item.map(internalPreviewConfig));
|
|
915
|
-
return internalPreviewConfig(item);
|
|
916
|
-
}
|
|
917
|
-
function normalizeHotOption(value) {
|
|
918
|
-
if ('false' === value) return false;
|
|
919
|
-
if ('true' === value) return true;
|
|
920
|
-
return value;
|
|
921
|
-
}
|
|
922
|
-
class ServeCommand {
|
|
923
|
-
async apply(cli) {
|
|
924
|
-
const command = cli.program.command('serve', 'run the rspack dev server.').alias('server').alias('s').alias('dev');
|
|
925
|
-
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');
|
|
926
|
-
command.action(async (cliOptions)=>{
|
|
927
|
-
setDefaultNodeEnv(cliOptions, 'development');
|
|
928
|
-
normalizeCommonOptions(cliOptions, 'serve');
|
|
929
|
-
cliOptions.hot = normalizeHotOption(cliOptions.hot);
|
|
930
|
-
const { RspackDevServer } = await import("@rspack/dev-server");
|
|
931
|
-
const userConfig = await cli.buildCompilerConfig(cliOptions, 'serve');
|
|
932
|
-
const compiler = await cli.createCompiler(userConfig);
|
|
933
|
-
if (!compiler) return;
|
|
934
|
-
const isMultiCompiler = cli.isMultipleCompiler(compiler);
|
|
935
|
-
const compilers = isMultiCompiler ? compiler.compilers : [
|
|
936
|
-
compiler
|
|
937
|
-
];
|
|
938
|
-
const userConfigs = isMultiCompiler ? userConfig : [
|
|
939
|
-
userConfig
|
|
940
|
-
];
|
|
941
|
-
const possibleCompilers = compilers.filter((compiler)=>compiler.options.devServer);
|
|
942
|
-
const usedPorts = [];
|
|
943
|
-
const servers = [];
|
|
944
|
-
const compilerForDevServer = possibleCompilers.length > 0 ? possibleCompilers[0] : compilers[0];
|
|
945
|
-
for (const [index, compiler] of compilers.entries()){
|
|
946
|
-
const userConfig = userConfigs[index];
|
|
947
|
-
const devServer = compiler.options.devServer ??= {};
|
|
948
|
-
const isWebAppOnly = compiler.platform.web && !compiler.platform.node && !compiler.platform.nwjs && !compiler.platform.electron && !compiler.platform.webworker;
|
|
949
|
-
if (isWebAppOnly && void 0 === userConfig.lazyCompilation) compiler.options.lazyCompilation = {
|
|
950
|
-
imports: true,
|
|
951
|
-
entries: false
|
|
952
|
-
};
|
|
953
|
-
devServer.hot = cliOptions.hot ?? devServer.hot ?? true;
|
|
954
|
-
if (false !== devServer.client) {
|
|
955
|
-
if (true === devServer.client || null == devServer.client) devServer.client = {};
|
|
956
|
-
devServer.client = {
|
|
957
|
-
overlay: {
|
|
958
|
-
errors: true,
|
|
959
|
-
warnings: false
|
|
960
|
-
},
|
|
961
|
-
...devServer.client
|
|
962
|
-
};
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
const devServerOptions = compilerForDevServer.options.devServer ??= {};
|
|
966
|
-
const { setupMiddlewares } = devServerOptions;
|
|
967
|
-
const lazyCompileMiddleware = rspackCore.Z.lazyCompilationMiddleware(compiler);
|
|
968
|
-
devServerOptions.setupMiddlewares = (middlewares, server)=>{
|
|
969
|
-
let finalMiddlewares = middlewares;
|
|
970
|
-
if (setupMiddlewares) finalMiddlewares = setupMiddlewares(finalMiddlewares, server);
|
|
971
|
-
return [
|
|
972
|
-
...finalMiddlewares,
|
|
973
|
-
lazyCompileMiddleware
|
|
974
|
-
];
|
|
975
|
-
};
|
|
976
|
-
devServerOptions.hot = cliOptions.hot ?? devServerOptions.hot ?? true;
|
|
977
|
-
devServerOptions.host = cliOptions.host || devServerOptions.host;
|
|
978
|
-
devServerOptions.port = cliOptions.port ?? devServerOptions.port;
|
|
979
|
-
if (false !== devServerOptions.client) {
|
|
980
|
-
if (true === devServerOptions.client || null == devServerOptions.client) devServerOptions.client = {};
|
|
981
|
-
devServerOptions.client = {
|
|
982
|
-
overlay: {
|
|
983
|
-
errors: true,
|
|
984
|
-
warnings: false
|
|
985
|
-
},
|
|
986
|
-
...devServerOptions.client
|
|
987
|
-
};
|
|
988
|
-
}
|
|
989
|
-
if (devServerOptions.port) {
|
|
990
|
-
const portNumber = Number(devServerOptions.port);
|
|
991
|
-
if (!Number.isNaN(portNumber)) {
|
|
992
|
-
if (usedPorts.find((port)=>portNumber === port)) throw new Error('Unique ports must be specified for each devServer option in your rspack configuration. Alternatively, run only 1 devServer config using the --config-name flag to specify your desired config.');
|
|
993
|
-
usedPorts.push(portNumber);
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
try {
|
|
997
|
-
const server = new RspackDevServer(devServerOptions, compiler);
|
|
998
|
-
await server.start();
|
|
999
|
-
servers.push(server);
|
|
1000
|
-
} catch (error) {
|
|
1001
|
-
const logger = cli.getLogger();
|
|
1002
|
-
logger.error(error);
|
|
1003
|
-
process.exit(2);
|
|
1004
|
-
}
|
|
1005
|
-
});
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
var lib = __webpack_require__("../../node_modules/.pnpm/pirates@4.0.7/node_modules/pirates/lib/index.js");
|
|
1009
|
-
const external_node_url_namespaceObject = require("node:url");
|
|
1010
|
-
const readPackageUp = (cwd = process.cwd())=>{
|
|
1011
|
-
let currentDir = external_node_path_default().resolve(cwd);
|
|
1012
|
-
let packageJsonPath = external_node_path_default().join(currentDir, 'package.json');
|
|
1013
|
-
while(!external_node_fs_default().existsSync(packageJsonPath)){
|
|
1014
|
-
const parentDir = external_node_path_default().dirname(currentDir);
|
|
1015
|
-
if (parentDir === currentDir) return null;
|
|
1016
|
-
currentDir = parentDir;
|
|
1017
|
-
packageJsonPath = external_node_path_default().join(currentDir, 'package.json');
|
|
1018
|
-
}
|
|
1019
|
-
try {
|
|
1020
|
-
return JSON.parse(external_node_fs_default().readFileSync(packageJsonPath, 'utf8'));
|
|
1021
|
-
} catch {
|
|
1022
|
-
return null;
|
|
1023
|
-
}
|
|
1024
|
-
};
|
|
1025
|
-
const utils_readPackageUp = readPackageUp;
|
|
1026
|
-
const isEsmFile = (filePath)=>{
|
|
1027
|
-
if (/\.(mjs|mts)$/.test(filePath)) return true;
|
|
1028
|
-
if (/\.(cjs|cts)$/.test(filePath)) return false;
|
|
1029
|
-
const packageJson = utils_readPackageUp(external_node_path_default().dirname(filePath));
|
|
1030
|
-
return packageJson?.type === 'module';
|
|
1031
|
-
};
|
|
1032
|
-
const crossImport = async (path)=>{
|
|
1033
|
-
if (isEsmFile(path)) {
|
|
1034
|
-
const url = (0, external_node_url_namespaceObject.pathToFileURL)(path).href;
|
|
1035
|
-
const { default: config } = await import(url);
|
|
1036
|
-
return config;
|
|
1037
|
-
}
|
|
1038
|
-
let result = require(path);
|
|
1039
|
-
if (result && 'object' == typeof result && 'default' in result) result = result.default || {};
|
|
1040
|
-
return result;
|
|
1041
|
-
};
|
|
1042
|
-
const DEFAULT_EXTENSIONS = [
|
|
1043
|
-
'.js',
|
|
1044
|
-
'.ts',
|
|
1045
|
-
'.mjs',
|
|
1046
|
-
'.mts',
|
|
1047
|
-
'.cjs',
|
|
1048
|
-
'.cts'
|
|
1049
|
-
];
|
|
1050
|
-
const findConfig = (basePath)=>DEFAULT_EXTENSIONS.map((ext)=>basePath + ext).find(external_node_fs_default().existsSync);
|
|
1051
|
-
const utils_findConfig = findConfig;
|
|
1052
|
-
const TS_EXTENSION = [
|
|
1053
|
-
'.ts',
|
|
1054
|
-
'.cts',
|
|
1055
|
-
'.mts'
|
|
1056
|
-
];
|
|
1057
|
-
const isTsFile = (configPath)=>{
|
|
1058
|
-
const ext = external_node_path_default().extname(configPath);
|
|
1059
|
-
return TS_EXTENSION.includes(ext);
|
|
1060
|
-
};
|
|
1061
|
-
const utils_isTsFile = isTsFile;
|
|
1062
|
-
const injectInlineSourceMap = ({ code, map })=>{
|
|
1063
|
-
if (map) {
|
|
1064
|
-
const base64Map = Buffer.from(map, 'utf8').toString('base64');
|
|
1065
|
-
const sourceMapContent = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Map}`;
|
|
1066
|
-
return `${code}\n${sourceMapContent}`;
|
|
1067
|
-
}
|
|
1068
|
-
return code;
|
|
1069
|
-
};
|
|
1070
|
-
function compile(sourcecode, filename) {
|
|
1071
|
-
const { code, map } = rspackCore.Z.experiments.swc.transformSync(sourcecode, {
|
|
1072
|
-
jsc: {
|
|
1073
|
-
parser: {
|
|
1074
|
-
syntax: "typescript",
|
|
1075
|
-
tsx: false,
|
|
1076
|
-
decorators: true,
|
|
1077
|
-
dynamicImport: true
|
|
1078
|
-
}
|
|
1079
|
-
},
|
|
1080
|
-
filename: filename,
|
|
1081
|
-
module: {
|
|
1082
|
-
type: 'commonjs'
|
|
1083
|
-
},
|
|
1084
|
-
sourceMaps: true,
|
|
1085
|
-
isModule: true
|
|
1086
|
-
});
|
|
1087
|
-
return injectInlineSourceMap({
|
|
1088
|
-
code,
|
|
1089
|
-
map
|
|
1090
|
-
});
|
|
1091
|
-
}
|
|
1092
|
-
const loadConfig_DEFAULT_CONFIG_NAME = 'rspack.config';
|
|
1093
|
-
const registerLoader = (configPath)=>{
|
|
1094
|
-
if (isEsmFile(configPath) && utils_isTsFile(configPath)) return;
|
|
1095
|
-
if (!utils_isTsFile(configPath)) throw new Error(`config file "${configPath}" is not supported.`);
|
|
1096
|
-
(0, lib.addHook)((code, filename)=>{
|
|
1097
|
-
try {
|
|
1098
|
-
return compile(code, filename);
|
|
1099
|
-
} catch (err) {
|
|
1100
|
-
throw new Error(`Failed to transform file "${filename}" when loading TypeScript config file:\n ${err instanceof Error ? err.message : String(err)}`);
|
|
1101
|
-
}
|
|
1102
|
-
}, {
|
|
1103
|
-
exts: TS_EXTENSION
|
|
1104
|
-
});
|
|
1105
|
-
};
|
|
1106
|
-
const checkIsMultiRspackOptions = (config)=>Array.isArray(config);
|
|
1107
|
-
async function loadExtendedConfig(config, configPath, cwd, options) {
|
|
1108
|
-
if (checkIsMultiRspackOptions(config)) {
|
|
1109
|
-
const resultPathMap = new WeakMap();
|
|
1110
|
-
const extendedConfigs = await Promise.all(config.map(async (item)=>{
|
|
1111
|
-
const { config, pathMap } = await loadExtendedConfig(item, configPath, cwd, options);
|
|
1112
|
-
resultPathMap.set(config, pathMap.get(config));
|
|
1113
|
-
return config;
|
|
1114
|
-
}));
|
|
1115
|
-
extendedConfigs.parallelism = config.parallelism;
|
|
1116
|
-
return {
|
|
1117
|
-
config: extendedConfigs,
|
|
1118
|
-
pathMap: resultPathMap
|
|
1119
|
-
};
|
|
1120
|
-
}
|
|
1121
|
-
const pathMap = new WeakMap();
|
|
1122
|
-
pathMap.set(config, [
|
|
1123
|
-
configPath
|
|
1124
|
-
]);
|
|
1125
|
-
if (!('extends' in config) || !config.extends) return {
|
|
1126
|
-
config,
|
|
1127
|
-
pathMap
|
|
1128
|
-
};
|
|
1129
|
-
const extendsList = Array.isArray(config.extends) ? config.extends : [
|
|
1130
|
-
config.extends
|
|
1131
|
-
];
|
|
1132
|
-
const { extends: _, ...configWithoutExtends } = config;
|
|
1133
|
-
const baseDir = external_node_path_default().dirname(configPath);
|
|
1134
|
-
let resultConfig = configWithoutExtends;
|
|
1135
|
-
pathMap.set(resultConfig, [
|
|
1136
|
-
configPath
|
|
1137
|
-
]);
|
|
1138
|
-
for (const extendPath of extendsList){
|
|
1139
|
-
let resolvedPath;
|
|
1140
|
-
if (extendPath.startsWith('.') || extendPath.startsWith('/') || extendPath.includes(':\\')) {
|
|
1141
|
-
resolvedPath = external_node_path_default().resolve(baseDir, extendPath);
|
|
1142
|
-
if (!external_node_path_default().extname(resolvedPath)) {
|
|
1143
|
-
const foundConfig = utils_findConfig(resolvedPath);
|
|
1144
|
-
if (foundConfig) resolvedPath = foundConfig;
|
|
1145
|
-
else throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
|
|
1146
|
-
}
|
|
1147
|
-
} else try {
|
|
1148
|
-
resolvedPath = require.resolve(extendPath, {
|
|
1149
|
-
paths: [
|
|
1150
|
-
baseDir,
|
|
1151
|
-
cwd
|
|
1152
|
-
]
|
|
1153
|
-
});
|
|
1154
|
-
} catch {
|
|
1155
|
-
throw new Error(`Cannot find module '${extendPath}' to extend from.`);
|
|
1156
|
-
}
|
|
1157
|
-
if (!external_node_fs_default().existsSync(resolvedPath)) throw new Error(`Extended configuration file "${resolvedPath}" not found.`);
|
|
1158
|
-
if (utils_isTsFile(resolvedPath) && 'register' === options.configLoader) registerLoader(resolvedPath);
|
|
1159
|
-
let loadedConfig = await crossImport(resolvedPath);
|
|
1160
|
-
if ('function' == typeof loadedConfig) {
|
|
1161
|
-
loadedConfig = loadedConfig(options.env, options);
|
|
1162
|
-
if ('function' == typeof loadedConfig.then) loadedConfig = await loadedConfig;
|
|
1163
|
-
}
|
|
1164
|
-
const { config: extendedConfig, pathMap: extendedPathMap } = await loadExtendedConfig(loadedConfig, resolvedPath, cwd, options);
|
|
1165
|
-
const configPaths = [
|
|
1166
|
-
...pathMap.get(resultConfig) || [],
|
|
1167
|
-
...extendedPathMap.get(extendedConfig) || []
|
|
1168
|
-
];
|
|
1169
|
-
resultConfig = rspackCore.Z.util.cleverMerge(extendedConfig, resultConfig);
|
|
1170
|
-
pathMap.set(resultConfig, configPaths);
|
|
1171
|
-
}
|
|
1172
|
-
return {
|
|
1173
|
-
config: resultConfig,
|
|
1174
|
-
pathMap
|
|
1175
|
-
};
|
|
1176
|
-
}
|
|
1177
|
-
async function loadRspackConfig(options, cwd = process.cwd()) {
|
|
1178
|
-
let configPath = '';
|
|
1179
|
-
if (options.config) {
|
|
1180
|
-
configPath = external_node_path_default().resolve(cwd, options.config);
|
|
1181
|
-
if (!external_node_fs_default().existsSync(configPath)) throw new Error(`config file "${configPath}" not found.`);
|
|
1182
|
-
} else {
|
|
1183
|
-
const defaultConfig = utils_findConfig(external_node_path_default().resolve(cwd, loadConfig_DEFAULT_CONFIG_NAME));
|
|
1184
|
-
if (!defaultConfig) return null;
|
|
1185
|
-
configPath = defaultConfig;
|
|
1186
|
-
}
|
|
1187
|
-
if (utils_isTsFile(configPath) && 'register' === options.configLoader) registerLoader(configPath);
|
|
1188
|
-
const loadedConfig = await crossImport(configPath);
|
|
1189
|
-
return {
|
|
1190
|
-
loadedConfig,
|
|
1191
|
-
configPath
|
|
1192
|
-
};
|
|
1193
|
-
}
|
|
1194
|
-
class RspackCLI {
|
|
1195
|
-
colors;
|
|
1196
|
-
program;
|
|
1197
|
-
constructor(){
|
|
1198
|
-
const program = dist('rspack');
|
|
1199
|
-
this.colors = this.createColors();
|
|
1200
|
-
this.program = program;
|
|
1201
|
-
program.help();
|
|
1202
|
-
program.version("1.7.2");
|
|
1203
|
-
}
|
|
1204
|
-
async buildCompilerConfig(options, rspackCommand) {
|
|
1205
|
-
let { config, pathMap } = await this.loadConfig(options);
|
|
1206
|
-
config = await this.buildConfig(config, pathMap, options, rspackCommand);
|
|
1207
|
-
return config;
|
|
1208
|
-
}
|
|
1209
|
-
async createCompiler(config, callback) {
|
|
1210
|
-
const isWatch = Array.isArray(config) ? config.some((i)=>i.watch) : config.watch;
|
|
1211
|
-
let compiler;
|
|
1212
|
-
try {
|
|
1213
|
-
compiler = (0, rspackCore.Z)(config, isWatch ? callback : void 0);
|
|
1214
|
-
if (!isWatch && compiler) compiler.unsafeFastDrop = true;
|
|
1215
|
-
} catch (e) {
|
|
1216
|
-
if (e instanceof rspackCore.Z.ValidationError) {
|
|
1217
|
-
this.getLogger().error(e.message);
|
|
1218
|
-
process.exit(2);
|
|
1219
|
-
} else if (e instanceof Error) {
|
|
1220
|
-
if ('function' == typeof callback) callback(e);
|
|
1221
|
-
else this.getLogger().error(e);
|
|
1222
|
-
return null;
|
|
1223
|
-
}
|
|
1224
|
-
throw e;
|
|
1225
|
-
}
|
|
1226
|
-
return compiler;
|
|
1227
|
-
}
|
|
1228
|
-
createColors(useColor) {
|
|
1229
|
-
const shouldUseColor = useColor || picocolors.isColorSupported;
|
|
1230
|
-
return {
|
|
1231
|
-
...(0, picocolors.createColors)(shouldUseColor),
|
|
1232
|
-
isColorSupported: shouldUseColor
|
|
1233
|
-
};
|
|
1234
|
-
}
|
|
1235
|
-
getLogger() {
|
|
1236
|
-
return {
|
|
1237
|
-
error: (val)=>console.error(`[rspack-cli] ${this.colors.red(external_node_util_default().format(val))}`),
|
|
1238
|
-
warn: (val)=>console.warn(`[rspack-cli] ${this.colors.yellow(val)}`),
|
|
1239
|
-
info: (val)=>console.info(`[rspack-cli] ${this.colors.cyan(val)}`),
|
|
1240
|
-
success: (val)=>console.log(`[rspack-cli] ${this.colors.green(val)}`),
|
|
1241
|
-
log: (val)=>console.log(`[rspack-cli] ${val}`),
|
|
1242
|
-
raw: (val)=>console.log(val)
|
|
1243
|
-
};
|
|
1244
|
-
}
|
|
1245
|
-
async run(argv) {
|
|
1246
|
-
await this.registerCommands();
|
|
1247
|
-
this.program.parse(argv);
|
|
1248
|
-
}
|
|
1249
|
-
async registerCommands() {
|
|
1250
|
-
const builtinCommands = [
|
|
1251
|
-
new BuildCommand(),
|
|
1252
|
-
new ServeCommand(),
|
|
1253
|
-
new PreviewCommand()
|
|
1254
|
-
];
|
|
1255
|
-
for (const command of builtinCommands)await command.apply(this);
|
|
1256
|
-
}
|
|
1257
|
-
async buildConfig(item, pathMap, options, command) {
|
|
1258
|
-
const isBuild = 'build' === command;
|
|
1259
|
-
const isServe = 'serve' === command;
|
|
1260
|
-
const internalBuildConfig = async (item)=>{
|
|
1261
|
-
if (options.entry) item.entry = {
|
|
1262
|
-
main: options.entry.map((x)=>external_node_path_default().resolve(process.cwd(), x))[0]
|
|
1263
|
-
};
|
|
1264
|
-
item.output = item.output || {};
|
|
1265
|
-
if (options.outputPath) item.output.path = external_node_path_default().resolve(process.cwd(), options.outputPath);
|
|
1266
|
-
if (options.analyze) {
|
|
1267
|
-
const { BundleAnalyzerPlugin } = await import("webpack-bundle-analyzer");
|
|
1268
|
-
(item.plugins ??= []).push({
|
|
1269
|
-
name: 'rspack-bundle-analyzer',
|
|
1270
|
-
apply (compiler) {
|
|
1271
|
-
new BundleAnalyzerPlugin({
|
|
1272
|
-
generateStatsFile: true
|
|
1273
|
-
}).apply(compiler);
|
|
1274
|
-
}
|
|
1275
|
-
});
|
|
1276
|
-
}
|
|
1277
|
-
if (options.profile) item.profile = true;
|
|
1278
|
-
if (process.env.RSPACK_PROFILE) {
|
|
1279
|
-
const { applyProfile } = await __webpack_require__.e("274").then(__webpack_require__.bind(__webpack_require__, "./src/utils/profile.ts"));
|
|
1280
|
-
await applyProfile(process.env.RSPACK_PROFILE, process.env.RSPACK_TRACE_LAYER, process.env.RSPACK_TRACE_OUTPUT);
|
|
1281
|
-
}
|
|
1282
|
-
if (options.watch) item.watch = options.watch;
|
|
1283
|
-
if (!item.mode) item.mode = isBuild ? 'production' : 'development';
|
|
1284
|
-
if (options.mode) item.mode = options.mode;
|
|
1285
|
-
if (void 0 === item.devtool) item.devtool = isBuild ? 'source-map' : 'cheap-module-source-map';
|
|
1286
|
-
if (void 0 !== options.devtool) item.devtool = options.devtool;
|
|
1287
|
-
if (isServe) {
|
|
1288
|
-
const installed = (item.plugins ||= []).find((item)=>item instanceof rspackCore.Z.ProgressPlugin);
|
|
1289
|
-
if (!installed) (item.plugins ??= []).push(new rspackCore.Z.ProgressPlugin());
|
|
1290
|
-
}
|
|
1291
|
-
const cacheOptions = item.experiments?.cache;
|
|
1292
|
-
if ('object' == typeof cacheOptions && 'persistent' === cacheOptions.type) {
|
|
1293
|
-
const configPaths = pathMap.get(item);
|
|
1294
|
-
if (configPaths) cacheOptions.buildDependencies = [
|
|
1295
|
-
...configPaths,
|
|
1296
|
-
...cacheOptions.buildDependencies || []
|
|
1297
|
-
];
|
|
1298
|
-
}
|
|
1299
|
-
if (void 0 === item.stats) item.stats = {
|
|
1300
|
-
preset: 'errors-warnings',
|
|
1301
|
-
timings: true
|
|
1302
|
-
};
|
|
1303
|
-
else if ('boolean' == typeof item.stats) item.stats = item.stats ? {
|
|
1304
|
-
preset: 'normal'
|
|
1305
|
-
} : {
|
|
1306
|
-
preset: 'none'
|
|
1307
|
-
};
|
|
1308
|
-
else if ('string' == typeof item.stats) item.stats = {
|
|
1309
|
-
preset: item.stats
|
|
1310
|
-
};
|
|
1311
|
-
if (this.colors.isColorSupported && void 0 === item.stats.colors) item.stats.colors = true;
|
|
1312
|
-
return item;
|
|
1313
|
-
};
|
|
1314
|
-
if (Array.isArray(item)) return Promise.all(item.map(internalBuildConfig));
|
|
1315
|
-
return internalBuildConfig(item);
|
|
1316
|
-
}
|
|
1317
|
-
async loadConfig(options) {
|
|
1318
|
-
const config = await loadRspackConfig(options);
|
|
1319
|
-
if (!config) return {
|
|
1320
|
-
config: this.filterConfig(options, {}),
|
|
1321
|
-
pathMap: new WeakMap()
|
|
1322
|
-
};
|
|
1323
|
-
let { loadedConfig, configPath } = config;
|
|
1324
|
-
if ('function' == typeof loadedConfig) {
|
|
1325
|
-
let functionResult = loadedConfig(options.env, options);
|
|
1326
|
-
if ('function' == typeof functionResult.then) functionResult = await functionResult;
|
|
1327
|
-
loadedConfig = functionResult;
|
|
1328
|
-
}
|
|
1329
|
-
const { config: extendedConfig, pathMap } = await loadExtendedConfig(loadedConfig, configPath, process.cwd(), options);
|
|
1330
|
-
return {
|
|
1331
|
-
config: this.filterConfig(options, extendedConfig),
|
|
1332
|
-
pathMap
|
|
1333
|
-
};
|
|
1334
|
-
}
|
|
1335
|
-
filterConfig(options, config) {
|
|
1336
|
-
if (options.configName) {
|
|
1337
|
-
const notFoundConfigNames = [];
|
|
1338
|
-
config = options.configName.map((configName)=>{
|
|
1339
|
-
let found;
|
|
1340
|
-
found = Array.isArray(config) ? config.find((options)=>options.name === configName) : config.name === configName ? config : void 0;
|
|
1341
|
-
if (!found) notFoundConfigNames.push(configName);
|
|
1342
|
-
return found;
|
|
1343
|
-
});
|
|
1344
|
-
if (notFoundConfigNames.length > 0) {
|
|
1345
|
-
this.getLogger().error(notFoundConfigNames.map((configName)=>`Configuration with the name "${configName}" was not found.`).join(' '));
|
|
1346
|
-
process.exit(2);
|
|
1347
|
-
}
|
|
1348
|
-
}
|
|
1349
|
-
return config;
|
|
1350
|
-
}
|
|
1351
|
-
isMultipleCompiler(compiler) {
|
|
1352
|
-
return Boolean(compiler.compilers);
|
|
1353
|
-
}
|
|
1354
|
-
isWatch(compiler) {
|
|
1355
|
-
return Boolean(this.isMultipleCompiler(compiler) ? compiler.compilers.some((compiler)=>compiler.options.watch) : compiler.options.watch);
|
|
1356
|
-
}
|
|
1357
|
-
}
|
|
1358
|
-
function defineConfig(config) {
|
|
1359
|
-
return config;
|
|
1360
|
-
}
|
|
1361
|
-
function definePlugin(plugin) {
|
|
1362
|
-
return plugin;
|
|
1363
|
-
}
|
|
1364
|
-
})();
|
|
1365
|
-
exports.RspackCLI = __webpack_exports__.RspackCLI;
|
|
1366
|
-
exports.defineConfig = __webpack_exports__.defineConfig;
|
|
1367
|
-
exports.definePlugin = __webpack_exports__.definePlugin;
|
|
1368
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
1369
|
-
"RspackCLI",
|
|
1370
|
-
"defineConfig",
|
|
1371
|
-
"definePlugin"
|
|
1372
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
1373
|
-
Object.defineProperty(exports, '__esModule', {
|
|
1374
|
-
value: true
|
|
1375
|
-
});
|
|
1
|
+
export { RspackCLI, defineConfig, definePlugin } from "./131.js";
|