rolldown 1.0.0-beta.1-commit.7c52c94 → 1.0.0-beta.10
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/bin/cli.mjs +2 -0
- package/dist/cli.cjs +1748 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +1745 -0
- package/dist/config.cjs +12 -0
- package/dist/config.d.cts +12 -0
- package/dist/config.d.mts +12 -0
- package/dist/config.mjs +10 -0
- package/dist/experimental-index.cjs +132 -0
- package/dist/experimental-index.d.cts +96 -0
- package/dist/experimental-index.d.mts +96 -0
- package/dist/experimental-index.mjs +91 -0
- package/dist/filter-index.cjs +105 -0
- package/dist/filter-index.d.cts +5 -0
- package/dist/filter-index.d.mts +5 -0
- package/dist/filter-index.mjs +44 -0
- package/dist/index.cjs +9 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +5 -0
- package/dist/{cjs/parallel-plugin-worker.cjs → parallel-plugin-worker.cjs} +7 -14
- package/dist/parallel-plugin-worker.d.cts +1 -0
- package/dist/parallel-plugin-worker.d.mts +1 -0
- package/dist/{esm/parallel-plugin-worker.mjs → parallel-plugin-worker.mjs} +5 -11
- package/dist/{cjs/parallel-plugin.cjs → parallel-plugin.cjs} +1 -2
- package/dist/parallel-plugin.d.cts +15 -0
- package/dist/parallel-plugin.d.mts +15 -0
- package/dist/{esm/parallel-plugin.mjs → parallel-plugin.mjs} +0 -1
- package/dist/parse-ast-index.cjs +4 -0
- package/dist/parse-ast-index.d.cts +9 -0
- package/dist/parse-ast-index.d.mts +9 -0
- package/dist/parse-ast-index.mjs +3 -0
- package/dist/shared/binding.d-Bl5Vi4GH.d.mts +1702 -0
- package/dist/shared/binding.d-DcFBMcjI.d.cts +1702 -0
- package/dist/shared/{chunk-qZFfknuJ.cjs → chunk-DDkG_k5U.cjs} +0 -1
- package/dist/shared/define-config.d-B2xOSmbM.d.cts +1082 -0
- package/dist/shared/define-config.d-USfUuKiR.d.mts +1082 -0
- package/dist/shared/load-config-D6gW8FDa.cjs +125 -0
- package/dist/shared/load-config-eyuttVHY.mjs +119 -0
- package/dist/shared/misc-BKp5iIef.cjs +67 -0
- package/dist/shared/misc-BN0nse6C.mjs +25 -0
- package/dist/shared/{binding-fhgdIkpS.cjs → parse-ast-index-BvK1MT-L.cjs} +347 -309
- package/dist/shared/{binding-Bl7VQy7c.mjs → parse-ast-index-PSQWLeSo.mjs} +334 -277
- package/dist/shared/prompt-8EeOGx1_.cjs +854 -0
- package/dist/shared/prompt-C3zHEaSG.mjs +852 -0
- package/dist/shared/src-C2v46mL8.cjs +4654 -0
- package/dist/shared/src-D-VRn8rI.mjs +4456 -0
- package/package.json +62 -61
- package/bin/cli.js +0 -2
- package/dist/cjs/cli.cjs +0 -769
- package/dist/cjs/experimental-index.cjs +0 -79
- package/dist/cjs/index.cjs +0 -8
- package/dist/cjs/parse-ast-index.cjs +0 -57
- package/dist/esm/cli.mjs +0 -766
- package/dist/esm/experimental-index.mjs +0 -56
- package/dist/esm/index.mjs +0 -4
- package/dist/esm/parse-ast-index.mjs +0 -55
- package/dist/shared/consola_36c0034f-Cx52UqEq.mjs +0 -832
- package/dist/shared/consola_36c0034f-CynBWXXO.cjs +0 -859
- package/dist/shared/prompt-B58MxVuU.cjs +0 -762
- package/dist/shared/prompt-DjjlOckE.mjs +0 -758
- package/dist/shared/src-CPCP99Z9.mjs +0 -2641
- package/dist/shared/src-lBcHSsjm.cjs +0 -2822
- package/dist/tsconfig.dts.tsbuildinfo +0 -1
- 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 -12
- 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 -1288
- package/dist/types/builtin-plugin/alias-plugin.d.ts +0 -10
- package/dist/types/builtin-plugin/constructors.d.ts +0 -20
- 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 -3
- 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 -28
- package/dist/types/log/logHandler.d.ts +0 -4
- package/dist/types/log/logger.d.ts +0 -6
- package/dist/types/log/logging.d.ts +0 -11
- package/dist/types/log/logs.d.ts +0 -18
- package/dist/types/options/input-options.d.ts +0 -125
- package/dist/types/options/normalized-input-options.d.ts +0 -18
- package/dist/types/options/normalized-output-options.d.ts +0 -67
- package/dist/types/options/output-options.d.ts +0 -80
- 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 -4
- 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 -15
- 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 -126
- package/dist/types/plugin/minimal-plugin-context.d.ts +0 -15
- 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 -16
- package/dist/types/plugin/plugin-context.d.ts +0 -52
- package/dist/types/plugin/plugin-driver.d.ts +0 -8
- package/dist/types/plugin/transform-plugin-context.d.ts +0 -17
- package/dist/types/types/assert.d.ts +0 -13
- 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 -10
- 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 -63
- package/dist/types/types/schema.d.ts +0 -33
- package/dist/types/types/sourcemap.d.ts +0 -13
- 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 -3
- 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 -8
- 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/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 -7
package/dist/cjs/cli.cjs
DELETED
|
@@ -1,769 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const require_chunk = require('../shared/chunk-qZFfknuJ.cjs');
|
|
3
|
-
const require_src = require('../shared/src-lBcHSsjm.cjs');
|
|
4
|
-
const require_binding = require('../shared/binding-fhgdIkpS.cjs');
|
|
5
|
-
const require_consola_36c0034f = require('../shared/consola_36c0034f-CynBWXXO.cjs');
|
|
6
|
-
const node_process = require_chunk.__toESM(require("node:process"));
|
|
7
|
-
const node_path = require_chunk.__toESM(require("node:path"));
|
|
8
|
-
const node_fs = require_chunk.__toESM(require("node:fs"));
|
|
9
|
-
const node_perf_hooks = require_chunk.__toESM(require("node:perf_hooks"));
|
|
10
|
-
const node_util = require_chunk.__toESM(require("node:util"));
|
|
11
|
-
const node_tty = require_chunk.__toESM(require("node:tty"));
|
|
12
|
-
const node_fs_promises = require_chunk.__toESM(require("node:fs/promises"));
|
|
13
|
-
const node_url = require_chunk.__toESM(require("node:url"));
|
|
14
|
-
|
|
15
|
-
//#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.js
|
|
16
|
-
const signals = [];
|
|
17
|
-
signals.push("SIGHUP", "SIGINT", "SIGTERM");
|
|
18
|
-
if (process.platform !== "win32") signals.push(
|
|
19
|
-
"SIGALRM",
|
|
20
|
-
"SIGABRT",
|
|
21
|
-
"SIGVTALRM",
|
|
22
|
-
"SIGXCPU",
|
|
23
|
-
"SIGXFSZ",
|
|
24
|
-
"SIGUSR2",
|
|
25
|
-
"SIGTRAP",
|
|
26
|
-
"SIGSYS",
|
|
27
|
-
"SIGQUIT",
|
|
28
|
-
"SIGIOT"
|
|
29
|
-
// should detect profiler and enable/disable accordingly.
|
|
30
|
-
// see #21
|
|
31
|
-
// 'SIGPROF'
|
|
32
|
-
);
|
|
33
|
-
if (process.platform === "linux") signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");
|
|
34
|
-
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.js
|
|
37
|
-
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";
|
|
38
|
-
const kExitEmitter = Symbol.for("signal-exit emitter");
|
|
39
|
-
const global = globalThis;
|
|
40
|
-
const ObjectDefineProperty = Object.defineProperty.bind(Object);
|
|
41
|
-
var Emitter = class {
|
|
42
|
-
emitted = {
|
|
43
|
-
afterExit: false,
|
|
44
|
-
exit: false
|
|
45
|
-
};
|
|
46
|
-
listeners = {
|
|
47
|
-
afterExit: [],
|
|
48
|
-
exit: []
|
|
49
|
-
};
|
|
50
|
-
count = 0;
|
|
51
|
-
id = Math.random();
|
|
52
|
-
constructor() {
|
|
53
|
-
if (global[kExitEmitter]) return global[kExitEmitter];
|
|
54
|
-
ObjectDefineProperty(global, kExitEmitter, {
|
|
55
|
-
value: this,
|
|
56
|
-
writable: false,
|
|
57
|
-
enumerable: false,
|
|
58
|
-
configurable: false
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
on(ev, fn) {
|
|
62
|
-
this.listeners[ev].push(fn);
|
|
63
|
-
}
|
|
64
|
-
removeListener(ev, fn) {
|
|
65
|
-
const list = this.listeners[ev];
|
|
66
|
-
const i = list.indexOf(fn);
|
|
67
|
-
if (i === -1) return;
|
|
68
|
-
if (i === 0 && list.length === 1) list.length = 0;
|
|
69
|
-
else list.splice(i, 1);
|
|
70
|
-
}
|
|
71
|
-
emit(ev, code, signal) {
|
|
72
|
-
if (this.emitted[ev]) return false;
|
|
73
|
-
this.emitted[ev] = true;
|
|
74
|
-
let ret = false;
|
|
75
|
-
for (const fn of this.listeners[ev]) ret = fn(code, signal) === true || ret;
|
|
76
|
-
if (ev === "exit") ret = this.emit("afterExit", code, signal) || ret;
|
|
77
|
-
return ret;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
var SignalExitBase = class {};
|
|
81
|
-
const signalExitWrap = (handler) => {
|
|
82
|
-
return {
|
|
83
|
-
onExit(cb, opts) {
|
|
84
|
-
return handler.onExit(cb, opts);
|
|
85
|
-
},
|
|
86
|
-
load() {
|
|
87
|
-
return handler.load();
|
|
88
|
-
},
|
|
89
|
-
unload() {
|
|
90
|
-
return handler.unload();
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
var SignalExitFallback = class extends SignalExitBase {
|
|
95
|
-
onExit() {
|
|
96
|
-
return () => {};
|
|
97
|
-
}
|
|
98
|
-
load() {}
|
|
99
|
-
unload() {}
|
|
100
|
-
};
|
|
101
|
-
var SignalExit = class extends SignalExitBase {
|
|
102
|
-
#hupSig = process$2.platform === "win32" ? "SIGINT" : "SIGHUP";
|
|
103
|
-
#emitter = new Emitter();
|
|
104
|
-
#process;
|
|
105
|
-
#originalProcessEmit;
|
|
106
|
-
#originalProcessReallyExit;
|
|
107
|
-
#sigListeners = {};
|
|
108
|
-
#loaded = false;
|
|
109
|
-
constructor(process$3) {
|
|
110
|
-
super();
|
|
111
|
-
this.#process = process$3;
|
|
112
|
-
this.#sigListeners = {};
|
|
113
|
-
for (const sig of signals) this.#sigListeners[sig] = () => {
|
|
114
|
-
const listeners = this.#process.listeners(sig);
|
|
115
|
-
let { count } = this.#emitter;
|
|
116
|
-
const p = process$3;
|
|
117
|
-
if (typeof p.__signal_exit_emitter__ === "object" && typeof p.__signal_exit_emitter__.count === "number") count += p.__signal_exit_emitter__.count;
|
|
118
|
-
if (listeners.length === count) {
|
|
119
|
-
this.unload();
|
|
120
|
-
const ret = this.#emitter.emit("exit", null, sig);
|
|
121
|
-
const s = sig === "SIGHUP" ? this.#hupSig : sig;
|
|
122
|
-
if (!ret) process$3.kill(process$3.pid, s);
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
this.#originalProcessReallyExit = process$3.reallyExit;
|
|
126
|
-
this.#originalProcessEmit = process$3.emit;
|
|
127
|
-
}
|
|
128
|
-
onExit(cb, opts) {
|
|
129
|
-
if (!processOk(this.#process)) return () => {};
|
|
130
|
-
if (this.#loaded === false) this.load();
|
|
131
|
-
const ev = opts?.alwaysLast ? "afterExit" : "exit";
|
|
132
|
-
this.#emitter.on(ev, cb);
|
|
133
|
-
return () => {
|
|
134
|
-
this.#emitter.removeListener(ev, cb);
|
|
135
|
-
if (this.#emitter.listeners["exit"].length === 0 && this.#emitter.listeners["afterExit"].length === 0) this.unload();
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
load() {
|
|
139
|
-
if (this.#loaded) return;
|
|
140
|
-
this.#loaded = true;
|
|
141
|
-
this.#emitter.count += 1;
|
|
142
|
-
for (const sig of signals) try {
|
|
143
|
-
const fn = this.#sigListeners[sig];
|
|
144
|
-
if (fn) this.#process.on(sig, fn);
|
|
145
|
-
} catch (_) {}
|
|
146
|
-
this.#process.emit = (ev, ...a) => {
|
|
147
|
-
return this.#processEmit(ev, ...a);
|
|
148
|
-
};
|
|
149
|
-
this.#process.reallyExit = (code) => {
|
|
150
|
-
return this.#processReallyExit(code);
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
unload() {
|
|
154
|
-
if (!this.#loaded) return;
|
|
155
|
-
this.#loaded = false;
|
|
156
|
-
signals.forEach((sig) => {
|
|
157
|
-
const listener = this.#sigListeners[sig];
|
|
158
|
-
if (!listener) throw new Error("Listener not defined for signal: " + sig);
|
|
159
|
-
try {
|
|
160
|
-
this.#process.removeListener(sig, listener);
|
|
161
|
-
} catch (_) {}
|
|
162
|
-
});
|
|
163
|
-
this.#process.emit = this.#originalProcessEmit;
|
|
164
|
-
this.#process.reallyExit = this.#originalProcessReallyExit;
|
|
165
|
-
this.#emitter.count -= 1;
|
|
166
|
-
}
|
|
167
|
-
#processReallyExit(code) {
|
|
168
|
-
if (!processOk(this.#process)) return 0;
|
|
169
|
-
this.#process.exitCode = code || 0;
|
|
170
|
-
this.#emitter.emit("exit", this.#process.exitCode, null);
|
|
171
|
-
return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode);
|
|
172
|
-
}
|
|
173
|
-
#processEmit(ev, ...args) {
|
|
174
|
-
const og = this.#originalProcessEmit;
|
|
175
|
-
if (ev === "exit" && processOk(this.#process)) {
|
|
176
|
-
if (typeof args[0] === "number") this.#process.exitCode = args[0];
|
|
177
|
-
const ret = og.call(this.#process, ev, ...args);
|
|
178
|
-
this.#emitter.emit("exit", this.#process.exitCode, null);
|
|
179
|
-
return ret;
|
|
180
|
-
} else return og.call(this.#process, ev, ...args);
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
const process$2 = globalThis.process;
|
|
184
|
-
const { onExit, load, unload } = signalExitWrap(processOk(process$2) ? new SignalExit(process$2) : new SignalExitFallback());
|
|
185
|
-
|
|
186
|
-
//#endregion
|
|
187
|
-
//#region src/cli/logger.ts
|
|
188
|
-
const logger = process.env.ROLLDOWN_TEST ? createTestingLogger() : require_consola_36c0034f.createConsola({ formatOptions: { date: false } });
|
|
189
|
-
function createTestingLogger() {
|
|
190
|
-
const types = [
|
|
191
|
-
"silent",
|
|
192
|
-
"fatal",
|
|
193
|
-
"error",
|
|
194
|
-
"warn",
|
|
195
|
-
"log",
|
|
196
|
-
"info",
|
|
197
|
-
"success",
|
|
198
|
-
"fail",
|
|
199
|
-
"ready",
|
|
200
|
-
"start",
|
|
201
|
-
"box",
|
|
202
|
-
"debug",
|
|
203
|
-
"trace",
|
|
204
|
-
"verbose"
|
|
205
|
-
];
|
|
206
|
-
const ret = Object.create(null);
|
|
207
|
-
for (const type of types) ret[type] = console.log;
|
|
208
|
-
return ret;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
//#endregion
|
|
212
|
-
//#region src/cli/load-config.ts
|
|
213
|
-
async function bundleTsConfig(configFile) {
|
|
214
|
-
const dirnameVarName = "injected_original_dirname";
|
|
215
|
-
const filenameVarName = "injected_original_filename";
|
|
216
|
-
const importMetaUrlVarName = "injected_original_import_meta_url";
|
|
217
|
-
const bundle = await require_src.rolldown({
|
|
218
|
-
input: configFile,
|
|
219
|
-
platform: "node",
|
|
220
|
-
resolve: { mainFields: ["main"] },
|
|
221
|
-
define: {
|
|
222
|
-
__dirname: dirnameVarName,
|
|
223
|
-
__filename: filenameVarName,
|
|
224
|
-
"import.meta.url": importMetaUrlVarName,
|
|
225
|
-
"import.meta.dirname": dirnameVarName,
|
|
226
|
-
"import.meta.filename": filenameVarName
|
|
227
|
-
},
|
|
228
|
-
treeshake: false,
|
|
229
|
-
external: [/^[\w@][^:]/],
|
|
230
|
-
plugins: [{
|
|
231
|
-
name: "inject-file-scope-variables",
|
|
232
|
-
transform: {
|
|
233
|
-
filter: { id: /\.[cm]?[jt]s$/ },
|
|
234
|
-
async handler(code, id) {
|
|
235
|
-
const injectValues = `const ${dirnameVarName} = ${JSON.stringify(node_path.default.dirname(id))};` + `const ${filenameVarName} = ${JSON.stringify(id)};` + `const ${importMetaUrlVarName} = ${JSON.stringify((0, node_url.pathToFileURL)(id).href)};`;
|
|
236
|
-
return {
|
|
237
|
-
code: injectValues + code,
|
|
238
|
-
map: null
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}]
|
|
243
|
-
});
|
|
244
|
-
const outputDir = node_path.default.dirname(configFile);
|
|
245
|
-
const result = await bundle.write({
|
|
246
|
-
dir: outputDir,
|
|
247
|
-
format: "esm",
|
|
248
|
-
sourcemap: "inline",
|
|
249
|
-
entryFileNames: "rolldown.config.[hash].js"
|
|
250
|
-
});
|
|
251
|
-
const fileName = result.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
|
|
252
|
-
return node_path.default.join(outputDir, fileName);
|
|
253
|
-
}
|
|
254
|
-
const SUPPORTED_JS_CONFIG_FORMATS = [
|
|
255
|
-
".js",
|
|
256
|
-
".mjs",
|
|
257
|
-
".cjs"
|
|
258
|
-
];
|
|
259
|
-
const SUPPORTED_TS_CONFIG_FORMATS = [
|
|
260
|
-
".ts",
|
|
261
|
-
".mts",
|
|
262
|
-
".cts"
|
|
263
|
-
];
|
|
264
|
-
const SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
|
|
265
|
-
const DEFAULT_CONFIG_BASE = "rolldown.config";
|
|
266
|
-
async function findConfigFileNameInCwd() {
|
|
267
|
-
const filesInWorkingDirectory = new Set(await (0, node_fs_promises.readdir)((0, node_process.cwd)()));
|
|
268
|
-
for (const extension of SUPPORTED_CONFIG_FORMATS) {
|
|
269
|
-
const fileName = `${DEFAULT_CONFIG_BASE}${extension}`;
|
|
270
|
-
if (filesInWorkingDirectory.has(fileName)) return fileName;
|
|
271
|
-
}
|
|
272
|
-
throw new Error("No `rolldown.config` configuration file found.");
|
|
273
|
-
}
|
|
274
|
-
async function loadTsConfig(configFile) {
|
|
275
|
-
const file = await bundleTsConfig(configFile);
|
|
276
|
-
try {
|
|
277
|
-
return (await import((0, node_url.pathToFileURL)(file).href)).default;
|
|
278
|
-
} finally {
|
|
279
|
-
node_fs.default.unlink(file, () => {});
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
async function loadConfig(configPath) {
|
|
283
|
-
const ext = node_path.default.extname(configPath = configPath || await findConfigFileNameInCwd());
|
|
284
|
-
try {
|
|
285
|
-
if (SUPPORTED_JS_CONFIG_FORMATS.includes(ext) || process.env.NODE_OPTIONS?.includes("--import=tsx") && SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return (await import((0, node_url.pathToFileURL)(configPath).href)).default;
|
|
286
|
-
else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) {
|
|
287
|
-
const rawConfigPath = node_path.default.resolve(configPath);
|
|
288
|
-
return await loadTsConfig(rawConfigPath);
|
|
289
|
-
} else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
|
|
290
|
-
} catch (err) {
|
|
291
|
-
throw new Error("Error happened while loading config.", { cause: err });
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
//#endregion
|
|
296
|
-
//#region src/cli/commands/bundle.ts
|
|
297
|
-
async function bundleWithConfig(configPath, cliOptions) {
|
|
298
|
-
const config = await loadConfig(configPath);
|
|
299
|
-
if (!config) {
|
|
300
|
-
logger.error(`No configuration found at ${config}`);
|
|
301
|
-
process.exit(1);
|
|
302
|
-
}
|
|
303
|
-
if (cliOptions.watch) await watchInner(config, cliOptions);
|
|
304
|
-
else await bundleInner(config, cliOptions);
|
|
305
|
-
}
|
|
306
|
-
async function bundleWithCliOptions(cliOptions) {
|
|
307
|
-
if (cliOptions.output.dir || cliOptions.output.file) {
|
|
308
|
-
const operation = cliOptions.watch ? watchInner : bundleInner;
|
|
309
|
-
await operation({}, cliOptions);
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
if (cliOptions.watch) {
|
|
313
|
-
logger.error("You must specify `output.dir` to use watch mode");
|
|
314
|
-
process.exit(1);
|
|
315
|
-
}
|
|
316
|
-
const build = await require_src.rolldown(cliOptions.input);
|
|
317
|
-
try {
|
|
318
|
-
const { output: outputs } = await build.generate(cliOptions.output);
|
|
319
|
-
if (outputs.length === 0) {
|
|
320
|
-
logger.error("No output generated");
|
|
321
|
-
process.exit(1);
|
|
322
|
-
}
|
|
323
|
-
for (const file of outputs) {
|
|
324
|
-
if (outputs.length > 1) logger.log(`\n${require_binding.colors.cyan(require_binding.colors.bold(`|→ ${file.fileName}:`))}\n`);
|
|
325
|
-
console.log(file.type === "asset" ? file.source : file.code);
|
|
326
|
-
}
|
|
327
|
-
} finally {
|
|
328
|
-
await build.close();
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
async function watchInner(config, cliOptions) {
|
|
332
|
-
let normalizedConfig = require_src.arraify(config).map((option) => {
|
|
333
|
-
return {
|
|
334
|
-
...option,
|
|
335
|
-
...cliOptions.input,
|
|
336
|
-
output: require_src.arraify(option.output || {}).map((output) => {
|
|
337
|
-
return {
|
|
338
|
-
...output,
|
|
339
|
-
...cliOptions.output
|
|
340
|
-
};
|
|
341
|
-
})
|
|
342
|
-
};
|
|
343
|
-
});
|
|
344
|
-
const watcher = await require_src.watch(normalizedConfig);
|
|
345
|
-
onExit((code) => {
|
|
346
|
-
Promise.resolve(watcher.close()).finally(() => {
|
|
347
|
-
process.exit(typeof code === "number" ? code : 0);
|
|
348
|
-
});
|
|
349
|
-
return true;
|
|
350
|
-
});
|
|
351
|
-
const changedFile = [];
|
|
352
|
-
watcher.on("change", (id, event) => {
|
|
353
|
-
if (event.event === "update") changedFile.push(id);
|
|
354
|
-
});
|
|
355
|
-
watcher.on("event", (event) => {
|
|
356
|
-
switch (event.code) {
|
|
357
|
-
case "BUNDLE_START":
|
|
358
|
-
if (changedFile.length > 0) logger.log(`Found ${require_binding.colors.bold(changedFile.map(relativeId).join(", "))} changed, rebuilding...`);
|
|
359
|
-
changedFile.length = 0;
|
|
360
|
-
break;
|
|
361
|
-
case "BUNDLE_END":
|
|
362
|
-
logger.success(`Rebuilt ${require_binding.colors.bold(relativeId(event.output[0]))} in ${require_binding.colors.bold(ms(event.duration))}.`);
|
|
363
|
-
break;
|
|
364
|
-
case "ERROR":
|
|
365
|
-
logger.error(event.error);
|
|
366
|
-
break;
|
|
367
|
-
default: break;
|
|
368
|
-
}
|
|
369
|
-
});
|
|
370
|
-
logger.log(`Waiting for changes...`);
|
|
371
|
-
}
|
|
372
|
-
async function bundleInner(config, cliOptions) {
|
|
373
|
-
const startTime = node_perf_hooks.performance.now();
|
|
374
|
-
const result = [];
|
|
375
|
-
const configList = require_src.arraify(config);
|
|
376
|
-
for (const config$1 of configList) {
|
|
377
|
-
const outputList = require_src.arraify(config$1.output || {});
|
|
378
|
-
const build = await require_src.rolldown({
|
|
379
|
-
...config$1,
|
|
380
|
-
...cliOptions.input
|
|
381
|
-
});
|
|
382
|
-
for (const output of outputList) try {
|
|
383
|
-
result.push(await build.write({
|
|
384
|
-
...output,
|
|
385
|
-
...cliOptions.output
|
|
386
|
-
}));
|
|
387
|
-
} finally {
|
|
388
|
-
await build.close();
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
result.forEach(printBundleOutputPretty);
|
|
392
|
-
logger.log(``);
|
|
393
|
-
const endTime = node_perf_hooks.performance.now();
|
|
394
|
-
const duration = endTime - startTime;
|
|
395
|
-
logger.success(`Finished in ${require_binding.colors.bold(ms(duration))}`);
|
|
396
|
-
}
|
|
397
|
-
function printBundleOutputPretty(output) {
|
|
398
|
-
const outputEntries = collectOutputEntries(output.output);
|
|
399
|
-
const outputLayoutSizes = collectOutputLayoutAdjustmentSizes(outputEntries);
|
|
400
|
-
printOutputEntries(outputEntries, outputLayoutSizes, "<DIR>");
|
|
401
|
-
}
|
|
402
|
-
function collectOutputEntries(output) {
|
|
403
|
-
return output.map((chunk) => ({
|
|
404
|
-
type: chunk.type,
|
|
405
|
-
fileName: chunk.fileName,
|
|
406
|
-
size: chunk.type === "chunk" ? chunk.code.length : chunk.source.length
|
|
407
|
-
}));
|
|
408
|
-
}
|
|
409
|
-
function collectOutputLayoutAdjustmentSizes(entries) {
|
|
410
|
-
let longest = 0;
|
|
411
|
-
let biggestSize = 0;
|
|
412
|
-
for (const entry of entries) {
|
|
413
|
-
if (entry.fileName.length > longest) longest = entry.fileName.length;
|
|
414
|
-
if (entry.size > biggestSize) biggestSize = entry.size;
|
|
415
|
-
}
|
|
416
|
-
const sizePad = displaySize(biggestSize).length;
|
|
417
|
-
return {
|
|
418
|
-
longest,
|
|
419
|
-
biggestSize,
|
|
420
|
-
sizePad
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
const numberFormatter = new Intl.NumberFormat("en", {
|
|
424
|
-
maximumFractionDigits: 2,
|
|
425
|
-
minimumFractionDigits: 2
|
|
426
|
-
});
|
|
427
|
-
function displaySize(bytes) {
|
|
428
|
-
return `${numberFormatter.format(bytes / 1e3)} kB`;
|
|
429
|
-
}
|
|
430
|
-
const CHUNK_GROUPS = [{
|
|
431
|
-
type: "asset",
|
|
432
|
-
color: "green"
|
|
433
|
-
}, {
|
|
434
|
-
type: "chunk",
|
|
435
|
-
color: "cyan"
|
|
436
|
-
}];
|
|
437
|
-
function printOutputEntries(entries, sizeAdjustment, distPath) {
|
|
438
|
-
for (const group of CHUNK_GROUPS) {
|
|
439
|
-
const filtered = entries.filter((e) => e.type === group.type);
|
|
440
|
-
if (!filtered.length) continue;
|
|
441
|
-
for (const entry of filtered.sort((a, z) => a.size - z.size)) {
|
|
442
|
-
let log = require_binding.colors.dim(withTrailingSlash(distPath));
|
|
443
|
-
log += require_binding.colors[group.color](entry.fileName.padEnd(sizeAdjustment.longest + 2));
|
|
444
|
-
log += require_binding.colors.dim(entry.type);
|
|
445
|
-
log += require_binding.colors.dim(` │ size: ${displaySize(entry.size).padStart(sizeAdjustment.sizePad)}`);
|
|
446
|
-
logger.log(log);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
function withTrailingSlash(path$2) {
|
|
451
|
-
if (path$2[path$2.length - 1] !== "/") return `${path$2}/`;
|
|
452
|
-
return path$2;
|
|
453
|
-
}
|
|
454
|
-
function ms(duration) {
|
|
455
|
-
return duration < 1e3 ? `${duration.toFixed(2)} ms` : `${(duration / 1e3).toFixed(2)} s`;
|
|
456
|
-
}
|
|
457
|
-
function relativeId(id) {
|
|
458
|
-
if (!node_path.default.isAbsolute(id)) return id;
|
|
459
|
-
return node_path.default.relative(node_path.default.resolve(), id);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
//#endregion
|
|
463
|
-
//#region src/cli/arguments/alias.ts
|
|
464
|
-
const alias = {
|
|
465
|
-
config: {
|
|
466
|
-
abbreviation: "c",
|
|
467
|
-
hint: "filename"
|
|
468
|
-
},
|
|
469
|
-
help: { abbreviation: "h" },
|
|
470
|
-
version: { abbreviation: "v" },
|
|
471
|
-
watch: { abbreviation: "w" },
|
|
472
|
-
dir: { abbreviation: "d" },
|
|
473
|
-
file: { abbreviation: "o" },
|
|
474
|
-
external: { abbreviation: "e" },
|
|
475
|
-
format: { abbreviation: "f" },
|
|
476
|
-
name: { abbreviation: "n" },
|
|
477
|
-
globals: { abbreviation: "g" },
|
|
478
|
-
sourcemap: {
|
|
479
|
-
abbreviation: "s",
|
|
480
|
-
default: true
|
|
481
|
-
},
|
|
482
|
-
minify: { abbreviation: "m" },
|
|
483
|
-
platform: { abbreviation: "p" },
|
|
484
|
-
assetFileNames: { hint: "name" },
|
|
485
|
-
chunkFileNames: { hint: "name" },
|
|
486
|
-
entryFileNames: { hint: "name" },
|
|
487
|
-
externalLiveBindings: {
|
|
488
|
-
default: true,
|
|
489
|
-
reverse: true
|
|
490
|
-
},
|
|
491
|
-
treeshake: {
|
|
492
|
-
default: true,
|
|
493
|
-
reverse: true
|
|
494
|
-
},
|
|
495
|
-
moduleTypes: { hint: "types" }
|
|
496
|
-
};
|
|
497
|
-
|
|
498
|
-
//#endregion
|
|
499
|
-
//#region src/cli/arguments/utils.ts
|
|
500
|
-
const priority = [
|
|
501
|
-
"object",
|
|
502
|
-
"array",
|
|
503
|
-
"string",
|
|
504
|
-
"number",
|
|
505
|
-
"boolean"
|
|
506
|
-
];
|
|
507
|
-
function getSchemaType(schema) {
|
|
508
|
-
if ("anyOf" in schema) {
|
|
509
|
-
const types = schema.anyOf.map(getSchemaType);
|
|
510
|
-
let result = priority.find((type) => types.includes(type));
|
|
511
|
-
if (result) return result;
|
|
512
|
-
}
|
|
513
|
-
if ("type" in schema) return schema.type;
|
|
514
|
-
if ("const" in schema) return typeof schema.const;
|
|
515
|
-
return "object";
|
|
516
|
-
}
|
|
517
|
-
function flattenSchema(schema, base = {}, parent = "") {
|
|
518
|
-
if (schema === undefined) return base;
|
|
519
|
-
for (const [k, value] of Object.entries(schema)) {
|
|
520
|
-
const key = parent ? `${parent}.${k}` : k;
|
|
521
|
-
if (getSchemaType(value) === "object") if ("properties" in value) flattenSchema(value.properties, base, key);
|
|
522
|
-
else base[key] = value;
|
|
523
|
-
else base[key] = value;
|
|
524
|
-
}
|
|
525
|
-
return base;
|
|
526
|
-
}
|
|
527
|
-
function setNestedProperty(obj, path$2, value) {
|
|
528
|
-
const keys = path$2.split(".");
|
|
529
|
-
let current = obj;
|
|
530
|
-
for (let i = 0; i < keys.length - 1; i++) {
|
|
531
|
-
if (!current[keys[i]]) current[keys[i]] = {};
|
|
532
|
-
current = current[keys[i]];
|
|
533
|
-
}
|
|
534
|
-
const finalKey = keys[keys.length - 1];
|
|
535
|
-
Object.defineProperty(current, finalKey, {
|
|
536
|
-
value,
|
|
537
|
-
writable: true,
|
|
538
|
-
enumerable: true,
|
|
539
|
-
configurable: true
|
|
540
|
-
});
|
|
541
|
-
}
|
|
542
|
-
function camelCaseToKebabCase(str) {
|
|
543
|
-
return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
544
|
-
}
|
|
545
|
-
function kebabCaseToCamelCase(str) {
|
|
546
|
-
return str.replace(/-./g, (match) => match[1].toUpperCase());
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
//#endregion
|
|
550
|
-
//#region src/cli/arguments/normalize.ts
|
|
551
|
-
function normalizeCliOptions(cliOptions, positionals) {
|
|
552
|
-
const [data, errors] = require_src.validateCliOptions(cliOptions);
|
|
553
|
-
if (errors?.length) {
|
|
554
|
-
errors.forEach((error) => {
|
|
555
|
-
logger.error(`Invalid value for option ${error}. You can use \`rolldown -h\` to see the help.`);
|
|
556
|
-
});
|
|
557
|
-
process.exit(1);
|
|
558
|
-
}
|
|
559
|
-
const options$1 = data ?? {};
|
|
560
|
-
const result = {
|
|
561
|
-
input: {},
|
|
562
|
-
output: {},
|
|
563
|
-
help: options$1.help ?? false,
|
|
564
|
-
version: options$1.version ?? false,
|
|
565
|
-
watch: options$1.watch ?? false
|
|
566
|
-
};
|
|
567
|
-
if (typeof options$1.config === "string") result.config = options$1.config;
|
|
568
|
-
const keysOfInput = require_src.getInputCliKeys();
|
|
569
|
-
const keysOfOutput = require_src.getOutputCliKeys();
|
|
570
|
-
const reservedKeys = [
|
|
571
|
-
"help",
|
|
572
|
-
"version",
|
|
573
|
-
"config",
|
|
574
|
-
"watch"
|
|
575
|
-
];
|
|
576
|
-
for (let [key, value] of Object.entries(options$1)) {
|
|
577
|
-
const keys = key.split(".");
|
|
578
|
-
const [primary] = keys;
|
|
579
|
-
if (keysOfInput.includes(primary)) setNestedProperty(result.input, key, value);
|
|
580
|
-
else if (keysOfOutput.includes(primary)) setNestedProperty(result.output, key, value);
|
|
581
|
-
else if (!reservedKeys.includes(key)) {
|
|
582
|
-
logger.error(`Unknown option: ${key}`);
|
|
583
|
-
process.exit(1);
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
if (!result.config && positionals.length > 0) result.input.input = positionals;
|
|
587
|
-
return result;
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
//#endregion
|
|
591
|
-
//#region src/cli/arguments/index.ts
|
|
592
|
-
const objectSchema = require_src.getJsonSchema();
|
|
593
|
-
const flattenedSchema = flattenSchema(objectSchema.properties);
|
|
594
|
-
const options = Object.fromEntries(Object.entries(flattenedSchema).map(([key, schema]) => {
|
|
595
|
-
const config = Object.getOwnPropertyDescriptor(alias, key)?.value;
|
|
596
|
-
const type = getSchemaType(schema);
|
|
597
|
-
const result = {
|
|
598
|
-
type: type === "boolean" ? "boolean" : "string",
|
|
599
|
-
description: schema?.description ?? config?.description ?? "",
|
|
600
|
-
hint: config?.hint
|
|
601
|
-
};
|
|
602
|
-
if (config && config?.abbreviation) result.short = config?.abbreviation;
|
|
603
|
-
if (config && config.reverse) if (result.description.startsWith("enable")) result.description = result.description.replace("enable", "disable");
|
|
604
|
-
else result.description = `disable ${result.description}`;
|
|
605
|
-
key = camelCaseToKebabCase(key);
|
|
606
|
-
return [config?.reverse ? `no-${key}` : key, result];
|
|
607
|
-
}));
|
|
608
|
-
function parseCliArguments() {
|
|
609
|
-
const { values, tokens, positionals } = (0, node_util.parseArgs)({
|
|
610
|
-
options,
|
|
611
|
-
tokens: true,
|
|
612
|
-
allowPositionals: true,
|
|
613
|
-
strict: false
|
|
614
|
-
});
|
|
615
|
-
tokens.filter((token) => token.kind === "option").forEach((option) => {
|
|
616
|
-
let negative = false;
|
|
617
|
-
if (option.name.startsWith("no-")) {
|
|
618
|
-
const name = kebabCaseToCamelCase(option.name.substring(3));
|
|
619
|
-
if (name in flattenedSchema) {
|
|
620
|
-
delete values[option.name];
|
|
621
|
-
option.name = name;
|
|
622
|
-
negative = true;
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
delete values[option.name];
|
|
626
|
-
option.name = kebabCaseToCamelCase(option.name);
|
|
627
|
-
let originalType = flattenedSchema[option.name];
|
|
628
|
-
if (!originalType) {
|
|
629
|
-
logger.error(`Invalid option: ${option.rawName}. We will ignore this option.`);
|
|
630
|
-
process.exit(1);
|
|
631
|
-
}
|
|
632
|
-
let type = getSchemaType(originalType);
|
|
633
|
-
if (type === "string" && typeof option.value !== "string") {
|
|
634
|
-
let opt = option;
|
|
635
|
-
let defaultValue = Object.getOwnPropertyDescriptor(alias, opt.name)?.value;
|
|
636
|
-
Object.defineProperty(values, opt.name, {
|
|
637
|
-
value: defaultValue.default ?? "",
|
|
638
|
-
enumerable: true,
|
|
639
|
-
configurable: true,
|
|
640
|
-
writable: true
|
|
641
|
-
});
|
|
642
|
-
} else if (type === "object" && typeof option.value === "string") {
|
|
643
|
-
const [key, value] = option.value.split(",").map((x) => x.split("="))[0];
|
|
644
|
-
if (!values[option.name]) Object.defineProperty(values, option.name, {
|
|
645
|
-
value: {},
|
|
646
|
-
enumerable: true,
|
|
647
|
-
configurable: true,
|
|
648
|
-
writable: true
|
|
649
|
-
});
|
|
650
|
-
if (key && value) Object.defineProperty(values[option.name], key, {
|
|
651
|
-
value,
|
|
652
|
-
enumerable: true,
|
|
653
|
-
configurable: true,
|
|
654
|
-
writable: true
|
|
655
|
-
});
|
|
656
|
-
} else if (type === "array" && typeof option.value === "string") {
|
|
657
|
-
if (!values[option.name]) Object.defineProperty(values, option.name, {
|
|
658
|
-
value: [],
|
|
659
|
-
enumerable: true,
|
|
660
|
-
configurable: true,
|
|
661
|
-
writable: true
|
|
662
|
-
});
|
|
663
|
-
values[option.name].push(option.value);
|
|
664
|
-
} else if (type === "boolean") Object.defineProperty(values, option.name, {
|
|
665
|
-
value: !negative,
|
|
666
|
-
enumerable: true,
|
|
667
|
-
configurable: true,
|
|
668
|
-
writable: true
|
|
669
|
-
});
|
|
670
|
-
else Object.defineProperty(values, option.name, {
|
|
671
|
-
value: option.value ?? "",
|
|
672
|
-
enumerable: true,
|
|
673
|
-
configurable: true,
|
|
674
|
-
writable: true
|
|
675
|
-
});
|
|
676
|
-
});
|
|
677
|
-
return normalizeCliOptions(values, positionals);
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
//#endregion
|
|
681
|
-
//#region src/cli/commands/help.ts
|
|
682
|
-
const introduction = `${require_binding.colors.gray(`${require_src.description} (rolldown v${require_src.version})`)}
|
|
683
|
-
|
|
684
|
-
${require_binding.colors.bold(require_binding.colors.underline("USAGE"))} ${require_binding.colors.cyan("rolldown -c <config>")} or ${require_binding.colors.cyan("rolldown <input> <options>")}`;
|
|
685
|
-
const examples = [
|
|
686
|
-
{
|
|
687
|
-
title: "Bundle with a config file `rolldown.config.mjs`",
|
|
688
|
-
command: "rolldown -c rolldown.config.mjs"
|
|
689
|
-
},
|
|
690
|
-
{
|
|
691
|
-
title: "Bundle the `src/main.ts` to `dist` with `cjs` format",
|
|
692
|
-
command: "rolldown src/main.ts -d dist -f cjs"
|
|
693
|
-
},
|
|
694
|
-
{
|
|
695
|
-
title: "Bundle the `src/main.ts` and handle the `.png` assets to Data URL",
|
|
696
|
-
command: "rolldown src/main.ts -d dist --moduleTypes .png=dataurl"
|
|
697
|
-
},
|
|
698
|
-
{
|
|
699
|
-
title: "Bundle the `src/main.tsx` and minify the output with sourcemap",
|
|
700
|
-
command: "rolldown src/main.tsx -d dist -m -s"
|
|
701
|
-
},
|
|
702
|
-
{
|
|
703
|
-
title: "Create self-executing IIFE using external jQuery as `$` and `_`",
|
|
704
|
-
command: "rolldown src/main.ts -d dist -n bundle -f iife -e jQuery,window._ -g jQuery=$"
|
|
705
|
-
}
|
|
706
|
-
];
|
|
707
|
-
const notes = [
|
|
708
|
-
"Due to the API limitation, you need to pass `-s` for `.map` sourcemap file as the last argument.",
|
|
709
|
-
"If you are using the configuration, please pass the `-c` as the last argument if you ignore the default configuration file.",
|
|
710
|
-
"CLI options will override the configuration file.",
|
|
711
|
-
"For more information, please visit https://rolldown.rs/."
|
|
712
|
-
];
|
|
713
|
-
function showHelp() {
|
|
714
|
-
logger.log(introduction);
|
|
715
|
-
logger.log("");
|
|
716
|
-
logger.log(`${require_binding.colors.bold(require_binding.colors.underline("OPTIONS"))}`);
|
|
717
|
-
logger.log("");
|
|
718
|
-
logger.log(Object.entries(options).sort(([a], [b]) => {
|
|
719
|
-
if (options[a].short && !options[b].short) return -1;
|
|
720
|
-
if (!options[a].short && options[b].short) return 1;
|
|
721
|
-
if (options[a].short && options[b].short) return options[a].short.localeCompare(options[b].short);
|
|
722
|
-
return a.localeCompare(b);
|
|
723
|
-
}).map(([option, { type, short, hint, description: description$1 }]) => {
|
|
724
|
-
let optionStr = ` --${option} `;
|
|
725
|
-
option = camelCaseToKebabCase(option);
|
|
726
|
-
if (short) optionStr += `-${short}, `;
|
|
727
|
-
if (type === "string") optionStr += `<${hint ?? option}>`;
|
|
728
|
-
if (description$1 && description$1.length > 0) description$1 = description$1[0].toUpperCase() + description$1.slice(1);
|
|
729
|
-
return require_binding.colors.cyan(optionStr.padEnd(30)) + description$1 + (description$1 && description$1?.endsWith(".") ? "" : ".");
|
|
730
|
-
}).join("\n"));
|
|
731
|
-
logger.log("");
|
|
732
|
-
logger.log(`${require_binding.colors.bold(require_binding.colors.underline("EXAMPLES"))}`);
|
|
733
|
-
logger.log("");
|
|
734
|
-
examples.forEach(({ title, command }, ord) => {
|
|
735
|
-
logger.log(` ${ord + 1}. ${title}:`);
|
|
736
|
-
logger.log(` ${require_binding.colors.cyan(command)}`);
|
|
737
|
-
logger.log("");
|
|
738
|
-
});
|
|
739
|
-
logger.log(`${require_binding.colors.bold(require_binding.colors.underline("NOTES"))}`);
|
|
740
|
-
logger.log("");
|
|
741
|
-
notes.forEach((note) => {
|
|
742
|
-
logger.log(` * ${require_binding.colors.gray(note)}`);
|
|
743
|
-
});
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
//#endregion
|
|
747
|
-
//#region src/cli/index.ts
|
|
748
|
-
async function main() {
|
|
749
|
-
const cliOptions = parseCliArguments();
|
|
750
|
-
if (cliOptions.config || cliOptions.config === "") {
|
|
751
|
-
await bundleWithConfig(cliOptions.config, cliOptions);
|
|
752
|
-
return;
|
|
753
|
-
}
|
|
754
|
-
if ("input" in cliOptions.input) {
|
|
755
|
-
await bundleWithCliOptions(cliOptions);
|
|
756
|
-
return;
|
|
757
|
-
}
|
|
758
|
-
if (cliOptions.version) {
|
|
759
|
-
logger.log(`rolldown v${require_src.version}`);
|
|
760
|
-
return;
|
|
761
|
-
}
|
|
762
|
-
showHelp();
|
|
763
|
-
}
|
|
764
|
-
main().catch((err) => {
|
|
765
|
-
console.error(err);
|
|
766
|
-
node_process.default.exit(1);
|
|
767
|
-
});
|
|
768
|
-
|
|
769
|
-
//#endregion
|