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/cjs/cli.cjs
CHANGED
|
@@ -1,188 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const require_chunk = require('../shared/chunk-qZFfknuJ.cjs');
|
|
3
|
-
const require_src = require('../shared/src-
|
|
4
|
-
const require_parse_ast_index = require('../shared/parse-ast-index-
|
|
5
|
-
const node_process = require_chunk.__toESM(require("node:process"));
|
|
6
|
-
const node_path = require_chunk.__toESM(require("node:path"));
|
|
3
|
+
const require_src = require('../shared/src-BPcsb-4N.cjs');
|
|
4
|
+
const require_parse_ast_index = require('../shared/parse-ast-index-0ei4fTjl.cjs');
|
|
7
5
|
const node_fs = require_chunk.__toESM(require("node:fs"));
|
|
8
|
-
const
|
|
6
|
+
const node_path = require_chunk.__toESM(require("node:path"));
|
|
7
|
+
const node_process = require_chunk.__toESM(require("node:process"));
|
|
9
8
|
const node_util = require_chunk.__toESM(require("node:util"));
|
|
10
9
|
const node_tty = require_chunk.__toESM(require("node:tty"));
|
|
10
|
+
const node_perf_hooks = require_chunk.__toESM(require("node:perf_hooks"));
|
|
11
11
|
const node_fs_promises = require_chunk.__toESM(require("node:fs/promises"));
|
|
12
12
|
const node_url = require_chunk.__toESM(require("node:url"));
|
|
13
13
|
|
|
14
|
-
//#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.js
|
|
15
|
-
const signals = [];
|
|
16
|
-
signals.push("SIGHUP", "SIGINT", "SIGTERM");
|
|
17
|
-
if (process.platform !== "win32") signals.push(
|
|
18
|
-
"SIGALRM",
|
|
19
|
-
"SIGABRT",
|
|
20
|
-
"SIGVTALRM",
|
|
21
|
-
"SIGXCPU",
|
|
22
|
-
"SIGXFSZ",
|
|
23
|
-
"SIGUSR2",
|
|
24
|
-
"SIGTRAP",
|
|
25
|
-
"SIGSYS",
|
|
26
|
-
"SIGQUIT",
|
|
27
|
-
"SIGIOT"
|
|
28
|
-
// should detect profiler and enable/disable accordingly.
|
|
29
|
-
// see #21
|
|
30
|
-
// 'SIGPROF'
|
|
31
|
-
);
|
|
32
|
-
if (process.platform === "linux") signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");
|
|
33
|
-
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.js
|
|
36
|
-
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";
|
|
37
|
-
const kExitEmitter = Symbol.for("signal-exit emitter");
|
|
38
|
-
const global = globalThis;
|
|
39
|
-
const ObjectDefineProperty = Object.defineProperty.bind(Object);
|
|
40
|
-
var Emitter = class {
|
|
41
|
-
emitted = {
|
|
42
|
-
afterExit: false,
|
|
43
|
-
exit: false
|
|
44
|
-
};
|
|
45
|
-
listeners = {
|
|
46
|
-
afterExit: [],
|
|
47
|
-
exit: []
|
|
48
|
-
};
|
|
49
|
-
count = 0;
|
|
50
|
-
id = Math.random();
|
|
51
|
-
constructor() {
|
|
52
|
-
if (global[kExitEmitter]) return global[kExitEmitter];
|
|
53
|
-
ObjectDefineProperty(global, kExitEmitter, {
|
|
54
|
-
value: this,
|
|
55
|
-
writable: false,
|
|
56
|
-
enumerable: false,
|
|
57
|
-
configurable: false
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
on(ev, fn) {
|
|
61
|
-
this.listeners[ev].push(fn);
|
|
62
|
-
}
|
|
63
|
-
removeListener(ev, fn) {
|
|
64
|
-
const list = this.listeners[ev];
|
|
65
|
-
const i$1 = list.indexOf(fn);
|
|
66
|
-
if (i$1 === -1) return;
|
|
67
|
-
if (i$1 === 0 && list.length === 1) list.length = 0;
|
|
68
|
-
else list.splice(i$1, 1);
|
|
69
|
-
}
|
|
70
|
-
emit(ev, code, signal) {
|
|
71
|
-
if (this.emitted[ev]) return false;
|
|
72
|
-
this.emitted[ev] = true;
|
|
73
|
-
let ret = false;
|
|
74
|
-
for (const fn of this.listeners[ev]) ret = fn(code, signal) === true || ret;
|
|
75
|
-
if (ev === "exit") ret = this.emit("afterExit", code, signal) || ret;
|
|
76
|
-
return ret;
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
var SignalExitBase = class {};
|
|
80
|
-
const signalExitWrap = (handler) => {
|
|
81
|
-
return {
|
|
82
|
-
onExit(cb, opts) {
|
|
83
|
-
return handler.onExit(cb, opts);
|
|
84
|
-
},
|
|
85
|
-
load() {
|
|
86
|
-
return handler.load();
|
|
87
|
-
},
|
|
88
|
-
unload() {
|
|
89
|
-
return handler.unload();
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
var SignalExitFallback = class extends SignalExitBase {
|
|
94
|
-
onExit() {
|
|
95
|
-
return () => {};
|
|
96
|
-
}
|
|
97
|
-
load() {}
|
|
98
|
-
unload() {}
|
|
99
|
-
};
|
|
100
|
-
var SignalExit = class extends SignalExitBase {
|
|
101
|
-
#hupSig = process$2.platform === "win32" ? "SIGINT" : "SIGHUP";
|
|
102
|
-
#emitter = new Emitter();
|
|
103
|
-
#process;
|
|
104
|
-
#originalProcessEmit;
|
|
105
|
-
#originalProcessReallyExit;
|
|
106
|
-
#sigListeners = {};
|
|
107
|
-
#loaded = false;
|
|
108
|
-
constructor(process$3) {
|
|
109
|
-
super();
|
|
110
|
-
this.#process = process$3;
|
|
111
|
-
this.#sigListeners = {};
|
|
112
|
-
for (const sig of signals) this.#sigListeners[sig] = () => {
|
|
113
|
-
const listeners = this.#process.listeners(sig);
|
|
114
|
-
let { count } = this.#emitter;
|
|
115
|
-
const p = process$3;
|
|
116
|
-
if (typeof p.__signal_exit_emitter__ === "object" && typeof p.__signal_exit_emitter__.count === "number") count += p.__signal_exit_emitter__.count;
|
|
117
|
-
if (listeners.length === count) {
|
|
118
|
-
this.unload();
|
|
119
|
-
const ret = this.#emitter.emit("exit", null, sig);
|
|
120
|
-
const s$1 = sig === "SIGHUP" ? this.#hupSig : sig;
|
|
121
|
-
if (!ret) process$3.kill(process$3.pid, s$1);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
this.#originalProcessReallyExit = process$3.reallyExit;
|
|
125
|
-
this.#originalProcessEmit = process$3.emit;
|
|
126
|
-
}
|
|
127
|
-
onExit(cb, opts) {
|
|
128
|
-
if (!processOk(this.#process)) return () => {};
|
|
129
|
-
if (this.#loaded === false) this.load();
|
|
130
|
-
const ev = opts?.alwaysLast ? "afterExit" : "exit";
|
|
131
|
-
this.#emitter.on(ev, cb);
|
|
132
|
-
return () => {
|
|
133
|
-
this.#emitter.removeListener(ev, cb);
|
|
134
|
-
if (this.#emitter.listeners["exit"].length === 0 && this.#emitter.listeners["afterExit"].length === 0) this.unload();
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
load() {
|
|
138
|
-
if (this.#loaded) return;
|
|
139
|
-
this.#loaded = true;
|
|
140
|
-
this.#emitter.count += 1;
|
|
141
|
-
for (const sig of signals) try {
|
|
142
|
-
const fn = this.#sigListeners[sig];
|
|
143
|
-
if (fn) this.#process.on(sig, fn);
|
|
144
|
-
} catch (_$1) {}
|
|
145
|
-
this.#process.emit = (ev, ...a$1) => {
|
|
146
|
-
return this.#processEmit(ev, ...a$1);
|
|
147
|
-
};
|
|
148
|
-
this.#process.reallyExit = (code) => {
|
|
149
|
-
return this.#processReallyExit(code);
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
unload() {
|
|
153
|
-
if (!this.#loaded) return;
|
|
154
|
-
this.#loaded = false;
|
|
155
|
-
signals.forEach((sig) => {
|
|
156
|
-
const listener = this.#sigListeners[sig];
|
|
157
|
-
if (!listener) throw new Error("Listener not defined for signal: " + sig);
|
|
158
|
-
try {
|
|
159
|
-
this.#process.removeListener(sig, listener);
|
|
160
|
-
} catch (_$1) {}
|
|
161
|
-
});
|
|
162
|
-
this.#process.emit = this.#originalProcessEmit;
|
|
163
|
-
this.#process.reallyExit = this.#originalProcessReallyExit;
|
|
164
|
-
this.#emitter.count -= 1;
|
|
165
|
-
}
|
|
166
|
-
#processReallyExit(code) {
|
|
167
|
-
if (!processOk(this.#process)) return 0;
|
|
168
|
-
this.#process.exitCode = code || 0;
|
|
169
|
-
this.#emitter.emit("exit", this.#process.exitCode, null);
|
|
170
|
-
return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode);
|
|
171
|
-
}
|
|
172
|
-
#processEmit(ev, ...args) {
|
|
173
|
-
const og = this.#originalProcessEmit;
|
|
174
|
-
if (ev === "exit" && processOk(this.#process)) {
|
|
175
|
-
if (typeof args[0] === "number") this.#process.exitCode = args[0];
|
|
176
|
-
const ret = og.call(this.#process, ev, ...args);
|
|
177
|
-
this.#emitter.emit("exit", this.#process.exitCode, null);
|
|
178
|
-
return ret;
|
|
179
|
-
} else return og.call(this.#process, ev, ...args);
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
const process$2 = globalThis.process;
|
|
183
|
-
const { onExit, load, unload } = signalExitWrap(processOk(process$2) ? new SignalExit(process$2) : new SignalExitFallback());
|
|
184
|
-
|
|
185
|
-
//#endregion
|
|
186
14
|
//#region ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/core.mjs
|
|
187
15
|
const LogLevels = {
|
|
188
16
|
silent: Number.NEGATIVE_INFINITY,
|
|
@@ -1169,286 +997,6 @@ function createTestingLogger() {
|
|
|
1169
997
|
return ret;
|
|
1170
998
|
}
|
|
1171
999
|
|
|
1172
|
-
//#endregion
|
|
1173
|
-
//#region src/cli/load-config.ts
|
|
1174
|
-
async function bundleTsConfig(configFile, isEsm) {
|
|
1175
|
-
const dirnameVarName = "injected_original_dirname";
|
|
1176
|
-
const filenameVarName = "injected_original_filename";
|
|
1177
|
-
const importMetaUrlVarName = "injected_original_import_meta_url";
|
|
1178
|
-
const bundle = await require_src.rolldown({
|
|
1179
|
-
input: configFile,
|
|
1180
|
-
platform: "node",
|
|
1181
|
-
resolve: { mainFields: ["main"] },
|
|
1182
|
-
define: {
|
|
1183
|
-
__dirname: dirnameVarName,
|
|
1184
|
-
__filename: filenameVarName,
|
|
1185
|
-
"import.meta.url": importMetaUrlVarName,
|
|
1186
|
-
"import.meta.dirname": dirnameVarName,
|
|
1187
|
-
"import.meta.filename": filenameVarName
|
|
1188
|
-
},
|
|
1189
|
-
treeshake: false,
|
|
1190
|
-
external: [/^[\w@][^:]/],
|
|
1191
|
-
plugins: [{
|
|
1192
|
-
name: "inject-file-scope-variables",
|
|
1193
|
-
transform: {
|
|
1194
|
-
filter: { id: /\.[cm]?[jt]s$/ },
|
|
1195
|
-
async handler(code, id) {
|
|
1196
|
-
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)};`;
|
|
1197
|
-
return {
|
|
1198
|
-
code: injectValues + code,
|
|
1199
|
-
map: null
|
|
1200
|
-
};
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
}]
|
|
1204
|
-
});
|
|
1205
|
-
const outputDir = node_path.default.dirname(configFile);
|
|
1206
|
-
const result = await bundle.write({
|
|
1207
|
-
dir: outputDir,
|
|
1208
|
-
format: isEsm ? "esm" : "cjs",
|
|
1209
|
-
sourcemap: "inline",
|
|
1210
|
-
entryFileNames: `rolldown.config.[hash]${node_path.default.extname(configFile).replace("ts", "js")}`
|
|
1211
|
-
});
|
|
1212
|
-
const fileName = result.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
|
|
1213
|
-
return node_path.default.join(outputDir, fileName);
|
|
1214
|
-
}
|
|
1215
|
-
const SUPPORTED_JS_CONFIG_FORMATS = [
|
|
1216
|
-
".js",
|
|
1217
|
-
".mjs",
|
|
1218
|
-
".cjs"
|
|
1219
|
-
];
|
|
1220
|
-
const SUPPORTED_TS_CONFIG_FORMATS = [
|
|
1221
|
-
".ts",
|
|
1222
|
-
".mts",
|
|
1223
|
-
".cts"
|
|
1224
|
-
];
|
|
1225
|
-
const SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
|
|
1226
|
-
const DEFAULT_CONFIG_BASE = "rolldown.config";
|
|
1227
|
-
async function findConfigFileNameInCwd() {
|
|
1228
|
-
const filesInWorkingDirectory = new Set(await (0, node_fs_promises.readdir)((0, node_process.cwd)()));
|
|
1229
|
-
for (const extension of SUPPORTED_CONFIG_FORMATS) {
|
|
1230
|
-
const fileName = `${DEFAULT_CONFIG_BASE}${extension}`;
|
|
1231
|
-
if (filesInWorkingDirectory.has(fileName)) return fileName;
|
|
1232
|
-
}
|
|
1233
|
-
throw new Error("No `rolldown.config` configuration file found.");
|
|
1234
|
-
}
|
|
1235
|
-
async function loadTsConfig(configFile) {
|
|
1236
|
-
const isEsm = isFilePathESM(configFile);
|
|
1237
|
-
const file = await bundleTsConfig(configFile, isEsm);
|
|
1238
|
-
try {
|
|
1239
|
-
return (await import((0, node_url.pathToFileURL)(file).href)).default;
|
|
1240
|
-
} finally {
|
|
1241
|
-
node_fs.default.unlink(file, () => {});
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
function isFilePathESM(filePath) {
|
|
1245
|
-
if (/\.m[jt]s$/.test(filePath)) return true;
|
|
1246
|
-
else if (/\.c[jt]s$/.test(filePath)) return false;
|
|
1247
|
-
else {
|
|
1248
|
-
const pkg = findNearestPackageData(node_path.default.dirname(filePath));
|
|
1249
|
-
if (pkg) return pkg.type === "module";
|
|
1250
|
-
return false;
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
function findNearestPackageData(basedir) {
|
|
1254
|
-
while (basedir) {
|
|
1255
|
-
const pkgPath = node_path.default.join(basedir, "package.json");
|
|
1256
|
-
if (tryStatSync(pkgPath)?.isFile()) try {
|
|
1257
|
-
return JSON.parse(node_fs.default.readFileSync(pkgPath, "utf-8"));
|
|
1258
|
-
} catch {}
|
|
1259
|
-
const nextBasedir = node_path.default.dirname(basedir);
|
|
1260
|
-
if (nextBasedir === basedir) break;
|
|
1261
|
-
basedir = nextBasedir;
|
|
1262
|
-
}
|
|
1263
|
-
return null;
|
|
1264
|
-
}
|
|
1265
|
-
function tryStatSync(file) {
|
|
1266
|
-
try {
|
|
1267
|
-
return node_fs.default.statSync(file, { throwIfNoEntry: false });
|
|
1268
|
-
} catch {}
|
|
1269
|
-
}
|
|
1270
|
-
async function loadConfig(configPath) {
|
|
1271
|
-
const ext = node_path.default.extname(configPath = configPath || await findConfigFileNameInCwd());
|
|
1272
|
-
try {
|
|
1273
|
-
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;
|
|
1274
|
-
else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) {
|
|
1275
|
-
const rawConfigPath = node_path.default.resolve(configPath);
|
|
1276
|
-
return await loadTsConfig(rawConfigPath);
|
|
1277
|
-
} else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
|
|
1278
|
-
} catch (err) {
|
|
1279
|
-
throw new Error("Error happened while loading config.", { cause: err });
|
|
1280
|
-
}
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
//#endregion
|
|
1284
|
-
//#region src/cli/commands/bundle.ts
|
|
1285
|
-
async function bundleWithConfig(configPath, cliOptions) {
|
|
1286
|
-
const config = await loadConfig(configPath);
|
|
1287
|
-
if (!config) {
|
|
1288
|
-
logger.error(`No configuration found at ${config}`);
|
|
1289
|
-
process.exit(1);
|
|
1290
|
-
}
|
|
1291
|
-
if (cliOptions.watch) await watchInner(config, cliOptions);
|
|
1292
|
-
else await bundleInner(config, cliOptions);
|
|
1293
|
-
}
|
|
1294
|
-
async function bundleWithCliOptions(cliOptions) {
|
|
1295
|
-
if (cliOptions.output.dir || cliOptions.output.file) {
|
|
1296
|
-
const operation = cliOptions.watch ? watchInner : bundleInner;
|
|
1297
|
-
await operation({}, cliOptions);
|
|
1298
|
-
return;
|
|
1299
|
-
}
|
|
1300
|
-
if (cliOptions.watch) {
|
|
1301
|
-
logger.error("You must specify `output.dir` to use watch mode");
|
|
1302
|
-
process.exit(1);
|
|
1303
|
-
}
|
|
1304
|
-
const build = await require_src.rolldown(cliOptions.input);
|
|
1305
|
-
try {
|
|
1306
|
-
const { output: outputs } = await build.generate(cliOptions.output);
|
|
1307
|
-
if (outputs.length === 0) {
|
|
1308
|
-
logger.error("No output generated");
|
|
1309
|
-
process.exit(1);
|
|
1310
|
-
}
|
|
1311
|
-
for (const file of outputs) {
|
|
1312
|
-
if (outputs.length > 1) logger.log(`\n${require_parse_ast_index.colors.cyan(require_parse_ast_index.colors.bold(`|→ ${file.fileName}:`))}\n`);
|
|
1313
|
-
console.log(file.type === "asset" ? file.source : file.code);
|
|
1314
|
-
}
|
|
1315
|
-
} finally {
|
|
1316
|
-
await build.close();
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
async function watchInner(config, cliOptions) {
|
|
1320
|
-
process.env.ROLLUP_WATCH = "true";
|
|
1321
|
-
process.env.ROLLDOWN_WATCH = "true";
|
|
1322
|
-
let normalizedConfig = require_src.arraify(config).map((option) => {
|
|
1323
|
-
return {
|
|
1324
|
-
...option,
|
|
1325
|
-
...cliOptions.input,
|
|
1326
|
-
output: require_src.arraify(option.output || {}).map((output) => {
|
|
1327
|
-
return {
|
|
1328
|
-
...output,
|
|
1329
|
-
...cliOptions.output
|
|
1330
|
-
};
|
|
1331
|
-
})
|
|
1332
|
-
};
|
|
1333
|
-
});
|
|
1334
|
-
const watcher = await require_src.watch(normalizedConfig);
|
|
1335
|
-
onExit((code) => {
|
|
1336
|
-
Promise.resolve(watcher.close()).finally(() => {
|
|
1337
|
-
process.exit(typeof code === "number" ? code : 0);
|
|
1338
|
-
});
|
|
1339
|
-
return true;
|
|
1340
|
-
});
|
|
1341
|
-
const changedFile = [];
|
|
1342
|
-
watcher.on("change", (id, event) => {
|
|
1343
|
-
if (event.event === "update") changedFile.push(id);
|
|
1344
|
-
});
|
|
1345
|
-
watcher.on("event", (event) => {
|
|
1346
|
-
switch (event.code) {
|
|
1347
|
-
case "BUNDLE_START":
|
|
1348
|
-
if (changedFile.length > 0) logger.log(`Found ${require_parse_ast_index.colors.bold(changedFile.map(relativeId).join(", "))} changed, rebuilding...`);
|
|
1349
|
-
changedFile.length = 0;
|
|
1350
|
-
break;
|
|
1351
|
-
case "BUNDLE_END":
|
|
1352
|
-
logger.success(`Rebuilt ${require_parse_ast_index.colors.bold(relativeId(event.output[0]))} in ${require_parse_ast_index.colors.bold(ms(event.duration))}.`);
|
|
1353
|
-
break;
|
|
1354
|
-
case "ERROR":
|
|
1355
|
-
logger.error(event.error);
|
|
1356
|
-
break;
|
|
1357
|
-
default: break;
|
|
1358
|
-
}
|
|
1359
|
-
});
|
|
1360
|
-
logger.log(`Waiting for changes...`);
|
|
1361
|
-
}
|
|
1362
|
-
async function bundleInner(config, cliOptions) {
|
|
1363
|
-
const startTime = node_perf_hooks.performance.now();
|
|
1364
|
-
const result = [];
|
|
1365
|
-
const configList = require_src.arraify(config);
|
|
1366
|
-
for (const config$1 of configList) {
|
|
1367
|
-
const outputList = require_src.arraify(config$1.output || {});
|
|
1368
|
-
const build = await require_src.rolldown({
|
|
1369
|
-
...config$1,
|
|
1370
|
-
...cliOptions.input
|
|
1371
|
-
});
|
|
1372
|
-
for (const output of outputList) try {
|
|
1373
|
-
result.push(await build.write({
|
|
1374
|
-
...output,
|
|
1375
|
-
...cliOptions.output
|
|
1376
|
-
}));
|
|
1377
|
-
} finally {
|
|
1378
|
-
await build.close();
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
1381
|
-
result.forEach(printBundleOutputPretty);
|
|
1382
|
-
logger.log(``);
|
|
1383
|
-
const endTime = node_perf_hooks.performance.now();
|
|
1384
|
-
const duration = endTime - startTime;
|
|
1385
|
-
logger.success(`Finished in ${require_parse_ast_index.colors.bold(ms(duration))}`);
|
|
1386
|
-
}
|
|
1387
|
-
function printBundleOutputPretty(output) {
|
|
1388
|
-
const outputEntries = collectOutputEntries(output.output);
|
|
1389
|
-
const outputLayoutSizes = collectOutputLayoutAdjustmentSizes(outputEntries);
|
|
1390
|
-
printOutputEntries(outputEntries, outputLayoutSizes, "<DIR>");
|
|
1391
|
-
}
|
|
1392
|
-
function collectOutputEntries(output) {
|
|
1393
|
-
return output.map((chunk) => ({
|
|
1394
|
-
type: chunk.type,
|
|
1395
|
-
fileName: chunk.fileName,
|
|
1396
|
-
size: chunk.type === "chunk" ? Buffer.byteLength(chunk.code) : Buffer.byteLength(chunk.source)
|
|
1397
|
-
}));
|
|
1398
|
-
}
|
|
1399
|
-
function collectOutputLayoutAdjustmentSizes(entries) {
|
|
1400
|
-
let longest = 0;
|
|
1401
|
-
let biggestSize = 0;
|
|
1402
|
-
for (const entry of entries) {
|
|
1403
|
-
if (entry.fileName.length > longest) longest = entry.fileName.length;
|
|
1404
|
-
if (entry.size > biggestSize) biggestSize = entry.size;
|
|
1405
|
-
}
|
|
1406
|
-
const sizePad = displaySize(biggestSize).length;
|
|
1407
|
-
return {
|
|
1408
|
-
longest,
|
|
1409
|
-
biggestSize,
|
|
1410
|
-
sizePad
|
|
1411
|
-
};
|
|
1412
|
-
}
|
|
1413
|
-
const numberFormatter = new Intl.NumberFormat("en", {
|
|
1414
|
-
maximumFractionDigits: 2,
|
|
1415
|
-
minimumFractionDigits: 2
|
|
1416
|
-
});
|
|
1417
|
-
function displaySize(bytes) {
|
|
1418
|
-
return `${numberFormatter.format(bytes / 1e3)} kB`;
|
|
1419
|
-
}
|
|
1420
|
-
const CHUNK_GROUPS = [{
|
|
1421
|
-
type: "asset",
|
|
1422
|
-
color: "green"
|
|
1423
|
-
}, {
|
|
1424
|
-
type: "chunk",
|
|
1425
|
-
color: "cyan"
|
|
1426
|
-
}];
|
|
1427
|
-
function printOutputEntries(entries, sizeAdjustment, distPath) {
|
|
1428
|
-
for (const group of CHUNK_GROUPS) {
|
|
1429
|
-
const filtered = entries.filter((e) => e.type === group.type);
|
|
1430
|
-
if (!filtered.length) continue;
|
|
1431
|
-
for (const entry of filtered.sort((a$1, z) => a$1.size - z.size)) {
|
|
1432
|
-
let log = require_parse_ast_index.colors.dim(withTrailingSlash(distPath));
|
|
1433
|
-
log += require_parse_ast_index.colors[group.color](entry.fileName.padEnd(sizeAdjustment.longest + 2));
|
|
1434
|
-
log += require_parse_ast_index.colors.dim(entry.type);
|
|
1435
|
-
log += require_parse_ast_index.colors.dim(` │ size: ${displaySize(entry.size).padStart(sizeAdjustment.sizePad)}`);
|
|
1436
|
-
logger.log(log);
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
function withTrailingSlash(path$2) {
|
|
1441
|
-
if (path$2[path$2.length - 1] !== "/") return `${path$2}/`;
|
|
1442
|
-
return path$2;
|
|
1443
|
-
}
|
|
1444
|
-
function ms(duration) {
|
|
1445
|
-
return duration < 1e3 ? `${duration.toFixed(2)} ms` : `${(duration / 1e3).toFixed(2)} s`;
|
|
1446
|
-
}
|
|
1447
|
-
function relativeId(id) {
|
|
1448
|
-
if (!node_path.default.isAbsolute(id)) return id;
|
|
1449
|
-
return node_path.default.relative(node_path.default.resolve(), id);
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
1000
|
//#endregion
|
|
1453
1001
|
//#region src/cli/arguments/alias.ts
|
|
1454
1002
|
const alias = {
|
|
@@ -1667,6 +1215,458 @@ function parseCliArguments() {
|
|
|
1667
1215
|
return normalizeCliOptions(values, positionals);
|
|
1668
1216
|
}
|
|
1669
1217
|
|
|
1218
|
+
//#endregion
|
|
1219
|
+
//#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.js
|
|
1220
|
+
const signals = [];
|
|
1221
|
+
signals.push("SIGHUP", "SIGINT", "SIGTERM");
|
|
1222
|
+
if (process.platform !== "win32") signals.push(
|
|
1223
|
+
"SIGALRM",
|
|
1224
|
+
"SIGABRT",
|
|
1225
|
+
"SIGVTALRM",
|
|
1226
|
+
"SIGXCPU",
|
|
1227
|
+
"SIGXFSZ",
|
|
1228
|
+
"SIGUSR2",
|
|
1229
|
+
"SIGTRAP",
|
|
1230
|
+
"SIGSYS",
|
|
1231
|
+
"SIGQUIT",
|
|
1232
|
+
"SIGIOT"
|
|
1233
|
+
// should detect profiler and enable/disable accordingly.
|
|
1234
|
+
// see #21
|
|
1235
|
+
// 'SIGPROF'
|
|
1236
|
+
);
|
|
1237
|
+
if (process.platform === "linux") signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");
|
|
1238
|
+
|
|
1239
|
+
//#endregion
|
|
1240
|
+
//#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.js
|
|
1241
|
+
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";
|
|
1242
|
+
const kExitEmitter = Symbol.for("signal-exit emitter");
|
|
1243
|
+
const global = globalThis;
|
|
1244
|
+
const ObjectDefineProperty = Object.defineProperty.bind(Object);
|
|
1245
|
+
var Emitter = class {
|
|
1246
|
+
emitted = {
|
|
1247
|
+
afterExit: false,
|
|
1248
|
+
exit: false
|
|
1249
|
+
};
|
|
1250
|
+
listeners = {
|
|
1251
|
+
afterExit: [],
|
|
1252
|
+
exit: []
|
|
1253
|
+
};
|
|
1254
|
+
count = 0;
|
|
1255
|
+
id = Math.random();
|
|
1256
|
+
constructor() {
|
|
1257
|
+
if (global[kExitEmitter]) return global[kExitEmitter];
|
|
1258
|
+
ObjectDefineProperty(global, kExitEmitter, {
|
|
1259
|
+
value: this,
|
|
1260
|
+
writable: false,
|
|
1261
|
+
enumerable: false,
|
|
1262
|
+
configurable: false
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
on(ev, fn) {
|
|
1266
|
+
this.listeners[ev].push(fn);
|
|
1267
|
+
}
|
|
1268
|
+
removeListener(ev, fn) {
|
|
1269
|
+
const list = this.listeners[ev];
|
|
1270
|
+
const i$1 = list.indexOf(fn);
|
|
1271
|
+
if (i$1 === -1) return;
|
|
1272
|
+
if (i$1 === 0 && list.length === 1) list.length = 0;
|
|
1273
|
+
else list.splice(i$1, 1);
|
|
1274
|
+
}
|
|
1275
|
+
emit(ev, code, signal) {
|
|
1276
|
+
if (this.emitted[ev]) return false;
|
|
1277
|
+
this.emitted[ev] = true;
|
|
1278
|
+
let ret = false;
|
|
1279
|
+
for (const fn of this.listeners[ev]) ret = fn(code, signal) === true || ret;
|
|
1280
|
+
if (ev === "exit") ret = this.emit("afterExit", code, signal) || ret;
|
|
1281
|
+
return ret;
|
|
1282
|
+
}
|
|
1283
|
+
};
|
|
1284
|
+
var SignalExitBase = class {};
|
|
1285
|
+
const signalExitWrap = (handler) => {
|
|
1286
|
+
return {
|
|
1287
|
+
onExit(cb, opts) {
|
|
1288
|
+
return handler.onExit(cb, opts);
|
|
1289
|
+
},
|
|
1290
|
+
load() {
|
|
1291
|
+
return handler.load();
|
|
1292
|
+
},
|
|
1293
|
+
unload() {
|
|
1294
|
+
return handler.unload();
|
|
1295
|
+
}
|
|
1296
|
+
};
|
|
1297
|
+
};
|
|
1298
|
+
var SignalExitFallback = class extends SignalExitBase {
|
|
1299
|
+
onExit() {
|
|
1300
|
+
return () => {};
|
|
1301
|
+
}
|
|
1302
|
+
load() {}
|
|
1303
|
+
unload() {}
|
|
1304
|
+
};
|
|
1305
|
+
var SignalExit = class extends SignalExitBase {
|
|
1306
|
+
#hupSig = process$2.platform === "win32" ? "SIGINT" : "SIGHUP";
|
|
1307
|
+
#emitter = new Emitter();
|
|
1308
|
+
#process;
|
|
1309
|
+
#originalProcessEmit;
|
|
1310
|
+
#originalProcessReallyExit;
|
|
1311
|
+
#sigListeners = {};
|
|
1312
|
+
#loaded = false;
|
|
1313
|
+
constructor(process$3) {
|
|
1314
|
+
super();
|
|
1315
|
+
this.#process = process$3;
|
|
1316
|
+
this.#sigListeners = {};
|
|
1317
|
+
for (const sig of signals) this.#sigListeners[sig] = () => {
|
|
1318
|
+
const listeners = this.#process.listeners(sig);
|
|
1319
|
+
let { count } = this.#emitter;
|
|
1320
|
+
const p = process$3;
|
|
1321
|
+
if (typeof p.__signal_exit_emitter__ === "object" && typeof p.__signal_exit_emitter__.count === "number") count += p.__signal_exit_emitter__.count;
|
|
1322
|
+
if (listeners.length === count) {
|
|
1323
|
+
this.unload();
|
|
1324
|
+
const ret = this.#emitter.emit("exit", null, sig);
|
|
1325
|
+
const s$1 = sig === "SIGHUP" ? this.#hupSig : sig;
|
|
1326
|
+
if (!ret) process$3.kill(process$3.pid, s$1);
|
|
1327
|
+
}
|
|
1328
|
+
};
|
|
1329
|
+
this.#originalProcessReallyExit = process$3.reallyExit;
|
|
1330
|
+
this.#originalProcessEmit = process$3.emit;
|
|
1331
|
+
}
|
|
1332
|
+
onExit(cb, opts) {
|
|
1333
|
+
if (!processOk(this.#process)) return () => {};
|
|
1334
|
+
if (this.#loaded === false) this.load();
|
|
1335
|
+
const ev = opts?.alwaysLast ? "afterExit" : "exit";
|
|
1336
|
+
this.#emitter.on(ev, cb);
|
|
1337
|
+
return () => {
|
|
1338
|
+
this.#emitter.removeListener(ev, cb);
|
|
1339
|
+
if (this.#emitter.listeners["exit"].length === 0 && this.#emitter.listeners["afterExit"].length === 0) this.unload();
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
load() {
|
|
1343
|
+
if (this.#loaded) return;
|
|
1344
|
+
this.#loaded = true;
|
|
1345
|
+
this.#emitter.count += 1;
|
|
1346
|
+
for (const sig of signals) try {
|
|
1347
|
+
const fn = this.#sigListeners[sig];
|
|
1348
|
+
if (fn) this.#process.on(sig, fn);
|
|
1349
|
+
} catch (_$1) {}
|
|
1350
|
+
this.#process.emit = (ev, ...a$1) => {
|
|
1351
|
+
return this.#processEmit(ev, ...a$1);
|
|
1352
|
+
};
|
|
1353
|
+
this.#process.reallyExit = (code) => {
|
|
1354
|
+
return this.#processReallyExit(code);
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
unload() {
|
|
1358
|
+
if (!this.#loaded) return;
|
|
1359
|
+
this.#loaded = false;
|
|
1360
|
+
signals.forEach((sig) => {
|
|
1361
|
+
const listener = this.#sigListeners[sig];
|
|
1362
|
+
if (!listener) throw new Error("Listener not defined for signal: " + sig);
|
|
1363
|
+
try {
|
|
1364
|
+
this.#process.removeListener(sig, listener);
|
|
1365
|
+
} catch (_$1) {}
|
|
1366
|
+
});
|
|
1367
|
+
this.#process.emit = this.#originalProcessEmit;
|
|
1368
|
+
this.#process.reallyExit = this.#originalProcessReallyExit;
|
|
1369
|
+
this.#emitter.count -= 1;
|
|
1370
|
+
}
|
|
1371
|
+
#processReallyExit(code) {
|
|
1372
|
+
if (!processOk(this.#process)) return 0;
|
|
1373
|
+
this.#process.exitCode = code || 0;
|
|
1374
|
+
this.#emitter.emit("exit", this.#process.exitCode, null);
|
|
1375
|
+
return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode);
|
|
1376
|
+
}
|
|
1377
|
+
#processEmit(ev, ...args) {
|
|
1378
|
+
const og = this.#originalProcessEmit;
|
|
1379
|
+
if (ev === "exit" && processOk(this.#process)) {
|
|
1380
|
+
if (typeof args[0] === "number") this.#process.exitCode = args[0];
|
|
1381
|
+
const ret = og.call(this.#process, ev, ...args);
|
|
1382
|
+
this.#emitter.emit("exit", this.#process.exitCode, null);
|
|
1383
|
+
return ret;
|
|
1384
|
+
} else return og.call(this.#process, ev, ...args);
|
|
1385
|
+
}
|
|
1386
|
+
};
|
|
1387
|
+
const process$2 = globalThis.process;
|
|
1388
|
+
const { onExit, load, unload } = signalExitWrap(processOk(process$2) ? new SignalExit(process$2) : new SignalExitFallback());
|
|
1389
|
+
|
|
1390
|
+
//#endregion
|
|
1391
|
+
//#region src/cli/load-config.ts
|
|
1392
|
+
async function bundleTsConfig(configFile, isEsm) {
|
|
1393
|
+
const dirnameVarName = "injected_original_dirname";
|
|
1394
|
+
const filenameVarName = "injected_original_filename";
|
|
1395
|
+
const importMetaUrlVarName = "injected_original_import_meta_url";
|
|
1396
|
+
const bundle = await require_src.rolldown({
|
|
1397
|
+
input: configFile,
|
|
1398
|
+
platform: "node",
|
|
1399
|
+
resolve: { mainFields: ["main"] },
|
|
1400
|
+
define: {
|
|
1401
|
+
__dirname: dirnameVarName,
|
|
1402
|
+
__filename: filenameVarName,
|
|
1403
|
+
"import.meta.url": importMetaUrlVarName,
|
|
1404
|
+
"import.meta.dirname": dirnameVarName,
|
|
1405
|
+
"import.meta.filename": filenameVarName
|
|
1406
|
+
},
|
|
1407
|
+
treeshake: false,
|
|
1408
|
+
external: [/^[\w@][^:]/],
|
|
1409
|
+
plugins: [{
|
|
1410
|
+
name: "inject-file-scope-variables",
|
|
1411
|
+
transform: {
|
|
1412
|
+
filter: { id: /\.[cm]?[jt]s$/ },
|
|
1413
|
+
async handler(code, id) {
|
|
1414
|
+
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)};`;
|
|
1415
|
+
return {
|
|
1416
|
+
code: injectValues + code,
|
|
1417
|
+
map: null
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
}]
|
|
1422
|
+
});
|
|
1423
|
+
const outputDir = node_path.default.dirname(configFile);
|
|
1424
|
+
const result = await bundle.write({
|
|
1425
|
+
dir: outputDir,
|
|
1426
|
+
format: isEsm ? "esm" : "cjs",
|
|
1427
|
+
sourcemap: "inline",
|
|
1428
|
+
entryFileNames: `rolldown.config.[hash]${node_path.default.extname(configFile).replace("ts", "js")}`
|
|
1429
|
+
});
|
|
1430
|
+
const fileName = result.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
|
|
1431
|
+
return node_path.default.join(outputDir, fileName);
|
|
1432
|
+
}
|
|
1433
|
+
const SUPPORTED_JS_CONFIG_FORMATS = [
|
|
1434
|
+
".js",
|
|
1435
|
+
".mjs",
|
|
1436
|
+
".cjs"
|
|
1437
|
+
];
|
|
1438
|
+
const SUPPORTED_TS_CONFIG_FORMATS = [
|
|
1439
|
+
".ts",
|
|
1440
|
+
".mts",
|
|
1441
|
+
".cts"
|
|
1442
|
+
];
|
|
1443
|
+
const SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
|
|
1444
|
+
const DEFAULT_CONFIG_BASE = "rolldown.config";
|
|
1445
|
+
async function findConfigFileNameInCwd() {
|
|
1446
|
+
const filesInWorkingDirectory = new Set(await (0, node_fs_promises.readdir)((0, node_process.cwd)()));
|
|
1447
|
+
for (const extension of SUPPORTED_CONFIG_FORMATS) {
|
|
1448
|
+
const fileName = `${DEFAULT_CONFIG_BASE}${extension}`;
|
|
1449
|
+
if (filesInWorkingDirectory.has(fileName)) return fileName;
|
|
1450
|
+
}
|
|
1451
|
+
throw new Error("No `rolldown.config` configuration file found.");
|
|
1452
|
+
}
|
|
1453
|
+
async function loadTsConfig(configFile) {
|
|
1454
|
+
const isEsm = isFilePathESM(configFile);
|
|
1455
|
+
const file = await bundleTsConfig(configFile, isEsm);
|
|
1456
|
+
try {
|
|
1457
|
+
return (await import((0, node_url.pathToFileURL)(file).href)).default;
|
|
1458
|
+
} finally {
|
|
1459
|
+
node_fs.default.unlink(file, () => {});
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
function isFilePathESM(filePath) {
|
|
1463
|
+
if (/\.m[jt]s$/.test(filePath)) return true;
|
|
1464
|
+
else if (/\.c[jt]s$/.test(filePath)) return false;
|
|
1465
|
+
else {
|
|
1466
|
+
const pkg = findNearestPackageData(node_path.default.dirname(filePath));
|
|
1467
|
+
if (pkg) return pkg.type === "module";
|
|
1468
|
+
return false;
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
function findNearestPackageData(basedir) {
|
|
1472
|
+
while (basedir) {
|
|
1473
|
+
const pkgPath = node_path.default.join(basedir, "package.json");
|
|
1474
|
+
if (tryStatSync(pkgPath)?.isFile()) try {
|
|
1475
|
+
return JSON.parse(node_fs.default.readFileSync(pkgPath, "utf-8"));
|
|
1476
|
+
} catch {}
|
|
1477
|
+
const nextBasedir = node_path.default.dirname(basedir);
|
|
1478
|
+
if (nextBasedir === basedir) break;
|
|
1479
|
+
basedir = nextBasedir;
|
|
1480
|
+
}
|
|
1481
|
+
return null;
|
|
1482
|
+
}
|
|
1483
|
+
function tryStatSync(file) {
|
|
1484
|
+
try {
|
|
1485
|
+
return node_fs.default.statSync(file, { throwIfNoEntry: false });
|
|
1486
|
+
} catch {}
|
|
1487
|
+
}
|
|
1488
|
+
async function loadConfig(configPath) {
|
|
1489
|
+
const ext = node_path.default.extname(configPath = configPath || await findConfigFileNameInCwd());
|
|
1490
|
+
try {
|
|
1491
|
+
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;
|
|
1492
|
+
else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) {
|
|
1493
|
+
const rawConfigPath = node_path.default.resolve(configPath);
|
|
1494
|
+
return await loadTsConfig(rawConfigPath);
|
|
1495
|
+
} else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
|
|
1496
|
+
} catch (err) {
|
|
1497
|
+
throw new Error("Error happened while loading config.", { cause: err });
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
//#endregion
|
|
1502
|
+
//#region src/cli/commands/bundle.ts
|
|
1503
|
+
async function bundleWithConfig(configPath, cliOptions) {
|
|
1504
|
+
const config = await loadConfig(configPath);
|
|
1505
|
+
if (!config) {
|
|
1506
|
+
logger.error(`No configuration found at ${config}`);
|
|
1507
|
+
process.exit(1);
|
|
1508
|
+
}
|
|
1509
|
+
if (cliOptions.watch) await watchInner(config, cliOptions);
|
|
1510
|
+
else await bundleInner(config, cliOptions);
|
|
1511
|
+
}
|
|
1512
|
+
async function bundleWithCliOptions(cliOptions) {
|
|
1513
|
+
if (cliOptions.output.dir || cliOptions.output.file) {
|
|
1514
|
+
const operation = cliOptions.watch ? watchInner : bundleInner;
|
|
1515
|
+
await operation({}, cliOptions);
|
|
1516
|
+
return;
|
|
1517
|
+
}
|
|
1518
|
+
if (cliOptions.watch) {
|
|
1519
|
+
logger.error("You must specify `output.dir` to use watch mode");
|
|
1520
|
+
process.exit(1);
|
|
1521
|
+
}
|
|
1522
|
+
const build = await require_src.rolldown(cliOptions.input);
|
|
1523
|
+
try {
|
|
1524
|
+
const { output: outputs } = await build.generate(cliOptions.output);
|
|
1525
|
+
if (outputs.length === 0) {
|
|
1526
|
+
logger.error("No output generated");
|
|
1527
|
+
process.exit(1);
|
|
1528
|
+
}
|
|
1529
|
+
for (const file of outputs) {
|
|
1530
|
+
if (outputs.length > 1) logger.log(`\n${require_parse_ast_index.colors.cyan(require_parse_ast_index.colors.bold(`|→ ${file.fileName}:`))}\n`);
|
|
1531
|
+
console.log(file.type === "asset" ? file.source : file.code);
|
|
1532
|
+
}
|
|
1533
|
+
} finally {
|
|
1534
|
+
await build.close();
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
async function watchInner(config, cliOptions) {
|
|
1538
|
+
process.env.ROLLUP_WATCH = "true";
|
|
1539
|
+
process.env.ROLLDOWN_WATCH = "true";
|
|
1540
|
+
let normalizedConfig = require_src.arraify(config).map((option) => {
|
|
1541
|
+
return {
|
|
1542
|
+
...option,
|
|
1543
|
+
...cliOptions.input,
|
|
1544
|
+
output: require_src.arraify(option.output || {}).map((output) => {
|
|
1545
|
+
return {
|
|
1546
|
+
...output,
|
|
1547
|
+
...cliOptions.output
|
|
1548
|
+
};
|
|
1549
|
+
})
|
|
1550
|
+
};
|
|
1551
|
+
});
|
|
1552
|
+
const watcher = await require_src.watch(normalizedConfig);
|
|
1553
|
+
onExit((code) => {
|
|
1554
|
+
Promise.resolve(watcher.close()).finally(() => {
|
|
1555
|
+
process.exit(typeof code === "number" ? code : 0);
|
|
1556
|
+
});
|
|
1557
|
+
return true;
|
|
1558
|
+
});
|
|
1559
|
+
const changedFile = [];
|
|
1560
|
+
watcher.on("change", (id, event) => {
|
|
1561
|
+
if (event.event === "update") changedFile.push(id);
|
|
1562
|
+
});
|
|
1563
|
+
watcher.on("event", (event) => {
|
|
1564
|
+
switch (event.code) {
|
|
1565
|
+
case "BUNDLE_START":
|
|
1566
|
+
if (changedFile.length > 0) logger.log(`Found ${require_parse_ast_index.colors.bold(changedFile.map(relativeId).join(", "))} changed, rebuilding...`);
|
|
1567
|
+
changedFile.length = 0;
|
|
1568
|
+
break;
|
|
1569
|
+
case "BUNDLE_END":
|
|
1570
|
+
logger.success(`Rebuilt ${require_parse_ast_index.colors.bold(relativeId(event.output[0]))} in ${require_parse_ast_index.colors.bold(ms(event.duration))}.`);
|
|
1571
|
+
break;
|
|
1572
|
+
case "ERROR":
|
|
1573
|
+
logger.error(event.error);
|
|
1574
|
+
break;
|
|
1575
|
+
default: break;
|
|
1576
|
+
}
|
|
1577
|
+
});
|
|
1578
|
+
logger.log(`Waiting for changes...`);
|
|
1579
|
+
}
|
|
1580
|
+
async function bundleInner(config, cliOptions) {
|
|
1581
|
+
const startTime = node_perf_hooks.performance.now();
|
|
1582
|
+
const result = [];
|
|
1583
|
+
const configList = require_src.arraify(config);
|
|
1584
|
+
for (const config$1 of configList) {
|
|
1585
|
+
const outputList = require_src.arraify(config$1.output || {});
|
|
1586
|
+
const build = await require_src.rolldown({
|
|
1587
|
+
...config$1,
|
|
1588
|
+
...cliOptions.input
|
|
1589
|
+
});
|
|
1590
|
+
for (const output of outputList) try {
|
|
1591
|
+
result.push(await build.write({
|
|
1592
|
+
...output,
|
|
1593
|
+
...cliOptions.output
|
|
1594
|
+
}));
|
|
1595
|
+
} finally {
|
|
1596
|
+
await build.close();
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
result.forEach(printBundleOutputPretty);
|
|
1600
|
+
logger.log(``);
|
|
1601
|
+
const endTime = node_perf_hooks.performance.now();
|
|
1602
|
+
const duration = endTime - startTime;
|
|
1603
|
+
logger.success(`Finished in ${require_parse_ast_index.colors.bold(ms(duration))}`);
|
|
1604
|
+
}
|
|
1605
|
+
function printBundleOutputPretty(output) {
|
|
1606
|
+
const outputEntries = collectOutputEntries(output.output);
|
|
1607
|
+
const outputLayoutSizes = collectOutputLayoutAdjustmentSizes(outputEntries);
|
|
1608
|
+
printOutputEntries(outputEntries, outputLayoutSizes, "<DIR>");
|
|
1609
|
+
}
|
|
1610
|
+
function collectOutputEntries(output) {
|
|
1611
|
+
return output.map((chunk) => ({
|
|
1612
|
+
type: chunk.type,
|
|
1613
|
+
fileName: chunk.fileName,
|
|
1614
|
+
size: chunk.type === "chunk" ? Buffer.byteLength(chunk.code) : Buffer.byteLength(chunk.source)
|
|
1615
|
+
}));
|
|
1616
|
+
}
|
|
1617
|
+
function collectOutputLayoutAdjustmentSizes(entries) {
|
|
1618
|
+
let longest = 0;
|
|
1619
|
+
let biggestSize = 0;
|
|
1620
|
+
for (const entry of entries) {
|
|
1621
|
+
if (entry.fileName.length > longest) longest = entry.fileName.length;
|
|
1622
|
+
if (entry.size > biggestSize) biggestSize = entry.size;
|
|
1623
|
+
}
|
|
1624
|
+
const sizePad = displaySize(biggestSize).length;
|
|
1625
|
+
return {
|
|
1626
|
+
longest,
|
|
1627
|
+
biggestSize,
|
|
1628
|
+
sizePad
|
|
1629
|
+
};
|
|
1630
|
+
}
|
|
1631
|
+
const numberFormatter = new Intl.NumberFormat("en", {
|
|
1632
|
+
maximumFractionDigits: 2,
|
|
1633
|
+
minimumFractionDigits: 2
|
|
1634
|
+
});
|
|
1635
|
+
function displaySize(bytes) {
|
|
1636
|
+
return `${numberFormatter.format(bytes / 1e3)} kB`;
|
|
1637
|
+
}
|
|
1638
|
+
const CHUNK_GROUPS = [{
|
|
1639
|
+
type: "asset",
|
|
1640
|
+
color: "green"
|
|
1641
|
+
}, {
|
|
1642
|
+
type: "chunk",
|
|
1643
|
+
color: "cyan"
|
|
1644
|
+
}];
|
|
1645
|
+
function printOutputEntries(entries, sizeAdjustment, distPath) {
|
|
1646
|
+
for (const group of CHUNK_GROUPS) {
|
|
1647
|
+
const filtered = entries.filter((e) => e.type === group.type);
|
|
1648
|
+
if (!filtered.length) continue;
|
|
1649
|
+
for (const entry of filtered.sort((a$1, z) => a$1.size - z.size)) {
|
|
1650
|
+
let log = require_parse_ast_index.colors.dim(withTrailingSlash(distPath));
|
|
1651
|
+
log += require_parse_ast_index.colors[group.color](entry.fileName.padEnd(sizeAdjustment.longest + 2));
|
|
1652
|
+
log += require_parse_ast_index.colors.dim(entry.type);
|
|
1653
|
+
log += require_parse_ast_index.colors.dim(` │ size: ${displaySize(entry.size).padStart(sizeAdjustment.sizePad)}`);
|
|
1654
|
+
logger.log(log);
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
function withTrailingSlash(path$2) {
|
|
1659
|
+
if (path$2[path$2.length - 1] !== "/") return `${path$2}/`;
|
|
1660
|
+
return path$2;
|
|
1661
|
+
}
|
|
1662
|
+
function ms(duration) {
|
|
1663
|
+
return duration < 1e3 ? `${duration.toFixed(2)} ms` : `${(duration / 1e3).toFixed(2)} s`;
|
|
1664
|
+
}
|
|
1665
|
+
function relativeId(id) {
|
|
1666
|
+
if (!node_path.default.isAbsolute(id)) return id;
|
|
1667
|
+
return node_path.default.relative(node_path.default.resolve(), id);
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
1670
|
//#endregion
|
|
1671
1671
|
//#region src/cli/commands/help.ts
|
|
1672
1672
|
const introduction = `${require_parse_ast_index.colors.gray(`${require_src.description} (rolldown v${require_src.version})`)}
|