@rolldown/browser 1.0.0-rc.7 → 1.0.0-rc.9
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 +629 -180
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +4 -4
- package/dist/experimental-index.browser.mjs +1 -1
- package/dist/experimental-index.d.mts +1 -1
- package/dist/experimental-index.mjs +2 -2
- package/dist/filter-index.d.mts +1 -1
- package/dist/index.browser.mjs +3 -3
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +6 -6
- package/dist/parallel-plugin-worker.mjs +1 -1
- package/dist/parallel-plugin.d.mts +1 -1
- package/dist/rolldown-binding.wasm32-wasi.wasm +0 -0
- package/dist/{rolldown-build-D97C-VhN.js → rolldown-build-sRmdtwRU.js} +26 -12
- package/dist/shared/{bindingify-input-options-kCVufQp0.mjs → bindingify-input-options-Cfptl9gw.mjs} +18 -7
- package/dist/shared/{define-config-Cci3IvO_.d.mts → define-config-B1J71V4c.d.mts} +39 -11
- package/dist/shared/{load-config-DNGVjxdv.mjs → load-config-B6MMusXN.mjs} +1 -1
- package/dist/shared/{rolldown-C9kn7lTZ.mjs → rolldown-BDqeiCX1.mjs} +1 -1
- package/dist/shared/{rolldown-build-8_xyZuDH.mjs → rolldown-build-DZ7tJkeQ.mjs} +9 -6
- package/dist/shared/{watch-dCFQWE8a.mjs → watch-Cj4uDLQX.mjs} +2 -2
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,16 +1,495 @@
|
|
|
1
|
-
import { n as onExit, t as watch } from "./shared/watch-
|
|
1
|
+
import { n as onExit, t as watch } from "./shared/watch-Cj4uDLQX.mjs";
|
|
2
2
|
import "./shared/normalize-string-or-regex-CF3Uz6aU.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { C as version, S as description } from "./shared/bindingify-input-options-Cfptl9gw.mjs";
|
|
4
4
|
import { h as arraify } from "./shared/composable-filters-B2ByPP8y.mjs";
|
|
5
|
-
import { a as getInputCliKeys, i as getCliSchemaInfo, l as styleText
|
|
5
|
+
import { a as getInputCliKeys, i as getCliSchemaInfo, l as styleText, o as getOutputCliKeys, r as logger, s as validateCliOptions } from "./shared/rolldown-build-DZ7tJkeQ.mjs";
|
|
6
6
|
import "./shared/error-CQ6njWsV.mjs";
|
|
7
7
|
import "./shared/parse-DDUnGYGU.mjs";
|
|
8
|
-
import { t as rolldown } from "./shared/rolldown-
|
|
9
|
-
import { t as loadConfig } from "./shared/load-config-
|
|
8
|
+
import { t as rolldown } from "./shared/rolldown-BDqeiCX1.mjs";
|
|
9
|
+
import { t as loadConfig } from "./shared/load-config-B6MMusXN.mjs";
|
|
10
10
|
import path from "node:path";
|
|
11
|
-
import { parseArgs } from "node:util";
|
|
12
11
|
import process$1 from "node:process";
|
|
12
|
+
import { EventEmitter } from "events";
|
|
13
13
|
import { performance } from "node:perf_hooks";
|
|
14
|
+
//#region ../../node_modules/.pnpm/cac@6.7.14/node_modules/cac/dist/index.mjs
|
|
15
|
+
function toArr(any) {
|
|
16
|
+
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
17
|
+
}
|
|
18
|
+
function toVal(out, key, val, opts) {
|
|
19
|
+
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;
|
|
20
|
+
out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
|
|
21
|
+
}
|
|
22
|
+
function mri2(args, opts) {
|
|
23
|
+
args = args || [];
|
|
24
|
+
opts = opts || {};
|
|
25
|
+
var k, arr, arg, name, val, out = { _: [] };
|
|
26
|
+
var i = 0, j = 0, idx = 0, len = args.length;
|
|
27
|
+
const alibi = opts.alias !== void 0;
|
|
28
|
+
const strict = opts.unknown !== void 0;
|
|
29
|
+
const defaults = opts.default !== void 0;
|
|
30
|
+
opts.alias = opts.alias || {};
|
|
31
|
+
opts.string = toArr(opts.string);
|
|
32
|
+
opts.boolean = toArr(opts.boolean);
|
|
33
|
+
if (alibi) for (k in opts.alias) {
|
|
34
|
+
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
35
|
+
for (i = 0; i < arr.length; i++) (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
36
|
+
}
|
|
37
|
+
for (i = opts.boolean.length; i-- > 0;) {
|
|
38
|
+
arr = opts.alias[opts.boolean[i]] || [];
|
|
39
|
+
for (j = arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
|
40
|
+
}
|
|
41
|
+
for (i = opts.string.length; i-- > 0;) {
|
|
42
|
+
arr = opts.alias[opts.string[i]] || [];
|
|
43
|
+
for (j = arr.length; j-- > 0;) opts.string.push(arr[j]);
|
|
44
|
+
}
|
|
45
|
+
if (defaults) for (k in opts.default) {
|
|
46
|
+
name = typeof opts.default[k];
|
|
47
|
+
arr = opts.alias[k] = opts.alias[k] || [];
|
|
48
|
+
if (opts[name] !== void 0) {
|
|
49
|
+
opts[name].push(k);
|
|
50
|
+
for (i = 0; i < arr.length; i++) opts[name].push(arr[i]);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const keys = strict ? Object.keys(opts.alias) : [];
|
|
54
|
+
for (i = 0; i < len; i++) {
|
|
55
|
+
arg = args[i];
|
|
56
|
+
if (arg === "--") {
|
|
57
|
+
out._ = out._.concat(args.slice(++i));
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
for (j = 0; j < arg.length; j++) if (arg.charCodeAt(j) !== 45) break;
|
|
61
|
+
if (j === 0) out._.push(arg);
|
|
62
|
+
else if (arg.substring(j, j + 3) === "no-") {
|
|
63
|
+
name = arg.substring(j + 3);
|
|
64
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown(arg);
|
|
65
|
+
out[name] = false;
|
|
66
|
+
} else {
|
|
67
|
+
for (idx = j + 1; idx < arg.length; idx++) if (arg.charCodeAt(idx) === 61) break;
|
|
68
|
+
name = arg.substring(j, idx);
|
|
69
|
+
val = arg.substring(++idx) || i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i];
|
|
70
|
+
arr = j === 2 ? [name] : name;
|
|
71
|
+
for (idx = 0; idx < arr.length; idx++) {
|
|
72
|
+
name = arr[idx];
|
|
73
|
+
if (strict && !~keys.indexOf(name)) return opts.unknown("-".repeat(j) + name);
|
|
74
|
+
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (defaults) {
|
|
79
|
+
for (k in opts.default) if (out[k] === void 0) out[k] = opts.default[k];
|
|
80
|
+
}
|
|
81
|
+
if (alibi) for (k in out) {
|
|
82
|
+
arr = opts.alias[k] || [];
|
|
83
|
+
while (arr.length > 0) out[arr.shift()] = out[k];
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
const removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
|
|
88
|
+
const findAllBrackets = (v) => {
|
|
89
|
+
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
|
90
|
+
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
|
91
|
+
const res = [];
|
|
92
|
+
const parse = (match) => {
|
|
93
|
+
let variadic = false;
|
|
94
|
+
let value = match[1];
|
|
95
|
+
if (value.startsWith("...")) {
|
|
96
|
+
value = value.slice(3);
|
|
97
|
+
variadic = true;
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
required: match[0].startsWith("<"),
|
|
101
|
+
value,
|
|
102
|
+
variadic
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
let angledMatch;
|
|
106
|
+
while (angledMatch = ANGLED_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(angledMatch));
|
|
107
|
+
let squareMatch;
|
|
108
|
+
while (squareMatch = SQUARE_BRACKET_RE_GLOBAL.exec(v)) res.push(parse(squareMatch));
|
|
109
|
+
return res;
|
|
110
|
+
};
|
|
111
|
+
const getMriOptions = (options) => {
|
|
112
|
+
const result = {
|
|
113
|
+
alias: {},
|
|
114
|
+
boolean: []
|
|
115
|
+
};
|
|
116
|
+
for (const [index, option] of options.entries()) {
|
|
117
|
+
if (option.names.length > 1) result.alias[option.names[0]] = option.names.slice(1);
|
|
118
|
+
if (option.isBoolean) if (option.negated) {
|
|
119
|
+
if (!options.some((o, i) => {
|
|
120
|
+
return i !== index && o.names.some((name) => option.names.includes(name)) && typeof o.required === "boolean";
|
|
121
|
+
})) result.boolean.push(option.names[0]);
|
|
122
|
+
} else result.boolean.push(option.names[0]);
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
};
|
|
126
|
+
const findLongest = (arr) => {
|
|
127
|
+
return arr.sort((a, b) => {
|
|
128
|
+
return a.length > b.length ? -1 : 1;
|
|
129
|
+
})[0];
|
|
130
|
+
};
|
|
131
|
+
const padRight = (str, length) => {
|
|
132
|
+
return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
|
133
|
+
};
|
|
134
|
+
const camelcase = (input) => {
|
|
135
|
+
return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
|
|
136
|
+
return p1 + p2.toUpperCase();
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
const setDotProp = (obj, keys, val) => {
|
|
140
|
+
let i = 0;
|
|
141
|
+
let length = keys.length;
|
|
142
|
+
let t = obj;
|
|
143
|
+
let x;
|
|
144
|
+
for (; i < length; ++i) {
|
|
145
|
+
x = t[keys[i]];
|
|
146
|
+
t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const setByType = (obj, transforms) => {
|
|
150
|
+
for (const key of Object.keys(transforms)) {
|
|
151
|
+
const transform = transforms[key];
|
|
152
|
+
if (transform.shouldTransform) {
|
|
153
|
+
obj[key] = Array.prototype.concat.call([], obj[key]);
|
|
154
|
+
if (typeof transform.transformFunction === "function") obj[key] = obj[key].map(transform.transformFunction);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
const getFileName = (input) => {
|
|
159
|
+
const m = /([^\\\/]+)$/.exec(input);
|
|
160
|
+
return m ? m[1] : "";
|
|
161
|
+
};
|
|
162
|
+
const camelcaseOptionName = (name) => {
|
|
163
|
+
return name.split(".").map((v, i) => {
|
|
164
|
+
return i === 0 ? camelcase(v) : v;
|
|
165
|
+
}).join(".");
|
|
166
|
+
};
|
|
167
|
+
var CACError = class extends Error {
|
|
168
|
+
constructor(message) {
|
|
169
|
+
super(message);
|
|
170
|
+
this.name = this.constructor.name;
|
|
171
|
+
if (typeof Error.captureStackTrace === "function") Error.captureStackTrace(this, this.constructor);
|
|
172
|
+
else this.stack = new Error(message).stack;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
var Option = class {
|
|
176
|
+
constructor(rawName, description, config) {
|
|
177
|
+
this.rawName = rawName;
|
|
178
|
+
this.description = description;
|
|
179
|
+
this.config = Object.assign({}, config);
|
|
180
|
+
rawName = rawName.replace(/\.\*/g, "");
|
|
181
|
+
this.negated = false;
|
|
182
|
+
this.names = removeBrackets(rawName).split(",").map((v) => {
|
|
183
|
+
let name = v.trim().replace(/^-{1,2}/, "");
|
|
184
|
+
if (name.startsWith("no-")) {
|
|
185
|
+
this.negated = true;
|
|
186
|
+
name = name.replace(/^no-/, "");
|
|
187
|
+
}
|
|
188
|
+
return camelcaseOptionName(name);
|
|
189
|
+
}).sort((a, b) => a.length > b.length ? 1 : -1);
|
|
190
|
+
this.name = this.names[this.names.length - 1];
|
|
191
|
+
if (this.negated && this.config.default == null) this.config.default = true;
|
|
192
|
+
if (rawName.includes("<")) this.required = true;
|
|
193
|
+
else if (rawName.includes("[")) this.required = false;
|
|
194
|
+
else this.isBoolean = true;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
const processArgs = process.argv;
|
|
198
|
+
const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
|
|
199
|
+
var Command = class {
|
|
200
|
+
constructor(rawName, description, config = {}, cli) {
|
|
201
|
+
this.rawName = rawName;
|
|
202
|
+
this.description = description;
|
|
203
|
+
this.config = config;
|
|
204
|
+
this.cli = cli;
|
|
205
|
+
this.options = [];
|
|
206
|
+
this.aliasNames = [];
|
|
207
|
+
this.name = removeBrackets(rawName);
|
|
208
|
+
this.args = findAllBrackets(rawName);
|
|
209
|
+
this.examples = [];
|
|
210
|
+
}
|
|
211
|
+
usage(text) {
|
|
212
|
+
this.usageText = text;
|
|
213
|
+
return this;
|
|
214
|
+
}
|
|
215
|
+
allowUnknownOptions() {
|
|
216
|
+
this.config.allowUnknownOptions = true;
|
|
217
|
+
return this;
|
|
218
|
+
}
|
|
219
|
+
ignoreOptionDefaultValue() {
|
|
220
|
+
this.config.ignoreOptionDefaultValue = true;
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
version(version, customFlags = "-v, --version") {
|
|
224
|
+
this.versionNumber = version;
|
|
225
|
+
this.option(customFlags, "Display version number");
|
|
226
|
+
return this;
|
|
227
|
+
}
|
|
228
|
+
example(example) {
|
|
229
|
+
this.examples.push(example);
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
option(rawName, description, config) {
|
|
233
|
+
const option = new Option(rawName, description, config);
|
|
234
|
+
this.options.push(option);
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
alias(name) {
|
|
238
|
+
this.aliasNames.push(name);
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
action(callback) {
|
|
242
|
+
this.commandAction = callback;
|
|
243
|
+
return this;
|
|
244
|
+
}
|
|
245
|
+
isMatched(name) {
|
|
246
|
+
return this.name === name || this.aliasNames.includes(name);
|
|
247
|
+
}
|
|
248
|
+
get isDefaultCommand() {
|
|
249
|
+
return this.name === "" || this.aliasNames.includes("!");
|
|
250
|
+
}
|
|
251
|
+
get isGlobalCommand() {
|
|
252
|
+
return this instanceof GlobalCommand;
|
|
253
|
+
}
|
|
254
|
+
hasOption(name) {
|
|
255
|
+
name = name.split(".")[0];
|
|
256
|
+
return this.options.find((option) => {
|
|
257
|
+
return option.names.includes(name);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
outputHelp() {
|
|
261
|
+
const { name, commands } = this.cli;
|
|
262
|
+
const { versionNumber, options: globalOptions, helpCallback } = this.cli.globalCommand;
|
|
263
|
+
let sections = [{ body: `${name}${versionNumber ? `/${versionNumber}` : ""}` }];
|
|
264
|
+
sections.push({
|
|
265
|
+
title: "Usage",
|
|
266
|
+
body: ` $ ${name} ${this.usageText || this.rawName}`
|
|
267
|
+
});
|
|
268
|
+
if ((this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0) {
|
|
269
|
+
const longestCommandName = findLongest(commands.map((command) => command.rawName));
|
|
270
|
+
sections.push({
|
|
271
|
+
title: "Commands",
|
|
272
|
+
body: commands.map((command) => {
|
|
273
|
+
return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
|
|
274
|
+
}).join("\n")
|
|
275
|
+
});
|
|
276
|
+
sections.push({
|
|
277
|
+
title: `For more info, run any command with the \`--help\` flag`,
|
|
278
|
+
body: commands.map((command) => ` $ ${name}${command.name === "" ? "" : ` ${command.name}`} --help`).join("\n")
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
let options = this.isGlobalCommand ? globalOptions : [...this.options, ...globalOptions || []];
|
|
282
|
+
if (!this.isGlobalCommand && !this.isDefaultCommand) options = options.filter((option) => option.name !== "version");
|
|
283
|
+
if (options.length > 0) {
|
|
284
|
+
const longestOptionName = findLongest(options.map((option) => option.rawName));
|
|
285
|
+
sections.push({
|
|
286
|
+
title: "Options",
|
|
287
|
+
body: options.map((option) => {
|
|
288
|
+
return ` ${padRight(option.rawName, longestOptionName.length)} ${option.description} ${option.config.default === void 0 ? "" : `(default: ${option.config.default})`}`;
|
|
289
|
+
}).join("\n")
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
if (this.examples.length > 0) sections.push({
|
|
293
|
+
title: "Examples",
|
|
294
|
+
body: this.examples.map((example) => {
|
|
295
|
+
if (typeof example === "function") return example(name);
|
|
296
|
+
return example;
|
|
297
|
+
}).join("\n")
|
|
298
|
+
});
|
|
299
|
+
if (helpCallback) sections = helpCallback(sections) || sections;
|
|
300
|
+
console.log(sections.map((section) => {
|
|
301
|
+
return section.title ? `${section.title}:
|
|
302
|
+
${section.body}` : section.body;
|
|
303
|
+
}).join("\n\n"));
|
|
304
|
+
}
|
|
305
|
+
outputVersion() {
|
|
306
|
+
const { name } = this.cli;
|
|
307
|
+
const { versionNumber } = this.cli.globalCommand;
|
|
308
|
+
if (versionNumber) console.log(`${name}/${versionNumber} ${platformInfo}`);
|
|
309
|
+
}
|
|
310
|
+
checkRequiredArgs() {
|
|
311
|
+
const minimalArgsCount = this.args.filter((arg) => arg.required).length;
|
|
312
|
+
if (this.cli.args.length < minimalArgsCount) throw new CACError(`missing required args for command \`${this.rawName}\``);
|
|
313
|
+
}
|
|
314
|
+
checkUnknownOptions() {
|
|
315
|
+
const { options, globalCommand } = this.cli;
|
|
316
|
+
if (!this.config.allowUnknownOptions) {
|
|
317
|
+
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}`}\``);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
checkOptionValue() {
|
|
321
|
+
const { options: parsedOptions, globalCommand } = this.cli;
|
|
322
|
+
const options = [...globalCommand.options, ...this.options];
|
|
323
|
+
for (const option of options) {
|
|
324
|
+
const value = parsedOptions[option.name.split(".")[0]];
|
|
325
|
+
if (option.required) {
|
|
326
|
+
const hasNegated = options.some((o) => o.negated && o.names.includes(option.name));
|
|
327
|
+
if (value === true || value === false && !hasNegated) throw new CACError(`option \`${option.rawName}\` value is missing`);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
var GlobalCommand = class extends Command {
|
|
333
|
+
constructor(cli) {
|
|
334
|
+
super("@@global@@", "", {}, cli);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
var __assign = Object.assign;
|
|
338
|
+
var CAC = class extends EventEmitter {
|
|
339
|
+
constructor(name = "") {
|
|
340
|
+
super();
|
|
341
|
+
this.name = name;
|
|
342
|
+
this.commands = [];
|
|
343
|
+
this.rawArgs = [];
|
|
344
|
+
this.args = [];
|
|
345
|
+
this.options = {};
|
|
346
|
+
this.globalCommand = new GlobalCommand(this);
|
|
347
|
+
this.globalCommand.usage("<command> [options]");
|
|
348
|
+
}
|
|
349
|
+
usage(text) {
|
|
350
|
+
this.globalCommand.usage(text);
|
|
351
|
+
return this;
|
|
352
|
+
}
|
|
353
|
+
command(rawName, description, config) {
|
|
354
|
+
const command = new Command(rawName, description || "", config, this);
|
|
355
|
+
command.globalCommand = this.globalCommand;
|
|
356
|
+
this.commands.push(command);
|
|
357
|
+
return command;
|
|
358
|
+
}
|
|
359
|
+
option(rawName, description, config) {
|
|
360
|
+
this.globalCommand.option(rawName, description, config);
|
|
361
|
+
return this;
|
|
362
|
+
}
|
|
363
|
+
help(callback) {
|
|
364
|
+
this.globalCommand.option("-h, --help", "Display this message");
|
|
365
|
+
this.globalCommand.helpCallback = callback;
|
|
366
|
+
this.showHelpOnExit = true;
|
|
367
|
+
return this;
|
|
368
|
+
}
|
|
369
|
+
version(version, customFlags = "-v, --version") {
|
|
370
|
+
this.globalCommand.version(version, customFlags);
|
|
371
|
+
this.showVersionOnExit = true;
|
|
372
|
+
return this;
|
|
373
|
+
}
|
|
374
|
+
example(example) {
|
|
375
|
+
this.globalCommand.example(example);
|
|
376
|
+
return this;
|
|
377
|
+
}
|
|
378
|
+
outputHelp() {
|
|
379
|
+
if (this.matchedCommand) this.matchedCommand.outputHelp();
|
|
380
|
+
else this.globalCommand.outputHelp();
|
|
381
|
+
}
|
|
382
|
+
outputVersion() {
|
|
383
|
+
this.globalCommand.outputVersion();
|
|
384
|
+
}
|
|
385
|
+
setParsedInfo({ args, options }, matchedCommand, matchedCommandName) {
|
|
386
|
+
this.args = args;
|
|
387
|
+
this.options = options;
|
|
388
|
+
if (matchedCommand) this.matchedCommand = matchedCommand;
|
|
389
|
+
if (matchedCommandName) this.matchedCommandName = matchedCommandName;
|
|
390
|
+
return this;
|
|
391
|
+
}
|
|
392
|
+
unsetMatchedCommand() {
|
|
393
|
+
this.matchedCommand = void 0;
|
|
394
|
+
this.matchedCommandName = void 0;
|
|
395
|
+
}
|
|
396
|
+
parse(argv = processArgs, { run = true } = {}) {
|
|
397
|
+
this.rawArgs = argv;
|
|
398
|
+
if (!this.name) this.name = argv[1] ? getFileName(argv[1]) : "cli";
|
|
399
|
+
let shouldParse = true;
|
|
400
|
+
for (const command of this.commands) {
|
|
401
|
+
const parsed = this.mri(argv.slice(2), command);
|
|
402
|
+
const commandName = parsed.args[0];
|
|
403
|
+
if (command.isMatched(commandName)) {
|
|
404
|
+
shouldParse = false;
|
|
405
|
+
const parsedInfo = __assign(__assign({}, parsed), { args: parsed.args.slice(1) });
|
|
406
|
+
this.setParsedInfo(parsedInfo, command, commandName);
|
|
407
|
+
this.emit(`command:${commandName}`, command);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (shouldParse) {
|
|
411
|
+
for (const command of this.commands) if (command.name === "") {
|
|
412
|
+
shouldParse = false;
|
|
413
|
+
const parsed = this.mri(argv.slice(2), command);
|
|
414
|
+
this.setParsedInfo(parsed, command);
|
|
415
|
+
this.emit(`command:!`, command);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
if (shouldParse) {
|
|
419
|
+
const parsed = this.mri(argv.slice(2));
|
|
420
|
+
this.setParsedInfo(parsed);
|
|
421
|
+
}
|
|
422
|
+
if (this.options.help && this.showHelpOnExit) {
|
|
423
|
+
this.outputHelp();
|
|
424
|
+
run = false;
|
|
425
|
+
this.unsetMatchedCommand();
|
|
426
|
+
}
|
|
427
|
+
if (this.options.version && this.showVersionOnExit && this.matchedCommandName == null) {
|
|
428
|
+
this.outputVersion();
|
|
429
|
+
run = false;
|
|
430
|
+
this.unsetMatchedCommand();
|
|
431
|
+
}
|
|
432
|
+
const parsedArgv = {
|
|
433
|
+
args: this.args,
|
|
434
|
+
options: this.options
|
|
435
|
+
};
|
|
436
|
+
if (run) this.runMatchedCommand();
|
|
437
|
+
if (!this.matchedCommand && this.args[0]) this.emit("command:*");
|
|
438
|
+
return parsedArgv;
|
|
439
|
+
}
|
|
440
|
+
mri(argv, command) {
|
|
441
|
+
const cliOptions = [...this.globalCommand.options, ...command ? command.options : []];
|
|
442
|
+
const mriOptions = getMriOptions(cliOptions);
|
|
443
|
+
let argsAfterDoubleDashes = [];
|
|
444
|
+
const doubleDashesIndex = argv.indexOf("--");
|
|
445
|
+
if (doubleDashesIndex > -1) {
|
|
446
|
+
argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
|
|
447
|
+
argv = argv.slice(0, doubleDashesIndex);
|
|
448
|
+
}
|
|
449
|
+
let parsed = mri2(argv, mriOptions);
|
|
450
|
+
parsed = Object.keys(parsed).reduce((res, name) => {
|
|
451
|
+
return __assign(__assign({}, res), { [camelcaseOptionName(name)]: parsed[name] });
|
|
452
|
+
}, { _: [] });
|
|
453
|
+
const args = parsed._;
|
|
454
|
+
const options = { "--": argsAfterDoubleDashes };
|
|
455
|
+
const ignoreDefault = command && command.config.ignoreOptionDefaultValue ? command.config.ignoreOptionDefaultValue : this.globalCommand.config.ignoreOptionDefaultValue;
|
|
456
|
+
let transforms = Object.create(null);
|
|
457
|
+
for (const cliOption of cliOptions) {
|
|
458
|
+
if (!ignoreDefault && cliOption.config.default !== void 0) for (const name of cliOption.names) options[name] = cliOption.config.default;
|
|
459
|
+
if (Array.isArray(cliOption.config.type)) {
|
|
460
|
+
if (transforms[cliOption.name] === void 0) {
|
|
461
|
+
transforms[cliOption.name] = Object.create(null);
|
|
462
|
+
transforms[cliOption.name]["shouldTransform"] = true;
|
|
463
|
+
transforms[cliOption.name]["transformFunction"] = cliOption.config.type[0];
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
for (const key of Object.keys(parsed)) if (key !== "_") {
|
|
468
|
+
setDotProp(options, key.split("."), parsed[key]);
|
|
469
|
+
setByType(options, transforms);
|
|
470
|
+
}
|
|
471
|
+
return {
|
|
472
|
+
args,
|
|
473
|
+
options
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
runMatchedCommand() {
|
|
477
|
+
const { args, options, matchedCommand: command } = this;
|
|
478
|
+
if (!command || !command.commandAction) return;
|
|
479
|
+
command.checkUnknownOptions();
|
|
480
|
+
command.checkOptionValue();
|
|
481
|
+
command.checkRequiredArgs();
|
|
482
|
+
const actionArgs = [];
|
|
483
|
+
command.args.forEach((arg, index) => {
|
|
484
|
+
if (arg.variadic) actionArgs.push(args.slice(index));
|
|
485
|
+
else actionArgs.push(args[index]);
|
|
486
|
+
});
|
|
487
|
+
actionArgs.push(options);
|
|
488
|
+
return command.commandAction.apply(this, actionArgs);
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
const cac = (name = "") => new CAC(name);
|
|
492
|
+
//#endregion
|
|
14
493
|
//#region src/cli/arguments/alias.ts
|
|
15
494
|
const alias = {
|
|
16
495
|
config: {
|
|
@@ -32,27 +511,15 @@ const alias = {
|
|
|
32
511
|
format: { abbreviation: "f" },
|
|
33
512
|
name: { abbreviation: "n" },
|
|
34
513
|
globals: { abbreviation: "g" },
|
|
35
|
-
sourcemap: {
|
|
36
|
-
abbreviation: "s",
|
|
37
|
-
default: true
|
|
38
|
-
},
|
|
514
|
+
sourcemap: { abbreviation: "s" },
|
|
39
515
|
minify: { abbreviation: "m" },
|
|
40
516
|
platform: { abbreviation: "p" },
|
|
41
517
|
assetFileNames: { hint: "name" },
|
|
42
518
|
chunkFileNames: { hint: "name" },
|
|
43
519
|
entryFileNames: { hint: "name" },
|
|
44
|
-
externalLiveBindings: {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
48
|
-
treeshake: {
|
|
49
|
-
default: true,
|
|
50
|
-
reverse: true
|
|
51
|
-
},
|
|
52
|
-
preserveEntrySignatures: {
|
|
53
|
-
default: "strict",
|
|
54
|
-
reverse: true
|
|
55
|
-
},
|
|
520
|
+
externalLiveBindings: { reverse: true },
|
|
521
|
+
treeshake: { reverse: true },
|
|
522
|
+
preserveEntrySignatures: { reverse: true },
|
|
56
523
|
moduleTypes: { hint: "types" }
|
|
57
524
|
};
|
|
58
525
|
//#endregion
|
|
@@ -75,24 +542,17 @@ function setNestedProperty(obj, path, value) {
|
|
|
75
542
|
function camelCaseToKebabCase(str) {
|
|
76
543
|
return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
77
544
|
}
|
|
78
|
-
function kebabCaseToCamelCase(str) {
|
|
79
|
-
return str.replace(/-./g, (match) => match[1].toUpperCase());
|
|
80
|
-
}
|
|
81
545
|
//#endregion
|
|
82
546
|
//#region src/cli/arguments/normalize.ts
|
|
547
|
+
const reservedKeys = new Set([
|
|
548
|
+
"help",
|
|
549
|
+
"version",
|
|
550
|
+
"config",
|
|
551
|
+
"watch",
|
|
552
|
+
"environment"
|
|
553
|
+
]);
|
|
83
554
|
function normalizeCliOptions(cliOptions, positionals) {
|
|
84
|
-
const
|
|
85
|
-
"__proto__",
|
|
86
|
-
"constructor",
|
|
87
|
-
"prototype"
|
|
88
|
-
];
|
|
89
|
-
const unflattenedCliOptions = {};
|
|
90
|
-
for (let [key, value] of Object.entries(cliOptions)) if (prototypePollutionKeys.includes(key)) {} else if (key.includes(".")) {
|
|
91
|
-
const [parentKey] = key.split(".");
|
|
92
|
-
unflattenedCliOptions[parentKey] ??= {};
|
|
93
|
-
setNestedProperty(unflattenedCliOptions, key, value);
|
|
94
|
-
} else unflattenedCliOptions[key] = value;
|
|
95
|
-
const [data, errors] = validateCliOptions(unflattenedCliOptions);
|
|
555
|
+
const [data, errors] = validateCliOptions(cliOptions);
|
|
96
556
|
if (errors?.length) {
|
|
97
557
|
errors.forEach((error) => {
|
|
98
558
|
logger.error(`${error}. You can use \`rolldown -h\` to see the help.`);
|
|
@@ -108,21 +568,15 @@ function normalizeCliOptions(cliOptions, positionals) {
|
|
|
108
568
|
watch: options.watch ?? false
|
|
109
569
|
};
|
|
110
570
|
if (typeof options.config === "string") result.config = options.config;
|
|
571
|
+
else if (options.config === true) result.config = "";
|
|
111
572
|
if (options.environment !== void 0) result.environment = options.environment;
|
|
112
|
-
const keysOfInput = getInputCliKeys();
|
|
113
|
-
const keysOfOutput = getOutputCliKeys();
|
|
114
|
-
const reservedKeys = [
|
|
115
|
-
"help",
|
|
116
|
-
"version",
|
|
117
|
-
"config",
|
|
118
|
-
"watch",
|
|
119
|
-
"environment"
|
|
120
|
-
];
|
|
573
|
+
const keysOfInput = new Set(getInputCliKeys());
|
|
574
|
+
const keysOfOutput = new Set(getOutputCliKeys());
|
|
121
575
|
for (let [key, value] of Object.entries(options)) {
|
|
122
576
|
const [primary] = key.split(".");
|
|
123
|
-
if (keysOfInput.
|
|
124
|
-
else if (keysOfOutput.
|
|
125
|
-
else if (!reservedKeys.
|
|
577
|
+
if (keysOfInput.has(primary)) setNestedProperty(result.input, key, value);
|
|
578
|
+
else if (keysOfOutput.has(primary)) setNestedProperty(result.output, key, value);
|
|
579
|
+
else if (!reservedKeys.has(key)) {
|
|
126
580
|
logger.error(`Unknown option: ${key}`);
|
|
127
581
|
process.exit(1);
|
|
128
582
|
}
|
|
@@ -135,119 +589,115 @@ function normalizeCliOptions(cliOptions, positionals) {
|
|
|
135
589
|
//#region src/cli/arguments/index.ts
|
|
136
590
|
const schemaInfo = getCliSchemaInfo();
|
|
137
591
|
const options = Object.fromEntries(Object.entries(schemaInfo).filter(([_key, info]) => info.type !== "never").map(([key, info]) => {
|
|
138
|
-
const config =
|
|
592
|
+
const config = alias[key];
|
|
593
|
+
let description = info?.description ?? config?.description ?? "";
|
|
594
|
+
if (config?.reverse) {
|
|
595
|
+
if (description.startsWith("enable")) description = description.replace("enable", "disable");
|
|
596
|
+
else if (!description.startsWith("Avoid")) description = `disable ${description}`;
|
|
597
|
+
}
|
|
139
598
|
const result = {
|
|
140
599
|
type: info.type === "boolean" ? "boolean" : "string",
|
|
141
|
-
description
|
|
142
|
-
hint: config?.hint
|
|
600
|
+
description
|
|
143
601
|
};
|
|
144
|
-
if (config
|
|
145
|
-
if (config
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
key = camelCaseToKebabCase(key);
|
|
150
|
-
return [config?.reverse ? `no-${key}` : key, result];
|
|
602
|
+
if (config?.abbreviation) result.short = config.abbreviation;
|
|
603
|
+
if (config?.hint) result.hint = config.hint;
|
|
604
|
+
const kebabKey = camelCaseToKebabCase(key);
|
|
605
|
+
return [config?.reverse ? `no-${kebabKey}` : kebabKey, result];
|
|
151
606
|
}));
|
|
607
|
+
const knownKeys = new Set(Object.keys(schemaInfo));
|
|
608
|
+
for (const key of Object.keys(schemaInfo)) {
|
|
609
|
+
const dotIdx = key.indexOf(".");
|
|
610
|
+
if (dotIdx > 0) knownKeys.add(key.substring(0, dotIdx));
|
|
611
|
+
}
|
|
612
|
+
const shortAliases = /* @__PURE__ */ new Set();
|
|
613
|
+
for (const config of Object.values(alias)) if (config?.abbreviation) shortAliases.add(config.abbreviation);
|
|
152
614
|
function parseCliArguments() {
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
615
|
+
const cli = cac("rolldown");
|
|
616
|
+
for (const [key, info] of Object.entries(schemaInfo)) {
|
|
617
|
+
if (info.type === "never") continue;
|
|
618
|
+
const config = alias[key];
|
|
619
|
+
let rawName = "";
|
|
620
|
+
if (config?.abbreviation) rawName += `-${config.abbreviation}, `;
|
|
621
|
+
if (config?.reverse) rawName += `--no-${key}`;
|
|
622
|
+
else rawName += `--${key}`;
|
|
623
|
+
if (info.type !== "boolean" && !config?.reverse) if (config?.requireValue) rawName += ` <${config?.hint ?? key}>`;
|
|
624
|
+
else rawName += ` [${config?.hint ?? key}]`;
|
|
625
|
+
cli.option(rawName, info.description ?? config?.description ?? "");
|
|
626
|
+
}
|
|
627
|
+
let parsedInput = [];
|
|
628
|
+
let parsedOptions = {};
|
|
629
|
+
const cmd = cli.command("[...input]", "");
|
|
630
|
+
cmd.allowUnknownOptions();
|
|
631
|
+
cmd.ignoreOptionDefaultValue();
|
|
632
|
+
cmd.action((input, opts) => {
|
|
633
|
+
parsedInput = input;
|
|
634
|
+
parsedOptions = opts;
|
|
158
635
|
});
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
636
|
+
try {
|
|
637
|
+
cli.parse(process.argv, { run: true });
|
|
638
|
+
} catch (err) {
|
|
639
|
+
if (err?.name === "CACError") {
|
|
640
|
+
const match = err.message.match(/option `(.+?)` value is missing/);
|
|
641
|
+
if (match) {
|
|
642
|
+
const optName = match[1].replace(/ [<[].*/, "").replace(/^-\w, /, "");
|
|
643
|
+
logger.error(`Option \`${optName}\` requires a value but none was provided.`);
|
|
644
|
+
} else logger.error(err.message);
|
|
645
|
+
process.exit(1);
|
|
168
646
|
}
|
|
169
|
-
|
|
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
|
-
if (
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
value: option.value ?? defaultValue?.default ?? "",
|
|
222
|
-
enumerable: true,
|
|
223
|
-
configurable: true,
|
|
224
|
-
writable: true
|
|
225
|
-
});
|
|
226
|
-
} else Object.defineProperty(values, option.name, {
|
|
227
|
-
value: option.value ?? "",
|
|
228
|
-
enumerable: true,
|
|
229
|
-
configurable: true,
|
|
230
|
-
writable: true
|
|
231
|
-
});
|
|
232
|
-
}).filter((item) => {
|
|
233
|
-
return item !== void 0;
|
|
234
|
-
});
|
|
235
|
-
invalid_options.sort((a, b) => {
|
|
236
|
-
return a.name.localeCompare(b.name);
|
|
237
|
-
});
|
|
238
|
-
if (invalid_options.length !== 0) {
|
|
239
|
-
let single = invalid_options.length === 1;
|
|
240
|
-
logger.warn(`Option \`${invalid_options.map((item) => item.name).join(",")}\` ${single ? "is" : "are"} unrecognized. We will ignore ${single ? "this" : "those"} option${single ? "" : "s"}.`);
|
|
241
|
-
}
|
|
242
|
-
let rawArgs = {
|
|
243
|
-
...values,
|
|
244
|
-
...invalid_options.reduce((acc, cur) => {
|
|
245
|
-
acc[cur.name] = cur.value;
|
|
246
|
-
return acc;
|
|
247
|
-
}, Object.create(null))
|
|
248
|
-
};
|
|
647
|
+
throw err;
|
|
648
|
+
}
|
|
649
|
+
delete parsedOptions["--"];
|
|
650
|
+
for (const short of shortAliases) delete parsedOptions[short];
|
|
651
|
+
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];
|
|
652
|
+
const unknownKeys = Object.keys(parsedOptions).filter((k) => !knownKeys.has(k));
|
|
653
|
+
if (unknownKeys.length > 0) {
|
|
654
|
+
unknownKeys.sort();
|
|
655
|
+
const single = unknownKeys.length === 1;
|
|
656
|
+
logger.warn(`Option \`${unknownKeys.join(",")}\` ${single ? "is" : "are"} unrecognized. We will ignore ${single ? "this" : "those"} option${single ? "" : "s"}.`);
|
|
657
|
+
}
|
|
658
|
+
const rawArgs = { ...parsedOptions };
|
|
659
|
+
for (const key of unknownKeys) delete parsedOptions[key];
|
|
660
|
+
for (const [key, value] of Object.entries(parsedOptions)) {
|
|
661
|
+
const type = schemaInfo[key]?.type;
|
|
662
|
+
if (Array.isArray(value)) {
|
|
663
|
+
if (type !== "array" && type !== "object") parsedOptions[key] = value[value.length - 1];
|
|
664
|
+
} else if (type === "array" && typeof value === "string") parsedOptions[key] = [value];
|
|
665
|
+
}
|
|
666
|
+
for (const [schemaKey, info] of Object.entries(schemaInfo)) {
|
|
667
|
+
if (info.type !== "object") continue;
|
|
668
|
+
const parts = schemaKey.split(".");
|
|
669
|
+
let parent = parsedOptions;
|
|
670
|
+
for (let i = 0; i < parts.length - 1; i++) parent = parent?.[parts[i]];
|
|
671
|
+
const leafKey = parts[parts.length - 1];
|
|
672
|
+
const value = parent?.[leafKey];
|
|
673
|
+
if (value === void 0) continue;
|
|
674
|
+
const values = Array.isArray(value) ? value : [value];
|
|
675
|
+
if (typeof values[0] !== "string") continue;
|
|
676
|
+
let usedDeprecatedSyntax = false;
|
|
677
|
+
const result = {};
|
|
678
|
+
for (const v of values) for (const pair of String(v).split(",")) {
|
|
679
|
+
const colonIdx = pair.indexOf(":");
|
|
680
|
+
const eqIdx = pair.indexOf("=");
|
|
681
|
+
let k;
|
|
682
|
+
let val;
|
|
683
|
+
if (colonIdx > 0 && (eqIdx === -1 || colonIdx < eqIdx)) {
|
|
684
|
+
k = pair.slice(0, colonIdx);
|
|
685
|
+
val = pair.slice(colonIdx + 1);
|
|
686
|
+
} else if (eqIdx > 0) {
|
|
687
|
+
k = pair.slice(0, eqIdx);
|
|
688
|
+
val = pair.slice(eqIdx + 1);
|
|
689
|
+
usedDeprecatedSyntax = true;
|
|
690
|
+
} else continue;
|
|
691
|
+
result[k] = val;
|
|
692
|
+
}
|
|
693
|
+
if (usedDeprecatedSyntax) {
|
|
694
|
+
const optionName = camelCaseToKebabCase(schemaKey);
|
|
695
|
+
logger.warn(`Using \`key=value\` syntax for \`--${optionName}\` is deprecated. Use \`key:value\` instead.`);
|
|
696
|
+
}
|
|
697
|
+
parent[leafKey] = result;
|
|
698
|
+
}
|
|
249
699
|
return {
|
|
250
|
-
...normalizeCliOptions(
|
|
700
|
+
...normalizeCliOptions(parsedOptions, parsedInput),
|
|
251
701
|
rawArgs
|
|
252
702
|
};
|
|
253
703
|
}
|
|
@@ -350,7 +800,7 @@ async function bundleWithCliOptions(cliOptions) {
|
|
|
350
800
|
process.exit(1);
|
|
351
801
|
}
|
|
352
802
|
for (const file of outputs) {
|
|
353
|
-
if (outputs.length > 1) logger.log(`\n${styleText
|
|
803
|
+
if (outputs.length > 1) logger.log(`\n${styleText(["cyan", "bold"], `|→ ${file.fileName}:`)}\n`);
|
|
354
804
|
console.log(file.type === "asset" ? file.source : file.code);
|
|
355
805
|
}
|
|
356
806
|
} catch (_) {
|
|
@@ -390,12 +840,12 @@ async function watchInner(config, cliOptions) {
|
|
|
390
840
|
clearScreen?.();
|
|
391
841
|
break;
|
|
392
842
|
case "BUNDLE_START":
|
|
393
|
-
if (changedFile.length > 0) logger.log(`Found ${styleText
|
|
843
|
+
if (changedFile.length > 0) logger.log(`Found ${styleText("bold", changedFile.map(relativeId).join(", "))} changed, rebuilding...`);
|
|
394
844
|
changedFile.length = 0;
|
|
395
845
|
break;
|
|
396
846
|
case "BUNDLE_END":
|
|
397
847
|
await event.result.close();
|
|
398
|
-
logger.success(`Rebuilt ${styleText
|
|
848
|
+
logger.success(`Rebuilt ${styleText("bold", relativeId(event.output[0]))} in ${styleText("green", ms(event.duration))}.`);
|
|
399
849
|
break;
|
|
400
850
|
case "ERROR":
|
|
401
851
|
await event.result.close();
|
|
@@ -428,7 +878,7 @@ async function bundleInner(config, cliOptions) {
|
|
|
428
878
|
result.forEach(printBundleOutputPretty);
|
|
429
879
|
logger.log(``);
|
|
430
880
|
const duration = performance.now() - startTime;
|
|
431
|
-
logger.success(`rolldown v${version} Finished in ${styleText
|
|
881
|
+
logger.success(`rolldown v${version} Finished in ${styleText("green", ms(duration))}`);
|
|
432
882
|
}
|
|
433
883
|
function printBundleOutputPretty(output) {
|
|
434
884
|
const outputEntries = collectOutputEntries(output.output);
|
|
@@ -474,10 +924,10 @@ function printOutputEntries(entries, sizeAdjustment, distPath) {
|
|
|
474
924
|
const filtered = entries.filter((e) => e.type === group.type);
|
|
475
925
|
if (!filtered.length) continue;
|
|
476
926
|
for (const entry of filtered.sort((a, z) => a.size - z.size)) {
|
|
477
|
-
let log = styleText
|
|
478
|
-
log += styleText
|
|
479
|
-
log += styleText
|
|
480
|
-
log += styleText
|
|
927
|
+
let log = styleText("dim", withTrailingSlash(distPath));
|
|
928
|
+
log += styleText(group.color, entry.fileName.padEnd(sizeAdjustment.longest + 2));
|
|
929
|
+
log += styleText("dim", entry.type);
|
|
930
|
+
log += styleText("dim", ` │ size: ${displaySize(entry.size).padStart(sizeAdjustment.sizePad)}`);
|
|
481
931
|
logger.log(log);
|
|
482
932
|
}
|
|
483
933
|
}
|
|
@@ -517,22 +967,17 @@ const examples = [
|
|
|
517
967
|
command: "rolldown src/main.ts -d dist -n bundle -f iife -e jQuery,window._ -g jQuery=$"
|
|
518
968
|
}
|
|
519
969
|
];
|
|
520
|
-
const notes = [
|
|
521
|
-
"Due to the API limitation, you need to pass `-s` for `.map` sourcemap file as the last argument.",
|
|
522
|
-
"If you are using the configuration, please pass the `-c` as the last argument if you ignore the default configuration file.",
|
|
523
|
-
"CLI options will override the configuration file.",
|
|
524
|
-
"For more information, please visit https://rolldown.rs/."
|
|
525
|
-
];
|
|
970
|
+
const notes = ["CLI options will override the configuration file.", "For more information, please visit https://rolldown.rs/."];
|
|
526
971
|
/**
|
|
527
972
|
* Generates the CLI help text as a string.
|
|
528
973
|
*/
|
|
529
974
|
function generateHelpText() {
|
|
530
975
|
const lines = [];
|
|
531
|
-
lines.push(`${styleText
|
|
976
|
+
lines.push(`${styleText("gray", `${description} (rolldown v${version})`)}`);
|
|
532
977
|
lines.push("");
|
|
533
|
-
lines.push(`${styleText
|
|
978
|
+
lines.push(`${styleText(["bold", "underline"], "USAGE")} ${styleText("cyan", "rolldown -c <config>")} or ${styleText("cyan", "rolldown <input> <options>")}`);
|
|
534
979
|
lines.push("");
|
|
535
|
-
lines.push(`${styleText
|
|
980
|
+
lines.push(`${styleText(["bold", "underline"], "OPTIONS")}`);
|
|
536
981
|
lines.push("");
|
|
537
982
|
lines.push(Object.entries(options).sort(([a], [b]) => {
|
|
538
983
|
if (options[a].short && !options[b].short) return -1;
|
|
@@ -545,20 +990,20 @@ function generateHelpText() {
|
|
|
545
990
|
if (short) optionStr += `-${short}, `;
|
|
546
991
|
if (type === "string") optionStr += `<${hint ?? option}>`;
|
|
547
992
|
if (description && description.length > 0) description = description[0].toUpperCase() + description.slice(1);
|
|
548
|
-
return styleText
|
|
993
|
+
return styleText("cyan", optionStr.padEnd(30)) + description + (description && description?.endsWith(".") ? "" : ".");
|
|
549
994
|
}).join("\n"));
|
|
550
995
|
lines.push("");
|
|
551
|
-
lines.push(`${styleText
|
|
996
|
+
lines.push(`${styleText(["bold", "underline"], "EXAMPLES")}`);
|
|
552
997
|
lines.push("");
|
|
553
998
|
examples.forEach(({ title, command }, ord) => {
|
|
554
999
|
lines.push(` ${ord + 1}. ${title}:`);
|
|
555
|
-
lines.push(` ${styleText
|
|
1000
|
+
lines.push(` ${styleText("cyan", command)}`);
|
|
556
1001
|
lines.push("");
|
|
557
1002
|
});
|
|
558
|
-
lines.push(`${styleText
|
|
1003
|
+
lines.push(`${styleText(["bold", "underline"], "NOTES")}`);
|
|
559
1004
|
lines.push("");
|
|
560
1005
|
notes.forEach((note) => {
|
|
561
|
-
lines.push(` * ${styleText
|
|
1006
|
+
lines.push(` * ${styleText("gray", note)}`);
|
|
562
1007
|
});
|
|
563
1008
|
return lines.join("\n");
|
|
564
1009
|
}
|
|
@@ -585,6 +1030,14 @@ async function main() {
|
|
|
585
1030
|
process$1.env[key] = value.length === 0 ? String(true) : value.join(":");
|
|
586
1031
|
}
|
|
587
1032
|
}
|
|
1033
|
+
if (cliOptions.help) {
|
|
1034
|
+
showHelp();
|
|
1035
|
+
return;
|
|
1036
|
+
}
|
|
1037
|
+
if (cliOptions.version) {
|
|
1038
|
+
logger.log(`rolldown v${version}`);
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
588
1041
|
if (cliOptions.config || cliOptions.config === "") {
|
|
589
1042
|
await bundleWithConfig(cliOptions.config, cliOptions, rawArgs);
|
|
590
1043
|
return;
|
|
@@ -593,10 +1046,6 @@ async function main() {
|
|
|
593
1046
|
await bundleWithCliOptions(cliOptions);
|
|
594
1047
|
return;
|
|
595
1048
|
}
|
|
596
|
-
if (cliOptions.version) {
|
|
597
|
-
logger.log(`rolldown v${version}`);
|
|
598
|
-
return;
|
|
599
|
-
}
|
|
600
1049
|
showHelp();
|
|
601
1050
|
}
|
|
602
1051
|
main().catch((err) => {
|