rolldown 1.0.0-beta.6-commit.0fdc9f2 → 1.0.0-beta.60
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 +11 -0
- package/bin/cli.mjs +3 -0
- package/dist/cli-setup.d.mts +1 -0
- package/dist/cli-setup.mjs +17 -0
- package/dist/cli.d.mts +1 -0
- package/dist/{esm/cli.mjs → cli.mjs} +405 -577
- package/dist/config.d.mts +10 -0
- package/dist/config.mjs +14 -0
- package/dist/experimental-index.d.mts +181 -0
- package/dist/experimental-index.mjs +266 -0
- package/dist/experimental-runtime-types.d.ts +92 -0
- package/dist/filter-index.d.mts +4 -0
- package/dist/filter-index.mjs +369 -0
- package/dist/get-log-filter.d.mts +7 -0
- package/dist/get-log-filter.mjs +48 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +38 -0
- package/dist/parallel-plugin-worker.d.mts +1 -0
- package/dist/parallel-plugin-worker.mjs +32 -0
- package/dist/parallel-plugin.d.mts +14 -0
- package/dist/{esm/parallel-plugin.mjs → parallel-plugin.mjs} +0 -1
- package/dist/parse-ast-index.d.mts +8 -0
- package/dist/parse-ast-index.mjs +4 -0
- package/dist/plugins-index.d.mts +31 -0
- package/dist/plugins-index.mjs +40 -0
- package/dist/shared/binding-C9YdqoUG.d.mts +1657 -0
- package/dist/shared/binding-Duj6W4V2.mjs +583 -0
- package/dist/shared/bindingify-input-options-tKpsInTJ.mjs +2174 -0
- package/dist/shared/constructors-D3qJVJZC.d.mts +28 -0
- package/dist/shared/constructors-DPqxrdwc.mjs +61 -0
- package/dist/shared/define-config-BF4P-Pum.mjs +7 -0
- package/dist/shared/define-config-BgCyRzGF.d.mts +2567 -0
- package/dist/shared/load-config-scjTHwJI.mjs +114 -0
- package/dist/shared/logging-DsnCZi19.d.mts +42 -0
- package/dist/shared/logs-cyjC0SDv.mjs +183 -0
- package/dist/shared/misc-0HsaOsAX.mjs +22 -0
- package/dist/shared/normalize-string-or-regex-DJvwOt-n.mjs +61 -0
- package/dist/shared/parse-ast-index-BNL_NOzM.mjs +99 -0
- package/dist/shared/{prompt-C6jWWCza.mjs → prompt-5sWCM0jm.mjs} +255 -260
- package/dist/shared/rolldown-8Hs4IFju.mjs +11 -0
- package/dist/shared/rolldown-build-if4L5V_l.mjs +2293 -0
- package/dist/shared/watch-jle4g7Gt.mjs +351 -0
- package/package.json +89 -106
- package/bin/cli.js +0 -2
- package/dist/cjs/cli.cjs +0 -1757
- package/dist/cjs/experimental-index.cjs +0 -86
- package/dist/cjs/index.cjs +0 -8
- package/dist/cjs/parallel-plugin-worker.cjs +0 -41
- package/dist/cjs/parallel-plugin.cjs +0 -9
- package/dist/cjs/parse-ast-index.cjs +0 -4
- package/dist/esm/experimental-index.mjs +0 -57
- package/dist/esm/index.mjs +0 -4
- package/dist/esm/parallel-plugin-worker.mjs +0 -39
- package/dist/esm/parse-ast-index.mjs +0 -3
- package/dist/shared/chunk-qZFfknuJ.cjs +0 -40
- package/dist/shared/parse-ast-index-BN2JFoRu.mjs +0 -696
- package/dist/shared/parse-ast-index-C8v5UEr2.cjs +0 -741
- package/dist/shared/prompt-_yrURmmm.cjs +0 -855
- package/dist/shared/src-Cl1wUC1i.cjs +0 -3073
- package/dist/shared/src-Dt33DQSB.mjs +0 -2886
- package/dist/types/api/build.d.ts +0 -18
- package/dist/types/api/experimental.d.ts +0 -7
- package/dist/types/api/rolldown/index.d.ts +0 -3
- package/dist/types/api/rolldown/rolldown-build.d.ts +0 -13
- package/dist/types/api/watch/index.d.ts +0 -3
- package/dist/types/api/watch/watch-emitter.d.ts +0 -31
- package/dist/types/api/watch/watcher.d.ts +0 -13
- package/dist/types/binding.d.ts +0 -1478
- package/dist/types/builtin-plugin/alias-plugin.d.ts +0 -10
- package/dist/types/builtin-plugin/constructors.d.ts +0 -22
- package/dist/types/builtin-plugin/replace-plugin.d.ts +0 -28
- package/dist/types/builtin-plugin/transform-plugin.d.ts +0 -9
- package/dist/types/builtin-plugin/utils.d.ts +0 -8
- package/dist/types/cli/arguments/alias.d.ts +0 -16
- package/dist/types/cli/arguments/index.d.ts +0 -15
- package/dist/types/cli/arguments/normalize.d.ts +0 -12
- package/dist/types/cli/arguments/utils.d.ts +0 -8
- package/dist/types/cli/colors.d.ts +0 -11
- package/dist/types/cli/commands/bundle.d.ts +0 -3
- package/dist/types/cli/commands/help.d.ts +0 -1
- package/dist/types/cli/index.d.ts +0 -1
- package/dist/types/cli/load-config.d.ts +0 -5
- package/dist/types/cli/logger.d.ts +0 -5
- package/dist/types/constants/plugin-context.d.ts +0 -7
- package/dist/types/constants/plugin.d.ts +0 -45
- package/dist/types/experimental-index.d.ts +0 -9
- package/dist/types/index.d.ts +0 -30
- package/dist/types/log/log-handler.d.ts +0 -4
- package/dist/types/log/logger.d.ts +0 -6
- package/dist/types/log/logging.d.ts +0 -12
- package/dist/types/log/logs.d.ts +0 -18
- package/dist/types/options/generated/checks-options.d.ts +0 -57
- package/dist/types/options/input-options.d.ts +0 -177
- package/dist/types/options/normalized-input-options.d.ts +0 -18
- package/dist/types/options/normalized-output-options.d.ts +0 -70
- package/dist/types/options/output-options.d.ts +0 -182
- package/dist/types/options/watch-options.d.ts +0 -5
- package/dist/types/parallel-plugin-worker.d.ts +0 -1
- package/dist/types/parallel-plugin.d.ts +0 -1
- package/dist/types/parse-ast-index.d.ts +0 -5
- package/dist/types/plugin/bindingify-build-hooks.d.ts +0 -10
- package/dist/types/plugin/bindingify-hook-filter.d.ts +0 -7
- package/dist/types/plugin/bindingify-output-hooks.d.ts +0 -14
- package/dist/types/plugin/bindingify-plugin-hook-meta.d.ts +0 -8
- package/dist/types/plugin/bindingify-plugin.d.ts +0 -16
- package/dist/types/plugin/bindingify-watch-hooks.d.ts +0 -5
- package/dist/types/plugin/hook-filter.d.ts +0 -48
- package/dist/types/plugin/index.d.ts +0 -136
- package/dist/types/plugin/minimal-plugin-context.d.ts +0 -23
- package/dist/types/plugin/parallel-plugin-implementation.d.ts +0 -10
- package/dist/types/plugin/parallel-plugin.d.ts +0 -9
- package/dist/types/plugin/plugin-context-data.d.ts +0 -17
- package/dist/types/plugin/plugin-context.d.ts +0 -67
- package/dist/types/plugin/plugin-driver.d.ts +0 -8
- package/dist/types/plugin/transform-plugin-context.d.ts +0 -28
- package/dist/types/types/assert.d.ts +0 -14
- package/dist/types/types/config-export.d.ts +0 -5
- package/dist/types/types/misc.d.ts +0 -40
- package/dist/types/types/module-info.d.ts +0 -15
- package/dist/types/types/module-side-effects.d.ts +0 -12
- package/dist/types/types/output-bundle.d.ts +0 -4
- package/dist/types/types/rolldown-options.d.ts +0 -5
- package/dist/types/types/rolldown-output.d.ts +0 -66
- package/dist/types/types/schema.d.ts +0 -33
- package/dist/types/types/sourcemap.d.ts +0 -14
- package/dist/types/types/utils.d.ts +0 -13
- package/dist/types/utils/asset-source.d.ts +0 -4
- package/dist/types/utils/async-flatten.d.ts +0 -1
- package/dist/types/utils/bindingify-input-options.d.ts +0 -7
- package/dist/types/utils/bindingify-output-options.d.ts +0 -5
- package/dist/types/utils/code-frame.d.ts +0 -1
- package/dist/types/utils/compose-js-plugins.d.ts +0 -2
- package/dist/types/utils/create-bundler-option.d.ts +0 -11
- package/dist/types/utils/create-bundler.d.ts +0 -9
- package/dist/types/utils/define-config.d.ts +0 -5
- package/dist/types/utils/error.d.ts +0 -2
- package/dist/types/utils/initialize-parallel-plugins.d.ts +0 -19
- package/dist/types/utils/misc.d.ts +0 -6
- package/dist/types/utils/normalize-hook.d.ts +0 -7
- package/dist/types/utils/normalize-plugin-option.d.ts +0 -13
- package/dist/types/utils/normalize-string-or-regex.d.ts +0 -2
- package/dist/types/utils/plugin/index.d.ts +0 -2
- package/dist/types/utils/resolved-external.d.ts +0 -4
- package/dist/types/utils/transform-module-info.d.ts +0 -4
- package/dist/types/utils/transform-rendered-chunk.d.ts +0 -4
- package/dist/types/utils/transform-rendered-module.d.ts +0 -3
- package/dist/types/utils/transform-side-effects.d.ts +0 -3
- package/dist/types/utils/transform-sourcemap.d.ts +0 -3
- package/dist/types/utils/transform-to-rollup-output.d.ts +0 -11
- package/dist/types/utils/validator.d.ts +0 -6
|
@@ -1,186 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import "./shared/binding-Duj6W4V2.mjs";
|
|
2
|
+
import { n as onExit, t as watch } from "./shared/watch-jle4g7Gt.mjs";
|
|
3
|
+
import "./shared/normalize-string-or-regex-DJvwOt-n.mjs";
|
|
4
|
+
import { C as description, w as version } from "./shared/bindingify-input-options-tKpsInTJ.mjs";
|
|
5
|
+
import { t as arraify } from "./shared/misc-0HsaOsAX.mjs";
|
|
6
|
+
import { a as getOutputCliKeys, c as styleText$1, i as getInputCliKeys, o as validateCliOptions, r as getCliSchemaInfo } from "./shared/rolldown-build-if4L5V_l.mjs";
|
|
7
|
+
import "./shared/parse-ast-index-BNL_NOzM.mjs";
|
|
8
|
+
import { t as rolldown } from "./shared/rolldown-8Hs4IFju.mjs";
|
|
9
|
+
import { t as loadConfig } from "./shared/load-config-scjTHwJI.mjs";
|
|
4
10
|
import path, { sep } from "node:path";
|
|
5
|
-
import fs from "node:fs";
|
|
6
|
-
import { performance } from "node:perf_hooks";
|
|
7
11
|
import { formatWithOptions, parseArgs } from "node:util";
|
|
12
|
+
import process$1 from "node:process";
|
|
8
13
|
import * as tty from "node:tty";
|
|
9
|
-
import {
|
|
10
|
-
import { pathToFileURL } from "node:url";
|
|
11
|
-
|
|
12
|
-
//#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.js
|
|
13
|
-
const signals = [];
|
|
14
|
-
signals.push("SIGHUP", "SIGINT", "SIGTERM");
|
|
15
|
-
if (process.platform !== "win32") signals.push(
|
|
16
|
-
"SIGALRM",
|
|
17
|
-
"SIGABRT",
|
|
18
|
-
"SIGVTALRM",
|
|
19
|
-
"SIGXCPU",
|
|
20
|
-
"SIGXFSZ",
|
|
21
|
-
"SIGUSR2",
|
|
22
|
-
"SIGTRAP",
|
|
23
|
-
"SIGSYS",
|
|
24
|
-
"SIGQUIT",
|
|
25
|
-
"SIGIOT"
|
|
26
|
-
// should detect profiler and enable/disable accordingly.
|
|
27
|
-
// see #21
|
|
28
|
-
// 'SIGPROF'
|
|
29
|
-
);
|
|
30
|
-
if (process.platform === "linux") signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");
|
|
31
|
-
|
|
32
|
-
//#endregion
|
|
33
|
-
//#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.js
|
|
34
|
-
const processOk = (process$3) => !!process$3 && typeof process$3 === "object" && typeof process$3.removeListener === "function" && typeof process$3.emit === "function" && typeof process$3.reallyExit === "function" && typeof process$3.listeners === "function" && typeof process$3.kill === "function" && typeof process$3.pid === "number" && typeof process$3.on === "function";
|
|
35
|
-
const kExitEmitter = Symbol.for("signal-exit emitter");
|
|
36
|
-
const global = globalThis;
|
|
37
|
-
const ObjectDefineProperty = Object.defineProperty.bind(Object);
|
|
38
|
-
var Emitter = class {
|
|
39
|
-
emitted = {
|
|
40
|
-
afterExit: false,
|
|
41
|
-
exit: false
|
|
42
|
-
};
|
|
43
|
-
listeners = {
|
|
44
|
-
afterExit: [],
|
|
45
|
-
exit: []
|
|
46
|
-
};
|
|
47
|
-
count = 0;
|
|
48
|
-
id = Math.random();
|
|
49
|
-
constructor() {
|
|
50
|
-
if (global[kExitEmitter]) return global[kExitEmitter];
|
|
51
|
-
ObjectDefineProperty(global, kExitEmitter, {
|
|
52
|
-
value: this,
|
|
53
|
-
writable: false,
|
|
54
|
-
enumerable: false,
|
|
55
|
-
configurable: false
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
on(ev, fn) {
|
|
59
|
-
this.listeners[ev].push(fn);
|
|
60
|
-
}
|
|
61
|
-
removeListener(ev, fn) {
|
|
62
|
-
const list = this.listeners[ev];
|
|
63
|
-
const i$1 = list.indexOf(fn);
|
|
64
|
-
if (i$1 === -1) return;
|
|
65
|
-
if (i$1 === 0 && list.length === 1) list.length = 0;
|
|
66
|
-
else list.splice(i$1, 1);
|
|
67
|
-
}
|
|
68
|
-
emit(ev, code, signal) {
|
|
69
|
-
if (this.emitted[ev]) return false;
|
|
70
|
-
this.emitted[ev] = true;
|
|
71
|
-
let ret = false;
|
|
72
|
-
for (const fn of this.listeners[ev]) ret = fn(code, signal) === true || ret;
|
|
73
|
-
if (ev === "exit") ret = this.emit("afterExit", code, signal) || ret;
|
|
74
|
-
return ret;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
var SignalExitBase = class {};
|
|
78
|
-
const signalExitWrap = (handler) => {
|
|
79
|
-
return {
|
|
80
|
-
onExit(cb, opts) {
|
|
81
|
-
return handler.onExit(cb, opts);
|
|
82
|
-
},
|
|
83
|
-
load() {
|
|
84
|
-
return handler.load();
|
|
85
|
-
},
|
|
86
|
-
unload() {
|
|
87
|
-
return handler.unload();
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
var SignalExitFallback = class extends SignalExitBase {
|
|
92
|
-
onExit() {
|
|
93
|
-
return () => {};
|
|
94
|
-
}
|
|
95
|
-
load() {}
|
|
96
|
-
unload() {}
|
|
97
|
-
};
|
|
98
|
-
var SignalExit = class extends SignalExitBase {
|
|
99
|
-
#hupSig = process$2.platform === "win32" ? "SIGINT" : "SIGHUP";
|
|
100
|
-
#emitter = new Emitter();
|
|
101
|
-
#process;
|
|
102
|
-
#originalProcessEmit;
|
|
103
|
-
#originalProcessReallyExit;
|
|
104
|
-
#sigListeners = {};
|
|
105
|
-
#loaded = false;
|
|
106
|
-
constructor(process$3) {
|
|
107
|
-
super();
|
|
108
|
-
this.#process = process$3;
|
|
109
|
-
this.#sigListeners = {};
|
|
110
|
-
for (const sig of signals) this.#sigListeners[sig] = () => {
|
|
111
|
-
const listeners = this.#process.listeners(sig);
|
|
112
|
-
let { count } = this.#emitter;
|
|
113
|
-
const p = process$3;
|
|
114
|
-
if (typeof p.__signal_exit_emitter__ === "object" && typeof p.__signal_exit_emitter__.count === "number") count += p.__signal_exit_emitter__.count;
|
|
115
|
-
if (listeners.length === count) {
|
|
116
|
-
this.unload();
|
|
117
|
-
const ret = this.#emitter.emit("exit", null, sig);
|
|
118
|
-
const s$1 = sig === "SIGHUP" ? this.#hupSig : sig;
|
|
119
|
-
if (!ret) process$3.kill(process$3.pid, s$1);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
this.#originalProcessReallyExit = process$3.reallyExit;
|
|
123
|
-
this.#originalProcessEmit = process$3.emit;
|
|
124
|
-
}
|
|
125
|
-
onExit(cb, opts) {
|
|
126
|
-
if (!processOk(this.#process)) return () => {};
|
|
127
|
-
if (this.#loaded === false) this.load();
|
|
128
|
-
const ev = opts?.alwaysLast ? "afterExit" : "exit";
|
|
129
|
-
this.#emitter.on(ev, cb);
|
|
130
|
-
return () => {
|
|
131
|
-
this.#emitter.removeListener(ev, cb);
|
|
132
|
-
if (this.#emitter.listeners["exit"].length === 0 && this.#emitter.listeners["afterExit"].length === 0) this.unload();
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
load() {
|
|
136
|
-
if (this.#loaded) return;
|
|
137
|
-
this.#loaded = true;
|
|
138
|
-
this.#emitter.count += 1;
|
|
139
|
-
for (const sig of signals) try {
|
|
140
|
-
const fn = this.#sigListeners[sig];
|
|
141
|
-
if (fn) this.#process.on(sig, fn);
|
|
142
|
-
} catch (_$1) {}
|
|
143
|
-
this.#process.emit = (ev, ...a$1) => {
|
|
144
|
-
return this.#processEmit(ev, ...a$1);
|
|
145
|
-
};
|
|
146
|
-
this.#process.reallyExit = (code) => {
|
|
147
|
-
return this.#processReallyExit(code);
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
unload() {
|
|
151
|
-
if (!this.#loaded) return;
|
|
152
|
-
this.#loaded = false;
|
|
153
|
-
signals.forEach((sig) => {
|
|
154
|
-
const listener = this.#sigListeners[sig];
|
|
155
|
-
if (!listener) throw new Error("Listener not defined for signal: " + sig);
|
|
156
|
-
try {
|
|
157
|
-
this.#process.removeListener(sig, listener);
|
|
158
|
-
} catch (_$1) {}
|
|
159
|
-
});
|
|
160
|
-
this.#process.emit = this.#originalProcessEmit;
|
|
161
|
-
this.#process.reallyExit = this.#originalProcessReallyExit;
|
|
162
|
-
this.#emitter.count -= 1;
|
|
163
|
-
}
|
|
164
|
-
#processReallyExit(code) {
|
|
165
|
-
if (!processOk(this.#process)) return 0;
|
|
166
|
-
this.#process.exitCode = code || 0;
|
|
167
|
-
this.#emitter.emit("exit", this.#process.exitCode, null);
|
|
168
|
-
return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode);
|
|
169
|
-
}
|
|
170
|
-
#processEmit(ev, ...args) {
|
|
171
|
-
const og = this.#originalProcessEmit;
|
|
172
|
-
if (ev === "exit" && processOk(this.#process)) {
|
|
173
|
-
if (typeof args[0] === "number") this.#process.exitCode = args[0];
|
|
174
|
-
const ret = og.call(this.#process, ev, ...args);
|
|
175
|
-
this.#emitter.emit("exit", this.#process.exitCode, null);
|
|
176
|
-
return ret;
|
|
177
|
-
} else return og.call(this.#process, ev, ...args);
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
const process$2 = globalThis.process;
|
|
181
|
-
const { onExit, load, unload } = signalExitWrap(processOk(process$2) ? new SignalExit(process$2) : new SignalExitFallback());
|
|
14
|
+
import { performance } from "node:perf_hooks";
|
|
182
15
|
|
|
183
|
-
//#endregion
|
|
184
16
|
//#region ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/core.mjs
|
|
185
17
|
const LogLevels = {
|
|
186
18
|
silent: Number.NEGATIVE_INFINITY,
|
|
@@ -570,12 +402,10 @@ function createConsola$1(options$1 = {}) {
|
|
|
570
402
|
//#region ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs
|
|
571
403
|
function parseStack(stack, message) {
|
|
572
404
|
const cwd$1 = process.cwd() + sep;
|
|
573
|
-
|
|
574
|
-
return lines;
|
|
405
|
+
return stack.split("\n").splice(message.split("\n").length).map((l$1) => l$1.trim().replace("file://", "").replace(cwd$1, ""));
|
|
575
406
|
}
|
|
576
407
|
function writeStream(data, stream) {
|
|
577
|
-
|
|
578
|
-
return write.call(stream, data);
|
|
408
|
+
return (stream.__write || stream.write).call(stream, data);
|
|
579
409
|
}
|
|
580
410
|
const bracket = (x) => x ? `[${x}]` : "";
|
|
581
411
|
var BasicReporter = class {
|
|
@@ -596,11 +426,10 @@ ${indent}`);
|
|
|
596
426
|
return causedPrefix + message + "\n" + stack + causedError;
|
|
597
427
|
}
|
|
598
428
|
formatArgs(args, opts) {
|
|
599
|
-
|
|
429
|
+
return formatWithOptions(opts, ...args.map((arg) => {
|
|
600
430
|
if (arg && typeof arg.stack === "string") return this.formatError(arg, opts);
|
|
601
431
|
return arg;
|
|
602
|
-
});
|
|
603
|
-
return formatWithOptions(opts, ..._args);
|
|
432
|
+
}));
|
|
604
433
|
}
|
|
605
434
|
formatDate(date, opts) {
|
|
606
435
|
return opts.date ? date.toLocaleTimeString() : "";
|
|
@@ -622,23 +451,22 @@ ${indent}`);
|
|
|
622
451
|
]);
|
|
623
452
|
}
|
|
624
453
|
log(logObj, ctx) {
|
|
625
|
-
|
|
454
|
+
return writeStream(this.formatLogObj(logObj, {
|
|
626
455
|
columns: ctx.options.stdout.columns || 0,
|
|
627
456
|
...ctx.options.formatOptions
|
|
628
|
-
});
|
|
629
|
-
return writeStream(line + "\n", logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout);
|
|
457
|
+
}) + "\n", logObj.level < 2 ? ctx.options.stderr || process.stderr : ctx.options.stdout || process.stdout);
|
|
630
458
|
}
|
|
631
459
|
};
|
|
632
460
|
|
|
633
461
|
//#endregion
|
|
634
462
|
//#region ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs
|
|
635
|
-
const { env
|
|
636
|
-
const isDisabled = "NO_COLOR" in env
|
|
637
|
-
const isForced = "FORCE_COLOR" in env
|
|
463
|
+
const { env = {}, argv = [], platform = "" } = typeof process === "undefined" ? {} : process;
|
|
464
|
+
const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
|
|
465
|
+
const isForced = "FORCE_COLOR" in env || argv.includes("--color");
|
|
638
466
|
const isWindows = platform === "win32";
|
|
639
|
-
const isDumbTerminal = env
|
|
640
|
-
const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env
|
|
641
|
-
const isCI = "CI" in env
|
|
467
|
+
const isDumbTerminal = env.TERM === "dumb";
|
|
468
|
+
const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal;
|
|
469
|
+
const isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
|
|
642
470
|
const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
|
|
643
471
|
function replaceClose(index, string, close, replace, head = string.slice(0, Math.max(0, index)) + replace, tail = string.slice(Math.max(0, index + close.length)), next = tail.indexOf(close)) {
|
|
644
472
|
return head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
|
|
@@ -698,9 +526,9 @@ const colorDefs = {
|
|
|
698
526
|
function createColors(useColor = isColorSupported) {
|
|
699
527
|
return useColor ? colorDefs : Object.fromEntries(Object.keys(colorDefs).map((key) => [key, String]));
|
|
700
528
|
}
|
|
701
|
-
const colors
|
|
529
|
+
const colors = createColors();
|
|
702
530
|
function getColor$1(color, fallback = "reset") {
|
|
703
|
-
return colors
|
|
531
|
+
return colors[color] || colors[fallback];
|
|
704
532
|
}
|
|
705
533
|
const ansiRegex$1 = [String.raw`[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)`, String.raw`(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))`].join("|");
|
|
706
534
|
function stripAnsi$1(text) {
|
|
@@ -822,21 +650,20 @@ function box(text, _opts = {}) {
|
|
|
822
650
|
//#endregion
|
|
823
651
|
//#region ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/index.mjs
|
|
824
652
|
const r = Object.create(null), i = (e) => globalThis.process?.env || import.meta.env || globalThis.Deno?.env.toObject() || globalThis.__env__ || (e ? r : globalThis), o = new Proxy(r, {
|
|
825
|
-
get(e, s
|
|
826
|
-
return i()[s
|
|
653
|
+
get(e, s) {
|
|
654
|
+
return i()[s] ?? r[s];
|
|
827
655
|
},
|
|
828
|
-
has(e, s
|
|
829
|
-
|
|
830
|
-
return s$1 in E || s$1 in r;
|
|
656
|
+
has(e, s) {
|
|
657
|
+
return s in i() || s in r;
|
|
831
658
|
},
|
|
832
|
-
set(e, s
|
|
659
|
+
set(e, s, E) {
|
|
833
660
|
const B = i(true);
|
|
834
|
-
return B[s
|
|
661
|
+
return B[s] = E, true;
|
|
835
662
|
},
|
|
836
|
-
deleteProperty(e, s
|
|
837
|
-
if (!s
|
|
663
|
+
deleteProperty(e, s) {
|
|
664
|
+
if (!s) return false;
|
|
838
665
|
const E = i(true);
|
|
839
|
-
return delete E[s
|
|
666
|
+
return delete E[s], true;
|
|
840
667
|
},
|
|
841
668
|
ownKeys() {
|
|
842
669
|
const e = i(true);
|
|
@@ -935,8 +762,8 @@ const r = Object.create(null), i = (e) => globalThis.process?.env || import.meta
|
|
|
935
762
|
];
|
|
936
763
|
function b() {
|
|
937
764
|
if (globalThis.process?.env) for (const e of f) {
|
|
938
|
-
const s
|
|
939
|
-
if (globalThis.process?.env[s
|
|
765
|
+
const s = e[1] || e[0];
|
|
766
|
+
if (globalThis.process?.env[s]) return {
|
|
940
767
|
name: e[0].toLowerCase(),
|
|
941
768
|
...e[2]
|
|
942
769
|
};
|
|
@@ -961,10 +788,10 @@ const A = /^win/i.test(I);
|
|
|
961
788
|
const C = (globalThis.process?.versions?.node || "").replace(/^v/, "") || null;
|
|
962
789
|
Number(C?.split(".")[0]);
|
|
963
790
|
const y = globalThis.process || Object.create(null), _ = { versions: {} };
|
|
964
|
-
new Proxy(y, { get(e, s
|
|
965
|
-
if (s
|
|
966
|
-
if (s
|
|
967
|
-
if (s
|
|
791
|
+
new Proxy(y, { get(e, s) {
|
|
792
|
+
if (s === "env") return o;
|
|
793
|
+
if (s in e) return e[s];
|
|
794
|
+
if (s in _) return _[s];
|
|
968
795
|
} });
|
|
969
796
|
const c = globalThis.process?.release?.name === "node", O = !!globalThis.Bun || !!globalThis.process?.versions?.bun, D = !!globalThis.Deno, L = !!globalThis.fastly, S = !!globalThis.Netlify, u = !!globalThis.EdgeRuntime, N = globalThis.navigator?.userAgent === "Cloudflare-Workers", F = [
|
|
970
797
|
[S, "netlify"],
|
|
@@ -976,14 +803,12 @@ const c = globalThis.process?.release?.name === "node", O = !!globalThis.Bun ||
|
|
|
976
803
|
[c, "node"]
|
|
977
804
|
];
|
|
978
805
|
function G() {
|
|
979
|
-
const e = F.find((s
|
|
806
|
+
const e = F.find((s) => s[0]);
|
|
980
807
|
if (e) return { name: e[1] };
|
|
981
808
|
}
|
|
982
|
-
|
|
983
|
-
P?.name;
|
|
809
|
+
G()?.name;
|
|
984
810
|
function ansiRegex({ onlyFirst = false } = {}) {
|
|
985
|
-
const
|
|
986
|
-
const pattern = [`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?${ST})`, "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");
|
|
811
|
+
const pattern = [`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))`, "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");
|
|
987
812
|
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
988
813
|
}
|
|
989
814
|
const regex = ansiRegex();
|
|
@@ -1037,10 +862,10 @@ function stringWidth$1(string, options$1 = {}) {
|
|
|
1037
862
|
return width;
|
|
1038
863
|
}
|
|
1039
864
|
function isUnicodeSupported() {
|
|
1040
|
-
const { env: env$
|
|
1041
|
-
const { TERM, TERM_PROGRAM } = env$
|
|
865
|
+
const { env: env$1 } = process$1;
|
|
866
|
+
const { TERM, TERM_PROGRAM } = env$1;
|
|
1042
867
|
if (process$1.platform !== "win32") return TERM !== "linux";
|
|
1043
|
-
return Boolean(env$
|
|
868
|
+
return Boolean(env$1.WT_SESSION) || Boolean(env$1.TERMINUS_SUBLIME) || env$1.ConEmuTask === "{cmd::Cmder}" || TERM_PROGRAM === "Terminus-Sublime" || TERM_PROGRAM === "vscode" || TERM === "xterm-256color" || TERM === "alacritty" || TERM === "rxvt-unicode" || TERM === "rxvt-unicode-256color" || env$1.TERMINAL_EMULATOR === "JetBrains-JediTerm";
|
|
1044
869
|
}
|
|
1045
870
|
const TYPE_COLOR_MAP = {
|
|
1046
871
|
info: "cyan",
|
|
@@ -1054,7 +879,7 @@ const LEVEL_COLOR_MAP = {
|
|
|
1054
879
|
1: "yellow"
|
|
1055
880
|
};
|
|
1056
881
|
const unicode = isUnicodeSupported();
|
|
1057
|
-
const s = (c
|
|
882
|
+
const s = (c, fallback) => unicode ? c : fallback;
|
|
1058
883
|
const TYPE_ICONS = {
|
|
1059
884
|
error: s("✖", "×"),
|
|
1060
885
|
fatal: s("✖", "×"),
|
|
@@ -1069,20 +894,19 @@ const TYPE_ICONS = {
|
|
|
1069
894
|
log: ""
|
|
1070
895
|
};
|
|
1071
896
|
function stringWidth(str) {
|
|
1072
|
-
|
|
1073
|
-
if (!hasICU || !Intl.Segmenter) return stripAnsi$1(str).length;
|
|
897
|
+
if (!(typeof Intl === "object") || !Intl.Segmenter) return stripAnsi$1(str).length;
|
|
1074
898
|
return stringWidth$1(str);
|
|
1075
899
|
}
|
|
1076
900
|
var FancyReporter = class extends BasicReporter {
|
|
1077
901
|
formatStack(stack, message, opts) {
|
|
1078
902
|
const indent = " ".repeat((opts?.errorLevel || 0) + 1);
|
|
1079
903
|
return `
|
|
1080
|
-
${indent}` + parseStack(stack, message).map((line) => " " + line.replace(/^at +/, (m) => colors
|
|
904
|
+
${indent}` + parseStack(stack, message).map((line) => " " + line.replace(/^at +/, (m) => colors.gray(m)).replace(/\((.+)\)/, (_, m) => `(${colors.cyan(m)})`)).join(`
|
|
1081
905
|
${indent}`);
|
|
1082
906
|
}
|
|
1083
907
|
formatType(logObj, isBadge, opts) {
|
|
1084
908
|
const typeColor = TYPE_COLOR_MAP[logObj.type] || LEVEL_COLOR_MAP[logObj.level] || "gray";
|
|
1085
|
-
if (isBadge) return getBgColor(typeColor)(colors
|
|
909
|
+
if (isBadge) return getBgColor(typeColor)(colors.black(` ${logObj.type.toUpperCase()} `));
|
|
1086
910
|
const _type = typeof TYPE_ICONS[logObj.type] === "string" ? TYPE_ICONS[logObj.type] : logObj.icon || logObj.type;
|
|
1087
911
|
return _type ? getColor(typeColor)(_type) : "";
|
|
1088
912
|
}
|
|
@@ -1093,45 +917,44 @@ ${indent}`);
|
|
|
1093
917
|
style: logObj.style
|
|
1094
918
|
});
|
|
1095
919
|
const date = this.formatDate(logObj.date, opts);
|
|
1096
|
-
const coloredDate = date && colors
|
|
920
|
+
const coloredDate = date && colors.gray(date);
|
|
1097
921
|
const isBadge = logObj.badge ?? logObj.level < 2;
|
|
1098
922
|
const type = this.formatType(logObj, isBadge, opts);
|
|
1099
|
-
const tag = logObj.tag ? colors
|
|
923
|
+
const tag = logObj.tag ? colors.gray(logObj.tag) : "";
|
|
1100
924
|
let line;
|
|
1101
925
|
const left = this.filterAndJoin([type, characterFormat(message)]);
|
|
1102
926
|
const right = this.filterAndJoin(opts.columns ? [tag, coloredDate] : [tag]);
|
|
1103
927
|
const space = (opts.columns || 0) - stringWidth(left) - stringWidth(right) - 2;
|
|
1104
|
-
line = space > 0 && (opts.columns || 0) >= 80 ? left + " ".repeat(space) + right : (right ? `${colors
|
|
928
|
+
line = space > 0 && (opts.columns || 0) >= 80 ? left + " ".repeat(space) + right : (right ? `${colors.gray(`[${right}]`)} ` : "") + left;
|
|
1105
929
|
line += characterFormat(additional.length > 0 ? "\n" + additional.join("\n") : "");
|
|
1106
930
|
if (logObj.type === "trace") {
|
|
1107
|
-
const _err = new Error("Trace: " + logObj.message);
|
|
931
|
+
const _err = /* @__PURE__ */ new Error("Trace: " + logObj.message);
|
|
1108
932
|
line += this.formatStack(_err.stack || "", _err.message);
|
|
1109
933
|
}
|
|
1110
934
|
return isBadge ? "\n" + line + "\n" : line;
|
|
1111
935
|
}
|
|
1112
936
|
};
|
|
1113
937
|
function characterFormat(str) {
|
|
1114
|
-
return str.replace(/`([^`]+)`/gm, (_
|
|
938
|
+
return str.replace(/`([^`]+)`/gm, (_, m) => colors.cyan(m)).replace(/\s+_([^_]+)_\s+/gm, (_, m) => ` ${colors.underline(m)} `);
|
|
1115
939
|
}
|
|
1116
940
|
function getColor(color = "white") {
|
|
1117
|
-
return colors
|
|
941
|
+
return colors[color] || colors.white;
|
|
1118
942
|
}
|
|
1119
943
|
function getBgColor(color = "bgWhite") {
|
|
1120
|
-
return colors
|
|
944
|
+
return colors[`bg${color[0].toUpperCase()}${color.slice(1)}`] || colors.bgWhite;
|
|
1121
945
|
}
|
|
1122
946
|
function createConsola(options$1 = {}) {
|
|
1123
947
|
let level = _getDefaultLogLevel();
|
|
1124
948
|
if (process.env.CONSOLA_LEVEL) level = Number.parseInt(process.env.CONSOLA_LEVEL) ?? level;
|
|
1125
|
-
|
|
949
|
+
return createConsola$1({
|
|
1126
950
|
level,
|
|
1127
951
|
defaults: { level },
|
|
1128
952
|
stdout: process.stdout,
|
|
1129
953
|
stderr: process.stderr,
|
|
1130
|
-
prompt: (...args) => import("
|
|
954
|
+
prompt: (...args) => import("./shared/prompt-5sWCM0jm.mjs").then((m) => m.prompt(...args)),
|
|
1131
955
|
reporters: options$1.reporters || [options$1.fancy ?? !(T || R) ? new FancyReporter() : new BasicReporter()],
|
|
1132
956
|
...options$1
|
|
1133
957
|
});
|
|
1134
|
-
return consola2;
|
|
1135
958
|
}
|
|
1136
959
|
function _getDefaultLogLevel() {
|
|
1137
960
|
if (g) return LogLevels.debug;
|
|
@@ -1142,6 +965,9 @@ const consola = createConsola();
|
|
|
1142
965
|
|
|
1143
966
|
//#endregion
|
|
1144
967
|
//#region src/cli/logger.ts
|
|
968
|
+
/**
|
|
969
|
+
* Console logger
|
|
970
|
+
*/
|
|
1145
971
|
const logger = process.env.ROLLDOWN_TEST ? createTestingLogger() : createConsola({ formatOptions: { date: false } });
|
|
1146
972
|
function createTestingLogger() {
|
|
1147
973
|
const types = [
|
|
@@ -1165,284 +991,6 @@ function createTestingLogger() {
|
|
|
1165
991
|
return ret;
|
|
1166
992
|
}
|
|
1167
993
|
|
|
1168
|
-
//#endregion
|
|
1169
|
-
//#region src/cli/load-config.ts
|
|
1170
|
-
async function bundleTsConfig(configFile, isEsm) {
|
|
1171
|
-
const dirnameVarName = "injected_original_dirname";
|
|
1172
|
-
const filenameVarName = "injected_original_filename";
|
|
1173
|
-
const importMetaUrlVarName = "injected_original_import_meta_url";
|
|
1174
|
-
const bundle = await rolldown({
|
|
1175
|
-
input: configFile,
|
|
1176
|
-
platform: "node",
|
|
1177
|
-
resolve: { mainFields: ["main"] },
|
|
1178
|
-
define: {
|
|
1179
|
-
__dirname: dirnameVarName,
|
|
1180
|
-
__filename: filenameVarName,
|
|
1181
|
-
"import.meta.url": importMetaUrlVarName,
|
|
1182
|
-
"import.meta.dirname": dirnameVarName,
|
|
1183
|
-
"import.meta.filename": filenameVarName
|
|
1184
|
-
},
|
|
1185
|
-
treeshake: false,
|
|
1186
|
-
external: [/^[\w@][^:]/],
|
|
1187
|
-
plugins: [{
|
|
1188
|
-
name: "inject-file-scope-variables",
|
|
1189
|
-
transform: {
|
|
1190
|
-
filter: { id: /\.[cm]?[jt]s$/ },
|
|
1191
|
-
async handler(code, id) {
|
|
1192
|
-
const injectValues = `const ${dirnameVarName} = ${JSON.stringify(path.dirname(id))};const ${filenameVarName} = ${JSON.stringify(id)};const ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(id).href)};`;
|
|
1193
|
-
return {
|
|
1194
|
-
code: injectValues + code,
|
|
1195
|
-
map: null
|
|
1196
|
-
};
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
}]
|
|
1200
|
-
});
|
|
1201
|
-
const outputDir = path.dirname(configFile);
|
|
1202
|
-
const result = await bundle.write({
|
|
1203
|
-
dir: outputDir,
|
|
1204
|
-
format: isEsm ? "esm" : "cjs",
|
|
1205
|
-
sourcemap: "inline",
|
|
1206
|
-
entryFileNames: `rolldown.config.[hash]${path.extname(configFile).replace("ts", "js")}`
|
|
1207
|
-
});
|
|
1208
|
-
const fileName = result.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
|
|
1209
|
-
return path.join(outputDir, fileName);
|
|
1210
|
-
}
|
|
1211
|
-
const SUPPORTED_JS_CONFIG_FORMATS = [
|
|
1212
|
-
".js",
|
|
1213
|
-
".mjs",
|
|
1214
|
-
".cjs"
|
|
1215
|
-
];
|
|
1216
|
-
const SUPPORTED_TS_CONFIG_FORMATS = [
|
|
1217
|
-
".ts",
|
|
1218
|
-
".mts",
|
|
1219
|
-
".cts"
|
|
1220
|
-
];
|
|
1221
|
-
const SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
|
|
1222
|
-
const DEFAULT_CONFIG_BASE = "rolldown.config";
|
|
1223
|
-
async function findConfigFileNameInCwd() {
|
|
1224
|
-
const filesInWorkingDirectory = new Set(await readdir(cwd()));
|
|
1225
|
-
for (const extension of SUPPORTED_CONFIG_FORMATS) {
|
|
1226
|
-
const fileName = `${DEFAULT_CONFIG_BASE}${extension}`;
|
|
1227
|
-
if (filesInWorkingDirectory.has(fileName)) return fileName;
|
|
1228
|
-
}
|
|
1229
|
-
throw new Error("No `rolldown.config` configuration file found.");
|
|
1230
|
-
}
|
|
1231
|
-
async function loadTsConfig(configFile) {
|
|
1232
|
-
const isEsm = isFilePathESM(configFile);
|
|
1233
|
-
const file = await bundleTsConfig(configFile, isEsm);
|
|
1234
|
-
try {
|
|
1235
|
-
return (await import(pathToFileURL(file).href)).default;
|
|
1236
|
-
} finally {
|
|
1237
|
-
fs.unlink(file, () => {});
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
function isFilePathESM(filePath) {
|
|
1241
|
-
if (/\.m[jt]s$/.test(filePath)) return true;
|
|
1242
|
-
else if (/\.c[jt]s$/.test(filePath)) return false;
|
|
1243
|
-
else {
|
|
1244
|
-
const pkg = findNearestPackageData(path.dirname(filePath));
|
|
1245
|
-
if (pkg) return pkg.type === "module";
|
|
1246
|
-
return false;
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
function findNearestPackageData(basedir) {
|
|
1250
|
-
while (basedir) {
|
|
1251
|
-
const pkgPath = path.join(basedir, "package.json");
|
|
1252
|
-
if (tryStatSync(pkgPath)?.isFile()) try {
|
|
1253
|
-
return JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
1254
|
-
} catch {}
|
|
1255
|
-
const nextBasedir = path.dirname(basedir);
|
|
1256
|
-
if (nextBasedir === basedir) break;
|
|
1257
|
-
basedir = nextBasedir;
|
|
1258
|
-
}
|
|
1259
|
-
return null;
|
|
1260
|
-
}
|
|
1261
|
-
function tryStatSync(file) {
|
|
1262
|
-
try {
|
|
1263
|
-
return fs.statSync(file, { throwIfNoEntry: false });
|
|
1264
|
-
} catch {}
|
|
1265
|
-
}
|
|
1266
|
-
async function loadConfig(configPath) {
|
|
1267
|
-
const ext = path.extname(configPath = configPath || await findConfigFileNameInCwd());
|
|
1268
|
-
try {
|
|
1269
|
-
if (SUPPORTED_JS_CONFIG_FORMATS.includes(ext) || process.env.NODE_OPTIONS?.includes("--import=tsx") && SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return (await import(pathToFileURL(configPath).href)).default;
|
|
1270
|
-
else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) {
|
|
1271
|
-
const rawConfigPath = path.resolve(configPath);
|
|
1272
|
-
return await loadTsConfig(rawConfigPath);
|
|
1273
|
-
} else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
|
|
1274
|
-
} catch (err) {
|
|
1275
|
-
throw new Error("Error happened while loading config.", { cause: err });
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
//#endregion
|
|
1280
|
-
//#region src/cli/commands/bundle.ts
|
|
1281
|
-
async function bundleWithConfig(configPath, cliOptions) {
|
|
1282
|
-
const config = await loadConfig(configPath);
|
|
1283
|
-
if (!config) {
|
|
1284
|
-
logger.error(`No configuration found at ${config}`);
|
|
1285
|
-
process.exit(1);
|
|
1286
|
-
}
|
|
1287
|
-
if (cliOptions.watch) await watchInner(config, cliOptions);
|
|
1288
|
-
else await bundleInner(config, cliOptions);
|
|
1289
|
-
}
|
|
1290
|
-
async function bundleWithCliOptions(cliOptions) {
|
|
1291
|
-
if (cliOptions.output.dir || cliOptions.output.file) {
|
|
1292
|
-
const operation = cliOptions.watch ? watchInner : bundleInner;
|
|
1293
|
-
await operation({}, cliOptions);
|
|
1294
|
-
return;
|
|
1295
|
-
}
|
|
1296
|
-
if (cliOptions.watch) {
|
|
1297
|
-
logger.error("You must specify `output.dir` to use watch mode");
|
|
1298
|
-
process.exit(1);
|
|
1299
|
-
}
|
|
1300
|
-
const build = await rolldown(cliOptions.input);
|
|
1301
|
-
try {
|
|
1302
|
-
const { output: outputs } = await build.generate(cliOptions.output);
|
|
1303
|
-
if (outputs.length === 0) {
|
|
1304
|
-
logger.error("No output generated");
|
|
1305
|
-
process.exit(1);
|
|
1306
|
-
}
|
|
1307
|
-
for (const file of outputs) {
|
|
1308
|
-
if (outputs.length > 1) logger.log(`\n${colors.cyan(colors.bold(`|→ ${file.fileName}:`))}\n`);
|
|
1309
|
-
console.log(file.type === "asset" ? file.source : file.code);
|
|
1310
|
-
}
|
|
1311
|
-
} finally {
|
|
1312
|
-
await build.close();
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
async function watchInner(config, cliOptions) {
|
|
1316
|
-
let normalizedConfig = arraify(config).map((option) => {
|
|
1317
|
-
return {
|
|
1318
|
-
...option,
|
|
1319
|
-
...cliOptions.input,
|
|
1320
|
-
output: arraify(option.output || {}).map((output) => {
|
|
1321
|
-
return {
|
|
1322
|
-
...output,
|
|
1323
|
-
...cliOptions.output
|
|
1324
|
-
};
|
|
1325
|
-
})
|
|
1326
|
-
};
|
|
1327
|
-
});
|
|
1328
|
-
const watcher = await watch(normalizedConfig);
|
|
1329
|
-
onExit((code) => {
|
|
1330
|
-
Promise.resolve(watcher.close()).finally(() => {
|
|
1331
|
-
process.exit(typeof code === "number" ? code : 0);
|
|
1332
|
-
});
|
|
1333
|
-
return true;
|
|
1334
|
-
});
|
|
1335
|
-
const changedFile = [];
|
|
1336
|
-
watcher.on("change", (id, event) => {
|
|
1337
|
-
if (event.event === "update") changedFile.push(id);
|
|
1338
|
-
});
|
|
1339
|
-
watcher.on("event", (event) => {
|
|
1340
|
-
switch (event.code) {
|
|
1341
|
-
case "BUNDLE_START":
|
|
1342
|
-
if (changedFile.length > 0) logger.log(`Found ${colors.bold(changedFile.map(relativeId).join(", "))} changed, rebuilding...`);
|
|
1343
|
-
changedFile.length = 0;
|
|
1344
|
-
break;
|
|
1345
|
-
case "BUNDLE_END":
|
|
1346
|
-
logger.success(`Rebuilt ${colors.bold(relativeId(event.output[0]))} in ${colors.bold(ms(event.duration))}.`);
|
|
1347
|
-
break;
|
|
1348
|
-
case "ERROR":
|
|
1349
|
-
logger.error(event.error);
|
|
1350
|
-
break;
|
|
1351
|
-
default: break;
|
|
1352
|
-
}
|
|
1353
|
-
});
|
|
1354
|
-
logger.log(`Waiting for changes...`);
|
|
1355
|
-
}
|
|
1356
|
-
async function bundleInner(config, cliOptions) {
|
|
1357
|
-
const startTime = performance.now();
|
|
1358
|
-
const result = [];
|
|
1359
|
-
const configList = arraify(config);
|
|
1360
|
-
for (const config$1 of configList) {
|
|
1361
|
-
const outputList = arraify(config$1.output || {});
|
|
1362
|
-
const build = await rolldown({
|
|
1363
|
-
...config$1,
|
|
1364
|
-
...cliOptions.input
|
|
1365
|
-
});
|
|
1366
|
-
for (const output of outputList) try {
|
|
1367
|
-
result.push(await build.write({
|
|
1368
|
-
...output,
|
|
1369
|
-
...cliOptions.output
|
|
1370
|
-
}));
|
|
1371
|
-
} finally {
|
|
1372
|
-
await build.close();
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
result.forEach(printBundleOutputPretty);
|
|
1376
|
-
logger.log(``);
|
|
1377
|
-
const endTime = performance.now();
|
|
1378
|
-
const duration = endTime - startTime;
|
|
1379
|
-
logger.success(`Finished in ${colors.bold(ms(duration))}`);
|
|
1380
|
-
}
|
|
1381
|
-
function printBundleOutputPretty(output) {
|
|
1382
|
-
const outputEntries = collectOutputEntries(output.output);
|
|
1383
|
-
const outputLayoutSizes = collectOutputLayoutAdjustmentSizes(outputEntries);
|
|
1384
|
-
printOutputEntries(outputEntries, outputLayoutSizes, "<DIR>");
|
|
1385
|
-
}
|
|
1386
|
-
function collectOutputEntries(output) {
|
|
1387
|
-
return output.map((chunk) => ({
|
|
1388
|
-
type: chunk.type,
|
|
1389
|
-
fileName: chunk.fileName,
|
|
1390
|
-
size: chunk.type === "chunk" ? chunk.code.length : chunk.source.length
|
|
1391
|
-
}));
|
|
1392
|
-
}
|
|
1393
|
-
function collectOutputLayoutAdjustmentSizes(entries) {
|
|
1394
|
-
let longest = 0;
|
|
1395
|
-
let biggestSize = 0;
|
|
1396
|
-
for (const entry of entries) {
|
|
1397
|
-
if (entry.fileName.length > longest) longest = entry.fileName.length;
|
|
1398
|
-
if (entry.size > biggestSize) biggestSize = entry.size;
|
|
1399
|
-
}
|
|
1400
|
-
const sizePad = displaySize(biggestSize).length;
|
|
1401
|
-
return {
|
|
1402
|
-
longest,
|
|
1403
|
-
biggestSize,
|
|
1404
|
-
sizePad
|
|
1405
|
-
};
|
|
1406
|
-
}
|
|
1407
|
-
const numberFormatter = new Intl.NumberFormat("en", {
|
|
1408
|
-
maximumFractionDigits: 2,
|
|
1409
|
-
minimumFractionDigits: 2
|
|
1410
|
-
});
|
|
1411
|
-
function displaySize(bytes) {
|
|
1412
|
-
return `${numberFormatter.format(bytes / 1e3)} kB`;
|
|
1413
|
-
}
|
|
1414
|
-
const CHUNK_GROUPS = [{
|
|
1415
|
-
type: "asset",
|
|
1416
|
-
color: "green"
|
|
1417
|
-
}, {
|
|
1418
|
-
type: "chunk",
|
|
1419
|
-
color: "cyan"
|
|
1420
|
-
}];
|
|
1421
|
-
function printOutputEntries(entries, sizeAdjustment, distPath) {
|
|
1422
|
-
for (const group of CHUNK_GROUPS) {
|
|
1423
|
-
const filtered = entries.filter((e) => e.type === group.type);
|
|
1424
|
-
if (!filtered.length) continue;
|
|
1425
|
-
for (const entry of filtered.sort((a$1, z) => a$1.size - z.size)) {
|
|
1426
|
-
let log = colors.dim(withTrailingSlash(distPath));
|
|
1427
|
-
log += colors[group.color](entry.fileName.padEnd(sizeAdjustment.longest + 2));
|
|
1428
|
-
log += colors.dim(entry.type);
|
|
1429
|
-
log += colors.dim(` │ size: ${displaySize(entry.size).padStart(sizeAdjustment.sizePad)}`);
|
|
1430
|
-
logger.log(log);
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
|
-
function withTrailingSlash(path$1) {
|
|
1435
|
-
if (path$1[path$1.length - 1] !== "/") return `${path$1}/`;
|
|
1436
|
-
return path$1;
|
|
1437
|
-
}
|
|
1438
|
-
function ms(duration) {
|
|
1439
|
-
return duration < 1e3 ? `${duration.toFixed(2)} ms` : `${(duration / 1e3).toFixed(2)} s`;
|
|
1440
|
-
}
|
|
1441
|
-
function relativeId(id) {
|
|
1442
|
-
if (!path.isAbsolute(id)) return id;
|
|
1443
|
-
return path.relative(path.resolve(), id);
|
|
1444
|
-
}
|
|
1445
|
-
|
|
1446
994
|
//#endregion
|
|
1447
995
|
//#region src/cli/arguments/alias.ts
|
|
1448
996
|
const alias = {
|
|
@@ -1476,38 +1024,15 @@ const alias = {
|
|
|
1476
1024
|
default: true,
|
|
1477
1025
|
reverse: true
|
|
1478
1026
|
},
|
|
1027
|
+
preserveEntrySignatures: {
|
|
1028
|
+
default: "strict",
|
|
1029
|
+
reverse: true
|
|
1030
|
+
},
|
|
1479
1031
|
moduleTypes: { hint: "types" }
|
|
1480
1032
|
};
|
|
1481
1033
|
|
|
1482
1034
|
//#endregion
|
|
1483
1035
|
//#region src/cli/arguments/utils.ts
|
|
1484
|
-
const priority = [
|
|
1485
|
-
"object",
|
|
1486
|
-
"array",
|
|
1487
|
-
"string",
|
|
1488
|
-
"number",
|
|
1489
|
-
"boolean"
|
|
1490
|
-
];
|
|
1491
|
-
function getSchemaType(schema) {
|
|
1492
|
-
if ("anyOf" in schema) {
|
|
1493
|
-
const types = schema.anyOf.map(getSchemaType);
|
|
1494
|
-
let result = priority.find((type) => types.includes(type));
|
|
1495
|
-
if (result) return result;
|
|
1496
|
-
}
|
|
1497
|
-
if ("type" in schema) return schema.type;
|
|
1498
|
-
if ("const" in schema) return typeof schema.const;
|
|
1499
|
-
return "object";
|
|
1500
|
-
}
|
|
1501
|
-
function flattenSchema(schema, base = {}, parent = "") {
|
|
1502
|
-
if (schema === void 0) return base;
|
|
1503
|
-
for (const [k, value] of Object.entries(schema)) {
|
|
1504
|
-
const key = parent ? `${parent}.${k}` : k;
|
|
1505
|
-
if (getSchemaType(value) === "object") if ("properties" in value) flattenSchema(value.properties, base, key);
|
|
1506
|
-
else base[key] = value;
|
|
1507
|
-
else base[key] = value;
|
|
1508
|
-
}
|
|
1509
|
-
return base;
|
|
1510
|
-
}
|
|
1511
1036
|
function setNestedProperty(obj, path$1, value) {
|
|
1512
1037
|
const keys = path$1.split(".");
|
|
1513
1038
|
let current = obj;
|
|
@@ -1533,7 +1058,18 @@ function kebabCaseToCamelCase(str) {
|
|
|
1533
1058
|
//#endregion
|
|
1534
1059
|
//#region src/cli/arguments/normalize.ts
|
|
1535
1060
|
function normalizeCliOptions(cliOptions, positionals) {
|
|
1536
|
-
const
|
|
1061
|
+
const prototypePollutionKeys = [
|
|
1062
|
+
"__proto__",
|
|
1063
|
+
"constructor",
|
|
1064
|
+
"prototype"
|
|
1065
|
+
];
|
|
1066
|
+
const unflattenedCliOptions = {};
|
|
1067
|
+
for (let [key, value] of Object.entries(cliOptions)) if (prototypePollutionKeys.includes(key)) {} else if (key.includes(".")) {
|
|
1068
|
+
const [parentKey] = key.split(".");
|
|
1069
|
+
unflattenedCliOptions[parentKey] ??= {};
|
|
1070
|
+
setNestedProperty(unflattenedCliOptions, key, value);
|
|
1071
|
+
} else unflattenedCliOptions[key] = value;
|
|
1072
|
+
const [data, errors] = validateCliOptions(unflattenedCliOptions);
|
|
1537
1073
|
if (errors?.length) {
|
|
1538
1074
|
errors.forEach((error) => {
|
|
1539
1075
|
logger.error(`${error}. You can use \`rolldown -h\` to see the help.`);
|
|
@@ -1549,17 +1085,18 @@ function normalizeCliOptions(cliOptions, positionals) {
|
|
|
1549
1085
|
watch: options$1.watch ?? false
|
|
1550
1086
|
};
|
|
1551
1087
|
if (typeof options$1.config === "string") result.config = options$1.config;
|
|
1088
|
+
if (options$1.environment !== void 0) result.environment = options$1.environment;
|
|
1552
1089
|
const keysOfInput = getInputCliKeys();
|
|
1553
1090
|
const keysOfOutput = getOutputCliKeys();
|
|
1554
1091
|
const reservedKeys = [
|
|
1555
1092
|
"help",
|
|
1556
1093
|
"version",
|
|
1557
1094
|
"config",
|
|
1558
|
-
"watch"
|
|
1095
|
+
"watch",
|
|
1096
|
+
"environment"
|
|
1559
1097
|
];
|
|
1560
1098
|
for (let [key, value] of Object.entries(options$1)) {
|
|
1561
|
-
const
|
|
1562
|
-
const [primary] = keys;
|
|
1099
|
+
const [primary] = key.split(".");
|
|
1563
1100
|
if (keysOfInput.includes(primary)) setNestedProperty(result.input, key, value);
|
|
1564
1101
|
else if (keysOfOutput.includes(primary)) setNestedProperty(result.output, key, value);
|
|
1565
1102
|
else if (!reservedKeys.includes(key)) {
|
|
@@ -1567,25 +1104,26 @@ function normalizeCliOptions(cliOptions, positionals) {
|
|
|
1567
1104
|
process.exit(1);
|
|
1568
1105
|
}
|
|
1569
1106
|
}
|
|
1570
|
-
if (!result.config && positionals.length > 0) result.input.input
|
|
1107
|
+
if (!result.config && positionals.length > 0) if (Array.isArray(result.input.input)) result.input.input.push(...positionals);
|
|
1108
|
+
else result.input.input = positionals;
|
|
1571
1109
|
return result;
|
|
1572
1110
|
}
|
|
1573
1111
|
|
|
1574
1112
|
//#endregion
|
|
1575
1113
|
//#region src/cli/arguments/index.ts
|
|
1576
|
-
const
|
|
1577
|
-
const
|
|
1578
|
-
const options = Object.fromEntries(Object.entries(flattenedSchema).map(([key, schema]) => {
|
|
1114
|
+
const schemaInfo = getCliSchemaInfo();
|
|
1115
|
+
const options = Object.fromEntries(Object.entries(schemaInfo).filter(([_key, info]) => info.type !== "never").map(([key, info]) => {
|
|
1579
1116
|
const config = Object.getOwnPropertyDescriptor(alias, key)?.value;
|
|
1580
|
-
const type = getSchemaType(schema);
|
|
1581
1117
|
const result = {
|
|
1582
|
-
type: type === "boolean" ? "boolean" : "string",
|
|
1583
|
-
description:
|
|
1118
|
+
type: info.type === "boolean" ? "boolean" : "string",
|
|
1119
|
+
description: info?.description ?? config?.description ?? "",
|
|
1584
1120
|
hint: config?.hint
|
|
1585
1121
|
};
|
|
1586
1122
|
if (config && config?.abbreviation) result.short = config?.abbreviation;
|
|
1587
|
-
if (config && config.reverse)
|
|
1588
|
-
|
|
1123
|
+
if (config && config.reverse) {
|
|
1124
|
+
if (result.description.startsWith("enable")) result.description = result.description.replace("enable", "disable");
|
|
1125
|
+
else if (!result.description.startsWith("Avoid")) result.description = `disable ${result.description}`;
|
|
1126
|
+
}
|
|
1589
1127
|
key = camelCaseToKebabCase(key);
|
|
1590
1128
|
return [config?.reverse ? `no-${key}` : key, result];
|
|
1591
1129
|
}));
|
|
@@ -1596,11 +1134,11 @@ function parseCliArguments() {
|
|
|
1596
1134
|
allowPositionals: true,
|
|
1597
1135
|
strict: false
|
|
1598
1136
|
});
|
|
1599
|
-
tokens.filter((token) => token.kind === "option").
|
|
1137
|
+
let invalid_options = tokens.filter((token) => token.kind === "option").map((option) => {
|
|
1600
1138
|
let negative = false;
|
|
1601
1139
|
if (option.name.startsWith("no-")) {
|
|
1602
1140
|
const name = kebabCaseToCamelCase(option.name.substring(3));
|
|
1603
|
-
if (name in
|
|
1141
|
+
if (name in schemaInfo) {
|
|
1604
1142
|
delete values[option.name];
|
|
1605
1143
|
option.name = name;
|
|
1606
1144
|
negative = true;
|
|
@@ -1608,12 +1146,12 @@ function parseCliArguments() {
|
|
|
1608
1146
|
}
|
|
1609
1147
|
delete values[option.name];
|
|
1610
1148
|
option.name = kebabCaseToCamelCase(option.name);
|
|
1611
|
-
let
|
|
1612
|
-
if (!
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
}
|
|
1616
|
-
let type =
|
|
1149
|
+
let originalInfo = schemaInfo[option.name];
|
|
1150
|
+
if (!originalInfo) return {
|
|
1151
|
+
name: option.name,
|
|
1152
|
+
value: option.value
|
|
1153
|
+
};
|
|
1154
|
+
let type = originalInfo.type;
|
|
1617
1155
|
if (type === "string" && typeof option.value !== "string") {
|
|
1618
1156
|
let opt = option;
|
|
1619
1157
|
let defaultValue = Object.getOwnPropertyDescriptor(alias, opt.name)?.value;
|
|
@@ -1624,14 +1162,14 @@ function parseCliArguments() {
|
|
|
1624
1162
|
writable: true
|
|
1625
1163
|
});
|
|
1626
1164
|
} else if (type === "object" && typeof option.value === "string") {
|
|
1627
|
-
const
|
|
1165
|
+
const pairs = option.value.split(",").map((x) => x.split("="));
|
|
1628
1166
|
if (!values[option.name]) Object.defineProperty(values, option.name, {
|
|
1629
1167
|
value: {},
|
|
1630
1168
|
enumerable: true,
|
|
1631
1169
|
configurable: true,
|
|
1632
1170
|
writable: true
|
|
1633
1171
|
});
|
|
1634
|
-
if (key && value) Object.defineProperty(values[option.name], key, {
|
|
1172
|
+
for (const [key, value] of pairs) if (key && value) Object.defineProperty(values[option.name], key, {
|
|
1635
1173
|
value,
|
|
1636
1174
|
enumerable: true,
|
|
1637
1175
|
configurable: true,
|
|
@@ -1651,21 +1189,293 @@ function parseCliArguments() {
|
|
|
1651
1189
|
configurable: true,
|
|
1652
1190
|
writable: true
|
|
1653
1191
|
});
|
|
1654
|
-
else
|
|
1192
|
+
else if (type === "union") {
|
|
1193
|
+
let defaultValue = Object.getOwnPropertyDescriptor(alias, option.name)?.value;
|
|
1194
|
+
Object.defineProperty(values, option.name, {
|
|
1195
|
+
value: option.value ?? defaultValue?.default ?? "",
|
|
1196
|
+
enumerable: true,
|
|
1197
|
+
configurable: true,
|
|
1198
|
+
writable: true
|
|
1199
|
+
});
|
|
1200
|
+
} else Object.defineProperty(values, option.name, {
|
|
1655
1201
|
value: option.value ?? "",
|
|
1656
1202
|
enumerable: true,
|
|
1657
1203
|
configurable: true,
|
|
1658
1204
|
writable: true
|
|
1659
1205
|
});
|
|
1206
|
+
}).filter((item) => {
|
|
1207
|
+
return item !== void 0;
|
|
1208
|
+
});
|
|
1209
|
+
invalid_options.sort((a$1, b$1) => {
|
|
1210
|
+
return a$1.name.localeCompare(b$1.name);
|
|
1211
|
+
});
|
|
1212
|
+
if (invalid_options.length !== 0) {
|
|
1213
|
+
let single = invalid_options.length === 1;
|
|
1214
|
+
logger.warn(`Option \`${invalid_options.map((item) => item.name).join(",")}\` ${single ? "is" : "are"} unrecognized. We will ignore ${single ? "this" : "those"} option${single ? "" : "s"}.`);
|
|
1215
|
+
}
|
|
1216
|
+
let rawArgs = {
|
|
1217
|
+
...values,
|
|
1218
|
+
...invalid_options.reduce((acc, cur) => {
|
|
1219
|
+
acc[cur.name] = cur.value;
|
|
1220
|
+
return acc;
|
|
1221
|
+
}, Object.create(null))
|
|
1222
|
+
};
|
|
1223
|
+
return {
|
|
1224
|
+
...normalizeCliOptions(values, positionals),
|
|
1225
|
+
rawArgs
|
|
1226
|
+
};
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
//#endregion
|
|
1230
|
+
//#region src/utils/clear-screen.ts
|
|
1231
|
+
const CLEAR_SCREEN = "\x1Bc";
|
|
1232
|
+
function getClearScreenFunction(options$1) {
|
|
1233
|
+
const isTTY = process.stdout.isTTY;
|
|
1234
|
+
const isAnyOptionNotAllowingClearScreen = arraify(options$1).some(({ watch: watch$1 }) => watch$1 === false || watch$1?.clearScreen === false);
|
|
1235
|
+
if (isTTY && !isAnyOptionNotAllowingClearScreen) return () => {
|
|
1236
|
+
process.stdout.write(CLEAR_SCREEN);
|
|
1237
|
+
};
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
//#endregion
|
|
1241
|
+
//#region \0@oxc-project+runtime@0.108.0/helpers/usingCtx.js
|
|
1242
|
+
function _usingCtx() {
|
|
1243
|
+
var r$1 = "function" == typeof SuppressedError ? SuppressedError : function(r$2, e$1) {
|
|
1244
|
+
var n$2 = Error();
|
|
1245
|
+
return n$2.name = "SuppressedError", n$2.error = r$2, n$2.suppressed = e$1, n$2;
|
|
1246
|
+
}, e = {}, n$1 = [];
|
|
1247
|
+
function using(r$2, e$1) {
|
|
1248
|
+
if (null != e$1) {
|
|
1249
|
+
if (Object(e$1) !== e$1) throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
|
|
1250
|
+
if (r$2) var o$1 = e$1[Symbol.asyncDispose || Symbol["for"]("Symbol.asyncDispose")];
|
|
1251
|
+
if (void 0 === o$1 && (o$1 = e$1[Symbol.dispose || Symbol["for"]("Symbol.dispose")], r$2)) var t$1 = o$1;
|
|
1252
|
+
if ("function" != typeof o$1) throw new TypeError("Object is not disposable.");
|
|
1253
|
+
t$1 && (o$1 = function o$2() {
|
|
1254
|
+
try {
|
|
1255
|
+
t$1.call(e$1);
|
|
1256
|
+
} catch (r$3) {
|
|
1257
|
+
return Promise.reject(r$3);
|
|
1258
|
+
}
|
|
1259
|
+
}), n$1.push({
|
|
1260
|
+
v: e$1,
|
|
1261
|
+
d: o$1,
|
|
1262
|
+
a: r$2
|
|
1263
|
+
});
|
|
1264
|
+
} else r$2 && n$1.push({
|
|
1265
|
+
d: e$1,
|
|
1266
|
+
a: r$2
|
|
1267
|
+
});
|
|
1268
|
+
return e$1;
|
|
1269
|
+
}
|
|
1270
|
+
return {
|
|
1271
|
+
e,
|
|
1272
|
+
u: using.bind(null, !1),
|
|
1273
|
+
a: using.bind(null, !0),
|
|
1274
|
+
d: function d() {
|
|
1275
|
+
var o$1, t$1 = this.e, s$1 = 0;
|
|
1276
|
+
function next() {
|
|
1277
|
+
for (; o$1 = n$1.pop();) try {
|
|
1278
|
+
if (!o$1.a && 1 === s$1) return s$1 = 0, n$1.push(o$1), Promise.resolve().then(next);
|
|
1279
|
+
if (o$1.d) {
|
|
1280
|
+
var r$2 = o$1.d.call(o$1.v);
|
|
1281
|
+
if (o$1.a) return s$1 |= 2, Promise.resolve(r$2).then(next, err);
|
|
1282
|
+
} else s$1 |= 1;
|
|
1283
|
+
} catch (r$3) {
|
|
1284
|
+
return err(r$3);
|
|
1285
|
+
}
|
|
1286
|
+
if (1 === s$1) return t$1 !== e ? Promise.reject(t$1) : Promise.resolve();
|
|
1287
|
+
if (t$1 !== e) throw t$1;
|
|
1288
|
+
}
|
|
1289
|
+
function err(n$2) {
|
|
1290
|
+
return t$1 = t$1 !== e ? new r$1(n$2, t$1) : n$2, next();
|
|
1291
|
+
}
|
|
1292
|
+
return next();
|
|
1293
|
+
}
|
|
1294
|
+
};
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
//#endregion
|
|
1298
|
+
//#region src/cli/commands/bundle.ts
|
|
1299
|
+
async function bundleWithConfig(configPath, cliOptions, rawArgs = {}) {
|
|
1300
|
+
if (cliOptions.watch) {
|
|
1301
|
+
process.env.ROLLUP_WATCH = "true";
|
|
1302
|
+
process.env.ROLLDOWN_WATCH = "true";
|
|
1303
|
+
}
|
|
1304
|
+
const config = await loadConfig(configPath);
|
|
1305
|
+
const resolvedConfig = typeof config === "function" ? await config(rawArgs) : config;
|
|
1306
|
+
if (typeof resolvedConfig !== "object" || resolvedConfig === null) {
|
|
1307
|
+
logger.error(`Invalid configuration from ${configPath}: expected object or array, got ${resolvedConfig}`);
|
|
1308
|
+
process.exit(1);
|
|
1309
|
+
}
|
|
1310
|
+
if (cliOptions.watch) await watchInner(resolvedConfig, cliOptions);
|
|
1311
|
+
else await bundleInner(resolvedConfig, cliOptions);
|
|
1312
|
+
}
|
|
1313
|
+
async function bundleWithCliOptions(cliOptions) {
|
|
1314
|
+
try {
|
|
1315
|
+
var _usingCtx$1 = _usingCtx();
|
|
1316
|
+
if (cliOptions.output.dir || cliOptions.output.file) {
|
|
1317
|
+
await (cliOptions.watch ? watchInner : bundleInner)({}, cliOptions);
|
|
1318
|
+
return;
|
|
1319
|
+
}
|
|
1320
|
+
if (cliOptions.watch) {
|
|
1321
|
+
logger.error("You must specify `output.dir` to use watch mode");
|
|
1322
|
+
process.exit(1);
|
|
1323
|
+
}
|
|
1324
|
+
const { output: outputs } = await _usingCtx$1.a(await rolldown(cliOptions.input)).generate(cliOptions.output);
|
|
1325
|
+
if (outputs.length === 0) {
|
|
1326
|
+
logger.error("No output generated");
|
|
1327
|
+
process.exit(1);
|
|
1328
|
+
}
|
|
1329
|
+
for (const file of outputs) {
|
|
1330
|
+
if (outputs.length > 1) logger.log(`\n${styleText$1(["cyan", "bold"], `|→ ${file.fileName}:`)}\n`);
|
|
1331
|
+
console.log(file.type === "asset" ? file.source : file.code);
|
|
1332
|
+
}
|
|
1333
|
+
} catch (_$1) {
|
|
1334
|
+
_usingCtx$1.e = _$1;
|
|
1335
|
+
} finally {
|
|
1336
|
+
await _usingCtx$1.d();
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
async function watchInner(config, cliOptions) {
|
|
1340
|
+
let normalizedConfig = arraify(config).map((option) => {
|
|
1341
|
+
return {
|
|
1342
|
+
...option,
|
|
1343
|
+
...cliOptions.input,
|
|
1344
|
+
output: arraify(option.output || {}).map((output) => {
|
|
1345
|
+
return {
|
|
1346
|
+
...output,
|
|
1347
|
+
...cliOptions.output
|
|
1348
|
+
};
|
|
1349
|
+
})
|
|
1350
|
+
};
|
|
1351
|
+
});
|
|
1352
|
+
const watcher = watch(normalizedConfig);
|
|
1353
|
+
onExit((code) => {
|
|
1354
|
+
Promise.resolve(watcher.close()).finally(() => {
|
|
1355
|
+
process.exit(typeof code === "number" ? code : 0);
|
|
1356
|
+
});
|
|
1357
|
+
return true;
|
|
1358
|
+
});
|
|
1359
|
+
const changedFile = [];
|
|
1360
|
+
watcher.on("change", (id, event) => {
|
|
1361
|
+
if (event.event === "update") changedFile.push(id);
|
|
1362
|
+
});
|
|
1363
|
+
const clearScreen = getClearScreenFunction(normalizedConfig);
|
|
1364
|
+
watcher.on("event", async (event) => {
|
|
1365
|
+
switch (event.code) {
|
|
1366
|
+
case "START":
|
|
1367
|
+
clearScreen?.();
|
|
1368
|
+
break;
|
|
1369
|
+
case "BUNDLE_START":
|
|
1370
|
+
if (changedFile.length > 0) logger.log(`Found ${styleText$1("bold", changedFile.map(relativeId).join(", "))} changed, rebuilding...`);
|
|
1371
|
+
changedFile.length = 0;
|
|
1372
|
+
break;
|
|
1373
|
+
case "BUNDLE_END":
|
|
1374
|
+
await event.result.close();
|
|
1375
|
+
logger.success(`Rebuilt ${styleText$1("bold", relativeId(event.output[0]))} in ${styleText$1("green", ms(event.duration))}.`);
|
|
1376
|
+
break;
|
|
1377
|
+
case "ERROR":
|
|
1378
|
+
await event.result.close();
|
|
1379
|
+
logger.error(event.error);
|
|
1380
|
+
break;
|
|
1381
|
+
default: break;
|
|
1382
|
+
}
|
|
1660
1383
|
});
|
|
1661
|
-
|
|
1384
|
+
logger.log(`Waiting for changes...`);
|
|
1385
|
+
}
|
|
1386
|
+
async function bundleInner(config, cliOptions) {
|
|
1387
|
+
const startTime = performance.now();
|
|
1388
|
+
const result = [];
|
|
1389
|
+
const configList = arraify(config);
|
|
1390
|
+
for (const config$1 of configList) {
|
|
1391
|
+
const outputList = arraify(config$1.output || {});
|
|
1392
|
+
const build = await rolldown({
|
|
1393
|
+
...config$1,
|
|
1394
|
+
...cliOptions.input
|
|
1395
|
+
});
|
|
1396
|
+
try {
|
|
1397
|
+
for (const output of outputList) result.push(await build.write({
|
|
1398
|
+
...output,
|
|
1399
|
+
...cliOptions.output
|
|
1400
|
+
}));
|
|
1401
|
+
} finally {
|
|
1402
|
+
await build.close();
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
result.forEach(printBundleOutputPretty);
|
|
1406
|
+
logger.log(``);
|
|
1407
|
+
const duration = performance.now() - startTime;
|
|
1408
|
+
logger.success(`rolldown v${version} Finished in ${styleText$1("green", ms(duration))}`);
|
|
1409
|
+
}
|
|
1410
|
+
function printBundleOutputPretty(output) {
|
|
1411
|
+
const outputEntries = collectOutputEntries(output.output);
|
|
1412
|
+
printOutputEntries(outputEntries, collectOutputLayoutAdjustmentSizes(outputEntries), "<DIR>");
|
|
1413
|
+
}
|
|
1414
|
+
function collectOutputEntries(output) {
|
|
1415
|
+
return output.map((chunk) => ({
|
|
1416
|
+
type: chunk.type,
|
|
1417
|
+
fileName: chunk.fileName,
|
|
1418
|
+
size: chunk.type === "chunk" ? Buffer.byteLength(chunk.code) : Buffer.byteLength(chunk.source)
|
|
1419
|
+
}));
|
|
1420
|
+
}
|
|
1421
|
+
function collectOutputLayoutAdjustmentSizes(entries) {
|
|
1422
|
+
let longest = 0;
|
|
1423
|
+
let biggestSize = 0;
|
|
1424
|
+
for (const entry of entries) {
|
|
1425
|
+
if (entry.fileName.length > longest) longest = entry.fileName.length;
|
|
1426
|
+
if (entry.size > biggestSize) biggestSize = entry.size;
|
|
1427
|
+
}
|
|
1428
|
+
const sizePad = displaySize(biggestSize).length;
|
|
1429
|
+
return {
|
|
1430
|
+
longest,
|
|
1431
|
+
biggestSize,
|
|
1432
|
+
sizePad
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
const numberFormatter = new Intl.NumberFormat("en", {
|
|
1436
|
+
maximumFractionDigits: 2,
|
|
1437
|
+
minimumFractionDigits: 2
|
|
1438
|
+
});
|
|
1439
|
+
function displaySize(bytes) {
|
|
1440
|
+
return `${numberFormatter.format(bytes / 1e3)} kB`;
|
|
1441
|
+
}
|
|
1442
|
+
const CHUNK_GROUPS = [{
|
|
1443
|
+
type: "asset",
|
|
1444
|
+
color: "green"
|
|
1445
|
+
}, {
|
|
1446
|
+
type: "chunk",
|
|
1447
|
+
color: "cyan"
|
|
1448
|
+
}];
|
|
1449
|
+
function printOutputEntries(entries, sizeAdjustment, distPath) {
|
|
1450
|
+
for (const group of CHUNK_GROUPS) {
|
|
1451
|
+
const filtered = entries.filter((e) => e.type === group.type);
|
|
1452
|
+
if (!filtered.length) continue;
|
|
1453
|
+
for (const entry of filtered.sort((a$1, z) => a$1.size - z.size)) {
|
|
1454
|
+
let log = styleText$1("dim", withTrailingSlash(distPath));
|
|
1455
|
+
log += styleText$1(group.color, entry.fileName.padEnd(sizeAdjustment.longest + 2));
|
|
1456
|
+
log += styleText$1("dim", entry.type);
|
|
1457
|
+
log += styleText$1("dim", ` │ size: ${displaySize(entry.size).padStart(sizeAdjustment.sizePad)}`);
|
|
1458
|
+
logger.log(log);
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
function withTrailingSlash(path$1) {
|
|
1463
|
+
if (path$1[path$1.length - 1] !== "/") return `${path$1}/`;
|
|
1464
|
+
return path$1;
|
|
1465
|
+
}
|
|
1466
|
+
function ms(duration) {
|
|
1467
|
+
return duration < 1e3 ? `${duration.toFixed(2)} ms` : `${(duration / 1e3).toFixed(2)} s`;
|
|
1468
|
+
}
|
|
1469
|
+
function relativeId(id) {
|
|
1470
|
+
if (!path.isAbsolute(id)) return id;
|
|
1471
|
+
return path.relative(path.resolve(), id);
|
|
1662
1472
|
}
|
|
1663
1473
|
|
|
1664
1474
|
//#endregion
|
|
1665
1475
|
//#region src/cli/commands/help.ts
|
|
1666
|
-
const introduction = `${
|
|
1476
|
+
const introduction = `${styleText$1("gray", `${description} (rolldown v${version})`)}
|
|
1667
1477
|
|
|
1668
|
-
${
|
|
1478
|
+
${styleText$1(["bold", "underline"], "USAGE")} ${styleText$1("cyan", "rolldown -c <config>")} or ${styleText$1("cyan", "rolldown <input> <options>")}`;
|
|
1669
1479
|
const examples = [
|
|
1670
1480
|
{
|
|
1671
1481
|
title: "Bundle with a config file `rolldown.config.mjs`",
|
|
@@ -1697,7 +1507,7 @@ const notes = [
|
|
|
1697
1507
|
function showHelp() {
|
|
1698
1508
|
logger.log(introduction);
|
|
1699
1509
|
logger.log("");
|
|
1700
|
-
logger.log(`${
|
|
1510
|
+
logger.log(`${styleText$1(["bold", "underline"], "OPTIONS")}`);
|
|
1701
1511
|
logger.log("");
|
|
1702
1512
|
logger.log(Object.entries(options).sort(([a$1], [b$1]) => {
|
|
1703
1513
|
if (options[a$1].short && !options[b$1].short) return -1;
|
|
@@ -1710,29 +1520,46 @@ function showHelp() {
|
|
|
1710
1520
|
if (short) optionStr += `-${short}, `;
|
|
1711
1521
|
if (type === "string") optionStr += `<${hint ?? option}>`;
|
|
1712
1522
|
if (description$1 && description$1.length > 0) description$1 = description$1[0].toUpperCase() + description$1.slice(1);
|
|
1713
|
-
return
|
|
1523
|
+
return styleText$1("cyan", optionStr.padEnd(30)) + description$1 + (description$1 && description$1?.endsWith(".") ? "" : ".");
|
|
1714
1524
|
}).join("\n"));
|
|
1715
1525
|
logger.log("");
|
|
1716
|
-
logger.log(`${
|
|
1526
|
+
logger.log(`${styleText$1(["bold", "underline"], "EXAMPLES")}`);
|
|
1717
1527
|
logger.log("");
|
|
1718
1528
|
examples.forEach(({ title, command }, ord) => {
|
|
1719
1529
|
logger.log(` ${ord + 1}. ${title}:`);
|
|
1720
|
-
logger.log(` ${
|
|
1530
|
+
logger.log(` ${styleText$1("cyan", command)}`);
|
|
1721
1531
|
logger.log("");
|
|
1722
1532
|
});
|
|
1723
|
-
logger.log(`${
|
|
1533
|
+
logger.log(`${styleText$1(["bold", "underline"], "NOTES")}`);
|
|
1724
1534
|
logger.log("");
|
|
1725
1535
|
notes.forEach((note) => {
|
|
1726
|
-
logger.log(` * ${
|
|
1536
|
+
logger.log(` * ${styleText$1("gray", note)}`);
|
|
1727
1537
|
});
|
|
1728
1538
|
}
|
|
1729
1539
|
|
|
1540
|
+
//#endregion
|
|
1541
|
+
//#region src/cli/version-check.ts
|
|
1542
|
+
function checkNodeVersion(nodeVersion) {
|
|
1543
|
+
const currentVersion = nodeVersion.split(".");
|
|
1544
|
+
const major = parseInt(currentVersion[0], 10);
|
|
1545
|
+
const minor = parseInt(currentVersion[1], 10);
|
|
1546
|
+
return major === 20 && minor >= 19 || major === 22 && minor >= 12 || major > 22;
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1730
1549
|
//#endregion
|
|
1731
1550
|
//#region src/cli/index.ts
|
|
1551
|
+
if (!checkNodeVersion(process$1.versions.node)) logger.warn(`You are using Node.js ${process$1.versions.node}. Rolldown requires Node.js version 20.19+ or 22.12+. Please upgrade your Node.js version.`);
|
|
1732
1552
|
async function main() {
|
|
1733
|
-
const cliOptions = parseCliArguments();
|
|
1553
|
+
const { rawArgs, ...cliOptions } = parseCliArguments();
|
|
1554
|
+
if (cliOptions.environment) {
|
|
1555
|
+
const environment = Array.isArray(cliOptions.environment) ? cliOptions.environment : [cliOptions.environment];
|
|
1556
|
+
for (const argument of environment) for (const pair of argument.split(",")) {
|
|
1557
|
+
const [key, ...value] = pair.split(":");
|
|
1558
|
+
process$1.env[key] = value.length === 0 ? String(true) : value.join(":");
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1734
1561
|
if (cliOptions.config || cliOptions.config === "") {
|
|
1735
|
-
await bundleWithConfig(cliOptions.config, cliOptions);
|
|
1562
|
+
await bundleWithConfig(cliOptions.config, cliOptions, rawArgs);
|
|
1736
1563
|
return;
|
|
1737
1564
|
}
|
|
1738
1565
|
if ("input" in cliOptions.input) {
|
|
@@ -1750,4 +1577,5 @@ main().catch((err) => {
|
|
|
1750
1577
|
process$1.exit(1);
|
|
1751
1578
|
});
|
|
1752
1579
|
|
|
1753
|
-
//#endregion
|
|
1580
|
+
//#endregion
|
|
1581
|
+
export { };
|