rolldown 1.0.0-beta.7-commit.51b53fd → 1.0.0-beta.7-commit.25f3c61
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.js +1 -1
- package/dist/cjs/cli.cjs +457 -457
- package/dist/cjs/experimental-index.cjs +24 -24
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/parallel-plugin-worker.cjs +2 -2
- package/dist/cjs/parse-ast-index.cjs +1 -1
- package/dist/esm/cli.mjs +457 -457
- package/dist/esm/experimental-index.mjs +24 -24
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/parallel-plugin-worker.mjs +2 -2
- package/dist/esm/parse-ast-index.mjs +1 -1
- package/dist/shared/{parse-ast-index-DbQWN9pL.cjs → parse-ast-index-0ei4fTjl.cjs} +253 -252
- package/dist/shared/{parse-ast-index-B-UemHTj.mjs → parse-ast-index-DNOUVcBy.mjs} +253 -252
- package/dist/shared/{src-eC0JqPTa.cjs → src-BPcsb-4N.cjs} +464 -464
- package/dist/shared/{src-DJ0d0UY6.mjs → src-DllTyFDp.mjs} +464 -464
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/binding.d.ts +5 -1
- package/dist/types/builtin-plugin/constructors.d.ts +1 -1
- package/dist/types/builtin-plugin/replace-plugin.d.ts +0 -1
- package/dist/types/cli/arguments/index.d.ts +1 -1
- package/dist/types/cli/arguments/normalize.d.ts +5 -1
- package/dist/types/experimental-index.d.ts +5 -5
- package/dist/types/index.d.ts +23 -23
- package/dist/types/log/logger.d.ts +2 -2
- package/dist/types/options/generated/checks-options.d.ts +11 -11
- package/dist/types/options/input-options.d.ts +4 -4
- package/dist/types/options/normalized-input-options.d.ts +2 -2
- package/dist/types/options/normalized-output-options.d.ts +1 -1
- package/dist/types/options/output-options.d.ts +2 -2
- package/dist/types/parallel-plugin.d.ts +1 -1
- package/dist/types/plugin/bindingify-build-hooks.d.ts +1 -1
- package/dist/types/plugin/bindingify-hook-filter.d.ts +2 -2
- package/dist/types/plugin/bindingify-output-hooks.d.ts +2 -2
- package/dist/types/plugin/bindingify-plugin-hook-meta.d.ts +1 -1
- package/dist/types/plugin/bindingify-plugin.d.ts +3 -3
- package/dist/types/plugin/bindingify-watch-hooks.d.ts +1 -1
- package/dist/types/plugin/hook-filter.d.ts +1 -1
- package/dist/types/plugin/index.d.ts +15 -16
- package/dist/types/plugin/plugin-context-data.d.ts +2 -2
- package/dist/types/plugin/plugin-context.d.ts +7 -7
- package/dist/types/plugin/plugin-driver.d.ts +2 -2
- package/dist/types/plugin/transform-plugin-context.d.ts +4 -4
- package/dist/types/types/rolldown-output.d.ts +1 -1
- package/dist/types/utils/bindingify-input-options.d.ts +3 -3
- package/dist/types/utils/create-bundler-option.d.ts +1 -1
- package/dist/types/utils/define-config.d.ts +1 -1
- package/dist/types/utils/initialize-parallel-plugins.d.ts +1 -1
- package/dist/types/utils/normalize-hook.d.ts +1 -1
- package/dist/types/utils/normalize-plugin-option.d.ts +1 -1
- package/dist/types/utils/transform-module-info.d.ts +2 -2
- package/dist/types/utils/transform-to-rollup-output.d.ts +2 -2
- package/package.json +25 -26
package/dist/esm/cli.mjs
CHANGED
|
@@ -1,186 +1,14 @@
|
|
|
1
|
-
import { colors } from "../shared/parse-ast-index-
|
|
2
|
-
import { arraify, description, getInputCliKeys, getJsonSchema, getOutputCliKeys, rolldown, validateCliOptions, version, watch } from "../shared/src-
|
|
3
|
-
import process$1, { cwd } from "node:process";
|
|
4
|
-
import path, { sep } from "node:path";
|
|
1
|
+
import { colors } from "../shared/parse-ast-index-DNOUVcBy.mjs";
|
|
2
|
+
import { arraify, description, getInputCliKeys, getJsonSchema, getOutputCliKeys, rolldown, validateCliOptions, version, watch } from "../shared/src-DllTyFDp.mjs";
|
|
5
3
|
import fs from "node:fs";
|
|
6
|
-
import {
|
|
4
|
+
import path, { sep } from "node:path";
|
|
5
|
+
import process$1, { cwd } from "node:process";
|
|
7
6
|
import { formatWithOptions, parseArgs } from "node:util";
|
|
8
7
|
import * as tty from "node:tty";
|
|
8
|
+
import { performance } from "node:perf_hooks";
|
|
9
9
|
import { readdir } from "node:fs/promises";
|
|
10
10
|
import { pathToFileURL } from "node:url";
|
|
11
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());
|
|
182
|
-
|
|
183
|
-
//#endregion
|
|
184
12
|
//#region ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/core.mjs
|
|
185
13
|
const LogLevels = {
|
|
186
14
|
silent: Number.NEGATIVE_INFINITY,
|
|
@@ -1165,286 +993,6 @@ function createTestingLogger() {
|
|
|
1165
993
|
return ret;
|
|
1166
994
|
}
|
|
1167
995
|
|
|
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
|
-
process.env.ROLLUP_WATCH = "true";
|
|
1317
|
-
process.env.ROLLDOWN_WATCH = "true";
|
|
1318
|
-
let normalizedConfig = arraify(config).map((option) => {
|
|
1319
|
-
return {
|
|
1320
|
-
...option,
|
|
1321
|
-
...cliOptions.input,
|
|
1322
|
-
output: arraify(option.output || {}).map((output) => {
|
|
1323
|
-
return {
|
|
1324
|
-
...output,
|
|
1325
|
-
...cliOptions.output
|
|
1326
|
-
};
|
|
1327
|
-
})
|
|
1328
|
-
};
|
|
1329
|
-
});
|
|
1330
|
-
const watcher = await watch(normalizedConfig);
|
|
1331
|
-
onExit((code) => {
|
|
1332
|
-
Promise.resolve(watcher.close()).finally(() => {
|
|
1333
|
-
process.exit(typeof code === "number" ? code : 0);
|
|
1334
|
-
});
|
|
1335
|
-
return true;
|
|
1336
|
-
});
|
|
1337
|
-
const changedFile = [];
|
|
1338
|
-
watcher.on("change", (id, event) => {
|
|
1339
|
-
if (event.event === "update") changedFile.push(id);
|
|
1340
|
-
});
|
|
1341
|
-
watcher.on("event", (event) => {
|
|
1342
|
-
switch (event.code) {
|
|
1343
|
-
case "BUNDLE_START":
|
|
1344
|
-
if (changedFile.length > 0) logger.log(`Found ${colors.bold(changedFile.map(relativeId).join(", "))} changed, rebuilding...`);
|
|
1345
|
-
changedFile.length = 0;
|
|
1346
|
-
break;
|
|
1347
|
-
case "BUNDLE_END":
|
|
1348
|
-
logger.success(`Rebuilt ${colors.bold(relativeId(event.output[0]))} in ${colors.bold(ms(event.duration))}.`);
|
|
1349
|
-
break;
|
|
1350
|
-
case "ERROR":
|
|
1351
|
-
logger.error(event.error);
|
|
1352
|
-
break;
|
|
1353
|
-
default: break;
|
|
1354
|
-
}
|
|
1355
|
-
});
|
|
1356
|
-
logger.log(`Waiting for changes...`);
|
|
1357
|
-
}
|
|
1358
|
-
async function bundleInner(config, cliOptions) {
|
|
1359
|
-
const startTime = performance.now();
|
|
1360
|
-
const result = [];
|
|
1361
|
-
const configList = arraify(config);
|
|
1362
|
-
for (const config$1 of configList) {
|
|
1363
|
-
const outputList = arraify(config$1.output || {});
|
|
1364
|
-
const build = await rolldown({
|
|
1365
|
-
...config$1,
|
|
1366
|
-
...cliOptions.input
|
|
1367
|
-
});
|
|
1368
|
-
for (const output of outputList) try {
|
|
1369
|
-
result.push(await build.write({
|
|
1370
|
-
...output,
|
|
1371
|
-
...cliOptions.output
|
|
1372
|
-
}));
|
|
1373
|
-
} finally {
|
|
1374
|
-
await build.close();
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
result.forEach(printBundleOutputPretty);
|
|
1378
|
-
logger.log(``);
|
|
1379
|
-
const endTime = performance.now();
|
|
1380
|
-
const duration = endTime - startTime;
|
|
1381
|
-
logger.success(`Finished in ${colors.bold(ms(duration))}`);
|
|
1382
|
-
}
|
|
1383
|
-
function printBundleOutputPretty(output) {
|
|
1384
|
-
const outputEntries = collectOutputEntries(output.output);
|
|
1385
|
-
const outputLayoutSizes = collectOutputLayoutAdjustmentSizes(outputEntries);
|
|
1386
|
-
printOutputEntries(outputEntries, outputLayoutSizes, "<DIR>");
|
|
1387
|
-
}
|
|
1388
|
-
function collectOutputEntries(output) {
|
|
1389
|
-
return output.map((chunk) => ({
|
|
1390
|
-
type: chunk.type,
|
|
1391
|
-
fileName: chunk.fileName,
|
|
1392
|
-
size: chunk.type === "chunk" ? Buffer.byteLength(chunk.code) : Buffer.byteLength(chunk.source)
|
|
1393
|
-
}));
|
|
1394
|
-
}
|
|
1395
|
-
function collectOutputLayoutAdjustmentSizes(entries) {
|
|
1396
|
-
let longest = 0;
|
|
1397
|
-
let biggestSize = 0;
|
|
1398
|
-
for (const entry of entries) {
|
|
1399
|
-
if (entry.fileName.length > longest) longest = entry.fileName.length;
|
|
1400
|
-
if (entry.size > biggestSize) biggestSize = entry.size;
|
|
1401
|
-
}
|
|
1402
|
-
const sizePad = displaySize(biggestSize).length;
|
|
1403
|
-
return {
|
|
1404
|
-
longest,
|
|
1405
|
-
biggestSize,
|
|
1406
|
-
sizePad
|
|
1407
|
-
};
|
|
1408
|
-
}
|
|
1409
|
-
const numberFormatter = new Intl.NumberFormat("en", {
|
|
1410
|
-
maximumFractionDigits: 2,
|
|
1411
|
-
minimumFractionDigits: 2
|
|
1412
|
-
});
|
|
1413
|
-
function displaySize(bytes) {
|
|
1414
|
-
return `${numberFormatter.format(bytes / 1e3)} kB`;
|
|
1415
|
-
}
|
|
1416
|
-
const CHUNK_GROUPS = [{
|
|
1417
|
-
type: "asset",
|
|
1418
|
-
color: "green"
|
|
1419
|
-
}, {
|
|
1420
|
-
type: "chunk",
|
|
1421
|
-
color: "cyan"
|
|
1422
|
-
}];
|
|
1423
|
-
function printOutputEntries(entries, sizeAdjustment, distPath) {
|
|
1424
|
-
for (const group of CHUNK_GROUPS) {
|
|
1425
|
-
const filtered = entries.filter((e) => e.type === group.type);
|
|
1426
|
-
if (!filtered.length) continue;
|
|
1427
|
-
for (const entry of filtered.sort((a$1, z) => a$1.size - z.size)) {
|
|
1428
|
-
let log = colors.dim(withTrailingSlash(distPath));
|
|
1429
|
-
log += colors[group.color](entry.fileName.padEnd(sizeAdjustment.longest + 2));
|
|
1430
|
-
log += colors.dim(entry.type);
|
|
1431
|
-
log += colors.dim(` │ size: ${displaySize(entry.size).padStart(sizeAdjustment.sizePad)}`);
|
|
1432
|
-
logger.log(log);
|
|
1433
|
-
}
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
function withTrailingSlash(path$1) {
|
|
1437
|
-
if (path$1[path$1.length - 1] !== "/") return `${path$1}/`;
|
|
1438
|
-
return path$1;
|
|
1439
|
-
}
|
|
1440
|
-
function ms(duration) {
|
|
1441
|
-
return duration < 1e3 ? `${duration.toFixed(2)} ms` : `${(duration / 1e3).toFixed(2)} s`;
|
|
1442
|
-
}
|
|
1443
|
-
function relativeId(id) {
|
|
1444
|
-
if (!path.isAbsolute(id)) return id;
|
|
1445
|
-
return path.relative(path.resolve(), id);
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
996
|
//#endregion
|
|
1449
997
|
//#region src/cli/arguments/alias.ts
|
|
1450
998
|
const alias = {
|
|
@@ -1663,6 +1211,458 @@ function parseCliArguments() {
|
|
|
1663
1211
|
return normalizeCliOptions(values, positionals);
|
|
1664
1212
|
}
|
|
1665
1213
|
|
|
1214
|
+
//#endregion
|
|
1215
|
+
//#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.js
|
|
1216
|
+
const signals = [];
|
|
1217
|
+
signals.push("SIGHUP", "SIGINT", "SIGTERM");
|
|
1218
|
+
if (process.platform !== "win32") signals.push(
|
|
1219
|
+
"SIGALRM",
|
|
1220
|
+
"SIGABRT",
|
|
1221
|
+
"SIGVTALRM",
|
|
1222
|
+
"SIGXCPU",
|
|
1223
|
+
"SIGXFSZ",
|
|
1224
|
+
"SIGUSR2",
|
|
1225
|
+
"SIGTRAP",
|
|
1226
|
+
"SIGSYS",
|
|
1227
|
+
"SIGQUIT",
|
|
1228
|
+
"SIGIOT"
|
|
1229
|
+
// should detect profiler and enable/disable accordingly.
|
|
1230
|
+
// see #21
|
|
1231
|
+
// 'SIGPROF'
|
|
1232
|
+
);
|
|
1233
|
+
if (process.platform === "linux") signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");
|
|
1234
|
+
|
|
1235
|
+
//#endregion
|
|
1236
|
+
//#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.js
|
|
1237
|
+
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";
|
|
1238
|
+
const kExitEmitter = Symbol.for("signal-exit emitter");
|
|
1239
|
+
const global = globalThis;
|
|
1240
|
+
const ObjectDefineProperty = Object.defineProperty.bind(Object);
|
|
1241
|
+
var Emitter = class {
|
|
1242
|
+
emitted = {
|
|
1243
|
+
afterExit: false,
|
|
1244
|
+
exit: false
|
|
1245
|
+
};
|
|
1246
|
+
listeners = {
|
|
1247
|
+
afterExit: [],
|
|
1248
|
+
exit: []
|
|
1249
|
+
};
|
|
1250
|
+
count = 0;
|
|
1251
|
+
id = Math.random();
|
|
1252
|
+
constructor() {
|
|
1253
|
+
if (global[kExitEmitter]) return global[kExitEmitter];
|
|
1254
|
+
ObjectDefineProperty(global, kExitEmitter, {
|
|
1255
|
+
value: this,
|
|
1256
|
+
writable: false,
|
|
1257
|
+
enumerable: false,
|
|
1258
|
+
configurable: false
|
|
1259
|
+
});
|
|
1260
|
+
}
|
|
1261
|
+
on(ev, fn) {
|
|
1262
|
+
this.listeners[ev].push(fn);
|
|
1263
|
+
}
|
|
1264
|
+
removeListener(ev, fn) {
|
|
1265
|
+
const list = this.listeners[ev];
|
|
1266
|
+
const i$1 = list.indexOf(fn);
|
|
1267
|
+
if (i$1 === -1) return;
|
|
1268
|
+
if (i$1 === 0 && list.length === 1) list.length = 0;
|
|
1269
|
+
else list.splice(i$1, 1);
|
|
1270
|
+
}
|
|
1271
|
+
emit(ev, code, signal) {
|
|
1272
|
+
if (this.emitted[ev]) return false;
|
|
1273
|
+
this.emitted[ev] = true;
|
|
1274
|
+
let ret = false;
|
|
1275
|
+
for (const fn of this.listeners[ev]) ret = fn(code, signal) === true || ret;
|
|
1276
|
+
if (ev === "exit") ret = this.emit("afterExit", code, signal) || ret;
|
|
1277
|
+
return ret;
|
|
1278
|
+
}
|
|
1279
|
+
};
|
|
1280
|
+
var SignalExitBase = class {};
|
|
1281
|
+
const signalExitWrap = (handler) => {
|
|
1282
|
+
return {
|
|
1283
|
+
onExit(cb, opts) {
|
|
1284
|
+
return handler.onExit(cb, opts);
|
|
1285
|
+
},
|
|
1286
|
+
load() {
|
|
1287
|
+
return handler.load();
|
|
1288
|
+
},
|
|
1289
|
+
unload() {
|
|
1290
|
+
return handler.unload();
|
|
1291
|
+
}
|
|
1292
|
+
};
|
|
1293
|
+
};
|
|
1294
|
+
var SignalExitFallback = class extends SignalExitBase {
|
|
1295
|
+
onExit() {
|
|
1296
|
+
return () => {};
|
|
1297
|
+
}
|
|
1298
|
+
load() {}
|
|
1299
|
+
unload() {}
|
|
1300
|
+
};
|
|
1301
|
+
var SignalExit = class extends SignalExitBase {
|
|
1302
|
+
#hupSig = process$2.platform === "win32" ? "SIGINT" : "SIGHUP";
|
|
1303
|
+
#emitter = new Emitter();
|
|
1304
|
+
#process;
|
|
1305
|
+
#originalProcessEmit;
|
|
1306
|
+
#originalProcessReallyExit;
|
|
1307
|
+
#sigListeners = {};
|
|
1308
|
+
#loaded = false;
|
|
1309
|
+
constructor(process$3) {
|
|
1310
|
+
super();
|
|
1311
|
+
this.#process = process$3;
|
|
1312
|
+
this.#sigListeners = {};
|
|
1313
|
+
for (const sig of signals) this.#sigListeners[sig] = () => {
|
|
1314
|
+
const listeners = this.#process.listeners(sig);
|
|
1315
|
+
let { count } = this.#emitter;
|
|
1316
|
+
const p = process$3;
|
|
1317
|
+
if (typeof p.__signal_exit_emitter__ === "object" && typeof p.__signal_exit_emitter__.count === "number") count += p.__signal_exit_emitter__.count;
|
|
1318
|
+
if (listeners.length === count) {
|
|
1319
|
+
this.unload();
|
|
1320
|
+
const ret = this.#emitter.emit("exit", null, sig);
|
|
1321
|
+
const s$1 = sig === "SIGHUP" ? this.#hupSig : sig;
|
|
1322
|
+
if (!ret) process$3.kill(process$3.pid, s$1);
|
|
1323
|
+
}
|
|
1324
|
+
};
|
|
1325
|
+
this.#originalProcessReallyExit = process$3.reallyExit;
|
|
1326
|
+
this.#originalProcessEmit = process$3.emit;
|
|
1327
|
+
}
|
|
1328
|
+
onExit(cb, opts) {
|
|
1329
|
+
if (!processOk(this.#process)) return () => {};
|
|
1330
|
+
if (this.#loaded === false) this.load();
|
|
1331
|
+
const ev = opts?.alwaysLast ? "afterExit" : "exit";
|
|
1332
|
+
this.#emitter.on(ev, cb);
|
|
1333
|
+
return () => {
|
|
1334
|
+
this.#emitter.removeListener(ev, cb);
|
|
1335
|
+
if (this.#emitter.listeners["exit"].length === 0 && this.#emitter.listeners["afterExit"].length === 0) this.unload();
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
load() {
|
|
1339
|
+
if (this.#loaded) return;
|
|
1340
|
+
this.#loaded = true;
|
|
1341
|
+
this.#emitter.count += 1;
|
|
1342
|
+
for (const sig of signals) try {
|
|
1343
|
+
const fn = this.#sigListeners[sig];
|
|
1344
|
+
if (fn) this.#process.on(sig, fn);
|
|
1345
|
+
} catch (_$1) {}
|
|
1346
|
+
this.#process.emit = (ev, ...a$1) => {
|
|
1347
|
+
return this.#processEmit(ev, ...a$1);
|
|
1348
|
+
};
|
|
1349
|
+
this.#process.reallyExit = (code) => {
|
|
1350
|
+
return this.#processReallyExit(code);
|
|
1351
|
+
};
|
|
1352
|
+
}
|
|
1353
|
+
unload() {
|
|
1354
|
+
if (!this.#loaded) return;
|
|
1355
|
+
this.#loaded = false;
|
|
1356
|
+
signals.forEach((sig) => {
|
|
1357
|
+
const listener = this.#sigListeners[sig];
|
|
1358
|
+
if (!listener) throw new Error("Listener not defined for signal: " + sig);
|
|
1359
|
+
try {
|
|
1360
|
+
this.#process.removeListener(sig, listener);
|
|
1361
|
+
} catch (_$1) {}
|
|
1362
|
+
});
|
|
1363
|
+
this.#process.emit = this.#originalProcessEmit;
|
|
1364
|
+
this.#process.reallyExit = this.#originalProcessReallyExit;
|
|
1365
|
+
this.#emitter.count -= 1;
|
|
1366
|
+
}
|
|
1367
|
+
#processReallyExit(code) {
|
|
1368
|
+
if (!processOk(this.#process)) return 0;
|
|
1369
|
+
this.#process.exitCode = code || 0;
|
|
1370
|
+
this.#emitter.emit("exit", this.#process.exitCode, null);
|
|
1371
|
+
return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode);
|
|
1372
|
+
}
|
|
1373
|
+
#processEmit(ev, ...args) {
|
|
1374
|
+
const og = this.#originalProcessEmit;
|
|
1375
|
+
if (ev === "exit" && processOk(this.#process)) {
|
|
1376
|
+
if (typeof args[0] === "number") this.#process.exitCode = args[0];
|
|
1377
|
+
const ret = og.call(this.#process, ev, ...args);
|
|
1378
|
+
this.#emitter.emit("exit", this.#process.exitCode, null);
|
|
1379
|
+
return ret;
|
|
1380
|
+
} else return og.call(this.#process, ev, ...args);
|
|
1381
|
+
}
|
|
1382
|
+
};
|
|
1383
|
+
const process$2 = globalThis.process;
|
|
1384
|
+
const { onExit, load, unload } = signalExitWrap(processOk(process$2) ? new SignalExit(process$2) : new SignalExitFallback());
|
|
1385
|
+
|
|
1386
|
+
//#endregion
|
|
1387
|
+
//#region src/cli/load-config.ts
|
|
1388
|
+
async function bundleTsConfig(configFile, isEsm) {
|
|
1389
|
+
const dirnameVarName = "injected_original_dirname";
|
|
1390
|
+
const filenameVarName = "injected_original_filename";
|
|
1391
|
+
const importMetaUrlVarName = "injected_original_import_meta_url";
|
|
1392
|
+
const bundle = await rolldown({
|
|
1393
|
+
input: configFile,
|
|
1394
|
+
platform: "node",
|
|
1395
|
+
resolve: { mainFields: ["main"] },
|
|
1396
|
+
define: {
|
|
1397
|
+
__dirname: dirnameVarName,
|
|
1398
|
+
__filename: filenameVarName,
|
|
1399
|
+
"import.meta.url": importMetaUrlVarName,
|
|
1400
|
+
"import.meta.dirname": dirnameVarName,
|
|
1401
|
+
"import.meta.filename": filenameVarName
|
|
1402
|
+
},
|
|
1403
|
+
treeshake: false,
|
|
1404
|
+
external: [/^[\w@][^:]/],
|
|
1405
|
+
plugins: [{
|
|
1406
|
+
name: "inject-file-scope-variables",
|
|
1407
|
+
transform: {
|
|
1408
|
+
filter: { id: /\.[cm]?[jt]s$/ },
|
|
1409
|
+
async handler(code, id) {
|
|
1410
|
+
const injectValues = `const ${dirnameVarName} = ${JSON.stringify(path.dirname(id))};const ${filenameVarName} = ${JSON.stringify(id)};const ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(id).href)};`;
|
|
1411
|
+
return {
|
|
1412
|
+
code: injectValues + code,
|
|
1413
|
+
map: null
|
|
1414
|
+
};
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
}]
|
|
1418
|
+
});
|
|
1419
|
+
const outputDir = path.dirname(configFile);
|
|
1420
|
+
const result = await bundle.write({
|
|
1421
|
+
dir: outputDir,
|
|
1422
|
+
format: isEsm ? "esm" : "cjs",
|
|
1423
|
+
sourcemap: "inline",
|
|
1424
|
+
entryFileNames: `rolldown.config.[hash]${path.extname(configFile).replace("ts", "js")}`
|
|
1425
|
+
});
|
|
1426
|
+
const fileName = result.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
|
|
1427
|
+
return path.join(outputDir, fileName);
|
|
1428
|
+
}
|
|
1429
|
+
const SUPPORTED_JS_CONFIG_FORMATS = [
|
|
1430
|
+
".js",
|
|
1431
|
+
".mjs",
|
|
1432
|
+
".cjs"
|
|
1433
|
+
];
|
|
1434
|
+
const SUPPORTED_TS_CONFIG_FORMATS = [
|
|
1435
|
+
".ts",
|
|
1436
|
+
".mts",
|
|
1437
|
+
".cts"
|
|
1438
|
+
];
|
|
1439
|
+
const SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
|
|
1440
|
+
const DEFAULT_CONFIG_BASE = "rolldown.config";
|
|
1441
|
+
async function findConfigFileNameInCwd() {
|
|
1442
|
+
const filesInWorkingDirectory = new Set(await readdir(cwd()));
|
|
1443
|
+
for (const extension of SUPPORTED_CONFIG_FORMATS) {
|
|
1444
|
+
const fileName = `${DEFAULT_CONFIG_BASE}${extension}`;
|
|
1445
|
+
if (filesInWorkingDirectory.has(fileName)) return fileName;
|
|
1446
|
+
}
|
|
1447
|
+
throw new Error("No `rolldown.config` configuration file found.");
|
|
1448
|
+
}
|
|
1449
|
+
async function loadTsConfig(configFile) {
|
|
1450
|
+
const isEsm = isFilePathESM(configFile);
|
|
1451
|
+
const file = await bundleTsConfig(configFile, isEsm);
|
|
1452
|
+
try {
|
|
1453
|
+
return (await import(pathToFileURL(file).href)).default;
|
|
1454
|
+
} finally {
|
|
1455
|
+
fs.unlink(file, () => {});
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
function isFilePathESM(filePath) {
|
|
1459
|
+
if (/\.m[jt]s$/.test(filePath)) return true;
|
|
1460
|
+
else if (/\.c[jt]s$/.test(filePath)) return false;
|
|
1461
|
+
else {
|
|
1462
|
+
const pkg = findNearestPackageData(path.dirname(filePath));
|
|
1463
|
+
if (pkg) return pkg.type === "module";
|
|
1464
|
+
return false;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
function findNearestPackageData(basedir) {
|
|
1468
|
+
while (basedir) {
|
|
1469
|
+
const pkgPath = path.join(basedir, "package.json");
|
|
1470
|
+
if (tryStatSync(pkgPath)?.isFile()) try {
|
|
1471
|
+
return JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
1472
|
+
} catch {}
|
|
1473
|
+
const nextBasedir = path.dirname(basedir);
|
|
1474
|
+
if (nextBasedir === basedir) break;
|
|
1475
|
+
basedir = nextBasedir;
|
|
1476
|
+
}
|
|
1477
|
+
return null;
|
|
1478
|
+
}
|
|
1479
|
+
function tryStatSync(file) {
|
|
1480
|
+
try {
|
|
1481
|
+
return fs.statSync(file, { throwIfNoEntry: false });
|
|
1482
|
+
} catch {}
|
|
1483
|
+
}
|
|
1484
|
+
async function loadConfig(configPath) {
|
|
1485
|
+
const ext = path.extname(configPath = configPath || await findConfigFileNameInCwd());
|
|
1486
|
+
try {
|
|
1487
|
+
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;
|
|
1488
|
+
else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) {
|
|
1489
|
+
const rawConfigPath = path.resolve(configPath);
|
|
1490
|
+
return await loadTsConfig(rawConfigPath);
|
|
1491
|
+
} else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
|
|
1492
|
+
} catch (err) {
|
|
1493
|
+
throw new Error("Error happened while loading config.", { cause: err });
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
//#endregion
|
|
1498
|
+
//#region src/cli/commands/bundle.ts
|
|
1499
|
+
async function bundleWithConfig(configPath, cliOptions) {
|
|
1500
|
+
const config = await loadConfig(configPath);
|
|
1501
|
+
if (!config) {
|
|
1502
|
+
logger.error(`No configuration found at ${config}`);
|
|
1503
|
+
process.exit(1);
|
|
1504
|
+
}
|
|
1505
|
+
if (cliOptions.watch) await watchInner(config, cliOptions);
|
|
1506
|
+
else await bundleInner(config, cliOptions);
|
|
1507
|
+
}
|
|
1508
|
+
async function bundleWithCliOptions(cliOptions) {
|
|
1509
|
+
if (cliOptions.output.dir || cliOptions.output.file) {
|
|
1510
|
+
const operation = cliOptions.watch ? watchInner : bundleInner;
|
|
1511
|
+
await operation({}, cliOptions);
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1514
|
+
if (cliOptions.watch) {
|
|
1515
|
+
logger.error("You must specify `output.dir` to use watch mode");
|
|
1516
|
+
process.exit(1);
|
|
1517
|
+
}
|
|
1518
|
+
const build = await rolldown(cliOptions.input);
|
|
1519
|
+
try {
|
|
1520
|
+
const { output: outputs } = await build.generate(cliOptions.output);
|
|
1521
|
+
if (outputs.length === 0) {
|
|
1522
|
+
logger.error("No output generated");
|
|
1523
|
+
process.exit(1);
|
|
1524
|
+
}
|
|
1525
|
+
for (const file of outputs) {
|
|
1526
|
+
if (outputs.length > 1) logger.log(`\n${colors.cyan(colors.bold(`|→ ${file.fileName}:`))}\n`);
|
|
1527
|
+
console.log(file.type === "asset" ? file.source : file.code);
|
|
1528
|
+
}
|
|
1529
|
+
} finally {
|
|
1530
|
+
await build.close();
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
async function watchInner(config, cliOptions) {
|
|
1534
|
+
process.env.ROLLUP_WATCH = "true";
|
|
1535
|
+
process.env.ROLLDOWN_WATCH = "true";
|
|
1536
|
+
let normalizedConfig = arraify(config).map((option) => {
|
|
1537
|
+
return {
|
|
1538
|
+
...option,
|
|
1539
|
+
...cliOptions.input,
|
|
1540
|
+
output: arraify(option.output || {}).map((output) => {
|
|
1541
|
+
return {
|
|
1542
|
+
...output,
|
|
1543
|
+
...cliOptions.output
|
|
1544
|
+
};
|
|
1545
|
+
})
|
|
1546
|
+
};
|
|
1547
|
+
});
|
|
1548
|
+
const watcher = await watch(normalizedConfig);
|
|
1549
|
+
onExit((code) => {
|
|
1550
|
+
Promise.resolve(watcher.close()).finally(() => {
|
|
1551
|
+
process.exit(typeof code === "number" ? code : 0);
|
|
1552
|
+
});
|
|
1553
|
+
return true;
|
|
1554
|
+
});
|
|
1555
|
+
const changedFile = [];
|
|
1556
|
+
watcher.on("change", (id, event) => {
|
|
1557
|
+
if (event.event === "update") changedFile.push(id);
|
|
1558
|
+
});
|
|
1559
|
+
watcher.on("event", (event) => {
|
|
1560
|
+
switch (event.code) {
|
|
1561
|
+
case "BUNDLE_START":
|
|
1562
|
+
if (changedFile.length > 0) logger.log(`Found ${colors.bold(changedFile.map(relativeId).join(", "))} changed, rebuilding...`);
|
|
1563
|
+
changedFile.length = 0;
|
|
1564
|
+
break;
|
|
1565
|
+
case "BUNDLE_END":
|
|
1566
|
+
logger.success(`Rebuilt ${colors.bold(relativeId(event.output[0]))} in ${colors.bold(ms(event.duration))}.`);
|
|
1567
|
+
break;
|
|
1568
|
+
case "ERROR":
|
|
1569
|
+
logger.error(event.error);
|
|
1570
|
+
break;
|
|
1571
|
+
default: break;
|
|
1572
|
+
}
|
|
1573
|
+
});
|
|
1574
|
+
logger.log(`Waiting for changes...`);
|
|
1575
|
+
}
|
|
1576
|
+
async function bundleInner(config, cliOptions) {
|
|
1577
|
+
const startTime = performance.now();
|
|
1578
|
+
const result = [];
|
|
1579
|
+
const configList = arraify(config);
|
|
1580
|
+
for (const config$1 of configList) {
|
|
1581
|
+
const outputList = arraify(config$1.output || {});
|
|
1582
|
+
const build = await rolldown({
|
|
1583
|
+
...config$1,
|
|
1584
|
+
...cliOptions.input
|
|
1585
|
+
});
|
|
1586
|
+
for (const output of outputList) try {
|
|
1587
|
+
result.push(await build.write({
|
|
1588
|
+
...output,
|
|
1589
|
+
...cliOptions.output
|
|
1590
|
+
}));
|
|
1591
|
+
} finally {
|
|
1592
|
+
await build.close();
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
result.forEach(printBundleOutputPretty);
|
|
1596
|
+
logger.log(``);
|
|
1597
|
+
const endTime = performance.now();
|
|
1598
|
+
const duration = endTime - startTime;
|
|
1599
|
+
logger.success(`Finished in ${colors.bold(ms(duration))}`);
|
|
1600
|
+
}
|
|
1601
|
+
function printBundleOutputPretty(output) {
|
|
1602
|
+
const outputEntries = collectOutputEntries(output.output);
|
|
1603
|
+
const outputLayoutSizes = collectOutputLayoutAdjustmentSizes(outputEntries);
|
|
1604
|
+
printOutputEntries(outputEntries, outputLayoutSizes, "<DIR>");
|
|
1605
|
+
}
|
|
1606
|
+
function collectOutputEntries(output) {
|
|
1607
|
+
return output.map((chunk) => ({
|
|
1608
|
+
type: chunk.type,
|
|
1609
|
+
fileName: chunk.fileName,
|
|
1610
|
+
size: chunk.type === "chunk" ? Buffer.byteLength(chunk.code) : Buffer.byteLength(chunk.source)
|
|
1611
|
+
}));
|
|
1612
|
+
}
|
|
1613
|
+
function collectOutputLayoutAdjustmentSizes(entries) {
|
|
1614
|
+
let longest = 0;
|
|
1615
|
+
let biggestSize = 0;
|
|
1616
|
+
for (const entry of entries) {
|
|
1617
|
+
if (entry.fileName.length > longest) longest = entry.fileName.length;
|
|
1618
|
+
if (entry.size > biggestSize) biggestSize = entry.size;
|
|
1619
|
+
}
|
|
1620
|
+
const sizePad = displaySize(biggestSize).length;
|
|
1621
|
+
return {
|
|
1622
|
+
longest,
|
|
1623
|
+
biggestSize,
|
|
1624
|
+
sizePad
|
|
1625
|
+
};
|
|
1626
|
+
}
|
|
1627
|
+
const numberFormatter = new Intl.NumberFormat("en", {
|
|
1628
|
+
maximumFractionDigits: 2,
|
|
1629
|
+
minimumFractionDigits: 2
|
|
1630
|
+
});
|
|
1631
|
+
function displaySize(bytes) {
|
|
1632
|
+
return `${numberFormatter.format(bytes / 1e3)} kB`;
|
|
1633
|
+
}
|
|
1634
|
+
const CHUNK_GROUPS = [{
|
|
1635
|
+
type: "asset",
|
|
1636
|
+
color: "green"
|
|
1637
|
+
}, {
|
|
1638
|
+
type: "chunk",
|
|
1639
|
+
color: "cyan"
|
|
1640
|
+
}];
|
|
1641
|
+
function printOutputEntries(entries, sizeAdjustment, distPath) {
|
|
1642
|
+
for (const group of CHUNK_GROUPS) {
|
|
1643
|
+
const filtered = entries.filter((e) => e.type === group.type);
|
|
1644
|
+
if (!filtered.length) continue;
|
|
1645
|
+
for (const entry of filtered.sort((a$1, z) => a$1.size - z.size)) {
|
|
1646
|
+
let log = colors.dim(withTrailingSlash(distPath));
|
|
1647
|
+
log += colors[group.color](entry.fileName.padEnd(sizeAdjustment.longest + 2));
|
|
1648
|
+
log += colors.dim(entry.type);
|
|
1649
|
+
log += colors.dim(` │ size: ${displaySize(entry.size).padStart(sizeAdjustment.sizePad)}`);
|
|
1650
|
+
logger.log(log);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
function withTrailingSlash(path$1) {
|
|
1655
|
+
if (path$1[path$1.length - 1] !== "/") return `${path$1}/`;
|
|
1656
|
+
return path$1;
|
|
1657
|
+
}
|
|
1658
|
+
function ms(duration) {
|
|
1659
|
+
return duration < 1e3 ? `${duration.toFixed(2)} ms` : `${(duration / 1e3).toFixed(2)} s`;
|
|
1660
|
+
}
|
|
1661
|
+
function relativeId(id) {
|
|
1662
|
+
if (!path.isAbsolute(id)) return id;
|
|
1663
|
+
return path.relative(path.resolve(), id);
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
1666
|
//#endregion
|
|
1667
1667
|
//#region src/cli/commands/help.ts
|
|
1668
1668
|
const introduction = `${colors.gray(`${description} (rolldown v${version})`)}
|