rolldown 0.14.0-snapshot-d42ea8a-20241202003632 → 0.15.0-commit.ac58858

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 (53) hide show
  1. package/dist/cjs/cli.cjs +189 -175
  2. package/dist/cjs/experimental-index.cjs +12 -3
  3. package/dist/cjs/index.cjs +2 -1
  4. package/dist/cjs/parallel-plugin-worker.cjs +2 -2
  5. package/dist/esm/cli.mjs +282 -268
  6. package/dist/esm/experimental-index.mjs +10 -1
  7. package/dist/esm/index.mjs +2 -2
  8. package/dist/esm/parallel-plugin-worker.mjs +1 -1
  9. package/dist/shared/{chunk-BK2Ye-xa.cjs → chunk-BFvIen8E.cjs} +0 -11
  10. package/dist/shared/{consola_36c0034f-_8_dG1Nr.cjs → consola_36c0034f-B7L-radJ.cjs} +2 -2
  11. package/dist/shared/{consola_36c0034f-DWsVjwtA.mjs → consola_36c0034f-D9ce-831.mjs} +10 -10
  12. package/dist/shared/{prompt-RFvZMmjc.cjs → prompt-BiXtYIJ2.cjs} +3 -3
  13. package/dist/shared/{prompt-DGW8ZJmn.mjs → prompt-DlQ-08lk.mjs} +2 -2
  14. package/dist/shared/{src-CfQyqNSn.cjs → src-Bs7g4_us.cjs} +227 -121
  15. package/dist/shared/{src-DhHfkqAC.mjs → src-C-NQjnqV.mjs} +226 -136
  16. package/dist/tsconfig.dts.tsbuildinfo +1 -0
  17. package/dist/types/api/build.d.ts +16 -0
  18. package/dist/types/api/experimental.d.ts +7 -0
  19. package/dist/types/api/rolldown/index.d.ts +3 -0
  20. package/dist/types/{rolldown-build.d.ts → api/rolldown/rolldown-build.d.ts} +3 -3
  21. package/dist/types/api/watch/index.d.ts +3 -0
  22. package/dist/types/{watcher.d.ts → api/watch/watch-emitter.d.ts} +15 -17
  23. package/dist/types/api/watch/watcher.d.ts +13 -0
  24. package/dist/types/binding.d.ts +108 -15
  25. package/dist/types/builtin-plugin/constructors.d.ts +1 -5
  26. package/dist/types/cli/arguments/index.d.ts +5 -3
  27. package/dist/types/cli/arguments/schema.d.ts +10 -397
  28. package/dist/types/cli/colors.d.ts +11 -1
  29. package/dist/types/cli/utils.d.ts +2 -1
  30. package/dist/types/constants/plugin.d.ts +8 -1
  31. package/dist/types/experimental-index.d.ts +1 -1
  32. package/dist/types/index.d.ts +8 -6
  33. package/dist/types/log/logging.d.ts +6 -6
  34. package/dist/types/log/logs.d.ts +1 -0
  35. package/dist/types/options/input-options-schema.d.ts +3 -595
  36. package/dist/types/options/input-options.d.ts +16 -1
  37. package/dist/types/options/normalized-input-options.d.ts +1 -1
  38. package/dist/types/options/normalized-output-options.d.ts +20 -17
  39. package/dist/types/options/output-options-schema.d.ts +2 -146
  40. package/dist/types/options/output-options.d.ts +1 -0
  41. package/dist/types/plugin/plugin-context-data.d.ts +2 -1
  42. package/dist/types/rollup.d.ts +4 -0
  43. package/dist/types/treeshake/module-side-effects.d.ts +14 -115
  44. package/dist/types/types/rolldown-output.d.ts +6 -0
  45. package/dist/types/utils/bindingify-input-options.d.ts +1 -1
  46. package/dist/types/utils/create-bundler-option.d.ts +11 -0
  47. package/dist/types/utils/error.d.ts +2 -1
  48. package/dist/types/utils/misc.d.ts +1 -0
  49. package/dist/types/utils/transform-sourcemap.d.ts +1 -1
  50. package/dist/types/utils/zod-ext.d.ts +6 -5
  51. package/package.json +15 -15
  52. package/dist/types/log/locate-character/index.d.ts +0 -13
  53. package/dist/types/rolldown.d.ts +0 -12
@@ -1,4 +1,5 @@
1
- const require_chunk = require('./chunk-BK2Ye-xa.cjs');
1
+ const require_chunk = require('./chunk-BFvIen8E.cjs');
2
+ const node_buffer = require_chunk.__toESM(require("node:buffer"));
2
3
  const zod = require_chunk.__toESM(require("zod"));
3
4
  const node_path = require_chunk.__toESM(require("node:path"));
4
5
  const node_worker_threads = require_chunk.__toESM(require("node:worker_threads"));
@@ -35,7 +36,11 @@ function bindingifySourcemap$1(map) {
35
36
  //#endregion
36
37
  //#region src/utils/error.ts
37
38
  function normalizeErrors(rawErrors) {
38
- const errors = rawErrors.map((e) => e instanceof Error ? e : Object.assign(new Error(), e, { stack: undefined }));
39
+ const errors = rawErrors.map((e) => e instanceof Error ? e : Object.assign(new Error(), {
40
+ kind: e.kind,
41
+ message: e.message,
42
+ stack: undefined
43
+ }));
39
44
  let summary = `Build failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
40
45
  for (let i = 0; i < errors.length; i++) {
41
46
  if (i >= 5) {
@@ -107,6 +112,19 @@ function transformChunkModules(modules) {
107
112
 
108
113
  //#endregion
109
114
  //#region src/utils/transform-to-rollup-output.ts
115
+ function transformToRollupSourceMap(map) {
116
+ const parsed = JSON.parse(map);
117
+ const obj = {
118
+ ...parsed,
119
+ toString() {
120
+ return JSON.stringify(obj);
121
+ },
122
+ toUrl() {
123
+ return `data:application/json;charset=utf-8;base64,${node_buffer.Buffer.from(obj.toString(), "utf-8").toString("base64")}`;
124
+ }
125
+ };
126
+ return obj;
127
+ }
110
128
  function transformToRollupOutputChunk(bindingChunk, changed) {
111
129
  const chunk = {
112
130
  type: "chunk",
@@ -132,7 +150,7 @@ function transformToRollupOutputChunk(bindingChunk, changed) {
132
150
  return bindingChunk.moduleIds;
133
151
  },
134
152
  get map() {
135
- return bindingChunk.map ? JSON.parse(bindingChunk.map) : null;
153
+ return bindingChunk.map ? transformToRollupSourceMap(bindingChunk.map) : null;
136
154
  },
137
155
  sourcemapFileName: bindingChunk.sourcemapFileName || null,
138
156
  preliminaryFileName: bindingChunk.preliminaryFileName
@@ -155,10 +173,12 @@ function transformToRollupOutputAsset(bindingAsset, changed) {
155
173
  type: "asset",
156
174
  fileName: bindingAsset.fileName,
157
175
  originalFileName: bindingAsset.originalFileName || null,
176
+ originalFileNames: bindingAsset.originalFileNames,
158
177
  get source() {
159
178
  return transformAssetSource(bindingAsset.source);
160
179
  },
161
- name: bindingAsset.name ?? undefined
180
+ name: bindingAsset.name ?? undefined,
181
+ names: bindingAsset.names
162
182
  };
163
183
  const cache = {};
164
184
  return new Proxy(asset, {
@@ -197,9 +217,9 @@ function collectChangedBundle(changed, bundle) {
197
217
  const item = bundle[key];
198
218
  if (item.type === "asset") assets.push({
199
219
  filename: item.fileName,
200
- originalFileName: item.originalFileName || undefined,
220
+ originalFileNames: item.originalFileNames,
201
221
  source: bindingAssetSource(item.source),
202
- name: item.name
222
+ names: item.names
203
223
  });
204
224
  else chunks.push({
205
225
  code: item.code,
@@ -207,7 +227,7 @@ else chunks.push({
207
227
  name: item.name,
208
228
  isEntry: item.isEntry,
209
229
  exports: item.exports,
210
- modules: Object.fromEntries(Object.entries(item.modules).map(([key$1, _]) => [key$1, {}])),
230
+ modules: {},
211
231
  imports: item.imports,
212
232
  dynamicImports: item.dynamicImports,
213
233
  facadeModuleId: item.facadeModuleId || undefined,
@@ -517,6 +537,7 @@ else loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architectur
517
537
  }
518
538
  module.exports.BindingBundleEndEventData = nativeBinding.BindingBundleEndEventData;
519
539
  module.exports.BindingCallableBuiltinPlugin = nativeBinding.BindingCallableBuiltinPlugin;
540
+ module.exports.BindingError = nativeBinding.BindingError;
520
541
  module.exports.BindingLog = nativeBinding.BindingLog;
521
542
  module.exports.BindingModuleInfo = nativeBinding.BindingModuleInfo;
522
543
  module.exports.BindingNormalizedOptions = nativeBinding.BindingNormalizedOptions;
@@ -535,8 +556,10 @@ else loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architectur
535
556
  module.exports.BindingHookSideEffects = nativeBinding.BindingHookSideEffects;
536
557
  module.exports.BindingLogLevel = nativeBinding.BindingLogLevel;
537
558
  module.exports.BindingPluginOrder = nativeBinding.BindingPluginOrder;
559
+ module.exports.HelperMode = nativeBinding.HelperMode;
538
560
  module.exports.isolatedDeclaration = nativeBinding.isolatedDeclaration;
539
561
  module.exports.registerPlugins = nativeBinding.registerPlugins;
562
+ module.exports.Severity = nativeBinding.Severity;
540
563
  module.exports.transform = nativeBinding.transform;
541
564
  } });
542
565
 
@@ -674,7 +697,7 @@ function locate(source, search, options) {
674
697
 
675
698
  //#endregion
676
699
  //#region src/log/logs.ts
677
- const INVALID_LOG_POSITION = "INVALID_LOG_POSITION", PLUGIN_ERROR = "PLUGIN_ERROR", INPUT_HOOK_IN_OUTPUT_PLUGIN = "INPUT_HOOK_IN_OUTPUT_PLUGIN", CYCLE_LOADING = "CYCLE_LOADING";
700
+ const INVALID_LOG_POSITION = "INVALID_LOG_POSITION", PLUGIN_ERROR = "PLUGIN_ERROR", INPUT_HOOK_IN_OUTPUT_PLUGIN = "INPUT_HOOK_IN_OUTPUT_PLUGIN", CYCLE_LOADING = "CYCLE_LOADING", MULTIPLY_NOTIFY_OPTION = "MULTIPLY_NOTIFY_OPTION";
678
701
  function logInvalidLogPosition(pluginName) {
679
702
  return {
680
703
  code: INVALID_LOG_POSITION,
@@ -693,6 +716,12 @@ function logCycleLoading(pluginName, moduleId) {
693
716
  message: `Found the module "${moduleId}" cycle loading at ${pluginName} plugin, it maybe blocking fetching modules.`
694
717
  };
695
718
  }
719
+ function logMultiplyNotifyOption() {
720
+ return {
721
+ code: MULTIPLY_NOTIFY_OPTION,
722
+ message: `Found multiply notify option at watch options, using first one to start notify watcher.`
723
+ };
724
+ }
696
725
  function logPluginError(error$1, plugin, { hook, id } = {}) {
697
726
  const code = error$1.code;
698
727
  if (!error$1.pluginCode && code != null && (typeof code !== "string" || !code.startsWith("PLUGIN_"))) error$1.pluginCode = code;
@@ -848,9 +877,9 @@ function relativeId(id) {
848
877
 
849
878
  //#endregion
850
879
  //#region src/builtin-plugin/utils.ts
851
- var import_binding$5 = require_chunk.__toESM(require_binding());
880
+ var import_binding$6 = require_chunk.__toESM(require_binding());
852
881
  function makeBuiltinPluginCallable(plugin) {
853
- let callablePlugin = new import_binding$5.BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
882
+ let callablePlugin = new import_binding$6.BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
854
883
  const wrappedPlugin = plugin;
855
884
  for (const key in callablePlugin) wrappedPlugin[key] = function(...args) {
856
885
  return callablePlugin[key](...args);
@@ -1083,7 +1112,7 @@ const ModuleSideEffectsRuleSchema = zod.z.object({
1083
1112
  }).refine((data) => {
1084
1113
  return data.test !== undefined || data.external !== undefined;
1085
1114
  }, "Either `test` or `external` should be set.");
1086
- const ModuleSideEffectsOptionSchema = zod.z.boolean().or(zod.z.array(ModuleSideEffectsRuleSchema)).or(zod.z.literal("no-external"));
1115
+ const ModuleSideEffectsOptionSchema = zod.z.boolean().or(zod.z.array(ModuleSideEffectsRuleSchema)).or(zod.z.function().args(zod.z.string(), zod.z.boolean()).returns(zod.z.boolean().optional())).or(zod.z.literal("no-external"));
1087
1116
  const TreeshakingOptionsSchema = zod.z.object({
1088
1117
  moduleSideEffects: ModuleSideEffectsOptionSchema.optional(),
1089
1118
  annotations: zod.z.boolean().optional()
@@ -1150,12 +1179,12 @@ var MinimalPluginContext = class {
1150
1179
 
1151
1180
  //#endregion
1152
1181
  //#region src/utils/transform-side-effects.ts
1153
- var import_binding$4 = require_chunk.__toESM(require_binding());
1182
+ var import_binding$5 = require_chunk.__toESM(require_binding());
1154
1183
  function bindingifySideEffects(sideEffects) {
1155
1184
  switch (sideEffects) {
1156
- case true: return import_binding$4.BindingHookSideEffects.True;
1157
- case false: return import_binding$4.BindingHookSideEffects.False;
1158
- case "no-treeshake": return import_binding$4.BindingHookSideEffects.NoTreeshake;
1185
+ case true: return import_binding$5.BindingHookSideEffects.True;
1186
+ case false: return import_binding$5.BindingHookSideEffects.False;
1187
+ case "no-treeshake": return import_binding$5.BindingHookSideEffects.NoTreeshake;
1159
1188
  case null:
1160
1189
  case undefined: return undefined;
1161
1190
  default: throw new Error(`Unexpected side effects: ${sideEffects}`);
@@ -1266,14 +1295,14 @@ var TransformPluginContext = class extends PluginContext {
1266
1295
 
1267
1296
  //#endregion
1268
1297
  //#region src/plugin/bindingify-plugin-hook-meta.ts
1269
- var import_binding$3 = require_chunk.__toESM(require_binding());
1298
+ var import_binding$4 = require_chunk.__toESM(require_binding());
1270
1299
  function bindingifyPluginHookMeta(options) {
1271
1300
  return { order: bindingPluginOrder(options.order) };
1272
1301
  }
1273
1302
  function bindingPluginOrder(order) {
1274
1303
  switch (order) {
1275
- case "post": return import_binding$3.BindingPluginOrder.Post;
1276
- case "pre": return import_binding$3.BindingPluginOrder.Pre;
1304
+ case "post": return import_binding$4.BindingPluginOrder.Post;
1305
+ case "pre": return import_binding$4.BindingPluginOrder.Pre;
1277
1306
  case null:
1278
1307
  case undefined: return undefined;
1279
1308
  default: throw new Error(`Unknown plugin order: ${order}`);
@@ -1354,7 +1383,7 @@ function bindingifyBuildEnd(args) {
1354
1383
  const { handler, meta } = normalizeHook(hook);
1355
1384
  return {
1356
1385
  plugin: async (ctx, err) => {
1357
- await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), err ? new Error(err) : undefined);
1386
+ await handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), err ? normalizeErrors(err) : undefined);
1358
1387
  },
1359
1388
  meta: bindingifyPluginHookMeta(meta)
1360
1389
  };
@@ -1581,6 +1610,9 @@ var NormalizedOutputOptionsImpl = class {
1581
1610
  get comments() {
1582
1611
  return this.inner.comments;
1583
1612
  }
1613
+ get polyfillRequire() {
1614
+ return this.inner.polyfillRequire;
1615
+ }
1584
1616
  };
1585
1617
 
1586
1618
  //#endregion
@@ -1631,7 +1663,7 @@ function bindingifyRenderError(args) {
1631
1663
  const { handler, meta } = normalizeHook(hook);
1632
1664
  return {
1633
1665
  plugin: async (ctx, err) => {
1634
- handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), new Error(err));
1666
+ handler.call(new PluginContext(ctx, args.plugin, args.pluginContextData, args.onLog, args.logLevel), normalizeErrors(err));
1635
1667
  },
1636
1668
  meta: bindingifyPluginHookMeta(meta)
1637
1669
  };
@@ -1932,7 +1964,7 @@ function normalizedStringOrRegex(pattern) {
1932
1964
 
1933
1965
  //#endregion
1934
1966
  //#region src/utils/bindingify-input-options.ts
1935
- var import_binding$2 = require_chunk.__toESM(require_binding());
1967
+ var import_binding$3 = require_chunk.__toESM(require_binding());
1936
1968
  function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, onLog, logLevel) {
1937
1969
  const pluginContextData = new PluginContextData();
1938
1970
  const plugins = rawPlugins.map((plugin) => {
@@ -1963,7 +1995,9 @@ function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, onLog,
1963
1995
  profilerNames: inputOptions?.profilerNames,
1964
1996
  jsx: bindingifyJsx(inputOptions.jsx),
1965
1997
  watch: bindingifyWatch(inputOptions.watch),
1966
- dropLabels: inputOptions.dropLabels
1998
+ dropLabels: inputOptions.dropLabels,
1999
+ keepNames: inputOptions.keepNames,
2000
+ checks: inputOptions.checks
1967
2001
  };
1968
2002
  }
1969
2003
  function bindingifyExternal(external) {
@@ -1987,7 +2021,7 @@ function bindingifyResolve(resolve) {
1987
2021
  return {
1988
2022
  alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
1989
2023
  find: name,
1990
- replacements: [replacement]
2024
+ replacements: arraify(replacement)
1991
2025
  })) : undefined,
1992
2026
  extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
1993
2027
  target: name,
@@ -2021,10 +2055,10 @@ function bindingifyInject(inject) {
2021
2055
  }
2022
2056
  function bindingifyLogLevel(logLevel) {
2023
2057
  switch (logLevel) {
2024
- case "silent": return import_binding$2.BindingLogLevel.Silent;
2025
- case "debug": return import_binding$2.BindingLogLevel.Debug;
2026
- case "warn": return import_binding$2.BindingLogLevel.Warn;
2027
- case "info": return import_binding$2.BindingLogLevel.Info;
2058
+ case "silent": return import_binding$3.BindingLogLevel.Silent;
2059
+ case "debug": return import_binding$3.BindingLogLevel.Debug;
2060
+ case "warn": return import_binding$3.BindingLogLevel.Warn;
2061
+ case "info": return import_binding$3.BindingLogLevel.Info;
2028
2062
  default: throw new Error(`Unexpected log level: ${logLevel}`);
2029
2063
  }
2030
2064
  }
@@ -2059,10 +2093,6 @@ function bindingifyWatch(watch$1) {
2059
2093
  include: normalizedStringOrRegex(watch$1.include),
2060
2094
  exclude: normalizedStringOrRegex(watch$1.exclude)
2061
2095
  };
2062
- if (watch$1.notify) value.notify = {
2063
- pollInterval: watch$1.notify.pollInterval,
2064
- compareContents: watch$1.notify.compareContents
2065
- };
2066
2096
  if (watch$1.chokidar) unsupported("The watch chokidar option is deprecated, please use notify options instead of it.");
2067
2097
  return value;
2068
2098
  }
@@ -2117,7 +2147,8 @@ function bindingifyOutputOptions(outputOptions) {
2117
2147
  minify: outputOptions.minify,
2118
2148
  externalLiveBindings: outputOptions.externalLiveBindings,
2119
2149
  inlineDynamicImports: outputOptions.inlineDynamicImports,
2120
- advancedChunks: outputOptions.advancedChunks
2150
+ advancedChunks: outputOptions.advancedChunks,
2151
+ polyfillRequire: outputOptions.polyfillRequire
2121
2152
  };
2122
2153
  }
2123
2154
  function bindingifyAddon(configAddon) {
@@ -2503,7 +2534,7 @@ else newPlugins.push(toBeComposed[0]);
2503
2534
 
2504
2535
  //#endregion
2505
2536
  //#region src/utils/initialize-parallel-plugins.ts
2506
- var import_binding$1 = require_chunk.__toESM(require_binding());
2537
+ var import_binding$2 = require_chunk.__toESM(require_binding());
2507
2538
  async function initializeParallelPlugins(plugins) {
2508
2539
  const pluginInfos = [];
2509
2540
  for (const [index, plugin] of plugins.entries()) if ("_parallel" in plugin) {
@@ -2516,7 +2547,7 @@ async function initializeParallelPlugins(plugins) {
2516
2547
  }
2517
2548
  if (pluginInfos.length <= 0) return undefined;
2518
2549
  const count = Math.min((0, node_os.availableParallelism)(), 8);
2519
- const parallelJsPluginRegistry = new import_binding$1.ParallelJsPluginRegistry(count);
2550
+ const parallelJsPluginRegistry = new import_binding$2.ParallelJsPluginRegistry(count);
2520
2551
  const registryId = parallelJsPluginRegistry.id;
2521
2552
  const workers = await initializeWorkers(registryId, count, pluginInfos);
2522
2553
  const stopWorkers = async () => {
@@ -2555,9 +2586,8 @@ else resolve();
2555
2586
  }
2556
2587
 
2557
2588
  //#endregion
2558
- //#region src/utils/create-bundler.ts
2559
- var import_binding = require_chunk.__toESM(require_binding());
2560
- async function createBundler(inputOptions, outputOptions) {
2589
+ //#region src/utils/create-bundler-option.ts
2590
+ async function createBundlerOptions(inputOptions, outputOptions) {
2561
2591
  const pluginDriver = new PluginDriver();
2562
2592
  inputOptions = await pluginDriver.callOptionsHook(inputOptions);
2563
2593
  if (inputOptions.treeshake !== undefined) TreeshakingOptionsSchema.parse(inputOptions.treeshake);
@@ -2573,7 +2603,13 @@ async function createBundler(inputOptions, outputOptions) {
2573
2603
  const bindingInputOptions = bindingifyInputOptions(plugins, inputOptions, outputOptions, onLog, logLevel);
2574
2604
  const bindingOutputOptions = bindingifyOutputOptions(outputOptions);
2575
2605
  return {
2576
- bundler: new import_binding.Bundler(bindingInputOptions, bindingOutputOptions, parallelPluginInitResult?.registry),
2606
+ bundlerOptions: {
2607
+ inputOptions: bindingInputOptions,
2608
+ outputOptions: bindingOutputOptions,
2609
+ parallelPluginsRegistry: parallelPluginInitResult?.registry
2610
+ },
2611
+ inputOptions,
2612
+ onLog,
2577
2613
  stopWorkers: parallelPluginInitResult?.stopWorkers
2578
2614
  };
2579
2615
  } catch (e) {
@@ -2583,7 +2619,23 @@ async function createBundler(inputOptions, outputOptions) {
2583
2619
  }
2584
2620
 
2585
2621
  //#endregion
2586
- //#region src/rolldown-build.ts
2622
+ //#region src/utils/create-bundler.ts
2623
+ var import_binding$1 = require_chunk.__toESM(require_binding());
2624
+ async function createBundler(inputOptions, outputOptions) {
2625
+ const option = await createBundlerOptions(inputOptions, outputOptions);
2626
+ try {
2627
+ return {
2628
+ bundler: new import_binding$1.Bundler(option.bundlerOptions),
2629
+ stopWorkers: option.stopWorkers
2630
+ };
2631
+ } catch (e) {
2632
+ await option.stopWorkers?.();
2633
+ throw e;
2634
+ }
2635
+ }
2636
+
2637
+ //#endregion
2638
+ //#region src/api/rolldown/rolldown-build.ts
2587
2639
  Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
2588
2640
  var RolldownBuild = class {
2589
2641
  #inputOptions;
@@ -2619,108 +2671,152 @@ var RolldownBuild = class {
2619
2671
  };
2620
2672
 
2621
2673
  //#endregion
2622
- //#region src/watcher.ts
2674
+ //#region src/api/rolldown/index.ts
2675
+ const rolldown = async (input) => {
2676
+ return new RolldownBuild(input);
2677
+ };
2678
+
2679
+ //#endregion
2680
+ //#region src/api/watch/watch-emitter.ts
2681
+ var WatcherEmitter = class {
2682
+ listeners = new Map();
2683
+ timer;
2684
+ constructor() {
2685
+ this.timer = setInterval(
2686
+ () => {},
2687
+ 1e9
2688
+ /* Low power usage */
2689
+ );
2690
+ }
2691
+ on(event, listener) {
2692
+ const listeners = this.listeners.get(event);
2693
+ if (listeners) listeners.push(listener);
2694
+ else this.listeners.set(event, [listener]);
2695
+ return this;
2696
+ }
2697
+ async onEvent(event) {
2698
+ const listeners = this.listeners.get(event.eventKind());
2699
+ if (listeners) switch (event.eventKind()) {
2700
+ case "close":
2701
+ case "restart":
2702
+ for (const listener of listeners) await listener();
2703
+ break;
2704
+ case "event":
2705
+ for (const listener of listeners) {
2706
+ const code = event.bundleEventKind();
2707
+ switch (code) {
2708
+ case "BUNDLE_END":
2709
+ const { duration, output } = event.bundleEndData();
2710
+ await listener({
2711
+ code: "BUNDLE_END",
2712
+ duration,
2713
+ output: [output]
2714
+ });
2715
+ break;
2716
+ case "ERROR":
2717
+ const errors = event.errors();
2718
+ await listener({
2719
+ code: "ERROR",
2720
+ error: normalizeErrors(errors)
2721
+ });
2722
+ break;
2723
+ default:
2724
+ await listener({ code });
2725
+ break;
2726
+ }
2727
+ }
2728
+ break;
2729
+ case "change":
2730
+ for (const listener of listeners) {
2731
+ const { path: path$2, kind } = event.watchChangeData();
2732
+ await listener(path$2, { event: kind });
2733
+ }
2734
+ break;
2735
+ default: throw new Error(`Unknown event: ${event}`);
2736
+ }
2737
+ }
2738
+ async close() {
2739
+ clearInterval(this.timer);
2740
+ }
2741
+ };
2742
+
2743
+ //#endregion
2744
+ //#region src/api/watch/watcher.ts
2745
+ var import_binding = require_chunk.__toESM(require_binding());
2623
2746
  var Watcher = class {
2624
2747
  closed;
2625
- controller;
2626
2748
  inner;
2749
+ emitter;
2627
2750
  stopWorkers;
2628
- listeners = new Map();
2629
- constructor(inner, stopWorkers) {
2751
+ constructor(emitter, inner, stopWorkers) {
2630
2752
  this.closed = false;
2631
- this.controller = new AbortController();
2632
2753
  this.inner = inner;
2754
+ this.emitter = emitter;
2755
+ const originClose = emitter.close.bind(emitter);
2756
+ emitter.close = async () => {
2757
+ await this.close();
2758
+ originClose();
2759
+ };
2633
2760
  this.stopWorkers = stopWorkers;
2634
2761
  }
2635
2762
  async close() {
2763
+ if (this.closed) return;
2636
2764
  this.closed = true;
2637
- await this.stopWorkers?.();
2765
+ for (const stop of this.stopWorkers) await stop?.();
2638
2766
  await this.inner.close();
2639
- this.controller.abort();
2640
2767
  }
2641
- on(event, listener) {
2642
- const listeners = this.listeners.get(event);
2643
- if (listeners) listeners.push(listener);
2644
- else this.listeners.set(event, [listener]);
2645
- return this;
2646
- }
2647
- watch() {
2648
- const timer = setInterval(
2649
- () => {},
2650
- 1e9
2651
- /* Low power usage */
2652
- );
2653
- this.controller.signal.addEventListener("abort", () => {
2654
- clearInterval(timer);
2655
- });
2656
- process.nextTick(() => this.inner.start(async (event) => {
2657
- const listeners = this.listeners.get(event.eventKind());
2658
- if (listeners) switch (event.eventKind()) {
2659
- case "close":
2660
- case "restart":
2661
- for (const listener of listeners) await listener();
2662
- break;
2663
- case "event":
2664
- for (const listener of listeners) {
2665
- const code = event.bundleEventKind();
2666
- switch (code) {
2667
- case "BUNDLE_END":
2668
- const { duration, output } = event.bundleEndData();
2669
- await listener({
2670
- code: "BUNDLE_END",
2671
- duration,
2672
- output: [output]
2673
- });
2674
- break;
2675
- case "ERROR":
2676
- const errors = event.errors();
2677
- await listener({
2678
- code: "ERROR",
2679
- error: normalizeErrors(errors)
2680
- });
2681
- break;
2682
- default:
2683
- await listener({ code });
2684
- break;
2685
- }
2686
- }
2687
- break;
2688
- case "change":
2689
- for (const listener of listeners) {
2690
- const { path: path$2, kind } = event.watchChangeData();
2691
- await listener(path$2, { event: kind });
2692
- }
2693
- break;
2694
- default: throw new Error(`Unknown event: ${event}`);
2695
- }
2696
- }));
2768
+ start() {
2769
+ process.nextTick(() => this.inner.start(this.emitter.onEvent.bind(this.emitter)));
2697
2770
  }
2698
2771
  };
2772
+ async function createWatcher(emitter, input) {
2773
+ const options = Array.isArray(input) ? input : [input];
2774
+ const bundlerOptions = await Promise.all(options.map((option) => createBundlerOptions(option, option.output || {})));
2775
+ const notifyOptions = getValidNotifyOption(bundlerOptions);
2776
+ const bindingWatcher = new import_binding.BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions);
2777
+ const watcher = new Watcher(emitter, bindingWatcher, bundlerOptions.map((option) => option.stopWorkers));
2778
+ watcher.start();
2779
+ }
2780
+ function getValidNotifyOption(bundlerOptions) {
2781
+ let result;
2782
+ for (const option of bundlerOptions) if (option.inputOptions.watch) {
2783
+ const notifyOption = option.inputOptions.watch.notify;
2784
+ if (notifyOption) if (result) {
2785
+ option.onLog(LOG_LEVEL_WARN, logMultiplyNotifyOption());
2786
+ return result;
2787
+ } else result = notifyOption;
2788
+ }
2789
+ }
2699
2790
 
2700
2791
  //#endregion
2701
- //#region src/rolldown.ts
2702
- const rolldown = async (input) => {
2703
- return new RolldownBuild(input);
2704
- };
2705
- const watch = async (input) => {
2706
- const { bundler, stopWorkers } = await createBundler(input, input.output || {});
2707
- const bindingWatcher = await bundler.watch();
2708
- const watcher = new Watcher(bindingWatcher, stopWorkers);
2709
- watcher.watch();
2710
- return watcher;
2711
- };
2712
- const experimental_scan = async (input) => {
2713
- const { bundler, stopWorkers } = await createBundler(input, {});
2714
- const output = await bundler.scan();
2715
- handleOutputErrors(output);
2716
- await stopWorkers?.();
2792
+ //#region src/api/watch/index.ts
2793
+ const watch = (input) => {
2794
+ const emitter = new WatcherEmitter();
2795
+ createWatcher(emitter, input);
2796
+ return emitter;
2717
2797
  };
2718
2798
 
2719
2799
  //#endregion
2720
2800
  //#region package.json
2721
- var version = "0.14.0";
2801
+ var version = "0.15.0-commit.ac58858";
2722
2802
  var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
2723
2803
 
2804
+ //#endregion
2805
+ //#region src/api/build.ts
2806
+ async function build(options) {
2807
+ if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
2808
+ else {
2809
+ const { output, write = true,...inputOptions } = options;
2810
+ const build$1 = await rolldown(inputOptions);
2811
+ try {
2812
+ if (write) return await build$1.write(output);
2813
+ else return await build$1.generate(output);
2814
+ } finally {
2815
+ await build$1.close();
2816
+ }
2817
+ }
2818
+ }
2819
+
2724
2820
  //#endregion
2725
2821
  //#region src/index.ts
2726
2822
  const VERSION = version;
@@ -2781,6 +2877,11 @@ Object.defineProperty(exports, 'BuiltinPlugin', {
2781
2877
  get: function () {
2782
2878
  return bindingifyPlugin;
2783
2879
  }
2880
+ });Object.defineProperty(exports, 'build', {
2881
+ enumerable: true,
2882
+ get: function () {
2883
+ return build;
2884
+ }
2784
2885
  });Object.defineProperty(exports, 'buildImportAnalysisPlugin', {
2785
2886
  enumerable: true,
2786
2887
  get: function () {
@@ -2791,6 +2892,11 @@ Object.defineProperty(exports, 'BuiltinPlugin', {
2791
2892
  get: function () {
2792
2893
  return composeJsPlugins;
2793
2894
  }
2895
+ });Object.defineProperty(exports, 'createBundler', {
2896
+ enumerable: true,
2897
+ get: function () {
2898
+ return createBundler;
2899
+ }
2794
2900
  });Object.defineProperty(exports, 'defineConfig', {
2795
2901
  enumerable: true,
2796
2902
  get: function () {
@@ -2806,10 +2912,10 @@ Object.defineProperty(exports, 'BuiltinPlugin', {
2806
2912
  get: function () {
2807
2913
  return dynamicImportVarsPlugin;
2808
2914
  }
2809
- });Object.defineProperty(exports, 'experimental_scan', {
2915
+ });Object.defineProperty(exports, 'handleOutputErrors', {
2810
2916
  enumerable: true,
2811
2917
  get: function () {
2812
- return experimental_scan;
2918
+ return handleOutputErrors;
2813
2919
  }
2814
2920
  });Object.defineProperty(exports, 'importGlobPlugin', {
2815
2921
  enumerable: true,