@rollipop/rolldown 1.0.0-rc.4 → 1.0.0-rc.6
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/cli.mjs +768 -185
- package/dist/config.d.mts +1 -2
- package/dist/config.mjs +2 -8
- package/dist/experimental-index.d.mts +13 -7
- package/dist/experimental-index.mjs +27 -13
- package/dist/filter-index.d.mts +1 -2
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +5 -10
- package/dist/parallel-plugin-worker.mjs +2 -5
- package/dist/parallel-plugin.d.mts +1 -2
- package/dist/parse-ast-index.d.mts +1 -1
- package/dist/parse-ast-index.mjs +1 -2
- package/dist/plugins-index.d.mts +3 -3
- package/dist/plugins-index.mjs +2 -3
- package/dist/shared/{binding-BohGL_65.d.mts → binding-BEVObikP.d.mts} +40 -17
- package/dist/shared/{binding-BuW0Fhs2.mjs → binding-BaD00V3B.mjs} +26 -26
- package/dist/shared/{bindingify-input-options-o_7NioSs.mjs → bindingify-input-options-KbcygofY.mjs} +52 -13
- package/dist/shared/{constructors-Dg8A45sy.d.mts → constructors-C0o3D5kM.d.mts} +7 -3
- package/dist/shared/{constructors-FqGyV5fj.mjs → constructors-DoVEGpfv.mjs} +8 -2
- package/dist/shared/{define-config-BvszQ-i2.d.mts → define-config-Dcf0-wDh.d.mts} +70 -12
- package/dist/shared/{error-BjNWBTlf.mjs → error-DMdvzIth.mjs} +1 -1
- package/dist/shared/{load-config-2dmAH96P.mjs → load-config-Cl0c9rzt.mjs} +1 -1
- package/dist/shared/{normalize-string-or-regex-BU5HSJy4.mjs → normalize-string-or-regex-C438JWX3.mjs} +20 -12
- package/dist/shared/{parse-Bt4kI3ey.mjs → parse-B_pfrOxH.mjs} +2 -2
- package/dist/shared/{transform-Cbhgjik0.mjs → resolve-tsconfig-C4k6MVJe.mjs} +28 -5
- package/dist/shared/{rolldown-build-tLuGZc7p.mjs → rolldown-build-CLB7U-T8.mjs} +20 -12
- package/dist/shared/{rolldown-B4lV-glW.mjs → rolldown-cb9tsyMG.mjs} +1 -1
- package/dist/shared/{transform-BoJxrM-e.d.mts → transform-CHWi6pVJ.d.mts} +19 -2
- package/dist/shared/{watch-hs9ntURJ.mjs → watch-dXreyeuN.mjs} +4 -4
- package/dist/utils-index.d.mts +3 -3
- package/dist/utils-index.mjs +5 -8
- package/package.json +19 -18
package/dist/cli.mjs
CHANGED
|
@@ -1,17 +1,630 @@
|
|
|
1
|
-
import "./shared/
|
|
2
|
-
import {
|
|
3
|
-
import "./shared/normalize-string-or-regex-BU5HSJy4.mjs";
|
|
4
|
-
import { S as version, x as description } from "./shared/bindingify-input-options-o_7NioSs.mjs";
|
|
1
|
+
import { n as onExit, t as watch } from "./shared/watch-dXreyeuN.mjs";
|
|
2
|
+
import { C as version, S as description } from "./shared/bindingify-input-options-KbcygofY.mjs";
|
|
5
3
|
import { t as arraify } from "./shared/misc-DJYbNKZX.mjs";
|
|
6
|
-
import { a as getInputCliKeys, i as getCliSchemaInfo, l as styleText
|
|
7
|
-
import "./shared/
|
|
8
|
-
import "./shared/
|
|
9
|
-
import { t as rolldown } from "./shared/rolldown-B4lV-glW.mjs";
|
|
10
|
-
import { t as loadConfig } from "./shared/load-config-2dmAH96P.mjs";
|
|
4
|
+
import { a as getInputCliKeys, i as getCliSchemaInfo, l as styleText, o as getOutputCliKeys, r as logger, s as validateCliOptions } from "./shared/rolldown-build-CLB7U-T8.mjs";
|
|
5
|
+
import { t as rolldown } from "./shared/rolldown-cb9tsyMG.mjs";
|
|
6
|
+
import { t as loadConfig } from "./shared/load-config-Cl0c9rzt.mjs";
|
|
11
7
|
import path from "node:path";
|
|
12
|
-
import { parseArgs } from "node:util";
|
|
13
8
|
import process$1 from "node:process";
|
|
14
9
|
import { performance } from "node:perf_hooks";
|
|
10
|
+
//#region ../../node_modules/.pnpm/cac@7.0.0/node_modules/cac/dist/index.js
|
|
11
|
+
function toArr(any) {
|
|
12
|
+
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
13
|
+
}
|
|
14
|
+
function toVal(out, key, val, opts) {
|
|
15
|
+
var x, old = out[key], nxt = !!~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : !!~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
|
|
16
|
+
out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
|
|
17
|
+
}
|
|
18
|
+
function lib_default(args, opts) {
|
|
19
|
+
args = args || [];
|
|
20
|
+
opts = opts || {};
|
|
21
|
+
var k, arr, arg, name, val, out = { _: [] };
|
|
22
|
+
var i = 0, j = 0, idx = 0, len = args.length;
|
|
23
|
+
const alibi = opts.alias !== void 0;
|
|
24
|
+
const strict = opts.unknown !== void 0;
|
|
25
|
+
const defaults = opts.default !== void 0;
|
|
26
|
+
opts.alias = opts.alias || {};
|
|
27
|
+
opts.string = toArr(opts.string);
|
|
28
|
+
opts.boolean = toArr(opts.boolean);
|
|
29
|
+
if (alibi) for (k in opts.alias) {
|
|
30
|
+
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
31
|
+
for (i = 0; i < arr.length; i++) (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
32
|
+
}
|
|
33
|
+
for (i = opts.boolean.length; i-- > 0;) {
|
|
34
|
+
arr = opts.alias[opts.boolean[i]] || [];
|
|
35
|
+
for (j = arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
|
36
|
+
}
|
|
37
|
+
for (i = opts.string.length; i-- > 0;) {
|
|
38
|
+
arr = opts.alias[opts.string[i]] || [];
|
|
39
|
+
for (j = arr.length; j-- > 0;) opts.string.push(arr[j]);
|
|
40
|
+
}
|
|
41
|
+
if (defaults) for (k in opts.default) {
|
|
42
|
+
name = typeof opts.default[k];
|
|
43
|
+
arr = opts.alias[k] = opts.alias[k] || [];
|
|
44
|
+
if (opts[name] !== void 0) {
|
|
45
|
+
opts[name].push(k);
|
|
46
|
+
for (i = 0; i < arr.length; i++) opts[name].push(arr[i]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const keys = strict ? Object.keys(opts.alias) : [];
|
|
50
|
+
for (i = 0; i < len; i++) {
|
|
51
|
+
arg = args[i];
|
|
52
|
+
if (arg === "--") {
|
|
53
|
+
out._ = out._.concat(args.slice(++i));
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
for (j = 0; j < arg.length; j++) if (arg.charCodeAt(j) !== 45) break;
|
|
57
|
+
if (j === 0) out._.push(arg);
|
|
58
|
+
else if (arg.substring(j, j + 3) === "no-") {
|
|
59
|
+
name = arg.substring(j + 3);
|
|
60
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
|
|
61
|
+
out[name] = false;
|
|
62
|
+
} else {
|
|
63
|
+
for (idx = j + 1; idx < arg.length; idx++) if (arg.charCodeAt(idx) === 61) break;
|
|
64
|
+
name = arg.substring(j, idx);
|
|
65
|
+
val = arg.substring(++idx) || i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i];
|
|
66
|
+
arr = j === 2 ? [name] : name;
|
|
67
|
+
for (idx = 0; idx < arr.length; idx++) {
|
|
68
|
+
name = arr[idx];
|
|
69
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
|
|
70
|
+
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (defaults) {
|
|
75
|
+
for (k in opts.default) if (out[k] === void 0) out[k] = opts.default[k];
|
|
76
|
+
}
|
|
77
|
+
if (alibi) for (k in out) {
|
|
78
|
+
arr = opts.alias[k] || [];
|
|
79
|
+
while (arr.length > 0) out[arr.shift()] = out[k];
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
function removeBrackets(v) {
|
|
84
|
+
return v.replace(/[<[].+/, "").trim();
|
|
85
|
+
}
|
|
86
|
+
function findAllBrackets(v) {
|
|
87
|
+
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
|
88
|
+
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
|
89
|
+
const res = [];
|
|
90
|
+
const parse = (match) => {
|
|
91
|
+
let variadic = false;
|
|
92
|
+
let value = match[1];
|
|
93
|
+
if (value.startsWith("...")) {
|
|
94
|
+
value = value.slice(3);
|
|
95
|
+
variadic = true;
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
required: match[0].startsWith("<"),
|
|
99
|
+
value,
|
|
100
|
+
variadic
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
let angledMatch;
|
|
104
|
+
while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(angledMatch));
|
|
105
|
+
let squareMatch;
|
|
106
|
+
while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(squareMatch));
|
|
107
|
+
return res;
|
|
108
|
+
}
|
|
109
|
+
function getMriOptions(options) {
|
|
110
|
+
const result = {
|
|
111
|
+
alias: {},
|
|
112
|
+
boolean: []
|
|
113
|
+
};
|
|
114
|
+
for (const [index, option] of options.entries()) {
|
|
115
|
+
if (option.names.length > 1) result.alias[option.names[0]] = option.names.slice(1);
|
|
116
|
+
if (option.isBoolean) if (option.negated) {
|
|
117
|
+
if (!options.some((o, i) => {
|
|
118
|
+
return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
|
|
119
|
+
})) result.boolean.push(option.names[0]);
|
|
120
|
+
} else result.boolean.push(option.names[0]);
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
function findLongest(arr) {
|
|
125
|
+
return arr.sort((a, b) => {
|
|
126
|
+
return a.length > b.length ? -1 : 1;
|
|
127
|
+
})[0];
|
|
128
|
+
}
|
|
129
|
+
function padRight(str, length) {
|
|
130
|
+
return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
|
131
|
+
}
|
|
132
|
+
function camelcase(input) {
|
|
133
|
+
return input.replaceAll(/([a-z])-([a-z])/g, (_, p1, p2) => {
|
|
134
|
+
return p1 + p2.toUpperCase();
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function setDotProp(obj, keys, val) {
|
|
138
|
+
let current = obj;
|
|
139
|
+
for (let i = 0; i < keys.length; i++) {
|
|
140
|
+
const key = keys[i];
|
|
141
|
+
if (i === keys.length - 1) {
|
|
142
|
+
current[key] = val;
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (current[key] == null) {
|
|
146
|
+
const nextKeyIsArrayIndex = +keys[i + 1] > -1;
|
|
147
|
+
current[key] = nextKeyIsArrayIndex ? [] : {};
|
|
148
|
+
}
|
|
149
|
+
current = current[key];
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function setByType(obj, transforms) {
|
|
153
|
+
for (const key of Object.keys(transforms)) {
|
|
154
|
+
const transform = transforms[key];
|
|
155
|
+
if (transform.shouldTransform) {
|
|
156
|
+
obj[key] = [obj[key]].flat();
|
|
157
|
+
if (typeof transform.transformFunction === "function") obj[key] = obj[key].map(transform.transformFunction);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function getFileName(input) {
|
|
162
|
+
const m = /([^\\/]+)$/.exec(input);
|
|
163
|
+
return m ? m[1] : "";
|
|
164
|
+
}
|
|
165
|
+
function camelcaseOptionName(name) {
|
|
166
|
+
return name.split(".").map((v, i) => {
|
|
167
|
+
return i === 0 ? camelcase(v) : v;
|
|
168
|
+
}).join(".");
|
|
169
|
+
}
|
|
170
|
+
var CACError = class extends Error {
|
|
171
|
+
constructor(message) {
|
|
172
|
+
super(message);
|
|
173
|
+
this.name = "CACError";
|
|
174
|
+
if (typeof Error.captureStackTrace !== "function") this.stack = new Error(message).stack;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
var Option = class {
|
|
178
|
+
rawName;
|
|
179
|
+
description;
|
|
180
|
+
/** Option name */
|
|
181
|
+
name;
|
|
182
|
+
/** Option name and aliases */
|
|
183
|
+
names;
|
|
184
|
+
isBoolean;
|
|
185
|
+
required;
|
|
186
|
+
config;
|
|
187
|
+
negated;
|
|
188
|
+
constructor(rawName, description, config) {
|
|
189
|
+
this.rawName = rawName;
|
|
190
|
+
this.description = description;
|
|
191
|
+
this.config = Object.assign({}, config);
|
|
192
|
+
rawName = rawName.replaceAll(".*", "");
|
|
193
|
+
this.negated = false;
|
|
194
|
+
this.names = removeBrackets(rawName).split(",").map((v) => {
|
|
195
|
+
let name = v.trim().replace(/^-{1,2}/, "");
|
|
196
|
+
if (name.startsWith("no-")) {
|
|
197
|
+
this.negated = true;
|
|
198
|
+
name = name.replace(/^no-/, "");
|
|
199
|
+
}
|
|
200
|
+
return camelcaseOptionName(name);
|
|
201
|
+
}).sort((a, b) => a.length > b.length ? 1 : -1);
|
|
202
|
+
this.name = this.names.at(-1);
|
|
203
|
+
if (this.negated && this.config.default == null) this.config.default = true;
|
|
204
|
+
if (rawName.includes("<")) this.required = true;
|
|
205
|
+
else if (rawName.includes("[")) this.required = false;
|
|
206
|
+
else this.isBoolean = true;
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
let runtimeProcessArgs;
|
|
210
|
+
let runtimeInfo;
|
|
211
|
+
if (typeof process !== "undefined") {
|
|
212
|
+
let runtimeName;
|
|
213
|
+
if (typeof Deno !== "undefined" && typeof Deno.version?.deno === "string") runtimeName = "deno";
|
|
214
|
+
else if (typeof Bun !== "undefined" && typeof Bun.version === "string") runtimeName = "bun";
|
|
215
|
+
else runtimeName = "node";
|
|
216
|
+
runtimeInfo = `${process.platform}-${process.arch} ${runtimeName}-${process.version}`;
|
|
217
|
+
runtimeProcessArgs = process.argv;
|
|
218
|
+
} else if (typeof navigator === "undefined") runtimeInfo = `unknown`;
|
|
219
|
+
else runtimeInfo = `${navigator.platform} ${navigator.userAgent}`;
|
|
220
|
+
var Command = class {
|
|
221
|
+
rawName;
|
|
222
|
+
description;
|
|
223
|
+
config;
|
|
224
|
+
cli;
|
|
225
|
+
options;
|
|
226
|
+
aliasNames;
|
|
227
|
+
name;
|
|
228
|
+
args;
|
|
229
|
+
commandAction;
|
|
230
|
+
usageText;
|
|
231
|
+
versionNumber;
|
|
232
|
+
examples;
|
|
233
|
+
helpCallback;
|
|
234
|
+
globalCommand;
|
|
235
|
+
constructor(rawName, description, config = {}, cli) {
|
|
236
|
+
this.rawName = rawName;
|
|
237
|
+
this.description = description;
|
|
238
|
+
this.config = config;
|
|
239
|
+
this.cli = cli;
|
|
240
|
+
this.options = [];
|
|
241
|
+
this.aliasNames = [];
|
|
242
|
+
this.name = removeBrackets(rawName);
|
|
243
|
+
this.args = findAllBrackets(rawName);
|
|
244
|
+
this.examples = [];
|
|
245
|
+
}
|
|
246
|
+
usage(text) {
|
|
247
|
+
this.usageText = text;
|
|
248
|
+
return this;
|
|
249
|
+
}
|
|
250
|
+
allowUnknownOptions() {
|
|
251
|
+
this.config.allowUnknownOptions = true;
|
|
252
|
+
return this;
|
|
253
|
+
}
|
|
254
|
+
ignoreOptionDefaultValue() {
|
|
255
|
+
this.config.ignoreOptionDefaultValue = true;
|
|
256
|
+
return this;
|
|
257
|
+
}
|
|
258
|
+
version(version, customFlags = "-v, --version") {
|
|
259
|
+
this.versionNumber = version;
|
|
260
|
+
this.option(customFlags, "Display version number");
|
|
261
|
+
return this;
|
|
262
|
+
}
|
|
263
|
+
example(example) {
|
|
264
|
+
this.examples.push(example);
|
|
265
|
+
return this;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Add a option for this command
|
|
269
|
+
* @param rawName Raw option name(s)
|
|
270
|
+
* @param description Option description
|
|
271
|
+
* @param config Option config
|
|
272
|
+
*/
|
|
273
|
+
option(rawName, description, config) {
|
|
274
|
+
const option = new Option(rawName, description, config);
|
|
275
|
+
this.options.push(option);
|
|
276
|
+
return this;
|
|
277
|
+
}
|
|
278
|
+
alias(name) {
|
|
279
|
+
this.aliasNames.push(name);
|
|
280
|
+
return this;
|
|
281
|
+
}
|
|
282
|
+
action(callback) {
|
|
283
|
+
this.commandAction = callback;
|
|
284
|
+
return this;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Check if a command name is matched by this command
|
|
288
|
+
* @param name Command name
|
|
289
|
+
*/
|
|
290
|
+
isMatched(name) {
|
|
291
|
+
return this.name === name || this.aliasNames.includes(name);
|
|
292
|
+
}
|
|
293
|
+
get isDefaultCommand() {
|
|
294
|
+
return this.name === "" || this.aliasNames.includes("!");
|
|
295
|
+
}
|
|
296
|
+
get isGlobalCommand() {
|
|
297
|
+
return this instanceof GlobalCommand;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Check if an option is registered in this command
|
|
301
|
+
* @param name Option name
|
|
302
|
+
*/
|
|
303
|
+
hasOption(name) {
|
|
304
|
+
name = name.split(".")[0];
|
|
305
|
+
return this.options.find((option) => {
|
|
306
|
+
return option.names.includes(name);
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
outputHelp() {
|
|
310
|
+
const { name, commands } = this.cli;
|
|
311
|
+
const { versionNumber, options: globalOptions, helpCallback } = this.cli.globalCommand;
|
|
312
|
+
let sections = [{ body: `${name}${versionNumber ? `/${versionNumber}` : ""}` }];
|
|
313
|
+
sections.push({
|
|
314
|
+
title: "Usage",
|
|
315
|
+
body: ` $ ${name} ${this.usageText || this.rawName}`
|
|
316
|
+
});
|
|
317
|
+
if ((this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0) {
|
|
318
|
+
const longestCommandName = findLongest(commands.map((command) => command.rawName));
|
|
319
|
+
sections.push({
|
|
320
|
+
title: "Commands",
|
|
321
|
+
body: commands.map((command) => {
|
|
322
|
+
return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
|
|
323
|
+
}).join("\n")
|
|
324
|
+
}, {
|
|
325
|
+
title: `For more info, run any command with the \`--help\` flag`,
|
|
326
|
+
body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
|
|
330
|
+
if (!this.isGlobalCommand && !this.isDefaultCommand) options = options.filter((option) => option.name !== "version");
|
|
331
|
+
if (options.length > 0) {
|
|
332
|
+
const longestOptionName = findLongest(options.map((option) => option.rawName));
|
|
333
|
+
sections.push({
|
|
334
|
+
title: "Options",
|
|
335
|
+
body: options.map((option) => {
|
|
336
|
+
return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === void 0 ? "" : `(default: ${option.config.default})`}`;
|
|
337
|
+
}).join("\n")
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
if (this.examples.length > 0) sections.push({
|
|
341
|
+
title: "Examples",
|
|
342
|
+
body: this.examples.map((example) => {
|
|
343
|
+
if (typeof example === "function") return example(name);
|
|
344
|
+
return example;
|
|
345
|
+
}).join("\n")
|
|
346
|
+
});
|
|
347
|
+
if (helpCallback) sections = helpCallback(sections) || sections;
|
|
348
|
+
console.info(sections.map((section) => {
|
|
349
|
+
return section.title ? `${section.title}:\n${section.body}` : section.body;
|
|
350
|
+
}).join("\n\n"));
|
|
351
|
+
}
|
|
352
|
+
outputVersion() {
|
|
353
|
+
const { name } = this.cli;
|
|
354
|
+
const { versionNumber } = this.cli.globalCommand;
|
|
355
|
+
if (versionNumber) console.info(`${name}/${versionNumber} ${runtimeInfo}`);
|
|
356
|
+
}
|
|
357
|
+
checkRequiredArgs() {
|
|
358
|
+
const minimalArgsCount = this.args.filter((arg) => arg.required).length;
|
|
359
|
+
if (this.cli.args.length < minimalArgsCount) throw new CACError(`missing required args for command \`${this.rawName}\``);
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Check if the parsed options contain any unknown options
|
|
363
|
+
*
|
|
364
|
+
* Exit and output error when true
|
|
365
|
+
*/
|
|
366
|
+
checkUnknownOptions() {
|
|
367
|
+
const { options, globalCommand } = this.cli;
|
|
368
|
+
if (!this.config.allowUnknownOptions) {
|
|
369
|
+
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}`}\``);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Check if the required string-type options exist
|
|
374
|
+
*/
|
|
375
|
+
checkOptionValue() {
|
|
376
|
+
const { options: parsedOptions, globalCommand } = this.cli;
|
|
377
|
+
const options = [...globalCommand.options, ...this.options];
|
|
378
|
+
for (const option of options) {
|
|
379
|
+
const value = parsedOptions[option.name.split(".")[0]];
|
|
380
|
+
if (option.required) {
|
|
381
|
+
const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
|
|
382
|
+
if (value === true || value === false && !hasNegated) throw new CACError(`option \`${option.rawName}\` value is missing`);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Check if the number of args is more than expected
|
|
388
|
+
*/
|
|
389
|
+
checkUnusedArgs() {
|
|
390
|
+
const maximumArgsCount = this.args.some((arg) => arg.variadic) ? Infinity : this.args.length;
|
|
391
|
+
if (maximumArgsCount < this.cli.args.length) throw new CACError(`Unused args: ${this.cli.args.slice(maximumArgsCount).map((arg) => `\`${arg}\``).join(", ")}`);
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
var GlobalCommand = class extends Command {
|
|
395
|
+
constructor(cli) {
|
|
396
|
+
super("@@global@@", "", {}, cli);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
var CAC = class extends EventTarget {
|
|
400
|
+
/** The program name to display in help and version message */
|
|
401
|
+
name;
|
|
402
|
+
commands;
|
|
403
|
+
globalCommand;
|
|
404
|
+
matchedCommand;
|
|
405
|
+
matchedCommandName;
|
|
406
|
+
/**
|
|
407
|
+
* Raw CLI arguments
|
|
408
|
+
*/
|
|
409
|
+
rawArgs;
|
|
410
|
+
/**
|
|
411
|
+
* Parsed CLI arguments
|
|
412
|
+
*/
|
|
413
|
+
args;
|
|
414
|
+
/**
|
|
415
|
+
* Parsed CLI options, camelCased
|
|
416
|
+
*/
|
|
417
|
+
options;
|
|
418
|
+
showHelpOnExit;
|
|
419
|
+
showVersionOnExit;
|
|
420
|
+
/**
|
|
421
|
+
* @param name The program name to display in help and version message
|
|
422
|
+
*/
|
|
423
|
+
constructor(name = "") {
|
|
424
|
+
super();
|
|
425
|
+
this.name = name;
|
|
426
|
+
this.commands = [];
|
|
427
|
+
this.rawArgs = [];
|
|
428
|
+
this.args = [];
|
|
429
|
+
this.options = {};
|
|
430
|
+
this.globalCommand = new GlobalCommand(this);
|
|
431
|
+
this.globalCommand.usage("<command> [options]");
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Add a global usage text.
|
|
435
|
+
*
|
|
436
|
+
* This is not used by sub-commands.
|
|
437
|
+
*/
|
|
438
|
+
usage(text) {
|
|
439
|
+
this.globalCommand.usage(text);
|
|
440
|
+
return this;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Add a sub-command
|
|
444
|
+
*/
|
|
445
|
+
command(rawName, description, config) {
|
|
446
|
+
const command = new Command(rawName, description || "", config, this);
|
|
447
|
+
command.globalCommand = this.globalCommand;
|
|
448
|
+
this.commands.push(command);
|
|
449
|
+
return command;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Add a global CLI option.
|
|
453
|
+
*
|
|
454
|
+
* Which is also applied to sub-commands.
|
|
455
|
+
*/
|
|
456
|
+
option(rawName, description, config) {
|
|
457
|
+
this.globalCommand.option(rawName, description, config);
|
|
458
|
+
return this;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Show help message when `-h, --help` flags appear.
|
|
462
|
+
*
|
|
463
|
+
*/
|
|
464
|
+
help(callback) {
|
|
465
|
+
this.globalCommand.option("-h, --help", "Display this message");
|
|
466
|
+
this.globalCommand.helpCallback = callback;
|
|
467
|
+
this.showHelpOnExit = true;
|
|
468
|
+
return this;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Show version number when `-v, --version` flags appear.
|
|
472
|
+
*
|
|
473
|
+
*/
|
|
474
|
+
version(version, customFlags = "-v, --version") {
|
|
475
|
+
this.globalCommand.version(version, customFlags);
|
|
476
|
+
this.showVersionOnExit = true;
|
|
477
|
+
return this;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Add a global example.
|
|
481
|
+
*
|
|
482
|
+
* This example added here will not be used by sub-commands.
|
|
483
|
+
*/
|
|
484
|
+
example(example) {
|
|
485
|
+
this.globalCommand.example(example);
|
|
486
|
+
return this;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Output the corresponding help message
|
|
490
|
+
* When a sub-command is matched, output the help message for the command
|
|
491
|
+
* Otherwise output the global one.
|
|
492
|
+
*
|
|
493
|
+
*/
|
|
494
|
+
outputHelp() {
|
|
495
|
+
if (this.matchedCommand) this.matchedCommand.outputHelp();
|
|
496
|
+
else this.globalCommand.outputHelp();
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Output the version number.
|
|
500
|
+
*
|
|
501
|
+
*/
|
|
502
|
+
outputVersion() {
|
|
503
|
+
this.globalCommand.outputVersion();
|
|
504
|
+
}
|
|
505
|
+
setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
|
|
506
|
+
this.args = args;
|
|
507
|
+
this.options = options;
|
|
508
|
+
if (matchedCommand) this.matchedCommand = matchedCommand;
|
|
509
|
+
if (matchedCommandName) this.matchedCommandName = matchedCommandName;
|
|
510
|
+
return this;
|
|
511
|
+
}
|
|
512
|
+
unsetMatchedCommand() {
|
|
513
|
+
this.matchedCommand = void 0;
|
|
514
|
+
this.matchedCommandName = void 0;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Parse argv
|
|
518
|
+
*/
|
|
519
|
+
parse(argv, { run = true } = {}) {
|
|
520
|
+
if (!argv) {
|
|
521
|
+
if (!runtimeProcessArgs) throw new Error("No argv provided and runtime process argv is not available.");
|
|
522
|
+
argv = runtimeProcessArgs;
|
|
523
|
+
}
|
|
524
|
+
this.rawArgs = argv;
|
|
525
|
+
if (!this.name) this.name = argv[1] ? getFileName(argv[1]) : "cli";
|
|
526
|
+
let shouldParse = true;
|
|
527
|
+
for (const command of this.commands) {
|
|
528
|
+
const parsed = this.mri(argv.slice(2), command);
|
|
529
|
+
const commandName = parsed.args[0];
|
|
530
|
+
if (command.isMatched(commandName)) {
|
|
531
|
+
shouldParse = false;
|
|
532
|
+
const parsedInfo = {
|
|
533
|
+
...parsed,
|
|
534
|
+
args: parsed.args.slice(1)
|
|
535
|
+
};
|
|
536
|
+
this.setParsedInfo(parsedInfo, command, commandName);
|
|
537
|
+
this.dispatchEvent(new CustomEvent(`command:${commandName}`, { detail: command }));
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
if (shouldParse) {
|
|
541
|
+
for (const command of this.commands) if (command.isDefaultCommand) {
|
|
542
|
+
shouldParse = false;
|
|
543
|
+
const parsed = this.mri(argv.slice(2), command);
|
|
544
|
+
this.setParsedInfo(parsed, command);
|
|
545
|
+
this.dispatchEvent(new CustomEvent("command:!", { detail: command }));
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
if (shouldParse) {
|
|
549
|
+
const parsed = this.mri(argv.slice(2));
|
|
550
|
+
this.setParsedInfo(parsed);
|
|
551
|
+
}
|
|
552
|
+
if (this.options.help && this.showHelpOnExit) {
|
|
553
|
+
this.outputHelp();
|
|
554
|
+
run = false;
|
|
555
|
+
this.unsetMatchedCommand();
|
|
556
|
+
}
|
|
557
|
+
if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
|
|
558
|
+
this.outputVersion();
|
|
559
|
+
run = false;
|
|
560
|
+
this.unsetMatchedCommand();
|
|
561
|
+
}
|
|
562
|
+
const parsedArgv = {
|
|
563
|
+
args: this.args,
|
|
564
|
+
options: this.options
|
|
565
|
+
};
|
|
566
|
+
if (run) this.runMatchedCommand();
|
|
567
|
+
if (!this.matchedCommand && this.args[0]) this.dispatchEvent(new CustomEvent("command:*", { detail: this.args[0] }));
|
|
568
|
+
return parsedArgv;
|
|
569
|
+
}
|
|
570
|
+
mri(argv, command) {
|
|
571
|
+
const cliOptions = [...this.globalCommand.options, ...command ? command.options : []];
|
|
572
|
+
const mriOptions = getMriOptions(cliOptions);
|
|
573
|
+
let argsAfterDoubleDashes = [];
|
|
574
|
+
const doubleDashesIndex = argv.indexOf("--");
|
|
575
|
+
if (doubleDashesIndex !== -1) {
|
|
576
|
+
argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
|
|
577
|
+
argv = argv.slice(0, doubleDashesIndex);
|
|
578
|
+
}
|
|
579
|
+
let parsed = lib_default(argv, mriOptions);
|
|
580
|
+
parsed = Object.keys(parsed).reduce((res, name) => {
|
|
581
|
+
return {
|
|
582
|
+
...res,
|
|
583
|
+
[camelcaseOptionName(name)]: parsed[name]
|
|
584
|
+
};
|
|
585
|
+
}, { _: [] });
|
|
586
|
+
const args = parsed._;
|
|
587
|
+
const options = { "--": argsAfterDoubleDashes };
|
|
588
|
+
const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
|
|
589
|
+
const transforms = Object.create(null);
|
|
590
|
+
for (const cliOption of cliOptions) {
|
|
591
|
+
if (!ignoreDefault && cliOption.config.default !== void 0) for (const name of cliOption.names) options[name] = cliOption.config.default;
|
|
592
|
+
if (Array.isArray(cliOption.config.type) && transforms[cliOption.name] === void 0) {
|
|
593
|
+
transforms[cliOption.name] = Object.create(null);
|
|
594
|
+
transforms[cliOption.name].shouldTransform = true;
|
|
595
|
+
transforms[cliOption.name].transformFunction = cliOption.config.type[0];
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
for (const key of Object.keys(parsed)) if (key !== "_") {
|
|
599
|
+
setDotProp(options, key.split("."), parsed[key]);
|
|
600
|
+
setByType(options, transforms);
|
|
601
|
+
}
|
|
602
|
+
return {
|
|
603
|
+
args,
|
|
604
|
+
options
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
runMatchedCommand() {
|
|
608
|
+
const { args, options, matchedCommand: command } = this;
|
|
609
|
+
if (!command || !command.commandAction) return;
|
|
610
|
+
command.checkUnknownOptions();
|
|
611
|
+
command.checkOptionValue();
|
|
612
|
+
command.checkRequiredArgs();
|
|
613
|
+
command.checkUnusedArgs();
|
|
614
|
+
const actionArgs = [];
|
|
615
|
+
command.args.forEach((arg, index) => {
|
|
616
|
+
if (arg.variadic) actionArgs.push(args.slice(index));
|
|
617
|
+
else actionArgs.push(args[index]);
|
|
618
|
+
});
|
|
619
|
+
actionArgs.push(options);
|
|
620
|
+
return command.commandAction.apply(this, actionArgs);
|
|
621
|
+
}
|
|
622
|
+
};
|
|
623
|
+
/**
|
|
624
|
+
* @param name The program name to display in help and version message
|
|
625
|
+
*/
|
|
626
|
+
const cac = (name = "") => new CAC(name);
|
|
627
|
+
//#endregion
|
|
15
628
|
//#region src/cli/arguments/alias.ts
|
|
16
629
|
const alias = {
|
|
17
630
|
config: {
|
|
@@ -33,27 +646,15 @@ const alias = {
|
|
|
33
646
|
format: { abbreviation: "f" },
|
|
34
647
|
name: { abbreviation: "n" },
|
|
35
648
|
globals: { abbreviation: "g" },
|
|
36
|
-
sourcemap: {
|
|
37
|
-
abbreviation: "s",
|
|
38
|
-
default: true
|
|
39
|
-
},
|
|
649
|
+
sourcemap: { abbreviation: "s" },
|
|
40
650
|
minify: { abbreviation: "m" },
|
|
41
651
|
platform: { abbreviation: "p" },
|
|
42
652
|
assetFileNames: { hint: "name" },
|
|
43
653
|
chunkFileNames: { hint: "name" },
|
|
44
654
|
entryFileNames: { hint: "name" },
|
|
45
|
-
externalLiveBindings: {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
},
|
|
49
|
-
treeshake: {
|
|
50
|
-
default: true,
|
|
51
|
-
reverse: true
|
|
52
|
-
},
|
|
53
|
-
preserveEntrySignatures: {
|
|
54
|
-
default: "strict",
|
|
55
|
-
reverse: true
|
|
56
|
-
},
|
|
655
|
+
externalLiveBindings: { reverse: true },
|
|
656
|
+
treeshake: { reverse: true },
|
|
657
|
+
preserveEntrySignatures: { reverse: true },
|
|
57
658
|
moduleTypes: { hint: "types" }
|
|
58
659
|
};
|
|
59
660
|
//#endregion
|
|
@@ -76,24 +677,17 @@ function setNestedProperty(obj, path, value) {
|
|
|
76
677
|
function camelCaseToKebabCase(str) {
|
|
77
678
|
return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
78
679
|
}
|
|
79
|
-
function kebabCaseToCamelCase(str) {
|
|
80
|
-
return str.replace(/-./g, (match) => match[1].toUpperCase());
|
|
81
|
-
}
|
|
82
680
|
//#endregion
|
|
83
681
|
//#region src/cli/arguments/normalize.ts
|
|
682
|
+
const reservedKeys = new Set([
|
|
683
|
+
"help",
|
|
684
|
+
"version",
|
|
685
|
+
"config",
|
|
686
|
+
"watch",
|
|
687
|
+
"environment"
|
|
688
|
+
]);
|
|
84
689
|
function normalizeCliOptions(cliOptions, positionals) {
|
|
85
|
-
const
|
|
86
|
-
"__proto__",
|
|
87
|
-
"constructor",
|
|
88
|
-
"prototype"
|
|
89
|
-
];
|
|
90
|
-
const unflattenedCliOptions = {};
|
|
91
|
-
for (let [key, value] of Object.entries(cliOptions)) if (prototypePollutionKeys.includes(key)) {} else if (key.includes(".")) {
|
|
92
|
-
const [parentKey] = key.split(".");
|
|
93
|
-
unflattenedCliOptions[parentKey] ??= {};
|
|
94
|
-
setNestedProperty(unflattenedCliOptions, key, value);
|
|
95
|
-
} else unflattenedCliOptions[key] = value;
|
|
96
|
-
const [data, errors] = validateCliOptions(unflattenedCliOptions);
|
|
690
|
+
const [data, errors] = validateCliOptions(cliOptions);
|
|
97
691
|
if (errors?.length) {
|
|
98
692
|
errors.forEach((error) => {
|
|
99
693
|
logger.error(`${error}. You can use \`rolldown -h\` to see the help.`);
|
|
@@ -109,21 +703,15 @@ function normalizeCliOptions(cliOptions, positionals) {
|
|
|
109
703
|
watch: options.watch ?? false
|
|
110
704
|
};
|
|
111
705
|
if (typeof options.config === "string") result.config = options.config;
|
|
706
|
+
else if (options.config === true) result.config = "";
|
|
112
707
|
if (options.environment !== void 0) result.environment = options.environment;
|
|
113
|
-
const keysOfInput = getInputCliKeys();
|
|
114
|
-
const keysOfOutput = getOutputCliKeys();
|
|
115
|
-
const reservedKeys = [
|
|
116
|
-
"help",
|
|
117
|
-
"version",
|
|
118
|
-
"config",
|
|
119
|
-
"watch",
|
|
120
|
-
"environment"
|
|
121
|
-
];
|
|
708
|
+
const keysOfInput = new Set(getInputCliKeys());
|
|
709
|
+
const keysOfOutput = new Set(getOutputCliKeys());
|
|
122
710
|
for (let [key, value] of Object.entries(options)) {
|
|
123
711
|
const [primary] = key.split(".");
|
|
124
|
-
if (keysOfInput.
|
|
125
|
-
else if (keysOfOutput.
|
|
126
|
-
else if (!reservedKeys.
|
|
712
|
+
if (keysOfInput.has(primary)) setNestedProperty(result.input, key, value);
|
|
713
|
+
else if (keysOfOutput.has(primary)) setNestedProperty(result.output, key, value);
|
|
714
|
+
else if (!reservedKeys.has(key)) {
|
|
127
715
|
logger.error(`Unknown option: ${key}`);
|
|
128
716
|
process.exit(1);
|
|
129
717
|
}
|
|
@@ -136,119 +724,115 @@ function normalizeCliOptions(cliOptions, positionals) {
|
|
|
136
724
|
//#region src/cli/arguments/index.ts
|
|
137
725
|
const schemaInfo = getCliSchemaInfo();
|
|
138
726
|
const options = Object.fromEntries(Object.entries(schemaInfo).filter(([_key, info]) => info.type !== "never").map(([key, info]) => {
|
|
139
|
-
const config =
|
|
727
|
+
const config = alias[key];
|
|
728
|
+
let description = info?.description ?? config?.description ?? "";
|
|
729
|
+
if (config?.reverse) {
|
|
730
|
+
if (description.startsWith("enable")) description = description.replace("enable", "disable");
|
|
731
|
+
else if (!description.startsWith("Avoid")) description = `disable ${description}`;
|
|
732
|
+
}
|
|
140
733
|
const result = {
|
|
141
734
|
type: info.type === "boolean" ? "boolean" : "string",
|
|
142
|
-
description
|
|
143
|
-
hint: config?.hint
|
|
735
|
+
description
|
|
144
736
|
};
|
|
145
|
-
if (config
|
|
146
|
-
if (config
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
key = camelCaseToKebabCase(key);
|
|
151
|
-
return [config?.reverse ? `no-${key}` : key, result];
|
|
737
|
+
if (config?.abbreviation) result.short = config.abbreviation;
|
|
738
|
+
if (config?.hint) result.hint = config.hint;
|
|
739
|
+
const kebabKey = camelCaseToKebabCase(key);
|
|
740
|
+
return [config?.reverse ? `no-${kebabKey}` : kebabKey, result];
|
|
152
741
|
}));
|
|
742
|
+
const knownKeys = new Set(Object.keys(schemaInfo));
|
|
743
|
+
for (const key of Object.keys(schemaInfo)) {
|
|
744
|
+
const dotIdx = key.indexOf(".");
|
|
745
|
+
if (dotIdx > 0) knownKeys.add(key.substring(0, dotIdx));
|
|
746
|
+
}
|
|
747
|
+
const shortAliases = /* @__PURE__ */ new Set();
|
|
748
|
+
for (const config of Object.values(alias)) if (config?.abbreviation) shortAliases.add(config.abbreviation);
|
|
153
749
|
function parseCliArguments() {
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
750
|
+
const cli = cac("rolldown");
|
|
751
|
+
for (const [key, info] of Object.entries(schemaInfo)) {
|
|
752
|
+
if (info.type === "never") continue;
|
|
753
|
+
const config = alias[key];
|
|
754
|
+
let rawName = "";
|
|
755
|
+
if (config?.abbreviation) rawName += `-${config.abbreviation}, `;
|
|
756
|
+
if (config?.reverse) rawName += `--no-${key}`;
|
|
757
|
+
else rawName += `--${key}`;
|
|
758
|
+
if (info.type !== "boolean" && !config?.reverse) if (config?.requireValue) rawName += ` <${config?.hint ?? key}>`;
|
|
759
|
+
else rawName += ` [${config?.hint ?? key}]`;
|
|
760
|
+
cli.option(rawName, info.description ?? config?.description ?? "");
|
|
761
|
+
}
|
|
762
|
+
let parsedInput = [];
|
|
763
|
+
let parsedOptions = {};
|
|
764
|
+
const cmd = cli.command("[...input]", "");
|
|
765
|
+
cmd.allowUnknownOptions();
|
|
766
|
+
cmd.ignoreOptionDefaultValue();
|
|
767
|
+
cmd.action((input, opts) => {
|
|
768
|
+
parsedInput = input;
|
|
769
|
+
parsedOptions = opts;
|
|
159
770
|
});
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
771
|
+
try {
|
|
772
|
+
cli.parse(process.argv, { run: true });
|
|
773
|
+
} catch (err) {
|
|
774
|
+
if (err?.name === "CACError") {
|
|
775
|
+
const match = err.message.match(/option `(.+?)` value is missing/);
|
|
776
|
+
if (match) {
|
|
777
|
+
const optName = match[1].replace(/ [<[].*/, "").replace(/^-\w, /, "");
|
|
778
|
+
logger.error(`Option \`${optName}\` requires a value but none was provided.`);
|
|
779
|
+
} else logger.error(err.message);
|
|
780
|
+
process.exit(1);
|
|
169
781
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
value: option.value ?? defaultValue?.default ?? "",
|
|
223
|
-
enumerable: true,
|
|
224
|
-
configurable: true,
|
|
225
|
-
writable: true
|
|
226
|
-
});
|
|
227
|
-
} else Object.defineProperty(values, option.name, {
|
|
228
|
-
value: option.value ?? "",
|
|
229
|
-
enumerable: true,
|
|
230
|
-
configurable: true,
|
|
231
|
-
writable: true
|
|
232
|
-
});
|
|
233
|
-
}).filter((item) => {
|
|
234
|
-
return item !== void 0;
|
|
235
|
-
});
|
|
236
|
-
invalid_options.sort((a, b) => {
|
|
237
|
-
return a.name.localeCompare(b.name);
|
|
238
|
-
});
|
|
239
|
-
if (invalid_options.length !== 0) {
|
|
240
|
-
let single = invalid_options.length === 1;
|
|
241
|
-
logger.warn(`Option \`${invalid_options.map((item) => item.name).join(",")}\` ${single ? "is" : "are"} unrecognized. We will ignore ${single ? "this" : "those"} option${single ? "" : "s"}.`);
|
|
242
|
-
}
|
|
243
|
-
let rawArgs = {
|
|
244
|
-
...values,
|
|
245
|
-
...invalid_options.reduce((acc, cur) => {
|
|
246
|
-
acc[cur.name] = cur.value;
|
|
247
|
-
return acc;
|
|
248
|
-
}, Object.create(null))
|
|
249
|
-
};
|
|
782
|
+
throw err;
|
|
783
|
+
}
|
|
784
|
+
delete parsedOptions["--"];
|
|
785
|
+
for (const short of shortAliases) delete parsedOptions[short];
|
|
786
|
+
for (const key of Object.keys(parsedOptions)) if (key === "__proto__" || key === "constructor" || key === "prototype" || key.startsWith("__proto__.") || key.startsWith("constructor.") || key.startsWith("prototype.")) delete parsedOptions[key];
|
|
787
|
+
const unknownKeys = Object.keys(parsedOptions).filter((k) => !knownKeys.has(k));
|
|
788
|
+
if (unknownKeys.length > 0) {
|
|
789
|
+
unknownKeys.sort();
|
|
790
|
+
const single = unknownKeys.length === 1;
|
|
791
|
+
logger.warn(`Option \`${unknownKeys.join(",")}\` ${single ? "is" : "are"} unrecognized. We will ignore ${single ? "this" : "those"} option${single ? "" : "s"}.`);
|
|
792
|
+
}
|
|
793
|
+
const rawArgs = { ...parsedOptions };
|
|
794
|
+
for (const key of unknownKeys) delete parsedOptions[key];
|
|
795
|
+
for (const [key, value] of Object.entries(parsedOptions)) {
|
|
796
|
+
const type = schemaInfo[key]?.type;
|
|
797
|
+
if (Array.isArray(value)) {
|
|
798
|
+
if (type !== "array" && type !== "object") parsedOptions[key] = value[value.length - 1];
|
|
799
|
+
} else if (type === "array" && typeof value === "string") parsedOptions[key] = [value];
|
|
800
|
+
}
|
|
801
|
+
for (const [schemaKey, info] of Object.entries(schemaInfo)) {
|
|
802
|
+
if (info.type !== "object") continue;
|
|
803
|
+
const parts = schemaKey.split(".");
|
|
804
|
+
let parent = parsedOptions;
|
|
805
|
+
for (let i = 0; i < parts.length - 1; i++) parent = parent?.[parts[i]];
|
|
806
|
+
const leafKey = parts[parts.length - 1];
|
|
807
|
+
const value = parent?.[leafKey];
|
|
808
|
+
if (value === void 0) continue;
|
|
809
|
+
const values = Array.isArray(value) ? value : [value];
|
|
810
|
+
if (typeof values[0] !== "string") continue;
|
|
811
|
+
let usedDeprecatedSyntax = false;
|
|
812
|
+
const result = {};
|
|
813
|
+
for (const v of values) for (const pair of String(v).split(",")) {
|
|
814
|
+
const colonIdx = pair.indexOf(":");
|
|
815
|
+
const eqIdx = pair.indexOf("=");
|
|
816
|
+
let k;
|
|
817
|
+
let val;
|
|
818
|
+
if (colonIdx > 0 && (eqIdx === -1 || colonIdx < eqIdx)) {
|
|
819
|
+
k = pair.slice(0, colonIdx);
|
|
820
|
+
val = pair.slice(colonIdx + 1);
|
|
821
|
+
} else if (eqIdx > 0) {
|
|
822
|
+
k = pair.slice(0, eqIdx);
|
|
823
|
+
val = pair.slice(eqIdx + 1);
|
|
824
|
+
usedDeprecatedSyntax = true;
|
|
825
|
+
} else continue;
|
|
826
|
+
result[k] = val;
|
|
827
|
+
}
|
|
828
|
+
if (usedDeprecatedSyntax) {
|
|
829
|
+
const optionName = camelCaseToKebabCase(schemaKey);
|
|
830
|
+
logger.warn(`Using \`key=value\` syntax for \`--${optionName}\` is deprecated. Use \`key:value\` instead.`);
|
|
831
|
+
}
|
|
832
|
+
parent[leafKey] = result;
|
|
833
|
+
}
|
|
250
834
|
return {
|
|
251
|
-
...normalizeCliOptions(
|
|
835
|
+
...normalizeCliOptions(parsedOptions, parsedInput),
|
|
252
836
|
rawArgs
|
|
253
837
|
};
|
|
254
838
|
}
|
|
@@ -263,7 +847,7 @@ function getClearScreenFunction(options) {
|
|
|
263
847
|
};
|
|
264
848
|
}
|
|
265
849
|
//#endregion
|
|
266
|
-
//#region \0@oxc-project+runtime@0.
|
|
850
|
+
//#region \0@oxc-project+runtime@0.121.0/helpers/usingCtx.js
|
|
267
851
|
function _usingCtx() {
|
|
268
852
|
var r = "function" == typeof SuppressedError ? SuppressedError : function(r, e) {
|
|
269
853
|
var n = Error();
|
|
@@ -351,7 +935,7 @@ async function bundleWithCliOptions(cliOptions) {
|
|
|
351
935
|
process.exit(1);
|
|
352
936
|
}
|
|
353
937
|
for (const file of outputs) {
|
|
354
|
-
if (outputs.length > 1) logger.log(`\n${styleText
|
|
938
|
+
if (outputs.length > 1) logger.log(`\n${styleText(["cyan", "bold"], `|→ ${file.fileName}:`)}\n`);
|
|
355
939
|
console.log(file.type === "asset" ? file.source : file.code);
|
|
356
940
|
}
|
|
357
941
|
} catch (_) {
|
|
@@ -391,12 +975,12 @@ async function watchInner(config, cliOptions) {
|
|
|
391
975
|
clearScreen?.();
|
|
392
976
|
break;
|
|
393
977
|
case "BUNDLE_START":
|
|
394
|
-
if (changedFile.length > 0) logger.log(`Found ${styleText
|
|
978
|
+
if (changedFile.length > 0) logger.log(`Found ${styleText("bold", changedFile.map(relativeId).join(", "))} changed, rebuilding...`);
|
|
395
979
|
changedFile.length = 0;
|
|
396
980
|
break;
|
|
397
981
|
case "BUNDLE_END":
|
|
398
982
|
await event.result.close();
|
|
399
|
-
logger.success(`Rebuilt ${styleText
|
|
983
|
+
logger.success(`Rebuilt ${styleText("bold", relativeId(event.output[0]))} in ${styleText("green", ms(event.duration))}.`);
|
|
400
984
|
break;
|
|
401
985
|
case "ERROR":
|
|
402
986
|
await event.result.close();
|
|
@@ -429,7 +1013,7 @@ async function bundleInner(config, cliOptions) {
|
|
|
429
1013
|
result.forEach(printBundleOutputPretty);
|
|
430
1014
|
logger.log(``);
|
|
431
1015
|
const duration = performance.now() - startTime;
|
|
432
|
-
logger.success(`rolldown v${version} Finished in ${styleText
|
|
1016
|
+
logger.success(`rolldown v${version} Finished in ${styleText("green", ms(duration))}`);
|
|
433
1017
|
}
|
|
434
1018
|
function printBundleOutputPretty(output) {
|
|
435
1019
|
const outputEntries = collectOutputEntries(output.output);
|
|
@@ -475,10 +1059,10 @@ function printOutputEntries(entries, sizeAdjustment, distPath) {
|
|
|
475
1059
|
const filtered = entries.filter((e) => e.type === group.type);
|
|
476
1060
|
if (!filtered.length) continue;
|
|
477
1061
|
for (const entry of filtered.sort((a, z) => a.size - z.size)) {
|
|
478
|
-
let log = styleText
|
|
479
|
-
log += styleText
|
|
480
|
-
log += styleText
|
|
481
|
-
log += styleText
|
|
1062
|
+
let log = styleText("dim", withTrailingSlash(distPath));
|
|
1063
|
+
log += styleText(group.color, entry.fileName.padEnd(sizeAdjustment.longest + 2));
|
|
1064
|
+
log += styleText("dim", entry.type);
|
|
1065
|
+
log += styleText("dim", ` │ size: ${displaySize(entry.size).padStart(sizeAdjustment.sizePad)}`);
|
|
482
1066
|
logger.log(log);
|
|
483
1067
|
}
|
|
484
1068
|
}
|
|
@@ -518,22 +1102,17 @@ const examples = [
|
|
|
518
1102
|
command: "rolldown src/main.ts -d dist -n bundle -f iife -e jQuery,window._ -g jQuery=$"
|
|
519
1103
|
}
|
|
520
1104
|
];
|
|
521
|
-
const notes = [
|
|
522
|
-
"Due to the API limitation, you need to pass `-s` for `.map` sourcemap file as the last argument.",
|
|
523
|
-
"If you are using the configuration, please pass the `-c` as the last argument if you ignore the default configuration file.",
|
|
524
|
-
"CLI options will override the configuration file.",
|
|
525
|
-
"For more information, please visit https://rolldown.rs/."
|
|
526
|
-
];
|
|
1105
|
+
const notes = ["CLI options will override the configuration file.", "For more information, please visit https://rolldown.rs/."];
|
|
527
1106
|
/**
|
|
528
1107
|
* Generates the CLI help text as a string.
|
|
529
1108
|
*/
|
|
530
1109
|
function generateHelpText() {
|
|
531
1110
|
const lines = [];
|
|
532
|
-
lines.push(`${styleText
|
|
1111
|
+
lines.push(`${styleText("gray", `${description} (rolldown v${version})`)}`);
|
|
533
1112
|
lines.push("");
|
|
534
|
-
lines.push(`${styleText
|
|
1113
|
+
lines.push(`${styleText(["bold", "underline"], "USAGE")} ${styleText("cyan", "rolldown -c <config>")} or ${styleText("cyan", "rolldown <input> <options>")}`);
|
|
535
1114
|
lines.push("");
|
|
536
|
-
lines.push(`${styleText
|
|
1115
|
+
lines.push(`${styleText(["bold", "underline"], "OPTIONS")}`);
|
|
537
1116
|
lines.push("");
|
|
538
1117
|
lines.push(Object.entries(options).sort(([a], [b]) => {
|
|
539
1118
|
if (options[a].short && !options[b].short) return -1;
|
|
@@ -546,20 +1125,20 @@ function generateHelpText() {
|
|
|
546
1125
|
if (short) optionStr += `-${short}, `;
|
|
547
1126
|
if (type === "string") optionStr += `<${hint ?? option}>`;
|
|
548
1127
|
if (description && description.length > 0) description = description[0].toUpperCase() + description.slice(1);
|
|
549
|
-
return styleText
|
|
1128
|
+
return styleText("cyan", optionStr.padEnd(30)) + description + (description && description?.endsWith(".") ? "" : ".");
|
|
550
1129
|
}).join("\n"));
|
|
551
1130
|
lines.push("");
|
|
552
|
-
lines.push(`${styleText
|
|
1131
|
+
lines.push(`${styleText(["bold", "underline"], "EXAMPLES")}`);
|
|
553
1132
|
lines.push("");
|
|
554
1133
|
examples.forEach(({ title, command }, ord) => {
|
|
555
1134
|
lines.push(` ${ord + 1}. ${title}:`);
|
|
556
|
-
lines.push(` ${styleText
|
|
1135
|
+
lines.push(` ${styleText("cyan", command)}`);
|
|
557
1136
|
lines.push("");
|
|
558
1137
|
});
|
|
559
|
-
lines.push(`${styleText
|
|
1138
|
+
lines.push(`${styleText(["bold", "underline"], "NOTES")}`);
|
|
560
1139
|
lines.push("");
|
|
561
1140
|
notes.forEach((note) => {
|
|
562
|
-
lines.push(` * ${styleText
|
|
1141
|
+
lines.push(` * ${styleText("gray", note)}`);
|
|
563
1142
|
});
|
|
564
1143
|
return lines.join("\n");
|
|
565
1144
|
}
|
|
@@ -586,6 +1165,14 @@ async function main() {
|
|
|
586
1165
|
process$1.env[key] = value.length === 0 ? String(true) : value.join(":");
|
|
587
1166
|
}
|
|
588
1167
|
}
|
|
1168
|
+
if (cliOptions.help) {
|
|
1169
|
+
showHelp();
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1172
|
+
if (cliOptions.version) {
|
|
1173
|
+
logger.log(`rolldown v${version}`);
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
589
1176
|
if (cliOptions.config || cliOptions.config === "") {
|
|
590
1177
|
await bundleWithConfig(cliOptions.config, cliOptions, rawArgs);
|
|
591
1178
|
return;
|
|
@@ -594,10 +1181,6 @@ async function main() {
|
|
|
594
1181
|
await bundleWithCliOptions(cliOptions);
|
|
595
1182
|
return;
|
|
596
1183
|
}
|
|
597
|
-
if (cliOptions.version) {
|
|
598
|
-
logger.log(`rolldown v${version}`);
|
|
599
|
-
return;
|
|
600
|
-
}
|
|
601
1184
|
showHelp();
|
|
602
1185
|
}
|
|
603
1186
|
main().catch((err) => {
|