@rollipop/rolldown 0.0.0-beta.0

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 (44) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +11 -0
  3. package/bin/cli.mjs +3 -0
  4. package/dist/cli-setup.d.mts +1 -0
  5. package/dist/cli-setup.mjs +17 -0
  6. package/dist/cli.d.mts +1 -0
  7. package/dist/cli.mjs +1581 -0
  8. package/dist/config.d.mts +10 -0
  9. package/dist/config.mjs +14 -0
  10. package/dist/experimental-index.d.mts +239 -0
  11. package/dist/experimental-index.mjs +299 -0
  12. package/dist/experimental-runtime-types.d.ts +92 -0
  13. package/dist/filter-index.d.mts +4 -0
  14. package/dist/filter-index.mjs +369 -0
  15. package/dist/get-log-filter.d.mts +7 -0
  16. package/dist/get-log-filter.mjs +48 -0
  17. package/dist/index.d.mts +4 -0
  18. package/dist/index.mjs +38 -0
  19. package/dist/parallel-plugin-worker.d.mts +1 -0
  20. package/dist/parallel-plugin-worker.mjs +32 -0
  21. package/dist/parallel-plugin.d.mts +14 -0
  22. package/dist/parallel-plugin.mjs +7 -0
  23. package/dist/parse-ast-index.d.mts +8 -0
  24. package/dist/parse-ast-index.mjs +4 -0
  25. package/dist/plugins-index.d.mts +31 -0
  26. package/dist/plugins-index.mjs +40 -0
  27. package/dist/shared/binding-DmMMxMk0.mjs +584 -0
  28. package/dist/shared/binding-kAegJ1Bj.d.mts +1775 -0
  29. package/dist/shared/bindingify-input-options-D0BAGfk2.mjs +1622 -0
  30. package/dist/shared/constructors-F44lhsH3.d.mts +30 -0
  31. package/dist/shared/constructors-Rl_oLd2F.mjs +67 -0
  32. package/dist/shared/define-config-BF4P-Pum.mjs +7 -0
  33. package/dist/shared/define-config-DJ1-iIdx.d.mts +2562 -0
  34. package/dist/shared/load-config-BEpugZky.mjs +114 -0
  35. package/dist/shared/logging-DsnCZi19.d.mts +42 -0
  36. package/dist/shared/logs-cyjC0SDv.mjs +183 -0
  37. package/dist/shared/misc-DpjTMcQQ.mjs +22 -0
  38. package/dist/shared/normalize-string-or-regex-DbTZ9prS.mjs +670 -0
  39. package/dist/shared/parse-ast-index-BuuhACPk.mjs +99 -0
  40. package/dist/shared/prompt-5sWCM0jm.mjs +847 -0
  41. package/dist/shared/rolldown-build-viDZfkdI.mjs +2292 -0
  42. package/dist/shared/rolldown-il0-nWH9.mjs +11 -0
  43. package/dist/shared/watch-BSdMzY6q.mjs +352 -0
  44. package/package.json +128 -0
@@ -0,0 +1,2292 @@
1
+ import { n as __toESM, t as require_binding } from "./binding-DmMMxMk0.mjs";
2
+ import { i as logInputHookInOutputPlugin, n as error } from "./logs-cyjC0SDv.mjs";
3
+ import { i as unimplemented } from "./misc-DpjTMcQQ.mjs";
4
+ import { C as LOG_LEVEL_DEBUG, D as logLevelPriority, E as LOG_LEVEL_WARN, S as normalizeLog, T as LOG_LEVEL_INFO, _ as PlainObjectLike, f as transformRenderedChunk, g as lazyProp, h as transformAssetSource, n as BuiltinPlugin, p as __decorate, u as transformToRollupOutput, v as MinimalPluginContextImpl, w as LOG_LEVEL_ERROR, y as VERSION } from "./normalize-string-or-regex-DbTZ9prS.mjs";
5
+ import { c as normalizeHook, i as transformModuleInfo, s as unwrapBindingResult, t as bindingifyInputOptions } from "./bindingify-input-options-D0BAGfk2.mjs";
6
+ import { Worker } from "node:worker_threads";
7
+ import path from "node:path";
8
+ import { styleText } from "node:util";
9
+ import os from "node:os";
10
+
11
+ //#region src/log/logger.ts
12
+ function getLogger(plugins, onLog, logLevel, watchMode) {
13
+ const minimalPriority = logLevelPriority[logLevel];
14
+ const logger = (level, log, skipped = /* @__PURE__ */ new Set()) => {
15
+ if (logLevelPriority[level] < minimalPriority) return;
16
+ for (const plugin of getSortedPlugins("onLog", plugins)) {
17
+ if (skipped.has(plugin)) continue;
18
+ const { onLog: pluginOnLog } = plugin;
19
+ if (pluginOnLog) {
20
+ const getLogHandler = (level$1) => {
21
+ if (logLevelPriority[level$1] < minimalPriority) return () => {};
22
+ return (log$1) => logger(level$1, normalizeLog(log$1), new Set(skipped).add(plugin));
23
+ };
24
+ if (("handler" in pluginOnLog ? pluginOnLog.handler : pluginOnLog).call({
25
+ debug: getLogHandler(LOG_LEVEL_DEBUG),
26
+ error: (log$1) => error(normalizeLog(log$1)),
27
+ info: getLogHandler(LOG_LEVEL_INFO),
28
+ meta: {
29
+ rollupVersion: "4.23.0",
30
+ rolldownVersion: VERSION,
31
+ watchMode
32
+ },
33
+ warn: getLogHandler(LOG_LEVEL_WARN),
34
+ pluginName: plugin.name || "unknown"
35
+ }, level, log) === false) return;
36
+ }
37
+ }
38
+ onLog(level, log);
39
+ };
40
+ return logger;
41
+ }
42
+ const getOnLog = (config, logLevel, printLog = defaultPrintLog) => {
43
+ const { onwarn, onLog } = config;
44
+ const defaultOnLog = getDefaultOnLog(printLog, onwarn);
45
+ if (onLog) {
46
+ const minimalPriority = logLevelPriority[logLevel];
47
+ return (level, log) => onLog(level, addLogToString(log), (level$1, handledLog) => {
48
+ if (level$1 === LOG_LEVEL_ERROR) return error(normalizeLog(handledLog));
49
+ if (logLevelPriority[level$1] >= minimalPriority) defaultOnLog(level$1, normalizeLog(handledLog));
50
+ });
51
+ }
52
+ return defaultOnLog;
53
+ };
54
+ const getDefaultOnLog = (printLog, onwarn) => onwarn ? (level, log) => {
55
+ if (level === LOG_LEVEL_WARN) onwarn(addLogToString(log), (warning) => printLog(LOG_LEVEL_WARN, normalizeLog(warning)));
56
+ else printLog(level, log);
57
+ } : printLog;
58
+ const addLogToString = (log) => {
59
+ Object.defineProperty(log, "toString", {
60
+ value: () => getExtendedLogMessage(log),
61
+ writable: true
62
+ });
63
+ return log;
64
+ };
65
+ const defaultPrintLog = (level, log) => {
66
+ const message = getExtendedLogMessage(log);
67
+ switch (level) {
68
+ case LOG_LEVEL_WARN: return console.warn(message);
69
+ case LOG_LEVEL_DEBUG: return console.debug(message);
70
+ default: return console.info(message);
71
+ }
72
+ };
73
+ const getExtendedLogMessage = (log) => {
74
+ let prefix = "";
75
+ if (log.plugin) prefix += `(${log.plugin} plugin) `;
76
+ if (log.loc) prefix += `${relativeId(log.loc.file)} (${log.loc.line}:${log.loc.column}) `;
77
+ return prefix + log.message;
78
+ };
79
+ function relativeId(id) {
80
+ if (!path.isAbsolute(id)) return id;
81
+ return path.relative(path.resolve(), id);
82
+ }
83
+
84
+ //#endregion
85
+ //#region src/constants/plugin.ts
86
+ const ENUMERATED_INPUT_PLUGIN_HOOK_NAMES = [
87
+ "options",
88
+ "buildStart",
89
+ "resolveId",
90
+ "load",
91
+ "transform",
92
+ "moduleParsed",
93
+ "buildEnd",
94
+ "onLog",
95
+ "resolveDynamicImport",
96
+ "closeBundle",
97
+ "closeWatcher",
98
+ "watchChange"
99
+ ];
100
+ const ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES = [
101
+ "augmentChunkHash",
102
+ "outputOptions",
103
+ "renderChunk",
104
+ "renderStart",
105
+ "renderError",
106
+ "writeBundle",
107
+ "generateBundle"
108
+ ];
109
+ const ENUMERATED_PLUGIN_HOOK_NAMES = [
110
+ ...ENUMERATED_INPUT_PLUGIN_HOOK_NAMES,
111
+ ...ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES,
112
+ "footer",
113
+ "banner",
114
+ "intro",
115
+ "outro"
116
+ ];
117
+ /**
118
+ * Names of all defined hooks. It's like
119
+ * ```js
120
+ * const DEFINED_HOOK_NAMES ={
121
+ * options: 'options',
122
+ * buildStart: 'buildStart',
123
+ * ...
124
+ * }
125
+ * ```
126
+ */
127
+ const DEFINED_HOOK_NAMES = {
128
+ [ENUMERATED_PLUGIN_HOOK_NAMES[0]]: ENUMERATED_PLUGIN_HOOK_NAMES[0],
129
+ [ENUMERATED_PLUGIN_HOOK_NAMES[1]]: ENUMERATED_PLUGIN_HOOK_NAMES[1],
130
+ [ENUMERATED_PLUGIN_HOOK_NAMES[2]]: ENUMERATED_PLUGIN_HOOK_NAMES[2],
131
+ [ENUMERATED_PLUGIN_HOOK_NAMES[3]]: ENUMERATED_PLUGIN_HOOK_NAMES[3],
132
+ [ENUMERATED_PLUGIN_HOOK_NAMES[4]]: ENUMERATED_PLUGIN_HOOK_NAMES[4],
133
+ [ENUMERATED_PLUGIN_HOOK_NAMES[5]]: ENUMERATED_PLUGIN_HOOK_NAMES[5],
134
+ [ENUMERATED_PLUGIN_HOOK_NAMES[6]]: ENUMERATED_PLUGIN_HOOK_NAMES[6],
135
+ [ENUMERATED_PLUGIN_HOOK_NAMES[7]]: ENUMERATED_PLUGIN_HOOK_NAMES[7],
136
+ [ENUMERATED_PLUGIN_HOOK_NAMES[8]]: ENUMERATED_PLUGIN_HOOK_NAMES[8],
137
+ [ENUMERATED_PLUGIN_HOOK_NAMES[9]]: ENUMERATED_PLUGIN_HOOK_NAMES[9],
138
+ [ENUMERATED_PLUGIN_HOOK_NAMES[10]]: ENUMERATED_PLUGIN_HOOK_NAMES[10],
139
+ [ENUMERATED_PLUGIN_HOOK_NAMES[11]]: ENUMERATED_PLUGIN_HOOK_NAMES[11],
140
+ [ENUMERATED_PLUGIN_HOOK_NAMES[12]]: ENUMERATED_PLUGIN_HOOK_NAMES[12],
141
+ [ENUMERATED_PLUGIN_HOOK_NAMES[13]]: ENUMERATED_PLUGIN_HOOK_NAMES[13],
142
+ [ENUMERATED_PLUGIN_HOOK_NAMES[14]]: ENUMERATED_PLUGIN_HOOK_NAMES[14],
143
+ [ENUMERATED_PLUGIN_HOOK_NAMES[15]]: ENUMERATED_PLUGIN_HOOK_NAMES[15],
144
+ [ENUMERATED_PLUGIN_HOOK_NAMES[16]]: ENUMERATED_PLUGIN_HOOK_NAMES[16],
145
+ [ENUMERATED_PLUGIN_HOOK_NAMES[17]]: ENUMERATED_PLUGIN_HOOK_NAMES[17],
146
+ [ENUMERATED_PLUGIN_HOOK_NAMES[18]]: ENUMERATED_PLUGIN_HOOK_NAMES[18],
147
+ [ENUMERATED_PLUGIN_HOOK_NAMES[19]]: ENUMERATED_PLUGIN_HOOK_NAMES[19],
148
+ [ENUMERATED_PLUGIN_HOOK_NAMES[20]]: ENUMERATED_PLUGIN_HOOK_NAMES[20],
149
+ [ENUMERATED_PLUGIN_HOOK_NAMES[21]]: ENUMERATED_PLUGIN_HOOK_NAMES[21],
150
+ [ENUMERATED_PLUGIN_HOOK_NAMES[22]]: ENUMERATED_PLUGIN_HOOK_NAMES[22]
151
+ };
152
+
153
+ //#endregion
154
+ //#region src/utils/async-flatten.ts
155
+ async function asyncFlatten(array$1) {
156
+ do
157
+ array$1 = (await Promise.all(array$1)).flat(Infinity);
158
+ while (array$1.some((v) => v?.then));
159
+ return array$1;
160
+ }
161
+
162
+ //#endregion
163
+ //#region src/utils/normalize-plugin-option.ts
164
+ const normalizePluginOption = async (plugins) => (await asyncFlatten([plugins])).filter(Boolean);
165
+ function checkOutputPluginOption(plugins, onLog) {
166
+ for (const plugin of plugins) for (const hook of ENUMERATED_INPUT_PLUGIN_HOOK_NAMES) if (hook in plugin) {
167
+ delete plugin[hook];
168
+ onLog(LOG_LEVEL_WARN, logInputHookInOutputPlugin(plugin.name, hook));
169
+ }
170
+ return plugins;
171
+ }
172
+ function normalizePlugins(plugins, anonymousPrefix) {
173
+ for (const [index, plugin] of plugins.entries()) {
174
+ if ("_parallel" in plugin) continue;
175
+ if (plugin instanceof BuiltinPlugin) continue;
176
+ if (!plugin.name) plugin.name = `${anonymousPrefix}${index + 1}`;
177
+ }
178
+ return plugins;
179
+ }
180
+ const ANONYMOUS_PLUGIN_PREFIX = "at position ";
181
+ const ANONYMOUS_OUTPUT_PLUGIN_PREFIX = "at output position ";
182
+
183
+ //#endregion
184
+ //#region src/plugin/plugin-driver.ts
185
+ var PluginDriver = class {
186
+ static async callOptionsHook(inputOptions, watchMode = false) {
187
+ const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
188
+ const plugins = getSortedPlugins("options", getObjectPlugins(await normalizePluginOption(inputOptions.plugins)));
189
+ const logger = getLogger(plugins, getOnLog(inputOptions, logLevel), logLevel, watchMode);
190
+ for (const plugin of plugins) {
191
+ const name = plugin.name || "unknown";
192
+ const options = plugin.options;
193
+ if (options) {
194
+ const { handler } = normalizeHook(options);
195
+ const result = await handler.call(new MinimalPluginContextImpl(logger, logLevel, name, watchMode, "onLog"), inputOptions);
196
+ if (result) inputOptions = result;
197
+ }
198
+ }
199
+ return inputOptions;
200
+ }
201
+ static callOutputOptionsHook(rawPlugins, outputOptions, onLog, logLevel, watchMode) {
202
+ const sortedPlugins = getSortedPlugins("outputOptions", getObjectPlugins(rawPlugins));
203
+ for (const plugin of sortedPlugins) {
204
+ const name = plugin.name || "unknown";
205
+ const options = plugin.outputOptions;
206
+ if (options) {
207
+ const { handler } = normalizeHook(options);
208
+ const result = handler.call(new MinimalPluginContextImpl(onLog, logLevel, name, watchMode), outputOptions);
209
+ if (result) outputOptions = result;
210
+ }
211
+ }
212
+ return outputOptions;
213
+ }
214
+ };
215
+ function getObjectPlugins(plugins) {
216
+ return plugins.filter((plugin) => {
217
+ if (!plugin) return;
218
+ if ("_parallel" in plugin) return;
219
+ if (plugin instanceof BuiltinPlugin) return;
220
+ return plugin;
221
+ });
222
+ }
223
+ function getSortedPlugins(hookName, plugins) {
224
+ const pre = [];
225
+ const normal = [];
226
+ const post = [];
227
+ for (const plugin of plugins) {
228
+ const hook = plugin[hookName];
229
+ if (hook) {
230
+ if (typeof hook === "object") {
231
+ if (hook.order === "pre") {
232
+ pre.push(plugin);
233
+ continue;
234
+ }
235
+ if (hook.order === "post") {
236
+ post.push(plugin);
237
+ continue;
238
+ }
239
+ }
240
+ normal.push(plugin);
241
+ }
242
+ }
243
+ return [
244
+ ...pre,
245
+ ...normal,
246
+ ...post
247
+ ];
248
+ }
249
+
250
+ //#endregion
251
+ //#region ../../node_modules/.pnpm/valibot@1.2.0_typescript@5.9.3/node_modules/valibot/dist/index.mjs
252
+ let store$4;
253
+ /**
254
+ * Returns the global configuration.
255
+ *
256
+ * @param config The config to merge.
257
+ *
258
+ * @returns The configuration.
259
+ */
260
+ /* @__NO_SIDE_EFFECTS__ */
261
+ function getGlobalConfig(config$1) {
262
+ return {
263
+ lang: config$1?.lang ?? store$4?.lang,
264
+ message: config$1?.message,
265
+ abortEarly: config$1?.abortEarly ?? store$4?.abortEarly,
266
+ abortPipeEarly: config$1?.abortPipeEarly ?? store$4?.abortPipeEarly
267
+ };
268
+ }
269
+ let store$3;
270
+ /**
271
+ * Returns a global error message.
272
+ *
273
+ * @param lang The language of the message.
274
+ *
275
+ * @returns The error message.
276
+ */
277
+ /* @__NO_SIDE_EFFECTS__ */
278
+ function getGlobalMessage(lang) {
279
+ return store$3?.get(lang);
280
+ }
281
+ let store$2;
282
+ /**
283
+ * Returns a schema error message.
284
+ *
285
+ * @param lang The language of the message.
286
+ *
287
+ * @returns The error message.
288
+ */
289
+ /* @__NO_SIDE_EFFECTS__ */
290
+ function getSchemaMessage(lang) {
291
+ return store$2?.get(lang);
292
+ }
293
+ let store$1;
294
+ /**
295
+ * Returns a specific error message.
296
+ *
297
+ * @param reference The identifier reference.
298
+ * @param lang The language of the message.
299
+ *
300
+ * @returns The error message.
301
+ */
302
+ /* @__NO_SIDE_EFFECTS__ */
303
+ function getSpecificMessage(reference, lang) {
304
+ return store$1?.get(reference)?.get(lang);
305
+ }
306
+ /**
307
+ * Stringifies an unknown input to a literal or type string.
308
+ *
309
+ * @param input The unknown input.
310
+ *
311
+ * @returns A literal or type string.
312
+ *
313
+ * @internal
314
+ */
315
+ /* @__NO_SIDE_EFFECTS__ */
316
+ function _stringify(input) {
317
+ const type = typeof input;
318
+ if (type === "string") return `"${input}"`;
319
+ if (type === "number" || type === "bigint" || type === "boolean") return `${input}`;
320
+ if (type === "object" || type === "function") return (input && Object.getPrototypeOf(input)?.constructor?.name) ?? "null";
321
+ return type;
322
+ }
323
+ /**
324
+ * Adds an issue to the dataset.
325
+ *
326
+ * @param context The issue context.
327
+ * @param label The issue label.
328
+ * @param dataset The input dataset.
329
+ * @param config The configuration.
330
+ * @param other The optional props.
331
+ *
332
+ * @internal
333
+ */
334
+ function _addIssue(context, label, dataset, config$1, other) {
335
+ const input = other && "input" in other ? other.input : dataset.value;
336
+ const expected = other?.expected ?? context.expects ?? null;
337
+ const received = other?.received ?? /* @__PURE__ */ _stringify(input);
338
+ const issue = {
339
+ kind: context.kind,
340
+ type: context.type,
341
+ input,
342
+ expected,
343
+ received,
344
+ message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
345
+ requirement: context.requirement,
346
+ path: other?.path,
347
+ issues: other?.issues,
348
+ lang: config$1.lang,
349
+ abortEarly: config$1.abortEarly,
350
+ abortPipeEarly: config$1.abortPipeEarly
351
+ };
352
+ const isSchema = context.kind === "schema";
353
+ const message$1 = other?.message ?? context.message ?? /* @__PURE__ */ getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? /* @__PURE__ */ getSchemaMessage(issue.lang) : null) ?? config$1.message ?? /* @__PURE__ */ getGlobalMessage(issue.lang);
354
+ if (message$1 !== void 0) issue.message = typeof message$1 === "function" ? message$1(issue) : message$1;
355
+ if (isSchema) dataset.typed = false;
356
+ if (dataset.issues) dataset.issues.push(issue);
357
+ else dataset.issues = [issue];
358
+ }
359
+ /**
360
+ * Returns the Standard Schema properties.
361
+ *
362
+ * @param context The schema context.
363
+ *
364
+ * @returns The Standard Schema properties.
365
+ */
366
+ /* @__NO_SIDE_EFFECTS__ */
367
+ function _getStandardProps(context) {
368
+ return {
369
+ version: 1,
370
+ vendor: "valibot",
371
+ validate(value$1) {
372
+ return context["~run"]({ value: value$1 }, /* @__PURE__ */ getGlobalConfig());
373
+ }
374
+ };
375
+ }
376
+ /**
377
+ * Disallows inherited object properties and prevents object prototype
378
+ * pollution by disallowing certain keys.
379
+ *
380
+ * @param object The object to check.
381
+ * @param key The key to check.
382
+ *
383
+ * @returns Whether the key is allowed.
384
+ *
385
+ * @internal
386
+ */
387
+ /* @__NO_SIDE_EFFECTS__ */
388
+ function _isValidObjectKey(object$1, key) {
389
+ return Object.hasOwn(object$1, key) && key !== "__proto__" && key !== "prototype" && key !== "constructor";
390
+ }
391
+ /**
392
+ * Joins multiple `expects` values with the given separator.
393
+ *
394
+ * @param values The `expects` values.
395
+ * @param separator The separator.
396
+ *
397
+ * @returns The joined `expects` property.
398
+ *
399
+ * @internal
400
+ */
401
+ /* @__NO_SIDE_EFFECTS__ */
402
+ function _joinExpects(values$1, separator) {
403
+ const list = [...new Set(values$1)];
404
+ if (list.length > 1) return `(${list.join(` ${separator} `)})`;
405
+ return list[0] ?? "never";
406
+ }
407
+ /**
408
+ * A Valibot error with useful information.
409
+ */
410
+ var ValiError = class extends Error {
411
+ /**
412
+ * Creates a Valibot error with useful information.
413
+ *
414
+ * @param issues The error issues.
415
+ */
416
+ constructor(issues) {
417
+ super(issues[0].message);
418
+ this.name = "ValiError";
419
+ this.issues = issues;
420
+ }
421
+ };
422
+ /* @__NO_SIDE_EFFECTS__ */
423
+ function args(schema) {
424
+ return {
425
+ kind: "transformation",
426
+ type: "args",
427
+ reference: args,
428
+ async: false,
429
+ schema,
430
+ "~run"(dataset, config$1) {
431
+ const func = dataset.value;
432
+ dataset.value = (...args_) => {
433
+ const argsDataset = this.schema["~run"]({ value: args_ }, config$1);
434
+ if (argsDataset.issues) throw new ValiError(argsDataset.issues);
435
+ return func(...argsDataset.value);
436
+ };
437
+ return dataset;
438
+ }
439
+ };
440
+ }
441
+ /**
442
+ * Creates an await transformation action.
443
+ *
444
+ * @returns An await action.
445
+ */
446
+ /* @__NO_SIDE_EFFECTS__ */
447
+ function awaitAsync() {
448
+ return {
449
+ kind: "transformation",
450
+ type: "await",
451
+ reference: awaitAsync,
452
+ async: true,
453
+ async "~run"(dataset) {
454
+ dataset.value = await dataset.value;
455
+ return dataset;
456
+ }
457
+ };
458
+ }
459
+ /**
460
+ * Creates a description metadata action.
461
+ *
462
+ * @param description_ The description text.
463
+ *
464
+ * @returns A description action.
465
+ */
466
+ /* @__NO_SIDE_EFFECTS__ */
467
+ function description(description_) {
468
+ return {
469
+ kind: "metadata",
470
+ type: "description",
471
+ reference: description,
472
+ description: description_
473
+ };
474
+ }
475
+ /* @__NO_SIDE_EFFECTS__ */
476
+ function returns(schema) {
477
+ return {
478
+ kind: "transformation",
479
+ type: "returns",
480
+ reference: returns,
481
+ async: false,
482
+ schema,
483
+ "~run"(dataset, config$1) {
484
+ const func = dataset.value;
485
+ dataset.value = (...args_) => {
486
+ const returnsDataset = this.schema["~run"]({ value: func(...args_) }, config$1);
487
+ if (returnsDataset.issues) throw new ValiError(returnsDataset.issues);
488
+ return returnsDataset.value;
489
+ };
490
+ return dataset;
491
+ }
492
+ };
493
+ }
494
+ /* @__NO_SIDE_EFFECTS__ */
495
+ function returnsAsync(schema) {
496
+ return {
497
+ kind: "transformation",
498
+ type: "returns",
499
+ reference: returnsAsync,
500
+ async: false,
501
+ schema,
502
+ "~run"(dataset, config$1) {
503
+ const func = dataset.value;
504
+ dataset.value = async (...args_) => {
505
+ const returnsDataset = await this.schema["~run"]({ value: await func(...args_) }, config$1);
506
+ if (returnsDataset.issues) throw new ValiError(returnsDataset.issues);
507
+ return returnsDataset.value;
508
+ };
509
+ return dataset;
510
+ }
511
+ };
512
+ }
513
+ /**
514
+ * Returns the fallback value of the schema.
515
+ *
516
+ * @param schema The schema to get it from.
517
+ * @param dataset The output dataset if available.
518
+ * @param config The config if available.
519
+ *
520
+ * @returns The fallback value.
521
+ */
522
+ /* @__NO_SIDE_EFFECTS__ */
523
+ function getFallback(schema, dataset, config$1) {
524
+ return typeof schema.fallback === "function" ? schema.fallback(dataset, config$1) : schema.fallback;
525
+ }
526
+ /**
527
+ * Returns the default value of the schema.
528
+ *
529
+ * @param schema The schema to get it from.
530
+ * @param dataset The input dataset if available.
531
+ * @param config The config if available.
532
+ *
533
+ * @returns The default value.
534
+ */
535
+ /* @__NO_SIDE_EFFECTS__ */
536
+ function getDefault(schema, dataset, config$1) {
537
+ return typeof schema.default === "function" ? schema.default(dataset, config$1) : schema.default;
538
+ }
539
+ /**
540
+ * Creates an any schema.
541
+ *
542
+ * Hint: This schema function exists only for completeness and is not
543
+ * recommended in practice. Instead, `unknown` should be used to accept
544
+ * unknown data.
545
+ *
546
+ * @returns An any schema.
547
+ */
548
+ /* @__NO_SIDE_EFFECTS__ */
549
+ function any() {
550
+ return {
551
+ kind: "schema",
552
+ type: "any",
553
+ reference: any,
554
+ expects: "any",
555
+ async: false,
556
+ get "~standard"() {
557
+ return /* @__PURE__ */ _getStandardProps(this);
558
+ },
559
+ "~run"(dataset) {
560
+ dataset.typed = true;
561
+ return dataset;
562
+ }
563
+ };
564
+ }
565
+ /* @__NO_SIDE_EFFECTS__ */
566
+ function array(item, message$1) {
567
+ return {
568
+ kind: "schema",
569
+ type: "array",
570
+ reference: array,
571
+ expects: "Array",
572
+ async: false,
573
+ item,
574
+ message: message$1,
575
+ get "~standard"() {
576
+ return /* @__PURE__ */ _getStandardProps(this);
577
+ },
578
+ "~run"(dataset, config$1) {
579
+ const input = dataset.value;
580
+ if (Array.isArray(input)) {
581
+ dataset.typed = true;
582
+ dataset.value = [];
583
+ for (let key = 0; key < input.length; key++) {
584
+ const value$1 = input[key];
585
+ const itemDataset = this.item["~run"]({ value: value$1 }, config$1);
586
+ if (itemDataset.issues) {
587
+ const pathItem = {
588
+ type: "array",
589
+ origin: "value",
590
+ input,
591
+ key,
592
+ value: value$1
593
+ };
594
+ for (const issue of itemDataset.issues) {
595
+ if (issue.path) issue.path.unshift(pathItem);
596
+ else issue.path = [pathItem];
597
+ dataset.issues?.push(issue);
598
+ }
599
+ if (!dataset.issues) dataset.issues = itemDataset.issues;
600
+ if (config$1.abortEarly) {
601
+ dataset.typed = false;
602
+ break;
603
+ }
604
+ }
605
+ if (!itemDataset.typed) dataset.typed = false;
606
+ dataset.value.push(itemDataset.value);
607
+ }
608
+ } else _addIssue(this, "type", dataset, config$1);
609
+ return dataset;
610
+ }
611
+ };
612
+ }
613
+ /* @__NO_SIDE_EFFECTS__ */
614
+ function boolean(message$1) {
615
+ return {
616
+ kind: "schema",
617
+ type: "boolean",
618
+ reference: boolean,
619
+ expects: "boolean",
620
+ async: false,
621
+ message: message$1,
622
+ get "~standard"() {
623
+ return /* @__PURE__ */ _getStandardProps(this);
624
+ },
625
+ "~run"(dataset, config$1) {
626
+ if (typeof dataset.value === "boolean") dataset.typed = true;
627
+ else _addIssue(this, "type", dataset, config$1);
628
+ return dataset;
629
+ }
630
+ };
631
+ }
632
+ /* @__NO_SIDE_EFFECTS__ */
633
+ function custom(check$1, message$1) {
634
+ return {
635
+ kind: "schema",
636
+ type: "custom",
637
+ reference: custom,
638
+ expects: "unknown",
639
+ async: false,
640
+ check: check$1,
641
+ message: message$1,
642
+ get "~standard"() {
643
+ return /* @__PURE__ */ _getStandardProps(this);
644
+ },
645
+ "~run"(dataset, config$1) {
646
+ if (this.check(dataset.value)) dataset.typed = true;
647
+ else _addIssue(this, "type", dataset, config$1);
648
+ return dataset;
649
+ }
650
+ };
651
+ }
652
+ /* @__NO_SIDE_EFFECTS__ */
653
+ function function_(message$1) {
654
+ return {
655
+ kind: "schema",
656
+ type: "function",
657
+ reference: function_,
658
+ expects: "Function",
659
+ async: false,
660
+ message: message$1,
661
+ get "~standard"() {
662
+ return /* @__PURE__ */ _getStandardProps(this);
663
+ },
664
+ "~run"(dataset, config$1) {
665
+ if (typeof dataset.value === "function") dataset.typed = true;
666
+ else _addIssue(this, "type", dataset, config$1);
667
+ return dataset;
668
+ }
669
+ };
670
+ }
671
+ /* @__NO_SIDE_EFFECTS__ */
672
+ function instance(class_, message$1) {
673
+ return {
674
+ kind: "schema",
675
+ type: "instance",
676
+ reference: instance,
677
+ expects: class_.name,
678
+ async: false,
679
+ class: class_,
680
+ message: message$1,
681
+ get "~standard"() {
682
+ return /* @__PURE__ */ _getStandardProps(this);
683
+ },
684
+ "~run"(dataset, config$1) {
685
+ if (dataset.value instanceof this.class) dataset.typed = true;
686
+ else _addIssue(this, "type", dataset, config$1);
687
+ return dataset;
688
+ }
689
+ };
690
+ }
691
+ /* @__NO_SIDE_EFFECTS__ */
692
+ function literal(literal_, message$1) {
693
+ return {
694
+ kind: "schema",
695
+ type: "literal",
696
+ reference: literal,
697
+ expects: /* @__PURE__ */ _stringify(literal_),
698
+ async: false,
699
+ literal: literal_,
700
+ message: message$1,
701
+ get "~standard"() {
702
+ return /* @__PURE__ */ _getStandardProps(this);
703
+ },
704
+ "~run"(dataset, config$1) {
705
+ if (dataset.value === this.literal) dataset.typed = true;
706
+ else _addIssue(this, "type", dataset, config$1);
707
+ return dataset;
708
+ }
709
+ };
710
+ }
711
+ /* @__NO_SIDE_EFFECTS__ */
712
+ function looseObject(entries$1, message$1) {
713
+ return {
714
+ kind: "schema",
715
+ type: "loose_object",
716
+ reference: looseObject,
717
+ expects: "Object",
718
+ async: false,
719
+ entries: entries$1,
720
+ message: message$1,
721
+ get "~standard"() {
722
+ return /* @__PURE__ */ _getStandardProps(this);
723
+ },
724
+ "~run"(dataset, config$1) {
725
+ const input = dataset.value;
726
+ if (input && typeof input === "object") {
727
+ dataset.typed = true;
728
+ dataset.value = {};
729
+ for (const key in this.entries) {
730
+ const valueSchema = this.entries[key];
731
+ if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
732
+ const value$1 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
733
+ const valueDataset = valueSchema["~run"]({ value: value$1 }, config$1);
734
+ if (valueDataset.issues) {
735
+ const pathItem = {
736
+ type: "object",
737
+ origin: "value",
738
+ input,
739
+ key,
740
+ value: value$1
741
+ };
742
+ for (const issue of valueDataset.issues) {
743
+ if (issue.path) issue.path.unshift(pathItem);
744
+ else issue.path = [pathItem];
745
+ dataset.issues?.push(issue);
746
+ }
747
+ if (!dataset.issues) dataset.issues = valueDataset.issues;
748
+ if (config$1.abortEarly) {
749
+ dataset.typed = false;
750
+ break;
751
+ }
752
+ }
753
+ if (!valueDataset.typed) dataset.typed = false;
754
+ dataset.value[key] = valueDataset.value;
755
+ } else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
756
+ else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
757
+ _addIssue(this, "key", dataset, config$1, {
758
+ input: void 0,
759
+ expected: `"${key}"`,
760
+ path: [{
761
+ type: "object",
762
+ origin: "key",
763
+ input,
764
+ key,
765
+ value: input[key]
766
+ }]
767
+ });
768
+ if (config$1.abortEarly) break;
769
+ }
770
+ }
771
+ if (!dataset.issues || !config$1.abortEarly) {
772
+ for (const key in input) if (/* @__PURE__ */ _isValidObjectKey(input, key) && !(key in this.entries)) dataset.value[key] = input[key];
773
+ }
774
+ } else _addIssue(this, "type", dataset, config$1);
775
+ return dataset;
776
+ }
777
+ };
778
+ }
779
+ /* @__NO_SIDE_EFFECTS__ */
780
+ function never(message$1) {
781
+ return {
782
+ kind: "schema",
783
+ type: "never",
784
+ reference: never,
785
+ expects: "never",
786
+ async: false,
787
+ message: message$1,
788
+ get "~standard"() {
789
+ return /* @__PURE__ */ _getStandardProps(this);
790
+ },
791
+ "~run"(dataset, config$1) {
792
+ _addIssue(this, "type", dataset, config$1);
793
+ return dataset;
794
+ }
795
+ };
796
+ }
797
+ /* @__NO_SIDE_EFFECTS__ */
798
+ function nullish(wrapped, default_) {
799
+ return {
800
+ kind: "schema",
801
+ type: "nullish",
802
+ reference: nullish,
803
+ expects: `(${wrapped.expects} | null | undefined)`,
804
+ async: false,
805
+ wrapped,
806
+ default: default_,
807
+ get "~standard"() {
808
+ return /* @__PURE__ */ _getStandardProps(this);
809
+ },
810
+ "~run"(dataset, config$1) {
811
+ if (dataset.value === null || dataset.value === void 0) {
812
+ if (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config$1);
813
+ if (dataset.value === null || dataset.value === void 0) {
814
+ dataset.typed = true;
815
+ return dataset;
816
+ }
817
+ }
818
+ return this.wrapped["~run"](dataset, config$1);
819
+ }
820
+ };
821
+ }
822
+ /* @__NO_SIDE_EFFECTS__ */
823
+ function number(message$1) {
824
+ return {
825
+ kind: "schema",
826
+ type: "number",
827
+ reference: number,
828
+ expects: "number",
829
+ async: false,
830
+ message: message$1,
831
+ get "~standard"() {
832
+ return /* @__PURE__ */ _getStandardProps(this);
833
+ },
834
+ "~run"(dataset, config$1) {
835
+ if (typeof dataset.value === "number" && !isNaN(dataset.value)) dataset.typed = true;
836
+ else _addIssue(this, "type", dataset, config$1);
837
+ return dataset;
838
+ }
839
+ };
840
+ }
841
+ /* @__NO_SIDE_EFFECTS__ */
842
+ function object(entries$1, message$1) {
843
+ return {
844
+ kind: "schema",
845
+ type: "object",
846
+ reference: object,
847
+ expects: "Object",
848
+ async: false,
849
+ entries: entries$1,
850
+ message: message$1,
851
+ get "~standard"() {
852
+ return /* @__PURE__ */ _getStandardProps(this);
853
+ },
854
+ "~run"(dataset, config$1) {
855
+ const input = dataset.value;
856
+ if (input && typeof input === "object") {
857
+ dataset.typed = true;
858
+ dataset.value = {};
859
+ for (const key in this.entries) {
860
+ const valueSchema = this.entries[key];
861
+ if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
862
+ const value$1 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
863
+ const valueDataset = valueSchema["~run"]({ value: value$1 }, config$1);
864
+ if (valueDataset.issues) {
865
+ const pathItem = {
866
+ type: "object",
867
+ origin: "value",
868
+ input,
869
+ key,
870
+ value: value$1
871
+ };
872
+ for (const issue of valueDataset.issues) {
873
+ if (issue.path) issue.path.unshift(pathItem);
874
+ else issue.path = [pathItem];
875
+ dataset.issues?.push(issue);
876
+ }
877
+ if (!dataset.issues) dataset.issues = valueDataset.issues;
878
+ if (config$1.abortEarly) {
879
+ dataset.typed = false;
880
+ break;
881
+ }
882
+ }
883
+ if (!valueDataset.typed) dataset.typed = false;
884
+ dataset.value[key] = valueDataset.value;
885
+ } else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
886
+ else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
887
+ _addIssue(this, "key", dataset, config$1, {
888
+ input: void 0,
889
+ expected: `"${key}"`,
890
+ path: [{
891
+ type: "object",
892
+ origin: "key",
893
+ input,
894
+ key,
895
+ value: input[key]
896
+ }]
897
+ });
898
+ if (config$1.abortEarly) break;
899
+ }
900
+ }
901
+ } else _addIssue(this, "type", dataset, config$1);
902
+ return dataset;
903
+ }
904
+ };
905
+ }
906
+ /* @__NO_SIDE_EFFECTS__ */
907
+ function optional(wrapped, default_) {
908
+ return {
909
+ kind: "schema",
910
+ type: "optional",
911
+ reference: optional,
912
+ expects: `(${wrapped.expects} | undefined)`,
913
+ async: false,
914
+ wrapped,
915
+ default: default_,
916
+ get "~standard"() {
917
+ return /* @__PURE__ */ _getStandardProps(this);
918
+ },
919
+ "~run"(dataset, config$1) {
920
+ if (dataset.value === void 0) {
921
+ if (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config$1);
922
+ if (dataset.value === void 0) {
923
+ dataset.typed = true;
924
+ return dataset;
925
+ }
926
+ }
927
+ return this.wrapped["~run"](dataset, config$1);
928
+ }
929
+ };
930
+ }
931
+ /* @__NO_SIDE_EFFECTS__ */
932
+ function picklist(options, message$1) {
933
+ return {
934
+ kind: "schema",
935
+ type: "picklist",
936
+ reference: picklist,
937
+ expects: /* @__PURE__ */ _joinExpects(options.map(_stringify), "|"),
938
+ async: false,
939
+ options,
940
+ message: message$1,
941
+ get "~standard"() {
942
+ return /* @__PURE__ */ _getStandardProps(this);
943
+ },
944
+ "~run"(dataset, config$1) {
945
+ if (this.options.includes(dataset.value)) dataset.typed = true;
946
+ else _addIssue(this, "type", dataset, config$1);
947
+ return dataset;
948
+ }
949
+ };
950
+ }
951
+ /* @__NO_SIDE_EFFECTS__ */
952
+ function promise(message$1) {
953
+ return {
954
+ kind: "schema",
955
+ type: "promise",
956
+ reference: promise,
957
+ expects: "Promise",
958
+ async: false,
959
+ message: message$1,
960
+ get "~standard"() {
961
+ return /* @__PURE__ */ _getStandardProps(this);
962
+ },
963
+ "~run"(dataset, config$1) {
964
+ if (dataset.value instanceof Promise) dataset.typed = true;
965
+ else _addIssue(this, "type", dataset, config$1);
966
+ return dataset;
967
+ }
968
+ };
969
+ }
970
+ /* @__NO_SIDE_EFFECTS__ */
971
+ function record(key, value$1, message$1) {
972
+ return {
973
+ kind: "schema",
974
+ type: "record",
975
+ reference: record,
976
+ expects: "Object",
977
+ async: false,
978
+ key,
979
+ value: value$1,
980
+ message: message$1,
981
+ get "~standard"() {
982
+ return /* @__PURE__ */ _getStandardProps(this);
983
+ },
984
+ "~run"(dataset, config$1) {
985
+ const input = dataset.value;
986
+ if (input && typeof input === "object") {
987
+ dataset.typed = true;
988
+ dataset.value = {};
989
+ for (const entryKey in input) if (/* @__PURE__ */ _isValidObjectKey(input, entryKey)) {
990
+ const entryValue = input[entryKey];
991
+ const keyDataset = this.key["~run"]({ value: entryKey }, config$1);
992
+ if (keyDataset.issues) {
993
+ const pathItem = {
994
+ type: "object",
995
+ origin: "key",
996
+ input,
997
+ key: entryKey,
998
+ value: entryValue
999
+ };
1000
+ for (const issue of keyDataset.issues) {
1001
+ issue.path = [pathItem];
1002
+ dataset.issues?.push(issue);
1003
+ }
1004
+ if (!dataset.issues) dataset.issues = keyDataset.issues;
1005
+ if (config$1.abortEarly) {
1006
+ dataset.typed = false;
1007
+ break;
1008
+ }
1009
+ }
1010
+ const valueDataset = this.value["~run"]({ value: entryValue }, config$1);
1011
+ if (valueDataset.issues) {
1012
+ const pathItem = {
1013
+ type: "object",
1014
+ origin: "value",
1015
+ input,
1016
+ key: entryKey,
1017
+ value: entryValue
1018
+ };
1019
+ for (const issue of valueDataset.issues) {
1020
+ if (issue.path) issue.path.unshift(pathItem);
1021
+ else issue.path = [pathItem];
1022
+ dataset.issues?.push(issue);
1023
+ }
1024
+ if (!dataset.issues) dataset.issues = valueDataset.issues;
1025
+ if (config$1.abortEarly) {
1026
+ dataset.typed = false;
1027
+ break;
1028
+ }
1029
+ }
1030
+ if (!keyDataset.typed || !valueDataset.typed) dataset.typed = false;
1031
+ if (keyDataset.typed) dataset.value[keyDataset.value] = valueDataset.value;
1032
+ }
1033
+ } else _addIssue(this, "type", dataset, config$1);
1034
+ return dataset;
1035
+ }
1036
+ };
1037
+ }
1038
+ /* @__NO_SIDE_EFFECTS__ */
1039
+ function strictObject(entries$1, message$1) {
1040
+ return {
1041
+ kind: "schema",
1042
+ type: "strict_object",
1043
+ reference: strictObject,
1044
+ expects: "Object",
1045
+ async: false,
1046
+ entries: entries$1,
1047
+ message: message$1,
1048
+ get "~standard"() {
1049
+ return /* @__PURE__ */ _getStandardProps(this);
1050
+ },
1051
+ "~run"(dataset, config$1) {
1052
+ const input = dataset.value;
1053
+ if (input && typeof input === "object") {
1054
+ dataset.typed = true;
1055
+ dataset.value = {};
1056
+ for (const key in this.entries) {
1057
+ const valueSchema = this.entries[key];
1058
+ if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
1059
+ const value$1 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
1060
+ const valueDataset = valueSchema["~run"]({ value: value$1 }, config$1);
1061
+ if (valueDataset.issues) {
1062
+ const pathItem = {
1063
+ type: "object",
1064
+ origin: "value",
1065
+ input,
1066
+ key,
1067
+ value: value$1
1068
+ };
1069
+ for (const issue of valueDataset.issues) {
1070
+ if (issue.path) issue.path.unshift(pathItem);
1071
+ else issue.path = [pathItem];
1072
+ dataset.issues?.push(issue);
1073
+ }
1074
+ if (!dataset.issues) dataset.issues = valueDataset.issues;
1075
+ if (config$1.abortEarly) {
1076
+ dataset.typed = false;
1077
+ break;
1078
+ }
1079
+ }
1080
+ if (!valueDataset.typed) dataset.typed = false;
1081
+ dataset.value[key] = valueDataset.value;
1082
+ } else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
1083
+ else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
1084
+ _addIssue(this, "key", dataset, config$1, {
1085
+ input: void 0,
1086
+ expected: `"${key}"`,
1087
+ path: [{
1088
+ type: "object",
1089
+ origin: "key",
1090
+ input,
1091
+ key,
1092
+ value: input[key]
1093
+ }]
1094
+ });
1095
+ if (config$1.abortEarly) break;
1096
+ }
1097
+ }
1098
+ if (!dataset.issues || !config$1.abortEarly) {
1099
+ for (const key in input) if (!(key in this.entries)) {
1100
+ _addIssue(this, "key", dataset, config$1, {
1101
+ input: key,
1102
+ expected: "never",
1103
+ path: [{
1104
+ type: "object",
1105
+ origin: "key",
1106
+ input,
1107
+ key,
1108
+ value: input[key]
1109
+ }]
1110
+ });
1111
+ break;
1112
+ }
1113
+ }
1114
+ } else _addIssue(this, "type", dataset, config$1);
1115
+ return dataset;
1116
+ }
1117
+ };
1118
+ }
1119
+ /* @__NO_SIDE_EFFECTS__ */
1120
+ function string(message$1) {
1121
+ return {
1122
+ kind: "schema",
1123
+ type: "string",
1124
+ reference: string,
1125
+ expects: "string",
1126
+ async: false,
1127
+ message: message$1,
1128
+ get "~standard"() {
1129
+ return /* @__PURE__ */ _getStandardProps(this);
1130
+ },
1131
+ "~run"(dataset, config$1) {
1132
+ if (typeof dataset.value === "string") dataset.typed = true;
1133
+ else _addIssue(this, "type", dataset, config$1);
1134
+ return dataset;
1135
+ }
1136
+ };
1137
+ }
1138
+ /* @__NO_SIDE_EFFECTS__ */
1139
+ function tuple(items, message$1) {
1140
+ return {
1141
+ kind: "schema",
1142
+ type: "tuple",
1143
+ reference: tuple,
1144
+ expects: "Array",
1145
+ async: false,
1146
+ items,
1147
+ message: message$1,
1148
+ get "~standard"() {
1149
+ return /* @__PURE__ */ _getStandardProps(this);
1150
+ },
1151
+ "~run"(dataset, config$1) {
1152
+ const input = dataset.value;
1153
+ if (Array.isArray(input)) {
1154
+ dataset.typed = true;
1155
+ dataset.value = [];
1156
+ for (let key = 0; key < this.items.length; key++) {
1157
+ const value$1 = input[key];
1158
+ const itemDataset = this.items[key]["~run"]({ value: value$1 }, config$1);
1159
+ if (itemDataset.issues) {
1160
+ const pathItem = {
1161
+ type: "array",
1162
+ origin: "value",
1163
+ input,
1164
+ key,
1165
+ value: value$1
1166
+ };
1167
+ for (const issue of itemDataset.issues) {
1168
+ if (issue.path) issue.path.unshift(pathItem);
1169
+ else issue.path = [pathItem];
1170
+ dataset.issues?.push(issue);
1171
+ }
1172
+ if (!dataset.issues) dataset.issues = itemDataset.issues;
1173
+ if (config$1.abortEarly) {
1174
+ dataset.typed = false;
1175
+ break;
1176
+ }
1177
+ }
1178
+ if (!itemDataset.typed) dataset.typed = false;
1179
+ dataset.value.push(itemDataset.value);
1180
+ }
1181
+ } else _addIssue(this, "type", dataset, config$1);
1182
+ return dataset;
1183
+ }
1184
+ };
1185
+ }
1186
+ /* @__NO_SIDE_EFFECTS__ */
1187
+ function undefined_(message$1) {
1188
+ return {
1189
+ kind: "schema",
1190
+ type: "undefined",
1191
+ reference: undefined_,
1192
+ expects: "undefined",
1193
+ async: false,
1194
+ message: message$1,
1195
+ get "~standard"() {
1196
+ return /* @__PURE__ */ _getStandardProps(this);
1197
+ },
1198
+ "~run"(dataset, config$1) {
1199
+ if (dataset.value === void 0) dataset.typed = true;
1200
+ else _addIssue(this, "type", dataset, config$1);
1201
+ return dataset;
1202
+ }
1203
+ };
1204
+ }
1205
+ /**
1206
+ * Returns the sub issues of the provided datasets for the union issue.
1207
+ *
1208
+ * @param datasets The datasets.
1209
+ *
1210
+ * @returns The sub issues.
1211
+ *
1212
+ * @internal
1213
+ */
1214
+ /* @__NO_SIDE_EFFECTS__ */
1215
+ function _subIssues(datasets) {
1216
+ let issues;
1217
+ if (datasets) for (const dataset of datasets) if (issues) issues.push(...dataset.issues);
1218
+ else issues = dataset.issues;
1219
+ return issues;
1220
+ }
1221
+ /* @__NO_SIDE_EFFECTS__ */
1222
+ function union(options, message$1) {
1223
+ return {
1224
+ kind: "schema",
1225
+ type: "union",
1226
+ reference: union,
1227
+ expects: /* @__PURE__ */ _joinExpects(options.map((option) => option.expects), "|"),
1228
+ async: false,
1229
+ options,
1230
+ message: message$1,
1231
+ get "~standard"() {
1232
+ return /* @__PURE__ */ _getStandardProps(this);
1233
+ },
1234
+ "~run"(dataset, config$1) {
1235
+ let validDataset;
1236
+ let typedDatasets;
1237
+ let untypedDatasets;
1238
+ for (const schema of this.options) {
1239
+ const optionDataset = schema["~run"]({ value: dataset.value }, config$1);
1240
+ if (optionDataset.typed) if (optionDataset.issues) if (typedDatasets) typedDatasets.push(optionDataset);
1241
+ else typedDatasets = [optionDataset];
1242
+ else {
1243
+ validDataset = optionDataset;
1244
+ break;
1245
+ }
1246
+ else if (untypedDatasets) untypedDatasets.push(optionDataset);
1247
+ else untypedDatasets = [optionDataset];
1248
+ }
1249
+ if (validDataset) return validDataset;
1250
+ if (typedDatasets) {
1251
+ if (typedDatasets.length === 1) return typedDatasets[0];
1252
+ _addIssue(this, "type", dataset, config$1, { issues: /* @__PURE__ */ _subIssues(typedDatasets) });
1253
+ dataset.typed = true;
1254
+ } else if (untypedDatasets?.length === 1) return untypedDatasets[0];
1255
+ else _addIssue(this, "type", dataset, config$1, { issues: /* @__PURE__ */ _subIssues(untypedDatasets) });
1256
+ return dataset;
1257
+ }
1258
+ };
1259
+ }
1260
+ /* @__NO_SIDE_EFFECTS__ */
1261
+ function unionAsync(options, message$1) {
1262
+ return {
1263
+ kind: "schema",
1264
+ type: "union",
1265
+ reference: unionAsync,
1266
+ expects: /* @__PURE__ */ _joinExpects(options.map((option) => option.expects), "|"),
1267
+ async: true,
1268
+ options,
1269
+ message: message$1,
1270
+ get "~standard"() {
1271
+ return /* @__PURE__ */ _getStandardProps(this);
1272
+ },
1273
+ async "~run"(dataset, config$1) {
1274
+ let validDataset;
1275
+ let typedDatasets;
1276
+ let untypedDatasets;
1277
+ for (const schema of this.options) {
1278
+ const optionDataset = await schema["~run"]({ value: dataset.value }, config$1);
1279
+ if (optionDataset.typed) if (optionDataset.issues) if (typedDatasets) typedDatasets.push(optionDataset);
1280
+ else typedDatasets = [optionDataset];
1281
+ else {
1282
+ validDataset = optionDataset;
1283
+ break;
1284
+ }
1285
+ else if (untypedDatasets) untypedDatasets.push(optionDataset);
1286
+ else untypedDatasets = [optionDataset];
1287
+ }
1288
+ if (validDataset) return validDataset;
1289
+ if (typedDatasets) {
1290
+ if (typedDatasets.length === 1) return typedDatasets[0];
1291
+ _addIssue(this, "type", dataset, config$1, { issues: /* @__PURE__ */ _subIssues(typedDatasets) });
1292
+ dataset.typed = true;
1293
+ } else if (untypedDatasets?.length === 1) return untypedDatasets[0];
1294
+ else _addIssue(this, "type", dataset, config$1, { issues: /* @__PURE__ */ _subIssues(untypedDatasets) });
1295
+ return dataset;
1296
+ }
1297
+ };
1298
+ }
1299
+ /* @__NO_SIDE_EFFECTS__ */
1300
+ function void_(message$1) {
1301
+ return {
1302
+ kind: "schema",
1303
+ type: "void",
1304
+ reference: void_,
1305
+ expects: "void",
1306
+ async: false,
1307
+ message: message$1,
1308
+ get "~standard"() {
1309
+ return /* @__PURE__ */ _getStandardProps(this);
1310
+ },
1311
+ "~run"(dataset, config$1) {
1312
+ if (dataset.value === void 0) dataset.typed = true;
1313
+ else _addIssue(this, "type", dataset, config$1);
1314
+ return dataset;
1315
+ }
1316
+ };
1317
+ }
1318
+ /* @__NO_SIDE_EFFECTS__ */
1319
+ function keyof(schema, message$1) {
1320
+ return /* @__PURE__ */ picklist(Object.keys(schema.entries), message$1);
1321
+ }
1322
+ /**
1323
+ * Creates a modified copy of an object schema that does not contain the
1324
+ * selected entries.
1325
+ *
1326
+ * @param schema The schema to omit from.
1327
+ * @param keys The selected entries.
1328
+ *
1329
+ * @returns An object schema.
1330
+ */
1331
+ /* @__NO_SIDE_EFFECTS__ */
1332
+ function omit(schema, keys) {
1333
+ const entries$1 = { ...schema.entries };
1334
+ for (const key of keys) delete entries$1[key];
1335
+ return {
1336
+ ...schema,
1337
+ entries: entries$1,
1338
+ get "~standard"() {
1339
+ return /* @__PURE__ */ _getStandardProps(this);
1340
+ }
1341
+ };
1342
+ }
1343
+ /* @__NO_SIDE_EFFECTS__ */
1344
+ function partial(schema, keys) {
1345
+ const entries$1 = {};
1346
+ for (const key in schema.entries) entries$1[key] = !keys || keys.includes(key) ? /* @__PURE__ */ optional(schema.entries[key]) : schema.entries[key];
1347
+ return {
1348
+ ...schema,
1349
+ entries: entries$1,
1350
+ get "~standard"() {
1351
+ return /* @__PURE__ */ _getStandardProps(this);
1352
+ }
1353
+ };
1354
+ }
1355
+ /* @__NO_SIDE_EFFECTS__ */
1356
+ function pipe(...pipe$1) {
1357
+ return {
1358
+ ...pipe$1[0],
1359
+ pipe: pipe$1,
1360
+ get "~standard"() {
1361
+ return /* @__PURE__ */ _getStandardProps(this);
1362
+ },
1363
+ "~run"(dataset, config$1) {
1364
+ for (const item of pipe$1) if (item.kind !== "metadata") {
1365
+ if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
1366
+ dataset.typed = false;
1367
+ break;
1368
+ }
1369
+ if (!dataset.issues || !config$1.abortEarly && !config$1.abortPipeEarly) dataset = item["~run"](dataset, config$1);
1370
+ }
1371
+ return dataset;
1372
+ }
1373
+ };
1374
+ }
1375
+ /* @__NO_SIDE_EFFECTS__ */
1376
+ function pipeAsync(...pipe$1) {
1377
+ return {
1378
+ ...pipe$1[0],
1379
+ pipe: pipe$1,
1380
+ async: true,
1381
+ get "~standard"() {
1382
+ return /* @__PURE__ */ _getStandardProps(this);
1383
+ },
1384
+ async "~run"(dataset, config$1) {
1385
+ for (const item of pipe$1) if (item.kind !== "metadata") {
1386
+ if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
1387
+ dataset.typed = false;
1388
+ break;
1389
+ }
1390
+ if (!dataset.issues || !config$1.abortEarly && !config$1.abortPipeEarly) dataset = await item["~run"](dataset, config$1);
1391
+ }
1392
+ return dataset;
1393
+ }
1394
+ };
1395
+ }
1396
+ /**
1397
+ * Parses an unknown input based on a schema.
1398
+ *
1399
+ * @param schema The schema to be used.
1400
+ * @param input The input to be parsed.
1401
+ * @param config The parse configuration.
1402
+ *
1403
+ * @returns The parse result.
1404
+ */
1405
+ /* @__NO_SIDE_EFFECTS__ */
1406
+ function safeParse(schema, input, config$1) {
1407
+ const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config$1));
1408
+ return {
1409
+ typed: dataset.typed,
1410
+ success: !dataset.issues,
1411
+ output: dataset.value,
1412
+ issues: dataset.issues
1413
+ };
1414
+ }
1415
+
1416
+ //#endregion
1417
+ //#region src/utils/flatten-valibot-schema.ts
1418
+ function unwrapSchema(schema) {
1419
+ if (!schema) return schema;
1420
+ if (schema.type === "optional" && schema.wrapped) return unwrapSchema(schema.wrapped);
1421
+ if (schema.type === "nullable" && schema.wrapped) return unwrapSchema(schema.wrapped);
1422
+ if (schema.type === "nullish" && schema.wrapped) return unwrapSchema(schema.wrapped);
1423
+ return schema;
1424
+ }
1425
+ function getValibotSchemaType(schema) {
1426
+ if (!schema) return "any";
1427
+ if (schema.type) switch (schema.type) {
1428
+ case "string": return "string";
1429
+ case "number": return "number";
1430
+ case "boolean": return "boolean";
1431
+ case "array": return "array";
1432
+ case "object":
1433
+ case "strict_object":
1434
+ case "loose_object": return "object";
1435
+ case "union": return "union";
1436
+ case "literal": return typeof schema.literal;
1437
+ case "record": return "object";
1438
+ case "optional": return getValibotSchemaType(schema.wrapped);
1439
+ case "nullable": return getValibotSchemaType(schema.wrapped);
1440
+ case "nullish": return getValibotSchemaType(schema.wrapped);
1441
+ case "never": return "never";
1442
+ case "any": return "any";
1443
+ case "custom": return "any";
1444
+ case "function": return "never";
1445
+ case "instance": return "object";
1446
+ default: return "any";
1447
+ }
1448
+ return "any";
1449
+ }
1450
+ function getValibotDescription(schema) {
1451
+ if (!schema) return void 0;
1452
+ if (schema.pipe && Array.isArray(schema.pipe)) {
1453
+ for (const action of schema.pipe) if (action.type === "description" && action.description) return action.description;
1454
+ }
1455
+ if (schema.type === "optional" && schema.wrapped) return getValibotDescription(schema.wrapped);
1456
+ }
1457
+ function flattenValibotSchema(schema, result = {}, prefix = "") {
1458
+ if (!schema || typeof schema !== "object") return result;
1459
+ if (schema.type === "strict_object" || schema.type === "object" || schema.type === "loose_object") {
1460
+ if (schema.entries && typeof schema.entries === "object") for (const [key, value] of Object.entries(schema.entries)) {
1461
+ const fullKey = prefix ? `${prefix}.${key}` : key;
1462
+ const valueSchema = value;
1463
+ const type = getValibotSchemaType(valueSchema);
1464
+ const description$1 = getValibotDescription(valueSchema);
1465
+ if (type === "object") {
1466
+ const unwrappedSchema = unwrapSchema(valueSchema);
1467
+ if (unwrappedSchema && unwrappedSchema.entries) flattenValibotSchema(unwrappedSchema, result, fullKey);
1468
+ else result[fullKey] = {
1469
+ type,
1470
+ description: description$1
1471
+ };
1472
+ } else result[fullKey] = {
1473
+ type,
1474
+ description: description$1
1475
+ };
1476
+ }
1477
+ }
1478
+ return result;
1479
+ }
1480
+
1481
+ //#endregion
1482
+ //#region src/utils/style-text.ts
1483
+ /**
1484
+ * Cross-platform styleText utility that works in both Node.js and browser environments
1485
+ * In Node.js, it uses the native `styleText` from `node:util`
1486
+ * In browser, it provides empty styling functions for compatibility
1487
+ */
1488
+ function styleText$1(...args$1) {
1489
+ return styleText(...args$1);
1490
+ }
1491
+
1492
+ //#endregion
1493
+ //#region src/utils/validator.ts
1494
+ const StringOrRegExpSchema = union([string(), instance(RegExp)]);
1495
+ function vFunction() {
1496
+ return function_();
1497
+ }
1498
+ const LogLevelSchema = union([
1499
+ literal("debug"),
1500
+ literal("info"),
1501
+ literal("warn")
1502
+ ]);
1503
+ const LogLevelOptionSchema = union([LogLevelSchema, literal("silent")]);
1504
+ const LogLevelWithErrorSchema = union([LogLevelSchema, literal("error")]);
1505
+ const RollupLogSchema = any();
1506
+ const RollupLogWithStringSchema = union([RollupLogSchema, string()]);
1507
+ const InputOptionSchema = union([
1508
+ string(),
1509
+ array(string()),
1510
+ record(string(), string())
1511
+ ]);
1512
+ const ExternalOptionFunctionSchema = pipe(vFunction(), args(tuple([
1513
+ string(),
1514
+ optional(string()),
1515
+ boolean()
1516
+ ])), returns(nullish(boolean())));
1517
+ const ExternalOptionSchema = union([
1518
+ StringOrRegExpSchema,
1519
+ array(StringOrRegExpSchema),
1520
+ ExternalOptionFunctionSchema
1521
+ ]);
1522
+ const ModuleTypesSchema = record(string(), union([
1523
+ literal("asset"),
1524
+ literal("base64"),
1525
+ literal("binary"),
1526
+ literal("css"),
1527
+ literal("dataurl"),
1528
+ literal("empty"),
1529
+ literal("js"),
1530
+ literal("json"),
1531
+ literal("jsx"),
1532
+ literal("text"),
1533
+ literal("ts"),
1534
+ literal("tsx")
1535
+ ]));
1536
+ const JsxOptionsSchema = strictObject({
1537
+ runtime: pipe(optional(union([literal("classic"), literal("automatic")])), description("Which runtime to use")),
1538
+ development: pipe(optional(boolean()), description("Development specific information")),
1539
+ throwIfNamespace: pipe(optional(boolean()), description("Toggles whether to throw an error when a tag name uses an XML namespace")),
1540
+ importSource: pipe(optional(string()), description("Import the factory of element and fragment if mode is classic")),
1541
+ pragma: pipe(optional(string()), description("Jsx element transformation")),
1542
+ pragmaFrag: pipe(optional(string()), description("Jsx fragment transformation")),
1543
+ refresh: pipe(optional(boolean()), description("Enable react fast refresh"))
1544
+ });
1545
+ const HelperModeSchema = union([literal("Runtime"), literal("External")]);
1546
+ const DecoratorOptionSchema = object({
1547
+ legacy: optional(boolean()),
1548
+ emitDecoratorMetadata: optional(boolean())
1549
+ });
1550
+ const HelpersSchema = object({ mode: optional(HelperModeSchema) });
1551
+ const RewriteImportExtensionsSchema = union([
1552
+ literal("rewrite"),
1553
+ literal("remove"),
1554
+ boolean()
1555
+ ]);
1556
+ const TypescriptSchema = object({
1557
+ jsxPragma: optional(string()),
1558
+ jsxPragmaFrag: optional(string()),
1559
+ onlyRemoveTypeImports: optional(boolean()),
1560
+ allowNamespaces: optional(boolean()),
1561
+ allowDeclareFields: optional(boolean()),
1562
+ declaration: optional(object({
1563
+ stripInternal: optional(boolean()),
1564
+ sourcemap: optional(boolean())
1565
+ })),
1566
+ rewriteImportExtensions: optional(RewriteImportExtensionsSchema)
1567
+ });
1568
+ const AssumptionsSchema = object({
1569
+ ignoreFunctionLength: optional(boolean()),
1570
+ noDocumentAll: optional(boolean()),
1571
+ objectRestNoSymbols: optional(boolean()),
1572
+ pureGetters: optional(boolean()),
1573
+ setPublicClassFields: optional(boolean())
1574
+ });
1575
+ const TransformOptionsSchema = object({
1576
+ assumptions: optional(AssumptionsSchema),
1577
+ typescript: optional(TypescriptSchema),
1578
+ helpers: optional(HelpersSchema),
1579
+ decorators: optional(DecoratorOptionSchema),
1580
+ jsx: optional(union([
1581
+ literal(false),
1582
+ literal("preserve"),
1583
+ literal("react"),
1584
+ literal("react-jsx"),
1585
+ JsxOptionsSchema
1586
+ ])),
1587
+ target: pipe(optional(union([string(), array(string())])), description("The JavaScript target environment")),
1588
+ define: pipe(optional(record(string(), string())), description("Define global variables (syntax: key=value,key2=value2)")),
1589
+ inject: pipe(optional(record(string(), union([string(), tuple([string(), string()])]))), description("Inject import statements on demand")),
1590
+ dropLabels: pipe(optional(array(string())), description("Remove labeled statements with these label names"))
1591
+ });
1592
+ const WatchOptionsSchema = strictObject({
1593
+ chokidar: optional(never(`The "watch.chokidar" option is deprecated, please use "watch.notify" instead of it`)),
1594
+ exclude: optional(union([StringOrRegExpSchema, array(StringOrRegExpSchema)])),
1595
+ include: optional(union([StringOrRegExpSchema, array(StringOrRegExpSchema)])),
1596
+ notify: pipe(optional(strictObject({
1597
+ compareContents: optional(boolean()),
1598
+ pollInterval: optional(number())
1599
+ })), description("Notify options")),
1600
+ skipWrite: pipe(optional(boolean()), description("Skip the bundle.write() step")),
1601
+ buildDelay: pipe(optional(number()), description("Throttle watch rebuilds")),
1602
+ clearScreen: pipe(optional(boolean()), description("Whether to clear the screen when a rebuild is triggered")),
1603
+ onInvalidate: pipe(optional(pipe(function_(), args(tuple([string()])))), description("An optional function that will be called immediately every time a module changes that is part of the build."))
1604
+ });
1605
+ const ChecksOptionsSchema = strictObject({
1606
+ circularDependency: pipe(optional(boolean()), description("Whether to emit warnings when detecting circular dependency")),
1607
+ eval: pipe(optional(boolean()), description("Whether to emit warnings when detecting uses of direct `eval`s")),
1608
+ missingGlobalName: pipe(optional(boolean()), description("Whether to emit warnings when the `output.globals` option is missing when needed")),
1609
+ missingNameOptionForIifeExport: pipe(optional(boolean()), description("Whether to emit warnings when the `output.name` option is missing when needed")),
1610
+ mixedExports: pipe(optional(boolean()), description("Whether to emit warnings when the way to export values is ambiguous")),
1611
+ unresolvedEntry: pipe(optional(boolean()), description("Whether to emit warnings when an entrypoint cannot be resolved")),
1612
+ unresolvedImport: pipe(optional(boolean()), description("Whether to emit warnings when an import cannot be resolved")),
1613
+ filenameConflict: pipe(optional(boolean()), description("Whether to emit warnings when files generated have the same name with different contents")),
1614
+ commonJsVariableInEsm: pipe(optional(boolean()), description("Whether to emit warnings when a CommonJS variable is used in an ES module")),
1615
+ importIsUndefined: pipe(optional(boolean()), description("Whether to emit warnings when an imported variable is not exported")),
1616
+ emptyImportMeta: pipe(optional(boolean()), description("Whether to emit warnings when `import.meta` is not supported with the output format and is replaced with an empty object (`{}`)")),
1617
+ cannotCallNamespace: pipe(optional(boolean()), description("Whether to emit warnings when a namespace is called as a function")),
1618
+ configurationFieldConflict: pipe(optional(boolean()), description("Whether to emit warnings when a config value is overridden by another config value with a higher priority")),
1619
+ preferBuiltinFeature: pipe(optional(boolean()), description("Whether to emit warnings when a plugin that is covered by a built-in feature is used")),
1620
+ couldNotCleanDirectory: pipe(optional(boolean()), description("Whether to emit warnings when Rolldown could not clean the output directory")),
1621
+ pluginTimings: pipe(optional(boolean()), description("Whether to emit warnings when plugins take significant time during the build process"))
1622
+ });
1623
+ const CompressOptionsKeepNamesSchema = strictObject({
1624
+ function: boolean(),
1625
+ class: boolean()
1626
+ });
1627
+ const CompressOptionsSchema = strictObject({
1628
+ target: optional(union([
1629
+ literal("esnext"),
1630
+ literal("es2015"),
1631
+ literal("es2016"),
1632
+ literal("es2017"),
1633
+ literal("es2018"),
1634
+ literal("es2019"),
1635
+ literal("es2020"),
1636
+ literal("es2021"),
1637
+ literal("es2022"),
1638
+ literal("es2023"),
1639
+ literal("es2024")
1640
+ ])),
1641
+ dropConsole: optional(boolean()),
1642
+ dropDebugger: optional(boolean()),
1643
+ keepNames: optional(CompressOptionsKeepNamesSchema),
1644
+ unused: optional(union([boolean(), literal("keep_assign")]))
1645
+ });
1646
+ const MangleOptionsKeepNamesSchema = strictObject({
1647
+ function: boolean(),
1648
+ class: boolean()
1649
+ });
1650
+ const MangleOptionsSchema = strictObject({
1651
+ toplevel: optional(boolean()),
1652
+ keepNames: optional(union([boolean(), MangleOptionsKeepNamesSchema])),
1653
+ debug: optional(boolean())
1654
+ });
1655
+ const CodegenOptionsSchema = strictObject({ removeWhitespace: optional(boolean()) });
1656
+ const MinifyOptionsSchema = strictObject({
1657
+ compress: optional(union([boolean(), CompressOptionsSchema])),
1658
+ mangle: optional(union([boolean(), MangleOptionsSchema])),
1659
+ codegen: optional(union([boolean(), CodegenOptionsSchema]))
1660
+ });
1661
+ const ResolveOptionsSchema = strictObject({
1662
+ alias: optional(record(string(), union([
1663
+ literal(false),
1664
+ string(),
1665
+ array(string())
1666
+ ]))),
1667
+ aliasFields: optional(array(array(string()))),
1668
+ conditionNames: optional(array(string())),
1669
+ extensionAlias: optional(record(string(), array(string()))),
1670
+ exportsFields: optional(array(array(string()))),
1671
+ extensions: optional(array(string())),
1672
+ mainFields: optional(array(string())),
1673
+ mainFiles: optional(array(string())),
1674
+ modules: optional(array(string())),
1675
+ symlinks: optional(boolean()),
1676
+ yarnPnp: optional(boolean())
1677
+ });
1678
+ const TreeshakingOptionsSchema = union([boolean(), looseObject({
1679
+ annotations: optional(boolean()),
1680
+ manualPureFunctions: optional(array(string())),
1681
+ unknownGlobalSideEffects: optional(boolean()),
1682
+ commonjs: optional(boolean()),
1683
+ propertyReadSideEffects: optional(union([literal(false), literal("always")])),
1684
+ propertyWriteSideEffects: optional(union([literal(false), literal("always")]))
1685
+ })]);
1686
+ const OptimizationOptionsSchema = strictObject({
1687
+ inlineConst: pipe(optional(union([boolean(), strictObject({
1688
+ mode: optional(union([literal("all"), literal("smart")])),
1689
+ pass: optional(number())
1690
+ })])), description("Enable crossmodule constant inlining")),
1691
+ pifeForModuleWrappers: pipe(optional(boolean()), description("Use PIFE pattern for module wrappers"))
1692
+ });
1693
+ const LogOrStringHandlerSchema = pipe(vFunction(), args(tuple([LogLevelWithErrorSchema, RollupLogWithStringSchema])));
1694
+ const OnLogSchema = pipe(vFunction(), args(tuple([
1695
+ LogLevelSchema,
1696
+ RollupLogSchema,
1697
+ LogOrStringHandlerSchema
1698
+ ])));
1699
+ const OnwarnSchema = pipe(vFunction(), args(tuple([RollupLogSchema, pipe(vFunction(), args(tuple([union([RollupLogWithStringSchema, pipe(vFunction(), returns(RollupLogWithStringSchema))])])))])));
1700
+ const DevModeSchema = union([boolean(), strictObject({
1701
+ port: optional(number()),
1702
+ host: optional(string()),
1703
+ implement: optional(string()),
1704
+ lazy: optional(boolean())
1705
+ })]);
1706
+ const InputOptionsSchema = strictObject({
1707
+ input: optional(InputOptionSchema),
1708
+ plugins: optional(custom(() => true)),
1709
+ external: optional(ExternalOptionSchema),
1710
+ makeAbsoluteExternalsRelative: optional(union([boolean(), literal("ifRelativeSource")])),
1711
+ resolve: optional(ResolveOptionsSchema),
1712
+ cwd: pipe(optional(string()), description("Current working directory")),
1713
+ platform: pipe(optional(union([
1714
+ literal("browser"),
1715
+ literal("neutral"),
1716
+ literal("node")
1717
+ ])), description(`Platform for which the code should be generated (node, ${styleText$1("underline", "browser")}, neutral)`)),
1718
+ shimMissingExports: pipe(optional(boolean()), description("Create shim variables for missing exports")),
1719
+ treeshake: optional(TreeshakingOptionsSchema),
1720
+ optimization: optional(OptimizationOptionsSchema),
1721
+ logLevel: pipe(optional(LogLevelOptionSchema), description(`Log level (${styleText$1("dim", "silent")}, ${styleText$1(["underline", "gray"], "info")}, debug, ${styleText$1("yellow", "warn")})`)),
1722
+ onLog: optional(OnLogSchema),
1723
+ onwarn: optional(OnwarnSchema),
1724
+ moduleTypes: pipe(optional(ModuleTypesSchema), description("Module types for customized extensions")),
1725
+ experimental: optional(strictObject({
1726
+ enableComposingJsPlugins: optional(boolean()),
1727
+ viteMode: optional(boolean()),
1728
+ resolveNewUrlToAsset: optional(boolean()),
1729
+ strictExecutionOrder: optional(boolean()),
1730
+ onDemandWrapping: optional(boolean()),
1731
+ incrementalBuild: optional(boolean()),
1732
+ devMode: optional(DevModeSchema),
1733
+ attachDebugInfo: optional(union([
1734
+ literal("none"),
1735
+ literal("simple"),
1736
+ literal("full")
1737
+ ])),
1738
+ chunkModulesOrder: optional(union([literal("module-id"), literal("exec-order")])),
1739
+ chunkImportMap: optional(union([boolean(), object({
1740
+ baseUrl: optional(string()),
1741
+ fileName: optional(string())
1742
+ })])),
1743
+ nativeMagicString: optional(boolean()),
1744
+ chunkOptimization: optional(boolean())
1745
+ })),
1746
+ transform: optional(TransformOptionsSchema),
1747
+ watch: optional(union([WatchOptionsSchema, literal(false)])),
1748
+ checks: optional(ChecksOptionsSchema),
1749
+ devtools: pipe(optional(object({ sessionId: pipe(optional(string()), description("Used to name the build.")) })), description("Enable debug mode. Emit debug information to disk. This might slow down the build process significantly.")),
1750
+ preserveEntrySignatures: pipe(optional(union([
1751
+ literal("strict"),
1752
+ literal("allow-extension"),
1753
+ literal("exports-only"),
1754
+ literal(false)
1755
+ ]))),
1756
+ tsconfig: pipe(optional(union([boolean(), string()])), description("Path to the tsconfig.json file."))
1757
+ });
1758
+ const InputCliOverrideSchema = strictObject({
1759
+ input: pipe(optional(array(string())), description("Entry file")),
1760
+ external: pipe(optional(array(string())), description("Comma-separated list of module ids to exclude from the bundle `<module-id>,...`")),
1761
+ treeshake: pipe(optional(boolean()), description("enable treeshaking")),
1762
+ makeAbsoluteExternalsRelative: pipe(optional(boolean()), description("Prevent normalization of external imports")),
1763
+ preserveEntrySignatures: pipe(optional(literal(false)), description("Avoid facade chunks for entry points")),
1764
+ context: pipe(optional(string()), description("The entity top-level `this` represents."))
1765
+ });
1766
+ const InputCliOptionsSchema = omit(strictObject({
1767
+ ...InputOptionsSchema.entries,
1768
+ ...InputCliOverrideSchema.entries
1769
+ }), [
1770
+ "plugins",
1771
+ "onwarn",
1772
+ "onLog",
1773
+ "resolve",
1774
+ "experimental",
1775
+ "watch"
1776
+ ]);
1777
+ const ModuleFormatSchema = union([
1778
+ literal("es"),
1779
+ literal("cjs"),
1780
+ literal("esm"),
1781
+ literal("module"),
1782
+ literal("commonjs"),
1783
+ literal("iife"),
1784
+ literal("umd")
1785
+ ]);
1786
+ const AddonFunctionSchema = pipe(vFunction(), args(tuple([custom(() => true)])), returnsAsync(unionAsync([string(), pipeAsync(promise(), awaitAsync(), string())])));
1787
+ const ChunkFileNamesFunctionSchema = pipe(vFunction(), args(tuple([custom(() => true)])), returns(string()));
1788
+ const ChunkFileNamesSchema = union([string(), ChunkFileNamesFunctionSchema]);
1789
+ const AssetFileNamesFunctionSchema = pipe(vFunction(), args(tuple([custom(() => true)])), returns(string()));
1790
+ const AssetFileNamesSchema = union([string(), AssetFileNamesFunctionSchema]);
1791
+ const SanitizeFileNameFunctionSchema = pipe(vFunction(), args(tuple([string()])), returns(string()));
1792
+ const SanitizeFileNameSchema = union([boolean(), SanitizeFileNameFunctionSchema]);
1793
+ const GlobalsFunctionSchema = pipe(vFunction(), args(tuple([string()])), returns(string()));
1794
+ const PathsFunctionSchema = pipe(vFunction(), args(tuple([string()])), returns(string()));
1795
+ const ManualChunksFunctionSchema = pipe(vFunction(), args(tuple([string(), object({})])), returns(nullish(string())));
1796
+ const AdvancedChunksNameFunctionSchema = pipe(vFunction(), args(tuple([string(), object({})])), returns(nullish(string())));
1797
+ const AdvancedChunksTestFunctionSchema = pipe(vFunction(), args(tuple([string()])), returns(union([
1798
+ boolean(),
1799
+ void_(),
1800
+ undefined_()
1801
+ ])));
1802
+ const AdvancedChunksSchema = strictObject({
1803
+ includeDependenciesRecursively: optional(boolean()),
1804
+ minSize: optional(number()),
1805
+ maxSize: optional(number()),
1806
+ minModuleSize: optional(number()),
1807
+ maxModuleSize: optional(number()),
1808
+ minShareCount: optional(number()),
1809
+ groups: optional(array(strictObject({
1810
+ name: union([string(), AdvancedChunksNameFunctionSchema]),
1811
+ test: optional(union([StringOrRegExpSchema, AdvancedChunksTestFunctionSchema])),
1812
+ priority: optional(number()),
1813
+ minSize: optional(number()),
1814
+ minShareCount: optional(number()),
1815
+ maxSize: optional(number()),
1816
+ minModuleSize: optional(number()),
1817
+ maxModuleSize: optional(number())
1818
+ })))
1819
+ });
1820
+ const GeneratedCodePresetSchema = union([literal("es5"), literal("es2015")]);
1821
+ const GeneratedCodeOptionsSchema = strictObject({
1822
+ symbols: pipe(optional(boolean()), description("Whether to use Symbol.toStringTag for namespace objects")),
1823
+ preset: GeneratedCodePresetSchema,
1824
+ profilerNames: pipe(optional(boolean()), description("Whether to add readable names to internal variables for profiling purposes"))
1825
+ });
1826
+ const OutputOptionsSchema = strictObject({
1827
+ dir: pipe(optional(string()), description("Output directory, defaults to `dist` if `file` is not set")),
1828
+ file: pipe(optional(string()), description("Single output file")),
1829
+ exports: pipe(optional(union([
1830
+ literal("auto"),
1831
+ literal("named"),
1832
+ literal("default"),
1833
+ literal("none")
1834
+ ])), description(`Specify a export mode (${styleText$1("underline", "auto")}, named, default, none)`)),
1835
+ hashCharacters: pipe(optional(union([
1836
+ literal("base64"),
1837
+ literal("base36"),
1838
+ literal("hex")
1839
+ ])), description("Use the specified character set for file hashes")),
1840
+ format: pipe(optional(ModuleFormatSchema), description(`Output format of the generated bundle (supports ${styleText$1("underline", "esm")}, cjs, and iife)`)),
1841
+ sourcemap: pipe(optional(union([
1842
+ boolean(),
1843
+ literal("inline"),
1844
+ literal("hidden")
1845
+ ])), description(`Generate sourcemap (\`-s inline\` for inline, or ${styleText$1("bold", "pass the `-s` on the last argument if you want to generate `.map` file")})`)),
1846
+ sourcemapBaseUrl: pipe(optional(string()), description("Base URL used to prefix sourcemap paths")),
1847
+ sourcemapDebugIds: pipe(optional(boolean()), description("Inject sourcemap debug IDs")),
1848
+ sourcemapIgnoreList: optional(union([
1849
+ boolean(),
1850
+ custom(() => true),
1851
+ StringOrRegExpSchema
1852
+ ])),
1853
+ sourcemapPathTransform: optional(custom(() => true)),
1854
+ banner: optional(union([string(), AddonFunctionSchema])),
1855
+ footer: optional(union([string(), AddonFunctionSchema])),
1856
+ postBanner: optional(union([string(), AddonFunctionSchema])),
1857
+ postFooter: optional(union([string(), AddonFunctionSchema])),
1858
+ intro: optional(union([string(), AddonFunctionSchema])),
1859
+ outro: optional(union([string(), AddonFunctionSchema])),
1860
+ extend: pipe(optional(boolean()), description("Extend global variable defined by name in IIFE / UMD formats")),
1861
+ esModule: optional(union([boolean(), literal("if-default-prop")])),
1862
+ assetFileNames: optional(AssetFileNamesSchema),
1863
+ entryFileNames: optional(ChunkFileNamesSchema),
1864
+ chunkFileNames: optional(ChunkFileNamesSchema),
1865
+ cssEntryFileNames: optional(ChunkFileNamesSchema),
1866
+ cssChunkFileNames: optional(ChunkFileNamesSchema),
1867
+ sanitizeFileName: optional(SanitizeFileNameSchema),
1868
+ minify: pipe(optional(union([
1869
+ boolean(),
1870
+ literal("dce-only"),
1871
+ MinifyOptionsSchema
1872
+ ])), description("Minify the bundled file")),
1873
+ name: pipe(optional(string()), description("Name for UMD / IIFE format outputs")),
1874
+ globals: pipe(optional(union([record(string(), string()), GlobalsFunctionSchema])), description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
1875
+ paths: pipe(optional(union([record(string(), string()), PathsFunctionSchema])), description("Maps external module IDs to paths")),
1876
+ generatedCode: pipe(optional(partial(GeneratedCodeOptionsSchema)), description("Generated code options")),
1877
+ externalLiveBindings: pipe(optional(boolean()), description("external live bindings")),
1878
+ inlineDynamicImports: pipe(optional(boolean()), description("Inline dynamic imports")),
1879
+ dynamicImportInCjs: pipe(optional(boolean()), description("Dynamic import in CJS output")),
1880
+ manualChunks: optional(ManualChunksFunctionSchema),
1881
+ codeSplitting: optional(AdvancedChunksSchema),
1882
+ advancedChunks: optional(AdvancedChunksSchema),
1883
+ legalComments: pipe(optional(union([literal("none"), literal("inline")])), description("Control comments in the output")),
1884
+ plugins: optional(custom(() => true)),
1885
+ polyfillRequire: pipe(optional(boolean()), description("Disable require polyfill injection")),
1886
+ hoistTransitiveImports: optional(literal(false)),
1887
+ preserveModules: pipe(optional(boolean()), description("Preserve module structure")),
1888
+ preserveModulesRoot: pipe(optional(string()), description("Put preserved modules under this path at root level")),
1889
+ virtualDirname: optional(string()),
1890
+ minifyInternalExports: pipe(optional(boolean()), description("Minify internal exports")),
1891
+ topLevelVar: pipe(optional(boolean()), description("Rewrite top-level declarations to use `var`.")),
1892
+ cleanDir: pipe(optional(boolean()), description("Clean output directory before emitting output")),
1893
+ keepNames: pipe(optional(boolean()), description("Keep function and class names after bundling"))
1894
+ });
1895
+ const getAddonDescription = (placement, wrapper) => {
1896
+ return `Code to insert the ${styleText$1("bold", placement)} of the bundled file (${styleText$1("bold", wrapper)} the wrapper function)`;
1897
+ };
1898
+ const OutputCliOverrideSchema = strictObject({
1899
+ assetFileNames: pipe(optional(string()), description("Name pattern for asset files")),
1900
+ entryFileNames: pipe(optional(string()), description("Name pattern for emitted entry chunks")),
1901
+ chunkFileNames: pipe(optional(string()), description("Name pattern for emitted secondary chunks")),
1902
+ cssEntryFileNames: pipe(optional(string()), description("Name pattern for emitted css entry chunks")),
1903
+ cssChunkFileNames: pipe(optional(string()), description("Name pattern for emitted css secondary chunks")),
1904
+ sanitizeFileName: pipe(optional(boolean()), description("Sanitize file name")),
1905
+ banner: pipe(optional(string()), description(getAddonDescription("top", "outside"))),
1906
+ footer: pipe(optional(string()), description(getAddonDescription("bottom", "outside"))),
1907
+ postBanner: pipe(optional(string()), description("A string to prepend to the top of each chunk. Applied after the `renderChunk` hook and minification")),
1908
+ postFooter: pipe(optional(string()), description("A string to append to the bottom of each chunk. Applied after the `renderChunk` hook and minification")),
1909
+ intro: pipe(optional(string()), description(getAddonDescription("top", "inside"))),
1910
+ outro: pipe(optional(string()), description(getAddonDescription("bottom", "inside"))),
1911
+ esModule: pipe(optional(boolean()), description("Always generate `__esModule` marks in non-ESM formats, defaults to `if-default-prop` (use `--no-esModule` to always disable)")),
1912
+ globals: pipe(optional(record(string(), string())), description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
1913
+ codeSplitting: pipe(optional(strictObject({
1914
+ minSize: pipe(optional(number()), description("Minimum size of the chunk")),
1915
+ minShareCount: pipe(optional(number()), description("Minimum share count of the chunk"))
1916
+ })), description("Code splitting options")),
1917
+ advancedChunks: pipe(optional(strictObject({
1918
+ minSize: pipe(optional(number()), description("Minimum size of the chunk")),
1919
+ minShareCount: pipe(optional(number()), description("Minimum share count of the chunk"))
1920
+ })), description("Deprecated: use codeSplitting instead")),
1921
+ minify: pipe(optional(boolean()), description("Minify the bundled file"))
1922
+ });
1923
+ const OutputCliOptionsSchema = omit(strictObject({
1924
+ ...OutputOptionsSchema.entries,
1925
+ ...OutputCliOverrideSchema.entries
1926
+ }), [
1927
+ "sourcemapIgnoreList",
1928
+ "sourcemapPathTransform",
1929
+ "plugins",
1930
+ "hoistTransitiveImports"
1931
+ ]);
1932
+ const CliOptionsSchema = strictObject({
1933
+ config: pipe(optional(union([string(), boolean()])), description("Path to the config file (default: `rolldown.config.js`)")),
1934
+ help: pipe(optional(boolean()), description("Show help")),
1935
+ environment: pipe(optional(union([string(), array(string())])), description("Pass additional settings to the config file via process.ENV.")),
1936
+ version: pipe(optional(boolean()), description("Show version number")),
1937
+ watch: pipe(optional(boolean()), description("Watch files in bundle and rebuild on changes")),
1938
+ ...InputCliOptionsSchema.entries,
1939
+ ...OutputCliOptionsSchema.entries
1940
+ });
1941
+ function validateCliOptions(options) {
1942
+ let parsed = safeParse(CliOptionsSchema, options);
1943
+ return [parsed.output, parsed.issues?.map((issue) => {
1944
+ return `Invalid value for option ${issue.path?.map((pathItem) => pathItem.key).join(" ")}: ${issue.message}`;
1945
+ })];
1946
+ }
1947
+ const inputHelperMsgRecord = {
1948
+ output: { ignored: true },
1949
+ "resolve.tsconfigFilename": { issueMsg: "It is deprecated. Please use the top-level `tsconfig` option instead." }
1950
+ };
1951
+ const outputHelperMsgRecord = {};
1952
+ function validateOption(key, options) {
1953
+ if (typeof options !== "object") throw new Error(`Invalid ${key} options. Expected an Object but received ${JSON.stringify(options)}.`);
1954
+ if (globalThis.process?.env?.ROLLUP_TEST) return;
1955
+ let parsed = safeParse(key === "input" ? InputOptionsSchema : OutputOptionsSchema, options);
1956
+ if (!parsed.success) {
1957
+ const errors = parsed.issues.map((issue) => {
1958
+ let issueMsg = issue.message;
1959
+ const issuePaths = issue.path.map((path$1) => path$1.key);
1960
+ if (issue.type === "union") {
1961
+ const subIssue = issue.issues?.find((i) => !(i.type !== issue.received && i.input === issue.input));
1962
+ if (subIssue) {
1963
+ if (subIssue.path) issuePaths.push(subIssue.path.map((path$1) => path$1.key));
1964
+ issueMsg = subIssue.message;
1965
+ }
1966
+ }
1967
+ const stringPath = issuePaths.join(".");
1968
+ const helper = key === "input" ? inputHelperMsgRecord[stringPath] : outputHelperMsgRecord[stringPath];
1969
+ if (helper && helper.ignored) return "";
1970
+ return `- For the "${stringPath}". ${helper?.issueMsg || issueMsg + "."} ${helper?.help ? `\n Help: ${helper.help}` : ""}`;
1971
+ }).filter(Boolean);
1972
+ if (errors.length) console.warn(`\x1b[33mWarning: Invalid ${key} options (${errors.length} issue${errors.length === 1 ? "" : "s"} found)\n${errors.join("\n")}\x1b[0m`);
1973
+ }
1974
+ }
1975
+ function getInputCliKeys() {
1976
+ return keyof(InputCliOptionsSchema).options;
1977
+ }
1978
+ function getOutputCliKeys() {
1979
+ return keyof(OutputCliOptionsSchema).options;
1980
+ }
1981
+ function getCliSchemaInfo() {
1982
+ return flattenValibotSchema(CliOptionsSchema);
1983
+ }
1984
+
1985
+ //#endregion
1986
+ //#region src/types/rolldown-output-impl.ts
1987
+ var RolldownOutputImpl = class extends PlainObjectLike {
1988
+ constructor(bindingOutputs) {
1989
+ super();
1990
+ this.bindingOutputs = bindingOutputs;
1991
+ }
1992
+ get output() {
1993
+ return transformToRollupOutput(this.bindingOutputs).output;
1994
+ }
1995
+ __rolldown_external_memory_handle__(keepDataAlive) {
1996
+ const results = this.output.map((item) => item.__rolldown_external_memory_handle__(keepDataAlive));
1997
+ if (!results.every((r) => r.freed)) {
1998
+ const reasons = results.filter((r) => !r.freed).map((r) => r.reason).filter(Boolean);
1999
+ return {
2000
+ freed: false,
2001
+ reason: `Failed to free ${reasons.length} item(s): ${reasons.join("; ")}`
2002
+ };
2003
+ }
2004
+ return { freed: true };
2005
+ }
2006
+ };
2007
+ __decorate([lazyProp], RolldownOutputImpl.prototype, "output", null);
2008
+
2009
+ //#endregion
2010
+ //#region src/types/chunking-context.ts
2011
+ var ChunkingContextImpl = class {
2012
+ constructor(context) {
2013
+ this.context = context;
2014
+ }
2015
+ getModuleInfo(moduleId) {
2016
+ const bindingInfo = this.context.getModuleInfo(moduleId);
2017
+ if (bindingInfo) return transformModuleInfo(bindingInfo, {
2018
+ moduleSideEffects: null,
2019
+ meta: {}
2020
+ });
2021
+ return null;
2022
+ }
2023
+ };
2024
+
2025
+ //#endregion
2026
+ //#region src/utils/bindingify-output-options.ts
2027
+ function bindingifyOutputOptions(outputOptions) {
2028
+ const { dir, format, exports, hashCharacters, sourcemap, sourcemapBaseUrl, sourcemapDebugIds, sourcemapIgnoreList, sourcemapPathTransform, name, assetFileNames, entryFileNames, chunkFileNames, cssEntryFileNames, cssChunkFileNames, banner, footer, postBanner, postFooter, intro, outro, esModule, globals, paths, generatedCode, file, sanitizeFileName, preserveModules, virtualDirname, legalComments, preserveModulesRoot, manualChunks, topLevelVar, cleanDir } = outputOptions;
2029
+ if (outputOptions.inlineDynamicImports === true) {
2030
+ if (manualChunks != null) throw new Error("Invalid value \"true\" for option \"output.inlineDynamicImports\" - this option is not supported for \"output.manualChunks\".");
2031
+ }
2032
+ const advancedChunks = bindingifyAdvancedChunks(outputOptions.codeSplitting, outputOptions.advancedChunks, manualChunks);
2033
+ return {
2034
+ dir,
2035
+ file: file == null ? void 0 : file,
2036
+ format: bindingifyFormat(format),
2037
+ exports,
2038
+ hashCharacters,
2039
+ sourcemap: bindingifySourcemap(sourcemap),
2040
+ sourcemapBaseUrl,
2041
+ sourcemapDebugIds,
2042
+ sourcemapIgnoreList: sourcemapIgnoreList ?? /node_modules/,
2043
+ sourcemapPathTransform,
2044
+ banner: bindingifyAddon(banner),
2045
+ footer: bindingifyAddon(footer),
2046
+ postBanner: bindingifyAddon(postBanner),
2047
+ postFooter: bindingifyAddon(postFooter),
2048
+ intro: bindingifyAddon(intro),
2049
+ outro: bindingifyAddon(outro),
2050
+ extend: outputOptions.extend,
2051
+ globals,
2052
+ paths,
2053
+ generatedCode,
2054
+ esModule,
2055
+ name,
2056
+ assetFileNames: bindingifyAssetFilenames(assetFileNames),
2057
+ entryFileNames,
2058
+ chunkFileNames,
2059
+ cssEntryFileNames,
2060
+ cssChunkFileNames,
2061
+ plugins: [],
2062
+ minify: outputOptions.minify,
2063
+ externalLiveBindings: outputOptions.externalLiveBindings,
2064
+ inlineDynamicImports: outputOptions.inlineDynamicImports,
2065
+ dynamicImportInCjs: outputOptions.dynamicImportInCjs,
2066
+ manualCodeSplitting: advancedChunks,
2067
+ polyfillRequire: outputOptions.polyfillRequire,
2068
+ sanitizeFileName,
2069
+ preserveModules,
2070
+ virtualDirname,
2071
+ legalComments,
2072
+ preserveModulesRoot,
2073
+ topLevelVar,
2074
+ minifyInternalExports: outputOptions.minifyInternalExports,
2075
+ cleanDir
2076
+ };
2077
+ }
2078
+ function bindingifyAddon(configAddon) {
2079
+ if (configAddon == null || configAddon === "") return;
2080
+ if (typeof configAddon === "function") return async (chunk) => configAddon(transformRenderedChunk(chunk));
2081
+ return configAddon;
2082
+ }
2083
+ function bindingifyFormat(format) {
2084
+ switch (format) {
2085
+ case void 0:
2086
+ case "es":
2087
+ case "esm":
2088
+ case "module": return "es";
2089
+ case "cjs":
2090
+ case "commonjs": return "cjs";
2091
+ case "iife": return "iife";
2092
+ case "umd": return "umd";
2093
+ default: unimplemented(`output.format: ${format}`);
2094
+ }
2095
+ }
2096
+ function bindingifySourcemap(sourcemap) {
2097
+ switch (sourcemap) {
2098
+ case true: return "file";
2099
+ case "inline": return "inline";
2100
+ case false:
2101
+ case void 0: return;
2102
+ case "hidden": return "hidden";
2103
+ default: throw new Error(`unknown sourcemap: ${sourcemap}`);
2104
+ }
2105
+ }
2106
+ function bindingifyAssetFilenames(assetFileNames) {
2107
+ if (typeof assetFileNames === "function") return (asset) => {
2108
+ return assetFileNames({
2109
+ name: asset.name,
2110
+ names: asset.names,
2111
+ originalFileName: asset.originalFileName,
2112
+ originalFileNames: asset.originalFileNames,
2113
+ source: transformAssetSource(asset.source),
2114
+ type: "asset"
2115
+ });
2116
+ };
2117
+ return assetFileNames;
2118
+ }
2119
+ function bindingifyAdvancedChunks(codeSplitting, advancedChunks, manualChunks) {
2120
+ let effectiveOption = codeSplitting;
2121
+ if (codeSplitting != null && advancedChunks != null) console.warn("`advancedChunks` option is ignored due to `codeSplitting` option is specified.");
2122
+ else if (codeSplitting == null && advancedChunks != null) {
2123
+ console.warn("`advancedChunks` option is deprecated, please use `codeSplitting` instead.");
2124
+ effectiveOption = advancedChunks;
2125
+ }
2126
+ if (manualChunks != null && effectiveOption != null) console.warn("`manualChunks` option is ignored due to `codeSplitting` option is specified.");
2127
+ else if (manualChunks != null) effectiveOption = { groups: [{ name(moduleId, ctx) {
2128
+ return manualChunks(moduleId, { getModuleInfo: (id) => ctx.getModuleInfo(id) });
2129
+ } }] };
2130
+ if (effectiveOption == null) return;
2131
+ const { groups, ...restOptions } = effectiveOption;
2132
+ return {
2133
+ ...restOptions,
2134
+ groups: groups?.map((group) => {
2135
+ const { name, ...restGroup } = group;
2136
+ return {
2137
+ ...restGroup,
2138
+ name: typeof name === "function" ? (id, ctx) => name(id, new ChunkingContextImpl(ctx)) : name
2139
+ };
2140
+ })
2141
+ };
2142
+ }
2143
+
2144
+ //#endregion
2145
+ //#region src/utils/initialize-parallel-plugins.ts
2146
+ var import_binding = /* @__PURE__ */ __toESM(require_binding(), 1);
2147
+ async function initializeParallelPlugins(plugins) {
2148
+ const pluginInfos = [];
2149
+ for (const [index, plugin] of plugins.entries()) if ("_parallel" in plugin) {
2150
+ const { fileUrl, options } = plugin._parallel;
2151
+ pluginInfos.push({
2152
+ index,
2153
+ fileUrl,
2154
+ options
2155
+ });
2156
+ }
2157
+ if (pluginInfos.length <= 0) return;
2158
+ const count = availableParallelism();
2159
+ const parallelJsPluginRegistry = new import_binding.ParallelJsPluginRegistry(count);
2160
+ const registryId = parallelJsPluginRegistry.id;
2161
+ const workers = await initializeWorkers(registryId, count, pluginInfos);
2162
+ const stopWorkers = async () => {
2163
+ await Promise.all(workers.map((worker) => worker.terminate()));
2164
+ };
2165
+ return {
2166
+ registry: parallelJsPluginRegistry,
2167
+ stopWorkers
2168
+ };
2169
+ }
2170
+ function initializeWorkers(registryId, count, pluginInfos) {
2171
+ return Promise.all(Array.from({ length: count }, (_, i) => initializeWorker(registryId, pluginInfos, i)));
2172
+ }
2173
+ async function initializeWorker(registryId, pluginInfos, threadNumber) {
2174
+ const urlString = import.meta.resolve("#parallel-plugin-worker");
2175
+ const workerData$1 = {
2176
+ registryId,
2177
+ pluginInfos,
2178
+ threadNumber
2179
+ };
2180
+ let worker;
2181
+ try {
2182
+ worker = new Worker(new URL(urlString), { workerData: workerData$1 });
2183
+ worker.unref();
2184
+ await new Promise((resolve, reject) => {
2185
+ worker.once("message", async (message) => {
2186
+ if (message.type === "error") reject(message.error);
2187
+ else resolve();
2188
+ });
2189
+ });
2190
+ return worker;
2191
+ } catch (e) {
2192
+ worker?.terminate();
2193
+ throw e;
2194
+ }
2195
+ }
2196
+ const availableParallelism = () => {
2197
+ let availableParallelism = 1;
2198
+ try {
2199
+ availableParallelism = os.availableParallelism();
2200
+ } catch {
2201
+ const cpus = os.cpus();
2202
+ if (Array.isArray(cpus) && cpus.length > 0) availableParallelism = cpus.length;
2203
+ }
2204
+ return Math.min(availableParallelism, 8);
2205
+ };
2206
+
2207
+ //#endregion
2208
+ //#region src/utils/create-bundler-option.ts
2209
+ async function createBundlerOptions(inputOptions, outputOptions, watchMode) {
2210
+ const inputPlugins = await normalizePluginOption(inputOptions.plugins);
2211
+ const outputPlugins = await normalizePluginOption(outputOptions.plugins);
2212
+ const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
2213
+ const onLog = getLogger(getObjectPlugins(inputPlugins), getOnLog(inputOptions, logLevel), logLevel, watchMode);
2214
+ outputOptions = PluginDriver.callOutputOptionsHook([...inputPlugins, ...outputPlugins], outputOptions, onLog, logLevel, watchMode);
2215
+ const normalizedOutputPlugins = await normalizePluginOption(outputOptions.plugins);
2216
+ let plugins = [...normalizePlugins(inputPlugins, ANONYMOUS_PLUGIN_PREFIX), ...checkOutputPluginOption(normalizePlugins(normalizedOutputPlugins, ANONYMOUS_OUTPUT_PLUGIN_PREFIX), onLog)];
2217
+ const parallelPluginInitResult = await initializeParallelPlugins(plugins);
2218
+ try {
2219
+ return {
2220
+ bundlerOptions: {
2221
+ inputOptions: bindingifyInputOptions(plugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode),
2222
+ outputOptions: bindingifyOutputOptions(outputOptions),
2223
+ parallelPluginsRegistry: parallelPluginInitResult?.registry
2224
+ },
2225
+ inputOptions,
2226
+ onLog,
2227
+ stopWorkers: parallelPluginInitResult?.stopWorkers
2228
+ };
2229
+ } catch (e) {
2230
+ await parallelPluginInitResult?.stopWorkers();
2231
+ throw e;
2232
+ }
2233
+ }
2234
+
2235
+ //#endregion
2236
+ //#region src/api/rolldown/rolldown-build.ts
2237
+ Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
2238
+ /** @category Programmatic APIs */
2239
+ var RolldownBuild = class RolldownBuild {
2240
+ #inputOptions;
2241
+ #bundler;
2242
+ #stopWorkers;
2243
+ static asyncRuntimeShutdown = false;
2244
+ constructor(inputOptions) {
2245
+ this.#inputOptions = inputOptions;
2246
+ this.#bundler = new import_binding.BindingBundler();
2247
+ }
2248
+ get closed() {
2249
+ return this.#bundler.closed;
2250
+ }
2251
+ async generate(outputOptions = {}) {
2252
+ return this.#build(false, outputOptions);
2253
+ }
2254
+ async write(outputOptions = {}) {
2255
+ return this.#build(true, outputOptions);
2256
+ }
2257
+ /**
2258
+ * Close the build and free resources.
2259
+ */
2260
+ async close() {
2261
+ await this.#stopWorkers?.();
2262
+ await this.#bundler.close();
2263
+ (0, import_binding.shutdownAsyncRuntime)();
2264
+ RolldownBuild.asyncRuntimeShutdown = true;
2265
+ this.#stopWorkers = void 0;
2266
+ }
2267
+ async [Symbol.asyncDispose]() {
2268
+ await this.close();
2269
+ }
2270
+ get watchFiles() {
2271
+ return Promise.resolve(this.#bundler.getWatchFiles());
2272
+ }
2273
+ async #build(isWrite, outputOptions) {
2274
+ validateOption("output", outputOptions);
2275
+ await this.#stopWorkers?.();
2276
+ const option = await createBundlerOptions(this.#inputOptions, outputOptions, false);
2277
+ if (RolldownBuild.asyncRuntimeShutdown) (0, import_binding.startAsyncRuntime)();
2278
+ try {
2279
+ this.#stopWorkers = option.stopWorkers;
2280
+ let output;
2281
+ if (isWrite) output = await this.#bundler.write(option.bundlerOptions);
2282
+ else output = await this.#bundler.generate(option.bundlerOptions);
2283
+ return new RolldownOutputImpl(unwrapBindingResult(output));
2284
+ } catch (e) {
2285
+ await option.stopWorkers?.();
2286
+ throw e;
2287
+ }
2288
+ }
2289
+ };
2290
+
2291
+ //#endregion
2292
+ export { getOutputCliKeys as a, styleText$1 as c, getInputCliKeys as i, PluginDriver as l, createBundlerOptions as n, validateCliOptions as o, getCliSchemaInfo as r, validateOption as s, RolldownBuild as t };