rolldown 1.0.0-beta.4-commit.d3748b6 → 1.0.0-beta.40

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.
Files changed (133) hide show
  1. package/bin/cli.mjs +2 -0
  2. package/dist/cli.d.mts +1 -0
  3. package/dist/cli.mjs +579 -0
  4. package/dist/config.d.mts +10 -0
  5. package/dist/config.mjs +10 -0
  6. package/dist/experimental-index.d.mts +147 -0
  7. package/dist/experimental-index.mjs +216 -0
  8. package/dist/experimental-runtime-types.d.ts +71 -0
  9. package/dist/filter-index.d.mts +4 -0
  10. package/dist/filter-index.mjs +44 -0
  11. package/dist/index.d.mts +3 -0
  12. package/dist/index.mjs +5 -0
  13. package/dist/parallel-plugin-worker.d.mts +1 -0
  14. package/dist/{esm/parallel-plugin-worker.mjs → parallel-plugin-worker.mjs} +8 -16
  15. package/dist/parallel-plugin.d.mts +14 -0
  16. package/dist/{esm/parallel-plugin.mjs → parallel-plugin.mjs} +0 -1
  17. package/dist/parse-ast-index.d.mts +8 -0
  18. package/dist/parse-ast-index.mjs +3 -0
  19. package/dist/shared/binding-BVXbXhPv.d.mts +1413 -0
  20. package/dist/shared/define-config-0kfJrpvQ.d.mts +1454 -0
  21. package/dist/shared/load-config-BJ274Wsp.mjs +117 -0
  22. package/dist/{esm/cli.mjs → shared/logger-CiCY7ucm.mjs} +107 -868
  23. package/dist/shared/misc-CQeo-AFx.mjs +22 -0
  24. package/dist/shared/parse-ast-index-C7EYXjEA.mjs +10974 -0
  25. package/dist/shared/{prompt-CxK9euq3.mjs → prompt-D2FxOcB5.mjs} +243 -245
  26. package/dist/shared/src-BH2eQDD9.mjs +4282 -0
  27. package/package.json +62 -76
  28. package/bin/cli.js +0 -2
  29. package/dist/cjs/cli.cjs +0 -1753
  30. package/dist/cjs/experimental-index.cjs +0 -85
  31. package/dist/cjs/index.cjs +0 -8
  32. package/dist/cjs/parallel-plugin-worker.cjs +0 -41
  33. package/dist/cjs/parallel-plugin.cjs +0 -9
  34. package/dist/cjs/parse-ast-index.cjs +0 -4
  35. package/dist/esm/experimental-index.mjs +0 -57
  36. package/dist/esm/index.mjs +0 -4
  37. package/dist/esm/parse-ast-index.mjs +0 -3
  38. package/dist/shared/chunk-qZFfknuJ.cjs +0 -40
  39. package/dist/shared/parse-ast-index-CyX8MVZE.mjs +0 -674
  40. package/dist/shared/parse-ast-index-D7XtMFo4.cjs +0 -719
  41. package/dist/shared/prompt-ZZScCEWI.cjs +0 -854
  42. package/dist/shared/src-CH716UxL.cjs +0 -3056
  43. package/dist/shared/src-CzSgWS0h.mjs +0 -2875
  44. package/dist/types/api/build.d.ts +0 -18
  45. package/dist/types/api/experimental.d.ts +0 -7
  46. package/dist/types/api/rolldown/index.d.ts +0 -3
  47. package/dist/types/api/rolldown/rolldown-build.d.ts +0 -13
  48. package/dist/types/api/watch/index.d.ts +0 -3
  49. package/dist/types/api/watch/watch-emitter.d.ts +0 -31
  50. package/dist/types/api/watch/watcher.d.ts +0 -13
  51. package/dist/types/binding.d.ts +0 -1456
  52. package/dist/types/builtin-plugin/alias-plugin.d.ts +0 -10
  53. package/dist/types/builtin-plugin/constructors.d.ts +0 -21
  54. package/dist/types/builtin-plugin/replace-plugin.d.ts +0 -28
  55. package/dist/types/builtin-plugin/transform-plugin.d.ts +0 -9
  56. package/dist/types/builtin-plugin/utils.d.ts +0 -8
  57. package/dist/types/cli/arguments/alias.d.ts +0 -16
  58. package/dist/types/cli/arguments/index.d.ts +0 -15
  59. package/dist/types/cli/arguments/normalize.d.ts +0 -12
  60. package/dist/types/cli/arguments/utils.d.ts +0 -8
  61. package/dist/types/cli/colors.d.ts +0 -11
  62. package/dist/types/cli/commands/bundle.d.ts +0 -3
  63. package/dist/types/cli/commands/help.d.ts +0 -1
  64. package/dist/types/cli/index.d.ts +0 -1
  65. package/dist/types/cli/load-config.d.ts +0 -5
  66. package/dist/types/cli/logger.d.ts +0 -5
  67. package/dist/types/constants/plugin-context.d.ts +0 -7
  68. package/dist/types/constants/plugin.d.ts +0 -45
  69. package/dist/types/experimental-index.d.ts +0 -9
  70. package/dist/types/index.d.ts +0 -30
  71. package/dist/types/log/log-handler.d.ts +0 -4
  72. package/dist/types/log/logger.d.ts +0 -6
  73. package/dist/types/log/logging.d.ts +0 -12
  74. package/dist/types/log/logs.d.ts +0 -18
  75. package/dist/types/options/generated/checks-options.d.ts +0 -57
  76. package/dist/types/options/input-options.d.ts +0 -177
  77. package/dist/types/options/normalized-input-options.d.ts +0 -18
  78. package/dist/types/options/normalized-output-options.d.ts +0 -70
  79. package/dist/types/options/output-options.d.ts +0 -182
  80. package/dist/types/options/watch-options.d.ts +0 -5
  81. package/dist/types/parallel-plugin-worker.d.ts +0 -1
  82. package/dist/types/parallel-plugin.d.ts +0 -1
  83. package/dist/types/parse-ast-index.d.ts +0 -5
  84. package/dist/types/plugin/bindingify-build-hooks.d.ts +0 -10
  85. package/dist/types/plugin/bindingify-hook-filter.d.ts +0 -7
  86. package/dist/types/plugin/bindingify-output-hooks.d.ts +0 -14
  87. package/dist/types/plugin/bindingify-plugin-hook-meta.d.ts +0 -8
  88. package/dist/types/plugin/bindingify-plugin.d.ts +0 -16
  89. package/dist/types/plugin/bindingify-watch-hooks.d.ts +0 -5
  90. package/dist/types/plugin/hook-filter.d.ts +0 -48
  91. package/dist/types/plugin/index.d.ts +0 -134
  92. package/dist/types/plugin/minimal-plugin-context.d.ts +0 -23
  93. package/dist/types/plugin/parallel-plugin-implementation.d.ts +0 -10
  94. package/dist/types/plugin/parallel-plugin.d.ts +0 -9
  95. package/dist/types/plugin/plugin-context-data.d.ts +0 -17
  96. package/dist/types/plugin/plugin-context.d.ts +0 -67
  97. package/dist/types/plugin/plugin-driver.d.ts +0 -8
  98. package/dist/types/plugin/transform-plugin-context.d.ts +0 -28
  99. package/dist/types/types/assert.d.ts +0 -14
  100. package/dist/types/types/config-export.d.ts +0 -5
  101. package/dist/types/types/misc.d.ts +0 -40
  102. package/dist/types/types/module-info.d.ts +0 -15
  103. package/dist/types/types/module-side-effects.d.ts +0 -12
  104. package/dist/types/types/output-bundle.d.ts +0 -4
  105. package/dist/types/types/rolldown-options.d.ts +0 -5
  106. package/dist/types/types/rolldown-output.d.ts +0 -66
  107. package/dist/types/types/schema.d.ts +0 -33
  108. package/dist/types/types/sourcemap.d.ts +0 -14
  109. package/dist/types/types/utils.d.ts +0 -13
  110. package/dist/types/utils/asset-source.d.ts +0 -4
  111. package/dist/types/utils/async-flatten.d.ts +0 -1
  112. package/dist/types/utils/bindingify-input-options.d.ts +0 -7
  113. package/dist/types/utils/bindingify-output-options.d.ts +0 -5
  114. package/dist/types/utils/code-frame.d.ts +0 -1
  115. package/dist/types/utils/compose-js-plugins.d.ts +0 -2
  116. package/dist/types/utils/create-bundler-option.d.ts +0 -11
  117. package/dist/types/utils/create-bundler.d.ts +0 -8
  118. package/dist/types/utils/define-config.d.ts +0 -5
  119. package/dist/types/utils/error.d.ts +0 -2
  120. package/dist/types/utils/initialize-parallel-plugins.d.ts +0 -19
  121. package/dist/types/utils/misc.d.ts +0 -6
  122. package/dist/types/utils/normalize-hook.d.ts +0 -7
  123. package/dist/types/utils/normalize-plugin-option.d.ts +0 -13
  124. package/dist/types/utils/normalize-string-or-regex.d.ts +0 -2
  125. package/dist/types/utils/plugin/index.d.ts +0 -2
  126. package/dist/types/utils/resolved-external.d.ts +0 -4
  127. package/dist/types/utils/transform-module-info.d.ts +0 -4
  128. package/dist/types/utils/transform-rendered-chunk.d.ts +0 -4
  129. package/dist/types/utils/transform-rendered-module.d.ts +0 -3
  130. package/dist/types/utils/transform-side-effects.d.ts +0 -3
  131. package/dist/types/utils/transform-sourcemap.d.ts +0 -3
  132. package/dist/types/utils/transform-to-rollup-output.d.ts +0 -11
  133. package/dist/types/utils/validator.d.ts +0 -6
@@ -1,187 +1,9 @@
1
- import { colors } from "../shared/parse-ast-index-CyX8MVZE.mjs";
2
- import { arraify, description, getInputCliKeys, getJsonSchema, getOutputCliKeys, rolldown, validateCliOptions, version, watch } from "../shared/src-CzSgWS0h.mjs";
3
- import process$1, { cwd } from "node:process";
4
- import path, { sep } from "node:path";
5
- import fs from "node:fs";
6
- import { performance } from "node:perf_hooks";
7
- import { formatWithOptions, parseArgs } from "node:util";
1
+ import { sep } from "node:path";
2
+ import { formatWithOptions } from "node:util";
3
+ import process$1 from "node:process";
8
4
  import * as tty from "node:tty";
9
- import { readdir } from "node:fs/promises";
10
- import { pathToFileURL } from "node:url";
11
5
 
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$1 = process$3;
114
- if (typeof p$1.__signal_exit_emitter__ === "object" && typeof p$1.__signal_exit_emitter__.count === "number") count += p$1.__signal_exit_emitter__.count;
115
- if (listeners.length === count) {
116
- this.unload();
117
- const ret = this.#emitter.emit("exit", null, sig);
118
- const s$2 = sig === "SIGHUP" ? this.#hupSig : sig;
119
- if (!ret) process$3.kill(process$3.pid, s$2);
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
- //#region ../../node_modules/.pnpm/consola@3.4.0/node_modules/consola/dist/core.mjs
6
+ //#region ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/core.mjs
185
7
  const LogLevels = {
186
8
  silent: Number.NEGATIVE_INFINITY,
187
9
  fatal: 0,
@@ -237,7 +59,7 @@ function _defu(baseObject, defaults, namespace = ".", merger) {
237
59
  return object;
238
60
  }
239
61
  function createDefu(merger) {
240
- return (...arguments_) => arguments_.reduce((p$1, c$1) => _defu(p$1, c$1, "", merger), {});
62
+ return (...arguments_) => arguments_.reduce((p, c$1) => _defu(p, c$1, "", merger), {});
241
63
  }
242
64
  const defu = createDefu();
243
65
  function isPlainObject(obj) {
@@ -260,13 +82,13 @@ var Consola = class Consola {
260
82
  *
261
83
  * @param {Partial<ConsolaOptions>} [options={}] - Configuration options for the Consola instance.
262
84
  */
263
- constructor(options$1 = {}) {
264
- const types = options$1.types || LogTypes;
85
+ constructor(options = {}) {
86
+ const types = options.types || LogTypes;
265
87
  this.options = defu({
266
- ...options$1,
267
- defaults: { ...options$1.defaults },
268
- level: _normalizeLogLevel(options$1.level, types),
269
- reporters: [...options$1.reporters || []]
88
+ ...options,
89
+ defaults: { ...options.defaults },
90
+ level: _normalizeLogLevel(options.level, types),
91
+ reporters: [...options.reporters || []]
270
92
  }, {
271
93
  types: LogTypes,
272
94
  throttle: 1e3,
@@ -324,10 +146,10 @@ var Consola = class Consola {
324
146
  * @param {Partial<ConsolaOptions>} options - Optional overrides for the new instance. See {@link ConsolaOptions}.
325
147
  * @returns {ConsolaInstance} A new Consola instance. See {@link ConsolaInstance}.
326
148
  */
327
- create(options$1) {
149
+ create(options) {
328
150
  const instance = new Consola({
329
151
  ...this.options,
330
- ...options$1
152
+ ...options
331
153
  });
332
154
  if (this._mockFn) instance.mockTypes(this._mockFn);
333
155
  return instance;
@@ -562,31 +384,29 @@ Consola.prototype.withScope = Consola.prototype.withTag;
562
384
  Consola.prototype.mock = Consola.prototype.mockTypes;
563
385
  Consola.prototype.pause = Consola.prototype.pauseLogs;
564
386
  Consola.prototype.resume = Consola.prototype.resumeLogs;
565
- function createConsola$1(options$1 = {}) {
566
- return new Consola(options$1);
387
+ function createConsola$1(options = {}) {
388
+ return new Consola(options);
567
389
  }
568
390
 
569
391
  //#endregion
570
- //#region ../../node_modules/.pnpm/consola@3.4.0/node_modules/consola/dist/shared/consola.Cs5FdtHD.mjs
571
- function parseStack(stack) {
392
+ //#region ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs
393
+ function parseStack(stack, message) {
572
394
  const cwd$1 = process.cwd() + sep;
573
- const lines = stack.split("\n").splice(1).map((l$1) => l$1.trim().replace("file://", "").replace(cwd$1, ""));
574
- return lines;
395
+ return stack.split("\n").splice(message.split("\n").length).map((l$1) => l$1.trim().replace("file://", "").replace(cwd$1, ""));
575
396
  }
576
397
  function writeStream(data, stream) {
577
- const write = stream.__write || stream.write;
578
- return write.call(stream, data);
398
+ return (stream.__write || stream.write).call(stream, data);
579
399
  }
580
400
  const bracket = (x) => x ? `[${x}]` : "";
581
401
  var BasicReporter = class {
582
- formatStack(stack, opts) {
402
+ formatStack(stack, message, opts) {
583
403
  const indent = " ".repeat((opts?.errorLevel || 0) + 1);
584
- return indent + parseStack(stack).join(`
404
+ return indent + parseStack(stack, message).join(`
585
405
  ${indent}`);
586
406
  }
587
407
  formatError(err, opts) {
588
408
  const message = err.message ?? formatWithOptions(opts, err);
589
- const stack = err.stack ? this.formatStack(err.stack, opts) : "";
409
+ const stack = err.stack ? this.formatStack(err.stack, message, opts) : "";
590
410
  const level = opts?.errorLevel || 0;
591
411
  const causedPrefix = level > 0 ? `${" ".repeat(level)}[cause]: ` : "";
592
412
  const causedError = err.cause ? "\n\n" + this.formatError(err.cause, {
@@ -631,14 +451,14 @@ ${indent}`);
631
451
  };
632
452
 
633
453
  //#endregion
634
- //#region ../../node_modules/.pnpm/consola@3.4.0/node_modules/consola/dist/shared/consola.lX6kr4n8.mjs
635
- const { env: env$1 = {}, argv = [], platform = "" } = typeof process === "undefined" ? {} : process;
636
- const isDisabled = "NO_COLOR" in env$1 || argv.includes("--no-color");
637
- const isForced = "FORCE_COLOR" in env$1 || argv.includes("--color");
454
+ //#region ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs
455
+ const { env = {}, argv = [], platform = "" } = typeof process === "undefined" ? {} : process;
456
+ const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
457
+ const isForced = "FORCE_COLOR" in env || argv.includes("--color");
638
458
  const isWindows = platform === "win32";
639
- const isDumbTerminal = env$1.TERM === "dumb";
640
- const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env$1.TERM && !isDumbTerminal;
641
- const isCI = "CI" in env$1 && ("GITHUB_ACTIONS" in env$1 || "GITLAB_CI" in env$1 || "CIRCLECI" in env$1);
459
+ const isDumbTerminal = env.TERM === "dumb";
460
+ const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal;
461
+ const isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
642
462
  const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
643
463
  function replaceClose(index, string, close, replace, head = string.slice(0, Math.max(0, index)) + replace, tail = string.slice(Math.max(0, index + close.length)), next = tail.indexOf(close)) {
644
464
  return head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
@@ -698,12 +518,12 @@ const colorDefs = {
698
518
  function createColors(useColor = isColorSupported) {
699
519
  return useColor ? colorDefs : Object.fromEntries(Object.keys(colorDefs).map((key) => [key, String]));
700
520
  }
701
- const colors$1 = createColors();
521
+ const colors = createColors();
702
522
  function getColor$1(color, fallback = "reset") {
703
- return colors$1[color] || colors$1[fallback];
523
+ return colors[color] || colors[fallback];
704
524
  }
705
525
  const ansiRegex$1 = [String.raw`[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)`, String.raw`(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))`].join("|");
706
- function stripAnsi$1(text) {
526
+ function stripAnsi(text) {
707
527
  return text.replace(new RegExp(ansiRegex$1, "g"), "");
708
528
  }
709
529
  const boxStylePresets = {
@@ -796,14 +616,14 @@ function box(text, _opts = {}) {
796
616
  if (_color) for (const key in borderStyle) borderStyle[key] = _color(borderStyle[key]);
797
617
  const paddingOffset = opts.style.padding % 2 === 0 ? opts.style.padding : opts.style.padding + 1;
798
618
  const height = textLines.length + paddingOffset;
799
- const width = Math.max(...textLines.map((line) => stripAnsi$1(line).length)) + paddingOffset;
619
+ const width = Math.max(...textLines.map((line) => stripAnsi(line).length), opts.title ? stripAnsi(opts.title).length : 0) + paddingOffset;
800
620
  const widthOffset = width + paddingOffset;
801
621
  const leftSpace = opts.style.marginLeft > 0 ? " ".repeat(opts.style.marginLeft) : "";
802
622
  if (opts.style.marginTop > 0) boxLines.push("".repeat(opts.style.marginTop));
803
623
  if (opts.title) {
804
624
  const title = _color ? _color(opts.title) : opts.title;
805
- const left = borderStyle.h.repeat(Math.floor((width - stripAnsi$1(opts.title).length) / 2));
806
- const right = borderStyle.h.repeat(width - stripAnsi$1(opts.title).length - stripAnsi$1(left).length + paddingOffset);
625
+ const left = borderStyle.h.repeat(Math.floor((width - stripAnsi(opts.title).length) / 2));
626
+ const right = borderStyle.h.repeat(width - stripAnsi(opts.title).length - stripAnsi(left).length + paddingOffset);
807
627
  boxLines.push(`${leftSpace}${borderStyle.tl}${left}${title}${right}${borderStyle.tr}`);
808
628
  } else boxLines.push(`${leftSpace}${borderStyle.tl}${borderStyle.h.repeat(widthOffset)}${borderStyle.tr}`);
809
629
  const valignOffset = opts.style.valign === "center" ? Math.floor((height - textLines.length) / 2) : opts.style.valign === "top" ? height - textLines.length - paddingOffset : height - textLines.length;
@@ -811,7 +631,7 @@ function box(text, _opts = {}) {
811
631
  else {
812
632
  const line = textLines[i$1 - valignOffset];
813
633
  const left = " ".repeat(paddingOffset);
814
- const right = " ".repeat(width - stripAnsi$1(line).length);
634
+ const right = " ".repeat(width - stripAnsi(line).length);
815
635
  boxLines.push(`${leftSpace}${borderStyle.v}${left}${line}${right}${borderStyle.v}`);
816
636
  }
817
637
  boxLines.push(`${leftSpace}${borderStyle.bl}${borderStyle.h.repeat(widthOffset)}${borderStyle.br}`);
@@ -820,29 +640,29 @@ function box(text, _opts = {}) {
820
640
  }
821
641
 
822
642
  //#endregion
823
- //#region ../../node_modules/.pnpm/consola@3.4.0/node_modules/consola/dist/index.mjs
824
- const r = Object.create(null), i = (e) => globalThis.process?.env || import.meta.env || globalThis.Deno?.env.toObject() || globalThis.__env__ || (e ? r : globalThis), s$1 = new Proxy(r, {
825
- get(e, o) {
826
- return i()[o] ?? r[o];
643
+ //#region ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/index.mjs
644
+ const r = Object.create(null), i = (e) => globalThis.process?.env || import.meta.env || globalThis.Deno?.env.toObject() || globalThis.__env__ || (e ? r : globalThis), o = new Proxy(r, {
645
+ get(e, s$1) {
646
+ return i()[s$1] ?? r[s$1];
827
647
  },
828
- has(e, o) {
648
+ has(e, s$1) {
829
649
  const E = i();
830
- return o in E || o in r;
650
+ return s$1 in E || s$1 in r;
831
651
  },
832
- set(e, o, E) {
833
- const b = i(true);
834
- return b[o] = E, true;
652
+ set(e, s$1, E) {
653
+ const B = i(true);
654
+ return B[s$1] = E, true;
835
655
  },
836
- deleteProperty(e, o) {
837
- if (!o) return false;
656
+ deleteProperty(e, s$1) {
657
+ if (!s$1) return false;
838
658
  const E = i(true);
839
- return delete E[o], true;
659
+ return delete E[s$1], true;
840
660
  },
841
661
  ownKeys() {
842
662
  const e = i(true);
843
663
  return Object.keys(e);
844
664
  }
845
- }), t = typeof process < "u" && process.env && process.env.NODE_ENV || "", B = [
665
+ }), t = typeof process < "u" && process.env && process.env.NODE_ENV || "", f = [
846
666
  ["APPVEYOR"],
847
667
  [
848
668
  "AWS_AMPLIFY",
@@ -910,6 +730,11 @@ const r = Object.create(null), i = (e) => globalThis.process?.env || import.meta
910
730
  "CODESANDBOX_SSE",
911
731
  { ci: false }
912
732
  ],
733
+ [
734
+ "CODESANDBOX",
735
+ "CODESANDBOX_HOST",
736
+ { ci: false }
737
+ ],
913
738
  ["STACKBLITZ"],
914
739
  ["STORMKIT"],
915
740
  ["CLEAVR"],
@@ -928,10 +753,10 @@ const r = Object.create(null), i = (e) => globalThis.process?.env || import.meta
928
753
  { ci: true }
929
754
  ]
930
755
  ];
931
- function p() {
932
- if (globalThis.process?.env) for (const e of B) {
933
- const o = e[1] || e[0];
934
- if (globalThis.process?.env[o]) return {
756
+ function b() {
757
+ if (globalThis.process?.env) for (const e of f) {
758
+ const s$1 = e[1] || e[0];
759
+ if (globalThis.process?.env[s$1]) return {
935
760
  name: e[0].toLowerCase(),
936
761
  ...e[2]
937
762
  };
@@ -944,45 +769,43 @@ function p() {
944
769
  ci: false
945
770
  };
946
771
  }
947
- const l = p();
772
+ const l = b();
948
773
  l.name;
949
774
  function n(e) {
950
775
  return e ? e !== "false" : false;
951
776
  }
952
- const I = globalThis.process?.platform || "", T = n(s$1.CI) || l.ci !== false, R = n(globalThis.process?.stdout && globalThis.process?.stdout.isTTY), U = n(s$1.DEBUG), A = t === "test" || n(s$1.TEST);
953
- n(s$1.MINIMAL);
954
- const _ = /^win/i.test(I);
955
- !n(s$1.NO_COLOR) && (n(s$1.FORCE_COLOR) || (R || _) && s$1.TERM);
777
+ const I = globalThis.process?.platform || "", T = n(o.CI) || l.ci !== false, a = n(globalThis.process?.stdout && globalThis.process?.stdout.isTTY), g = n(o.DEBUG), R = t === "test" || n(o.TEST);
778
+ n(o.MINIMAL);
779
+ const A = /^win/i.test(I);
780
+ !n(o.NO_COLOR) && (n(o.FORCE_COLOR) || (a || A) && o.TERM);
956
781
  const C = (globalThis.process?.versions?.node || "").replace(/^v/, "") || null;
957
782
  Number(C?.split(".")[0]);
958
- const y = globalThis.process || Object.create(null), c = { versions: {} };
959
- new Proxy(y, { get(e, o) {
960
- if (o === "env") return s$1;
961
- if (o in e) return e[o];
962
- if (o in c) return c[o];
783
+ const y = globalThis.process || Object.create(null), _ = { versions: {} };
784
+ new Proxy(y, { get(e, s$1) {
785
+ if (s$1 === "env") return o;
786
+ if (s$1 in e) return e[s$1];
787
+ if (s$1 in _) return _[s$1];
963
788
  } });
964
- const L = globalThis.process?.release?.name === "node", a = !!globalThis.Bun || !!globalThis.process?.versions?.bun, D = !!globalThis.Deno, O = !!globalThis.fastly, S = !!globalThis.Netlify, N = !!globalThis.EdgeRuntime, P = globalThis.navigator?.userAgent === "Cloudflare-Workers", F = [
789
+ const c = globalThis.process?.release?.name === "node", O = !!globalThis.Bun || !!globalThis.process?.versions?.bun, D = !!globalThis.Deno, L = !!globalThis.fastly, S = !!globalThis.Netlify, u = !!globalThis.EdgeRuntime, N = globalThis.navigator?.userAgent === "Cloudflare-Workers", F = [
965
790
  [S, "netlify"],
966
- [N, "edge-light"],
967
- [P, "workerd"],
968
- [O, "fastly"],
791
+ [u, "edge-light"],
792
+ [N, "workerd"],
793
+ [L, "fastly"],
969
794
  [D, "deno"],
970
- [a, "bun"],
971
- [L, "node"]
795
+ [O, "bun"],
796
+ [c, "node"]
972
797
  ];
973
798
  function G() {
974
- const e = F.find((o) => o[0]);
799
+ const e = F.find((s$1) => s$1[0]);
975
800
  if (e) return { name: e[1] };
976
801
  }
977
- const u = G();
978
- u?.name;
802
+ G()?.name;
979
803
  function ansiRegex({ onlyFirst = false } = {}) {
980
- const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
981
- const pattern = [`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?${ST})`, "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");
804
+ const pattern = [`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))`, "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");
982
805
  return new RegExp(pattern, onlyFirst ? void 0 : "g");
983
806
  }
984
807
  const regex = ansiRegex();
985
- function stripAnsi(string) {
808
+ function stripAnsi$1(string) {
986
809
  if (typeof string !== "string") throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
987
810
  return string.replace(regex, "");
988
811
  }
@@ -1008,10 +831,10 @@ const emojiRegex = () => {
1008
831
  };
1009
832
  const segmenter = globalThis.Intl?.Segmenter ? new Intl.Segmenter() : { segment: (str) => str.split("") };
1010
833
  const defaultIgnorableCodePointRegex = /^\p{Default_Ignorable_Code_Point}$/u;
1011
- function stringWidth$1(string, options$1 = {}) {
834
+ function stringWidth$1(string, options = {}) {
1012
835
  if (typeof string !== "string" || string.length === 0) return 0;
1013
- const { ambiguousIsNarrow = true, countAnsiEscapeCodes = false } = options$1;
1014
- if (!countAnsiEscapeCodes) string = stripAnsi(string);
836
+ const { ambiguousIsNarrow = true, countAnsiEscapeCodes = false } = options;
837
+ if (!countAnsiEscapeCodes) string = stripAnsi$1(string);
1015
838
  if (string.length === 0) return 0;
1016
839
  let width = 0;
1017
840
  const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
@@ -1032,10 +855,10 @@ function stringWidth$1(string, options$1 = {}) {
1032
855
  return width;
1033
856
  }
1034
857
  function isUnicodeSupported() {
1035
- const { env: env$2 } = process$1;
1036
- const { TERM, TERM_PROGRAM } = env$2;
858
+ const { env: env$1 } = process$1;
859
+ const { TERM, TERM_PROGRAM } = env$1;
1037
860
  if (process$1.platform !== "win32") return TERM !== "linux";
1038
- return Boolean(env$2.WT_SESSION) || Boolean(env$2.TERMINUS_SUBLIME) || env$2.ConEmuTask === "{cmd::Cmder}" || TERM_PROGRAM === "Terminus-Sublime" || TERM_PROGRAM === "vscode" || TERM === "xterm-256color" || TERM === "alacritty" || TERM === "rxvt-unicode" || TERM === "rxvt-unicode-256color" || env$2.TERMINAL_EMULATOR === "JetBrains-JediTerm";
861
+ return Boolean(env$1.WT_SESSION) || Boolean(env$1.TERMINUS_SUBLIME) || env$1.ConEmuTask === "{cmd::Cmder}" || TERM_PROGRAM === "Terminus-Sublime" || TERM_PROGRAM === "vscode" || TERM === "xterm-256color" || TERM === "alacritty" || TERM === "rxvt-unicode" || TERM === "rxvt-unicode-256color" || env$1.TERMINAL_EMULATOR === "JetBrains-JediTerm";
1039
862
  }
1040
863
  const TYPE_COLOR_MAP = {
1041
864
  info: "cyan",
@@ -1064,20 +887,19 @@ const TYPE_ICONS = {
1064
887
  log: ""
1065
888
  };
1066
889
  function stringWidth(str) {
1067
- const hasICU = typeof Intl === "object";
1068
- if (!hasICU || !Intl.Segmenter) return stripAnsi$1(str).length;
890
+ if (!(typeof Intl === "object") || !Intl.Segmenter) return stripAnsi(str).length;
1069
891
  return stringWidth$1(str);
1070
892
  }
1071
893
  var FancyReporter = class extends BasicReporter {
1072
- formatStack(stack, opts) {
894
+ formatStack(stack, message, opts) {
1073
895
  const indent = " ".repeat((opts?.errorLevel || 0) + 1);
1074
896
  return `
1075
- ${indent}` + parseStack(stack).map((line) => " " + line.replace(/^at +/, (m) => colors$1.gray(m)).replace(/\((.+)\)/, (_$1, m) => `(${colors$1.cyan(m)})`)).join(`
897
+ ${indent}` + parseStack(stack, message).map((line) => " " + line.replace(/^at +/, (m) => colors.gray(m)).replace(/\((.+)\)/, (_$1, m) => `(${colors.cyan(m)})`)).join(`
1076
898
  ${indent}`);
1077
899
  }
1078
900
  formatType(logObj, isBadge, opts) {
1079
901
  const typeColor = TYPE_COLOR_MAP[logObj.type] || LEVEL_COLOR_MAP[logObj.level] || "gray";
1080
- if (isBadge) return getBgColor(typeColor)(colors$1.black(` ${logObj.type.toUpperCase()} `));
902
+ if (isBadge) return getBgColor(typeColor)(colors.black(` ${logObj.type.toUpperCase()} `));
1081
903
  const _type = typeof TYPE_ICONS[logObj.type] === "string" ? TYPE_ICONS[logObj.type] : logObj.icon || logObj.type;
1082
904
  return _type ? getColor(typeColor)(_type) : "";
1083
905
  }
@@ -1088,55 +910,57 @@ ${indent}`);
1088
910
  style: logObj.style
1089
911
  });
1090
912
  const date = this.formatDate(logObj.date, opts);
1091
- const coloredDate = date && colors$1.gray(date);
913
+ const coloredDate = date && colors.gray(date);
1092
914
  const isBadge = logObj.badge ?? logObj.level < 2;
1093
915
  const type = this.formatType(logObj, isBadge, opts);
1094
- const tag = logObj.tag ? colors$1.gray(logObj.tag) : "";
916
+ const tag = logObj.tag ? colors.gray(logObj.tag) : "";
1095
917
  let line;
1096
918
  const left = this.filterAndJoin([type, characterFormat(message)]);
1097
919
  const right = this.filterAndJoin(opts.columns ? [tag, coloredDate] : [tag]);
1098
920
  const space = (opts.columns || 0) - stringWidth(left) - stringWidth(right) - 2;
1099
- line = space > 0 && (opts.columns || 0) >= 80 ? left + " ".repeat(space) + right : (right ? `${colors$1.gray(`[${right}]`)} ` : "") + left;
921
+ line = space > 0 && (opts.columns || 0) >= 80 ? left + " ".repeat(space) + right : (right ? `${colors.gray(`[${right}]`)} ` : "") + left;
1100
922
  line += characterFormat(additional.length > 0 ? "\n" + additional.join("\n") : "");
1101
923
  if (logObj.type === "trace") {
1102
- const _err = new Error("Trace: " + logObj.message);
1103
- line += this.formatStack(_err.stack || "");
924
+ const _err = /* @__PURE__ */ new Error("Trace: " + logObj.message);
925
+ line += this.formatStack(_err.stack || "", _err.message);
1104
926
  }
1105
927
  return isBadge ? "\n" + line + "\n" : line;
1106
928
  }
1107
929
  };
1108
930
  function characterFormat(str) {
1109
- return str.replace(/`([^`]+)`/gm, (_$1, m) => colors$1.cyan(m)).replace(/\s+_([^_]+)_\s+/gm, (_$1, m) => ` ${colors$1.underline(m)} `);
931
+ return str.replace(/`([^`]+)`/gm, (_$1, m) => colors.cyan(m)).replace(/\s+_([^_]+)_\s+/gm, (_$1, m) => ` ${colors.underline(m)} `);
1110
932
  }
1111
933
  function getColor(color = "white") {
1112
- return colors$1[color] || colors$1.white;
934
+ return colors[color] || colors.white;
1113
935
  }
1114
936
  function getBgColor(color = "bgWhite") {
1115
- return colors$1[`bg${color[0].toUpperCase()}${color.slice(1)}`] || colors$1.bgWhite;
937
+ return colors[`bg${color[0].toUpperCase()}${color.slice(1)}`] || colors.bgWhite;
1116
938
  }
1117
- function createConsola(options$1 = {}) {
939
+ function createConsola(options = {}) {
1118
940
  let level = _getDefaultLogLevel();
1119
941
  if (process.env.CONSOLA_LEVEL) level = Number.parseInt(process.env.CONSOLA_LEVEL) ?? level;
1120
- const consola2 = createConsola$1({
942
+ return createConsola$1({
1121
943
  level,
1122
944
  defaults: { level },
1123
945
  stdout: process.stdout,
1124
946
  stderr: process.stderr,
1125
- prompt: (...args) => import("../shared/prompt-CxK9euq3.mjs").then((m) => m.prompt(...args)),
1126
- reporters: options$1.reporters || [options$1.fancy ?? !(T || A) ? new FancyReporter() : new BasicReporter()],
1127
- ...options$1
947
+ prompt: (...args) => import("./prompt-D2FxOcB5.mjs").then((m) => m.prompt(...args)),
948
+ reporters: options.reporters || [options.fancy ?? !(T || R) ? new FancyReporter() : new BasicReporter()],
949
+ ...options
1128
950
  });
1129
- return consola2;
1130
951
  }
1131
952
  function _getDefaultLogLevel() {
1132
- if (U) return LogLevels.debug;
1133
- if (A) return LogLevels.warn;
953
+ if (g) return LogLevels.debug;
954
+ if (R) return LogLevels.warn;
1134
955
  return LogLevels.info;
1135
956
  }
1136
957
  const consola = createConsola();
1137
958
 
1138
959
  //#endregion
1139
960
  //#region src/cli/logger.ts
961
+ /**
962
+ * Console logger
963
+ */
1140
964
  const logger = process.env.ROLLDOWN_TEST ? createTestingLogger() : createConsola({ formatOptions: { date: false } });
1141
965
  function createTestingLogger() {
1142
966
  const types = [
@@ -1161,589 +985,4 @@ function createTestingLogger() {
1161
985
  }
1162
986
 
1163
987
  //#endregion
1164
- //#region src/cli/load-config.ts
1165
- async function bundleTsConfig(configFile, isEsm) {
1166
- const dirnameVarName = "injected_original_dirname";
1167
- const filenameVarName = "injected_original_filename";
1168
- const importMetaUrlVarName = "injected_original_import_meta_url";
1169
- const bundle = await rolldown({
1170
- input: configFile,
1171
- platform: "node",
1172
- resolve: { mainFields: ["main"] },
1173
- define: {
1174
- __dirname: dirnameVarName,
1175
- __filename: filenameVarName,
1176
- "import.meta.url": importMetaUrlVarName,
1177
- "import.meta.dirname": dirnameVarName,
1178
- "import.meta.filename": filenameVarName
1179
- },
1180
- treeshake: false,
1181
- external: [/^[\w@][^:]/],
1182
- plugins: [{
1183
- name: "inject-file-scope-variables",
1184
- transform: {
1185
- filter: { id: /\.[cm]?[jt]s$/ },
1186
- async handler(code, id) {
1187
- const injectValues = `const ${dirnameVarName} = ${JSON.stringify(path.dirname(id))};const ${filenameVarName} = ${JSON.stringify(id)};const ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(id).href)};`;
1188
- return {
1189
- code: injectValues + code,
1190
- map: null
1191
- };
1192
- }
1193
- }
1194
- }]
1195
- });
1196
- const outputDir = path.dirname(configFile);
1197
- const result = await bundle.write({
1198
- dir: outputDir,
1199
- format: isEsm ? "esm" : "cjs",
1200
- sourcemap: "inline",
1201
- entryFileNames: `rolldown.config.[hash]${path.extname(configFile).replace("ts", "js")}`
1202
- });
1203
- const fileName = result.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
1204
- return path.join(outputDir, fileName);
1205
- }
1206
- const SUPPORTED_JS_CONFIG_FORMATS = [
1207
- ".js",
1208
- ".mjs",
1209
- ".cjs"
1210
- ];
1211
- const SUPPORTED_TS_CONFIG_FORMATS = [
1212
- ".ts",
1213
- ".mts",
1214
- ".cts"
1215
- ];
1216
- const SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
1217
- const DEFAULT_CONFIG_BASE = "rolldown.config";
1218
- async function findConfigFileNameInCwd() {
1219
- const filesInWorkingDirectory = new Set(await readdir(cwd()));
1220
- for (const extension of SUPPORTED_CONFIG_FORMATS) {
1221
- const fileName = `${DEFAULT_CONFIG_BASE}${extension}`;
1222
- if (filesInWorkingDirectory.has(fileName)) return fileName;
1223
- }
1224
- throw new Error("No `rolldown.config` configuration file found.");
1225
- }
1226
- async function loadTsConfig(configFile) {
1227
- const isEsm = isFilePathESM(configFile);
1228
- const file = await bundleTsConfig(configFile, isEsm);
1229
- try {
1230
- return (await import(pathToFileURL(file).href)).default;
1231
- } finally {
1232
- fs.unlink(file, () => {});
1233
- }
1234
- }
1235
- function isFilePathESM(filePath) {
1236
- if (/\.m[jt]s$/.test(filePath)) return true;
1237
- else if (/\.c[jt]s$/.test(filePath)) return false;
1238
- else {
1239
- const pkg = findNearestPackageData(path.dirname(filePath));
1240
- if (pkg) return pkg.type === "module";
1241
- return false;
1242
- }
1243
- }
1244
- function findNearestPackageData(basedir) {
1245
- while (basedir) {
1246
- const pkgPath = path.join(basedir, "package.json");
1247
- if (tryStatSync(pkgPath)?.isFile()) try {
1248
- return JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
1249
- } catch {}
1250
- const nextBasedir = path.dirname(basedir);
1251
- if (nextBasedir === basedir) break;
1252
- basedir = nextBasedir;
1253
- }
1254
- return null;
1255
- }
1256
- function tryStatSync(file) {
1257
- try {
1258
- return fs.statSync(file, { throwIfNoEntry: false });
1259
- } catch {}
1260
- }
1261
- async function loadConfig(configPath) {
1262
- const ext = path.extname(configPath = configPath || await findConfigFileNameInCwd());
1263
- try {
1264
- 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;
1265
- else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) {
1266
- const rawConfigPath = path.resolve(configPath);
1267
- return await loadTsConfig(rawConfigPath);
1268
- } else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
1269
- } catch (err) {
1270
- throw new Error("Error happened while loading config.", { cause: err });
1271
- }
1272
- }
1273
-
1274
- //#endregion
1275
- //#region src/cli/commands/bundle.ts
1276
- async function bundleWithConfig(configPath, cliOptions) {
1277
- const config = await loadConfig(configPath);
1278
- if (!config) {
1279
- logger.error(`No configuration found at ${config}`);
1280
- process.exit(1);
1281
- }
1282
- if (cliOptions.watch) await watchInner(config, cliOptions);
1283
- else await bundleInner(config, cliOptions);
1284
- }
1285
- async function bundleWithCliOptions(cliOptions) {
1286
- if (cliOptions.output.dir || cliOptions.output.file) {
1287
- const operation = cliOptions.watch ? watchInner : bundleInner;
1288
- await operation({}, cliOptions);
1289
- return;
1290
- }
1291
- if (cliOptions.watch) {
1292
- logger.error("You must specify `output.dir` to use watch mode");
1293
- process.exit(1);
1294
- }
1295
- const build = await rolldown(cliOptions.input);
1296
- try {
1297
- const { output: outputs } = await build.generate(cliOptions.output);
1298
- if (outputs.length === 0) {
1299
- logger.error("No output generated");
1300
- process.exit(1);
1301
- }
1302
- for (const file of outputs) {
1303
- if (outputs.length > 1) logger.log(`\n${colors.cyan(colors.bold(`|→ ${file.fileName}:`))}\n`);
1304
- console.log(file.type === "asset" ? file.source : file.code);
1305
- }
1306
- } finally {
1307
- await build.close();
1308
- }
1309
- }
1310
- async function watchInner(config, cliOptions) {
1311
- let normalizedConfig = arraify(config).map((option) => {
1312
- return {
1313
- ...option,
1314
- ...cliOptions.input,
1315
- output: arraify(option.output || {}).map((output) => {
1316
- return {
1317
- ...output,
1318
- ...cliOptions.output
1319
- };
1320
- })
1321
- };
1322
- });
1323
- const watcher = await watch(normalizedConfig);
1324
- onExit((code) => {
1325
- Promise.resolve(watcher.close()).finally(() => {
1326
- process.exit(typeof code === "number" ? code : 0);
1327
- });
1328
- return true;
1329
- });
1330
- const changedFile = [];
1331
- watcher.on("change", (id, event) => {
1332
- if (event.event === "update") changedFile.push(id);
1333
- });
1334
- watcher.on("event", (event) => {
1335
- switch (event.code) {
1336
- case "BUNDLE_START":
1337
- if (changedFile.length > 0) logger.log(`Found ${colors.bold(changedFile.map(relativeId).join(", "))} changed, rebuilding...`);
1338
- changedFile.length = 0;
1339
- break;
1340
- case "BUNDLE_END":
1341
- logger.success(`Rebuilt ${colors.bold(relativeId(event.output[0]))} in ${colors.bold(ms(event.duration))}.`);
1342
- break;
1343
- case "ERROR":
1344
- logger.error(event.error);
1345
- break;
1346
- default: break;
1347
- }
1348
- });
1349
- logger.log(`Waiting for changes...`);
1350
- }
1351
- async function bundleInner(config, cliOptions) {
1352
- const startTime = performance.now();
1353
- const result = [];
1354
- const configList = arraify(config);
1355
- for (const config$1 of configList) {
1356
- const outputList = arraify(config$1.output || {});
1357
- const build = await rolldown({
1358
- ...config$1,
1359
- ...cliOptions.input
1360
- });
1361
- for (const output of outputList) try {
1362
- result.push(await build.write({
1363
- ...output,
1364
- ...cliOptions.output
1365
- }));
1366
- } finally {
1367
- await build.close();
1368
- }
1369
- }
1370
- result.forEach(printBundleOutputPretty);
1371
- logger.log(``);
1372
- const endTime = performance.now();
1373
- const duration = endTime - startTime;
1374
- logger.success(`Finished in ${colors.bold(ms(duration))}`);
1375
- }
1376
- function printBundleOutputPretty(output) {
1377
- const outputEntries = collectOutputEntries(output.output);
1378
- const outputLayoutSizes = collectOutputLayoutAdjustmentSizes(outputEntries);
1379
- printOutputEntries(outputEntries, outputLayoutSizes, "<DIR>");
1380
- }
1381
- function collectOutputEntries(output) {
1382
- return output.map((chunk) => ({
1383
- type: chunk.type,
1384
- fileName: chunk.fileName,
1385
- size: chunk.type === "chunk" ? chunk.code.length : chunk.source.length
1386
- }));
1387
- }
1388
- function collectOutputLayoutAdjustmentSizes(entries) {
1389
- let longest = 0;
1390
- let biggestSize = 0;
1391
- for (const entry of entries) {
1392
- if (entry.fileName.length > longest) longest = entry.fileName.length;
1393
- if (entry.size > biggestSize) biggestSize = entry.size;
1394
- }
1395
- const sizePad = displaySize(biggestSize).length;
1396
- return {
1397
- longest,
1398
- biggestSize,
1399
- sizePad
1400
- };
1401
- }
1402
- const numberFormatter = new Intl.NumberFormat("en", {
1403
- maximumFractionDigits: 2,
1404
- minimumFractionDigits: 2
1405
- });
1406
- function displaySize(bytes) {
1407
- return `${numberFormatter.format(bytes / 1e3)} kB`;
1408
- }
1409
- const CHUNK_GROUPS = [{
1410
- type: "asset",
1411
- color: "green"
1412
- }, {
1413
- type: "chunk",
1414
- color: "cyan"
1415
- }];
1416
- function printOutputEntries(entries, sizeAdjustment, distPath) {
1417
- for (const group of CHUNK_GROUPS) {
1418
- const filtered = entries.filter((e) => e.type === group.type);
1419
- if (!filtered.length) continue;
1420
- for (const entry of filtered.sort((a$1, z) => a$1.size - z.size)) {
1421
- let log = colors.dim(withTrailingSlash(distPath));
1422
- log += colors[group.color](entry.fileName.padEnd(sizeAdjustment.longest + 2));
1423
- log += colors.dim(entry.type);
1424
- log += colors.dim(` │ size: ${displaySize(entry.size).padStart(sizeAdjustment.sizePad)}`);
1425
- logger.log(log);
1426
- }
1427
- }
1428
- }
1429
- function withTrailingSlash(path$1) {
1430
- if (path$1[path$1.length - 1] !== "/") return `${path$1}/`;
1431
- return path$1;
1432
- }
1433
- function ms(duration) {
1434
- return duration < 1e3 ? `${duration.toFixed(2)} ms` : `${(duration / 1e3).toFixed(2)} s`;
1435
- }
1436
- function relativeId(id) {
1437
- if (!path.isAbsolute(id)) return id;
1438
- return path.relative(path.resolve(), id);
1439
- }
1440
-
1441
- //#endregion
1442
- //#region src/cli/arguments/alias.ts
1443
- const alias = {
1444
- config: {
1445
- abbreviation: "c",
1446
- hint: "filename"
1447
- },
1448
- help: { abbreviation: "h" },
1449
- version: { abbreviation: "v" },
1450
- watch: { abbreviation: "w" },
1451
- dir: { abbreviation: "d" },
1452
- file: { abbreviation: "o" },
1453
- external: { abbreviation: "e" },
1454
- format: { abbreviation: "f" },
1455
- name: { abbreviation: "n" },
1456
- globals: { abbreviation: "g" },
1457
- sourcemap: {
1458
- abbreviation: "s",
1459
- default: true
1460
- },
1461
- minify: { abbreviation: "m" },
1462
- platform: { abbreviation: "p" },
1463
- assetFileNames: { hint: "name" },
1464
- chunkFileNames: { hint: "name" },
1465
- entryFileNames: { hint: "name" },
1466
- externalLiveBindings: {
1467
- default: true,
1468
- reverse: true
1469
- },
1470
- treeshake: {
1471
- default: true,
1472
- reverse: true
1473
- },
1474
- moduleTypes: { hint: "types" }
1475
- };
1476
-
1477
- //#endregion
1478
- //#region src/cli/arguments/utils.ts
1479
- const priority = [
1480
- "object",
1481
- "array",
1482
- "string",
1483
- "number",
1484
- "boolean"
1485
- ];
1486
- function getSchemaType(schema) {
1487
- if ("anyOf" in schema) {
1488
- const types = schema.anyOf.map(getSchemaType);
1489
- let result = priority.find((type) => types.includes(type));
1490
- if (result) return result;
1491
- }
1492
- if ("type" in schema) return schema.type;
1493
- if ("const" in schema) return typeof schema.const;
1494
- return "object";
1495
- }
1496
- function flattenSchema(schema, base = {}, parent = "") {
1497
- if (schema === void 0) return base;
1498
- for (const [k, value] of Object.entries(schema)) {
1499
- const key = parent ? `${parent}.${k}` : k;
1500
- if (getSchemaType(value) === "object") if ("properties" in value) flattenSchema(value.properties, base, key);
1501
- else base[key] = value;
1502
- else base[key] = value;
1503
- }
1504
- return base;
1505
- }
1506
- function setNestedProperty(obj, path$1, value) {
1507
- const keys = path$1.split(".");
1508
- let current = obj;
1509
- for (let i$1 = 0; i$1 < keys.length - 1; i$1++) {
1510
- if (!current[keys[i$1]]) current[keys[i$1]] = {};
1511
- current = current[keys[i$1]];
1512
- }
1513
- const finalKey = keys[keys.length - 1];
1514
- Object.defineProperty(current, finalKey, {
1515
- value,
1516
- writable: true,
1517
- enumerable: true,
1518
- configurable: true
1519
- });
1520
- }
1521
- function camelCaseToKebabCase(str) {
1522
- return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
1523
- }
1524
- function kebabCaseToCamelCase(str) {
1525
- return str.replace(/-./g, (match) => match[1].toUpperCase());
1526
- }
1527
-
1528
- //#endregion
1529
- //#region src/cli/arguments/normalize.ts
1530
- function normalizeCliOptions(cliOptions, positionals) {
1531
- const [data, errors] = validateCliOptions(cliOptions);
1532
- if (errors?.length) {
1533
- errors.forEach((error) => {
1534
- logger.error(`${error}. You can use \`rolldown -h\` to see the help.`);
1535
- });
1536
- process.exit(1);
1537
- }
1538
- const options$1 = data ?? {};
1539
- const result = {
1540
- input: {},
1541
- output: {},
1542
- help: options$1.help ?? false,
1543
- version: options$1.version ?? false,
1544
- watch: options$1.watch ?? false
1545
- };
1546
- if (typeof options$1.config === "string") result.config = options$1.config;
1547
- const keysOfInput = getInputCliKeys();
1548
- const keysOfOutput = getOutputCliKeys();
1549
- const reservedKeys = [
1550
- "help",
1551
- "version",
1552
- "config",
1553
- "watch"
1554
- ];
1555
- for (let [key, value] of Object.entries(options$1)) {
1556
- const keys = key.split(".");
1557
- const [primary] = keys;
1558
- if (keysOfInput.includes(primary)) setNestedProperty(result.input, key, value);
1559
- else if (keysOfOutput.includes(primary)) setNestedProperty(result.output, key, value);
1560
- else if (!reservedKeys.includes(key)) {
1561
- logger.error(`Unknown option: ${key}`);
1562
- process.exit(1);
1563
- }
1564
- }
1565
- if (!result.config && positionals.length > 0) result.input.input = positionals;
1566
- return result;
1567
- }
1568
-
1569
- //#endregion
1570
- //#region src/cli/arguments/index.ts
1571
- const objectSchema = getJsonSchema();
1572
- const flattenedSchema = flattenSchema(objectSchema.properties);
1573
- const options = Object.fromEntries(Object.entries(flattenedSchema).map(([key, schema]) => {
1574
- const config = Object.getOwnPropertyDescriptor(alias, key)?.value;
1575
- const type = getSchemaType(schema);
1576
- const result = {
1577
- type: type === "boolean" ? "boolean" : "string",
1578
- description: schema?.description ?? config?.description ?? "",
1579
- hint: config?.hint
1580
- };
1581
- if (config && config?.abbreviation) result.short = config?.abbreviation;
1582
- if (config && config.reverse) if (result.description.startsWith("enable")) result.description = result.description.replace("enable", "disable");
1583
- else result.description = `disable ${result.description}`;
1584
- key = camelCaseToKebabCase(key);
1585
- return [config?.reverse ? `no-${key}` : key, result];
1586
- }));
1587
- function parseCliArguments() {
1588
- const { values, tokens, positionals } = parseArgs({
1589
- options,
1590
- tokens: true,
1591
- allowPositionals: true,
1592
- strict: false
1593
- });
1594
- tokens.filter((token) => token.kind === "option").forEach((option) => {
1595
- let negative = false;
1596
- if (option.name.startsWith("no-")) {
1597
- const name = kebabCaseToCamelCase(option.name.substring(3));
1598
- if (name in flattenedSchema) {
1599
- delete values[option.name];
1600
- option.name = name;
1601
- negative = true;
1602
- }
1603
- }
1604
- delete values[option.name];
1605
- option.name = kebabCaseToCamelCase(option.name);
1606
- let originalType = flattenedSchema[option.name];
1607
- if (!originalType) {
1608
- logger.error(`Invalid option: ${option.rawName}. We will ignore this option.`);
1609
- process.exit(1);
1610
- }
1611
- let type = getSchemaType(originalType);
1612
- if (type === "string" && typeof option.value !== "string") {
1613
- let opt = option;
1614
- let defaultValue = Object.getOwnPropertyDescriptor(alias, opt.name)?.value;
1615
- Object.defineProperty(values, opt.name, {
1616
- value: defaultValue.default ?? "",
1617
- enumerable: true,
1618
- configurable: true,
1619
- writable: true
1620
- });
1621
- } else if (type === "object" && typeof option.value === "string") {
1622
- const [key, value] = option.value.split(",").map((x) => x.split("="))[0];
1623
- if (!values[option.name]) Object.defineProperty(values, option.name, {
1624
- value: {},
1625
- enumerable: true,
1626
- configurable: true,
1627
- writable: true
1628
- });
1629
- if (key && value) Object.defineProperty(values[option.name], key, {
1630
- value,
1631
- enumerable: true,
1632
- configurable: true,
1633
- writable: true
1634
- });
1635
- } else if (type === "array" && typeof option.value === "string") {
1636
- if (!values[option.name]) Object.defineProperty(values, option.name, {
1637
- value: [],
1638
- enumerable: true,
1639
- configurable: true,
1640
- writable: true
1641
- });
1642
- values[option.name].push(option.value);
1643
- } else if (type === "boolean") Object.defineProperty(values, option.name, {
1644
- value: !negative,
1645
- enumerable: true,
1646
- configurable: true,
1647
- writable: true
1648
- });
1649
- else Object.defineProperty(values, option.name, {
1650
- value: option.value ?? "",
1651
- enumerable: true,
1652
- configurable: true,
1653
- writable: true
1654
- });
1655
- });
1656
- return normalizeCliOptions(values, positionals);
1657
- }
1658
-
1659
- //#endregion
1660
- //#region src/cli/commands/help.ts
1661
- const introduction = `${colors.gray(`${description} (rolldown v${version})`)}
1662
-
1663
- ${colors.bold(colors.underline("USAGE"))} ${colors.cyan("rolldown -c <config>")} or ${colors.cyan("rolldown <input> <options>")}`;
1664
- const examples = [
1665
- {
1666
- title: "Bundle with a config file `rolldown.config.mjs`",
1667
- command: "rolldown -c rolldown.config.mjs"
1668
- },
1669
- {
1670
- title: "Bundle the `src/main.ts` to `dist` with `cjs` format",
1671
- command: "rolldown src/main.ts -d dist -f cjs"
1672
- },
1673
- {
1674
- title: "Bundle the `src/main.ts` and handle the `.png` assets to Data URL",
1675
- command: "rolldown src/main.ts -d dist --moduleTypes .png=dataurl"
1676
- },
1677
- {
1678
- title: "Bundle the `src/main.tsx` and minify the output with sourcemap",
1679
- command: "rolldown src/main.tsx -d dist -m -s"
1680
- },
1681
- {
1682
- title: "Create self-executing IIFE using external jQuery as `$` and `_`",
1683
- command: "rolldown src/main.ts -d dist -n bundle -f iife -e jQuery,window._ -g jQuery=$"
1684
- }
1685
- ];
1686
- const notes = [
1687
- "Due to the API limitation, you need to pass `-s` for `.map` sourcemap file as the last argument.",
1688
- "If you are using the configuration, please pass the `-c` as the last argument if you ignore the default configuration file.",
1689
- "CLI options will override the configuration file.",
1690
- "For more information, please visit https://rolldown.rs/."
1691
- ];
1692
- function showHelp() {
1693
- logger.log(introduction);
1694
- logger.log("");
1695
- logger.log(`${colors.bold(colors.underline("OPTIONS"))}`);
1696
- logger.log("");
1697
- logger.log(Object.entries(options).sort(([a$1], [b]) => {
1698
- if (options[a$1].short && !options[b].short) return -1;
1699
- if (!options[a$1].short && options[b].short) return 1;
1700
- if (options[a$1].short && options[b].short) return options[a$1].short.localeCompare(options[b].short);
1701
- return a$1.localeCompare(b);
1702
- }).map(([option, { type, short, hint, description: description$1 }]) => {
1703
- let optionStr = ` --${option} `;
1704
- option = camelCaseToKebabCase(option);
1705
- if (short) optionStr += `-${short}, `;
1706
- if (type === "string") optionStr += `<${hint ?? option}>`;
1707
- if (description$1 && description$1.length > 0) description$1 = description$1[0].toUpperCase() + description$1.slice(1);
1708
- return colors.cyan(optionStr.padEnd(30)) + description$1 + (description$1 && description$1?.endsWith(".") ? "" : ".");
1709
- }).join("\n"));
1710
- logger.log("");
1711
- logger.log(`${colors.bold(colors.underline("EXAMPLES"))}`);
1712
- logger.log("");
1713
- examples.forEach(({ title, command }, ord) => {
1714
- logger.log(` ${ord + 1}. ${title}:`);
1715
- logger.log(` ${colors.cyan(command)}`);
1716
- logger.log("");
1717
- });
1718
- logger.log(`${colors.bold(colors.underline("NOTES"))}`);
1719
- logger.log("");
1720
- notes.forEach((note) => {
1721
- logger.log(` * ${colors.gray(note)}`);
1722
- });
1723
- }
1724
-
1725
- //#endregion
1726
- //#region src/cli/index.ts
1727
- async function main() {
1728
- const cliOptions = parseCliArguments();
1729
- if (cliOptions.config || cliOptions.config === "") {
1730
- await bundleWithConfig(cliOptions.config, cliOptions);
1731
- return;
1732
- }
1733
- if ("input" in cliOptions.input) {
1734
- await bundleWithCliOptions(cliOptions);
1735
- return;
1736
- }
1737
- if (cliOptions.version) {
1738
- logger.log(`rolldown v${version}`);
1739
- return;
1740
- }
1741
- showHelp();
1742
- }
1743
- main().catch((err) => {
1744
- if (err instanceof Error && typeof err.stack === "string") err.stack = err.stack.replace(err.message, "");
1745
- logger.error(err);
1746
- process$1.exit(1);
1747
- });
1748
-
1749
- //#endregion
988
+ export { logger };