rolldown 0.15.0-snapshot-5e456b6-20241203003703 → 0.15.0-snapshot-993c4a1-20241205003858

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.
package/dist/esm/cli.mjs CHANGED
@@ -1,140 +1,13 @@
1
- import { LogLevelOptionSchema, LogLevelSchema, LogLevelWithErrorSchema, RollupLogSchema, RollupLogWithStringSchema, TreeshakingOptionsSchema, __export, arraify, description, rolldown, version, watch } from "../shared/src-DEPa5yhI.mjs";
2
- import { createConsola } from "../shared/consola_36c0034f-DWsVjwtA.mjs";
1
+ import { LogLevelOptionSchema, LogLevelSchema, LogLevelWithErrorSchema, RollupLogSchema, RollupLogWithStringSchema, TreeshakingOptionsSchema, __export, arraify, description, rolldown, version, watch } from "../shared/src-qgo__dKA.mjs";
2
+ import { createConsola } from "../shared/consola_36c0034f--bn5jvdH.mjs";
3
3
  import { ZodFirstPartyTypeKind, ZodFirstPartyTypeKind as ZodFirstPartyTypeKind$1, ZodFirstPartyTypeKind as ZodFirstPartyTypeKind$2, z, z as z$1, z as z$2, z as z$3 } from "zod";
4
4
  import nodePath, { default as path } from "node:path";
5
5
  import process$1, { env } from "node:process";
6
6
  import { performance } from "node:perf_hooks";
7
+ import * as tty from "tty";
7
8
  import { pathToFileURL } from "node:url";
8
9
  import { parseArgs } from "node:util";
9
- import * as tty from "tty";
10
-
11
- //#region src/cli/utils.ts
12
- const logger = process.env.ROLLDOWN_TEST ? createTestingLogger() : createConsola({ formatOptions: { date: false } });
13
- function createTestingLogger() {
14
- const types = [
15
- "silent",
16
- "fatal",
17
- "error",
18
- "warn",
19
- "log",
20
- "info",
21
- "success",
22
- "fail",
23
- "ready",
24
- "start",
25
- "box",
26
- "debug",
27
- "trace",
28
- "verbose"
29
- ];
30
- const ret = Object.create(null);
31
- for (const type of types) ret[type] = console.log;
32
- return ret;
33
- }
34
- async function ensureConfig(configPath) {
35
- const fileUrl = pathToFileURL(configPath).toString();
36
- let configExports;
37
- try {
38
- configExports = await import(fileUrl);
39
- } catch (err) {
40
- let errorMessage = "Error happened while loading config.";
41
- if (!isSupportedFormat(configPath)) errorMessage += ` Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${nodePath.extname(configPath)}\``;
42
- throw new Error(errorMessage, { cause: err });
43
- }
44
- return configExports.default;
45
- }
46
- const SUPPORTED_CONFIG_FORMATS = [
47
- ".js",
48
- ".mjs",
49
- ".cjs"
50
- ];
51
- /**
52
- * Check whether the configuration file is supported
53
- */
54
- function isSupportedFormat(configPath) {
55
- const ext = nodePath.extname(configPath);
56
- return SUPPORTED_CONFIG_FORMATS.includes(ext);
57
- }
58
-
59
- //#endregion
60
- //#region ../../node_modules/.pnpm/colorette@2.0.20/node_modules/colorette/index.js
61
- const { env: env$1 = {}, argv = [], platform = "" } = typeof process === "undefined" ? {} : process;
62
- const isDisabled = "NO_COLOR" in env$1 || argv.includes("--no-color");
63
- const isForced = "FORCE_COLOR" in env$1 || argv.includes("--color");
64
- const isWindows = platform === "win32";
65
- const isDumbTerminal = env$1.TERM === "dumb";
66
- const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env$1.TERM && !isDumbTerminal;
67
- const isCI = "CI" in env$1 && ("GITHUB_ACTIONS" in env$1 || "GITLAB_CI" in env$1 || "CIRCLECI" in env$1);
68
- const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
69
- const replaceClose = (index, string, close, replace, head = string.substring(0, index) + replace, tail = string.substring(index + close.length), next = tail.indexOf(close)) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
70
- const clearBleed = (index, string, open, close, replace) => index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
71
- const filterEmpty = (open, close, replace = open, at = open.length + 1) => (string) => string || !(string === "" || string === undefined) ? clearBleed(("" + string).indexOf(close, at), string, open, close, replace) : "";
72
- const init = (open, close, replace) => filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`, replace);
73
- const colors = {
74
- reset: init(0, 0),
75
- bold: init(1, 22, "\x1B[22m\x1B[1m"),
76
- dim: init(2, 22, "\x1B[22m\x1B[2m"),
77
- italic: init(3, 23),
78
- underline: init(4, 24),
79
- inverse: init(7, 27),
80
- hidden: init(8, 28),
81
- strikethrough: init(9, 29),
82
- black: init(30, 39),
83
- red: init(31, 39),
84
- green: init(32, 39),
85
- yellow: init(33, 39),
86
- blue: init(34, 39),
87
- magenta: init(35, 39),
88
- cyan: init(36, 39),
89
- white: init(37, 39),
90
- gray: init(90, 39),
91
- bgBlack: init(40, 49),
92
- bgRed: init(41, 49),
93
- bgGreen: init(42, 49),
94
- bgYellow: init(43, 49),
95
- bgBlue: init(44, 49),
96
- bgMagenta: init(45, 49),
97
- bgCyan: init(46, 49),
98
- bgWhite: init(47, 49),
99
- blackBright: init(90, 39),
100
- redBright: init(91, 39),
101
- greenBright: init(92, 39),
102
- yellowBright: init(93, 39),
103
- blueBright: init(94, 39),
104
- magentaBright: init(95, 39),
105
- cyanBright: init(96, 39),
106
- whiteBright: init(97, 39),
107
- bgBlackBright: init(100, 49),
108
- bgRedBright: init(101, 49),
109
- bgGreenBright: init(102, 49),
110
- bgYellowBright: init(103, 49),
111
- bgBlueBright: init(104, 49),
112
- bgMagentaBright: init(105, 49),
113
- bgCyanBright: init(106, 49),
114
- bgWhiteBright: init(107, 49)
115
- };
116
- const createColors = ({ useColor = isColorSupported } = {}) => useColor ? colors : Object.keys(colors).reduce((colors$1, key) => ({
117
- ...colors$1,
118
- [key]: String
119
- }), {});
120
- const { reset, bold: bold$1, dim: dim$1, italic, underline: underline$1, inverse, hidden, strikethrough, black, red: red$1, green: green$1, yellow: yellow$1, blue, magenta, cyan: cyan$1, white, gray: gray$1, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, blackBright, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright, bgBlackBright, bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright } = createColors();
121
-
122
- //#endregion
123
- //#region src/cli/colors.ts
124
- var colors_exports = {};
125
- __export(colors_exports, {
126
- bold: () => bold,
127
- cyan: () => cyan,
128
- dim: () => dim,
129
- gray: () => gray,
130
- green: () => green,
131
- red: () => red,
132
- underline: () => underline,
133
- yellow: () => yellow
134
- });
135
- const { bold, cyan, dim, gray, green, red, underline, yellow } = createColors({ useColor: env.FORCE_COLOR !== "0" && !env.NO_COLOR });
136
10
 
137
- //#endregion
138
11
  //#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.js
139
12
  const signals = [];
140
13
  signals.push("SIGHUP", "SIGINT", "SIGTERM");
@@ -306,6 +179,133 @@ var SignalExit = class extends SignalExitBase {
306
179
  const process$2 = globalThis.process;
307
180
  const { onExit, load, unload } = signalExitWrap(processOk(process$2) ? new SignalExit(process$2) : new SignalExitFallback());
308
181
 
182
+ //#endregion
183
+ //#region ../../node_modules/.pnpm/colorette@2.0.20/node_modules/colorette/index.js
184
+ const { env: env$1 = {}, argv = [], platform = "" } = typeof process === "undefined" ? {} : process;
185
+ const isDisabled = "NO_COLOR" in env$1 || argv.includes("--no-color");
186
+ const isForced = "FORCE_COLOR" in env$1 || argv.includes("--color");
187
+ const isWindows = platform === "win32";
188
+ const isDumbTerminal = env$1.TERM === "dumb";
189
+ const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env$1.TERM && !isDumbTerminal;
190
+ const isCI = "CI" in env$1 && ("GITHUB_ACTIONS" in env$1 || "GITLAB_CI" in env$1 || "CIRCLECI" in env$1);
191
+ const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
192
+ const replaceClose = (index, string, close, replace, head = string.substring(0, index) + replace, tail = string.substring(index + close.length), next = tail.indexOf(close)) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
193
+ const clearBleed = (index, string, open, close, replace) => index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
194
+ const filterEmpty = (open, close, replace = open, at = open.length + 1) => (string) => string || !(string === "" || string === undefined) ? clearBleed(("" + string).indexOf(close, at), string, open, close, replace) : "";
195
+ const init = (open, close, replace) => filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`, replace);
196
+ const colors = {
197
+ reset: init(0, 0),
198
+ bold: init(1, 22, "\x1B[22m\x1B[1m"),
199
+ dim: init(2, 22, "\x1B[22m\x1B[2m"),
200
+ italic: init(3, 23),
201
+ underline: init(4, 24),
202
+ inverse: init(7, 27),
203
+ hidden: init(8, 28),
204
+ strikethrough: init(9, 29),
205
+ black: init(30, 39),
206
+ red: init(31, 39),
207
+ green: init(32, 39),
208
+ yellow: init(33, 39),
209
+ blue: init(34, 39),
210
+ magenta: init(35, 39),
211
+ cyan: init(36, 39),
212
+ white: init(37, 39),
213
+ gray: init(90, 39),
214
+ bgBlack: init(40, 49),
215
+ bgRed: init(41, 49),
216
+ bgGreen: init(42, 49),
217
+ bgYellow: init(43, 49),
218
+ bgBlue: init(44, 49),
219
+ bgMagenta: init(45, 49),
220
+ bgCyan: init(46, 49),
221
+ bgWhite: init(47, 49),
222
+ blackBright: init(90, 39),
223
+ redBright: init(91, 39),
224
+ greenBright: init(92, 39),
225
+ yellowBright: init(93, 39),
226
+ blueBright: init(94, 39),
227
+ magentaBright: init(95, 39),
228
+ cyanBright: init(96, 39),
229
+ whiteBright: init(97, 39),
230
+ bgBlackBright: init(100, 49),
231
+ bgRedBright: init(101, 49),
232
+ bgGreenBright: init(102, 49),
233
+ bgYellowBright: init(103, 49),
234
+ bgBlueBright: init(104, 49),
235
+ bgMagentaBright: init(105, 49),
236
+ bgCyanBright: init(106, 49),
237
+ bgWhiteBright: init(107, 49)
238
+ };
239
+ const createColors = ({ useColor = isColorSupported } = {}) => useColor ? colors : Object.keys(colors).reduce((colors$1, key) => ({
240
+ ...colors$1,
241
+ [key]: String
242
+ }), {});
243
+ const { reset, bold: bold$1, dim: dim$1, italic, underline: underline$1, inverse, hidden, strikethrough, black, red: red$1, green: green$1, yellow: yellow$1, blue, magenta, cyan: cyan$1, white, gray: gray$1, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, blackBright, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright, bgBlackBright, bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright } = createColors();
244
+
245
+ //#endregion
246
+ //#region src/cli/colors.ts
247
+ var colors_exports = {};
248
+ __export(colors_exports, {
249
+ bold: () => bold,
250
+ cyan: () => cyan,
251
+ dim: () => dim,
252
+ gray: () => gray,
253
+ green: () => green,
254
+ red: () => red,
255
+ underline: () => underline,
256
+ yellow: () => yellow
257
+ });
258
+ const { bold, cyan, dim, gray, green, red, underline, yellow } = createColors({ useColor: env.FORCE_COLOR !== "0" && !env.NO_COLOR });
259
+
260
+ //#endregion
261
+ //#region src/cli/utils.ts
262
+ const logger = process.env.ROLLDOWN_TEST ? createTestingLogger() : createConsola({ formatOptions: { date: false } });
263
+ function createTestingLogger() {
264
+ const types = [
265
+ "silent",
266
+ "fatal",
267
+ "error",
268
+ "warn",
269
+ "log",
270
+ "info",
271
+ "success",
272
+ "fail",
273
+ "ready",
274
+ "start",
275
+ "box",
276
+ "debug",
277
+ "trace",
278
+ "verbose"
279
+ ];
280
+ const ret = Object.create(null);
281
+ for (const type of types) ret[type] = console.log;
282
+ return ret;
283
+ }
284
+ async function ensureConfig(configPath) {
285
+ const fileUrl = pathToFileURL(configPath).toString();
286
+ let configExports;
287
+ try {
288
+ configExports = await import(fileUrl);
289
+ } catch (err) {
290
+ let errorMessage = "Error happened while loading config.";
291
+ if (!isSupportedFormat(configPath)) errorMessage += ` Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${nodePath.extname(configPath)}\``;
292
+ throw new Error(errorMessage, { cause: err });
293
+ }
294
+ return configExports.default;
295
+ }
296
+ const SUPPORTED_CONFIG_FORMATS = [
297
+ ".js",
298
+ ".mjs",
299
+ ".cjs"
300
+ ];
301
+ /**
302
+ * Check whether the configuration file is supported
303
+ */
304
+ function isSupportedFormat(configPath) {
305
+ const ext = nodePath.extname(configPath);
306
+ return SUPPORTED_CONFIG_FORMATS.includes(ext);
307
+ }
308
+
309
309
  //#endregion
310
310
  //#region src/cli/commands/bundle.ts
311
311
  async function bundleWithConfig(configPath, cliOptions) {
@@ -315,24 +315,33 @@ async function bundleWithConfig(configPath, cliOptions) {
315
315
  process.exit(1);
316
316
  }
317
317
  const configList = arraify(config);
318
- for (const config$1 of configList) cliOptions.watch ? await watchInner(config$1, cliOptions) : bundleInner(config$1, cliOptions);
318
+ const operation = cliOptions.watch ? watchInner : bundleInner;
319
+ for (const config$1 of configList) await operation(config$1, cliOptions);
319
320
  }
320
321
  async function bundleWithCliOptions(cliOptions) {
321
- if (cliOptions.output.dir) cliOptions.watch ? await watchInner({}, cliOptions) : await bundleInner({}, cliOptions);
322
- else if (!cliOptions.watch) {
323
- const build = await rolldown(cliOptions.input);
324
- const { output } = await build.generate(cliOptions.output);
325
- if (output.length > 1) {
326
- logger.error("Multiple chunks are not supported to display in stdout");
327
- process.exit(1);
328
- } else if (output.length === 0) {
329
- logger.error("No output generated");
330
- process.exit(1);
331
- } else logger.log(output[0].code);
332
- } else {
322
+ if (cliOptions.output.dir) {
323
+ const operation = cliOptions.watch ? watchInner : bundleInner;
324
+ await operation({}, cliOptions);
325
+ return;
326
+ }
327
+ if (cliOptions.watch) {
333
328
  logger.error("You must specify `output.dir` to use watch mode");
334
329
  process.exit(1);
335
330
  }
331
+ const build = await rolldown(cliOptions.input);
332
+ try {
333
+ const { output: outputs } = await build.generate(cliOptions.output);
334
+ if (outputs.length === 0) {
335
+ logger.error("No output generated");
336
+ process.exit(1);
337
+ }
338
+ for (const file of outputs) {
339
+ if (outputs.length > 1) logger.log(`\n${cyan(bold(`|→ ${file.fileName}:`))}\n`);
340
+ logger.log(file.type === "asset" ? file.source : file.code);
341
+ }
342
+ } finally {
343
+ await build.close();
344
+ }
336
345
  }
337
346
  async function watchInner(options$1, cliOptions) {
338
347
  const watcher = await watch({
@@ -372,15 +381,19 @@ async function bundleInner(options$1, cliOptions) {
372
381
  ...options$1,
373
382
  ...cliOptions.input
374
383
  });
375
- const bundleOutput = await build.write({
376
- ...options$1?.output,
377
- ...cliOptions.output
378
- });
379
- const endTime = performance.now();
380
- printBundleOutputPretty(bundleOutput);
381
- logger.log(``);
382
- const duration = endTime - startTime;
383
- logger.success(`Finished in ${bold(ms(duration))}`);
384
+ try {
385
+ const bundleOutput = await build.write({
386
+ ...options$1?.output,
387
+ ...cliOptions.output
388
+ });
389
+ const endTime = performance.now();
390
+ printBundleOutputPretty(bundleOutput);
391
+ logger.log(``);
392
+ const duration = endTime - startTime;
393
+ logger.success(`Finished in ${bold(ms(duration))}`);
394
+ } finally {
395
+ await build.close();
396
+ }
384
397
  }
385
398
  function printBundleOutputPretty(output) {
386
399
  const outputEntries = collectOutputEntries(output.output);
@@ -1,4 +1,4 @@
1
- import { BuiltinPlugin, __toESM, buildImportAnalysisPlugin, composeJsPlugins, createBundler, dynamicImportVarsPlugin, handleOutputErrors, importGlobPlugin, jsonPlugin, loadFallbackPlugin, manifestPlugin, modulePreloadPolyfillPlugin, normalizedStringOrRegex, require_binding, viteResolvePlugin, wasmFallbackPlugin, wasmHelperPlugin } from "../shared/src-DEPa5yhI.mjs";
1
+ import { BuiltinPlugin, __toESM, buildImportAnalysisPlugin, composeJsPlugins, createBundler, dynamicImportVarsPlugin, handleOutputErrors, importGlobPlugin, jsonPlugin, loadFallbackPlugin, manifestPlugin, modulePreloadPolyfillPlugin, normalizedStringOrRegex, require_binding, viteResolvePlugin, wasmFallbackPlugin, wasmHelperPlugin } from "../shared/src-qgo__dKA.mjs";
2
2
  import { pathToFileURL } from "node:url";
3
3
 
4
4
  //#region src/plugin/parallel-plugin.ts
@@ -1,3 +1,3 @@
1
- import { VERSION, build, defineConfig, rolldown, watch } from "../shared/src-DEPa5yhI.mjs";
1
+ import { VERSION, build, defineConfig, rolldown, watch } from "../shared/src-qgo__dKA.mjs";
2
2
 
3
3
  export { VERSION, build, defineConfig, rolldown, watch };
@@ -1,4 +1,4 @@
1
- import { PluginContextData, __toESM, bindingifyPlugin, require_binding } from "../shared/src-DEPa5yhI.mjs";
1
+ import { PluginContextData, __toESM, bindingifyPlugin, require_binding } from "../shared/src-qgo__dKA.mjs";
2
2
  import { parentPort, workerData } from "node:worker_threads";
3
3
 
4
4
  //#region src/parallel-plugin-worker.ts
@@ -815,7 +815,7 @@ function createConsola(options = {}) {
815
815
  defaults: { level },
816
816
  stdout: process.stdout,
817
817
  stderr: process.stderr,
818
- prompt: (...args) => import("./prompt-DGW8ZJmn.mjs").then((m) => m.prompt(...args)),
818
+ prompt: (...args) => import("./prompt-DHyJur3_.mjs").then((m) => m.prompt(...args)),
819
819
  reporters: options.reporters || [options.fancy ?? !(isCI || isTest) ? new FancyReporter() : new BasicReporter()],
820
820
  ...options
821
821
  });
@@ -818,7 +818,7 @@ function createConsola(options = {}) {
818
818
  stdout: process.stdout,
819
819
  stderr: process.stderr,
820
820
  prompt: (...args) => Promise.resolve().then(function() {
821
- return require("./prompt-RFvZMmjc.cjs");
821
+ return require("./prompt-DkiZzbTg.cjs");
822
822
  }).then((m) => m.prompt(...args)),
823
823
  reporters: options.reporters || [options.fancy ?? !(isCI || isTest) ? new FancyReporter() : new BasicReporter()],
824
824
  ...options
@@ -1,7 +1,7 @@
1
- import { colors, getDefaultExportFromCjs, isUnicodeSupported } from "./consola_36c0034f-DWsVjwtA.mjs";
1
+ import { colors, getDefaultExportFromCjs, isUnicodeSupported } from "./consola_36c0034f--bn5jvdH.mjs";
2
2
  import { stdin, stdout } from "node:process";
3
- import { WriteStream } from "node:tty";
4
3
  import require$$0 from "tty";
4
+ import { WriteStream } from "node:tty";
5
5
  import f from "node:readline";
6
6
 
7
7
  //#region ../../node_modules/.pnpm/consola@3.2.3/node_modules/consola/dist/chunks/prompt.mjs
@@ -3,9 +3,9 @@ const require_chunk = require('./chunk-BK2Ye-xa.cjs');
3
3
  const require_consola_36c0034f = require('./consola_36c0034f-_8_dG1Nr.cjs');
4
4
  const node_path = require_chunk.__toESM(require("node:path"));
5
5
  const node_process = require_chunk.__toESM(require("node:process"));
6
+ const tty = require_chunk.__toESM(require("tty"));
6
7
  const node_util = require_chunk.__toESM(require("node:util"));
7
8
  const node_tty = require_chunk.__toESM(require("node:tty"));
8
- const tty = require_chunk.__toESM(require("tty"));
9
9
  const node_readline = require_chunk.__toESM(require("node:readline"));
10
10
 
11
11
  //#region ../../node_modules/.pnpm/consola@3.2.3/node_modules/consola/dist/chunks/prompt.mjs
@@ -155,10 +155,12 @@ function transformToRollupOutputAsset(bindingAsset, changed) {
155
155
  type: "asset",
156
156
  fileName: bindingAsset.fileName,
157
157
  originalFileName: bindingAsset.originalFileName || null,
158
+ originalFileNames: bindingAsset.originalFileNames,
158
159
  get source() {
159
160
  return transformAssetSource(bindingAsset.source);
160
161
  },
161
- name: bindingAsset.name ?? undefined
162
+ name: bindingAsset.name ?? undefined,
163
+ names: bindingAsset.names
162
164
  };
163
165
  const cache = {};
164
166
  return new Proxy(asset, {
@@ -197,9 +199,9 @@ function collectChangedBundle(changed, bundle) {
197
199
  const item = bundle[key];
198
200
  if (item.type === "asset") assets.push({
199
201
  filename: item.fileName,
200
- originalFileName: item.originalFileName || undefined,
202
+ originalFileNames: item.originalFileNames,
201
203
  source: bindingAssetSource(item.source),
202
- name: item.name
204
+ names: item.names
203
205
  });
204
206
  else chunks.push({
205
207
  code: item.code,
@@ -1084,7 +1086,7 @@ const ModuleSideEffectsRuleSchema = zod.z.object({
1084
1086
  }).refine((data) => {
1085
1087
  return data.test !== undefined || data.external !== undefined;
1086
1088
  }, "Either `test` or `external` should be set.");
1087
- const ModuleSideEffectsOptionSchema = zod.z.boolean().or(zod.z.array(ModuleSideEffectsRuleSchema)).or(zod.z.literal("no-external"));
1089
+ 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"));
1088
1090
  const TreeshakingOptionsSchema = zod.z.object({
1089
1091
  moduleSideEffects: ModuleSideEffectsOptionSchema.optional(),
1090
1092
  annotations: zod.z.boolean().optional()
@@ -1964,7 +1966,8 @@ function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, onLog,
1964
1966
  profilerNames: inputOptions?.profilerNames,
1965
1967
  jsx: bindingifyJsx(inputOptions.jsx),
1966
1968
  watch: bindingifyWatch(inputOptions.watch),
1967
- dropLabels: inputOptions.dropLabels
1969
+ dropLabels: inputOptions.dropLabels,
1970
+ keepNames: inputOptions.keepNames
1968
1971
  };
1969
1972
  }
1970
1973
  function bindingifyExternal(external) {
@@ -2625,93 +2628,111 @@ const rolldown = async (input) => {
2625
2628
  return new RolldownBuild(input);
2626
2629
  };
2627
2630
 
2631
+ //#endregion
2632
+ //#region src/api/watch/watch-emitter.ts
2633
+ var WatcherEmitter = class {
2634
+ listeners = new Map();
2635
+ timer;
2636
+ constructor() {
2637
+ this.timer = setInterval(
2638
+ () => {},
2639
+ 1e9
2640
+ /* Low power usage */
2641
+ );
2642
+ }
2643
+ on(event, listener) {
2644
+ const listeners = this.listeners.get(event);
2645
+ if (listeners) listeners.push(listener);
2646
+ else this.listeners.set(event, [listener]);
2647
+ return this;
2648
+ }
2649
+ async onEvent(event) {
2650
+ const listeners = this.listeners.get(event.eventKind());
2651
+ if (listeners) switch (event.eventKind()) {
2652
+ case "close":
2653
+ case "restart":
2654
+ for (const listener of listeners) await listener();
2655
+ break;
2656
+ case "event":
2657
+ for (const listener of listeners) {
2658
+ const code = event.bundleEventKind();
2659
+ switch (code) {
2660
+ case "BUNDLE_END":
2661
+ const { duration, output } = event.bundleEndData();
2662
+ await listener({
2663
+ code: "BUNDLE_END",
2664
+ duration,
2665
+ output: [output]
2666
+ });
2667
+ break;
2668
+ case "ERROR":
2669
+ const errors = event.errors();
2670
+ await listener({
2671
+ code: "ERROR",
2672
+ error: normalizeErrors(errors)
2673
+ });
2674
+ break;
2675
+ default:
2676
+ await listener({ code });
2677
+ break;
2678
+ }
2679
+ }
2680
+ break;
2681
+ case "change":
2682
+ for (const listener of listeners) {
2683
+ const { path: path$2, kind } = event.watchChangeData();
2684
+ await listener(path$2, { event: kind });
2685
+ }
2686
+ break;
2687
+ default: throw new Error(`Unknown event: ${event}`);
2688
+ }
2689
+ }
2690
+ async close() {
2691
+ clearInterval(this.timer);
2692
+ }
2693
+ };
2694
+
2628
2695
  //#endregion
2629
2696
  //#region src/api/watch/watcher.ts
2630
2697
  var Watcher = class {
2631
2698
  closed;
2632
- controller;
2633
2699
  inner;
2700
+ emitter;
2634
2701
  stopWorkers;
2635
- listeners = new Map();
2636
- constructor(inner, stopWorkers) {
2702
+ constructor(emitter, inner, stopWorkers) {
2637
2703
  this.closed = false;
2638
- this.controller = new AbortController();
2639
2704
  this.inner = inner;
2705
+ this.emitter = emitter;
2706
+ const originClose = emitter.close.bind(emitter);
2707
+ emitter.close = async () => {
2708
+ await this.close();
2709
+ originClose();
2710
+ };
2640
2711
  this.stopWorkers = stopWorkers;
2641
2712
  }
2642
2713
  async close() {
2714
+ if (this.closed) return;
2643
2715
  this.closed = true;
2644
2716
  await this.stopWorkers?.();
2645
2717
  await this.inner.close();
2646
- this.controller.abort();
2647
- }
2648
- on(event, listener) {
2649
- const listeners = this.listeners.get(event);
2650
- if (listeners) listeners.push(listener);
2651
- else this.listeners.set(event, [listener]);
2652
- return this;
2653
2718
  }
2654
- watch() {
2655
- const timer = setInterval(
2656
- () => {},
2657
- 1e9
2658
- /* Low power usage */
2659
- );
2660
- this.controller.signal.addEventListener("abort", () => {
2661
- clearInterval(timer);
2662
- });
2663
- process.nextTick(() => this.inner.start(async (event) => {
2664
- const listeners = this.listeners.get(event.eventKind());
2665
- if (listeners) switch (event.eventKind()) {
2666
- case "close":
2667
- case "restart":
2668
- for (const listener of listeners) await listener();
2669
- break;
2670
- case "event":
2671
- for (const listener of listeners) {
2672
- const code = event.bundleEventKind();
2673
- switch (code) {
2674
- case "BUNDLE_END":
2675
- const { duration, output } = event.bundleEndData();
2676
- await listener({
2677
- code: "BUNDLE_END",
2678
- duration,
2679
- output: [output]
2680
- });
2681
- break;
2682
- case "ERROR":
2683
- const errors = event.errors();
2684
- await listener({
2685
- code: "ERROR",
2686
- error: normalizeErrors(errors)
2687
- });
2688
- break;
2689
- default:
2690
- await listener({ code });
2691
- break;
2692
- }
2693
- }
2694
- break;
2695
- case "change":
2696
- for (const listener of listeners) {
2697
- const { path: path$2, kind } = event.watchChangeData();
2698
- await listener(path$2, { event: kind });
2699
- }
2700
- break;
2701
- default: throw new Error(`Unknown event: ${event}`);
2702
- }
2703
- }));
2719
+ start() {
2720
+ process.nextTick(() => this.inner.start(this.emitter.onEvent.bind(this.emitter)));
2704
2721
  }
2705
2722
  };
2723
+ async function createWatcher(emitter, input) {
2724
+ const { bundler, stopWorkers } = await createBundler(input, input.output || {});
2725
+ const bindingWatcher = await bundler.watch();
2726
+ const watcher = new Watcher(emitter, bindingWatcher, stopWorkers);
2727
+ watcher.start();
2728
+ }
2706
2729
 
2707
2730
  //#endregion
2708
2731
  //#region src/api/watch/index.ts
2709
- const watch = async (input) => {
2710
- const { bundler, stopWorkers } = await createBundler(input, input.output || {});
2711
- const bindingWatcher = await bundler.watch();
2712
- const watcher = new Watcher(bindingWatcher, stopWorkers);
2713
- watcher.watch();
2714
- return watcher;
2732
+ const watch = (input) => {
2733
+ const emitter = new WatcherEmitter();
2734
+ createWatcher(emitter, input);
2735
+ return emitter;
2715
2736
  };
2716
2737
 
2717
2738
  //#endregion
@@ -2724,10 +2745,14 @@ var description = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compat
2724
2745
  async function build(options) {
2725
2746
  if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
2726
2747
  else {
2727
- const { output,...inputOptions } = options;
2748
+ const { output, write = true,...inputOptions } = options;
2728
2749
  const build$1 = await rolldown(inputOptions);
2729
- if (options.write) return build$1.write(output);
2730
- else return build$1.generate(output);
2750
+ try {
2751
+ if (write) return await build$1.write(output);
2752
+ else return await build$1.generate(output);
2753
+ } finally {
2754
+ await build$1.close();
2755
+ }
2731
2756
  }
2732
2757
  }
2733
2758