rolldown 1.0.0-beta.4-commit.308f68b → 1.0.0-beta.41

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 +146 -0
  7. package/dist/experimental-index.mjs +215 -0
  8. package/dist/experimental-runtime-types.d.ts +77 -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-DOpOtI1J.d.mts +1404 -0
  20. package/dist/shared/define-config-BZ_n3PjJ.d.mts +1475 -0
  21. package/dist/shared/load-config-DkgIoWHl.mjs +117 -0
  22. package/dist/{esm/cli.mjs → shared/logger-ClMekpHZ.mjs} +107 -868
  23. package/dist/shared/misc-CQeo-AFx.mjs +22 -0
  24. package/dist/shared/parse-ast-index-D2PcAmXE.mjs +10975 -0
  25. package/dist/shared/{prompt-CxK9euq3.mjs → prompt-R6XhwkxA.mjs} +253 -255
  26. package/dist/shared/src-DkvlJJsC.mjs +4277 -0
  27. package/package.json +63 -77
  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-DB6mZNTU.mjs +0 -2875
  43. package/dist/shared/src-y8hk77fd.cjs +0 -3056
  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
package/bin/cli.mjs ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import '../dist/cli.mjs';
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ export { };
package/dist/cli.mjs ADDED
@@ -0,0 +1,579 @@
1
+ import "./shared/parse-ast-index-D2PcAmXE.mjs";
2
+ import { description, getCliSchemaInfo, getInputCliKeys, getOutputCliKeys, onExit, rolldown, validateCliOptions, version, watch } from "./shared/src-DkvlJJsC.mjs";
3
+ import { arraify } from "./shared/misc-CQeo-AFx.mjs";
4
+ import { logger } from "./shared/logger-ClMekpHZ.mjs";
5
+ import { loadConfig } from "./shared/load-config-DkgIoWHl.mjs";
6
+ import path from "node:path";
7
+ import colors from "ansis";
8
+ import { parseArgs } from "node:util";
9
+ import process$1 from "node:process";
10
+ import { performance } from "node:perf_hooks";
11
+
12
+ //#region src/cli/arguments/alias.ts
13
+ const alias = {
14
+ config: {
15
+ abbreviation: "c",
16
+ hint: "filename"
17
+ },
18
+ help: { abbreviation: "h" },
19
+ version: { abbreviation: "v" },
20
+ watch: { abbreviation: "w" },
21
+ dir: { abbreviation: "d" },
22
+ file: { abbreviation: "o" },
23
+ external: { abbreviation: "e" },
24
+ format: { abbreviation: "f" },
25
+ name: { abbreviation: "n" },
26
+ globals: { abbreviation: "g" },
27
+ sourcemap: {
28
+ abbreviation: "s",
29
+ default: true
30
+ },
31
+ minify: { abbreviation: "m" },
32
+ platform: { abbreviation: "p" },
33
+ assetFileNames: { hint: "name" },
34
+ chunkFileNames: { hint: "name" },
35
+ entryFileNames: { hint: "name" },
36
+ externalLiveBindings: {
37
+ default: true,
38
+ reverse: true
39
+ },
40
+ treeshake: {
41
+ default: true,
42
+ reverse: true
43
+ },
44
+ preserveEntrySignatures: {
45
+ default: "strict",
46
+ reverse: true
47
+ },
48
+ moduleTypes: { hint: "types" }
49
+ };
50
+
51
+ //#endregion
52
+ //#region src/cli/arguments/utils.ts
53
+ function setNestedProperty(obj, path$1, value) {
54
+ const keys = path$1.split(".");
55
+ let current = obj;
56
+ for (let i = 0; i < keys.length - 1; i++) {
57
+ if (!current[keys[i]]) current[keys[i]] = {};
58
+ current = current[keys[i]];
59
+ }
60
+ const finalKey = keys[keys.length - 1];
61
+ Object.defineProperty(current, finalKey, {
62
+ value,
63
+ writable: true,
64
+ enumerable: true,
65
+ configurable: true
66
+ });
67
+ }
68
+ function camelCaseToKebabCase(str) {
69
+ return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
70
+ }
71
+ function kebabCaseToCamelCase(str) {
72
+ return str.replace(/-./g, (match) => match[1].toUpperCase());
73
+ }
74
+
75
+ //#endregion
76
+ //#region src/cli/arguments/normalize.ts
77
+ function normalizeCliOptions(cliOptions, positionals) {
78
+ const [data, errors] = validateCliOptions(cliOptions);
79
+ if (errors?.length) {
80
+ errors.forEach((error) => {
81
+ logger.error(`${error}. You can use \`rolldown -h\` to see the help.`);
82
+ });
83
+ process.exit(1);
84
+ }
85
+ const options$1 = data ?? {};
86
+ const result = {
87
+ input: {},
88
+ output: {},
89
+ help: options$1.help ?? false,
90
+ version: options$1.version ?? false,
91
+ watch: options$1.watch ?? false
92
+ };
93
+ if (typeof options$1.config === "string") result.config = options$1.config;
94
+ const keysOfInput = getInputCliKeys();
95
+ const keysOfOutput = getOutputCliKeys();
96
+ const reservedKeys = [
97
+ "help",
98
+ "version",
99
+ "config",
100
+ "watch"
101
+ ];
102
+ for (let [key, value] of Object.entries(options$1)) {
103
+ const [primary] = key.split(".");
104
+ if (keysOfInput.includes(primary)) setNestedProperty(result.input, key, value);
105
+ else if (keysOfOutput.includes(primary)) setNestedProperty(result.output, key, value);
106
+ else if (!reservedKeys.includes(key)) {
107
+ logger.error(`Unknown option: ${key}`);
108
+ process.exit(1);
109
+ }
110
+ }
111
+ if (!result.config && positionals.length > 0) if (Array.isArray(result.input.input)) result.input.input.push(...positionals);
112
+ else result.input.input = positionals;
113
+ return result;
114
+ }
115
+
116
+ //#endregion
117
+ //#region src/cli/arguments/index.ts
118
+ const schemaInfo = getCliSchemaInfo();
119
+ const options = Object.fromEntries(Object.entries(schemaInfo).filter(([_key, info]) => info.type !== "never").map(([key, info]) => {
120
+ const config = Object.getOwnPropertyDescriptor(alias, key)?.value;
121
+ const result = {
122
+ type: info.type === "boolean" ? "boolean" : "string",
123
+ description: info?.description ?? config?.description ?? "",
124
+ hint: config?.hint
125
+ };
126
+ if (config && config?.abbreviation) result.short = config?.abbreviation;
127
+ if (config && config.reverse) {
128
+ if (result.description.startsWith("enable")) result.description = result.description.replace("enable", "disable");
129
+ else if (!result.description.startsWith("Avoid")) result.description = `disable ${result.description}`;
130
+ }
131
+ key = camelCaseToKebabCase(key);
132
+ return [config?.reverse ? `no-${key}` : key, result];
133
+ }));
134
+ function parseCliArguments() {
135
+ const { values, tokens, positionals } = parseArgs({
136
+ options,
137
+ tokens: true,
138
+ allowPositionals: true,
139
+ strict: false
140
+ });
141
+ let invalid_options = tokens.filter((token) => token.kind === "option").map((option) => {
142
+ let negative = false;
143
+ if (option.name.startsWith("no-")) {
144
+ const name = kebabCaseToCamelCase(option.name.substring(3));
145
+ if (name in schemaInfo) {
146
+ delete values[option.name];
147
+ option.name = name;
148
+ negative = true;
149
+ }
150
+ }
151
+ delete values[option.name];
152
+ option.name = kebabCaseToCamelCase(option.name);
153
+ let originalInfo = schemaInfo[option.name];
154
+ if (!originalInfo) return {
155
+ name: option.name,
156
+ value: option.value
157
+ };
158
+ let type = originalInfo.type;
159
+ if (type === "string" && typeof option.value !== "string") {
160
+ let opt = option;
161
+ let defaultValue = Object.getOwnPropertyDescriptor(alias, opt.name)?.value;
162
+ Object.defineProperty(values, opt.name, {
163
+ value: defaultValue.default ?? "",
164
+ enumerable: true,
165
+ configurable: true,
166
+ writable: true
167
+ });
168
+ } else if (type === "object" && typeof option.value === "string") {
169
+ const [key, value] = option.value.split(",").map((x) => x.split("="))[0];
170
+ if (!values[option.name]) Object.defineProperty(values, option.name, {
171
+ value: {},
172
+ enumerable: true,
173
+ configurable: true,
174
+ writable: true
175
+ });
176
+ if (key && value) Object.defineProperty(values[option.name], key, {
177
+ value,
178
+ enumerable: true,
179
+ configurable: true,
180
+ writable: true
181
+ });
182
+ } else if (type === "array" && typeof option.value === "string") {
183
+ if (!values[option.name]) Object.defineProperty(values, option.name, {
184
+ value: [],
185
+ enumerable: true,
186
+ configurable: true,
187
+ writable: true
188
+ });
189
+ values[option.name].push(option.value);
190
+ } else if (type === "boolean") Object.defineProperty(values, option.name, {
191
+ value: !negative,
192
+ enumerable: true,
193
+ configurable: true,
194
+ writable: true
195
+ });
196
+ else if (type === "union") {
197
+ let defaultValue = Object.getOwnPropertyDescriptor(alias, option.name)?.value;
198
+ Object.defineProperty(values, option.name, {
199
+ value: option.value ?? defaultValue?.default ?? "",
200
+ enumerable: true,
201
+ configurable: true,
202
+ writable: true
203
+ });
204
+ } else Object.defineProperty(values, option.name, {
205
+ value: option.value ?? "",
206
+ enumerable: true,
207
+ configurable: true,
208
+ writable: true
209
+ });
210
+ }).filter((item) => {
211
+ return item !== void 0;
212
+ });
213
+ invalid_options.sort((a, b) => {
214
+ return a.name.localeCompare(b.name);
215
+ });
216
+ if (invalid_options.length !== 0) {
217
+ let single = invalid_options.length === 1;
218
+ logger.warn(`Option \`${invalid_options.map((item) => item.name).join(",")}\` ${single ? "is" : "are"} unrecognized. We will ignore ${single ? "this" : "those"} option${single ? "" : "s"}.`);
219
+ }
220
+ let rawArgs = {
221
+ ...values,
222
+ ...invalid_options.reduce((acc, cur) => {
223
+ acc[cur.name] = cur.value;
224
+ return acc;
225
+ }, Object.create(null))
226
+ };
227
+ return {
228
+ ...normalizeCliOptions(values, positionals),
229
+ rawArgs
230
+ };
231
+ }
232
+
233
+ //#endregion
234
+ //#region src/utils/clear-screen.ts
235
+ const CLEAR_SCREEN = "\x1Bc";
236
+ function getClearScreenFunction(options$1) {
237
+ const isTTY = process.stdout.isTTY;
238
+ const isAnyOptionNotAllowingClearScreen = arraify(options$1).some(({ watch: watch$1 }) => watch$1 === false || watch$1?.clearScreen === false);
239
+ if (isTTY && !isAnyOptionNotAllowingClearScreen) return () => {
240
+ process.stdout.write(CLEAR_SCREEN);
241
+ };
242
+ }
243
+
244
+ //#endregion
245
+ //#region \0@oxc-project+runtime@0.93.0/helpers/usingCtx.js
246
+ function _usingCtx() {
247
+ var r = "function" == typeof SuppressedError ? SuppressedError : function(r$1, e$1) {
248
+ var n$1 = Error();
249
+ return n$1.name = "SuppressedError", n$1.error = r$1, n$1.suppressed = e$1, n$1;
250
+ }, e = {}, n = [];
251
+ function using(r$1, e$1) {
252
+ if (null != e$1) {
253
+ if (Object(e$1) !== e$1) throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
254
+ if (r$1) var o = e$1[Symbol.asyncDispose || Symbol["for"]("Symbol.asyncDispose")];
255
+ if (void 0 === o && (o = e$1[Symbol.dispose || Symbol["for"]("Symbol.dispose")], r$1)) var t = o;
256
+ if ("function" != typeof o) throw new TypeError("Object is not disposable.");
257
+ t && (o = function o$1() {
258
+ try {
259
+ t.call(e$1);
260
+ } catch (r$2) {
261
+ return Promise.reject(r$2);
262
+ }
263
+ }), n.push({
264
+ v: e$1,
265
+ d: o,
266
+ a: r$1
267
+ });
268
+ } else r$1 && n.push({
269
+ d: e$1,
270
+ a: r$1
271
+ });
272
+ return e$1;
273
+ }
274
+ return {
275
+ e,
276
+ u: using.bind(null, !1),
277
+ a: using.bind(null, !0),
278
+ d: function d() {
279
+ var o, t = this.e, s = 0;
280
+ function next() {
281
+ for (; o = n.pop();) try {
282
+ if (!o.a && 1 === s) return s = 0, n.push(o), Promise.resolve().then(next);
283
+ if (o.d) {
284
+ var r$1 = o.d.call(o.v);
285
+ if (o.a) return s |= 2, Promise.resolve(r$1).then(next, err);
286
+ } else s |= 1;
287
+ } catch (r$2) {
288
+ return err(r$2);
289
+ }
290
+ if (1 === s) return t !== e ? Promise.reject(t) : Promise.resolve();
291
+ if (t !== e) throw t;
292
+ }
293
+ function err(n$1) {
294
+ return t = t !== e ? new r(n$1, t) : n$1, next();
295
+ }
296
+ return next();
297
+ }
298
+ };
299
+ }
300
+
301
+ //#endregion
302
+ //#region src/cli/commands/bundle.ts
303
+ async function bundleWithConfig(configPath, cliOptions, rawArgs = {}) {
304
+ if (cliOptions.watch) {
305
+ process.env.ROLLUP_WATCH = "true";
306
+ process.env.ROLLDOWN_WATCH = "true";
307
+ }
308
+ const config = await loadConfig(configPath);
309
+ if (!config) {
310
+ logger.error(`No configuration found at ${config}`);
311
+ process.exit(1);
312
+ }
313
+ const resolvedConfig = typeof config === "function" ? await config(rawArgs) : config;
314
+ if (cliOptions.watch) await watchInner(resolvedConfig, cliOptions);
315
+ else await bundleInner(resolvedConfig, cliOptions);
316
+ }
317
+ async function bundleWithCliOptions(cliOptions) {
318
+ try {
319
+ var _usingCtx$1 = _usingCtx();
320
+ if (cliOptions.output.dir || cliOptions.output.file) {
321
+ await (cliOptions.watch ? watchInner : bundleInner)({}, cliOptions);
322
+ return;
323
+ }
324
+ if (cliOptions.watch) {
325
+ logger.error("You must specify `output.dir` to use watch mode");
326
+ process.exit(1);
327
+ }
328
+ const { output: outputs } = await _usingCtx$1.a(await rolldown(cliOptions.input)).generate(cliOptions.output);
329
+ if (outputs.length === 0) {
330
+ logger.error("No output generated");
331
+ process.exit(1);
332
+ }
333
+ for (const file of outputs) {
334
+ if (outputs.length > 1) logger.log(`\n${colors.cyan(colors.bold(`|→ ${file.fileName}:`))}\n`);
335
+ console.log(file.type === "asset" ? file.source : file.code);
336
+ }
337
+ } catch (_) {
338
+ _usingCtx$1.e = _;
339
+ } finally {
340
+ await _usingCtx$1.d();
341
+ }
342
+ }
343
+ async function watchInner(config, cliOptions) {
344
+ let normalizedConfig = arraify(config).map((option) => {
345
+ return {
346
+ ...option,
347
+ ...cliOptions.input,
348
+ output: arraify(option.output || {}).map((output) => {
349
+ return {
350
+ ...output,
351
+ ...cliOptions.output
352
+ };
353
+ })
354
+ };
355
+ });
356
+ const watcher = watch(normalizedConfig);
357
+ onExit((code) => {
358
+ Promise.resolve(watcher.close()).finally(() => {
359
+ process.exit(typeof code === "number" ? code : 0);
360
+ });
361
+ return true;
362
+ });
363
+ const changedFile = [];
364
+ watcher.on("change", (id, event) => {
365
+ if (event.event === "update") changedFile.push(id);
366
+ });
367
+ const clearScreen = getClearScreenFunction(normalizedConfig);
368
+ watcher.on("event", async (event) => {
369
+ switch (event.code) {
370
+ case "START":
371
+ clearScreen?.();
372
+ break;
373
+ case "BUNDLE_START":
374
+ if (changedFile.length > 0) logger.log(`Found ${colors.bold(changedFile.map(relativeId).join(", "))} changed, rebuilding...`);
375
+ changedFile.length = 0;
376
+ break;
377
+ case "BUNDLE_END":
378
+ await event.result.close();
379
+ logger.success(`Rebuilt ${colors.bold(relativeId(event.output[0]))} in ${colors.green(ms(event.duration))}.`);
380
+ break;
381
+ case "ERROR":
382
+ await event.result.close();
383
+ logger.error(event.error);
384
+ break;
385
+ default: break;
386
+ }
387
+ });
388
+ logger.log(`Waiting for changes...`);
389
+ }
390
+ async function bundleInner(config, cliOptions) {
391
+ const startTime = performance.now();
392
+ const result = [];
393
+ const configList = arraify(config);
394
+ for (const config$1 of configList) {
395
+ const outputList = arraify(config$1.output || {});
396
+ const build = await rolldown({
397
+ ...config$1,
398
+ ...cliOptions.input
399
+ });
400
+ for (const output of outputList) try {
401
+ result.push(await build.write({
402
+ ...output,
403
+ ...cliOptions.output
404
+ }));
405
+ } finally {
406
+ await build.close();
407
+ }
408
+ }
409
+ result.forEach(printBundleOutputPretty);
410
+ logger.log(``);
411
+ const duration = performance.now() - startTime;
412
+ logger.success(`rolldown v${version} Finished in ${colors.green(ms(duration))}`);
413
+ }
414
+ function printBundleOutputPretty(output) {
415
+ const outputEntries = collectOutputEntries(output.output);
416
+ const outputLayoutSizes = collectOutputLayoutAdjustmentSizes(outputEntries);
417
+ printOutputEntries(outputEntries, outputLayoutSizes, "<DIR>");
418
+ }
419
+ function collectOutputEntries(output) {
420
+ return output.map((chunk) => ({
421
+ type: chunk.type,
422
+ fileName: chunk.fileName,
423
+ size: chunk.type === "chunk" ? Buffer.byteLength(chunk.code) : Buffer.byteLength(chunk.source)
424
+ }));
425
+ }
426
+ function collectOutputLayoutAdjustmentSizes(entries) {
427
+ let longest = 0;
428
+ let biggestSize = 0;
429
+ for (const entry of entries) {
430
+ if (entry.fileName.length > longest) longest = entry.fileName.length;
431
+ if (entry.size > biggestSize) biggestSize = entry.size;
432
+ }
433
+ const sizePad = displaySize(biggestSize).length;
434
+ return {
435
+ longest,
436
+ biggestSize,
437
+ sizePad
438
+ };
439
+ }
440
+ const numberFormatter = new Intl.NumberFormat("en", {
441
+ maximumFractionDigits: 2,
442
+ minimumFractionDigits: 2
443
+ });
444
+ function displaySize(bytes) {
445
+ return `${numberFormatter.format(bytes / 1e3)} kB`;
446
+ }
447
+ const CHUNK_GROUPS = [{
448
+ type: "asset",
449
+ color: "green"
450
+ }, {
451
+ type: "chunk",
452
+ color: "cyan"
453
+ }];
454
+ function printOutputEntries(entries, sizeAdjustment, distPath) {
455
+ for (const group of CHUNK_GROUPS) {
456
+ const filtered = entries.filter((e) => e.type === group.type);
457
+ if (!filtered.length) continue;
458
+ for (const entry of filtered.sort((a, z) => a.size - z.size)) {
459
+ let log = colors.dim(withTrailingSlash(distPath));
460
+ log += colors[group.color](entry.fileName.padEnd(sizeAdjustment.longest + 2));
461
+ log += colors.dim(entry.type);
462
+ log += colors.dim(` │ size: ${displaySize(entry.size).padStart(sizeAdjustment.sizePad)}`);
463
+ logger.log(log);
464
+ }
465
+ }
466
+ }
467
+ function withTrailingSlash(path$1) {
468
+ if (path$1[path$1.length - 1] !== "/") return `${path$1}/`;
469
+ return path$1;
470
+ }
471
+ function ms(duration) {
472
+ return duration < 1e3 ? `${duration.toFixed(2)} ms` : `${(duration / 1e3).toFixed(2)} s`;
473
+ }
474
+ function relativeId(id) {
475
+ if (!path.isAbsolute(id)) return id;
476
+ return path.relative(path.resolve(), id);
477
+ }
478
+
479
+ //#endregion
480
+ //#region src/cli/commands/help.ts
481
+ const introduction = `${colors.gray(`${description} (rolldown v${version})`)}
482
+
483
+ ${colors.bold(colors.underline("USAGE"))} ${colors.cyan("rolldown -c <config>")} or ${colors.cyan("rolldown <input> <options>")}`;
484
+ const examples = [
485
+ {
486
+ title: "Bundle with a config file `rolldown.config.mjs`",
487
+ command: "rolldown -c rolldown.config.mjs"
488
+ },
489
+ {
490
+ title: "Bundle the `src/main.ts` to `dist` with `cjs` format",
491
+ command: "rolldown src/main.ts -d dist -f cjs"
492
+ },
493
+ {
494
+ title: "Bundle the `src/main.ts` and handle the `.png` assets to Data URL",
495
+ command: "rolldown src/main.ts -d dist --moduleTypes .png=dataurl"
496
+ },
497
+ {
498
+ title: "Bundle the `src/main.tsx` and minify the output with sourcemap",
499
+ command: "rolldown src/main.tsx -d dist -m -s"
500
+ },
501
+ {
502
+ title: "Create self-executing IIFE using external jQuery as `$` and `_`",
503
+ command: "rolldown src/main.ts -d dist -n bundle -f iife -e jQuery,window._ -g jQuery=$"
504
+ }
505
+ ];
506
+ const notes = [
507
+ "Due to the API limitation, you need to pass `-s` for `.map` sourcemap file as the last argument.",
508
+ "If you are using the configuration, please pass the `-c` as the last argument if you ignore the default configuration file.",
509
+ "CLI options will override the configuration file.",
510
+ "For more information, please visit https://rolldown.rs/."
511
+ ];
512
+ function showHelp() {
513
+ logger.log(introduction);
514
+ logger.log("");
515
+ logger.log(`${colors.bold(colors.underline("OPTIONS"))}`);
516
+ logger.log("");
517
+ logger.log(Object.entries(options).sort(([a], [b]) => {
518
+ if (options[a].short && !options[b].short) return -1;
519
+ if (!options[a].short && options[b].short) return 1;
520
+ if (options[a].short && options[b].short) return options[a].short.localeCompare(options[b].short);
521
+ return a.localeCompare(b);
522
+ }).map(([option, { type, short, hint, description: description$1 }]) => {
523
+ let optionStr = ` --${option} `;
524
+ option = camelCaseToKebabCase(option);
525
+ if (short) optionStr += `-${short}, `;
526
+ if (type === "string") optionStr += `<${hint ?? option}>`;
527
+ if (description$1 && description$1.length > 0) description$1 = description$1[0].toUpperCase() + description$1.slice(1);
528
+ return colors.cyan(optionStr.padEnd(30)) + description$1 + (description$1 && description$1?.endsWith(".") ? "" : ".");
529
+ }).join("\n"));
530
+ logger.log("");
531
+ logger.log(`${colors.bold(colors.underline("EXAMPLES"))}`);
532
+ logger.log("");
533
+ examples.forEach(({ title, command }, ord) => {
534
+ logger.log(` ${ord + 1}. ${title}:`);
535
+ logger.log(` ${colors.cyan(command)}`);
536
+ logger.log("");
537
+ });
538
+ logger.log(`${colors.bold(colors.underline("NOTES"))}`);
539
+ logger.log("");
540
+ notes.forEach((note) => {
541
+ logger.log(` * ${colors.gray(note)}`);
542
+ });
543
+ }
544
+
545
+ //#endregion
546
+ //#region src/cli/version-check.ts
547
+ function checkNodeVersion(nodeVersion) {
548
+ const currentVersion = nodeVersion.split(".");
549
+ const major = parseInt(currentVersion[0], 10);
550
+ const minor = parseInt(currentVersion[1], 10);
551
+ return major === 20 && minor >= 19 || major === 22 && minor >= 12 || major > 22;
552
+ }
553
+
554
+ //#endregion
555
+ //#region src/cli/index.ts
556
+ if (!checkNodeVersion(process$1.versions.node)) logger.warn(`You are using Node.js ${process$1.versions.node}. Rolldown requires Node.js version 20.19+ or 22.12+. Please upgrade your Node.js version.`);
557
+ async function main() {
558
+ const { rawArgs,...cliOptions } = parseCliArguments();
559
+ if (cliOptions.config || cliOptions.config === "") {
560
+ await bundleWithConfig(cliOptions.config, cliOptions, rawArgs);
561
+ return;
562
+ }
563
+ if ("input" in cliOptions.input) {
564
+ await bundleWithCliOptions(cliOptions);
565
+ return;
566
+ }
567
+ if (cliOptions.version) {
568
+ logger.log(`rolldown v${version}`);
569
+ return;
570
+ }
571
+ showHelp();
572
+ }
573
+ main().catch((err) => {
574
+ logger.error(err);
575
+ process$1.exit(1);
576
+ });
577
+
578
+ //#endregion
579
+ export { };
@@ -0,0 +1,10 @@
1
+ import "./shared/binding-DOpOtI1J.mjs";
2
+ import { ConfigExport, defineConfig } from "./shared/define-config-BZ_n3PjJ.mjs";
3
+
4
+ //#region src/utils/load-config.d.ts
5
+ declare function loadConfig(configPath: string): Promise<ConfigExport>;
6
+ //#endregion
7
+ //#region src/config.d.ts
8
+ declare const VERSION: string;
9
+ //#endregion
10
+ export { VERSION, defineConfig, loadConfig };
@@ -0,0 +1,10 @@
1
+ import "./shared/parse-ast-index-D2PcAmXE.mjs";
2
+ import { defineConfig, version } from "./shared/src-DkvlJJsC.mjs";
3
+ import "./shared/misc-CQeo-AFx.mjs";
4
+ import { loadConfig } from "./shared/load-config-DkgIoWHl.mjs";
5
+
6
+ //#region src/config.ts
7
+ const VERSION = version;
8
+
9
+ //#endregion
10
+ export { VERSION, defineConfig, loadConfig };