@rollipop/rolldown 1.0.0-rc.2 → 1.0.0-rc.4

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 (48) hide show
  1. package/bin/cli.mjs +0 -1
  2. package/dist/cli.mjs +28 -1008
  3. package/dist/config.d.mts +10 -5
  4. package/dist/config.mjs +10 -14
  5. package/dist/experimental-index.d.mts +86 -14
  6. package/dist/experimental-index.mjs +77 -22
  7. package/dist/experimental-runtime-types.d.ts +0 -5
  8. package/dist/filter-index.d.mts +2 -2
  9. package/dist/filter-index.mjs +25 -8
  10. package/dist/get-log-filter.d.mts +3 -7
  11. package/dist/get-log-filter.mjs +23 -3
  12. package/dist/index.d.mts +4 -4
  13. package/dist/index.mjs +10 -12
  14. package/dist/parallel-plugin-worker.mjs +7 -8
  15. package/dist/parallel-plugin.d.mts +2 -2
  16. package/dist/parallel-plugin.mjs +1 -2
  17. package/dist/parse-ast-index.d.mts +26 -2
  18. package/dist/parse-ast-index.mjs +61 -4
  19. package/dist/plugins-index.d.mts +8 -5
  20. package/dist/plugins-index.mjs +9 -8
  21. package/dist/shared/{binding-Bo6UcGYl.d.mts → binding-BohGL_65.d.mts} +310 -120
  22. package/dist/shared/{binding-9QXxzPo6.mjs → binding-BuW0Fhs2.mjs} +39 -42
  23. package/dist/shared/{bindingify-input-options-C--dZCPv.mjs → bindingify-input-options-o_7NioSs.mjs} +77 -161
  24. package/dist/shared/{constructors-B64fS2o1.d.mts → constructors-Dg8A45sy.d.mts} +9 -4
  25. package/dist/shared/{constructors-DsYXT8FB.mjs → constructors-FqGyV5fj.mjs} +8 -7
  26. package/dist/shared/{define-config-DT_Hpxdr.d.mts → define-config-BvszQ-i2.d.mts} +212 -71
  27. package/dist/shared/{define-config-BVG4QvnP.mjs → define-config-DJOr6Iwt.mjs} +1 -2
  28. package/dist/shared/error-BjNWBTlf.mjs +85 -0
  29. package/dist/shared/get-log-filter-semyr3Lj.d.mts +35 -0
  30. package/dist/shared/{load-config-TBowPn4n.mjs → load-config-2dmAH96P.mjs} +11 -5
  31. package/dist/shared/{logs-NH298mHo.mjs → logs-D80CXhvg.mjs} +6 -9
  32. package/dist/shared/{misc-CCZIsXVO.mjs → misc-DJYbNKZX.mjs} +1 -2
  33. package/dist/shared/{normalize-string-or-regex-CaBvmZZK.mjs → normalize-string-or-regex-BU5HSJy4.mjs} +3 -6
  34. package/dist/shared/parse-Bt4kI3ey.mjs +74 -0
  35. package/dist/shared/{prompt-CI-U8Lh4.mjs → prompt-BYQIwEjg.mjs} +1 -3
  36. package/dist/shared/{rolldown-5hTSdYMy.mjs → rolldown-B4lV-glW.mjs} +2 -4
  37. package/dist/shared/rolldown-build-tLuGZc7p.mjs +3318 -0
  38. package/dist/shared/transform-BoJxrM-e.d.mts +132 -0
  39. package/dist/shared/transform-Cbhgjik0.mjs +90 -0
  40. package/dist/shared/{watch-CkctCkiN.mjs → watch-hs9ntURJ.mjs} +71 -76
  41. package/dist/utils-index.d.mts +376 -0
  42. package/dist/utils-index.mjs +2417 -0
  43. package/package.json +18 -17
  44. package/dist/cli-setup.d.mts +0 -1
  45. package/dist/cli-setup.mjs +0 -17
  46. package/dist/shared/parse-ast-index-BQ9Myuc2.mjs +0 -99
  47. package/dist/shared/rolldown-build-B7oitB1K.mjs +0 -2374
  48. /package/dist/shared/{logging-CE90D8JR.d.mts → logging-C6h4g8dA.d.mts} +0 -0
@@ -0,0 +1,132 @@
1
+ import { a as RolldownLog } from "./logging-C6h4g8dA.mjs";
2
+ import { I as ParseResult$1, L as ParserOptions$1, N as MinifyOptions$1, P as MinifyResult$1, U as TsconfigCache, V as SourceMap, a as BindingEnhancedTransformOptions, o as BindingEnhancedTransformResult } from "./binding-BohGL_65.mjs";
3
+
4
+ //#region src/utils/parse.d.ts
5
+ /**
6
+ * Result of parsing a code
7
+ *
8
+ * @category Utilities
9
+ */
10
+ interface ParseResult extends ParseResult$1 {}
11
+ /**
12
+ * Options for parsing a code
13
+ *
14
+ * @category Utilities
15
+ */
16
+ interface ParserOptions extends ParserOptions$1 {}
17
+ /**
18
+ * Parse JS/TS source asynchronously on a separate thread.
19
+ *
20
+ * Note that not all of the workload can happen on a separate thread.
21
+ * Parsing on Rust side does happen in a separate thread, but deserialization of the AST to JS objects
22
+ * has to happen on current thread. This synchronous deserialization work typically outweighs
23
+ * the asynchronous parsing by a factor of between 3 and 20.
24
+ *
25
+ * i.e. the majority of the workload cannot be parallelized by using this method.
26
+ *
27
+ * Generally {@linkcode parseSync} is preferable to use as it does not have the overhead of spawning a thread.
28
+ * If you need to parallelize parsing multiple files, it is recommended to use worker threads.
29
+ *
30
+ * @category Utilities
31
+ */
32
+ declare function parse(filename: string, sourceText: string, options?: ParserOptions | null): Promise<ParseResult>;
33
+ /**
34
+ * Parse JS/TS source synchronously on current thread.
35
+ *
36
+ * This is generally preferable over {@linkcode parse} (async) as it does not have the overhead
37
+ * of spawning a thread, and the majority of the workload cannot be parallelized anyway
38
+ * (see {@linkcode parse} documentation for details).
39
+ *
40
+ * If you need to parallelize parsing multiple files, it is recommended to use worker threads
41
+ * with {@linkcode parseSync} rather than using {@linkcode parse}.
42
+ *
43
+ * @category Utilities
44
+ */
45
+ declare function parseSync(filename: string, sourceText: string, options?: ParserOptions | null): ParseResult;
46
+ //#endregion
47
+ //#region src/utils/minify.d.ts
48
+ /**
49
+ * Options for minification.
50
+ *
51
+ * @category Utilities
52
+ */
53
+ interface MinifyOptions extends MinifyOptions$1 {
54
+ inputMap?: SourceMap;
55
+ }
56
+ /**
57
+ * The result of minification.
58
+ *
59
+ * @category Utilities
60
+ */
61
+ interface MinifyResult extends MinifyResult$1 {}
62
+ /**
63
+ * Minify asynchronously.
64
+ *
65
+ * Note: This function can be slower than {@linkcode minifySync} due to the overhead of spawning a thread.
66
+ *
67
+ * @category Utilities
68
+ * @experimental
69
+ */
70
+ declare function minify(filename: string, sourceText: string, options?: MinifyOptions | null): Promise<MinifyResult>;
71
+ /**
72
+ * Minify synchronously.
73
+ *
74
+ * @category Utilities
75
+ * @experimental
76
+ */
77
+ declare function minifySync(filename: string, sourceText: string, options?: MinifyOptions | null): MinifyResult;
78
+ //#endregion
79
+ //#region src/utils/transform.d.ts
80
+ /**
81
+ * Options for transforming a code.
82
+ *
83
+ * @category Utilities
84
+ */
85
+ interface TransformOptions extends BindingEnhancedTransformOptions {}
86
+ /**
87
+ * Result of transforming a code.
88
+ *
89
+ * @category Utilities
90
+ */
91
+ type TransformResult = Omit<BindingEnhancedTransformResult, "errors" | "warnings"> & {
92
+ errors: Error[];
93
+ warnings: RolldownLog[];
94
+ };
95
+ /**
96
+ * Transpile a JavaScript or TypeScript into a target ECMAScript version, asynchronously.
97
+ *
98
+ * Note: This function can be slower than `transformSync` due to the overhead of spawning a thread.
99
+ *
100
+ * @param filename The name of the file being transformed. If this is a
101
+ * relative path, consider setting the {@linkcode TransformOptions#cwd} option.
102
+ * @param sourceText The source code to transform.
103
+ * @param options The transform options including tsconfig and inputMap. See {@linkcode TransformOptions} for more information.
104
+ * @param cache Optional tsconfig cache for reusing resolved tsconfig across multiple transforms.
105
+ * Only used when `options.tsconfig` is `true`.
106
+ *
107
+ * @returns a promise that resolves to an object containing the transformed code,
108
+ * source maps, and any errors that occurred during parsing or transformation.
109
+ *
110
+ * @category Utilities
111
+ * @experimental
112
+ */
113
+ declare function transform(filename: string, sourceText: string, options?: TransformOptions | null, cache?: TsconfigCache | null): Promise<TransformResult>;
114
+ /**
115
+ * Transpile a JavaScript or TypeScript into a target ECMAScript version.
116
+ *
117
+ * @param filename The name of the file being transformed. If this is a
118
+ * relative path, consider setting the {@linkcode TransformOptions#cwd} option.
119
+ * @param sourceText The source code to transform.
120
+ * @param options The transform options including tsconfig and inputMap. See {@linkcode TransformOptions} for more information.
121
+ * @param cache Optional tsconfig cache for reusing resolved tsconfig across multiple transforms.
122
+ * Only used when `options.tsconfig` is `true`.
123
+ *
124
+ * @returns an object containing the transformed code, source maps, and any errors
125
+ * that occurred during parsing or transformation.
126
+ *
127
+ * @category Utilities
128
+ * @experimental
129
+ */
130
+ declare function transformSync(filename: string, sourceText: string, options?: TransformOptions | null, cache?: TsconfigCache | null): TransformResult;
131
+ //#endregion
132
+ export { MinifyOptions as a, minifySync as c, parse as d, parseSync as f, transformSync as i, ParseResult as l, TransformResult as n, MinifyResult as o, transform as r, minify as s, TransformOptions as t, ParserOptions as u };
@@ -0,0 +1,90 @@
1
+ import { n as __toESM, t as require_binding } from "./binding-BuW0Fhs2.mjs";
2
+ import { a as bindingifySourcemap, n as normalizeBindingError } from "./error-BjNWBTlf.mjs";
3
+ //#region src/utils/minify.ts
4
+ var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
5
+ /**
6
+ * Minify asynchronously.
7
+ *
8
+ * Note: This function can be slower than {@linkcode minifySync} due to the overhead of spawning a thread.
9
+ *
10
+ * @category Utilities
11
+ * @experimental
12
+ */
13
+ async function minify(filename, sourceText, options) {
14
+ const inputMap = bindingifySourcemap(options?.inputMap);
15
+ const result = await (0, import_binding.minify)(filename, sourceText, options);
16
+ if (result.map && inputMap) result.map = {
17
+ version: 3,
18
+ ...(0, import_binding.collapseSourcemaps)([inputMap, bindingifySourcemap(result.map)])
19
+ };
20
+ return result;
21
+ }
22
+ /**
23
+ * Minify synchronously.
24
+ *
25
+ * @category Utilities
26
+ * @experimental
27
+ */
28
+ function minifySync(filename, sourceText, options) {
29
+ const inputMap = bindingifySourcemap(options?.inputMap);
30
+ const result = (0, import_binding.minifySync)(filename, sourceText, options);
31
+ if (result.map && inputMap) result.map = {
32
+ version: 3,
33
+ ...(0, import_binding.collapseSourcemaps)([inputMap, bindingifySourcemap(result.map)])
34
+ };
35
+ return result;
36
+ }
37
+ //#endregion
38
+ //#region src/utils/transform.ts
39
+ /**
40
+ * Transpile a JavaScript or TypeScript into a target ECMAScript version, asynchronously.
41
+ *
42
+ * Note: This function can be slower than `transformSync` due to the overhead of spawning a thread.
43
+ *
44
+ * @param filename The name of the file being transformed. If this is a
45
+ * relative path, consider setting the {@linkcode TransformOptions#cwd} option.
46
+ * @param sourceText The source code to transform.
47
+ * @param options The transform options including tsconfig and inputMap. See {@linkcode TransformOptions} for more information.
48
+ * @param cache Optional tsconfig cache for reusing resolved tsconfig across multiple transforms.
49
+ * Only used when `options.tsconfig` is `true`.
50
+ *
51
+ * @returns a promise that resolves to an object containing the transformed code,
52
+ * source maps, and any errors that occurred during parsing or transformation.
53
+ *
54
+ * @category Utilities
55
+ * @experimental
56
+ */
57
+ async function transform(filename, sourceText, options, cache) {
58
+ const result = await (0, import_binding.enhancedTransform)(filename, sourceText, options, cache);
59
+ return {
60
+ ...result,
61
+ errors: result.errors.map(normalizeBindingError),
62
+ warnings: result.warnings.map((w) => w.field0)
63
+ };
64
+ }
65
+ /**
66
+ * Transpile a JavaScript or TypeScript into a target ECMAScript version.
67
+ *
68
+ * @param filename The name of the file being transformed. If this is a
69
+ * relative path, consider setting the {@linkcode TransformOptions#cwd} option.
70
+ * @param sourceText The source code to transform.
71
+ * @param options The transform options including tsconfig and inputMap. See {@linkcode TransformOptions} for more information.
72
+ * @param cache Optional tsconfig cache for reusing resolved tsconfig across multiple transforms.
73
+ * Only used when `options.tsconfig` is `true`.
74
+ *
75
+ * @returns an object containing the transformed code, source maps, and any errors
76
+ * that occurred during parsing or transformation.
77
+ *
78
+ * @category Utilities
79
+ * @experimental
80
+ */
81
+ function transformSync(filename, sourceText, options, cache) {
82
+ const result = (0, import_binding.enhancedTransformSync)(filename, sourceText, options, cache);
83
+ return {
84
+ ...result,
85
+ errors: result.errors.map(normalizeBindingError),
86
+ warnings: result.warnings.map((w) => w.field0)
87
+ };
88
+ }
89
+ //#endregion
90
+ export { minifySync as a, minify as i, transform as n, transformSync as r, import_binding as t };
@@ -1,9 +1,9 @@
1
- import { n as __toESM, t as require_binding } from "./binding-9QXxzPo6.mjs";
2
- import { o as logMultiplyNotifyOption } from "./logs-NH298mHo.mjs";
3
- import { a as aggregateBindingErrorsIntoJsError, b as LOG_LEVEL_WARN } from "./bindingify-input-options-C--dZCPv.mjs";
4
- import { t as arraify } from "./misc-CCZIsXVO.mjs";
5
- import { l as PluginDriver, n as createBundlerOptions } from "./rolldown-build-B7oitB1K.mjs";
6
-
1
+ import { n as __toESM, t as require_binding } from "./binding-BuW0Fhs2.mjs";
2
+ import { o as logMultipleWatcherOption } from "./logs-D80CXhvg.mjs";
3
+ import { _ as LOG_LEVEL_WARN } from "./bindingify-input-options-o_7NioSs.mjs";
4
+ import { t as arraify } from "./misc-DJYbNKZX.mjs";
5
+ import { n as createBundlerOptions, u as PluginDriver } from "./rolldown-build-tLuGZc7p.mjs";
6
+ import { t as aggregateBindingErrorsIntoJsError } from "./error-BjNWBTlf.mjs";
7
7
  //#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.js
8
8
  /**
9
9
  * This is not the set of all possible signals.
@@ -35,7 +35,6 @@ const signals = [];
35
35
  signals.push("SIGHUP", "SIGINT", "SIGTERM");
36
36
  if (process.platform !== "win32") signals.push("SIGALRM", "SIGABRT", "SIGVTALRM", "SIGXCPU", "SIGXFSZ", "SIGUSR2", "SIGTRAP", "SIGSYS", "SIGQUIT", "SIGIOT");
37
37
  if (process.platform === "linux") signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");
38
-
39
38
  //#endregion
40
39
  //#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.js
41
40
  const processOk = (process) => !!process && typeof process === "object" && typeof process.removeListener === "function" && typeof process.emit === "function" && typeof process.reallyExit === "function" && typeof process.listeners === "function" && typeof process.kill === "function" && typeof process.pid === "number" && typeof process.on === "function";
@@ -203,7 +202,6 @@ var SignalExit = class extends SignalExitBase {
203
202
  };
204
203
  const process$1 = globalThis.process;
205
204
  const { onExit: onExit$1, load, unload } = signalExitWrap(processOk(process$1) ? new SignalExit(process$1) : new SignalExitFallback());
206
-
207
205
  //#endregion
208
206
  //#region src/utils/signal-exit.ts
209
207
  function onExit(...args) {
@@ -215,16 +213,10 @@ function onExit(...args) {
215
213
  }
216
214
  onExit$1(...args);
217
215
  }
218
-
219
216
  //#endregion
220
217
  //#region src/api/watch/watch-emitter.ts
221
- var import_binding = /* @__PURE__ */ __toESM(require_binding());
222
218
  var WatcherEmitter = class {
223
219
  listeners = /* @__PURE__ */ new Map();
224
- timer;
225
- constructor() {
226
- this.timer = setInterval(() => {}, 1e9);
227
- }
228
220
  on(event, listener) {
229
221
  const listeners = this.listeners.get(event);
230
222
  if (listeners) listeners.push(listener);
@@ -240,58 +232,56 @@ var WatcherEmitter = class {
240
232
  return this;
241
233
  }
242
234
  clear(event) {
243
- if (this.listeners.has(event)) this.listeners.delete(event);
244
- }
245
- async onEvent(event) {
246
- const listeners = this.listeners.get(event.eventKind());
247
- if (listeners) switch (event.eventKind()) {
248
- case "close":
249
- case "restart":
250
- for (const listener of listeners) await listener();
251
- break;
252
- case "event":
253
- for (const listener of listeners) {
254
- const code = event.bundleEventKind();
255
- switch (code) {
256
- case "BUNDLE_END":
257
- const { duration, output, result } = event.bundleEndData();
258
- await listener({
259
- code: "BUNDLE_END",
260
- duration,
261
- output: [output],
262
- result
263
- });
264
- break;
265
- case "ERROR":
266
- const data = event.bundleErrorData();
267
- await listener({
268
- code: "ERROR",
269
- error: aggregateBindingErrorsIntoJsError(data.error),
270
- result: data.result
271
- });
272
- break;
273
- default:
274
- await listener({ code });
275
- break;
276
- }
277
- }
278
- break;
279
- case "change":
280
- for (const listener of listeners) {
281
- const { path, kind } = event.watchChangeData();
282
- await listener(path, { event: kind });
283
- }
284
- break;
285
- default: throw new Error(`Unknown event: ${event}`);
286
- }
235
+ this.listeners.delete(event);
287
236
  }
288
- async close() {
289
- clearInterval(this.timer);
237
+ /** Async emit — sequential dispatch so side effects from earlier handlers
238
+ * (e.g. `event.result.close()` triggering `closeBundle`) are visible to later handlers. */
239
+ async emit(event, ...args) {
240
+ const handlers = this.listeners.get(event);
241
+ if (handlers?.length) for (const h of handlers) await h(...args);
290
242
  }
243
+ async close() {}
291
244
  };
292
-
293
245
  //#endregion
294
246
  //#region src/api/watch/watcher.ts
247
+ var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
248
+ function createEventCallback(emitter) {
249
+ return async (event) => {
250
+ switch (event.eventKind()) {
251
+ case "event": {
252
+ const code = event.bundleEventKind();
253
+ if (code === "BUNDLE_END") {
254
+ const { duration, output, result } = event.bundleEndData();
255
+ await emitter.emit("event", {
256
+ code: "BUNDLE_END",
257
+ duration,
258
+ output: [output],
259
+ result
260
+ });
261
+ } else if (code === "ERROR") {
262
+ const data = event.bundleErrorData();
263
+ await emitter.emit("event", {
264
+ code: "ERROR",
265
+ error: aggregateBindingErrorsIntoJsError(data.error),
266
+ result: data.result
267
+ });
268
+ } else await emitter.emit("event", { code });
269
+ break;
270
+ }
271
+ case "change": {
272
+ const { path, kind } = event.watchChangeData();
273
+ await emitter.emit("change", path, { event: kind });
274
+ break;
275
+ }
276
+ case "restart":
277
+ await emitter.emit("restart");
278
+ break;
279
+ case "close":
280
+ await emitter.emit("close");
281
+ break;
282
+ }
283
+ };
284
+ }
295
285
  var Watcher = class {
296
286
  closed;
297
287
  inner;
@@ -307,6 +297,7 @@ var Watcher = class {
307
297
  originClose();
308
298
  };
309
299
  this.stopWorkers = stopWorkers;
300
+ process.nextTick(() => this.run());
310
301
  }
311
302
  async close() {
312
303
  if (this.closed) return;
@@ -315,8 +306,9 @@ var Watcher = class {
315
306
  await this.inner.close();
316
307
  (0, import_binding.shutdownAsyncRuntime)();
317
308
  }
318
- start() {
319
- process.nextTick(() => this.inner.start(this.emitter.onEvent.bind(this.emitter)));
309
+ async run() {
310
+ await this.inner.run();
311
+ this.inner.waitForClose();
320
312
  }
321
313
  };
322
314
  async function createWatcher(emitter, input) {
@@ -324,20 +316,24 @@ async function createWatcher(emitter, input) {
324
316
  const bundlerOptions = await Promise.all(options.map((option) => arraify(option.output || {}).map(async (output) => {
325
317
  return createBundlerOptions(await PluginDriver.callOptionsHook(option, true), output, true);
326
318
  })).flat());
327
- const notifyOptions = getValidNotifyOption(bundlerOptions);
328
- new Watcher(emitter, new import_binding.BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions), bundlerOptions.map((option) => option.stopWorkers)).start();
319
+ warnMultiplePollingOptions(bundlerOptions);
320
+ const callback = createEventCallback(emitter);
321
+ new Watcher(emitter, new import_binding.BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), callback), bundlerOptions.map((option) => option.stopWorkers));
329
322
  }
330
- function getValidNotifyOption(bundlerOptions) {
331
- let result;
332
- for (const option of bundlerOptions) if (option.inputOptions.watch) {
333
- const notifyOption = option.inputOptions.watch.notify;
334
- if (notifyOption) if (result) {
335
- option.onLog(LOG_LEVEL_WARN, logMultiplyNotifyOption());
336
- return result;
337
- } else result = notifyOption;
323
+ function warnMultiplePollingOptions(bundlerOptions) {
324
+ let found = false;
325
+ for (const option of bundlerOptions) {
326
+ const watch = option.inputOptions.watch;
327
+ const watcher = watch && typeof watch === "object" ? watch.watcher ?? watch.notify : void 0;
328
+ if (watcher && (watcher.usePolling != null || watcher.pollInterval != null)) {
329
+ if (found) {
330
+ option.onLog(LOG_LEVEL_WARN, logMultipleWatcherOption());
331
+ return;
332
+ }
333
+ found = true;
334
+ }
338
335
  }
339
336
  }
340
-
341
337
  //#endregion
342
338
  //#region src/api/watch/index.ts
343
339
  /**
@@ -374,6 +370,5 @@ function watch(input) {
374
370
  createWatcher(emitter, input);
375
371
  return emitter;
376
372
  }
377
-
378
373
  //#endregion
379
- export { onExit as n, watch as t };
374
+ export { onExit as n, watch as t };