rolldown 1.0.0-beta.3-commit.e170e6e → 1.0.0-beta.30

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 (149) hide show
  1. package/bin/cli.mjs +2 -0
  2. package/dist/{cjs/cli.cjs → cli.cjs} +620 -620
  3. package/dist/cli.d.cts +1 -0
  4. package/dist/cli.d.mts +1 -0
  5. package/dist/{esm/cli.mjs → cli.mjs} +596 -593
  6. package/dist/config.cjs +12 -0
  7. package/dist/config.d.cts +10 -0
  8. package/dist/config.d.mts +10 -0
  9. package/dist/config.mjs +10 -0
  10. package/dist/experimental-index.cjs +105 -0
  11. package/dist/experimental-index.d.cts +58 -0
  12. package/dist/experimental-index.d.mts +58 -0
  13. package/dist/experimental-index.mjs +82 -0
  14. package/dist/experimental-runtime-types.d.ts +66 -0
  15. package/dist/filter-index.cjs +105 -0
  16. package/dist/filter-index.d.cts +4 -0
  17. package/dist/filter-index.d.mts +4 -0
  18. package/dist/filter-index.mjs +44 -0
  19. package/dist/index.cjs +9 -0
  20. package/dist/index.d.cts +3 -0
  21. package/dist/index.d.mts +3 -0
  22. package/dist/index.mjs +5 -0
  23. package/dist/{cjs/parallel-plugin-worker.cjs → parallel-plugin-worker.cjs} +6 -15
  24. package/dist/parallel-plugin-worker.d.cts +1 -0
  25. package/dist/parallel-plugin-worker.d.mts +1 -0
  26. package/dist/{esm/parallel-plugin-worker.mjs → parallel-plugin-worker.mjs} +5 -13
  27. package/dist/{cjs/parallel-plugin.cjs → parallel-plugin.cjs} +1 -2
  28. package/dist/parallel-plugin.d.cts +14 -0
  29. package/dist/parallel-plugin.d.mts +14 -0
  30. package/dist/{esm/parallel-plugin.mjs → parallel-plugin.mjs} +0 -1
  31. package/dist/parse-ast-index.cjs +4 -0
  32. package/dist/parse-ast-index.d.cts +8 -0
  33. package/dist/parse-ast-index.d.mts +8 -0
  34. package/dist/parse-ast-index.mjs +3 -0
  35. package/dist/shared/binding-BAyrv67G.d.cts +1309 -0
  36. package/dist/shared/binding-DUz1Q2JW.d.mts +1309 -0
  37. package/dist/shared/{chunk-qZFfknuJ.cjs → chunk-DDkG_k5U.cjs} +0 -1
  38. package/dist/shared/define-config-CMH1jWhX.d.cts +1331 -0
  39. package/dist/shared/define-config-D_KKKWbo.d.mts +1331 -0
  40. package/dist/shared/load-config-BWjPkvnW.mjs +119 -0
  41. package/dist/shared/load-config-BtTrX40c.cjs +125 -0
  42. package/dist/shared/misc-CQeo-AFx.mjs +22 -0
  43. package/dist/shared/misc-DksvspN4.cjs +58 -0
  44. package/dist/shared/parse-ast-index-DrqwhzH4.cjs +784 -0
  45. package/dist/shared/parse-ast-index-DyFjvjrb.mjs +656 -0
  46. package/dist/shared/{prompt-CxK9euq3.mjs → prompt-C5jz26Zn.mjs} +241 -240
  47. package/dist/shared/{prompt-ZZScCEWI.cjs → prompt-QNI93ne7.cjs} +245 -245
  48. package/dist/shared/src-CRRyjCYJ.cjs +4573 -0
  49. package/dist/shared/src-DR2upIfp.mjs +4381 -0
  50. package/package.json +69 -69
  51. package/bin/cli.js +0 -2
  52. package/dist/cjs/experimental-index.cjs +0 -85
  53. package/dist/cjs/index.cjs +0 -8
  54. package/dist/cjs/parse-ast-index.cjs +0 -4
  55. package/dist/esm/experimental-index.mjs +0 -57
  56. package/dist/esm/index.mjs +0 -4
  57. package/dist/esm/parse-ast-index.mjs +0 -3
  58. package/dist/shared/parse-ast-index-DIxeQDpE.mjs +0 -674
  59. package/dist/shared/parse-ast-index-Dh_sWnMa.cjs +0 -719
  60. package/dist/shared/src-CLo-BgXK.cjs +0 -3007
  61. package/dist/shared/src-CTS_IQ3m.mjs +0 -2826
  62. package/dist/types/api/build.d.ts +0 -18
  63. package/dist/types/api/experimental.d.ts +0 -7
  64. package/dist/types/api/rolldown/index.d.ts +0 -3
  65. package/dist/types/api/rolldown/rolldown-build.d.ts +0 -13
  66. package/dist/types/api/watch/index.d.ts +0 -3
  67. package/dist/types/api/watch/watch-emitter.d.ts +0 -31
  68. package/dist/types/api/watch/watcher.d.ts +0 -13
  69. package/dist/types/binding.d.ts +0 -1435
  70. package/dist/types/builtin-plugin/alias-plugin.d.ts +0 -10
  71. package/dist/types/builtin-plugin/constructors.d.ts +0 -21
  72. package/dist/types/builtin-plugin/replace-plugin.d.ts +0 -28
  73. package/dist/types/builtin-plugin/transform-plugin.d.ts +0 -9
  74. package/dist/types/builtin-plugin/utils.d.ts +0 -8
  75. package/dist/types/cli/arguments/alias.d.ts +0 -16
  76. package/dist/types/cli/arguments/index.d.ts +0 -15
  77. package/dist/types/cli/arguments/normalize.d.ts +0 -12
  78. package/dist/types/cli/arguments/utils.d.ts +0 -8
  79. package/dist/types/cli/colors.d.ts +0 -11
  80. package/dist/types/cli/commands/bundle.d.ts +0 -3
  81. package/dist/types/cli/commands/help.d.ts +0 -1
  82. package/dist/types/cli/index.d.ts +0 -1
  83. package/dist/types/cli/load-config.d.ts +0 -5
  84. package/dist/types/cli/logger.d.ts +0 -5
  85. package/dist/types/constants/plugin-context.d.ts +0 -7
  86. package/dist/types/constants/plugin.d.ts +0 -45
  87. package/dist/types/experimental-index.d.ts +0 -9
  88. package/dist/types/index.d.ts +0 -30
  89. package/dist/types/log/log-handler.d.ts +0 -4
  90. package/dist/types/log/logger.d.ts +0 -6
  91. package/dist/types/log/logging.d.ts +0 -12
  92. package/dist/types/log/logs.d.ts +0 -18
  93. package/dist/types/options/input-options.d.ts +0 -181
  94. package/dist/types/options/normalized-input-options.d.ts +0 -18
  95. package/dist/types/options/normalized-output-options.d.ts +0 -70
  96. package/dist/types/options/output-options.d.ts +0 -182
  97. package/dist/types/options/watch-options.d.ts +0 -5
  98. package/dist/types/parallel-plugin-worker.d.ts +0 -1
  99. package/dist/types/parallel-plugin.d.ts +0 -1
  100. package/dist/types/parse-ast-index.d.ts +0 -5
  101. package/dist/types/plugin/bindingify-build-hooks.d.ts +0 -10
  102. package/dist/types/plugin/bindingify-hook-filter.d.ts +0 -7
  103. package/dist/types/plugin/bindingify-output-hooks.d.ts +0 -14
  104. package/dist/types/plugin/bindingify-plugin-hook-meta.d.ts +0 -8
  105. package/dist/types/plugin/bindingify-plugin.d.ts +0 -16
  106. package/dist/types/plugin/bindingify-watch-hooks.d.ts +0 -5
  107. package/dist/types/plugin/hook-filter.d.ts +0 -48
  108. package/dist/types/plugin/index.d.ts +0 -134
  109. package/dist/types/plugin/minimal-plugin-context.d.ts +0 -23
  110. package/dist/types/plugin/parallel-plugin-implementation.d.ts +0 -10
  111. package/dist/types/plugin/parallel-plugin.d.ts +0 -9
  112. package/dist/types/plugin/plugin-context-data.d.ts +0 -17
  113. package/dist/types/plugin/plugin-context.d.ts +0 -67
  114. package/dist/types/plugin/plugin-driver.d.ts +0 -8
  115. package/dist/types/plugin/transform-plugin-context.d.ts +0 -28
  116. package/dist/types/types/assert.d.ts +0 -14
  117. package/dist/types/types/config-export.d.ts +0 -5
  118. package/dist/types/types/misc.d.ts +0 -40
  119. package/dist/types/types/module-info.d.ts +0 -15
  120. package/dist/types/types/module-side-effects.d.ts +0 -12
  121. package/dist/types/types/output-bundle.d.ts +0 -4
  122. package/dist/types/types/rolldown-options.d.ts +0 -5
  123. package/dist/types/types/rolldown-output.d.ts +0 -66
  124. package/dist/types/types/schema.d.ts +0 -33
  125. package/dist/types/types/sourcemap.d.ts +0 -14
  126. package/dist/types/types/utils.d.ts +0 -13
  127. package/dist/types/utils/asset-source.d.ts +0 -4
  128. package/dist/types/utils/async-flatten.d.ts +0 -1
  129. package/dist/types/utils/bindingify-input-options.d.ts +0 -7
  130. package/dist/types/utils/bindingify-output-options.d.ts +0 -5
  131. package/dist/types/utils/code-frame.d.ts +0 -1
  132. package/dist/types/utils/compose-js-plugins.d.ts +0 -2
  133. package/dist/types/utils/create-bundler-option.d.ts +0 -11
  134. package/dist/types/utils/create-bundler.d.ts +0 -8
  135. package/dist/types/utils/define-config.d.ts +0 -5
  136. package/dist/types/utils/error.d.ts +0 -2
  137. package/dist/types/utils/initialize-parallel-plugins.d.ts +0 -19
  138. package/dist/types/utils/misc.d.ts +0 -6
  139. package/dist/types/utils/normalize-hook.d.ts +0 -7
  140. package/dist/types/utils/normalize-plugin-option.d.ts +0 -13
  141. package/dist/types/utils/normalize-string-or-regex.d.ts +0 -2
  142. package/dist/types/utils/plugin/index.d.ts +0 -2
  143. package/dist/types/utils/transform-module-info.d.ts +0 -4
  144. package/dist/types/utils/transform-rendered-chunk.d.ts +0 -4
  145. package/dist/types/utils/transform-rendered-module.d.ts +0 -3
  146. package/dist/types/utils/transform-side-effects.d.ts +0 -3
  147. package/dist/types/utils/transform-sourcemap.d.ts +0 -3
  148. package/dist/types/utils/transform-to-rollup-output.d.ts +0 -11
  149. package/dist/types/utils/validator.d.ts +0 -6
@@ -1,187 +1,15 @@
1
- import { colors } from "../shared/parse-ast-index-DIxeQDpE.mjs";
2
- import { arraify, description, getInputCliKeys, getJsonSchema, getOutputCliKeys, rolldown, validateCliOptions, version, watch } from "../shared/src-CTS_IQ3m.mjs";
3
- import process$1, { cwd } from "node:process";
1
+ import { __commonJS, __toESM } from "./shared/parse-ast-index-DyFjvjrb.mjs";
2
+ import { description, getInputCliKeys, getJsonSchema, getOutputCliKeys, rolldown, validateCliOptions, version, watch } from "./shared/src-DR2upIfp.mjs";
3
+ import { arraify } from "./shared/misc-CQeo-AFx.mjs";
4
+ import { loadConfig } from "./shared/load-config-BWjPkvnW.mjs";
4
5
  import path, { sep } from "node:path";
5
- import fs from "node:fs";
6
- import { performance } from "node:perf_hooks";
6
+ import colors from "ansis";
7
+ import process$1 from "node:process";
7
8
  import { formatWithOptions, parseArgs } from "node:util";
8
9
  import * as tty from "node:tty";
9
- import { readdir } from "node:fs/promises";
10
- import { pathToFileURL } from "node:url";
11
-
12
- //#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.js
13
- const signals = [];
14
- signals.push("SIGHUP", "SIGINT", "SIGTERM");
15
- if (process.platform !== "win32") signals.push(
16
- "SIGALRM",
17
- "SIGABRT",
18
- "SIGVTALRM",
19
- "SIGXCPU",
20
- "SIGXFSZ",
21
- "SIGUSR2",
22
- "SIGTRAP",
23
- "SIGSYS",
24
- "SIGQUIT",
25
- "SIGIOT"
26
- // should detect profiler and enable/disable accordingly.
27
- // see #21
28
- // 'SIGPROF'
29
- );
30
- if (process.platform === "linux") signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");
31
-
32
- //#endregion
33
- //#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.js
34
- const processOk = (process$3) => !!process$3 && typeof process$3 === "object" && typeof process$3.removeListener === "function" && typeof process$3.emit === "function" && typeof process$3.reallyExit === "function" && typeof process$3.listeners === "function" && typeof process$3.kill === "function" && typeof process$3.pid === "number" && typeof process$3.on === "function";
35
- const kExitEmitter = Symbol.for("signal-exit emitter");
36
- const global = globalThis;
37
- const ObjectDefineProperty = Object.defineProperty.bind(Object);
38
- var Emitter = class {
39
- emitted = {
40
- afterExit: false,
41
- exit: false
42
- };
43
- listeners = {
44
- afterExit: [],
45
- exit: []
46
- };
47
- count = 0;
48
- id = Math.random();
49
- constructor() {
50
- if (global[kExitEmitter]) return global[kExitEmitter];
51
- ObjectDefineProperty(global, kExitEmitter, {
52
- value: this,
53
- writable: false,
54
- enumerable: false,
55
- configurable: false
56
- });
57
- }
58
- on(ev, fn) {
59
- this.listeners[ev].push(fn);
60
- }
61
- removeListener(ev, fn) {
62
- const list = this.listeners[ev];
63
- const i$1 = list.indexOf(fn);
64
- if (i$1 === -1) return;
65
- if (i$1 === 0 && list.length === 1) list.length = 0;
66
- else list.splice(i$1, 1);
67
- }
68
- emit(ev, code, signal) {
69
- if (this.emitted[ev]) return false;
70
- this.emitted[ev] = true;
71
- let ret = false;
72
- for (const fn of this.listeners[ev]) ret = fn(code, signal) === true || ret;
73
- if (ev === "exit") ret = this.emit("afterExit", code, signal) || ret;
74
- return ret;
75
- }
76
- };
77
- var SignalExitBase = class {};
78
- const signalExitWrap = (handler) => {
79
- return {
80
- onExit(cb, opts) {
81
- return handler.onExit(cb, opts);
82
- },
83
- load() {
84
- return handler.load();
85
- },
86
- unload() {
87
- return handler.unload();
88
- }
89
- };
90
- };
91
- var SignalExitFallback = class extends SignalExitBase {
92
- onExit() {
93
- return () => {};
94
- }
95
- load() {}
96
- unload() {}
97
- };
98
- var SignalExit = class extends SignalExitBase {
99
- #hupSig = process$2.platform === "win32" ? "SIGINT" : "SIGHUP";
100
- #emitter = new Emitter();
101
- #process;
102
- #originalProcessEmit;
103
- #originalProcessReallyExit;
104
- #sigListeners = {};
105
- #loaded = false;
106
- constructor(process$3) {
107
- super();
108
- this.#process = process$3;
109
- this.#sigListeners = {};
110
- for (const sig of signals) this.#sigListeners[sig] = () => {
111
- const listeners = this.#process.listeners(sig);
112
- let { count } = this.#emitter;
113
- const p$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());
10
+ import { performance } from "node:perf_hooks";
182
11
 
183
- //#endregion
184
- //#region ../../node_modules/.pnpm/consola@3.4.0/node_modules/consola/dist/core.mjs
12
+ //#region ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/core.mjs
185
13
  const LogLevels = {
186
14
  silent: Number.NEGATIVE_INFINITY,
187
15
  fatal: 0,
@@ -237,7 +65,7 @@ function _defu(baseObject, defaults, namespace = ".", merger) {
237
65
  return object;
238
66
  }
239
67
  function createDefu(merger) {
240
- return (...arguments_) => arguments_.reduce((p$1, c$1) => _defu(p$1, c$1, "", merger), {});
68
+ return (...arguments_) => arguments_.reduce((p, c$1) => _defu(p, c$1, "", merger), {});
241
69
  }
242
70
  const defu = createDefu();
243
71
  function isPlainObject(obj) {
@@ -567,10 +395,10 @@ function createConsola$1(options$1 = {}) {
567
395
  }
568
396
 
569
397
  //#endregion
570
- //#region ../../node_modules/.pnpm/consola@3.4.0/node_modules/consola/dist/shared/consola.Cs5FdtHD.mjs
571
- function parseStack(stack) {
398
+ //#region ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs
399
+ function parseStack(stack, message) {
572
400
  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, ""));
401
+ const lines = stack.split("\n").splice(message.split("\n").length).map((l$1) => l$1.trim().replace("file://", "").replace(cwd$1, ""));
574
402
  return lines;
575
403
  }
576
404
  function writeStream(data, stream) {
@@ -579,14 +407,14 @@ function writeStream(data, stream) {
579
407
  }
580
408
  const bracket = (x) => x ? `[${x}]` : "";
581
409
  var BasicReporter = class {
582
- formatStack(stack, opts) {
410
+ formatStack(stack, message, opts) {
583
411
  const indent = " ".repeat((opts?.errorLevel || 0) + 1);
584
- return indent + parseStack(stack).join(`
412
+ return indent + parseStack(stack, message).join(`
585
413
  ${indent}`);
586
414
  }
587
415
  formatError(err, opts) {
588
416
  const message = err.message ?? formatWithOptions(opts, err);
589
- const stack = err.stack ? this.formatStack(err.stack, opts) : "";
417
+ const stack = err.stack ? this.formatStack(err.stack, message, opts) : "";
590
418
  const level = opts?.errorLevel || 0;
591
419
  const causedPrefix = level > 0 ? `${" ".repeat(level)}[cause]: ` : "";
592
420
  const causedError = err.cause ? "\n\n" + this.formatError(err.cause, {
@@ -631,14 +459,14 @@ ${indent}`);
631
459
  };
632
460
 
633
461
  //#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");
462
+ //#region ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs
463
+ const { env = {}, argv = [], platform = "" } = typeof process === "undefined" ? {} : process;
464
+ const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
465
+ const isForced = "FORCE_COLOR" in env || argv.includes("--color");
638
466
  const isWindows = platform === "win32";
639
- const isDumbTerminal = env$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);
467
+ const isDumbTerminal = env.TERM === "dumb";
468
+ const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal;
469
+ const isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
642
470
  const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
643
471
  function replaceClose(index, string, close, replace, head = string.slice(0, Math.max(0, index)) + replace, tail = string.slice(Math.max(0, index + close.length)), next = tail.indexOf(close)) {
644
472
  return head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
@@ -703,7 +531,7 @@ function getColor$1(color, fallback = "reset") {
703
531
  return colors$1[color] || colors$1[fallback];
704
532
  }
705
533
  const ansiRegex$1 = [String.raw`[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)`, String.raw`(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))`].join("|");
706
- function stripAnsi$1(text) {
534
+ function stripAnsi(text) {
707
535
  return text.replace(new RegExp(ansiRegex$1, "g"), "");
708
536
  }
709
537
  const boxStylePresets = {
@@ -796,14 +624,14 @@ function box(text, _opts = {}) {
796
624
  if (_color) for (const key in borderStyle) borderStyle[key] = _color(borderStyle[key]);
797
625
  const paddingOffset = opts.style.padding % 2 === 0 ? opts.style.padding : opts.style.padding + 1;
798
626
  const height = textLines.length + paddingOffset;
799
- const width = Math.max(...textLines.map((line) => stripAnsi$1(line).length)) + paddingOffset;
627
+ const width = Math.max(...textLines.map((line) => stripAnsi(line).length), opts.title ? stripAnsi(opts.title).length : 0) + paddingOffset;
800
628
  const widthOffset = width + paddingOffset;
801
629
  const leftSpace = opts.style.marginLeft > 0 ? " ".repeat(opts.style.marginLeft) : "";
802
630
  if (opts.style.marginTop > 0) boxLines.push("".repeat(opts.style.marginTop));
803
631
  if (opts.title) {
804
632
  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);
633
+ const left = borderStyle.h.repeat(Math.floor((width - stripAnsi(opts.title).length) / 2));
634
+ const right = borderStyle.h.repeat(width - stripAnsi(opts.title).length - stripAnsi(left).length + paddingOffset);
807
635
  boxLines.push(`${leftSpace}${borderStyle.tl}${left}${title}${right}${borderStyle.tr}`);
808
636
  } else boxLines.push(`${leftSpace}${borderStyle.tl}${borderStyle.h.repeat(widthOffset)}${borderStyle.tr}`);
809
637
  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 +639,7 @@ function box(text, _opts = {}) {
811
639
  else {
812
640
  const line = textLines[i$1 - valignOffset];
813
641
  const left = " ".repeat(paddingOffset);
814
- const right = " ".repeat(width - stripAnsi$1(line).length);
642
+ const right = " ".repeat(width - stripAnsi(line).length);
815
643
  boxLines.push(`${leftSpace}${borderStyle.v}${left}${line}${right}${borderStyle.v}`);
816
644
  }
817
645
  boxLines.push(`${leftSpace}${borderStyle.bl}${borderStyle.h.repeat(widthOffset)}${borderStyle.br}`);
@@ -820,29 +648,29 @@ function box(text, _opts = {}) {
820
648
  }
821
649
 
822
650
  //#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];
651
+ //#region ../../node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/index.mjs
652
+ const r = Object.create(null), i = (e) => globalThis.process?.env || import.meta.env || globalThis.Deno?.env.toObject() || globalThis.__env__ || (e ? r : globalThis), o = new Proxy(r, {
653
+ get(e, s$1) {
654
+ return i()[s$1] ?? r[s$1];
827
655
  },
828
- has(e, o) {
656
+ has(e, s$1) {
829
657
  const E = i();
830
- return o in E || o in r;
658
+ return s$1 in E || s$1 in r;
831
659
  },
832
- set(e, o, E) {
833
- const b = i(true);
834
- return b[o] = E, true;
660
+ set(e, s$1, E) {
661
+ const B = i(true);
662
+ return B[s$1] = E, true;
835
663
  },
836
- deleteProperty(e, o) {
837
- if (!o) return false;
664
+ deleteProperty(e, s$1) {
665
+ if (!s$1) return false;
838
666
  const E = i(true);
839
- return delete E[o], true;
667
+ return delete E[s$1], true;
840
668
  },
841
669
  ownKeys() {
842
670
  const e = i(true);
843
671
  return Object.keys(e);
844
672
  }
845
- }), t = typeof process < "u" && process.env && process.env.NODE_ENV || "", B = [
673
+ }), t = typeof process < "u" && process.env && process.env.NODE_ENV || "", f = [
846
674
  ["APPVEYOR"],
847
675
  [
848
676
  "AWS_AMPLIFY",
@@ -910,6 +738,11 @@ const r = Object.create(null), i = (e) => globalThis.process?.env || import.meta
910
738
  "CODESANDBOX_SSE",
911
739
  { ci: false }
912
740
  ],
741
+ [
742
+ "CODESANDBOX",
743
+ "CODESANDBOX_HOST",
744
+ { ci: false }
745
+ ],
913
746
  ["STACKBLITZ"],
914
747
  ["STORMKIT"],
915
748
  ["CLEAVR"],
@@ -928,10 +761,10 @@ const r = Object.create(null), i = (e) => globalThis.process?.env || import.meta
928
761
  { ci: true }
929
762
  ]
930
763
  ];
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 {
764
+ function b() {
765
+ if (globalThis.process?.env) for (const e of f) {
766
+ const s$1 = e[1] || e[0];
767
+ if (globalThis.process?.env[s$1]) return {
935
768
  name: e[0].toLowerCase(),
936
769
  ...e[2]
937
770
  };
@@ -944,45 +777,45 @@ function p() {
944
777
  ci: false
945
778
  };
946
779
  }
947
- const l = p();
780
+ const l = b();
948
781
  l.name;
949
782
  function n(e) {
950
783
  return e ? e !== "false" : false;
951
784
  }
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);
785
+ 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);
786
+ n(o.MINIMAL);
787
+ const A = /^win/i.test(I);
788
+ !n(o.NO_COLOR) && (n(o.FORCE_COLOR) || (a || A) && o.TERM);
956
789
  const C = (globalThis.process?.versions?.node || "").replace(/^v/, "") || null;
957
790
  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];
791
+ const y = globalThis.process || Object.create(null), _ = { versions: {} };
792
+ new Proxy(y, { get(e, s$1) {
793
+ if (s$1 === "env") return o;
794
+ if (s$1 in e) return e[s$1];
795
+ if (s$1 in _) return _[s$1];
963
796
  } });
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 = [
797
+ 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
798
  [S, "netlify"],
966
- [N, "edge-light"],
967
- [P, "workerd"],
968
- [O, "fastly"],
799
+ [u, "edge-light"],
800
+ [N, "workerd"],
801
+ [L, "fastly"],
969
802
  [D, "deno"],
970
- [a, "bun"],
971
- [L, "node"]
803
+ [O, "bun"],
804
+ [c, "node"]
972
805
  ];
973
806
  function G() {
974
- const e = F.find((o) => o[0]);
807
+ const e = F.find((s$1) => s$1[0]);
975
808
  if (e) return { name: e[1] };
976
809
  }
977
- const u = G();
978
- u?.name;
810
+ const P = G();
811
+ P?.name;
979
812
  function ansiRegex({ onlyFirst = false } = {}) {
980
813
  const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
981
814
  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("|");
982
815
  return new RegExp(pattern, onlyFirst ? void 0 : "g");
983
816
  }
984
817
  const regex = ansiRegex();
985
- function stripAnsi(string) {
818
+ function stripAnsi$1(string) {
986
819
  if (typeof string !== "string") throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
987
820
  return string.replace(regex, "");
988
821
  }
@@ -1011,7 +844,7 @@ const defaultIgnorableCodePointRegex = /^\p{Default_Ignorable_Code_Point}$/u;
1011
844
  function stringWidth$1(string, options$1 = {}) {
1012
845
  if (typeof string !== "string" || string.length === 0) return 0;
1013
846
  const { ambiguousIsNarrow = true, countAnsiEscapeCodes = false } = options$1;
1014
- if (!countAnsiEscapeCodes) string = stripAnsi(string);
847
+ if (!countAnsiEscapeCodes) string = stripAnsi$1(string);
1015
848
  if (string.length === 0) return 0;
1016
849
  let width = 0;
1017
850
  const eastAsianWidthOptions = { ambiguousAsWide: !ambiguousIsNarrow };
@@ -1032,10 +865,10 @@ function stringWidth$1(string, options$1 = {}) {
1032
865
  return width;
1033
866
  }
1034
867
  function isUnicodeSupported() {
1035
- const { env: env$2 } = process$1;
1036
- const { TERM, TERM_PROGRAM } = env$2;
868
+ const { env: env$1 } = process$1;
869
+ const { TERM, TERM_PROGRAM } = env$1;
1037
870
  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";
871
+ 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
872
  }
1040
873
  const TYPE_COLOR_MAP = {
1041
874
  info: "cyan",
@@ -1065,14 +898,14 @@ const TYPE_ICONS = {
1065
898
  };
1066
899
  function stringWidth(str) {
1067
900
  const hasICU = typeof Intl === "object";
1068
- if (!hasICU || !Intl.Segmenter) return stripAnsi$1(str).length;
901
+ if (!hasICU || !Intl.Segmenter) return stripAnsi(str).length;
1069
902
  return stringWidth$1(str);
1070
903
  }
1071
904
  var FancyReporter = class extends BasicReporter {
1072
- formatStack(stack, opts) {
905
+ formatStack(stack, message, opts) {
1073
906
  const indent = " ".repeat((opts?.errorLevel || 0) + 1);
1074
907
  return `
1075
- ${indent}` + parseStack(stack).map((line) => " " + line.replace(/^at +/, (m) => colors$1.gray(m)).replace(/\((.+)\)/, (_$1, m) => `(${colors$1.cyan(m)})`)).join(`
908
+ ${indent}` + parseStack(stack, message).map((line) => " " + line.replace(/^at +/, (m) => colors$1.gray(m)).replace(/\((.+)\)/, (_$1, m) => `(${colors$1.cyan(m)})`)).join(`
1076
909
  ${indent}`);
1077
910
  }
1078
911
  formatType(logObj, isBadge, opts) {
@@ -1099,8 +932,8 @@ ${indent}`);
1099
932
  line = space > 0 && (opts.columns || 0) >= 80 ? left + " ".repeat(space) + right : (right ? `${colors$1.gray(`[${right}]`)} ` : "") + left;
1100
933
  line += characterFormat(additional.length > 0 ? "\n" + additional.join("\n") : "");
1101
934
  if (logObj.type === "trace") {
1102
- const _err = new Error("Trace: " + logObj.message);
1103
- line += this.formatStack(_err.stack || "");
935
+ const _err = /* @__PURE__ */ new Error("Trace: " + logObj.message);
936
+ line += this.formatStack(_err.stack || "", _err.message);
1104
937
  }
1105
938
  return isBadge ? "\n" + line + "\n" : line;
1106
939
  }
@@ -1122,21 +955,24 @@ function createConsola(options$1 = {}) {
1122
955
  defaults: { level },
1123
956
  stdout: process.stdout,
1124
957
  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()],
958
+ prompt: (...args) => import("./shared/prompt-C5jz26Zn.mjs").then((m) => m.prompt(...args)),
959
+ reporters: options$1.reporters || [options$1.fancy ?? !(T || R) ? new FancyReporter() : new BasicReporter()],
1127
960
  ...options$1
1128
961
  });
1129
962
  return consola2;
1130
963
  }
1131
964
  function _getDefaultLogLevel() {
1132
- if (U) return LogLevels.debug;
1133
- if (A) return LogLevels.warn;
965
+ if (g) return LogLevels.debug;
966
+ if (R) return LogLevels.warn;
1134
967
  return LogLevels.info;
1135
968
  }
1136
969
  const consola = createConsola();
1137
970
 
1138
971
  //#endregion
1139
972
  //#region src/cli/logger.ts
973
+ /**
974
+ * Console logger
975
+ */
1140
976
  const logger = process.env.ROLLDOWN_TEST ? createTestingLogger() : createConsola({ formatOptions: { date: false } });
1141
977
  function createTestingLogger() {
1142
978
  const types = [
@@ -1161,139 +997,520 @@ function createTestingLogger() {
1161
997
  }
1162
998
 
1163
999
  //#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"
1000
+ //#region src/cli/arguments/alias.ts
1001
+ const alias = {
1002
+ config: {
1003
+ abbreviation: "c",
1004
+ hint: "filename"
1005
+ },
1006
+ help: { abbreviation: "h" },
1007
+ version: { abbreviation: "v" },
1008
+ watch: { abbreviation: "w" },
1009
+ dir: { abbreviation: "d" },
1010
+ file: { abbreviation: "o" },
1011
+ external: { abbreviation: "e" },
1012
+ format: { abbreviation: "f" },
1013
+ name: { abbreviation: "n" },
1014
+ globals: { abbreviation: "g" },
1015
+ sourcemap: {
1016
+ abbreviation: "s",
1017
+ default: true
1018
+ },
1019
+ minify: { abbreviation: "m" },
1020
+ platform: { abbreviation: "p" },
1021
+ assetFileNames: { hint: "name" },
1022
+ chunkFileNames: { hint: "name" },
1023
+ entryFileNames: { hint: "name" },
1024
+ externalLiveBindings: {
1025
+ default: true,
1026
+ reverse: true
1027
+ },
1028
+ treeshake: {
1029
+ default: true,
1030
+ reverse: true
1031
+ },
1032
+ preserveEntrySignatures: {
1033
+ default: "strict",
1034
+ reverse: true
1035
+ },
1036
+ moduleTypes: { hint: "types" }
1037
+ };
1038
+
1039
+ //#endregion
1040
+ //#region src/cli/arguments/utils.ts
1041
+ const priority = [
1042
+ "object",
1043
+ "array",
1044
+ "string",
1045
+ "number",
1046
+ "boolean"
1215
1047
  ];
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, () => {});
1048
+ function getSchemaType(schema) {
1049
+ if ("anyOf" in schema) {
1050
+ const types = schema.anyOf.map(getSchemaType);
1051
+ let result = priority.find((type) => types.includes(type));
1052
+ if (result) return result;
1233
1053
  }
1054
+ if ("type" in schema) return schema.type;
1055
+ if ("const" in schema) return typeof schema.const;
1056
+ return "never";
1234
1057
  }
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;
1058
+ function flattenSchema(schema, base = {}, parent = "") {
1059
+ if (schema === void 0) return base;
1060
+ for (const [k, value] of Object.entries(schema)) {
1061
+ const key = parent ? `${parent}.${k}` : k;
1062
+ if (getSchemaType(value) === "object") if ("properties" in value) flattenSchema(value.properties, base, key);
1063
+ else base[key] = value;
1064
+ else base[key] = value;
1242
1065
  }
1066
+ return base;
1243
1067
  }
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;
1068
+ function setNestedProperty(obj, path$1, value) {
1069
+ const keys = path$1.split(".");
1070
+ let current = obj;
1071
+ for (let i$1 = 0; i$1 < keys.length - 1; i$1++) {
1072
+ if (!current[keys[i$1]]) current[keys[i$1]] = {};
1073
+ current = current[keys[i$1]];
1253
1074
  }
1254
- return null;
1075
+ const finalKey = keys[keys.length - 1];
1076
+ Object.defineProperty(current, finalKey, {
1077
+ value,
1078
+ writable: true,
1079
+ enumerable: true,
1080
+ configurable: true
1081
+ });
1255
1082
  }
1256
- function tryStatSync(file) {
1257
- try {
1258
- return fs.statSync(file, { throwIfNoEntry: false });
1259
- } catch {}
1083
+ function camelCaseToKebabCase(str) {
1084
+ return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
1260
1085
  }
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
- }
1086
+ function kebabCaseToCamelCase(str) {
1087
+ return str.replace(/-./g, (match) => match[1].toUpperCase());
1272
1088
  }
1273
1089
 
1274
1090
  //#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}`);
1091
+ //#region src/cli/arguments/normalize.ts
1092
+ function normalizeCliOptions(cliOptions, positionals) {
1093
+ const [data, errors] = validateCliOptions(cliOptions);
1094
+ if (errors?.length) {
1095
+ errors.forEach((error) => {
1096
+ logger.error(`${error}. You can use \`rolldown -h\` to see the help.`);
1097
+ });
1098
+ process.exit(1);
1099
+ }
1100
+ const options$1 = data ?? {};
1101
+ const result = {
1102
+ input: {},
1103
+ output: {},
1104
+ help: options$1.help ?? false,
1105
+ version: options$1.version ?? false,
1106
+ watch: options$1.watch ?? false
1107
+ };
1108
+ if (typeof options$1.config === "string") result.config = options$1.config;
1109
+ const keysOfInput = getInputCliKeys();
1110
+ const keysOfOutput = getOutputCliKeys();
1111
+ const reservedKeys = [
1112
+ "help",
1113
+ "version",
1114
+ "config",
1115
+ "watch"
1116
+ ];
1117
+ for (let [key, value] of Object.entries(options$1)) {
1118
+ const keys = key.split(".");
1119
+ const [primary] = keys;
1120
+ if (keysOfInput.includes(primary)) setNestedProperty(result.input, key, value);
1121
+ else if (keysOfOutput.includes(primary)) setNestedProperty(result.output, key, value);
1122
+ else if (!reservedKeys.includes(key)) {
1123
+ logger.error(`Unknown option: ${key}`);
1124
+ process.exit(1);
1125
+ }
1126
+ }
1127
+ if (!result.config && positionals.length > 0) if (Array.isArray(result.input.input)) result.input.input.push(...positionals);
1128
+ else result.input.input = positionals;
1129
+ return result;
1130
+ }
1131
+
1132
+ //#endregion
1133
+ //#region src/cli/arguments/index.ts
1134
+ const objectSchema = getJsonSchema();
1135
+ const flattenedSchema = flattenSchema(objectSchema.properties);
1136
+ const options = Object.fromEntries(Object.entries(flattenedSchema).filter(([_key, schema]) => getSchemaType(schema) !== "never").map(([key, schema]) => {
1137
+ const config = Object.getOwnPropertyDescriptor(alias, key)?.value;
1138
+ const type = getSchemaType(schema);
1139
+ const result = {
1140
+ type: type === "boolean" ? "boolean" : "string",
1141
+ description: schema?.description ?? config?.description ?? "",
1142
+ hint: config?.hint
1143
+ };
1144
+ if (config && config?.abbreviation) result.short = config?.abbreviation;
1145
+ if (config && config.reverse) {
1146
+ if (result.description.startsWith("enable")) result.description = result.description.replace("enable", "disable");
1147
+ else if (!result.description.startsWith("Avoid")) result.description = `disable ${result.description}`;
1148
+ }
1149
+ key = camelCaseToKebabCase(key);
1150
+ return [config?.reverse ? `no-${key}` : key, result];
1151
+ }));
1152
+ function parseCliArguments() {
1153
+ const { values, tokens, positionals } = parseArgs({
1154
+ options,
1155
+ tokens: true,
1156
+ allowPositionals: true,
1157
+ strict: false
1158
+ });
1159
+ tokens.filter((token) => token.kind === "option").forEach((option) => {
1160
+ let negative = false;
1161
+ if (option.name.startsWith("no-")) {
1162
+ const name = kebabCaseToCamelCase(option.name.substring(3));
1163
+ if (name in flattenedSchema) {
1164
+ delete values[option.name];
1165
+ option.name = name;
1166
+ negative = true;
1167
+ }
1168
+ }
1169
+ delete values[option.name];
1170
+ option.name = kebabCaseToCamelCase(option.name);
1171
+ let originalType = flattenedSchema[option.name];
1172
+ if (!originalType) {
1173
+ logger.error(`Invalid option: ${option.rawName}. We will ignore this option.`);
1174
+ process.exit(1);
1175
+ }
1176
+ let type = getSchemaType(originalType);
1177
+ if (type === "string" && typeof option.value !== "string") {
1178
+ let opt = option;
1179
+ let defaultValue = Object.getOwnPropertyDescriptor(alias, opt.name)?.value;
1180
+ Object.defineProperty(values, opt.name, {
1181
+ value: defaultValue.default ?? "",
1182
+ enumerable: true,
1183
+ configurable: true,
1184
+ writable: true
1185
+ });
1186
+ } else if (type === "object" && typeof option.value === "string") {
1187
+ const [key, value] = option.value.split(",").map((x) => x.split("="))[0];
1188
+ if (!values[option.name]) Object.defineProperty(values, option.name, {
1189
+ value: {},
1190
+ enumerable: true,
1191
+ configurable: true,
1192
+ writable: true
1193
+ });
1194
+ if (key && value) Object.defineProperty(values[option.name], key, {
1195
+ value,
1196
+ enumerable: true,
1197
+ configurable: true,
1198
+ writable: true
1199
+ });
1200
+ } else if (type === "array" && typeof option.value === "string") {
1201
+ if (!values[option.name]) Object.defineProperty(values, option.name, {
1202
+ value: [],
1203
+ enumerable: true,
1204
+ configurable: true,
1205
+ writable: true
1206
+ });
1207
+ values[option.name].push(option.value);
1208
+ } else if (type === "boolean") Object.defineProperty(values, option.name, {
1209
+ value: !negative,
1210
+ enumerable: true,
1211
+ configurable: true,
1212
+ writable: true
1213
+ });
1214
+ else Object.defineProperty(values, option.name, {
1215
+ value: option.value ?? "",
1216
+ enumerable: true,
1217
+ configurable: true,
1218
+ writable: true
1219
+ });
1220
+ });
1221
+ return normalizeCliOptions(values, positionals);
1222
+ }
1223
+
1224
+ //#endregion
1225
+ //#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.js
1226
+ /**
1227
+ * This is not the set of all possible signals.
1228
+ *
1229
+ * It IS, however, the set of all signals that trigger
1230
+ * an exit on either Linux or BSD systems. Linux is a
1231
+ * superset of the signal names supported on BSD, and
1232
+ * the unknown signals just fail to register, so we can
1233
+ * catch that easily enough.
1234
+ *
1235
+ * Windows signals are a different set, since there are
1236
+ * signals that terminate Windows processes, but don't
1237
+ * terminate (or don't even exist) on Posix systems.
1238
+ *
1239
+ * Don't bother with SIGKILL. It's uncatchable, which
1240
+ * means that we can't fire any callbacks anyway.
1241
+ *
1242
+ * If a user does happen to register a handler on a non-
1243
+ * fatal signal like SIGWINCH or something, and then
1244
+ * exit, it'll end up firing `process.emit('exit')`, so
1245
+ * the handler will be fired anyway.
1246
+ *
1247
+ * SIGBUS, SIGFPE, SIGSEGV and SIGILL, when not raised
1248
+ * artificially, inherently leave the process in a
1249
+ * state from which it is not safe to try and enter JS
1250
+ * listeners.
1251
+ */
1252
+ const signals = [];
1253
+ signals.push("SIGHUP", "SIGINT", "SIGTERM");
1254
+ if (process.platform !== "win32") signals.push("SIGALRM", "SIGABRT", "SIGVTALRM", "SIGXCPU", "SIGXFSZ", "SIGUSR2", "SIGTRAP", "SIGSYS", "SIGQUIT", "SIGIOT");
1255
+ if (process.platform === "linux") signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");
1256
+
1257
+ //#endregion
1258
+ //#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.js
1259
+ 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";
1260
+ const kExitEmitter = Symbol.for("signal-exit emitter");
1261
+ const global = globalThis;
1262
+ const ObjectDefineProperty = Object.defineProperty.bind(Object);
1263
+ var Emitter = class {
1264
+ emitted = {
1265
+ afterExit: false,
1266
+ exit: false
1267
+ };
1268
+ listeners = {
1269
+ afterExit: [],
1270
+ exit: []
1271
+ };
1272
+ count = 0;
1273
+ id = Math.random();
1274
+ constructor() {
1275
+ if (global[kExitEmitter]) return global[kExitEmitter];
1276
+ ObjectDefineProperty(global, kExitEmitter, {
1277
+ value: this,
1278
+ writable: false,
1279
+ enumerable: false,
1280
+ configurable: false
1281
+ });
1282
+ }
1283
+ on(ev, fn) {
1284
+ this.listeners[ev].push(fn);
1285
+ }
1286
+ removeListener(ev, fn) {
1287
+ const list = this.listeners[ev];
1288
+ const i$1 = list.indexOf(fn);
1289
+ /* c8 ignore start */
1290
+ if (i$1 === -1) return;
1291
+ /* c8 ignore stop */
1292
+ if (i$1 === 0 && list.length === 1) list.length = 0;
1293
+ else list.splice(i$1, 1);
1294
+ }
1295
+ emit(ev, code, signal) {
1296
+ if (this.emitted[ev]) return false;
1297
+ this.emitted[ev] = true;
1298
+ let ret = false;
1299
+ for (const fn of this.listeners[ev]) ret = fn(code, signal) === true || ret;
1300
+ if (ev === "exit") ret = this.emit("afterExit", code, signal) || ret;
1301
+ return ret;
1302
+ }
1303
+ };
1304
+ var SignalExitBase = class {};
1305
+ const signalExitWrap = (handler) => {
1306
+ return {
1307
+ onExit(cb, opts) {
1308
+ return handler.onExit(cb, opts);
1309
+ },
1310
+ load() {
1311
+ return handler.load();
1312
+ },
1313
+ unload() {
1314
+ return handler.unload();
1315
+ }
1316
+ };
1317
+ };
1318
+ var SignalExitFallback = class extends SignalExitBase {
1319
+ onExit() {
1320
+ return () => {};
1321
+ }
1322
+ load() {}
1323
+ unload() {}
1324
+ };
1325
+ var SignalExit = class extends SignalExitBase {
1326
+ /* c8 ignore start */
1327
+ #hupSig = process$2.platform === "win32" ? "SIGINT" : "SIGHUP";
1328
+ /* c8 ignore stop */
1329
+ #emitter = new Emitter();
1330
+ #process;
1331
+ #originalProcessEmit;
1332
+ #originalProcessReallyExit;
1333
+ #sigListeners = {};
1334
+ #loaded = false;
1335
+ constructor(process$3) {
1336
+ super();
1337
+ this.#process = process$3;
1338
+ this.#sigListeners = {};
1339
+ for (const sig of signals) this.#sigListeners[sig] = () => {
1340
+ const listeners = this.#process.listeners(sig);
1341
+ let { count } = this.#emitter;
1342
+ /* c8 ignore start */
1343
+ const p = process$3;
1344
+ if (typeof p.__signal_exit_emitter__ === "object" && typeof p.__signal_exit_emitter__.count === "number") count += p.__signal_exit_emitter__.count;
1345
+ /* c8 ignore stop */
1346
+ if (listeners.length === count) {
1347
+ this.unload();
1348
+ const ret = this.#emitter.emit("exit", null, sig);
1349
+ /* c8 ignore start */
1350
+ const s$1 = sig === "SIGHUP" ? this.#hupSig : sig;
1351
+ if (!ret) process$3.kill(process$3.pid, s$1);
1352
+ }
1353
+ };
1354
+ this.#originalProcessReallyExit = process$3.reallyExit;
1355
+ this.#originalProcessEmit = process$3.emit;
1356
+ }
1357
+ onExit(cb, opts) {
1358
+ /* c8 ignore start */
1359
+ if (!processOk(this.#process)) return () => {};
1360
+ /* c8 ignore stop */
1361
+ if (this.#loaded === false) this.load();
1362
+ const ev = opts?.alwaysLast ? "afterExit" : "exit";
1363
+ this.#emitter.on(ev, cb);
1364
+ return () => {
1365
+ this.#emitter.removeListener(ev, cb);
1366
+ if (this.#emitter.listeners["exit"].length === 0 && this.#emitter.listeners["afterExit"].length === 0) this.unload();
1367
+ };
1368
+ }
1369
+ load() {
1370
+ if (this.#loaded) return;
1371
+ this.#loaded = true;
1372
+ this.#emitter.count += 1;
1373
+ for (const sig of signals) try {
1374
+ const fn = this.#sigListeners[sig];
1375
+ if (fn) this.#process.on(sig, fn);
1376
+ } catch (_$1) {}
1377
+ this.#process.emit = (ev, ...a$1) => {
1378
+ return this.#processEmit(ev, ...a$1);
1379
+ };
1380
+ this.#process.reallyExit = (code) => {
1381
+ return this.#processReallyExit(code);
1382
+ };
1383
+ }
1384
+ unload() {
1385
+ if (!this.#loaded) return;
1386
+ this.#loaded = false;
1387
+ signals.forEach((sig) => {
1388
+ const listener = this.#sigListeners[sig];
1389
+ /* c8 ignore start */
1390
+ if (!listener) throw new Error("Listener not defined for signal: " + sig);
1391
+ /* c8 ignore stop */
1392
+ try {
1393
+ this.#process.removeListener(sig, listener);
1394
+ } catch (_$1) {}
1395
+ /* c8 ignore stop */
1396
+ });
1397
+ this.#process.emit = this.#originalProcessEmit;
1398
+ this.#process.reallyExit = this.#originalProcessReallyExit;
1399
+ this.#emitter.count -= 1;
1400
+ }
1401
+ #processReallyExit(code) {
1402
+ /* c8 ignore start */
1403
+ if (!processOk(this.#process)) return 0;
1404
+ this.#process.exitCode = code || 0;
1405
+ /* c8 ignore stop */
1406
+ this.#emitter.emit("exit", this.#process.exitCode, null);
1407
+ return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode);
1408
+ }
1409
+ #processEmit(ev, ...args) {
1410
+ const og = this.#originalProcessEmit;
1411
+ if (ev === "exit" && processOk(this.#process)) {
1412
+ if (typeof args[0] === "number") this.#process.exitCode = args[0];
1413
+ /* c8 ignore start */
1414
+ const ret = og.call(this.#process, ev, ...args);
1415
+ /* c8 ignore start */
1416
+ this.#emitter.emit("exit", this.#process.exitCode, null);
1417
+ /* c8 ignore stop */
1418
+ return ret;
1419
+ } else return og.call(this.#process, ev, ...args);
1420
+ }
1421
+ };
1422
+ const process$2 = globalThis.process;
1423
+ const { onExit, load, unload } = signalExitWrap(processOk(process$2) ? new SignalExit(process$2) : new SignalExitFallback());
1424
+
1425
+ //#endregion
1426
+ //#region ../../node_modules/.pnpm/@oxc-project+runtime@0.78.0/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js
1427
+ var require_usingCtx = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.78.0/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js": ((exports, module) => {
1428
+ function _usingCtx() {
1429
+ var r$1 = "function" == typeof SuppressedError ? SuppressedError : function(r$2, e$1) {
1430
+ var n$2 = Error();
1431
+ return n$2.name = "SuppressedError", n$2.error = r$2, n$2.suppressed = e$1, n$2;
1432
+ }, e = {}, n$1 = [];
1433
+ function using(r$2, e$1) {
1434
+ if (null != e$1) {
1435
+ if (Object(e$1) !== e$1) throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
1436
+ if (r$2) var o$1 = e$1[Symbol.asyncDispose || Symbol["for"]("Symbol.asyncDispose")];
1437
+ if (void 0 === o$1 && (o$1 = e$1[Symbol.dispose || Symbol["for"]("Symbol.dispose")], r$2)) var t$1 = o$1;
1438
+ if ("function" != typeof o$1) throw new TypeError("Object is not disposable.");
1439
+ t$1 && (o$1 = function o$2() {
1440
+ try {
1441
+ t$1.call(e$1);
1442
+ } catch (r$3) {
1443
+ return Promise.reject(r$3);
1444
+ }
1445
+ }), n$1.push({
1446
+ v: e$1,
1447
+ d: o$1,
1448
+ a: r$2
1449
+ });
1450
+ } else r$2 && n$1.push({
1451
+ d: e$1,
1452
+ a: r$2
1453
+ });
1454
+ return e$1;
1455
+ }
1456
+ return {
1457
+ e,
1458
+ u: using.bind(null, !1),
1459
+ a: using.bind(null, !0),
1460
+ d: function d() {
1461
+ var o$1, t$1 = this.e, s$1 = 0;
1462
+ function next() {
1463
+ for (; o$1 = n$1.pop();) try {
1464
+ if (!o$1.a && 1 === s$1) return s$1 = 0, n$1.push(o$1), Promise.resolve().then(next);
1465
+ if (o$1.d) {
1466
+ var r$2 = o$1.d.call(o$1.v);
1467
+ if (o$1.a) return s$1 |= 2, Promise.resolve(r$2).then(next, err);
1468
+ } else s$1 |= 1;
1469
+ } catch (r$3) {
1470
+ return err(r$3);
1471
+ }
1472
+ if (1 === s$1) return t$1 !== e ? Promise.reject(t$1) : Promise.resolve();
1473
+ if (t$1 !== e) throw t$1;
1474
+ }
1475
+ function err(n$2) {
1476
+ return t$1 = t$1 !== e ? new r$1(n$2, t$1) : n$2, next();
1477
+ }
1478
+ return next();
1479
+ }
1480
+ };
1481
+ }
1482
+ module.exports = _usingCtx, module.exports.__esModule = true, module.exports["default"] = module.exports;
1483
+ }) });
1484
+
1485
+ //#endregion
1486
+ //#region src/cli/commands/bundle.ts
1487
+ var import_usingCtx = /* @__PURE__ */ __toESM(require_usingCtx(), 1);
1488
+ async function bundleWithConfig(configPath, cliOptions) {
1489
+ if (cliOptions.watch) {
1490
+ process.env.ROLLUP_WATCH = "true";
1491
+ process.env.ROLLDOWN_WATCH = "true";
1492
+ }
1493
+ const config = await loadConfig(configPath);
1494
+ if (!config) {
1495
+ logger.error(`No configuration found at ${config}`);
1280
1496
  process.exit(1);
1281
1497
  }
1282
1498
  if (cliOptions.watch) await watchInner(config, cliOptions);
1283
1499
  else await bundleInner(config, cliOptions);
1284
1500
  }
1285
1501
  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
1502
  try {
1503
+ var _usingCtx$1 = (0, import_usingCtx.default)();
1504
+ if (cliOptions.output.dir || cliOptions.output.file) {
1505
+ const operation = cliOptions.watch ? watchInner : bundleInner;
1506
+ await operation({}, cliOptions);
1507
+ return;
1508
+ }
1509
+ if (cliOptions.watch) {
1510
+ logger.error("You must specify `output.dir` to use watch mode");
1511
+ process.exit(1);
1512
+ }
1513
+ const build = _usingCtx$1.a(await rolldown(cliOptions.input));
1297
1514
  const { output: outputs } = await build.generate(cliOptions.output);
1298
1515
  if (outputs.length === 0) {
1299
1516
  logger.error("No output generated");
@@ -1303,8 +1520,10 @@ async function bundleWithCliOptions(cliOptions) {
1303
1520
  if (outputs.length > 1) logger.log(`\n${colors.cyan(colors.bold(`|→ ${file.fileName}:`))}\n`);
1304
1521
  console.log(file.type === "asset" ? file.source : file.code);
1305
1522
  }
1523
+ } catch (_$1) {
1524
+ _usingCtx$1.e = _$1;
1306
1525
  } finally {
1307
- await build.close();
1526
+ await _usingCtx$1.d();
1308
1527
  }
1309
1528
  }
1310
1529
  async function watchInner(config, cliOptions) {
@@ -1320,7 +1539,7 @@ async function watchInner(config, cliOptions) {
1320
1539
  })
1321
1540
  };
1322
1541
  });
1323
- const watcher = await watch(normalizedConfig);
1542
+ const watcher = watch(normalizedConfig);
1324
1543
  onExit((code) => {
1325
1544
  Promise.resolve(watcher.close()).finally(() => {
1326
1545
  process.exit(typeof code === "number" ? code : 0);
@@ -1331,16 +1550,18 @@ async function watchInner(config, cliOptions) {
1331
1550
  watcher.on("change", (id, event) => {
1332
1551
  if (event.event === "update") changedFile.push(id);
1333
1552
  });
1334
- watcher.on("event", (event) => {
1553
+ watcher.on("event", async (event) => {
1335
1554
  switch (event.code) {
1336
1555
  case "BUNDLE_START":
1337
1556
  if (changedFile.length > 0) logger.log(`Found ${colors.bold(changedFile.map(relativeId).join(", "))} changed, rebuilding...`);
1338
1557
  changedFile.length = 0;
1339
1558
  break;
1340
1559
  case "BUNDLE_END":
1341
- logger.success(`Rebuilt ${colors.bold(relativeId(event.output[0]))} in ${colors.bold(ms(event.duration))}.`);
1560
+ await event.result.close();
1561
+ logger.success(`Rebuilt ${colors.bold(relativeId(event.output[0]))} in ${colors.green(ms(event.duration))}.`);
1342
1562
  break;
1343
1563
  case "ERROR":
1564
+ await event.result.close();
1344
1565
  logger.error(event.error);
1345
1566
  break;
1346
1567
  default: break;
@@ -1371,7 +1592,7 @@ async function bundleInner(config, cliOptions) {
1371
1592
  logger.log(``);
1372
1593
  const endTime = performance.now();
1373
1594
  const duration = endTime - startTime;
1374
- logger.success(`Finished in ${colors.bold(ms(duration))}`);
1595
+ logger.success(`rolldown v${version} Finished in ${colors.green(ms(duration))}`);
1375
1596
  }
1376
1597
  function printBundleOutputPretty(output) {
1377
1598
  const outputEntries = collectOutputEntries(output.output);
@@ -1382,7 +1603,7 @@ function collectOutputEntries(output) {
1382
1603
  return output.map((chunk) => ({
1383
1604
  type: chunk.type,
1384
1605
  fileName: chunk.fileName,
1385
- size: chunk.type === "chunk" ? chunk.code.length : chunk.source.length
1606
+ size: chunk.type === "chunk" ? Buffer.byteLength(chunk.code) : Buffer.byteLength(chunk.source)
1386
1607
  }));
1387
1608
  }
1388
1609
  function collectOutputLayoutAdjustmentSizes(entries) {
@@ -1438,224 +1659,6 @@ function relativeId(id) {
1438
1659
  return path.relative(path.resolve(), id);
1439
1660
  }
1440
1661
 
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(`Invalid value for option ${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
1662
  //#endregion
1660
1663
  //#region src/cli/commands/help.ts
1661
1664
  const introduction = `${colors.gray(`${description} (rolldown v${version})`)}
@@ -1694,11 +1697,11 @@ function showHelp() {
1694
1697
  logger.log("");
1695
1698
  logger.log(`${colors.bold(colors.underline("OPTIONS"))}`);
1696
1699
  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);
1700
+ logger.log(Object.entries(options).sort(([a$1], [b$1]) => {
1701
+ if (options[a$1].short && !options[b$1].short) return -1;
1702
+ if (!options[a$1].short && options[b$1].short) return 1;
1703
+ if (options[a$1].short && options[b$1].short) return options[a$1].short.localeCompare(options[b$1].short);
1704
+ return a$1.localeCompare(b$1);
1702
1705
  }).map(([option, { type, short, hint, description: description$1 }]) => {
1703
1706
  let optionStr = ` --${option} `;
1704
1707
  option = camelCaseToKebabCase(option);