@rolldown/browser 1.0.0-beta.35 → 1.0.0-beta.37

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 (51) hide show
  1. package/dist/cli.mjs +96 -1069
  2. package/dist/config.d.mts +2 -2
  3. package/dist/config.mjs +4 -4
  4. package/dist/experimental-index.browser.mjs +493 -7
  5. package/dist/experimental-index.d.mts +43 -5
  6. package/dist/experimental-index.mjs +32 -9
  7. package/dist/filter-index.d.mts +2 -2
  8. package/dist/filter-index.mjs +1 -1
  9. package/dist/index.browser.mjs +1 -1
  10. package/dist/index.d.mts +3 -3
  11. package/dist/index.mjs +3 -3
  12. package/dist/parallel-plugin-worker.mjs +4 -5
  13. package/dist/parallel-plugin.d.mts +2 -2
  14. package/dist/parse-ast-index.d.mts +1 -1
  15. package/dist/parse-ast-index.mjs +1 -1
  16. package/dist/rolldown-binding.wasi-browser.js +1 -0
  17. package/dist/rolldown-binding.wasi.cjs +1 -0
  18. package/dist/rolldown-binding.wasm32-wasi.wasm +0 -0
  19. package/dist/shared/{binding-9k0egz6L.d.mts → binding-Cjs27cfu.d.mts} +1 -0
  20. package/dist/shared/{define-config-DhrkZ_o7.d.cts → define-config-DzsPS4fI.d.mts} +8 -8
  21. package/dist/shared/{dist-ByKQkexh.mjs → dist-CHTC3-kR.mjs} +1 -1
  22. package/dist/shared/{load-config-BCjD-AGJ.mjs → load-config-efyGD8HY.mjs} +4 -6
  23. package/dist/{cli.cjs → shared/logger-CiCY7ucm.mjs} +34 -817
  24. package/dist/shared/{parse-ast-index-C_CZT4St.mjs → parse-ast-index-C3TkGcEQ.mjs} +1 -1
  25. package/dist/shared/{prompt-C5jz26Zn.mjs → prompt-D2FxOcB5.mjs} +4 -7
  26. package/dist/shared/{src-B0RCtUy7.mjs → src-kVjGhYdF.mjs} +89 -70
  27. package/dist/{src-C8U06Im1.js → src-C2GHZXDs.js} +88 -70
  28. package/package.json +10 -24
  29. package/dist/cli.d.cts +0 -1
  30. package/dist/config.cjs +0 -12
  31. package/dist/config.d.cts +0 -10
  32. package/dist/experimental-index.cjs +0 -176
  33. package/dist/experimental-index.d.cts +0 -99
  34. package/dist/filter-index.cjs +0 -53
  35. package/dist/filter-index.d.cts +0 -4
  36. package/dist/index.cjs +0 -9
  37. package/dist/index.d.cts +0 -3
  38. package/dist/parallel-plugin-worker.cjs +0 -35
  39. package/dist/parallel-plugin-worker.d.cts +0 -1
  40. package/dist/parallel-plugin.cjs +0 -8
  41. package/dist/parallel-plugin.d.cts +0 -14
  42. package/dist/parse-ast-index.cjs +0 -4
  43. package/dist/parse-ast-index.d.cts +0 -8
  44. package/dist/shared/binding-D13M6Llu.d.cts +0 -1425
  45. package/dist/shared/chunk-DDkG_k5U.cjs +0 -39
  46. package/dist/shared/define-config-DJXaSinS.d.mts +0 -1421
  47. package/dist/shared/dist-CK0hotcm.cjs +0 -240
  48. package/dist/shared/load-config-BJKhRKZL.cjs +0 -130
  49. package/dist/shared/parse-ast-index-J0xVKZRe.cjs +0 -327
  50. package/dist/shared/prompt-Q05EYrFb.cjs +0 -858
  51. package/dist/shared/src-Bd4BGX4v.cjs +0 -4788
@@ -1,4788 +0,0 @@
1
- const require_chunk = require('./chunk-DDkG_k5U.cjs');
2
- const require_parse_ast_index = require('./parse-ast-index-J0xVKZRe.cjs');
3
- const require_dist = require('./dist-CK0hotcm.cjs');
4
- let node_worker_threads = require("node:worker_threads");
5
- node_worker_threads = require_chunk.__toESM(node_worker_threads);
6
- let src_rolldown_binding_wasi_cjs = require("../rolldown-binding.wasi.cjs");
7
- src_rolldown_binding_wasi_cjs = require_chunk.__toESM(src_rolldown_binding_wasi_cjs);
8
- let node_path = require("node:path");
9
- node_path = require_chunk.__toESM(node_path);
10
- let node_url = require("node:url");
11
- node_url = require_chunk.__toESM(node_url);
12
- let node_fs_promises = require("node:fs/promises");
13
- node_fs_promises = require_chunk.__toESM(node_fs_promises);
14
- let node_os = require("node:os");
15
- node_os = require_chunk.__toESM(node_os);
16
-
17
- //#region package.json
18
- var version = "1.0.0-beta.35";
19
- var description$1 = "Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.";
20
-
21
- //#endregion
22
- //#region src/builtin-plugin/utils.ts
23
- const BuiltinClassSymbol = Symbol.for("__RolldownBuiltinPlugin__");
24
- var BuiltinPlugin = class {
25
- constructor(name, _options) {
26
- this.name = name;
27
- this._options = _options;
28
- this[BuiltinClassSymbol] = true;
29
- }
30
- };
31
- function isBuiltinPlugin(obj) {
32
- return obj && obj[BuiltinClassSymbol] === true;
33
- }
34
- function createBuiltinPlugin(name, options) {
35
- return new BuiltinPlugin(name, options);
36
- }
37
- function makeBuiltinPluginCallable(plugin) {
38
- let callablePlugin = new src_rolldown_binding_wasi_cjs.BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
39
- const wrappedPlugin = plugin;
40
- for (const key in callablePlugin) wrappedPlugin[key] = async function(...args$1) {
41
- try {
42
- return await callablePlugin[key](...args$1);
43
- } catch (e$2) {
44
- if (e$2 instanceof Error && !e$2.stack?.includes("at ")) Error.captureStackTrace(e$2, wrappedPlugin[key]);
45
- return require_parse_ast_index.error(require_parse_ast_index.logPluginError(e$2, plugin.name, {
46
- hook: key,
47
- id: key === "transform" ? args$1[2] : void 0
48
- }));
49
- }
50
- };
51
- return wrappedPlugin;
52
- }
53
- function bindingifyBuiltInPlugin(plugin) {
54
- return {
55
- __name: plugin.name,
56
- options: plugin._options
57
- };
58
- }
59
-
60
- //#endregion
61
- //#region src/log/logging.ts
62
- const LOG_LEVEL_SILENT = "silent";
63
- const LOG_LEVEL_ERROR = "error";
64
- const LOG_LEVEL_WARN = "warn";
65
- const LOG_LEVEL_INFO = "info";
66
- const LOG_LEVEL_DEBUG = "debug";
67
- const logLevelPriority = {
68
- [LOG_LEVEL_DEBUG]: 0,
69
- [LOG_LEVEL_INFO]: 1,
70
- [LOG_LEVEL_WARN]: 2,
71
- [LOG_LEVEL_SILENT]: 3
72
- };
73
-
74
- //#endregion
75
- //#region src/log/log-handler.ts
76
- const normalizeLog = (log) => typeof log === "string" ? { message: log } : typeof log === "function" ? normalizeLog(log()) : log;
77
- function getLogHandler(level, code$1, logger, pluginName, logLevel) {
78
- if (logLevelPriority[level] < logLevelPriority[logLevel]) return require_dist.noop;
79
- return (log, pos) => {
80
- if (pos != null) logger(LOG_LEVEL_WARN, require_parse_ast_index.logInvalidLogPosition(pluginName));
81
- log = normalizeLog(log);
82
- if (log.code && !log.pluginCode) log.pluginCode = log.code;
83
- log.code = code$1;
84
- log.plugin = pluginName;
85
- logger(level, log);
86
- };
87
- }
88
-
89
- //#endregion
90
- //#region src/log/logger.ts
91
- function getLogger(plugins, onLog, logLevel, watchMode) {
92
- const minimalPriority = logLevelPriority[logLevel];
93
- const logger = (level, log, skipped = /* @__PURE__ */ new Set()) => {
94
- const logPriority = logLevelPriority[level];
95
- if (logPriority < minimalPriority) return;
96
- for (const plugin of getSortedPlugins("onLog", plugins)) {
97
- if (skipped.has(plugin)) continue;
98
- const { onLog: pluginOnLog } = plugin;
99
- if (pluginOnLog) {
100
- const getLogHandler$1 = (level$1) => {
101
- if (logLevelPriority[level$1] < minimalPriority) return () => {};
102
- return (log$1) => logger(level$1, normalizeLog(log$1), new Set(skipped).add(plugin));
103
- };
104
- const handler = "handler" in pluginOnLog ? pluginOnLog.handler : pluginOnLog;
105
- if (handler.call({
106
- debug: getLogHandler$1(LOG_LEVEL_DEBUG),
107
- error: (log$1) => require_parse_ast_index.error(normalizeLog(log$1)),
108
- info: getLogHandler$1(LOG_LEVEL_INFO),
109
- meta: {
110
- rollupVersion: "4.23.0",
111
- rolldownVersion: VERSION,
112
- watchMode
113
- },
114
- warn: getLogHandler$1(LOG_LEVEL_WARN),
115
- pluginName: plugin.name || "unknown"
116
- }, level, log) === false) return;
117
- }
118
- }
119
- onLog(level, log);
120
- };
121
- return logger;
122
- }
123
- const getOnLog = (config, logLevel, printLog = defaultPrintLog) => {
124
- const { onwarn, onLog } = config;
125
- const defaultOnLog = getDefaultOnLog(printLog, onwarn);
126
- if (onLog) {
127
- const minimalPriority = logLevelPriority[logLevel];
128
- return (level, log) => onLog(level, addLogToString(log), (level$1, handledLog) => {
129
- if (level$1 === LOG_LEVEL_ERROR) return require_parse_ast_index.error(normalizeLog(handledLog));
130
- if (logLevelPriority[level$1] >= minimalPriority) defaultOnLog(level$1, normalizeLog(handledLog));
131
- });
132
- }
133
- return defaultOnLog;
134
- };
135
- const getDefaultOnLog = (printLog, onwarn) => onwarn ? (level, log) => {
136
- if (level === LOG_LEVEL_WARN) onwarn(addLogToString(log), (warning) => printLog(LOG_LEVEL_WARN, normalizeLog(warning)));
137
- else printLog(level, log);
138
- } : printLog;
139
- const addLogToString = (log) => {
140
- Object.defineProperty(log, "toString", {
141
- value: () => getExtendedLogMessage(log),
142
- writable: true
143
- });
144
- return log;
145
- };
146
- const defaultPrintLog = (level, log) => {
147
- const message = getExtendedLogMessage(log);
148
- switch (level) {
149
- case LOG_LEVEL_WARN: return console.warn(message);
150
- case LOG_LEVEL_DEBUG: return console.debug(message);
151
- default: return console.info(message);
152
- }
153
- };
154
- const getExtendedLogMessage = (log) => {
155
- let prefix = "";
156
- if (log.plugin) prefix += `(${log.plugin} plugin) `;
157
- if (log.loc) prefix += `${relativeId(log.loc.file)} (${log.loc.line}:${log.loc.column}) `;
158
- return prefix + log.message;
159
- };
160
- function relativeId(id$1) {
161
- if (!node_path.default.isAbsolute(id$1)) return id$1;
162
- return node_path.default.relative(node_path.default.resolve(), id$1);
163
- }
164
-
165
- //#endregion
166
- //#region src/utils/normalize-hook.ts
167
- function normalizeHook(hook) {
168
- if (typeof hook === "function" || typeof hook === "string") return {
169
- handler: hook,
170
- options: {},
171
- meta: {}
172
- };
173
- if (typeof hook === "object" && hook !== null) {
174
- const { handler, order,...options } = hook;
175
- return {
176
- handler,
177
- options,
178
- meta: { order }
179
- };
180
- }
181
- require_dist.unreachable("Invalid hook type");
182
- }
183
-
184
- //#endregion
185
- //#region src/utils/normalize-string-or-regex.ts
186
- function normalizedStringOrRegex(pattern) {
187
- if (!pattern) return void 0;
188
- if (!isReadonlyArray(pattern)) return [pattern];
189
- return pattern;
190
- }
191
- function isReadonlyArray(input) {
192
- return Array.isArray(input);
193
- }
194
-
195
- //#endregion
196
- //#region src/builtin-plugin/constructors.ts
197
- function modulePreloadPolyfillPlugin(config) {
198
- return createBuiltinPlugin("builtin:module-preload-polyfill", config);
199
- }
200
- function dynamicImportVarsPlugin(config) {
201
- if (config) {
202
- config.include = normalizedStringOrRegex(config.include);
203
- config.exclude = normalizedStringOrRegex(config.exclude);
204
- }
205
- return createBuiltinPlugin("builtin:dynamic-import-vars", config);
206
- }
207
- function importGlobPlugin(config) {
208
- return createBuiltinPlugin("builtin:import-glob", config);
209
- }
210
- function reporterPlugin(config) {
211
- return createBuiltinPlugin("builtin:reporter", config);
212
- }
213
- function manifestPlugin(config) {
214
- return createBuiltinPlugin("builtin:manifest", config);
215
- }
216
- function wasmHelperPlugin(config) {
217
- return createBuiltinPlugin("builtin:wasm-helper", config);
218
- }
219
- function wasmFallbackPlugin() {
220
- const builtinPlugin = createBuiltinPlugin("builtin:wasm-fallback");
221
- return makeBuiltinPluginCallable(builtinPlugin);
222
- }
223
- function loadFallbackPlugin() {
224
- return createBuiltinPlugin("builtin:load-fallback");
225
- }
226
- function jsonPlugin(config) {
227
- const builtinPlugin = createBuiltinPlugin("builtin:json", config);
228
- return makeBuiltinPluginCallable(builtinPlugin);
229
- }
230
- function buildImportAnalysisPlugin(config) {
231
- return createBuiltinPlugin("builtin:build-import-analysis", config);
232
- }
233
- function viteResolvePlugin(config) {
234
- const builtinPlugin = createBuiltinPlugin("builtin:vite-resolve", config);
235
- return makeBuiltinPluginCallable(builtinPlugin);
236
- }
237
- function isolatedDeclarationPlugin(config) {
238
- return createBuiltinPlugin("builtin:isolated-declaration", config);
239
- }
240
- function assetPlugin(config) {
241
- return createBuiltinPlugin("builtin:asset", config);
242
- }
243
- function webWorkerPostPlugin() {
244
- return createBuiltinPlugin("builtin:web-worker-post");
245
- }
246
- function oxcRuntimePlugin(config) {
247
- return createBuiltinPlugin("builtin:oxc-runtime", config);
248
- }
249
- function esmExternalRequirePlugin(config) {
250
- return createBuiltinPlugin("builtin:esm-external-require", config);
251
- }
252
-
253
- //#endregion
254
- //#region src/constants/plugin.ts
255
- const ENUMERATED_INPUT_PLUGIN_HOOK_NAMES = [
256
- "options",
257
- "buildStart",
258
- "resolveId",
259
- "load",
260
- "transform",
261
- "moduleParsed",
262
- "buildEnd",
263
- "onLog",
264
- "resolveDynamicImport",
265
- "closeBundle",
266
- "closeWatcher",
267
- "watchChange"
268
- ];
269
- const ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES = [
270
- "augmentChunkHash",
271
- "outputOptions",
272
- "renderChunk",
273
- "renderStart",
274
- "renderError",
275
- "writeBundle",
276
- "generateBundle"
277
- ];
278
- const ENUMERATED_PLUGIN_HOOK_NAMES = [
279
- ...ENUMERATED_INPUT_PLUGIN_HOOK_NAMES,
280
- ...ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES,
281
- "footer",
282
- "banner",
283
- "intro",
284
- "outro"
285
- ];
286
- /**
287
- * Names of all defined hooks. It's like
288
- * ```js
289
- * const DEFINED_HOOK_NAMES ={
290
- * options: 'options',
291
- * buildStart: 'buildStart',
292
- * ...
293
- * }
294
- * ```
295
- */
296
- const DEFINED_HOOK_NAMES = {
297
- [ENUMERATED_PLUGIN_HOOK_NAMES[0]]: ENUMERATED_PLUGIN_HOOK_NAMES[0],
298
- [ENUMERATED_PLUGIN_HOOK_NAMES[1]]: ENUMERATED_PLUGIN_HOOK_NAMES[1],
299
- [ENUMERATED_PLUGIN_HOOK_NAMES[2]]: ENUMERATED_PLUGIN_HOOK_NAMES[2],
300
- [ENUMERATED_PLUGIN_HOOK_NAMES[3]]: ENUMERATED_PLUGIN_HOOK_NAMES[3],
301
- [ENUMERATED_PLUGIN_HOOK_NAMES[4]]: ENUMERATED_PLUGIN_HOOK_NAMES[4],
302
- [ENUMERATED_PLUGIN_HOOK_NAMES[5]]: ENUMERATED_PLUGIN_HOOK_NAMES[5],
303
- [ENUMERATED_PLUGIN_HOOK_NAMES[6]]: ENUMERATED_PLUGIN_HOOK_NAMES[6],
304
- [ENUMERATED_PLUGIN_HOOK_NAMES[7]]: ENUMERATED_PLUGIN_HOOK_NAMES[7],
305
- [ENUMERATED_PLUGIN_HOOK_NAMES[8]]: ENUMERATED_PLUGIN_HOOK_NAMES[8],
306
- [ENUMERATED_PLUGIN_HOOK_NAMES[9]]: ENUMERATED_PLUGIN_HOOK_NAMES[9],
307
- [ENUMERATED_PLUGIN_HOOK_NAMES[10]]: ENUMERATED_PLUGIN_HOOK_NAMES[10],
308
- [ENUMERATED_PLUGIN_HOOK_NAMES[11]]: ENUMERATED_PLUGIN_HOOK_NAMES[11],
309
- [ENUMERATED_PLUGIN_HOOK_NAMES[12]]: ENUMERATED_PLUGIN_HOOK_NAMES[12],
310
- [ENUMERATED_PLUGIN_HOOK_NAMES[13]]: ENUMERATED_PLUGIN_HOOK_NAMES[13],
311
- [ENUMERATED_PLUGIN_HOOK_NAMES[14]]: ENUMERATED_PLUGIN_HOOK_NAMES[14],
312
- [ENUMERATED_PLUGIN_HOOK_NAMES[15]]: ENUMERATED_PLUGIN_HOOK_NAMES[15],
313
- [ENUMERATED_PLUGIN_HOOK_NAMES[16]]: ENUMERATED_PLUGIN_HOOK_NAMES[16],
314
- [ENUMERATED_PLUGIN_HOOK_NAMES[17]]: ENUMERATED_PLUGIN_HOOK_NAMES[17],
315
- [ENUMERATED_PLUGIN_HOOK_NAMES[18]]: ENUMERATED_PLUGIN_HOOK_NAMES[18],
316
- [ENUMERATED_PLUGIN_HOOK_NAMES[19]]: ENUMERATED_PLUGIN_HOOK_NAMES[19],
317
- [ENUMERATED_PLUGIN_HOOK_NAMES[20]]: ENUMERATED_PLUGIN_HOOK_NAMES[20],
318
- [ENUMERATED_PLUGIN_HOOK_NAMES[21]]: ENUMERATED_PLUGIN_HOOK_NAMES[21],
319
- [ENUMERATED_PLUGIN_HOOK_NAMES[22]]: ENUMERATED_PLUGIN_HOOK_NAMES[22]
320
- };
321
-
322
- //#endregion
323
- //#region src/utils/async-flatten.ts
324
- async function asyncFlatten(array$1) {
325
- do
326
- array$1 = (await Promise.all(array$1)).flat(Infinity);
327
- while (array$1.some((v) => v?.then));
328
- return array$1;
329
- }
330
-
331
- //#endregion
332
- //#region src/utils/normalize-plugin-option.ts
333
- const normalizePluginOption = async (plugins) => (await asyncFlatten([plugins])).filter(Boolean);
334
- function checkOutputPluginOption(plugins, onLog) {
335
- for (const plugin of plugins) for (const hook of ENUMERATED_INPUT_PLUGIN_HOOK_NAMES) if (hook in plugin) {
336
- delete plugin[hook];
337
- onLog(LOG_LEVEL_WARN, require_parse_ast_index.logInputHookInOutputPlugin(plugin.name, hook));
338
- }
339
- return plugins;
340
- }
341
- function normalizePlugins(plugins, anonymousPrefix) {
342
- for (const [index, plugin] of plugins.entries()) {
343
- if ("_parallel" in plugin) continue;
344
- if (isBuiltinPlugin(plugin)) continue;
345
- if (!plugin.name) plugin.name = `${anonymousPrefix}${index + 1}`;
346
- }
347
- return plugins;
348
- }
349
- const ANONYMOUS_PLUGIN_PREFIX = "at position ";
350
- const ANONYMOUS_OUTPUT_PLUGIN_PREFIX = "at output position ";
351
- const BUILTIN_PLUGINS = [oxcRuntimePlugin({ resolveBase: (0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href) })];
352
-
353
- //#endregion
354
- //#region src/plugin/minimal-plugin-context.ts
355
- var MinimalPluginContextImpl = class {
356
- info;
357
- warn;
358
- debug;
359
- meta;
360
- constructor(onLog, logLevel, pluginName, watchMode, hookName) {
361
- this.pluginName = pluginName;
362
- this.hookName = hookName;
363
- this.debug = getLogHandler(LOG_LEVEL_DEBUG, "PLUGIN_LOG", onLog, pluginName, logLevel);
364
- this.info = getLogHandler(LOG_LEVEL_INFO, "PLUGIN_LOG", onLog, pluginName, logLevel);
365
- this.warn = getLogHandler(LOG_LEVEL_WARN, "PLUGIN_WARNING", onLog, pluginName, logLevel);
366
- this.meta = {
367
- rollupVersion: "4.23.0",
368
- rolldownVersion: VERSION,
369
- watchMode
370
- };
371
- }
372
- error(e$2) {
373
- return require_parse_ast_index.error(require_parse_ast_index.logPluginError(normalizeLog(e$2), this.pluginName, { hook: this.hookName }));
374
- }
375
- };
376
-
377
- //#endregion
378
- //#region src/plugin/plugin-driver.ts
379
- var PluginDriver = class {
380
- static async callOptionsHook(inputOptions, watchMode = false) {
381
- const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
382
- const plugins = getSortedPlugins("options", getObjectPlugins(await normalizePluginOption(inputOptions.plugins)));
383
- const logger = getLogger(plugins, getOnLog(inputOptions, logLevel), logLevel, watchMode);
384
- for (const plugin of plugins) {
385
- const name = plugin.name || "unknown";
386
- const options = plugin.options;
387
- if (options) {
388
- const { handler } = normalizeHook(options);
389
- const result = await handler.call(new MinimalPluginContextImpl(logger, logLevel, name, watchMode, "onLog"), inputOptions);
390
- if (result) inputOptions = result;
391
- }
392
- }
393
- return inputOptions;
394
- }
395
- static callOutputOptionsHook(rawPlugins, outputOptions, onLog, logLevel, watchMode) {
396
- const sortedPlugins = getSortedPlugins("outputOptions", getObjectPlugins(rawPlugins));
397
- for (const plugin of sortedPlugins) {
398
- const name = plugin.name || "unknown";
399
- const options = plugin.outputOptions;
400
- if (options) {
401
- const { handler } = normalizeHook(options);
402
- const result = handler.call(new MinimalPluginContextImpl(onLog, logLevel, name, watchMode), outputOptions);
403
- if (result) outputOptions = result;
404
- }
405
- }
406
- return outputOptions;
407
- }
408
- };
409
- function getObjectPlugins(plugins) {
410
- return plugins.filter((plugin) => {
411
- if (!plugin) return void 0;
412
- if ("_parallel" in plugin) return void 0;
413
- if (isBuiltinPlugin(plugin)) return void 0;
414
- return plugin;
415
- });
416
- }
417
- function getSortedPlugins(hookName, plugins) {
418
- const pre = [];
419
- const normal = [];
420
- const post = [];
421
- for (const plugin of plugins) {
422
- const hook = plugin[hookName];
423
- if (hook) {
424
- if (typeof hook === "object") {
425
- if (hook.order === "pre") {
426
- pre.push(plugin);
427
- continue;
428
- }
429
- if (hook.order === "post") {
430
- post.push(plugin);
431
- continue;
432
- }
433
- }
434
- normal.push(plugin);
435
- }
436
- }
437
- return [
438
- ...pre,
439
- ...normal,
440
- ...post
441
- ];
442
- }
443
-
444
- //#endregion
445
- //#region ../../node_modules/.pnpm/valibot@1.1.0_typescript@5.9.2/node_modules/valibot/dist/index.js
446
- var store$1;
447
- /* @__NO_SIDE_EFFECTS__ */
448
- function getGlobalConfig(config2) {
449
- return {
450
- lang: config2?.lang ?? store$1?.lang,
451
- message: config2?.message,
452
- abortEarly: config2?.abortEarly ?? store$1?.abortEarly,
453
- abortPipeEarly: config2?.abortPipeEarly ?? store$1?.abortPipeEarly
454
- };
455
- }
456
- var store2;
457
- /* @__NO_SIDE_EFFECTS__ */
458
- function getGlobalMessage(lang) {
459
- return store2?.get(lang);
460
- }
461
- var store3;
462
- /* @__NO_SIDE_EFFECTS__ */
463
- function getSchemaMessage(lang) {
464
- return store3?.get(lang);
465
- }
466
- var store4;
467
- /* @__NO_SIDE_EFFECTS__ */
468
- function getSpecificMessage(reference, lang) {
469
- return store4?.get(reference)?.get(lang);
470
- }
471
- /* @__NO_SIDE_EFFECTS__ */
472
- function _stringify(input) {
473
- const type = typeof input;
474
- if (type === "string") return `"${input}"`;
475
- if (type === "number" || type === "bigint" || type === "boolean") return `${input}`;
476
- if (type === "object" || type === "function") return (input && Object.getPrototypeOf(input)?.constructor?.name) ?? "null";
477
- return type;
478
- }
479
- function _addIssue(context, label, dataset, config2, other) {
480
- const input = other && "input" in other ? other.input : dataset.value;
481
- const expected = other?.expected ?? context.expects ?? null;
482
- const received = other?.received ?? /* @__PURE__ */ _stringify(input);
483
- const issue = {
484
- kind: context.kind,
485
- type: context.type,
486
- input,
487
- expected,
488
- received,
489
- message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
490
- requirement: context.requirement,
491
- path: other?.path,
492
- issues: other?.issues,
493
- lang: config2.lang,
494
- abortEarly: config2.abortEarly,
495
- abortPipeEarly: config2.abortPipeEarly
496
- };
497
- const isSchema = context.kind === "schema";
498
- const message2 = other?.message ?? context.message ?? /* @__PURE__ */ getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? /* @__PURE__ */ getSchemaMessage(issue.lang) : null) ?? config2.message ?? /* @__PURE__ */ getGlobalMessage(issue.lang);
499
- if (message2 !== void 0) issue.message = typeof message2 === "function" ? message2(issue) : message2;
500
- if (isSchema) dataset.typed = false;
501
- if (dataset.issues) dataset.issues.push(issue);
502
- else dataset.issues = [issue];
503
- }
504
- /* @__NO_SIDE_EFFECTS__ */
505
- function _getStandardProps(context) {
506
- return {
507
- version: 1,
508
- vendor: "valibot",
509
- validate(value2) {
510
- return context["~run"]({ value: value2 }, /* @__PURE__ */ getGlobalConfig());
511
- }
512
- };
513
- }
514
- /* @__NO_SIDE_EFFECTS__ */
515
- function _isValidObjectKey(object2, key) {
516
- return Object.hasOwn(object2, key) && key !== "__proto__" && key !== "prototype" && key !== "constructor";
517
- }
518
- /* @__NO_SIDE_EFFECTS__ */
519
- function _joinExpects(values2, separator) {
520
- const list = [...new Set(values2)];
521
- if (list.length > 1) return `(${list.join(` ${separator} `)})`;
522
- return list[0] ?? "never";
523
- }
524
- var ValiError = class extends Error {
525
- /**
526
- * Creates a Valibot error with useful information.
527
- *
528
- * @param issues The error issues.
529
- */
530
- constructor(issues) {
531
- super(issues[0].message);
532
- this.name = "ValiError";
533
- this.issues = issues;
534
- }
535
- };
536
- /* @__NO_SIDE_EFFECTS__ */
537
- function args(schema) {
538
- return {
539
- kind: "transformation",
540
- type: "args",
541
- reference: args,
542
- async: false,
543
- schema,
544
- "~run"(dataset, config2) {
545
- const func = dataset.value;
546
- dataset.value = (...args_) => {
547
- const argsDataset = this.schema["~run"]({ value: args_ }, config2);
548
- if (argsDataset.issues) throw new ValiError(argsDataset.issues);
549
- return func(...argsDataset.value);
550
- };
551
- return dataset;
552
- }
553
- };
554
- }
555
- /* @__NO_SIDE_EFFECTS__ */
556
- function awaitAsync() {
557
- return {
558
- kind: "transformation",
559
- type: "await",
560
- reference: awaitAsync,
561
- async: true,
562
- async "~run"(dataset) {
563
- dataset.value = await dataset.value;
564
- return dataset;
565
- }
566
- };
567
- }
568
- /* @__NO_SIDE_EFFECTS__ */
569
- function description(description_) {
570
- return {
571
- kind: "metadata",
572
- type: "description",
573
- reference: description,
574
- description: description_
575
- };
576
- }
577
- /* @__NO_SIDE_EFFECTS__ */
578
- function returns(schema) {
579
- return {
580
- kind: "transformation",
581
- type: "returns",
582
- reference: returns,
583
- async: false,
584
- schema,
585
- "~run"(dataset, config2) {
586
- const func = dataset.value;
587
- dataset.value = (...args_) => {
588
- const returnsDataset = this.schema["~run"]({ value: func(...args_) }, config2);
589
- if (returnsDataset.issues) throw new ValiError(returnsDataset.issues);
590
- return returnsDataset.value;
591
- };
592
- return dataset;
593
- }
594
- };
595
- }
596
- /* @__NO_SIDE_EFFECTS__ */
597
- function returnsAsync(schema) {
598
- return {
599
- kind: "transformation",
600
- type: "returns",
601
- reference: returnsAsync,
602
- async: false,
603
- schema,
604
- "~run"(dataset, config2) {
605
- const func = dataset.value;
606
- dataset.value = async (...args_) => {
607
- const returnsDataset = await this.schema["~run"]({ value: await func(...args_) }, config2);
608
- if (returnsDataset.issues) throw new ValiError(returnsDataset.issues);
609
- return returnsDataset.value;
610
- };
611
- return dataset;
612
- }
613
- };
614
- }
615
- /* @__NO_SIDE_EFFECTS__ */
616
- function getFallback(schema, dataset, config2) {
617
- return typeof schema.fallback === "function" ? schema.fallback(dataset, config2) : schema.fallback;
618
- }
619
- /* @__NO_SIDE_EFFECTS__ */
620
- function getDefault(schema, dataset, config2) {
621
- return typeof schema.default === "function" ? schema.default(dataset, config2) : schema.default;
622
- }
623
- /* @__NO_SIDE_EFFECTS__ */
624
- function any() {
625
- return {
626
- kind: "schema",
627
- type: "any",
628
- reference: any,
629
- expects: "any",
630
- async: false,
631
- get "~standard"() {
632
- return /* @__PURE__ */ _getStandardProps(this);
633
- },
634
- "~run"(dataset) {
635
- dataset.typed = true;
636
- return dataset;
637
- }
638
- };
639
- }
640
- /* @__NO_SIDE_EFFECTS__ */
641
- function array(item, message2) {
642
- return {
643
- kind: "schema",
644
- type: "array",
645
- reference: array,
646
- expects: "Array",
647
- async: false,
648
- item,
649
- message: message2,
650
- get "~standard"() {
651
- return /* @__PURE__ */ _getStandardProps(this);
652
- },
653
- "~run"(dataset, config2) {
654
- const input = dataset.value;
655
- if (Array.isArray(input)) {
656
- dataset.typed = true;
657
- dataset.value = [];
658
- for (let key = 0; key < input.length; key++) {
659
- const value2 = input[key];
660
- const itemDataset = this.item["~run"]({ value: value2 }, config2);
661
- if (itemDataset.issues) {
662
- const pathItem = {
663
- type: "array",
664
- origin: "value",
665
- input,
666
- key,
667
- value: value2
668
- };
669
- for (const issue of itemDataset.issues) {
670
- if (issue.path) issue.path.unshift(pathItem);
671
- else issue.path = [pathItem];
672
- dataset.issues?.push(issue);
673
- }
674
- if (!dataset.issues) dataset.issues = itemDataset.issues;
675
- if (config2.abortEarly) {
676
- dataset.typed = false;
677
- break;
678
- }
679
- }
680
- if (!itemDataset.typed) dataset.typed = false;
681
- dataset.value.push(itemDataset.value);
682
- }
683
- } else _addIssue(this, "type", dataset, config2);
684
- return dataset;
685
- }
686
- };
687
- }
688
- /* @__NO_SIDE_EFFECTS__ */
689
- function boolean(message2) {
690
- return {
691
- kind: "schema",
692
- type: "boolean",
693
- reference: boolean,
694
- expects: "boolean",
695
- async: false,
696
- message: message2,
697
- get "~standard"() {
698
- return /* @__PURE__ */ _getStandardProps(this);
699
- },
700
- "~run"(dataset, config2) {
701
- if (typeof dataset.value === "boolean") dataset.typed = true;
702
- else _addIssue(this, "type", dataset, config2);
703
- return dataset;
704
- }
705
- };
706
- }
707
- /* @__NO_SIDE_EFFECTS__ */
708
- function custom(check2, message2) {
709
- return {
710
- kind: "schema",
711
- type: "custom",
712
- reference: custom,
713
- expects: "unknown",
714
- async: false,
715
- check: check2,
716
- message: message2,
717
- get "~standard"() {
718
- return /* @__PURE__ */ _getStandardProps(this);
719
- },
720
- "~run"(dataset, config2) {
721
- if (this.check(dataset.value)) dataset.typed = true;
722
- else _addIssue(this, "type", dataset, config2);
723
- return dataset;
724
- }
725
- };
726
- }
727
- /* @__NO_SIDE_EFFECTS__ */
728
- function function_(message2) {
729
- return {
730
- kind: "schema",
731
- type: "function",
732
- reference: function_,
733
- expects: "Function",
734
- async: false,
735
- message: message2,
736
- get "~standard"() {
737
- return /* @__PURE__ */ _getStandardProps(this);
738
- },
739
- "~run"(dataset, config2) {
740
- if (typeof dataset.value === "function") dataset.typed = true;
741
- else _addIssue(this, "type", dataset, config2);
742
- return dataset;
743
- }
744
- };
745
- }
746
- /* @__NO_SIDE_EFFECTS__ */
747
- function instance(class_, message2) {
748
- return {
749
- kind: "schema",
750
- type: "instance",
751
- reference: instance,
752
- expects: class_.name,
753
- async: false,
754
- class: class_,
755
- message: message2,
756
- get "~standard"() {
757
- return /* @__PURE__ */ _getStandardProps(this);
758
- },
759
- "~run"(dataset, config2) {
760
- if (dataset.value instanceof this.class) dataset.typed = true;
761
- else _addIssue(this, "type", dataset, config2);
762
- return dataset;
763
- }
764
- };
765
- }
766
- /* @__NO_SIDE_EFFECTS__ */
767
- function literal(literal_, message2) {
768
- return {
769
- kind: "schema",
770
- type: "literal",
771
- reference: literal,
772
- expects: /* @__PURE__ */ _stringify(literal_),
773
- async: false,
774
- literal: literal_,
775
- message: message2,
776
- get "~standard"() {
777
- return /* @__PURE__ */ _getStandardProps(this);
778
- },
779
- "~run"(dataset, config2) {
780
- if (dataset.value === this.literal) dataset.typed = true;
781
- else _addIssue(this, "type", dataset, config2);
782
- return dataset;
783
- }
784
- };
785
- }
786
- /* @__NO_SIDE_EFFECTS__ */
787
- function looseObject(entries2, message2) {
788
- return {
789
- kind: "schema",
790
- type: "loose_object",
791
- reference: looseObject,
792
- expects: "Object",
793
- async: false,
794
- entries: entries2,
795
- message: message2,
796
- get "~standard"() {
797
- return /* @__PURE__ */ _getStandardProps(this);
798
- },
799
- "~run"(dataset, config2) {
800
- const input = dataset.value;
801
- if (input && typeof input === "object") {
802
- dataset.typed = true;
803
- dataset.value = {};
804
- for (const key in this.entries) {
805
- const valueSchema = this.entries[key];
806
- if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
807
- const value2 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
808
- const valueDataset = valueSchema["~run"]({ value: value2 }, config2);
809
- if (valueDataset.issues) {
810
- const pathItem = {
811
- type: "object",
812
- origin: "value",
813
- input,
814
- key,
815
- value: value2
816
- };
817
- for (const issue of valueDataset.issues) {
818
- if (issue.path) issue.path.unshift(pathItem);
819
- else issue.path = [pathItem];
820
- dataset.issues?.push(issue);
821
- }
822
- if (!dataset.issues) dataset.issues = valueDataset.issues;
823
- if (config2.abortEarly) {
824
- dataset.typed = false;
825
- break;
826
- }
827
- }
828
- if (!valueDataset.typed) dataset.typed = false;
829
- dataset.value[key] = valueDataset.value;
830
- } else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
831
- else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
832
- _addIssue(this, "key", dataset, config2, {
833
- input: void 0,
834
- expected: `"${key}"`,
835
- path: [{
836
- type: "object",
837
- origin: "key",
838
- input,
839
- key,
840
- value: input[key]
841
- }]
842
- });
843
- if (config2.abortEarly) break;
844
- }
845
- }
846
- if (!dataset.issues || !config2.abortEarly) {
847
- for (const key in input) if (/* @__PURE__ */ _isValidObjectKey(input, key) && !(key in this.entries)) dataset.value[key] = input[key];
848
- }
849
- } else _addIssue(this, "type", dataset, config2);
850
- return dataset;
851
- }
852
- };
853
- }
854
- /* @__NO_SIDE_EFFECTS__ */
855
- function never(message2) {
856
- return {
857
- kind: "schema",
858
- type: "never",
859
- reference: never,
860
- expects: "never",
861
- async: false,
862
- message: message2,
863
- get "~standard"() {
864
- return /* @__PURE__ */ _getStandardProps(this);
865
- },
866
- "~run"(dataset, config2) {
867
- _addIssue(this, "type", dataset, config2);
868
- return dataset;
869
- }
870
- };
871
- }
872
- /* @__NO_SIDE_EFFECTS__ */
873
- function nullish(wrapped, default_) {
874
- return {
875
- kind: "schema",
876
- type: "nullish",
877
- reference: nullish,
878
- expects: `(${wrapped.expects} | null | undefined)`,
879
- async: false,
880
- wrapped,
881
- default: default_,
882
- get "~standard"() {
883
- return /* @__PURE__ */ _getStandardProps(this);
884
- },
885
- "~run"(dataset, config2) {
886
- if (dataset.value === null || dataset.value === void 0) {
887
- if (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config2);
888
- if (dataset.value === null || dataset.value === void 0) {
889
- dataset.typed = true;
890
- return dataset;
891
- }
892
- }
893
- return this.wrapped["~run"](dataset, config2);
894
- }
895
- };
896
- }
897
- /* @__NO_SIDE_EFFECTS__ */
898
- function number(message2) {
899
- return {
900
- kind: "schema",
901
- type: "number",
902
- reference: number,
903
- expects: "number",
904
- async: false,
905
- message: message2,
906
- get "~standard"() {
907
- return /* @__PURE__ */ _getStandardProps(this);
908
- },
909
- "~run"(dataset, config2) {
910
- if (typeof dataset.value === "number" && !isNaN(dataset.value)) dataset.typed = true;
911
- else _addIssue(this, "type", dataset, config2);
912
- return dataset;
913
- }
914
- };
915
- }
916
- /* @__NO_SIDE_EFFECTS__ */
917
- function object(entries2, message2) {
918
- return {
919
- kind: "schema",
920
- type: "object",
921
- reference: object,
922
- expects: "Object",
923
- async: false,
924
- entries: entries2,
925
- message: message2,
926
- get "~standard"() {
927
- return /* @__PURE__ */ _getStandardProps(this);
928
- },
929
- "~run"(dataset, config2) {
930
- const input = dataset.value;
931
- if (input && typeof input === "object") {
932
- dataset.typed = true;
933
- dataset.value = {};
934
- for (const key in this.entries) {
935
- const valueSchema = this.entries[key];
936
- if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
937
- const value2 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
938
- const valueDataset = valueSchema["~run"]({ value: value2 }, config2);
939
- if (valueDataset.issues) {
940
- const pathItem = {
941
- type: "object",
942
- origin: "value",
943
- input,
944
- key,
945
- value: value2
946
- };
947
- for (const issue of valueDataset.issues) {
948
- if (issue.path) issue.path.unshift(pathItem);
949
- else issue.path = [pathItem];
950
- dataset.issues?.push(issue);
951
- }
952
- if (!dataset.issues) dataset.issues = valueDataset.issues;
953
- if (config2.abortEarly) {
954
- dataset.typed = false;
955
- break;
956
- }
957
- }
958
- if (!valueDataset.typed) dataset.typed = false;
959
- dataset.value[key] = valueDataset.value;
960
- } else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
961
- else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
962
- _addIssue(this, "key", dataset, config2, {
963
- input: void 0,
964
- expected: `"${key}"`,
965
- path: [{
966
- type: "object",
967
- origin: "key",
968
- input,
969
- key,
970
- value: input[key]
971
- }]
972
- });
973
- if (config2.abortEarly) break;
974
- }
975
- }
976
- } else _addIssue(this, "type", dataset, config2);
977
- return dataset;
978
- }
979
- };
980
- }
981
- /* @__NO_SIDE_EFFECTS__ */
982
- function optional(wrapped, default_) {
983
- return {
984
- kind: "schema",
985
- type: "optional",
986
- reference: optional,
987
- expects: `(${wrapped.expects} | undefined)`,
988
- async: false,
989
- wrapped,
990
- default: default_,
991
- get "~standard"() {
992
- return /* @__PURE__ */ _getStandardProps(this);
993
- },
994
- "~run"(dataset, config2) {
995
- if (dataset.value === void 0) {
996
- if (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config2);
997
- if (dataset.value === void 0) {
998
- dataset.typed = true;
999
- return dataset;
1000
- }
1001
- }
1002
- return this.wrapped["~run"](dataset, config2);
1003
- }
1004
- };
1005
- }
1006
- /* @__NO_SIDE_EFFECTS__ */
1007
- function picklist(options, message2) {
1008
- return {
1009
- kind: "schema",
1010
- type: "picklist",
1011
- reference: picklist,
1012
- expects: /* @__PURE__ */ _joinExpects(options.map(_stringify), "|"),
1013
- async: false,
1014
- options,
1015
- message: message2,
1016
- get "~standard"() {
1017
- return /* @__PURE__ */ _getStandardProps(this);
1018
- },
1019
- "~run"(dataset, config2) {
1020
- if (this.options.includes(dataset.value)) dataset.typed = true;
1021
- else _addIssue(this, "type", dataset, config2);
1022
- return dataset;
1023
- }
1024
- };
1025
- }
1026
- /* @__NO_SIDE_EFFECTS__ */
1027
- function promise(message2) {
1028
- return {
1029
- kind: "schema",
1030
- type: "promise",
1031
- reference: promise,
1032
- expects: "Promise",
1033
- async: false,
1034
- message: message2,
1035
- get "~standard"() {
1036
- return /* @__PURE__ */ _getStandardProps(this);
1037
- },
1038
- "~run"(dataset, config2) {
1039
- if (dataset.value instanceof Promise) dataset.typed = true;
1040
- else _addIssue(this, "type", dataset, config2);
1041
- return dataset;
1042
- }
1043
- };
1044
- }
1045
- /* @__NO_SIDE_EFFECTS__ */
1046
- function record(key, value2, message2) {
1047
- return {
1048
- kind: "schema",
1049
- type: "record",
1050
- reference: record,
1051
- expects: "Object",
1052
- async: false,
1053
- key,
1054
- value: value2,
1055
- message: message2,
1056
- get "~standard"() {
1057
- return /* @__PURE__ */ _getStandardProps(this);
1058
- },
1059
- "~run"(dataset, config2) {
1060
- const input = dataset.value;
1061
- if (input && typeof input === "object") {
1062
- dataset.typed = true;
1063
- dataset.value = {};
1064
- for (const entryKey in input) if (/* @__PURE__ */ _isValidObjectKey(input, entryKey)) {
1065
- const entryValue = input[entryKey];
1066
- const keyDataset = this.key["~run"]({ value: entryKey }, config2);
1067
- if (keyDataset.issues) {
1068
- const pathItem = {
1069
- type: "object",
1070
- origin: "key",
1071
- input,
1072
- key: entryKey,
1073
- value: entryValue
1074
- };
1075
- for (const issue of keyDataset.issues) {
1076
- issue.path = [pathItem];
1077
- dataset.issues?.push(issue);
1078
- }
1079
- if (!dataset.issues) dataset.issues = keyDataset.issues;
1080
- if (config2.abortEarly) {
1081
- dataset.typed = false;
1082
- break;
1083
- }
1084
- }
1085
- const valueDataset = this.value["~run"]({ value: entryValue }, config2);
1086
- if (valueDataset.issues) {
1087
- const pathItem = {
1088
- type: "object",
1089
- origin: "value",
1090
- input,
1091
- key: entryKey,
1092
- value: entryValue
1093
- };
1094
- for (const issue of valueDataset.issues) {
1095
- if (issue.path) issue.path.unshift(pathItem);
1096
- else issue.path = [pathItem];
1097
- dataset.issues?.push(issue);
1098
- }
1099
- if (!dataset.issues) dataset.issues = valueDataset.issues;
1100
- if (config2.abortEarly) {
1101
- dataset.typed = false;
1102
- break;
1103
- }
1104
- }
1105
- if (!keyDataset.typed || !valueDataset.typed) dataset.typed = false;
1106
- if (keyDataset.typed) dataset.value[keyDataset.value] = valueDataset.value;
1107
- }
1108
- } else _addIssue(this, "type", dataset, config2);
1109
- return dataset;
1110
- }
1111
- };
1112
- }
1113
- /* @__NO_SIDE_EFFECTS__ */
1114
- function strictObject(entries2, message2) {
1115
- return {
1116
- kind: "schema",
1117
- type: "strict_object",
1118
- reference: strictObject,
1119
- expects: "Object",
1120
- async: false,
1121
- entries: entries2,
1122
- message: message2,
1123
- get "~standard"() {
1124
- return /* @__PURE__ */ _getStandardProps(this);
1125
- },
1126
- "~run"(dataset, config2) {
1127
- const input = dataset.value;
1128
- if (input && typeof input === "object") {
1129
- dataset.typed = true;
1130
- dataset.value = {};
1131
- for (const key in this.entries) {
1132
- const valueSchema = this.entries[key];
1133
- if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) {
1134
- const value2 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema);
1135
- const valueDataset = valueSchema["~run"]({ value: value2 }, config2);
1136
- if (valueDataset.issues) {
1137
- const pathItem = {
1138
- type: "object",
1139
- origin: "value",
1140
- input,
1141
- key,
1142
- value: value2
1143
- };
1144
- for (const issue of valueDataset.issues) {
1145
- if (issue.path) issue.path.unshift(pathItem);
1146
- else issue.path = [pathItem];
1147
- dataset.issues?.push(issue);
1148
- }
1149
- if (!dataset.issues) dataset.issues = valueDataset.issues;
1150
- if (config2.abortEarly) {
1151
- dataset.typed = false;
1152
- break;
1153
- }
1154
- }
1155
- if (!valueDataset.typed) dataset.typed = false;
1156
- dataset.value[key] = valueDataset.value;
1157
- } else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema);
1158
- else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") {
1159
- _addIssue(this, "key", dataset, config2, {
1160
- input: void 0,
1161
- expected: `"${key}"`,
1162
- path: [{
1163
- type: "object",
1164
- origin: "key",
1165
- input,
1166
- key,
1167
- value: input[key]
1168
- }]
1169
- });
1170
- if (config2.abortEarly) break;
1171
- }
1172
- }
1173
- if (!dataset.issues || !config2.abortEarly) {
1174
- for (const key in input) if (!(key in this.entries)) {
1175
- _addIssue(this, "key", dataset, config2, {
1176
- input: key,
1177
- expected: "never",
1178
- path: [{
1179
- type: "object",
1180
- origin: "key",
1181
- input,
1182
- key,
1183
- value: input[key]
1184
- }]
1185
- });
1186
- break;
1187
- }
1188
- }
1189
- } else _addIssue(this, "type", dataset, config2);
1190
- return dataset;
1191
- }
1192
- };
1193
- }
1194
- /* @__NO_SIDE_EFFECTS__ */
1195
- function string(message2) {
1196
- return {
1197
- kind: "schema",
1198
- type: "string",
1199
- reference: string,
1200
- expects: "string",
1201
- async: false,
1202
- message: message2,
1203
- get "~standard"() {
1204
- return /* @__PURE__ */ _getStandardProps(this);
1205
- },
1206
- "~run"(dataset, config2) {
1207
- if (typeof dataset.value === "string") dataset.typed = true;
1208
- else _addIssue(this, "type", dataset, config2);
1209
- return dataset;
1210
- }
1211
- };
1212
- }
1213
- /* @__NO_SIDE_EFFECTS__ */
1214
- function tuple(items, message2) {
1215
- return {
1216
- kind: "schema",
1217
- type: "tuple",
1218
- reference: tuple,
1219
- expects: "Array",
1220
- async: false,
1221
- items,
1222
- message: message2,
1223
- get "~standard"() {
1224
- return /* @__PURE__ */ _getStandardProps(this);
1225
- },
1226
- "~run"(dataset, config2) {
1227
- const input = dataset.value;
1228
- if (Array.isArray(input)) {
1229
- dataset.typed = true;
1230
- dataset.value = [];
1231
- for (let key = 0; key < this.items.length; key++) {
1232
- const value2 = input[key];
1233
- const itemDataset = this.items[key]["~run"]({ value: value2 }, config2);
1234
- if (itemDataset.issues) {
1235
- const pathItem = {
1236
- type: "array",
1237
- origin: "value",
1238
- input,
1239
- key,
1240
- value: value2
1241
- };
1242
- for (const issue of itemDataset.issues) {
1243
- if (issue.path) issue.path.unshift(pathItem);
1244
- else issue.path = [pathItem];
1245
- dataset.issues?.push(issue);
1246
- }
1247
- if (!dataset.issues) dataset.issues = itemDataset.issues;
1248
- if (config2.abortEarly) {
1249
- dataset.typed = false;
1250
- break;
1251
- }
1252
- }
1253
- if (!itemDataset.typed) dataset.typed = false;
1254
- dataset.value.push(itemDataset.value);
1255
- }
1256
- } else _addIssue(this, "type", dataset, config2);
1257
- return dataset;
1258
- }
1259
- };
1260
- }
1261
- /* @__NO_SIDE_EFFECTS__ */
1262
- function _subIssues(datasets) {
1263
- let issues;
1264
- if (datasets) for (const dataset of datasets) if (issues) issues.push(...dataset.issues);
1265
- else issues = dataset.issues;
1266
- return issues;
1267
- }
1268
- /* @__NO_SIDE_EFFECTS__ */
1269
- function union(options, message2) {
1270
- return {
1271
- kind: "schema",
1272
- type: "union",
1273
- reference: union,
1274
- expects: /* @__PURE__ */ _joinExpects(options.map((option) => option.expects), "|"),
1275
- async: false,
1276
- options,
1277
- message: message2,
1278
- get "~standard"() {
1279
- return /* @__PURE__ */ _getStandardProps(this);
1280
- },
1281
- "~run"(dataset, config2) {
1282
- let validDataset;
1283
- let typedDatasets;
1284
- let untypedDatasets;
1285
- for (const schema of this.options) {
1286
- const optionDataset = schema["~run"]({ value: dataset.value }, config2);
1287
- if (optionDataset.typed) if (optionDataset.issues) if (typedDatasets) typedDatasets.push(optionDataset);
1288
- else typedDatasets = [optionDataset];
1289
- else {
1290
- validDataset = optionDataset;
1291
- break;
1292
- }
1293
- else if (untypedDatasets) untypedDatasets.push(optionDataset);
1294
- else untypedDatasets = [optionDataset];
1295
- }
1296
- if (validDataset) return validDataset;
1297
- if (typedDatasets) {
1298
- if (typedDatasets.length === 1) return typedDatasets[0];
1299
- _addIssue(this, "type", dataset, config2, { issues: /* @__PURE__ */ _subIssues(typedDatasets) });
1300
- dataset.typed = true;
1301
- } else if (untypedDatasets?.length === 1) return untypedDatasets[0];
1302
- else _addIssue(this, "type", dataset, config2, { issues: /* @__PURE__ */ _subIssues(untypedDatasets) });
1303
- return dataset;
1304
- }
1305
- };
1306
- }
1307
- /* @__NO_SIDE_EFFECTS__ */
1308
- function unionAsync(options, message2) {
1309
- return {
1310
- kind: "schema",
1311
- type: "union",
1312
- reference: unionAsync,
1313
- expects: /* @__PURE__ */ _joinExpects(options.map((option) => option.expects), "|"),
1314
- async: true,
1315
- options,
1316
- message: message2,
1317
- get "~standard"() {
1318
- return /* @__PURE__ */ _getStandardProps(this);
1319
- },
1320
- async "~run"(dataset, config2) {
1321
- let validDataset;
1322
- let typedDatasets;
1323
- let untypedDatasets;
1324
- for (const schema of this.options) {
1325
- const optionDataset = await schema["~run"]({ value: dataset.value }, config2);
1326
- if (optionDataset.typed) if (optionDataset.issues) if (typedDatasets) typedDatasets.push(optionDataset);
1327
- else typedDatasets = [optionDataset];
1328
- else {
1329
- validDataset = optionDataset;
1330
- break;
1331
- }
1332
- else if (untypedDatasets) untypedDatasets.push(optionDataset);
1333
- else untypedDatasets = [optionDataset];
1334
- }
1335
- if (validDataset) return validDataset;
1336
- if (typedDatasets) {
1337
- if (typedDatasets.length === 1) return typedDatasets[0];
1338
- _addIssue(this, "type", dataset, config2, { issues: /* @__PURE__ */ _subIssues(typedDatasets) });
1339
- dataset.typed = true;
1340
- } else if (untypedDatasets?.length === 1) return untypedDatasets[0];
1341
- else _addIssue(this, "type", dataset, config2, { issues: /* @__PURE__ */ _subIssues(untypedDatasets) });
1342
- return dataset;
1343
- }
1344
- };
1345
- }
1346
- /* @__NO_SIDE_EFFECTS__ */
1347
- function void_(message2) {
1348
- return {
1349
- kind: "schema",
1350
- type: "void",
1351
- reference: void_,
1352
- expects: "void",
1353
- async: false,
1354
- message: message2,
1355
- get "~standard"() {
1356
- return /* @__PURE__ */ _getStandardProps(this);
1357
- },
1358
- "~run"(dataset, config2) {
1359
- if (dataset.value === void 0) dataset.typed = true;
1360
- else _addIssue(this, "type", dataset, config2);
1361
- return dataset;
1362
- }
1363
- };
1364
- }
1365
- /* @__NO_SIDE_EFFECTS__ */
1366
- function keyof(schema, message2) {
1367
- return /* @__PURE__ */ picklist(Object.keys(schema.entries), message2);
1368
- }
1369
- /* @__NO_SIDE_EFFECTS__ */
1370
- function omit(schema, keys) {
1371
- const entries2 = { ...schema.entries };
1372
- for (const key of keys) delete entries2[key];
1373
- return {
1374
- ...schema,
1375
- entries: entries2,
1376
- get "~standard"() {
1377
- return /* @__PURE__ */ _getStandardProps(this);
1378
- }
1379
- };
1380
- }
1381
- /* @__NO_SIDE_EFFECTS__ */
1382
- function pipe(...pipe2) {
1383
- return {
1384
- ...pipe2[0],
1385
- pipe: pipe2,
1386
- get "~standard"() {
1387
- return /* @__PURE__ */ _getStandardProps(this);
1388
- },
1389
- "~run"(dataset, config2) {
1390
- for (const item of pipe2) if (item.kind !== "metadata") {
1391
- if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
1392
- dataset.typed = false;
1393
- break;
1394
- }
1395
- if (!dataset.issues || !config2.abortEarly && !config2.abortPipeEarly) dataset = item["~run"](dataset, config2);
1396
- }
1397
- return dataset;
1398
- }
1399
- };
1400
- }
1401
- /* @__NO_SIDE_EFFECTS__ */
1402
- function pipeAsync(...pipe2) {
1403
- return {
1404
- ...pipe2[0],
1405
- pipe: pipe2,
1406
- async: true,
1407
- get "~standard"() {
1408
- return /* @__PURE__ */ _getStandardProps(this);
1409
- },
1410
- async "~run"(dataset, config2) {
1411
- for (const item of pipe2) if (item.kind !== "metadata") {
1412
- if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) {
1413
- dataset.typed = false;
1414
- break;
1415
- }
1416
- if (!dataset.issues || !config2.abortEarly && !config2.abortPipeEarly) dataset = await item["~run"](dataset, config2);
1417
- }
1418
- return dataset;
1419
- }
1420
- };
1421
- }
1422
- /* @__NO_SIDE_EFFECTS__ */
1423
- function safeParse(schema, input, config2) {
1424
- const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config2));
1425
- return {
1426
- typed: dataset.typed,
1427
- success: !dataset.issues,
1428
- output: dataset.value,
1429
- issues: dataset.issues
1430
- };
1431
- }
1432
-
1433
- //#endregion
1434
- //#region ../../node_modules/.pnpm/@valibot+to-json-schema@1.3.0_valibot@1.1.0_typescript@5.9.2_/node_modules/@valibot/to-json-schema/dist/index.js
1435
- /**
1436
- * Adds an error message to the errors array.
1437
- *
1438
- * @param errors The array of error messages.
1439
- * @param message The error message to add.
1440
- *
1441
- * @returns The new errors.
1442
- */
1443
- function addError(errors, message) {
1444
- if (errors) {
1445
- errors.push(message);
1446
- return errors;
1447
- }
1448
- return [message];
1449
- }
1450
- /**
1451
- * Throws an error or logs a warning based on the configuration.
1452
- *
1453
- * @param message The message to throw or log.
1454
- * @param config The conversion configuration.
1455
- */
1456
- function handleError(message, config) {
1457
- switch (config?.errorMode) {
1458
- case "ignore": break;
1459
- case "warn":
1460
- console.warn(message);
1461
- break;
1462
- default: throw new Error(message);
1463
- }
1464
- }
1465
- /**
1466
- * Converts any supported Valibot action to the JSON Schema format.
1467
- *
1468
- * @param jsonSchema The JSON Schema object.
1469
- * @param valibotAction The Valibot action object.
1470
- * @param config The conversion configuration.
1471
- *
1472
- * @returns The converted JSON Schema.
1473
- */
1474
- function convertAction(jsonSchema, valibotAction, config) {
1475
- if (config?.ignoreActions?.includes(valibotAction.type)) return jsonSchema;
1476
- let errors;
1477
- switch (valibotAction.type) {
1478
- case "base64":
1479
- jsonSchema.contentEncoding = "base64";
1480
- break;
1481
- case "bic":
1482
- case "cuid2":
1483
- case "decimal":
1484
- case "digits":
1485
- case "emoji":
1486
- case "hexadecimal":
1487
- case "hex_color":
1488
- case "nanoid":
1489
- case "octal":
1490
- case "ulid":
1491
- jsonSchema.pattern = valibotAction.requirement.source;
1492
- break;
1493
- case "description":
1494
- jsonSchema.description = valibotAction.description;
1495
- break;
1496
- case "email":
1497
- jsonSchema.format = "email";
1498
- break;
1499
- case "empty":
1500
- if (jsonSchema.type === "array") jsonSchema.maxItems = 0;
1501
- else {
1502
- if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
1503
- jsonSchema.maxLength = 0;
1504
- }
1505
- break;
1506
- case "entries":
1507
- jsonSchema.minProperties = valibotAction.requirement;
1508
- jsonSchema.maxProperties = valibotAction.requirement;
1509
- break;
1510
- case "integer":
1511
- jsonSchema.type = "integer";
1512
- break;
1513
- case "ipv4":
1514
- jsonSchema.format = "ipv4";
1515
- break;
1516
- case "ipv6":
1517
- jsonSchema.format = "ipv6";
1518
- break;
1519
- case "iso_date":
1520
- jsonSchema.format = "date";
1521
- break;
1522
- case "iso_date_time":
1523
- case "iso_timestamp":
1524
- jsonSchema.format = "date-time";
1525
- break;
1526
- case "iso_time":
1527
- jsonSchema.format = "time";
1528
- break;
1529
- case "length":
1530
- if (jsonSchema.type === "array") {
1531
- jsonSchema.minItems = valibotAction.requirement;
1532
- jsonSchema.maxItems = valibotAction.requirement;
1533
- } else {
1534
- if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
1535
- jsonSchema.minLength = valibotAction.requirement;
1536
- jsonSchema.maxLength = valibotAction.requirement;
1537
- }
1538
- break;
1539
- case "max_entries":
1540
- jsonSchema.maxProperties = valibotAction.requirement;
1541
- break;
1542
- case "max_length":
1543
- if (jsonSchema.type === "array") jsonSchema.maxItems = valibotAction.requirement;
1544
- else {
1545
- if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
1546
- jsonSchema.maxLength = valibotAction.requirement;
1547
- }
1548
- break;
1549
- case "max_value":
1550
- if (jsonSchema.type !== "number") errors = addError(errors, `The "max_value" action is not supported on type "${jsonSchema.type}".`);
1551
- jsonSchema.maximum = valibotAction.requirement;
1552
- break;
1553
- case "metadata":
1554
- if (typeof valibotAction.metadata.title === "string") jsonSchema.title = valibotAction.metadata.title;
1555
- if (typeof valibotAction.metadata.description === "string") jsonSchema.description = valibotAction.metadata.description;
1556
- if (Array.isArray(valibotAction.metadata.examples)) jsonSchema.examples = valibotAction.metadata.examples;
1557
- break;
1558
- case "min_entries":
1559
- jsonSchema.minProperties = valibotAction.requirement;
1560
- break;
1561
- case "min_length":
1562
- if (jsonSchema.type === "array") jsonSchema.minItems = valibotAction.requirement;
1563
- else {
1564
- if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
1565
- jsonSchema.minLength = valibotAction.requirement;
1566
- }
1567
- break;
1568
- case "min_value":
1569
- if (jsonSchema.type !== "number") errors = addError(errors, `The "min_value" action is not supported on type "${jsonSchema.type}".`);
1570
- jsonSchema.minimum = valibotAction.requirement;
1571
- break;
1572
- case "multiple_of":
1573
- jsonSchema.multipleOf = valibotAction.requirement;
1574
- break;
1575
- case "non_empty":
1576
- if (jsonSchema.type === "array") jsonSchema.minItems = 1;
1577
- else {
1578
- if (jsonSchema.type !== "string") errors = addError(errors, `The "${valibotAction.type}" action is not supported on type "${jsonSchema.type}".`);
1579
- jsonSchema.minLength = 1;
1580
- }
1581
- break;
1582
- case "regex":
1583
- if (valibotAction.requirement.flags) errors = addError(errors, "RegExp flags are not supported by JSON Schema.");
1584
- jsonSchema.pattern = valibotAction.requirement.source;
1585
- break;
1586
- case "title":
1587
- jsonSchema.title = valibotAction.title;
1588
- break;
1589
- case "url":
1590
- jsonSchema.format = "uri";
1591
- break;
1592
- case "uuid":
1593
- jsonSchema.format = "uuid";
1594
- break;
1595
- case "value":
1596
- jsonSchema.const = valibotAction.requirement;
1597
- break;
1598
- default: errors = addError(errors, `The "${valibotAction.type}" action cannot be converted to JSON Schema.`);
1599
- }
1600
- if (config?.overrideAction) {
1601
- const actionOverride = config.overrideAction({
1602
- valibotAction,
1603
- jsonSchema,
1604
- errors
1605
- });
1606
- if (actionOverride) return { ...actionOverride };
1607
- }
1608
- if (errors) for (const message of errors) handleError(message, config);
1609
- return jsonSchema;
1610
- }
1611
- /**
1612
- * Flattens a Valibot pipe by recursively expanding nested pipes.
1613
- *
1614
- * @param pipe The pipeline to flatten.
1615
- *
1616
- * @returns A flat pipeline.
1617
- */
1618
- function flattenPipe(pipe$1) {
1619
- return pipe$1.flatMap((item) => "pipe" in item ? flattenPipe(item.pipe) : item);
1620
- }
1621
- let refCount = 0;
1622
- /**
1623
- * Converts any supported Valibot schema to the JSON Schema format.
1624
- *
1625
- * @param jsonSchema The JSON Schema object.
1626
- * @param valibotSchema The Valibot schema object.
1627
- * @param config The conversion configuration.
1628
- * @param context The conversion context.
1629
- * @param skipRef Whether to skip using a reference.
1630
- *
1631
- * @returns The converted JSON Schema.
1632
- */
1633
- function convertSchema(jsonSchema, valibotSchema, config, context, skipRef = false) {
1634
- if (!skipRef) {
1635
- const referenceId = context.referenceMap.get(valibotSchema);
1636
- if (referenceId) {
1637
- jsonSchema.$ref = `#/$defs/${referenceId}`;
1638
- if (config?.overrideRef) {
1639
- const refOverride = config.overrideRef({
1640
- ...context,
1641
- referenceId,
1642
- valibotSchema,
1643
- jsonSchema
1644
- });
1645
- if (refOverride) jsonSchema.$ref = refOverride;
1646
- }
1647
- return jsonSchema;
1648
- }
1649
- }
1650
- if ("pipe" in valibotSchema) {
1651
- const flatPipe = flattenPipe(valibotSchema.pipe);
1652
- let startIndex = 0;
1653
- let stopIndex = flatPipe.length - 1;
1654
- if (config?.typeMode === "input") {
1655
- const inputStopIndex = flatPipe.slice(1).findIndex((item) => item.kind === "schema" || item.kind === "transformation" && (item.type === "find_item" || item.type === "parse_json" || item.type === "raw_transform" || item.type === "reduce_items" || item.type === "stringify_json" || item.type === "transform"));
1656
- if (inputStopIndex !== -1) stopIndex = inputStopIndex;
1657
- } else if (config?.typeMode === "output") {
1658
- const outputStartIndex = flatPipe.findLastIndex((item) => item.kind === "schema");
1659
- if (outputStartIndex !== -1) startIndex = outputStartIndex;
1660
- }
1661
- for (let index = startIndex; index <= stopIndex; index++) {
1662
- const valibotPipeItem = flatPipe[index];
1663
- if (valibotPipeItem.kind === "schema") {
1664
- if (index > startIndex) handleError("Set the \"typeMode\" config to \"input\" or \"output\" to convert pipelines with multiple schemas.", config);
1665
- jsonSchema = convertSchema(jsonSchema, valibotPipeItem, config, context, true);
1666
- } else jsonSchema = convertAction(jsonSchema, valibotPipeItem, config);
1667
- }
1668
- return jsonSchema;
1669
- }
1670
- let errors;
1671
- switch (valibotSchema.type) {
1672
- case "boolean":
1673
- jsonSchema.type = "boolean";
1674
- break;
1675
- case "null":
1676
- jsonSchema.type = "null";
1677
- break;
1678
- case "number":
1679
- jsonSchema.type = "number";
1680
- break;
1681
- case "string":
1682
- jsonSchema.type = "string";
1683
- break;
1684
- case "array":
1685
- jsonSchema.type = "array";
1686
- jsonSchema.items = convertSchema({}, valibotSchema.item, config, context);
1687
- break;
1688
- case "tuple":
1689
- case "tuple_with_rest":
1690
- case "loose_tuple":
1691
- case "strict_tuple":
1692
- jsonSchema.type = "array";
1693
- jsonSchema.items = [];
1694
- jsonSchema.minItems = valibotSchema.items.length;
1695
- for (const item of valibotSchema.items) jsonSchema.items.push(convertSchema({}, item, config, context));
1696
- if (valibotSchema.type === "tuple_with_rest") jsonSchema.additionalItems = convertSchema({}, valibotSchema.rest, config, context);
1697
- else if (valibotSchema.type === "strict_tuple") jsonSchema.additionalItems = false;
1698
- break;
1699
- case "object":
1700
- case "object_with_rest":
1701
- case "loose_object":
1702
- case "strict_object":
1703
- jsonSchema.type = "object";
1704
- jsonSchema.properties = {};
1705
- jsonSchema.required = [];
1706
- for (const key in valibotSchema.entries) {
1707
- const entry = valibotSchema.entries[key];
1708
- jsonSchema.properties[key] = convertSchema({}, entry, config, context);
1709
- if (entry.type !== "nullish" && entry.type !== "optional") jsonSchema.required.push(key);
1710
- }
1711
- if (valibotSchema.type === "object_with_rest") jsonSchema.additionalProperties = convertSchema({}, valibotSchema.rest, config, context);
1712
- else if (valibotSchema.type === "strict_object") jsonSchema.additionalProperties = false;
1713
- break;
1714
- case "record":
1715
- if ("pipe" in valibotSchema.key) errors = addError(errors, "The \"record\" schema with a schema for the key that contains a \"pipe\" cannot be converted to JSON Schema.");
1716
- if (valibotSchema.key.type !== "string") errors = addError(errors, `The "record" schema with the "${valibotSchema.key.type}" schema for the key cannot be converted to JSON Schema.`);
1717
- jsonSchema.type = "object";
1718
- jsonSchema.additionalProperties = convertSchema({}, valibotSchema.value, config, context);
1719
- break;
1720
- case "any":
1721
- case "unknown": break;
1722
- case "nullable":
1723
- case "nullish":
1724
- jsonSchema.anyOf = [convertSchema({}, valibotSchema.wrapped, config, context), { type: "null" }];
1725
- if (valibotSchema.default !== void 0) jsonSchema.default = getDefault(valibotSchema);
1726
- break;
1727
- case "exact_optional":
1728
- case "optional":
1729
- case "undefinedable":
1730
- jsonSchema = convertSchema(jsonSchema, valibotSchema.wrapped, config, context);
1731
- if (valibotSchema.default !== void 0) jsonSchema.default = getDefault(valibotSchema);
1732
- break;
1733
- case "literal":
1734
- if (typeof valibotSchema.literal !== "boolean" && typeof valibotSchema.literal !== "number" && typeof valibotSchema.literal !== "string") errors = addError(errors, "The value of the \"literal\" schema is not JSON compatible.");
1735
- jsonSchema.const = valibotSchema.literal;
1736
- break;
1737
- case "enum":
1738
- jsonSchema.enum = valibotSchema.options;
1739
- break;
1740
- case "picklist":
1741
- if (valibotSchema.options.some((option) => typeof option !== "number" && typeof option !== "string")) errors = addError(errors, "An option of the \"picklist\" schema is not JSON compatible.");
1742
- jsonSchema.enum = valibotSchema.options;
1743
- break;
1744
- case "union":
1745
- case "variant":
1746
- jsonSchema.anyOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context));
1747
- break;
1748
- case "intersect":
1749
- jsonSchema.allOf = valibotSchema.options.map((option) => convertSchema({}, option, config, context));
1750
- break;
1751
- case "lazy": {
1752
- let wrappedValibotSchema = context.getterMap.get(valibotSchema.getter);
1753
- if (!wrappedValibotSchema) {
1754
- wrappedValibotSchema = valibotSchema.getter(void 0);
1755
- context.getterMap.set(valibotSchema.getter, wrappedValibotSchema);
1756
- }
1757
- let referenceId = context.referenceMap.get(wrappedValibotSchema);
1758
- if (!referenceId) {
1759
- referenceId = `${refCount++}`;
1760
- context.referenceMap.set(wrappedValibotSchema, referenceId);
1761
- context.definitions[referenceId] = convertSchema({}, wrappedValibotSchema, config, context, true);
1762
- }
1763
- jsonSchema.$ref = `#/$defs/${referenceId}`;
1764
- if (config?.overrideRef) {
1765
- const refOverride = config.overrideRef({
1766
- ...context,
1767
- referenceId,
1768
- valibotSchema: wrappedValibotSchema,
1769
- jsonSchema
1770
- });
1771
- if (refOverride) jsonSchema.$ref = refOverride;
1772
- }
1773
- break;
1774
- }
1775
- default: errors = addError(errors, `The "${valibotSchema.type}" schema cannot be converted to JSON Schema.`);
1776
- }
1777
- if (config?.overrideSchema) {
1778
- const schemaOverride = config.overrideSchema({
1779
- ...context,
1780
- referenceId: context.referenceMap.get(valibotSchema),
1781
- valibotSchema,
1782
- jsonSchema,
1783
- errors
1784
- });
1785
- if (schemaOverride) return { ...schemaOverride };
1786
- }
1787
- if (errors) for (const message of errors) handleError(message, config);
1788
- return jsonSchema;
1789
- }
1790
- let store;
1791
- /**
1792
- * Returns the current global schema definitions.
1793
- *
1794
- * @returns The schema definitions.
1795
- *
1796
- * @beta
1797
- */
1798
- function getGlobalDefs() {
1799
- return store;
1800
- }
1801
- /**
1802
- * Converts a Valibot schema to the JSON Schema format.
1803
- *
1804
- * @param schema The Valibot schema object.
1805
- * @param config The JSON Schema configuration.
1806
- *
1807
- * @returns The converted JSON Schema.
1808
- */
1809
- function toJsonSchema(schema, config) {
1810
- const context = {
1811
- definitions: {},
1812
- referenceMap: /* @__PURE__ */ new Map(),
1813
- getterMap: /* @__PURE__ */ new Map()
1814
- };
1815
- const definitions = config?.definitions ?? getGlobalDefs();
1816
- if (definitions) {
1817
- for (const key in definitions) context.referenceMap.set(definitions[key], key);
1818
- for (const key in definitions) context.definitions[key] = convertSchema({}, definitions[key], config, context, true);
1819
- }
1820
- const jsonSchema = convertSchema({ $schema: "http://json-schema.org/draft-07/schema#" }, schema, config, context);
1821
- if (context.referenceMap.size) jsonSchema.$defs = context.definitions;
1822
- return jsonSchema;
1823
- }
1824
-
1825
- //#endregion
1826
- //#region ../../node_modules/.pnpm/ansis@4.1.0/node_modules/ansis/index.cjs
1827
- var require_ansis = /* @__PURE__ */ require_chunk.__commonJS({ "../../node_modules/.pnpm/ansis@4.1.0/node_modules/ansis/index.cjs": ((exports, module) => {
1828
- let e$1, t$2, r, { defineProperty: n$1, setPrototypeOf: l, create: o, keys: s } = Object, i = "", { round: c, max: a$1 } = Math, p = (e$2) => {
1829
- let t$3 = /([a-f\d]{3,6})/i.exec(e$2)?.[1], r$1 = t$3?.length, n$2 = parseInt(6 ^ r$1 ? 3 ^ r$1 ? "0" : t$3[0] + t$3[0] + t$3[1] + t$3[1] + t$3[2] + t$3[2] : t$3, 16);
1830
- return [
1831
- n$2 >> 16 & 255,
1832
- n$2 >> 8 & 255,
1833
- 255 & n$2
1834
- ];
1835
- }, u = (e$2, t$3, r$1) => e$2 ^ t$3 || t$3 ^ r$1 ? 16 + 36 * c(e$2 / 51) + 6 * c(t$3 / 51) + c(r$1 / 51) : 8 > e$2 ? 16 : e$2 > 248 ? 231 : c(24 * (e$2 - 8) / 247) + 232, d = (e$2) => {
1836
- let t$3, r$1, n$2, l$1, o$1;
1837
- return 8 > e$2 ? 30 + e$2 : 16 > e$2 ? e$2 - 8 + 90 : (232 > e$2 ? (o$1 = (e$2 -= 16) % 36, t$3 = (e$2 / 36 | 0) / 5, r$1 = (o$1 / 6 | 0) / 5, n$2 = o$1 % 6 / 5) : t$3 = r$1 = n$2 = (10 * (e$2 - 232) + 8) / 255, l$1 = 2 * a$1(t$3, r$1, n$2), l$1 ? 30 + (c(n$2) << 2 | c(r$1) << 1 | c(t$3)) + (2 ^ l$1 ? 0 : 60) : 30);
1838
- }, g = (() => {
1839
- let r$1 = (e$2) => o$1.some(((t$3) => e$2.test(t$3))), n$2 = globalThis, l$1 = n$2.process ?? {}, o$1 = l$1.argv ?? [], i$1 = l$1.env ?? {}, c$1 = -1;
1840
- try {
1841
- e$1 = "," + s(i$1).join(",");
1842
- } catch (e$2) {
1843
- i$1 = {}, c$1 = 0;
1844
- }
1845
- let a$2 = "FORCE_COLOR", p$1 = {
1846
- false: 0,
1847
- 0: 0,
1848
- 1: 1,
1849
- 2: 2,
1850
- 3: 3
1851
- }[i$1[a$2]] ?? -1, u$1 = a$2 in i$1 && p$1 || r$1(/^--color=?(true|always)?$/);
1852
- return u$1 && (c$1 = p$1), ~c$1 || (c$1 = ((r$2, n$3, l$2) => (t$2 = r$2.TERM, {
1853
- "24bit": 3,
1854
- truecolor: 3,
1855
- ansi256: 2,
1856
- ansi: 1
1857
- }[r$2.COLORTERM] || (r$2.CI ? /,GITHUB/.test(e$1) ? 3 : 1 : n$3 && "dumb" !== t$2 ? l$2 ? 3 : /-256/.test(t$2) ? 2 : 1 : 0)))(i$1, !!i$1.PM2_HOME || i$1.NEXT_RUNTIME?.includes("edge") || !!l$1.stdout?.isTTY, "win32" === l$1.platform)), !p$1 || i$1.NO_COLOR || r$1(/^--(no-color|color=(false|never))$/) ? 0 : n$2.window?.chrome || u$1 && !c$1 ? 3 : c$1;
1858
- })(), f = {
1859
- open: i,
1860
- close: i
1861
- }, h = 39, b = 49, O = {}, m = ({ p: e$2 }, { open: t$3, close: n$2 }) => {
1862
- let o$1 = (e$3, ...r$1) => {
1863
- if (!e$3) {
1864
- if (t$3 && t$3 === n$2) return t$3;
1865
- if ((e$3 ?? i) === i) return i;
1866
- }
1867
- let l$1, s$2 = e$3.raw ? String.raw({ raw: e$3 }, ...r$1) : i + e$3, c$2 = o$1.p, a$2 = c$2.o, p$1 = c$2.c;
1868
- if (s$2.includes("\x1B")) for (; c$2; c$2 = c$2.p) {
1869
- let { open: e$4, close: t$4 } = c$2, r$2 = t$4.length, n$3 = i, o$2 = 0;
1870
- if (r$2) for (; ~(l$1 = s$2.indexOf(t$4, o$2)); o$2 = l$1 + r$2) n$3 += s$2.slice(o$2, l$1) + e$4;
1871
- s$2 = n$3 + s$2.slice(o$2);
1872
- }
1873
- return a$2 + (s$2.includes("\n") ? s$2.replace(/(\r?\n)/g, p$1 + "$1" + a$2) : s$2) + p$1;
1874
- }, s$1 = t$3, c$1 = n$2;
1875
- return e$2 && (s$1 = e$2.o + t$3, c$1 = n$2 + e$2.c), l(o$1, r), o$1.p = {
1876
- open: t$3,
1877
- close: n$2,
1878
- o: s$1,
1879
- c: c$1,
1880
- p: e$2
1881
- }, o$1.open = s$1, o$1.close = c$1, o$1;
1882
- };
1883
- const w = function(e$2 = g) {
1884
- let t$3 = {
1885
- Ansis: w,
1886
- level: e$2,
1887
- isSupported: () => s$1,
1888
- strip: (e$3) => e$3.replace(/[›][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, i),
1889
- extend(e$3) {
1890
- for (let t$4 in e$3) {
1891
- let r$1 = e$3[t$4], l$1 = (typeof r$1)[0], o$1 = "s" === l$1 ? x(...p(r$1)) : r$1;
1892
- O[t$4] = "f" === l$1 ? { get() {
1893
- return (...e$4) => m(this, r$1(...e$4));
1894
- } } : { get() {
1895
- let e$4 = m(this, o$1);
1896
- return n$1(this, t$4, { value: e$4 }), e$4;
1897
- } };
1898
- }
1899
- return r = o({}, O), l(t$3, r), t$3;
1900
- }
1901
- }, s$1 = e$2 > 0, c$1 = (e$3, t$4) => s$1 ? {
1902
- open: `[${e$3}m`,
1903
- close: `[${t$4}m`
1904
- } : f, a$2 = (e$3) => (t$4) => e$3(...p(t$4)), y$1 = (e$3, t$4) => (r$1, n$2, l$1) => c$1(`${e$3}8;2;${r$1};${n$2};${l$1}`, t$4), R = (e$3, t$4) => (r$1, n$2, l$1) => c$1(((e$4, t$5, r$2) => d(u(e$4, t$5, r$2)))(r$1, n$2, l$1) + e$3, t$4), $ = (e$3) => (t$4, r$1, n$2) => e$3(u(t$4, r$1, n$2)), x = y$1(3, h), T = y$1(4, b), v = (e$3) => c$1("38;5;" + e$3, h), C = (e$3) => c$1("48;5;" + e$3, b);
1905
- 2 === e$2 ? (x = $(v), T = $(C)) : 1 === e$2 && (x = R(0, h), T = R(10, b), v = (e$3) => c$1(d(e$3), h), C = (e$3) => c$1(d(e$3) + 10, b));
1906
- let E, M = {
1907
- fg: v,
1908
- bg: C,
1909
- rgb: x,
1910
- bgRgb: T,
1911
- hex: a$2(x),
1912
- bgHex: a$2(T),
1913
- visible: f,
1914
- reset: c$1(0, 0),
1915
- bold: c$1(1, 22),
1916
- dim: c$1(2, 22),
1917
- italic: c$1(3, 23),
1918
- underline: c$1(4, 24),
1919
- inverse: c$1(7, 27),
1920
- hidden: c$1(8, 28),
1921
- strikethrough: c$1(9, 29)
1922
- }, I = "Bright";
1923
- return "black,red,green,yellow,blue,magenta,cyan,white,gray".split(",").map(((e$3, t$4) => {
1924
- E = "bg" + e$3[0].toUpperCase() + e$3.slice(1), 8 > t$4 ? (M[e$3 + I] = c$1(90 + t$4, h), M[E + I] = c$1(100 + t$4, b)) : t$4 = 60, M[e$3] = c$1(30 + t$4, h), M[E] = c$1(40 + t$4, b);
1925
- })), t$3.extend(M);
1926
- }, y = new w();
1927
- module.exports = y, y.default = y;
1928
- }) });
1929
-
1930
- //#endregion
1931
- //#region ../../node_modules/.pnpm/ansis@4.1.0/node_modules/ansis/index.mjs
1932
- var import_ansis = /* @__PURE__ */ require_chunk.__toESM(require_ansis(), 1);
1933
- var ansis_default = import_ansis.default;
1934
- const { Ansis, fg, bg, rgb, bgRgb, hex, bgHex, reset, inverse, hidden, visible, bold, dim, italic, underline, strikethrough, black, red, green, yellow, blue, magenta, cyan, white, gray, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bgGray, bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright } = import_ansis.default;
1935
-
1936
- //#endregion
1937
- //#region src/utils/validator.ts
1938
- const StringOrRegExpSchema = union([string(), instance(RegExp)]);
1939
- const LogLevelSchema = union([
1940
- literal("debug"),
1941
- literal("info"),
1942
- literal("warn")
1943
- ]);
1944
- const LogLevelOptionSchema = union([LogLevelSchema, literal("silent")]);
1945
- const LogLevelWithErrorSchema = union([LogLevelSchema, literal("error")]);
1946
- const RollupLogSchema = any();
1947
- const RollupLogWithStringSchema = union([RollupLogSchema, string()]);
1948
- const InputOptionSchema = union([
1949
- string(),
1950
- array(string()),
1951
- record(string(), string())
1952
- ]);
1953
- const ExternalSchema = union([
1954
- StringOrRegExpSchema,
1955
- array(StringOrRegExpSchema),
1956
- pipe(function_(), args(tuple([
1957
- string(),
1958
- optional(string()),
1959
- boolean()
1960
- ])), returns(nullish(boolean())))
1961
- ]);
1962
- const ModuleTypesSchema = record(string(), union([
1963
- literal("asset"),
1964
- literal("base64"),
1965
- literal("binary"),
1966
- literal("css"),
1967
- literal("dataurl"),
1968
- literal("empty"),
1969
- literal("js"),
1970
- literal("json"),
1971
- literal("jsx"),
1972
- literal("text"),
1973
- literal("ts"),
1974
- literal("tsx")
1975
- ]));
1976
- const JsxOptionsSchema = strictObject({
1977
- runtime: pipe(optional(union([literal("classic"), literal("automatic")])), description("Which runtime to use")),
1978
- development: pipe(optional(boolean()), description("Development specific information")),
1979
- throwIfNamespace: pipe(optional(string()), description("Toggles whether to throw an error when a tag name uses an XML namespace")),
1980
- importSource: pipe(optional(string()), description("Import the factory of element and fragment if mode is classic")),
1981
- pragma: pipe(optional(string()), description("Jsx element transformation")),
1982
- pragmaFlag: pipe(optional(string()), description("Jsx fragment transformation")),
1983
- refresh: pipe(optional(boolean()), description("Enable react fast refresh"))
1984
- });
1985
- const RollupJsxOptionsSchema = strictObject({
1986
- mode: optional(union([
1987
- literal("classic"),
1988
- literal("automatic"),
1989
- literal("preserve")
1990
- ])),
1991
- factory: optional(string()),
1992
- fragment: optional(string()),
1993
- importSource: optional(string()),
1994
- jsxImportSource: optional(string())
1995
- });
1996
- const HelperModeSchema = union([literal("Runtime"), literal("External")]);
1997
- const DecoratorOptionSchema = object({
1998
- legacy: optional(boolean()),
1999
- emitDecoratorMetadata: optional(boolean())
2000
- });
2001
- const HelpersSchema = object({ mode: optional(HelperModeSchema) });
2002
- const RewriteImportExtensionsSchema = union([
2003
- literal("rewrite"),
2004
- literal("remove"),
2005
- boolean()
2006
- ]);
2007
- const TypescriptSchema = object({
2008
- jsxPragma: optional(string()),
2009
- jsxPragmaFrag: optional(string()),
2010
- onlyRemoveTypeImports: optional(boolean()),
2011
- allowNamespaces: optional(boolean()),
2012
- allowDeclareFields: optional(boolean()),
2013
- declaration: optional(object({
2014
- stripInternal: optional(boolean()),
2015
- sourcemap: optional(boolean())
2016
- })),
2017
- rewriteImportExtensions: optional(RewriteImportExtensionsSchema)
2018
- });
2019
- const AssumptionsSchema = object({
2020
- ignoreFunctionLength: optional(boolean()),
2021
- noDocumentAll: optional(boolean()),
2022
- objectRestNoSymbols: optional(boolean()),
2023
- pureGetters: optional(boolean()),
2024
- setPublicClassFields: optional(boolean())
2025
- });
2026
- const TransformOptionsSchema = object({
2027
- assumptions: optional(AssumptionsSchema),
2028
- typescript: optional(TypescriptSchema),
2029
- helpers: optional(HelpersSchema),
2030
- decorators: optional(DecoratorOptionSchema),
2031
- jsx: optional(union([literal("preserve"), JsxOptionsSchema])),
2032
- target: pipe(optional(union([string(), array(string())])), description("The JavaScript target environment"))
2033
- });
2034
- const WatchOptionsSchema = strictObject({
2035
- chokidar: optional(never(`The "watch.chokidar" option is deprecated, please use "watch.notify" instead of it`)),
2036
- exclude: optional(union([StringOrRegExpSchema, array(StringOrRegExpSchema)])),
2037
- include: optional(union([StringOrRegExpSchema, array(StringOrRegExpSchema)])),
2038
- notify: pipe(optional(strictObject({
2039
- compareContents: optional(boolean()),
2040
- pollInterval: optional(number())
2041
- })), description("Notify options")),
2042
- skipWrite: pipe(optional(boolean()), description("Skip the bundle.write() step")),
2043
- buildDelay: pipe(optional(number()), description("Throttle watch rebuilds")),
2044
- clearScreen: pipe(optional(boolean()), description("Whether to clear the screen when a rebuild is triggered")),
2045
- 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."))
2046
- });
2047
- const ChecksOptionsSchema = strictObject({
2048
- circularDependency: pipe(optional(boolean()), description("Whether to emit warning when detecting circular dependency")),
2049
- eval: pipe(optional(boolean()), description("Whether to emit warning when detecting eval")),
2050
- missingGlobalName: pipe(optional(boolean()), description("Whether to emit warning when detecting missing global name")),
2051
- missingNameOptionForIifeExport: pipe(optional(boolean()), description("Whether to emit warning when detecting missing name option for iife export")),
2052
- mixedExport: pipe(optional(boolean()), description("Whether to emit warning when detecting mixed export")),
2053
- unresolvedEntry: pipe(optional(boolean()), description("Whether to emit warning when detecting unresolved entry")),
2054
- unresolvedImport: pipe(optional(boolean()), description("Whether to emit warning when detecting unresolved import")),
2055
- filenameConflict: pipe(optional(boolean()), description("Whether to emit warning when detecting filename conflict")),
2056
- commonJsVariableInEsm: pipe(optional(boolean()), description("Whether to emit warning when detecting common js variable in esm")),
2057
- importIsUndefined: pipe(optional(boolean()), description("Whether to emit warning when detecting import is undefined")),
2058
- emptyImportMeta: pipe(optional(boolean()), description("Whether to emit warning when detecting empty import meta")),
2059
- configurationFieldConflict: pipe(optional(boolean()), description("Whether to emit warning when detecting configuration field conflict")),
2060
- preferBuiltinFeature: pipe(optional(boolean()), description("Whether to emit warning when detecting prefer builtin feature"))
2061
- });
2062
- const MinifyOptionsSchema = strictObject({
2063
- mangle: optional(boolean()),
2064
- compress: optional(boolean()),
2065
- removeWhitespace: optional(boolean())
2066
- });
2067
- const ResolveOptionsSchema = strictObject({
2068
- alias: optional(record(string(), union([string(), array(string())]))),
2069
- aliasFields: optional(array(array(string()))),
2070
- conditionNames: optional(array(string())),
2071
- extensionAlias: optional(record(string(), array(string()))),
2072
- exportsFields: optional(array(array(string()))),
2073
- extensions: optional(array(string())),
2074
- mainFields: optional(array(string())),
2075
- mainFiles: optional(array(string())),
2076
- modules: optional(array(string())),
2077
- symlinks: optional(boolean()),
2078
- yarnPnp: optional(boolean())
2079
- });
2080
- const TreeshakingOptionsSchema = union([boolean(), looseObject({
2081
- annotations: optional(boolean()),
2082
- manualPureFunctions: optional(array(string())),
2083
- unknownGlobalSideEffects: optional(boolean()),
2084
- commonjs: optional(boolean()),
2085
- propertyReadSideEffects: optional(union([literal(false), literal("always")])),
2086
- propertyWriteSideEffects: optional(union([literal(false), literal("always")]))
2087
- })]);
2088
- const OptimizationOptionsSchema = strictObject({
2089
- inlineConst: pipe(optional(union([
2090
- boolean(),
2091
- literal("smart"),
2092
- strictObject({
2093
- mode: optional(union([literal("all"), literal("smart")])),
2094
- pass: optional(number())
2095
- })
2096
- ])), description("Enable crossmodule constant inlining")),
2097
- pifeForModuleWrappers: pipe(optional(boolean()), description("Use PIFE pattern for module wrappers"))
2098
- });
2099
- const OnLogSchema = pipe(function_(), args(tuple([
2100
- LogLevelSchema,
2101
- RollupLogSchema,
2102
- pipe(function_(), args(tuple([LogLevelWithErrorSchema, RollupLogWithStringSchema])))
2103
- ])));
2104
- const OnwarnSchema = pipe(function_(), args(tuple([RollupLogSchema, pipe(function_(), args(tuple([union([RollupLogWithStringSchema, pipe(function_(), returns(RollupLogWithStringSchema))])])))])));
2105
- const HmrSchema = union([boolean(), strictObject({
2106
- new: optional(boolean()),
2107
- port: optional(number()),
2108
- host: optional(string()),
2109
- implement: optional(string())
2110
- })]);
2111
- const InputOptionsSchema = strictObject({
2112
- input: optional(InputOptionSchema),
2113
- plugins: optional(custom(() => true)),
2114
- external: optional(ExternalSchema),
2115
- makeAbsoluteExternalsRelative: optional(union([boolean(), literal("ifRelativeSource")])),
2116
- resolve: optional(ResolveOptionsSchema),
2117
- cwd: pipe(optional(string()), description("Current working directory")),
2118
- platform: pipe(optional(union([
2119
- literal("browser"),
2120
- literal("neutral"),
2121
- literal("node")
2122
- ])), description(`Platform for which the code should be generated (node, ${ansis_default.underline("browser")}, neutral)`)),
2123
- shimMissingExports: pipe(optional(boolean()), description("Create shim variables for missing exports")),
2124
- treeshake: optional(TreeshakingOptionsSchema),
2125
- optimization: optional(OptimizationOptionsSchema),
2126
- logLevel: pipe(optional(LogLevelOptionSchema), description(`Log level (${ansis_default.dim("silent")}, ${ansis_default.underline(ansis_default.gray("info"))}, debug, ${ansis_default.yellow("warn")})`)),
2127
- onLog: optional(OnLogSchema),
2128
- onwarn: optional(OnwarnSchema),
2129
- moduleTypes: pipe(optional(ModuleTypesSchema), description("Module types for customized extensions")),
2130
- experimental: optional(strictObject({
2131
- disableLiveBindings: optional(boolean()),
2132
- enableComposingJsPlugins: optional(boolean()),
2133
- viteMode: optional(boolean()),
2134
- resolveNewUrlToAsset: optional(boolean()),
2135
- strictExecutionOrder: optional(boolean()),
2136
- onDemandWrapping: optional(boolean()),
2137
- incrementalBuild: optional(boolean()),
2138
- hmr: optional(HmrSchema),
2139
- attachDebugInfo: optional(union([
2140
- literal("none"),
2141
- literal("simple"),
2142
- literal("full")
2143
- ])),
2144
- chunkModulesOrder: optional(union([literal("module-id"), literal("exec-order")])),
2145
- chunkImportMap: optional(union([boolean(), object({
2146
- baseUrl: optional(string()),
2147
- fileName: optional(string())
2148
- })]))
2149
- })),
2150
- define: pipe(optional(record(string(), string())), description("Define global variables")),
2151
- inject: optional(record(string(), union([string(), tuple([string(), string()])]))),
2152
- profilerNames: optional(boolean()),
2153
- jsx: optional(union([
2154
- literal(false),
2155
- literal("react"),
2156
- literal("react-jsx"),
2157
- literal("preserve"),
2158
- RollupJsxOptionsSchema
2159
- ])),
2160
- transform: optional(TransformOptionsSchema),
2161
- watch: optional(union([WatchOptionsSchema, literal(false)])),
2162
- dropLabels: pipe(optional(array(string())), description("Remove labeled statements with these label names")),
2163
- checks: optional(ChecksOptionsSchema),
2164
- keepNames: pipe(optional(boolean()), description("Keep function/class name")),
2165
- debug: 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.")),
2166
- preserveEntrySignatures: pipe(optional(union([
2167
- literal("strict"),
2168
- literal("allow-extension"),
2169
- literal("exports-only"),
2170
- literal(false)
2171
- ]))),
2172
- tsconfig: pipe(optional(string()), description("Path to the tsconfig.json file."))
2173
- });
2174
- const InputCliOverrideSchema = strictObject({
2175
- input: pipe(optional(array(string())), description("Entry file")),
2176
- external: pipe(optional(array(string())), description("Comma-separated list of module ids to exclude from the bundle `<module-id>,...`")),
2177
- inject: pipe(optional(record(string(), string())), description("Inject import statements on demand")),
2178
- treeshake: pipe(optional(boolean()), description("enable treeshaking")),
2179
- makeAbsoluteExternalsRelative: pipe(optional(boolean()), description("Prevent normalization of external imports")),
2180
- jsx: pipe(optional(union([
2181
- literal(false),
2182
- literal("react"),
2183
- literal("react-jsx"),
2184
- literal("preserve")
2185
- ])), description("Jsx options preset")),
2186
- preserveEntrySignatures: pipe(optional(union([literal(false)])), description("Avoid facade chunks for entry points")),
2187
- context: pipe(optional(string()), description("The entity top-level `this` represents."))
2188
- });
2189
- const InputCliOptionsSchema = omit(strictObject({
2190
- ...InputOptionsSchema.entries,
2191
- ...InputCliOverrideSchema.entries
2192
- }), [
2193
- "plugins",
2194
- "onwarn",
2195
- "onLog",
2196
- "resolve",
2197
- "experimental",
2198
- "profilerNames",
2199
- "watch"
2200
- ]);
2201
- const ModuleFormatSchema = union([
2202
- literal("es"),
2203
- literal("cjs"),
2204
- literal("esm"),
2205
- literal("module"),
2206
- literal("commonjs"),
2207
- literal("iife"),
2208
- literal("umd")
2209
- ]);
2210
- const AddonFunctionSchema = pipe(function_(), args(tuple([custom(() => true)])), returnsAsync(unionAsync([string(), pipeAsync(promise(), awaitAsync(), string())])));
2211
- const ChunkFileNamesSchema = union([string(), pipe(function_(), args(tuple([custom(() => true)])), returns(string()))]);
2212
- const AssetFileNamesSchema = union([string(), pipe(function_(), args(tuple([custom(() => true)])), returns(string()))]);
2213
- const SanitizeFileNameSchema = union([boolean(), pipe(function_(), args(tuple([string()])), returns(string()))]);
2214
- const GlobalsFunctionSchema = pipe(function_(), args(tuple([string()])), returns(string()));
2215
- const AdvancedChunksSchema = strictObject({
2216
- includeDependenciesRecursively: optional(boolean()),
2217
- minSize: optional(number()),
2218
- maxSize: optional(number()),
2219
- minModuleSize: optional(number()),
2220
- maxModuleSize: optional(number()),
2221
- minShareCount: optional(number()),
2222
- groups: optional(array(strictObject({
2223
- name: union([string(), pipe(function_(), args(tuple([string()])), returns(nullish(string())))]),
2224
- test: optional(union([
2225
- string(),
2226
- instance(RegExp),
2227
- pipe(function_(), args(tuple([string()])), returns(union([nullish(boolean()), void_()])))
2228
- ])),
2229
- priority: optional(number()),
2230
- minSize: optional(number()),
2231
- minShareCount: optional(number()),
2232
- maxSize: optional(number()),
2233
- minModuleSize: optional(number()),
2234
- maxModuleSize: optional(number())
2235
- })))
2236
- });
2237
- const OutputOptionsSchema = strictObject({
2238
- dir: pipe(optional(string()), description("Output directory, defaults to `dist` if `file` is not set")),
2239
- file: pipe(optional(string()), description("Single output file")),
2240
- exports: pipe(optional(union([
2241
- literal("auto"),
2242
- literal("named"),
2243
- literal("default"),
2244
- literal("none")
2245
- ])), description(`Specify a export mode (${ansis_default.underline("auto")}, named, default, none)`)),
2246
- hashCharacters: pipe(optional(union([
2247
- literal("base64"),
2248
- literal("base36"),
2249
- literal("hex")
2250
- ])), description("Use the specified character set for file hashes")),
2251
- format: pipe(optional(ModuleFormatSchema), description(`Output format of the generated bundle (supports ${ansis_default.underline("esm")}, cjs, and iife)`)),
2252
- sourcemap: pipe(optional(union([
2253
- boolean(),
2254
- literal("inline"),
2255
- literal("hidden")
2256
- ])), description(`Generate sourcemap (\`-s inline\` for inline, or ${ansis_default.bold("pass the `-s` on the last argument if you want to generate `.map` file")})`)),
2257
- sourcemapBaseUrl: pipe(optional(string()), description("Base URL used to prefix sourcemap paths")),
2258
- sourcemapDebugIds: pipe(optional(boolean()), description("Inject sourcemap debug IDs")),
2259
- sourcemapIgnoreList: optional(union([boolean(), custom(() => true)])),
2260
- sourcemapPathTransform: optional(custom(() => true)),
2261
- banner: optional(union([string(), AddonFunctionSchema])),
2262
- footer: optional(union([string(), AddonFunctionSchema])),
2263
- intro: optional(union([string(), AddonFunctionSchema])),
2264
- outro: optional(union([string(), AddonFunctionSchema])),
2265
- extend: pipe(optional(boolean()), description("Extend global variable defined by name in IIFE / UMD formats")),
2266
- esModule: optional(union([boolean(), literal("if-default-prop")])),
2267
- assetFileNames: optional(AssetFileNamesSchema),
2268
- entryFileNames: optional(ChunkFileNamesSchema),
2269
- chunkFileNames: optional(ChunkFileNamesSchema),
2270
- cssEntryFileNames: optional(ChunkFileNamesSchema),
2271
- cssChunkFileNames: optional(ChunkFileNamesSchema),
2272
- sanitizeFileName: optional(SanitizeFileNameSchema),
2273
- minify: pipe(optional(union([
2274
- boolean(),
2275
- string("dce-only"),
2276
- MinifyOptionsSchema
2277
- ])), description("Minify the bundled file")),
2278
- name: pipe(optional(string()), description("Name for UMD / IIFE format outputs")),
2279
- globals: pipe(optional(union([record(string(), string()), GlobalsFunctionSchema])), description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
2280
- externalLiveBindings: pipe(optional(boolean()), description("external live bindings")),
2281
- inlineDynamicImports: pipe(optional(boolean()), description("Inline dynamic imports")),
2282
- manualChunks: optional(pipe(function_(), args(tuple([string(), object({})])), returns(union([string(), nullish(string())])))),
2283
- advancedChunks: optional(AdvancedChunksSchema),
2284
- legalComments: pipe(optional(union([literal("none"), literal("inline")])), description("Control comments in the output")),
2285
- plugins: optional(custom(() => true)),
2286
- polyfillRequire: pipe(optional(boolean()), description("Disable require polyfill injection")),
2287
- hoistTransitiveImports: optional(custom((input) => {
2288
- if (input) return false;
2289
- return true;
2290
- }, () => `The 'true' value is not supported`)),
2291
- preserveModules: pipe(optional(boolean()), description("Preserve module structure")),
2292
- preserveModulesRoot: pipe(optional(string()), description("Put preserved modules under this path at root level")),
2293
- virtualDirname: optional(string()),
2294
- minifyInternalExports: pipe(optional(boolean()), description("Minify internal exports")),
2295
- topLevelVar: pipe(optional(boolean()), description("Rewrite top-level declarations to use `var`."))
2296
- });
2297
- const getAddonDescription = (placement, wrapper) => {
2298
- return `Code to insert the ${ansis_default.bold(placement)} of the bundled file (${ansis_default.bold(wrapper)} the wrapper function)`;
2299
- };
2300
- const OutputCliOverrideSchema = strictObject({
2301
- assetFileNames: pipe(optional(string()), description("Name pattern for asset files")),
2302
- entryFileNames: pipe(optional(string()), description("Name pattern for emitted entry chunks")),
2303
- chunkFileNames: pipe(optional(string()), description("Name pattern for emitted secondary chunks")),
2304
- cssEntryFileNames: pipe(optional(string()), description("Name pattern for emitted css entry chunks")),
2305
- cssChunkFileNames: pipe(optional(string()), description("Name pattern for emitted css secondary chunks")),
2306
- sanitizeFileName: pipe(optional(boolean()), description("Sanitize file name")),
2307
- banner: pipe(optional(string()), description(getAddonDescription("top", "outside"))),
2308
- footer: pipe(optional(string()), description(getAddonDescription("bottom", "outside"))),
2309
- intro: pipe(optional(string()), description(getAddonDescription("top", "inside"))),
2310
- outro: pipe(optional(string()), description(getAddonDescription("bottom", "inside"))),
2311
- esModule: pipe(optional(boolean()), description("Always generate `__esModule` marks in non-ESM formats, defaults to `if-default-prop` (use `--no-esModule` to always disable)")),
2312
- globals: pipe(optional(record(string(), string())), description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
2313
- advancedChunks: pipe(optional(strictObject({
2314
- minSize: pipe(optional(number()), description("Minimum size of the chunk")),
2315
- minShareCount: pipe(optional(number()), description("Minimum share count of the chunk"))
2316
- })), description("Global variable of UMD / IIFE dependencies (syntax: `key=value`)")),
2317
- minify: pipe(optional(boolean()), description("Minify the bundled file"))
2318
- });
2319
- const OutputCliOptionsSchema = omit(strictObject({
2320
- ...OutputOptionsSchema.entries,
2321
- ...OutputCliOverrideSchema.entries
2322
- }), [
2323
- "sourcemapIgnoreList",
2324
- "sourcemapPathTransform",
2325
- "plugins",
2326
- "hoistTransitiveImports"
2327
- ]);
2328
- const CliOptionsSchema = strictObject({
2329
- config: pipe(optional(union([string(), boolean()])), description("Path to the config file (default: `rolldown.config.js`)")),
2330
- help: pipe(optional(boolean()), description("Show help")),
2331
- version: pipe(optional(boolean()), description("Show version number")),
2332
- watch: pipe(optional(boolean()), description("Watch files in bundle and rebuild on changes")),
2333
- ...InputCliOptionsSchema.entries,
2334
- ...OutputCliOptionsSchema.entries
2335
- });
2336
- function validateCliOptions(options) {
2337
- let parsed = safeParse(CliOptionsSchema, options);
2338
- return [parsed.output, parsed.issues?.map((issue) => {
2339
- const option = issue.path?.map((pathItem) => pathItem.key).join(" ");
2340
- return `Invalid value for option ${option}: ${issue.message}`;
2341
- })];
2342
- }
2343
- const inputHelperMsgRecord = {
2344
- output: { ignored: true },
2345
- "resolve.tsconfigFilename": { issueMsg: "It is deprecated. Please use the top-level `tsconfig` option instead." }
2346
- };
2347
- const outputHelperMsgRecord = {};
2348
- function validateOption(key, options) {
2349
- if (typeof options !== "object") throw new Error(`Invalid ${key} options. Expected an Object but received ${JSON.stringify(options)}.`);
2350
- if (globalThis.process?.env?.ROLLUP_TEST) return;
2351
- let parsed = safeParse(key === "input" ? InputOptionsSchema : OutputOptionsSchema, options);
2352
- if (!parsed.success) {
2353
- const errors = parsed.issues.map((issue) => {
2354
- let issueMsg = issue.message;
2355
- const issuePaths = issue.path.map((path$2) => path$2.key);
2356
- if (issue.type === "union") {
2357
- const subIssue = issue.issues?.find((i$1) => !(i$1.type !== issue.received && i$1.input === issue.input));
2358
- if (subIssue) {
2359
- if (subIssue.path) issuePaths.push(subIssue.path.map((path$2) => path$2.key));
2360
- issueMsg = subIssue.message;
2361
- }
2362
- }
2363
- const stringPath = issuePaths.join(".");
2364
- const helper = key === "input" ? inputHelperMsgRecord[stringPath] : outputHelperMsgRecord[stringPath];
2365
- if (helper && helper.ignored) return "";
2366
- return `- For the "${stringPath}". ${helper?.issueMsg || issueMsg + "."} ${helper?.help ? `\n Help: ${helper.help}` : ""}`;
2367
- }).filter(Boolean);
2368
- if (errors.length) console.warn(`\x1b[33mWarning: Invalid ${key} options (${errors.length} issue${errors.length === 1 ? "" : "s"} found)\n${errors.join("\n")}\x1b[0m`);
2369
- }
2370
- }
2371
- function getInputCliKeys() {
2372
- return keyof(InputCliOptionsSchema).options;
2373
- }
2374
- function getOutputCliKeys() {
2375
- return keyof(OutputCliOptionsSchema).options;
2376
- }
2377
- function getJsonSchema() {
2378
- return toJsonSchema(CliOptionsSchema, { errorMode: "ignore" });
2379
- }
2380
-
2381
- //#endregion
2382
- //#region src/types/sourcemap.ts
2383
- function bindingifySourcemap$1(map) {
2384
- if (map == null) return;
2385
- return { inner: typeof map === "string" ? map : {
2386
- file: map.file ?? void 0,
2387
- mappings: map.mappings,
2388
- sourceRoot: "sourceRoot" in map ? map.sourceRoot ?? void 0 : void 0,
2389
- sources: map.sources?.map((s$1) => s$1 ?? void 0),
2390
- sourcesContent: map.sourcesContent?.map((s$1) => s$1 ?? void 0),
2391
- names: map.names,
2392
- x_google_ignoreList: map.x_google_ignoreList,
2393
- debugId: "debugId" in map ? map.debugId : void 0
2394
- } };
2395
- }
2396
-
2397
- //#endregion
2398
- //#region src/utils/error.ts
2399
- function normalizeErrors(rawErrors) {
2400
- const errors = rawErrors.map((e$2) => e$2 instanceof Error ? e$2 : Object.assign(/* @__PURE__ */ new Error(), {
2401
- kind: e$2.kind,
2402
- message: e$2.message,
2403
- stack: void 0
2404
- }));
2405
- let summary = `Build failed with ${errors.length} error${errors.length < 2 ? "" : "s"}:\n`;
2406
- for (let i$1 = 0; i$1 < errors.length; i$1++) {
2407
- summary += "\n";
2408
- if (i$1 >= 5) {
2409
- summary += "...";
2410
- break;
2411
- }
2412
- summary += getErrorMessage(errors[i$1]);
2413
- }
2414
- const wrapper = new Error(summary);
2415
- Object.defineProperty(wrapper, "errors", {
2416
- configurable: true,
2417
- enumerable: true,
2418
- get: () => errors,
2419
- set: (value) => Object.defineProperty(wrapper, "errors", {
2420
- configurable: true,
2421
- enumerable: true,
2422
- value
2423
- })
2424
- });
2425
- return wrapper;
2426
- }
2427
- function getErrorMessage(e$2) {
2428
- if (Object.hasOwn(e$2, "kind")) return e$2.message;
2429
- let s$1 = "";
2430
- if (e$2.plugin) s$1 += `[plugin ${e$2.plugin}]`;
2431
- const id$1 = e$2.id ?? e$2.loc?.file;
2432
- if (id$1) {
2433
- s$1 += " " + id$1;
2434
- if (e$2.loc) s$1 += `:${e$2.loc.line}:${e$2.loc.column}`;
2435
- }
2436
- if (s$1) s$1 += "\n";
2437
- const message = `${e$2.name ?? "Error"}: ${e$2.message}`;
2438
- s$1 += message;
2439
- if (e$2.frame) s$1 = joinNewLine(s$1, e$2.frame);
2440
- if (e$2.stack) s$1 = joinNewLine(s$1, e$2.stack.replace(message, ""));
2441
- if (e$2.cause) {
2442
- s$1 = joinNewLine(s$1, "Caused by:");
2443
- s$1 = joinNewLine(s$1, getErrorMessage(e$2.cause).split("\n").map((line) => " " + line).join("\n"));
2444
- }
2445
- return s$1;
2446
- }
2447
- function joinNewLine(s1, s2) {
2448
- return s1.replace(/\n+$/, "") + "\n" + s2.replace(/^\n+/, "");
2449
- }
2450
-
2451
- //#endregion
2452
- //#region src/utils/transform-module-info.ts
2453
- function transformModuleInfo(info, option) {
2454
- return {
2455
- get ast() {
2456
- return require_dist.unsupported("ModuleInfo#ast");
2457
- },
2458
- get code() {
2459
- return info.code;
2460
- },
2461
- id: info.id,
2462
- importers: info.importers,
2463
- dynamicImporters: info.dynamicImporters,
2464
- importedIds: info.importedIds,
2465
- dynamicallyImportedIds: info.dynamicallyImportedIds,
2466
- exports: info.exports,
2467
- isEntry: info.isEntry,
2468
- ...option
2469
- };
2470
- }
2471
-
2472
- //#endregion
2473
- //#region src/utils/transform-sourcemap.ts
2474
- function isEmptySourcemapFiled(array$1) {
2475
- if (!array$1) return true;
2476
- if (array$1.length === 0 || !array$1[0]) return true;
2477
- return false;
2478
- }
2479
- function normalizeTransformHookSourcemap(id$1, originalCode, rawMap) {
2480
- if (!rawMap) return;
2481
- let map = typeof rawMap === "object" ? rawMap : JSON.parse(rawMap);
2482
- if (isEmptySourcemapFiled(map.sourcesContent)) map.sourcesContent = [originalCode];
2483
- if (isEmptySourcemapFiled(map.sources) || map.sources && map.sources.length === 1 && map.sources[0] !== id$1) map.sources = [id$1];
2484
- return map;
2485
- }
2486
-
2487
- //#endregion
2488
- //#region ../../node_modules/.pnpm/remeda@2.30.0/node_modules/remeda/dist/lazyDataLastImpl-BDhrIOwR.js
2489
- function e(e$2, t$3, n$2) {
2490
- let r$1 = (n$3) => e$2(n$3, ...t$3);
2491
- return n$2 === void 0 ? r$1 : Object.assign(r$1, {
2492
- lazy: n$2,
2493
- lazyArgs: t$3
2494
- });
2495
- }
2496
-
2497
- //#endregion
2498
- //#region ../../node_modules/.pnpm/remeda@2.30.0/node_modules/remeda/dist/purry-DH9cw9sy.js
2499
- function t(t$3, n$2, r$1) {
2500
- let i$1 = t$3.length - n$2.length;
2501
- if (i$1 === 0) return t$3(...n$2);
2502
- if (i$1 === 1) return e(t$3, n$2, r$1);
2503
- throw Error(`Wrong number of arguments`);
2504
- }
2505
-
2506
- //#endregion
2507
- //#region ../../node_modules/.pnpm/remeda@2.30.0/node_modules/remeda/dist/partition-BJYkp-a7.js
2508
- function t$1(...t$3) {
2509
- return t(n, t$3);
2510
- }
2511
- const n = (e$2, t$3) => {
2512
- let n$2 = [[], []];
2513
- for (let [r$1, i$1] of e$2.entries()) t$3(i$1, r$1, e$2) ? n$2[0].push(i$1) : n$2[1].push(i$1);
2514
- return n$2;
2515
- };
2516
-
2517
- //#endregion
2518
- //#region src/plugin/bindingify-hook-filter.ts
2519
- function generalHookFilterMatcherToFilterExprs(matcher, stringKind) {
2520
- if (typeof matcher === "string" || matcher instanceof RegExp) return [require_dist.include(generateAtomMatcher(stringKind, matcher))];
2521
- if (Array.isArray(matcher)) return matcher.map((m$1) => require_dist.include(generateAtomMatcher(stringKind, m$1)));
2522
- let ret = [];
2523
- if (matcher.exclude) ret.push(...require_dist.arraify(matcher.exclude).map((m$1) => require_dist.exclude(generateAtomMatcher(stringKind, m$1))));
2524
- if (matcher.include) ret.push(...require_dist.arraify(matcher.include).map((m$1) => require_dist.include(generateAtomMatcher(stringKind, m$1))));
2525
- return ret;
2526
- }
2527
- function generateAtomMatcher(kind, matcher) {
2528
- return kind === "code" ? require_dist.code(matcher) : require_dist.id(matcher);
2529
- }
2530
- function transformFilterMatcherToFilterExprs(filterOption) {
2531
- if (!filterOption) return void 0;
2532
- if (Array.isArray(filterOption)) return filterOption;
2533
- const { id: id$1, code: code$1, moduleType: moduleType$1 } = filterOption;
2534
- let ret = [];
2535
- let idIncludes = [];
2536
- let idExcludes = [];
2537
- let codeIncludes = [];
2538
- let codeExcludes = [];
2539
- if (id$1) [idIncludes, idExcludes] = t$1(generalHookFilterMatcherToFilterExprs(id$1, "id") ?? [], (m$1) => m$1.kind === "include");
2540
- if (code$1) [codeIncludes, codeExcludes] = t$1(generalHookFilterMatcherToFilterExprs(code$1, "code") ?? [], (m$1) => m$1.kind === "include");
2541
- ret.push(...idExcludes);
2542
- ret.push(...codeExcludes);
2543
- let andExprList = [];
2544
- if (moduleType$1) {
2545
- let moduleTypes = Array.isArray(moduleType$1) ? moduleType$1 : moduleType$1.include ?? [];
2546
- andExprList.push(require_dist.or(...moduleTypes.map((m$1) => require_dist.moduleType(m$1))));
2547
- }
2548
- if (idIncludes.length) andExprList.push(require_dist.or(...idIncludes.map((item) => item.expr)));
2549
- if (codeIncludes.length) andExprList.push(require_dist.or(...codeIncludes.map((item) => item.expr)));
2550
- if (andExprList.length) ret.push(require_dist.include(require_dist.and(...andExprList)));
2551
- return ret;
2552
- }
2553
- function bindingifyGeneralHookFilter(stringKind, pattern) {
2554
- let filterExprs = generalHookFilterMatcherToFilterExprs(pattern, stringKind);
2555
- let ret = [];
2556
- if (filterExprs) ret = filterExprs.map(bindingifyFilterExpr);
2557
- return ret.length > 0 ? { value: ret } : void 0;
2558
- }
2559
- function bindingifyFilterExpr(expr) {
2560
- let list = [];
2561
- bindingifyFilterExprImpl(expr, list);
2562
- return list;
2563
- }
2564
- function bindingifyFilterExprImpl(expr, list) {
2565
- switch (expr.kind) {
2566
- case "and": {
2567
- let args$1 = expr.args;
2568
- for (let i$1 = args$1.length - 1; i$1 >= 0; i$1--) bindingifyFilterExprImpl(args$1[i$1], list);
2569
- list.push({
2570
- kind: "And",
2571
- payload: args$1.length
2572
- });
2573
- break;
2574
- }
2575
- case "or": {
2576
- let args$1 = expr.args;
2577
- for (let i$1 = args$1.length - 1; i$1 >= 0; i$1--) bindingifyFilterExprImpl(args$1[i$1], list);
2578
- list.push({
2579
- kind: "Or",
2580
- payload: args$1.length
2581
- });
2582
- break;
2583
- }
2584
- case "not":
2585
- bindingifyFilterExprImpl(expr.expr, list);
2586
- list.push({ kind: "Not" });
2587
- break;
2588
- case "id":
2589
- list.push({
2590
- kind: "Id",
2591
- payload: expr.pattern
2592
- });
2593
- if (expr.params.cleanUrl) list.push({ kind: "CleanUrl" });
2594
- break;
2595
- case "moduleType":
2596
- list.push({
2597
- kind: "ModuleType",
2598
- payload: expr.pattern
2599
- });
2600
- break;
2601
- case "code":
2602
- list.push({
2603
- kind: "Code",
2604
- payload: expr.pattern
2605
- });
2606
- break;
2607
- case "include":
2608
- bindingifyFilterExprImpl(expr.expr, list);
2609
- list.push({ kind: "Include" });
2610
- break;
2611
- case "exclude":
2612
- bindingifyFilterExprImpl(expr.expr, list);
2613
- list.push({ kind: "Exclude" });
2614
- break;
2615
- case "query":
2616
- list.push({
2617
- kind: "QueryKey",
2618
- payload: expr.key
2619
- });
2620
- list.push({
2621
- kind: "QueryValue",
2622
- payload: expr.pattern
2623
- });
2624
- break;
2625
- default: throw new Error(`Unknown filter expression: ${expr}`);
2626
- }
2627
- }
2628
- function bindingifyResolveIdFilter(filterOption) {
2629
- if (!filterOption) return void 0;
2630
- if (Array.isArray(filterOption)) return { value: filterOption.map(bindingifyFilterExpr) };
2631
- return filterOption.id ? bindingifyGeneralHookFilter("id", filterOption.id) : void 0;
2632
- }
2633
- function bindingifyLoadFilter(filterOption) {
2634
- if (!filterOption) return void 0;
2635
- if (Array.isArray(filterOption)) return { value: filterOption.map(bindingifyFilterExpr) };
2636
- return filterOption.id ? bindingifyGeneralHookFilter("id", filterOption.id) : void 0;
2637
- }
2638
- function bindingifyTransformFilter(filterOption) {
2639
- if (!filterOption) return void 0;
2640
- let filterExprs = transformFilterMatcherToFilterExprs(filterOption);
2641
- let ret = [];
2642
- if (filterExprs) ret = filterExprs.map(bindingifyFilterExpr);
2643
- return { value: ret.length > 0 ? ret : void 0 };
2644
- }
2645
- function bindingifyRenderChunkFilter(filterOption) {
2646
- if (!filterOption) return void 0;
2647
- if (Array.isArray(filterOption)) return { value: filterOption.map(bindingifyFilterExpr) };
2648
- return filterOption.code ? bindingifyGeneralHookFilter("code", filterOption.code) : void 0;
2649
- }
2650
-
2651
- //#endregion
2652
- //#region src/plugin/bindingify-plugin-hook-meta.ts
2653
- function bindingifyPluginHookMeta(options) {
2654
- return { order: bindingPluginOrder(options.order) };
2655
- }
2656
- function bindingPluginOrder(order) {
2657
- switch (order) {
2658
- case "post": return src_rolldown_binding_wasi_cjs.BindingPluginOrder.Post;
2659
- case "pre": return src_rolldown_binding_wasi_cjs.BindingPluginOrder.Pre;
2660
- case null:
2661
- case void 0: return void 0;
2662
- default: throw new Error(`Unknown plugin order: ${order}`);
2663
- }
2664
- }
2665
-
2666
- //#endregion
2667
- //#region src/utils/asset-source.ts
2668
- function transformAssetSource(bindingAssetSource$1) {
2669
- return bindingAssetSource$1.inner;
2670
- }
2671
- function bindingAssetSource(source) {
2672
- return { inner: source };
2673
- }
2674
-
2675
- //#endregion
2676
- //#region src/plugin/fs.ts
2677
- const fsModule = {
2678
- appendFile: node_fs_promises.default.appendFile,
2679
- copyFile: node_fs_promises.default.copyFile,
2680
- mkdir: node_fs_promises.default.mkdir,
2681
- mkdtemp: node_fs_promises.default.mkdtemp,
2682
- readdir: node_fs_promises.default.readdir,
2683
- readFile: node_fs_promises.default.readFile,
2684
- realpath: node_fs_promises.default.realpath,
2685
- rename: node_fs_promises.default.rename,
2686
- rmdir: node_fs_promises.default.rmdir,
2687
- stat: node_fs_promises.default.stat,
2688
- lstat: node_fs_promises.default.lstat,
2689
- unlink: node_fs_promises.default.unlink,
2690
- writeFile: node_fs_promises.default.writeFile
2691
- };
2692
-
2693
- //#endregion
2694
- //#region src/plugin/plugin-context.ts
2695
- var PluginContextImpl = class extends MinimalPluginContextImpl {
2696
- fs = fsModule;
2697
- getModuleInfo;
2698
- constructor(outputOptions, context, plugin, data, onLog, logLevel, watchMode, currentLoadingModule) {
2699
- super(onLog, logLevel, plugin.name, watchMode);
2700
- this.outputOptions = outputOptions;
2701
- this.context = context;
2702
- this.data = data;
2703
- this.onLog = onLog;
2704
- this.currentLoadingModule = currentLoadingModule;
2705
- this.getModuleInfo = (id$1) => this.data.getModuleInfo(id$1, context);
2706
- }
2707
- async load(options) {
2708
- const id$1 = options.id;
2709
- if (id$1 === this.currentLoadingModule) this.onLog(LOG_LEVEL_WARN, require_parse_ast_index.logCycleLoading(this.pluginName, this.currentLoadingModule));
2710
- const moduleInfo = this.data.getModuleInfo(id$1, this.context);
2711
- if (moduleInfo && moduleInfo.code !== null) return moduleInfo;
2712
- const rawOptions = {
2713
- meta: options.meta || {},
2714
- moduleSideEffects: options.moduleSideEffects || null,
2715
- invalidate: false
2716
- };
2717
- this.data.updateModuleOption(id$1, rawOptions);
2718
- async function createLoadModulePromise(context, data) {
2719
- const loadPromise = data.loadModulePromiseMap.get(id$1);
2720
- if (loadPromise) return loadPromise;
2721
- const promise$1 = new Promise((resolve, _) => {
2722
- data.loadModulePromiseResolveFnMap.set(id$1, resolve);
2723
- });
2724
- data.loadModulePromiseMap.set(id$1, promise$1);
2725
- try {
2726
- await context.load(id$1, options.moduleSideEffects ?? void 0);
2727
- } catch (e$2) {
2728
- data.loadModulePromiseMap.delete(id$1);
2729
- data.loadModulePromiseResolveFnMap.delete(id$1);
2730
- throw e$2;
2731
- }
2732
- return promise$1;
2733
- }
2734
- await createLoadModulePromise(this.context, this.data);
2735
- return this.data.getModuleInfo(id$1, this.context);
2736
- }
2737
- async resolve(source, importer, options) {
2738
- let receipt = void 0;
2739
- if (options != null) receipt = this.data.saveResolveOptions(options);
2740
- const vitePluginCustom = Object.entries(options?.custom ?? {}).reduce((acc, [key, value]) => {
2741
- if (key.startsWith("vite:")) (acc ??= {})[key] = value;
2742
- return acc;
2743
- }, void 0);
2744
- const res = await this.context.resolve(source, importer, {
2745
- custom: receipt,
2746
- isEntry: options?.isEntry,
2747
- skipSelf: options?.skipSelf,
2748
- vitePluginCustom
2749
- });
2750
- if (receipt != null) this.data.removeSavedResolveOptions(receipt);
2751
- if (res == null) return null;
2752
- const info = this.data.getModuleOption(res.id) || {};
2753
- return {
2754
- ...res,
2755
- external: res.external === "relative" ? require_dist.unreachable(`The PluginContext resolve result external couldn't be 'relative'`) : res.external,
2756
- ...info,
2757
- moduleSideEffects: info.moduleSideEffects ?? res.moduleSideEffects ?? null,
2758
- packageJsonPath: res.packageJsonPath
2759
- };
2760
- }
2761
- emitFile = (file) => {
2762
- if (file.type === "prebuilt-chunk") return require_dist.unimplemented("PluginContext.emitFile with type prebuilt-chunk");
2763
- if (file.type === "chunk") return this.context.emitChunk({
2764
- preserveEntrySignatures: bindingifyPreserveEntrySignatures(file.preserveSignature),
2765
- ...file
2766
- });
2767
- const fnSanitizedFileName = file.fileName || typeof this.outputOptions.sanitizeFileName !== "function" ? void 0 : this.outputOptions.sanitizeFileName(file.name || "asset");
2768
- const filename = file.fileName ? void 0 : this.getAssetFileNames(file);
2769
- return this.context.emitFile({
2770
- ...file,
2771
- originalFileName: file.originalFileName || void 0,
2772
- source: bindingAssetSource(file.source)
2773
- }, filename, fnSanitizedFileName);
2774
- };
2775
- getAssetFileNames(file) {
2776
- if (typeof this.outputOptions.assetFileNames === "function") return this.outputOptions.assetFileNames({
2777
- type: "asset",
2778
- name: file.name,
2779
- names: file.name ? [file.name] : [],
2780
- originalFileName: file.originalFileName,
2781
- originalFileNames: file.originalFileName ? [file.originalFileName] : [],
2782
- source: file.source
2783
- });
2784
- }
2785
- getFileName(referenceId) {
2786
- return this.context.getFileName(referenceId);
2787
- }
2788
- getModuleIds() {
2789
- return this.data.getModuleIds(this.context);
2790
- }
2791
- addWatchFile(id$1) {
2792
- this.context.addWatchFile(id$1);
2793
- }
2794
- parse(input, options) {
2795
- return require_parse_ast_index.parseAst(input, options);
2796
- }
2797
- };
2798
-
2799
- //#endregion
2800
- //#region src/plugin/transform-plugin-context.ts
2801
- var TransformPluginContextImpl = class extends PluginContextImpl {
2802
- constructor(outputOptions, context, plugin, data, inner, moduleId, moduleSource, onLog, LogLevelOption, watchMode) {
2803
- super(outputOptions, context, plugin, data, onLog, LogLevelOption, watchMode, moduleId);
2804
- this.inner = inner;
2805
- this.moduleId = moduleId;
2806
- this.moduleSource = moduleSource;
2807
- const getLogHandler$1 = (handler) => (log, pos) => {
2808
- log = normalizeLog(log);
2809
- if (pos) require_parse_ast_index.augmentCodeLocation(log, pos, moduleSource, moduleId);
2810
- log.id = moduleId;
2811
- log.hook = "transform";
2812
- handler(log);
2813
- };
2814
- this.debug = getLogHandler$1(this.debug);
2815
- this.warn = getLogHandler$1(this.warn);
2816
- this.info = getLogHandler$1(this.info);
2817
- }
2818
- error(e$2, pos) {
2819
- if (typeof e$2 === "string") e$2 = { message: e$2 };
2820
- if (pos) require_parse_ast_index.augmentCodeLocation(e$2, pos, this.moduleSource, this.moduleId);
2821
- e$2.id = this.moduleId;
2822
- e$2.hook = "transform";
2823
- return require_parse_ast_index.error(require_parse_ast_index.logPluginError(normalizeLog(e$2), this.pluginName));
2824
- }
2825
- getCombinedSourcemap() {
2826
- return JSON.parse(this.inner.getCombinedSourcemap());
2827
- }
2828
- };
2829
-
2830
- //#endregion
2831
- //#region src/plugin/bindingify-build-hooks.ts
2832
- function bindingifyBuildStart(args$1) {
2833
- const hook = args$1.plugin.buildStart;
2834
- if (!hook) return {};
2835
- const { handler, meta } = normalizeHook(hook);
2836
- return {
2837
- plugin: async (ctx, opts) => {
2838
- await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), args$1.pluginContextData.getInputOptions(opts));
2839
- },
2840
- meta: bindingifyPluginHookMeta(meta)
2841
- };
2842
- }
2843
- function bindingifyBuildEnd(args$1) {
2844
- const hook = args$1.plugin.buildEnd;
2845
- if (!hook) return {};
2846
- const { handler, meta } = normalizeHook(hook);
2847
- return {
2848
- plugin: async (ctx, err) => {
2849
- await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), err ? normalizeErrors(err) : void 0);
2850
- },
2851
- meta: bindingifyPluginHookMeta(meta)
2852
- };
2853
- }
2854
- function bindingifyResolveId(args$1) {
2855
- const hook = args$1.plugin.resolveId;
2856
- if (!hook) return {};
2857
- const { handler, meta, options } = normalizeHook(hook);
2858
- return {
2859
- plugin: async (ctx, specifier, importer, extraOptions) => {
2860
- const contextResolveOptions = extraOptions.custom != null ? args$1.pluginContextData.getSavedResolveOptions(extraOptions.custom) : void 0;
2861
- const ret = await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), specifier, importer ?? void 0, {
2862
- ...extraOptions,
2863
- custom: contextResolveOptions?.custom
2864
- });
2865
- if (ret == null) return;
2866
- if (ret === false) return {
2867
- id: specifier,
2868
- external: true,
2869
- normalizeExternalId: true
2870
- };
2871
- if (typeof ret === "string") return {
2872
- id: ret,
2873
- normalizeExternalId: false
2874
- };
2875
- let exist = args$1.pluginContextData.updateModuleOption(ret.id, {
2876
- meta: ret.meta || {},
2877
- moduleSideEffects: ret.moduleSideEffects ?? null,
2878
- invalidate: false
2879
- });
2880
- return {
2881
- id: ret.id,
2882
- external: ret.external,
2883
- normalizeExternalId: false,
2884
- moduleSideEffects: exist.moduleSideEffects ?? void 0,
2885
- packageJsonPath: ret.packageJsonPath
2886
- };
2887
- },
2888
- meta: bindingifyPluginHookMeta(meta),
2889
- filter: bindingifyResolveIdFilter(options.filter)
2890
- };
2891
- }
2892
- function bindingifyResolveDynamicImport(args$1) {
2893
- const hook = args$1.plugin.resolveDynamicImport;
2894
- if (!hook) return {};
2895
- const { handler, meta } = normalizeHook(hook);
2896
- return {
2897
- plugin: async (ctx, specifier, importer) => {
2898
- const ret = await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), specifier, importer ?? void 0);
2899
- if (ret == null) return;
2900
- if (ret === false) return {
2901
- id: specifier,
2902
- external: true
2903
- };
2904
- if (typeof ret === "string") return { id: ret };
2905
- const result = {
2906
- id: ret.id,
2907
- external: ret.external
2908
- };
2909
- if (ret.moduleSideEffects !== null) result.moduleSideEffects = ret.moduleSideEffects;
2910
- args$1.pluginContextData.updateModuleOption(ret.id, {
2911
- meta: ret.meta || {},
2912
- moduleSideEffects: ret.moduleSideEffects || null,
2913
- invalidate: false
2914
- });
2915
- return result;
2916
- },
2917
- meta: bindingifyPluginHookMeta(meta)
2918
- };
2919
- }
2920
- function bindingifyTransform(args$1) {
2921
- const hook = args$1.plugin.transform;
2922
- if (!hook) return {};
2923
- const { handler, meta, options } = normalizeHook(hook);
2924
- return {
2925
- plugin: async (ctx, code$1, id$1, meta$1) => {
2926
- const ret = await handler.call(new TransformPluginContextImpl(args$1.outputOptions, ctx.inner(), args$1.plugin, args$1.pluginContextData, ctx, id$1, code$1, args$1.onLog, args$1.logLevel, args$1.watchMode), code$1, id$1, meta$1);
2927
- if (ret == null) return void 0;
2928
- if (typeof ret === "string") return { code: ret };
2929
- let moduleOption = args$1.pluginContextData.updateModuleOption(id$1, {
2930
- meta: ret.meta ?? {},
2931
- moduleSideEffects: ret.moduleSideEffects ?? null,
2932
- invalidate: false
2933
- });
2934
- return {
2935
- code: ret.code,
2936
- map: bindingifySourcemap$1(normalizeTransformHookSourcemap(id$1, code$1, ret.map)),
2937
- moduleSideEffects: moduleOption.moduleSideEffects ?? void 0,
2938
- moduleType: ret.moduleType
2939
- };
2940
- },
2941
- meta: bindingifyPluginHookMeta(meta),
2942
- filter: bindingifyTransformFilter(options.filter)
2943
- };
2944
- }
2945
- function bindingifyLoad(args$1) {
2946
- const hook = args$1.plugin.load;
2947
- if (!hook) return {};
2948
- const { handler, meta, options } = normalizeHook(hook);
2949
- return {
2950
- plugin: async (ctx, id$1) => {
2951
- const ret = await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode, id$1), id$1);
2952
- if (ret == null) return;
2953
- if (typeof ret === "string") return { code: ret };
2954
- let moduleOption = args$1.pluginContextData.updateModuleOption(id$1, {
2955
- meta: ret.meta || {},
2956
- moduleSideEffects: ret.moduleSideEffects ?? null,
2957
- invalidate: false
2958
- });
2959
- let map = preProcessSourceMap(ret, id$1);
2960
- return {
2961
- code: ret.code,
2962
- map: bindingifySourcemap$1(map),
2963
- moduleType: ret.moduleType,
2964
- moduleSideEffects: moduleOption.moduleSideEffects ?? void 0
2965
- };
2966
- },
2967
- meta: bindingifyPluginHookMeta(meta),
2968
- filter: bindingifyLoadFilter(options.filter)
2969
- };
2970
- }
2971
- function preProcessSourceMap(ret, id$1) {
2972
- if (!ret.map) return;
2973
- let map = typeof ret.map === "object" ? ret.map : JSON.parse(ret.map);
2974
- if (!isEmptySourcemapFiled(map.sources)) {
2975
- const directory = node_path.default.dirname(id$1) || ".";
2976
- const sourceRoot = map.sourceRoot || ".";
2977
- map.sources = map.sources.map((source) => node_path.default.resolve(directory, sourceRoot, source));
2978
- }
2979
- return map;
2980
- }
2981
- function bindingifyModuleParsed(args$1) {
2982
- const hook = args$1.plugin.moduleParsed;
2983
- if (!hook) return {};
2984
- const { handler, meta } = normalizeHook(hook);
2985
- return {
2986
- plugin: async (ctx, moduleInfo) => {
2987
- await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), transformModuleInfo(moduleInfo, args$1.pluginContextData.getModuleOption(moduleInfo.id)));
2988
- },
2989
- meta: bindingifyPluginHookMeta(meta)
2990
- };
2991
- }
2992
-
2993
- //#endregion
2994
- //#region src/utils/transform-rendered-module.ts
2995
- function transformToRenderedModule(bindingRenderedModule) {
2996
- return {
2997
- get code() {
2998
- return bindingRenderedModule.code;
2999
- },
3000
- get renderedLength() {
3001
- return bindingRenderedModule.code?.length || 0;
3002
- },
3003
- get renderedExports() {
3004
- return bindingRenderedModule.renderedExports;
3005
- }
3006
- };
3007
- }
3008
-
3009
- //#endregion
3010
- //#region src/utils/transform-rendered-chunk.ts
3011
- function transformRenderedChunk(chunk) {
3012
- let modules = null;
3013
- return {
3014
- type: "chunk",
3015
- get name() {
3016
- return chunk.name;
3017
- },
3018
- get isEntry() {
3019
- return chunk.isEntry;
3020
- },
3021
- get isDynamicEntry() {
3022
- return chunk.isDynamicEntry;
3023
- },
3024
- get facadeModuleId() {
3025
- return chunk.facadeModuleId;
3026
- },
3027
- get moduleIds() {
3028
- return chunk.moduleIds;
3029
- },
3030
- get exports() {
3031
- return chunk.exports;
3032
- },
3033
- get fileName() {
3034
- return chunk.fileName;
3035
- },
3036
- get imports() {
3037
- return chunk.imports;
3038
- },
3039
- get dynamicImports() {
3040
- return chunk.dynamicImports;
3041
- },
3042
- get modules() {
3043
- if (!modules) modules = transformChunkModules(chunk.modules);
3044
- return modules;
3045
- }
3046
- };
3047
- }
3048
- function transformChunkModules(modules) {
3049
- const result = {};
3050
- for (let i$1 = 0; i$1 < modules.values.length; i$1++) {
3051
- let key = modules.keys[i$1];
3052
- const mod = modules.values[i$1];
3053
- result[key] = transformToRenderedModule(mod);
3054
- }
3055
- return result;
3056
- }
3057
-
3058
- //#endregion
3059
- //#region src/utils/transform-to-rollup-output.ts
3060
- function transformToRollupSourceMap(map) {
3061
- const parsed = JSON.parse(map);
3062
- const obj = {
3063
- ...parsed,
3064
- toString() {
3065
- return JSON.stringify(obj);
3066
- },
3067
- toUrl() {
3068
- return `data:application/json;charset=utf-8;base64,${Buffer.from(obj.toString(), "utf-8").toString("base64")}`;
3069
- }
3070
- };
3071
- return obj;
3072
- }
3073
- function transformToRollupOutputChunk(bindingChunk, changed) {
3074
- const chunk = {
3075
- type: "chunk",
3076
- get code() {
3077
- return bindingChunk.code;
3078
- },
3079
- fileName: bindingChunk.fileName,
3080
- name: bindingChunk.name,
3081
- get modules() {
3082
- return transformChunkModules(bindingChunk.modules);
3083
- },
3084
- get imports() {
3085
- return bindingChunk.imports;
3086
- },
3087
- get dynamicImports() {
3088
- return bindingChunk.dynamicImports;
3089
- },
3090
- exports: bindingChunk.exports,
3091
- isEntry: bindingChunk.isEntry,
3092
- facadeModuleId: bindingChunk.facadeModuleId || null,
3093
- isDynamicEntry: bindingChunk.isDynamicEntry,
3094
- get moduleIds() {
3095
- return bindingChunk.moduleIds;
3096
- },
3097
- get map() {
3098
- return bindingChunk.map ? transformToRollupSourceMap(bindingChunk.map) : null;
3099
- },
3100
- sourcemapFileName: bindingChunk.sourcemapFileName || null,
3101
- preliminaryFileName: bindingChunk.preliminaryFileName
3102
- };
3103
- const cache = {};
3104
- return new Proxy(chunk, {
3105
- get(target, p$1) {
3106
- if (p$1 in cache) return cache[p$1];
3107
- const value = target[p$1];
3108
- cache[p$1] = value;
3109
- return value;
3110
- },
3111
- set(_target, p$1, newValue) {
3112
- cache[p$1] = newValue;
3113
- changed?.updated.add(bindingChunk.fileName);
3114
- return true;
3115
- },
3116
- has(target, p$1) {
3117
- if (p$1 in cache) return true;
3118
- return p$1 in target;
3119
- }
3120
- });
3121
- }
3122
- function transformToRollupOutputAsset(bindingAsset, changed) {
3123
- const asset = {
3124
- type: "asset",
3125
- fileName: bindingAsset.fileName,
3126
- originalFileName: bindingAsset.originalFileName || null,
3127
- originalFileNames: bindingAsset.originalFileNames,
3128
- get source() {
3129
- return transformAssetSource(bindingAsset.source);
3130
- },
3131
- name: bindingAsset.name ?? void 0,
3132
- names: bindingAsset.names
3133
- };
3134
- const cache = {};
3135
- return new Proxy(asset, {
3136
- get(target, p$1) {
3137
- if (p$1 in cache) return cache[p$1];
3138
- const value = target[p$1];
3139
- cache[p$1] = value;
3140
- return value;
3141
- },
3142
- set(_target, p$1, newValue) {
3143
- cache[p$1] = newValue;
3144
- changed?.updated.add(bindingAsset.fileName);
3145
- return true;
3146
- }
3147
- });
3148
- }
3149
- function transformToRollupOutput(output, changed) {
3150
- handleOutputErrors(output);
3151
- const { chunks, assets } = output;
3152
- return { output: [...chunks.map((chunk) => transformToRollupOutputChunk(chunk, changed)), ...assets.map((asset) => transformToRollupOutputAsset(asset, changed))] };
3153
- }
3154
- function handleOutputErrors(output) {
3155
- const rawErrors = output.errors;
3156
- if (rawErrors.length > 0) throw normalizeErrors(rawErrors);
3157
- }
3158
- function transformToOutputBundle(context, output, changed) {
3159
- const bundle = Object.fromEntries(transformToRollupOutput(output, changed).output.map((item) => [item.fileName, item]));
3160
- return new Proxy(bundle, {
3161
- set(_target, _p, _newValue, _receiver) {
3162
- const originalStackTraceLimit = Error.stackTraceLimit;
3163
- Error.stackTraceLimit = 2;
3164
- const message = "This plugin assigns to bundle variable. This is discouraged by Rollup and is not supported by Rolldown. This will be ignored. https://rollupjs.org/plugin-development/#generatebundle:~:text=DANGER,this.emitFile.";
3165
- const stack = new Error(message).stack ?? message;
3166
- Error.stackTraceLimit = originalStackTraceLimit;
3167
- context.warn({
3168
- message: stack,
3169
- code: "UNSUPPORTED_BUNDLE_ASSIGNMENT"
3170
- });
3171
- return true;
3172
- },
3173
- deleteProperty(target, property) {
3174
- if (typeof property === "string") changed.deleted.add(property);
3175
- return true;
3176
- }
3177
- });
3178
- }
3179
- function collectChangedBundle(changed, bundle) {
3180
- const changes = {};
3181
- for (const key in bundle) {
3182
- if (changed.deleted.has(key) || !changed.updated.has(key)) continue;
3183
- const item = bundle[key];
3184
- if (item.type === "asset") changes[key] = {
3185
- filename: item.fileName,
3186
- originalFileNames: item.originalFileNames,
3187
- source: bindingAssetSource(item.source),
3188
- names: item.names
3189
- };
3190
- else changes[key] = {
3191
- code: item.code,
3192
- filename: item.fileName,
3193
- name: item.name,
3194
- isEntry: item.isEntry,
3195
- exports: item.exports,
3196
- modules: {},
3197
- imports: item.imports,
3198
- dynamicImports: item.dynamicImports,
3199
- facadeModuleId: item.facadeModuleId || void 0,
3200
- isDynamicEntry: item.isDynamicEntry,
3201
- moduleIds: item.moduleIds,
3202
- map: bindingifySourcemap$1(item.map),
3203
- sourcemapFilename: item.sourcemapFileName || void 0,
3204
- preliminaryFilename: item.preliminaryFileName
3205
- };
3206
- }
3207
- return {
3208
- changes,
3209
- deleted: changed.deleted
3210
- };
3211
- }
3212
-
3213
- //#endregion
3214
- //#region src/plugin/bindingify-output-hooks.ts
3215
- function bindingifyRenderStart(args$1) {
3216
- const hook = args$1.plugin.renderStart;
3217
- if (!hook) return {};
3218
- const { handler, meta } = normalizeHook(hook);
3219
- return {
3220
- plugin: async (ctx, opts) => {
3221
- handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), args$1.pluginContextData.getOutputOptions(opts), args$1.pluginContextData.getInputOptions(opts));
3222
- },
3223
- meta: bindingifyPluginHookMeta(meta)
3224
- };
3225
- }
3226
- function bindingifyRenderChunk(args$1) {
3227
- const hook = args$1.plugin.renderChunk;
3228
- if (!hook) return {};
3229
- const { handler, meta, options } = normalizeHook(hook);
3230
- return {
3231
- plugin: async (ctx, code$1, chunk, opts, meta$1) => {
3232
- if (args$1.pluginContextData.getRenderChunkMeta() == null) args$1.pluginContextData.setRenderChunkMeta({ chunks: Object.fromEntries(Object.entries(meta$1.chunks).map(([key, value]) => [key, transformRenderedChunk(value)])) });
3233
- const ret = await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), code$1, transformRenderedChunk(chunk), args$1.pluginContextData.getOutputOptions(opts), args$1.pluginContextData.getRenderChunkMeta());
3234
- if (ret == null) return;
3235
- if (typeof ret === "string") return { code: ret };
3236
- if (!ret.map) return { code: ret.code };
3237
- return {
3238
- code: ret.code,
3239
- map: bindingifySourcemap$1(ret.map)
3240
- };
3241
- },
3242
- meta: bindingifyPluginHookMeta(meta),
3243
- filter: bindingifyRenderChunkFilter(options.filter)
3244
- };
3245
- }
3246
- function bindingifyAugmentChunkHash(args$1) {
3247
- const hook = args$1.plugin.augmentChunkHash;
3248
- if (!hook) return {};
3249
- const { handler, meta } = normalizeHook(hook);
3250
- return {
3251
- plugin: async (ctx, chunk) => {
3252
- return await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), transformRenderedChunk(chunk));
3253
- },
3254
- meta: bindingifyPluginHookMeta(meta)
3255
- };
3256
- }
3257
- function bindingifyRenderError(args$1) {
3258
- const hook = args$1.plugin.renderError;
3259
- if (!hook) return {};
3260
- const { handler, meta } = normalizeHook(hook);
3261
- return {
3262
- plugin: async (ctx, err) => {
3263
- handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), normalizeErrors(err));
3264
- },
3265
- meta: bindingifyPluginHookMeta(meta)
3266
- };
3267
- }
3268
- function bindingifyGenerateBundle(args$1) {
3269
- const hook = args$1.plugin.generateBundle;
3270
- if (!hook) return {};
3271
- const { handler, meta } = normalizeHook(hook);
3272
- return {
3273
- plugin: async (ctx, bundle, isWrite, opts) => {
3274
- const changed = {
3275
- updated: /* @__PURE__ */ new Set(),
3276
- deleted: /* @__PURE__ */ new Set()
3277
- };
3278
- const context = new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode);
3279
- const output = transformToOutputBundle(context, bundle, changed);
3280
- await handler.call(context, args$1.pluginContextData.getOutputOptions(opts), output, isWrite);
3281
- return collectChangedBundle(changed, output);
3282
- },
3283
- meta: bindingifyPluginHookMeta(meta)
3284
- };
3285
- }
3286
- function bindingifyWriteBundle(args$1) {
3287
- const hook = args$1.plugin.writeBundle;
3288
- if (!hook) return {};
3289
- const { handler, meta } = normalizeHook(hook);
3290
- return {
3291
- plugin: async (ctx, bundle, opts) => {
3292
- const changed = {
3293
- updated: /* @__PURE__ */ new Set(),
3294
- deleted: /* @__PURE__ */ new Set()
3295
- };
3296
- const context = new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode);
3297
- const output = transformToOutputBundle(context, bundle, changed);
3298
- await handler.call(context, args$1.pluginContextData.getOutputOptions(opts), output);
3299
- return collectChangedBundle(changed, output);
3300
- },
3301
- meta: bindingifyPluginHookMeta(meta)
3302
- };
3303
- }
3304
- function bindingifyCloseBundle(args$1) {
3305
- const hook = args$1.plugin.closeBundle;
3306
- if (!hook) return {};
3307
- const { handler, meta } = normalizeHook(hook);
3308
- return {
3309
- plugin: async (ctx) => {
3310
- await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode));
3311
- },
3312
- meta: bindingifyPluginHookMeta(meta)
3313
- };
3314
- }
3315
- function bindingifyBanner(args$1) {
3316
- const hook = args$1.plugin.banner;
3317
- if (!hook) return {};
3318
- const { handler, meta } = normalizeHook(hook);
3319
- return {
3320
- plugin: async (ctx, chunk) => {
3321
- if (typeof handler === "string") return handler;
3322
- return handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), transformRenderedChunk(chunk));
3323
- },
3324
- meta: bindingifyPluginHookMeta(meta)
3325
- };
3326
- }
3327
- function bindingifyFooter(args$1) {
3328
- const hook = args$1.plugin.footer;
3329
- if (!hook) return {};
3330
- const { handler, meta } = normalizeHook(hook);
3331
- return {
3332
- plugin: async (ctx, chunk) => {
3333
- if (typeof handler === "string") return handler;
3334
- return handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), transformRenderedChunk(chunk));
3335
- },
3336
- meta: bindingifyPluginHookMeta(meta)
3337
- };
3338
- }
3339
- function bindingifyIntro(args$1) {
3340
- const hook = args$1.plugin.intro;
3341
- if (!hook) return {};
3342
- const { handler, meta } = normalizeHook(hook);
3343
- return {
3344
- plugin: async (ctx, chunk) => {
3345
- if (typeof handler === "string") return handler;
3346
- return handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), transformRenderedChunk(chunk));
3347
- },
3348
- meta: bindingifyPluginHookMeta(meta)
3349
- };
3350
- }
3351
- function bindingifyOutro(args$1) {
3352
- const hook = args$1.plugin.outro;
3353
- if (!hook) return {};
3354
- const { handler, meta } = normalizeHook(hook);
3355
- return {
3356
- plugin: async (ctx, chunk) => {
3357
- if (typeof handler === "string") return handler;
3358
- return handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), transformRenderedChunk(chunk));
3359
- },
3360
- meta: bindingifyPluginHookMeta(meta)
3361
- };
3362
- }
3363
-
3364
- //#endregion
3365
- //#region src/plugin/bindingify-watch-hooks.ts
3366
- function bindingifyWatchChange(args$1) {
3367
- const hook = args$1.plugin.watchChange;
3368
- if (!hook) return {};
3369
- const { handler, meta } = normalizeHook(hook);
3370
- return {
3371
- plugin: async (ctx, id$1, event) => {
3372
- await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode), id$1, { event });
3373
- },
3374
- meta: bindingifyPluginHookMeta(meta)
3375
- };
3376
- }
3377
- function bindingifyCloseWatcher(args$1) {
3378
- const hook = args$1.plugin.closeWatcher;
3379
- if (!hook) return {};
3380
- const { handler, meta } = normalizeHook(hook);
3381
- return {
3382
- plugin: async (ctx) => {
3383
- await handler.call(new PluginContextImpl(args$1.outputOptions, ctx, args$1.plugin, args$1.pluginContextData, args$1.onLog, args$1.logLevel, args$1.watchMode));
3384
- },
3385
- meta: bindingifyPluginHookMeta(meta)
3386
- };
3387
- }
3388
-
3389
- //#endregion
3390
- //#region src/plugin/generated/hook-usage.ts
3391
- let HookUsageKind = /* @__PURE__ */ function(HookUsageKind$1) {
3392
- HookUsageKind$1[HookUsageKind$1["buildStart"] = 1] = "buildStart";
3393
- HookUsageKind$1[HookUsageKind$1["resolveId"] = 2] = "resolveId";
3394
- HookUsageKind$1[HookUsageKind$1["resolveDynamicImport"] = 4] = "resolveDynamicImport";
3395
- HookUsageKind$1[HookUsageKind$1["load"] = 8] = "load";
3396
- HookUsageKind$1[HookUsageKind$1["transform"] = 16] = "transform";
3397
- HookUsageKind$1[HookUsageKind$1["moduleParsed"] = 32] = "moduleParsed";
3398
- HookUsageKind$1[HookUsageKind$1["buildEnd"] = 64] = "buildEnd";
3399
- HookUsageKind$1[HookUsageKind$1["renderStart"] = 128] = "renderStart";
3400
- HookUsageKind$1[HookUsageKind$1["renderError"] = 256] = "renderError";
3401
- HookUsageKind$1[HookUsageKind$1["renderChunk"] = 512] = "renderChunk";
3402
- HookUsageKind$1[HookUsageKind$1["augmentChunkHash"] = 1024] = "augmentChunkHash";
3403
- HookUsageKind$1[HookUsageKind$1["generateBundle"] = 2048] = "generateBundle";
3404
- HookUsageKind$1[HookUsageKind$1["writeBundle"] = 4096] = "writeBundle";
3405
- HookUsageKind$1[HookUsageKind$1["closeBundle"] = 8192] = "closeBundle";
3406
- HookUsageKind$1[HookUsageKind$1["watchChange"] = 16384] = "watchChange";
3407
- HookUsageKind$1[HookUsageKind$1["closeWatcher"] = 32768] = "closeWatcher";
3408
- HookUsageKind$1[HookUsageKind$1["transformAst"] = 65536] = "transformAst";
3409
- HookUsageKind$1[HookUsageKind$1["banner"] = 131072] = "banner";
3410
- HookUsageKind$1[HookUsageKind$1["footer"] = 262144] = "footer";
3411
- HookUsageKind$1[HookUsageKind$1["intro"] = 524288] = "intro";
3412
- HookUsageKind$1[HookUsageKind$1["outro"] = 1048576] = "outro";
3413
- return HookUsageKind$1;
3414
- }({});
3415
- var HookUsage = class {
3416
- bitflag = BigInt(0);
3417
- constructor() {}
3418
- union(kind) {
3419
- this.bitflag |= BigInt(kind);
3420
- }
3421
- inner() {
3422
- return Number(this.bitflag);
3423
- }
3424
- };
3425
- function extractHookUsage(plugin) {
3426
- let hookUsage = new HookUsage();
3427
- if (plugin.buildStart) hookUsage.union(HookUsageKind.buildStart);
3428
- if (plugin.resolveId) hookUsage.union(HookUsageKind.resolveId);
3429
- if (plugin.resolveDynamicImport) hookUsage.union(HookUsageKind.resolveDynamicImport);
3430
- if (plugin.load) hookUsage.union(HookUsageKind.load);
3431
- if (plugin.transform) hookUsage.union(HookUsageKind.transform);
3432
- if (plugin.moduleParsed) hookUsage.union(HookUsageKind.moduleParsed);
3433
- if (plugin.buildEnd) hookUsage.union(HookUsageKind.buildEnd);
3434
- if (plugin.renderStart) hookUsage.union(HookUsageKind.renderStart);
3435
- if (plugin.renderError) hookUsage.union(HookUsageKind.renderError);
3436
- if (plugin.renderChunk) hookUsage.union(HookUsageKind.renderChunk);
3437
- if (plugin.augmentChunkHash) hookUsage.union(HookUsageKind.augmentChunkHash);
3438
- if (plugin.generateBundle) hookUsage.union(HookUsageKind.generateBundle);
3439
- if (plugin.writeBundle) hookUsage.union(HookUsageKind.writeBundle);
3440
- if (plugin.closeBundle) hookUsage.union(HookUsageKind.closeBundle);
3441
- if (plugin.watchChange) hookUsage.union(HookUsageKind.watchChange);
3442
- if (plugin.closeWatcher) hookUsage.union(HookUsageKind.closeWatcher);
3443
- if (plugin.banner) hookUsage.union(HookUsageKind.banner);
3444
- if (plugin.footer) hookUsage.union(HookUsageKind.footer);
3445
- if (plugin.intro) hookUsage.union(HookUsageKind.intro);
3446
- if (plugin.outro) hookUsage.union(HookUsageKind.outro);
3447
- return hookUsage;
3448
- }
3449
-
3450
- //#endregion
3451
- //#region src/plugin/bindingify-plugin.ts
3452
- function bindingifyPlugin(plugin, options, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode) {
3453
- const args$1 = {
3454
- plugin,
3455
- options,
3456
- outputOptions,
3457
- pluginContextData,
3458
- onLog,
3459
- logLevel,
3460
- watchMode,
3461
- normalizedOutputPlugins
3462
- };
3463
- const { plugin: buildStart, meta: buildStartMeta } = bindingifyBuildStart(args$1);
3464
- const { plugin: resolveId, meta: resolveIdMeta, filter: resolveIdFilter } = bindingifyResolveId(args$1);
3465
- const { plugin: resolveDynamicImport, meta: resolveDynamicImportMeta } = bindingifyResolveDynamicImport(args$1);
3466
- const { plugin: buildEnd, meta: buildEndMeta } = bindingifyBuildEnd(args$1);
3467
- const { plugin: transform, meta: transformMeta, filter: transformFilter } = bindingifyTransform(args$1);
3468
- const { plugin: moduleParsed, meta: moduleParsedMeta } = bindingifyModuleParsed(args$1);
3469
- const { plugin: load, meta: loadMeta, filter: loadFilter } = bindingifyLoad(args$1);
3470
- const { plugin: renderChunk, meta: renderChunkMeta, filter: renderChunkFilter } = bindingifyRenderChunk(args$1);
3471
- const { plugin: augmentChunkHash, meta: augmentChunkHashMeta } = bindingifyAugmentChunkHash(args$1);
3472
- const { plugin: renderStart, meta: renderStartMeta } = bindingifyRenderStart(args$1);
3473
- const { plugin: renderError, meta: renderErrorMeta } = bindingifyRenderError(args$1);
3474
- const { plugin: generateBundle, meta: generateBundleMeta } = bindingifyGenerateBundle(args$1);
3475
- const { plugin: writeBundle, meta: writeBundleMeta } = bindingifyWriteBundle(args$1);
3476
- const { plugin: closeBundle, meta: closeBundleMeta } = bindingifyCloseBundle(args$1);
3477
- const { plugin: banner, meta: bannerMeta } = bindingifyBanner(args$1);
3478
- const { plugin: footer, meta: footerMeta } = bindingifyFooter(args$1);
3479
- const { plugin: intro, meta: introMeta } = bindingifyIntro(args$1);
3480
- const { plugin: outro, meta: outroMeta } = bindingifyOutro(args$1);
3481
- const { plugin: watchChange, meta: watchChangeMeta } = bindingifyWatchChange(args$1);
3482
- const { plugin: closeWatcher, meta: closeWatcherMeta } = bindingifyCloseWatcher(args$1);
3483
- let hookUsage = extractHookUsage(plugin).inner();
3484
- const result = {
3485
- name: plugin.name,
3486
- buildStart,
3487
- buildStartMeta,
3488
- resolveId,
3489
- resolveIdMeta,
3490
- resolveIdFilter,
3491
- resolveDynamicImport,
3492
- resolveDynamicImportMeta,
3493
- buildEnd,
3494
- buildEndMeta,
3495
- transform,
3496
- transformMeta,
3497
- transformFilter,
3498
- moduleParsed,
3499
- moduleParsedMeta,
3500
- load,
3501
- loadMeta,
3502
- loadFilter,
3503
- renderChunk,
3504
- renderChunkMeta,
3505
- renderChunkFilter,
3506
- augmentChunkHash,
3507
- augmentChunkHashMeta,
3508
- renderStart,
3509
- renderStartMeta,
3510
- renderError,
3511
- renderErrorMeta,
3512
- generateBundle,
3513
- generateBundleMeta,
3514
- writeBundle,
3515
- writeBundleMeta,
3516
- closeBundle,
3517
- closeBundleMeta,
3518
- banner,
3519
- bannerMeta,
3520
- footer,
3521
- footerMeta,
3522
- intro,
3523
- introMeta,
3524
- outro,
3525
- outroMeta,
3526
- watchChange,
3527
- watchChangeMeta,
3528
- closeWatcher,
3529
- closeWatcherMeta,
3530
- hookUsage
3531
- };
3532
- return wrapHandlers(result);
3533
- }
3534
- function wrapHandlers(plugin) {
3535
- for (const hookName of [
3536
- "buildStart",
3537
- "resolveId",
3538
- "resolveDynamicImport",
3539
- "buildEnd",
3540
- "transform",
3541
- "moduleParsed",
3542
- "load",
3543
- "renderChunk",
3544
- "augmentChunkHash",
3545
- "renderStart",
3546
- "renderError",
3547
- "generateBundle",
3548
- "writeBundle",
3549
- "closeBundle",
3550
- "banner",
3551
- "footer",
3552
- "intro",
3553
- "outro",
3554
- "watchChange",
3555
- "closeWatcher"
3556
- ]) {
3557
- const handler = plugin[hookName];
3558
- if (handler) plugin[hookName] = async (...args$1) => {
3559
- try {
3560
- return await handler(...args$1);
3561
- } catch (e$2) {
3562
- return require_parse_ast_index.error(require_parse_ast_index.logPluginError(e$2, plugin.name, {
3563
- hook: hookName,
3564
- id: hookName === "transform" ? args$1[2] : void 0
3565
- }));
3566
- }
3567
- };
3568
- }
3569
- return plugin;
3570
- }
3571
-
3572
- //#endregion
3573
- //#region src/options/normalized-input-options.ts
3574
- var NormalizedInputOptionsImpl = class {
3575
- inner;
3576
- constructor(inner, onLog) {
3577
- this.onLog = onLog;
3578
- this.inner = inner;
3579
- }
3580
- get shimMissingExports() {
3581
- return this.inner.shimMissingExports;
3582
- }
3583
- get input() {
3584
- return this.inner.input;
3585
- }
3586
- get cwd() {
3587
- return this.inner.cwd ?? void 0;
3588
- }
3589
- get platform() {
3590
- return this.inner.platform;
3591
- }
3592
- get context() {
3593
- return this.inner.context;
3594
- }
3595
- };
3596
-
3597
- //#endregion
3598
- //#region src/types/chunking-context.ts
3599
- var ChunkingContextImpl = class {
3600
- constructor(context) {
3601
- this.context = context;
3602
- }
3603
- getModuleInfo(moduleId) {
3604
- const bindingInfo = this.context.getModuleInfo(moduleId);
3605
- if (bindingInfo) {
3606
- const info = transformModuleInfo(bindingInfo, {
3607
- moduleSideEffects: null,
3608
- meta: {}
3609
- });
3610
- return info;
3611
- }
3612
- return null;
3613
- }
3614
- };
3615
-
3616
- //#endregion
3617
- //#region src/utils/bindingify-output-options.ts
3618
- function bindingifyOutputOptions(outputOptions) {
3619
- const { dir, format, exports: exports$1, hashCharacters, sourcemap, sourcemapBaseUrl, sourcemapDebugIds, sourcemapIgnoreList, sourcemapPathTransform, name, assetFileNames, entryFileNames, chunkFileNames, cssEntryFileNames, cssChunkFileNames, banner, footer, intro, outro, esModule, globals, file, sanitizeFileName, preserveModules, virtualDirname, legalComments, preserveModulesRoot, manualChunks, topLevelVar } = outputOptions;
3620
- const advancedChunks = bindingifyAdvancedChunks(outputOptions.advancedChunks, manualChunks);
3621
- return {
3622
- dir,
3623
- file: file == null ? void 0 : file,
3624
- format: bindingifyFormat(format),
3625
- exports: exports$1,
3626
- hashCharacters,
3627
- sourcemap: bindingifySourcemap(sourcemap),
3628
- sourcemapBaseUrl,
3629
- sourcemapDebugIds,
3630
- sourcemapIgnoreList: bindingifySourcemapIgnoreList(sourcemapIgnoreList),
3631
- sourcemapPathTransform,
3632
- banner: bindingifyAddon(banner),
3633
- footer: bindingifyAddon(footer),
3634
- intro: bindingifyAddon(intro),
3635
- outro: bindingifyAddon(outro),
3636
- extend: outputOptions.extend,
3637
- globals,
3638
- esModule,
3639
- name,
3640
- assetFileNames: bindingifyAssetFilenames(assetFileNames),
3641
- entryFileNames,
3642
- chunkFileNames,
3643
- cssEntryFileNames,
3644
- cssChunkFileNames,
3645
- plugins: [],
3646
- minify: outputOptions.minify,
3647
- externalLiveBindings: outputOptions.externalLiveBindings,
3648
- inlineDynamicImports: outputOptions.inlineDynamicImports,
3649
- advancedChunks,
3650
- polyfillRequire: outputOptions.polyfillRequire,
3651
- sanitizeFileName,
3652
- preserveModules,
3653
- virtualDirname,
3654
- legalComments,
3655
- preserveModulesRoot,
3656
- topLevelVar,
3657
- minifyInternalExports: outputOptions.minifyInternalExports
3658
- };
3659
- }
3660
- function bindingifyAddon(configAddon) {
3661
- return async (chunk) => {
3662
- if (typeof configAddon === "function") return configAddon(transformRenderedChunk(chunk));
3663
- return configAddon || "";
3664
- };
3665
- }
3666
- function bindingifyFormat(format) {
3667
- switch (format) {
3668
- case void 0:
3669
- case "es":
3670
- case "esm":
3671
- case "module": return "es";
3672
- case "cjs":
3673
- case "commonjs": return "cjs";
3674
- case "iife": return "iife";
3675
- case "umd": return "umd";
3676
- default: require_dist.unimplemented(`output.format: ${format}`);
3677
- }
3678
- }
3679
- function bindingifySourcemap(sourcemap) {
3680
- switch (sourcemap) {
3681
- case true: return "file";
3682
- case "inline": return "inline";
3683
- case false:
3684
- case void 0: return void 0;
3685
- case "hidden": return "hidden";
3686
- default: throw new Error(`unknown sourcemap: ${sourcemap}`);
3687
- }
3688
- }
3689
- function bindingifySourcemapIgnoreList(sourcemapIgnoreList) {
3690
- return typeof sourcemapIgnoreList === "function" ? sourcemapIgnoreList : sourcemapIgnoreList === false ? () => false : (relativeSourcePath, _sourcemapPath) => relativeSourcePath.includes("node_modules");
3691
- }
3692
- function bindingifyAssetFilenames(assetFileNames) {
3693
- if (typeof assetFileNames === "function") return (asset) => {
3694
- return assetFileNames({
3695
- name: asset.name,
3696
- names: asset.names,
3697
- originalFileName: asset.originalFileName,
3698
- originalFileNames: asset.originalFileNames,
3699
- source: transformAssetSource(asset.source),
3700
- type: "asset"
3701
- });
3702
- };
3703
- return assetFileNames;
3704
- }
3705
- function bindingifyAdvancedChunks(advancedChunks, manualChunks) {
3706
- if (manualChunks != null && advancedChunks != null) console.warn("`manualChunks` option is ignored due to `advancedChunks` option is specified.");
3707
- else if (manualChunks != null) advancedChunks = { groups: [{ name(moduleId, ctx) {
3708
- return manualChunks(moduleId, { getModuleInfo: (id$1) => ctx.getModuleInfo(id$1) });
3709
- } }] };
3710
- if (advancedChunks == null) return void 0;
3711
- const { groups,...restAdvancedChunks } = advancedChunks;
3712
- return {
3713
- ...restAdvancedChunks,
3714
- groups: groups?.map((group) => {
3715
- const { name,...restGroup } = group;
3716
- return {
3717
- ...restGroup,
3718
- name: typeof name === "function" ? (id$1, ctx) => name(id$1, new ChunkingContextImpl(ctx)) : name
3719
- };
3720
- })
3721
- };
3722
- }
3723
-
3724
- //#endregion
3725
- //#region src/options/normalized-output-options.ts
3726
- var NormalizedOutputOptionsImpl = class {
3727
- constructor(inner, outputOptions, normalizedOutputPlugins) {
3728
- this.inner = inner;
3729
- this.outputOptions = outputOptions;
3730
- this.normalizedOutputPlugins = normalizedOutputPlugins;
3731
- }
3732
- get dir() {
3733
- return this.inner.dir ?? void 0;
3734
- }
3735
- get entryFileNames() {
3736
- return this.inner.entryFilenames || this.outputOptions.entryFileNames;
3737
- }
3738
- get chunkFileNames() {
3739
- return this.inner.chunkFilenames || this.outputOptions.chunkFileNames;
3740
- }
3741
- get assetFileNames() {
3742
- return this.inner.assetFilenames || this.outputOptions.assetFileNames;
3743
- }
3744
- get format() {
3745
- return this.inner.format;
3746
- }
3747
- get exports() {
3748
- return this.inner.exports;
3749
- }
3750
- get sourcemap() {
3751
- return this.inner.sourcemap;
3752
- }
3753
- get sourcemapBaseUrl() {
3754
- return this.inner.sourcemapBaseUrl ?? void 0;
3755
- }
3756
- get cssEntryFileNames() {
3757
- return this.inner.cssEntryFilenames || this.outputOptions.cssEntryFileNames;
3758
- }
3759
- get cssChunkFileNames() {
3760
- return this.inner.cssChunkFilenames || this.outputOptions.cssChunkFileNames;
3761
- }
3762
- get shimMissingExports() {
3763
- return this.inner.shimMissingExports;
3764
- }
3765
- get name() {
3766
- return this.inner.name ?? void 0;
3767
- }
3768
- get file() {
3769
- return this.inner.file ?? void 0;
3770
- }
3771
- get inlineDynamicImports() {
3772
- return this.inner.inlineDynamicImports;
3773
- }
3774
- get externalLiveBindings() {
3775
- return this.inner.externalLiveBindings;
3776
- }
3777
- get banner() {
3778
- return normalizeAddon(this.outputOptions.banner);
3779
- }
3780
- get footer() {
3781
- return normalizeAddon(this.outputOptions.footer);
3782
- }
3783
- get intro() {
3784
- return normalizeAddon(this.outputOptions.intro);
3785
- }
3786
- get outro() {
3787
- return normalizeAddon(this.outputOptions.outro);
3788
- }
3789
- get esModule() {
3790
- return this.inner.esModule;
3791
- }
3792
- get extend() {
3793
- return this.inner.extend;
3794
- }
3795
- get globals() {
3796
- return this.inner.globals || this.outputOptions.globals;
3797
- }
3798
- get hashCharacters() {
3799
- return this.inner.hashCharacters;
3800
- }
3801
- get sourcemapDebugIds() {
3802
- return this.inner.sourcemapDebugIds;
3803
- }
3804
- get sourcemapIgnoreList() {
3805
- return bindingifySourcemapIgnoreList(this.outputOptions.sourcemapIgnoreList);
3806
- }
3807
- get sourcemapPathTransform() {
3808
- return this.outputOptions.sourcemapPathTransform;
3809
- }
3810
- get minify() {
3811
- let ret = this.inner.minify;
3812
- if (typeof ret === "object" && ret !== null) {
3813
- delete ret["codegen"];
3814
- delete ret["module"];
3815
- delete ret["sourcemap"];
3816
- }
3817
- return ret;
3818
- }
3819
- get legalComments() {
3820
- return this.inner.legalComments;
3821
- }
3822
- get polyfillRequire() {
3823
- return this.inner.polyfillRequire;
3824
- }
3825
- get plugins() {
3826
- return this.normalizedOutputPlugins;
3827
- }
3828
- get preserveModules() {
3829
- return this.inner.preserveModules;
3830
- }
3831
- get preserveModulesRoot() {
3832
- return this.inner.preserveModulesRoot;
3833
- }
3834
- get virtualDirname() {
3835
- return this.inner.virtualDirname;
3836
- }
3837
- get topLevelVar() {
3838
- return this.inner.topLevelVar ?? false;
3839
- }
3840
- get minifyInternalExports() {
3841
- return this.inner.minifyInternalExports ?? false;
3842
- }
3843
- };
3844
- function normalizeAddon(value) {
3845
- if (typeof value === "function") return value;
3846
- return () => value || "";
3847
- }
3848
-
3849
- //#endregion
3850
- //#region src/plugin/plugin-context-data.ts
3851
- var PluginContextData = class {
3852
- moduleOptionMap = /* @__PURE__ */ new Map();
3853
- resolveOptionsMap = /* @__PURE__ */ new Map();
3854
- loadModulePromiseMap = /* @__PURE__ */ new Map();
3855
- loadModulePromiseResolveFnMap = /* @__PURE__ */ new Map();
3856
- renderedChunkMeta = null;
3857
- normalizedInputOptions = null;
3858
- normalizedOutputOptions = null;
3859
- constructor(onLog, outputOptions, normalizedOutputPlugins) {
3860
- this.onLog = onLog;
3861
- this.outputOptions = outputOptions;
3862
- this.normalizedOutputPlugins = normalizedOutputPlugins;
3863
- }
3864
- updateModuleOption(id$1, option) {
3865
- const existing = this.moduleOptionMap.get(id$1);
3866
- if (existing) {
3867
- if (option.moduleSideEffects != null) existing.moduleSideEffects = option.moduleSideEffects;
3868
- if (option.meta != null) Object.assign(existing.meta, option.meta);
3869
- if (option.invalidate != null) existing.invalidate = option.invalidate;
3870
- } else {
3871
- this.moduleOptionMap.set(id$1, option);
3872
- return option;
3873
- }
3874
- return existing;
3875
- }
3876
- getModuleOption(id$1) {
3877
- const option = this.moduleOptionMap.get(id$1);
3878
- if (!option) {
3879
- const raw = {
3880
- moduleSideEffects: null,
3881
- meta: {}
3882
- };
3883
- this.moduleOptionMap.set(id$1, raw);
3884
- return raw;
3885
- }
3886
- return option;
3887
- }
3888
- getModuleInfo(id$1, context) {
3889
- const bindingInfo = context.getModuleInfo(id$1);
3890
- if (bindingInfo) {
3891
- const info = transformModuleInfo(bindingInfo, this.getModuleOption(id$1));
3892
- return this.proxyModuleInfo(id$1, info);
3893
- }
3894
- return null;
3895
- }
3896
- proxyModuleInfo(id$1, info) {
3897
- let moduleSideEffects = info.moduleSideEffects;
3898
- Object.defineProperty(info, "moduleSideEffects", {
3899
- get() {
3900
- return moduleSideEffects;
3901
- },
3902
- set: (v) => {
3903
- this.updateModuleOption(id$1, {
3904
- moduleSideEffects: v,
3905
- meta: info.meta,
3906
- invalidate: true
3907
- });
3908
- moduleSideEffects = v;
3909
- }
3910
- });
3911
- return info;
3912
- }
3913
- getModuleIds(context) {
3914
- const moduleIds = context.getModuleIds();
3915
- return moduleIds.values();
3916
- }
3917
- saveResolveOptions(options) {
3918
- const index = this.resolveOptionsMap.size;
3919
- this.resolveOptionsMap.set(index, options);
3920
- return index;
3921
- }
3922
- getSavedResolveOptions(receipt) {
3923
- return this.resolveOptionsMap.get(receipt);
3924
- }
3925
- removeSavedResolveOptions(receipt) {
3926
- this.resolveOptionsMap.delete(receipt);
3927
- }
3928
- setRenderChunkMeta(meta) {
3929
- this.renderedChunkMeta = meta;
3930
- }
3931
- getRenderChunkMeta() {
3932
- return this.renderedChunkMeta;
3933
- }
3934
- getInputOptions(opts) {
3935
- this.normalizedInputOptions ??= new NormalizedInputOptionsImpl(opts, this.onLog);
3936
- return this.normalizedInputOptions;
3937
- }
3938
- getOutputOptions(opts) {
3939
- this.normalizedOutputOptions ??= new NormalizedOutputOptionsImpl(opts, this.outputOptions, this.normalizedOutputPlugins);
3940
- return this.normalizedOutputOptions;
3941
- }
3942
- markModuleLoaded(id$1, _success) {
3943
- const resolve = this.loadModulePromiseResolveFnMap.get(id$1);
3944
- if (resolve) resolve();
3945
- }
3946
- clear() {
3947
- this.renderedChunkMeta = null;
3948
- this.loadModulePromiseMap.clear();
3949
- this.loadModulePromiseResolveFnMap.clear();
3950
- }
3951
- };
3952
-
3953
- //#endregion
3954
- //#region src/utils/bindingify-input-options.ts
3955
- function bindingifyInputOptions(rawPlugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode) {
3956
- const pluginContextData = new PluginContextData(onLog, outputOptions, normalizedOutputPlugins);
3957
- const plugins = rawPlugins.map((plugin) => {
3958
- if ("_parallel" in plugin) return void 0;
3959
- if (isBuiltinPlugin(plugin)) return bindingifyBuiltInPlugin(plugin);
3960
- return bindingifyPlugin(plugin, inputOptions, outputOptions, pluginContextData, normalizedOutputPlugins, onLog, logLevel, watchMode);
3961
- });
3962
- const { jsx, transform } = bindingifyJsx(onLog, inputOptions.jsx, inputOptions.transform);
3963
- return {
3964
- input: bindingifyInput(inputOptions.input),
3965
- plugins,
3966
- cwd: inputOptions.cwd ?? process.cwd(),
3967
- external: bindingifyExternal(inputOptions.external),
3968
- resolve: bindingifyResolve(inputOptions.resolve),
3969
- platform: inputOptions.platform,
3970
- shimMissingExports: inputOptions.shimMissingExports,
3971
- logLevel: bindingifyLogLevel(logLevel),
3972
- onLog: async (level, log) => onLog(level, log),
3973
- treeshake: bindingifyTreeshakeOptions(inputOptions.treeshake),
3974
- moduleTypes: inputOptions.moduleTypes,
3975
- define: inputOptions.define ? Object.entries(inputOptions.define) : void 0,
3976
- inject: bindingifyInject(inputOptions.inject),
3977
- experimental: bindingifyExperimental(inputOptions.experimental),
3978
- profilerNames: inputOptions?.profilerNames,
3979
- jsx,
3980
- transform,
3981
- watch: bindingifyWatch(inputOptions.watch),
3982
- dropLabels: inputOptions.dropLabels,
3983
- keepNames: inputOptions.keepNames,
3984
- checks: inputOptions.checks,
3985
- deferSyncScanData: () => {
3986
- let ret = [];
3987
- pluginContextData.moduleOptionMap.forEach((value, key) => {
3988
- if (value.invalidate) ret.push({
3989
- id: key,
3990
- sideEffects: value.moduleSideEffects ?? void 0
3991
- });
3992
- });
3993
- return ret;
3994
- },
3995
- makeAbsoluteExternalsRelative: bindingifyMakeAbsoluteExternalsRelative(inputOptions.makeAbsoluteExternalsRelative),
3996
- debug: inputOptions.debug,
3997
- invalidateJsSideCache: pluginContextData.clear.bind(pluginContextData),
3998
- markModuleLoaded: pluginContextData.markModuleLoaded.bind(pluginContextData),
3999
- preserveEntrySignatures: bindingifyPreserveEntrySignatures(inputOptions.preserveEntrySignatures),
4000
- optimization: inputOptions.optimization,
4001
- context: inputOptions.context,
4002
- tsconfig: inputOptions.resolve?.tsconfigFilename ?? inputOptions.tsconfig
4003
- };
4004
- }
4005
- function bindingifyHmr(hmr) {
4006
- if (hmr) {
4007
- if (typeof hmr === "boolean") return hmr ? {} : void 0;
4008
- return hmr;
4009
- }
4010
- }
4011
- function bindingifyAttachDebugInfo(attachDebugInfo) {
4012
- switch (attachDebugInfo) {
4013
- case void 0: return void 0;
4014
- case "full": return src_rolldown_binding_wasi_cjs.BindingAttachDebugInfo.Full;
4015
- case "simple": return src_rolldown_binding_wasi_cjs.BindingAttachDebugInfo.Simple;
4016
- case "none": return src_rolldown_binding_wasi_cjs.BindingAttachDebugInfo.None;
4017
- }
4018
- }
4019
- function bindingifyExternal(external) {
4020
- if (external) {
4021
- if (typeof external === "function") return (id$1, importer, isResolved) => {
4022
- if (id$1.startsWith("\0")) return false;
4023
- return external(id$1, importer, isResolved) ?? false;
4024
- };
4025
- const externalArr = require_dist.arraify(external);
4026
- return (id$1, _importer, _isResolved) => {
4027
- return externalArr.some((pat) => {
4028
- if (pat instanceof RegExp) return pat.test(id$1);
4029
- return id$1 === pat;
4030
- });
4031
- };
4032
- }
4033
- }
4034
- function bindingifyExperimental(experimental) {
4035
- let chunkModulesOrder = src_rolldown_binding_wasi_cjs.BindingChunkModuleOrderBy.ExecOrder;
4036
- if (experimental?.chunkModulesOrder) switch (experimental.chunkModulesOrder) {
4037
- case "exec-order":
4038
- chunkModulesOrder = src_rolldown_binding_wasi_cjs.BindingChunkModuleOrderBy.ExecOrder;
4039
- break;
4040
- case "module-id":
4041
- chunkModulesOrder = src_rolldown_binding_wasi_cjs.BindingChunkModuleOrderBy.ModuleId;
4042
- break;
4043
- default: throw new Error(`Unexpected chunkModulesOrder: ${experimental.chunkModulesOrder}`);
4044
- }
4045
- return {
4046
- strictExecutionOrder: experimental?.strictExecutionOrder,
4047
- disableLiveBindings: experimental?.disableLiveBindings,
4048
- viteMode: experimental?.viteMode,
4049
- resolveNewUrlToAsset: experimental?.resolveNewUrlToAsset,
4050
- hmr: bindingifyHmr(experimental?.hmr),
4051
- attachDebugInfo: bindingifyAttachDebugInfo(experimental?.attachDebugInfo),
4052
- chunkModulesOrder,
4053
- chunkImportMap: experimental?.chunkImportMap,
4054
- onDemandWrapping: experimental?.onDemandWrapping,
4055
- incrementalBuild: experimental?.incrementalBuild
4056
- };
4057
- }
4058
- function bindingifyResolve(resolve) {
4059
- const yarnPnp = typeof process === "object" && !!process.versions?.pnp;
4060
- if (resolve) {
4061
- const { alias, extensionAlias,...rest } = resolve;
4062
- return {
4063
- alias: alias ? Object.entries(alias).map(([name, replacement]) => ({
4064
- find: name,
4065
- replacements: require_dist.arraify(replacement)
4066
- })) : void 0,
4067
- extensionAlias: extensionAlias ? Object.entries(extensionAlias).map(([name, value]) => ({
4068
- target: name,
4069
- replacements: value
4070
- })) : void 0,
4071
- yarnPnp,
4072
- ...rest
4073
- };
4074
- } else return { yarnPnp };
4075
- }
4076
- function bindingifyInject(inject) {
4077
- if (inject) return Object.entries(inject).map(([alias, item]) => {
4078
- if (Array.isArray(item)) {
4079
- if (item[1] === "*") return {
4080
- tagNamespace: true,
4081
- alias,
4082
- from: item[0]
4083
- };
4084
- return {
4085
- tagNamed: true,
4086
- alias,
4087
- from: item[0],
4088
- imported: item[1]
4089
- };
4090
- } else return {
4091
- tagNamed: true,
4092
- imported: "default",
4093
- alias,
4094
- from: item
4095
- };
4096
- });
4097
- }
4098
- function bindingifyLogLevel(logLevel) {
4099
- switch (logLevel) {
4100
- case "silent": return src_rolldown_binding_wasi_cjs.BindingLogLevel.Silent;
4101
- case "debug": return src_rolldown_binding_wasi_cjs.BindingLogLevel.Debug;
4102
- case "warn": return src_rolldown_binding_wasi_cjs.BindingLogLevel.Warn;
4103
- case "info": return src_rolldown_binding_wasi_cjs.BindingLogLevel.Info;
4104
- default: throw new Error(`Unexpected log level: ${logLevel}`);
4105
- }
4106
- }
4107
- function bindingifyInput(input) {
4108
- if (input === void 0) return [];
4109
- if (typeof input === "string") return [{ import: input }];
4110
- if (Array.isArray(input)) return input.map((src) => ({ import: src }));
4111
- return Object.entries(input).map(([name, import_path]) => {
4112
- return {
4113
- name,
4114
- import: import_path
4115
- };
4116
- });
4117
- }
4118
- function bindingifyJsx(onLog, input, transform) {
4119
- if (transform?.jsx) {
4120
- if (input !== void 0) onLog(LOG_LEVEL_WARN, require_parse_ast_index.logDuplicateJsxConfig());
4121
- return { transform };
4122
- }
4123
- if (typeof input === "object") {
4124
- if (input.mode === "preserve") return {
4125
- jsx: src_rolldown_binding_wasi_cjs.BindingJsx.Preserve,
4126
- transform
4127
- };
4128
- const mode = input.mode ?? "automatic";
4129
- transform ??= {};
4130
- transform.jsx = {
4131
- runtime: mode,
4132
- pragma: input.factory,
4133
- pragmaFrag: input.fragment,
4134
- importSource: mode === "classic" ? input.importSource : mode === "automatic" ? input.jsxImportSource : void 0
4135
- };
4136
- return { transform };
4137
- }
4138
- let jsx;
4139
- switch (input) {
4140
- case false:
4141
- jsx = src_rolldown_binding_wasi_cjs.BindingJsx.Disable;
4142
- break;
4143
- case "react":
4144
- jsx = src_rolldown_binding_wasi_cjs.BindingJsx.React;
4145
- break;
4146
- case "react-jsx":
4147
- jsx = src_rolldown_binding_wasi_cjs.BindingJsx.ReactJsx;
4148
- break;
4149
- case "preserve":
4150
- jsx = src_rolldown_binding_wasi_cjs.BindingJsx.Preserve;
4151
- break;
4152
- }
4153
- return {
4154
- jsx,
4155
- transform
4156
- };
4157
- }
4158
- function bindingifyWatch(watch$1) {
4159
- if (watch$1) return {
4160
- buildDelay: watch$1.buildDelay,
4161
- skipWrite: watch$1.skipWrite,
4162
- include: normalizedStringOrRegex(watch$1.include),
4163
- exclude: normalizedStringOrRegex(watch$1.exclude),
4164
- onInvalidate: (...args$1) => watch$1.onInvalidate?.(...args$1)
4165
- };
4166
- }
4167
- function bindingifyTreeshakeOptions(config) {
4168
- if (config === false) return void 0;
4169
- if (config === true || config === void 0) return { moduleSideEffects: true };
4170
- let normalizedConfig = {
4171
- moduleSideEffects: true,
4172
- annotations: config.annotations,
4173
- manualPureFunctions: config.manualPureFunctions,
4174
- unknownGlobalSideEffects: config.unknownGlobalSideEffects,
4175
- commonjs: config.commonjs
4176
- };
4177
- switch (config.propertyReadSideEffects) {
4178
- case "always":
4179
- normalizedConfig.propertyReadSideEffects = src_rolldown_binding_wasi_cjs.BindingPropertyReadSideEffects.Always;
4180
- break;
4181
- case false:
4182
- normalizedConfig.propertyReadSideEffects = src_rolldown_binding_wasi_cjs.BindingPropertyReadSideEffects.False;
4183
- break;
4184
- default:
4185
- }
4186
- switch (config.propertyWriteSideEffects) {
4187
- case "always":
4188
- normalizedConfig.propertyWriteSideEffects = src_rolldown_binding_wasi_cjs.BindingPropertyWriteSideEffects.Always;
4189
- break;
4190
- case false:
4191
- normalizedConfig.propertyWriteSideEffects = src_rolldown_binding_wasi_cjs.BindingPropertyWriteSideEffects.False;
4192
- break;
4193
- default:
4194
- }
4195
- if (config.moduleSideEffects === void 0) normalizedConfig.moduleSideEffects = true;
4196
- else if (config.moduleSideEffects === "no-external") normalizedConfig.moduleSideEffects = [{
4197
- external: true,
4198
- sideEffects: false
4199
- }, {
4200
- external: false,
4201
- sideEffects: true
4202
- }];
4203
- else normalizedConfig.moduleSideEffects = config.moduleSideEffects;
4204
- return normalizedConfig;
4205
- }
4206
- function bindingifyMakeAbsoluteExternalsRelative(makeAbsoluteExternalsRelative) {
4207
- if (makeAbsoluteExternalsRelative === "ifRelativeSource") return { type: "IfRelativeSource" };
4208
- if (typeof makeAbsoluteExternalsRelative === "boolean") return {
4209
- type: "Bool",
4210
- field0: makeAbsoluteExternalsRelative
4211
- };
4212
- }
4213
- function bindingifyPreserveEntrySignatures(preserveEntrySignatures) {
4214
- if (preserveEntrySignatures == void 0) return void 0;
4215
- else if (typeof preserveEntrySignatures === "string") return {
4216
- type: "String",
4217
- field0: preserveEntrySignatures
4218
- };
4219
- else return {
4220
- type: "Bool",
4221
- field0: preserveEntrySignatures
4222
- };
4223
- }
4224
-
4225
- //#endregion
4226
- //#region src/utils/initialize-parallel-plugins.ts
4227
- async function initializeParallelPlugins(plugins) {
4228
- const pluginInfos = [];
4229
- for (const [index, plugin] of plugins.entries()) if ("_parallel" in plugin) {
4230
- const { fileUrl, options } = plugin._parallel;
4231
- pluginInfos.push({
4232
- index,
4233
- fileUrl,
4234
- options
4235
- });
4236
- }
4237
- if (pluginInfos.length <= 0) return void 0;
4238
- const count = availableParallelism();
4239
- const parallelJsPluginRegistry = new src_rolldown_binding_wasi_cjs.ParallelJsPluginRegistry(count);
4240
- const registryId = parallelJsPluginRegistry.id;
4241
- const workers = await initializeWorkers(registryId, count, pluginInfos);
4242
- const stopWorkers = async () => {
4243
- await Promise.all(workers.map((worker) => worker.terminate()));
4244
- };
4245
- return {
4246
- registry: parallelJsPluginRegistry,
4247
- stopWorkers
4248
- };
4249
- }
4250
- function initializeWorkers(registryId, count, pluginInfos) {
4251
- return Promise.all(Array.from({ length: count }, (_, i$1) => initializeWorker(registryId, pluginInfos, i$1)));
4252
- }
4253
- async function initializeWorker(registryId, pluginInfos, threadNumber) {
4254
- const urlString = (void 0)("#parallel-plugin-worker");
4255
- const workerData = {
4256
- registryId,
4257
- pluginInfos,
4258
- threadNumber
4259
- };
4260
- let worker;
4261
- try {
4262
- worker = new node_worker_threads.Worker(new URL(urlString), { workerData });
4263
- worker.unref();
4264
- await new Promise((resolve, reject) => {
4265
- worker.once("message", async (message) => {
4266
- if (message.type === "error") reject(message.error);
4267
- else resolve();
4268
- });
4269
- });
4270
- return worker;
4271
- } catch (e$2) {
4272
- worker?.terminate();
4273
- throw e$2;
4274
- }
4275
- }
4276
- const availableParallelism = () => {
4277
- let availableParallelism$1 = 1;
4278
- try {
4279
- availableParallelism$1 = node_os.default.availableParallelism();
4280
- } catch {
4281
- const cpus = node_os.default.cpus();
4282
- if (Array.isArray(cpus) && cpus.length > 0) availableParallelism$1 = cpus.length;
4283
- }
4284
- return Math.min(availableParallelism$1, 8);
4285
- };
4286
-
4287
- //#endregion
4288
- //#region src/utils/create-bundler-option.ts
4289
- async function createBundlerOptions(inputOptions, outputOptions, watchMode) {
4290
- const inputPlugins = await normalizePluginOption(inputOptions.plugins);
4291
- const outputPlugins = await normalizePluginOption(outputOptions.plugins);
4292
- const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO;
4293
- const onLog = getLogger(getObjectPlugins(inputPlugins), getOnLog(inputOptions, logLevel), logLevel, watchMode);
4294
- outputOptions = PluginDriver.callOutputOptionsHook([...inputPlugins, ...outputPlugins], outputOptions, onLog, logLevel, watchMode);
4295
- const normalizedOutputPlugins = await normalizePluginOption(outputOptions.plugins);
4296
- let plugins = [
4297
- ...BUILTIN_PLUGINS,
4298
- ...normalizePlugins(inputPlugins, ANONYMOUS_PLUGIN_PREFIX),
4299
- ...checkOutputPluginOption(normalizePlugins(normalizedOutputPlugins, ANONYMOUS_OUTPUT_PLUGIN_PREFIX), onLog)
4300
- ];
4301
- const parallelPluginInitResult = await initializeParallelPlugins(plugins);
4302
- try {
4303
- const bindingInputOptions = bindingifyInputOptions(plugins, inputOptions, outputOptions, normalizedOutputPlugins, onLog, logLevel, watchMode);
4304
- const bindingOutputOptions = bindingifyOutputOptions(outputOptions);
4305
- return {
4306
- bundlerOptions: {
4307
- inputOptions: bindingInputOptions,
4308
- outputOptions: bindingOutputOptions,
4309
- parallelPluginsRegistry: parallelPluginInitResult?.registry
4310
- },
4311
- inputOptions,
4312
- onLog,
4313
- stopWorkers: parallelPluginInitResult?.stopWorkers
4314
- };
4315
- } catch (e$2) {
4316
- await parallelPluginInitResult?.stopWorkers();
4317
- throw e$2;
4318
- }
4319
- }
4320
-
4321
- //#endregion
4322
- //#region src/utils/create-bundler.ts
4323
- let asyncRuntimeShutdown = false;
4324
- async function createBundlerImpl(bundler, inputOptions, outputOptions) {
4325
- const option = await createBundlerOptions(inputOptions, outputOptions, false);
4326
- if (asyncRuntimeShutdown) (0, src_rolldown_binding_wasi_cjs.startAsyncRuntime)();
4327
- try {
4328
- return {
4329
- impl: bundler.createImpl(option.bundlerOptions),
4330
- stopWorkers: option.stopWorkers,
4331
- shutdown: () => {
4332
- (0, src_rolldown_binding_wasi_cjs.shutdownAsyncRuntime)();
4333
- asyncRuntimeShutdown = true;
4334
- }
4335
- };
4336
- } catch (e$2) {
4337
- await option.stopWorkers?.();
4338
- throw e$2;
4339
- }
4340
- }
4341
-
4342
- //#endregion
4343
- //#region src/utils/transform-hmr-patch-output.ts
4344
- function transformHmrPatchOutput(output) {
4345
- handleHmrPatchOutputErrors(output);
4346
- const { patch } = output;
4347
- return patch ?? void 0;
4348
- }
4349
- function handleHmrPatchOutputErrors(output) {
4350
- const rawErrors = output.errors;
4351
- if (rawErrors.length > 0) throw normalizeErrors(rawErrors);
4352
- }
4353
-
4354
- //#endregion
4355
- //#region src/api/rolldown/rolldown-build.ts
4356
- Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
4357
- var RolldownBuild = class {
4358
- #inputOptions;
4359
- #bundler;
4360
- #bundlerImpl;
4361
- constructor(inputOptions) {
4362
- this.#inputOptions = inputOptions;
4363
- this.#bundler = new src_rolldown_binding_wasi_cjs.BindingBundler();
4364
- }
4365
- get closed() {
4366
- return this.#bundlerImpl?.impl.closed ?? true;
4367
- }
4368
- async #getBundlerWithStopWorker(outputOptions) {
4369
- if (this.#bundlerImpl) await this.#bundlerImpl.stopWorkers?.();
4370
- return this.#bundlerImpl = await createBundlerImpl(this.#bundler, this.#inputOptions, outputOptions);
4371
- }
4372
- async generate(outputOptions = {}) {
4373
- validateOption("output", outputOptions);
4374
- const { impl } = await this.#getBundlerWithStopWorker(outputOptions);
4375
- const output = await impl.generate();
4376
- return transformToRollupOutput(output);
4377
- }
4378
- async write(outputOptions = {}) {
4379
- validateOption("output", outputOptions);
4380
- const { impl } = await this.#getBundlerWithStopWorker(outputOptions);
4381
- const output = await impl.write();
4382
- return transformToRollupOutput(output);
4383
- }
4384
- async close() {
4385
- if (this.#bundlerImpl) {
4386
- await this.#bundlerImpl.stopWorkers?.();
4387
- await this.#bundlerImpl.impl.close();
4388
- this.#bundlerImpl.shutdown();
4389
- this.#bundlerImpl = void 0;
4390
- }
4391
- }
4392
- async [Symbol.asyncDispose]() {
4393
- await this.close();
4394
- }
4395
- async generateHmrPatch(changedFiles) {
4396
- const ret = await this.#bundlerImpl.impl.generateHmrPatch(changedFiles);
4397
- switch (ret.type) {
4398
- case "Ok": return ret.field0;
4399
- case "Error": throw normalizeErrors(ret.field0);
4400
- default: throw new Error("Unknown error");
4401
- }
4402
- }
4403
- async hmrInvalidate(file, firstInvalidatedBy) {
4404
- const output = await this.#bundlerImpl.impl.hmrInvalidate(file, firstInvalidatedBy);
4405
- return transformHmrPatchOutput(output);
4406
- }
4407
- get watchFiles() {
4408
- return this.#bundlerImpl?.impl.getWatchFiles() ?? Promise.resolve([]);
4409
- }
4410
- };
4411
-
4412
- //#endregion
4413
- //#region src/api/rolldown/index.ts
4414
- const rolldown = async (input) => {
4415
- validateOption("input", input);
4416
- const inputOptions = await PluginDriver.callOptionsHook(input);
4417
- return new RolldownBuild(inputOptions);
4418
- };
4419
-
4420
- //#endregion
4421
- //#region src/api/build.ts
4422
- async function build(options) {
4423
- if (Array.isArray(options)) return Promise.all(options.map((opts) => build(opts)));
4424
- else {
4425
- const { output, write = true,...inputOptions } = options;
4426
- const build$1 = await rolldown(inputOptions);
4427
- try {
4428
- if (write) return await build$1.write(output);
4429
- else return await build$1.generate(output);
4430
- } finally {
4431
- await build$1.close();
4432
- }
4433
- }
4434
- }
4435
-
4436
- //#endregion
4437
- //#region src/api/watch/watch-emitter.ts
4438
- var WatcherEmitter = class {
4439
- listeners = /* @__PURE__ */ new Map();
4440
- timer;
4441
- constructor() {
4442
- this.timer = setInterval(() => {}, 1e9);
4443
- }
4444
- on(event, listener) {
4445
- const listeners = this.listeners.get(event);
4446
- if (listeners) listeners.push(listener);
4447
- else this.listeners.set(event, [listener]);
4448
- return this;
4449
- }
4450
- off(event, listener) {
4451
- const listeners = this.listeners.get(event);
4452
- if (listeners) {
4453
- const index = listeners.indexOf(listener);
4454
- if (index !== -1) listeners.splice(index, 1);
4455
- }
4456
- return this;
4457
- }
4458
- clear(event) {
4459
- if (this.listeners.has(event)) this.listeners.delete(event);
4460
- }
4461
- async onEvent(event) {
4462
- const listeners = this.listeners.get(event.eventKind());
4463
- if (listeners) switch (event.eventKind()) {
4464
- case "close":
4465
- case "restart":
4466
- for (const listener of listeners) await listener();
4467
- break;
4468
- case "event":
4469
- for (const listener of listeners) {
4470
- const code$1 = event.bundleEventKind();
4471
- switch (code$1) {
4472
- case "BUNDLE_END":
4473
- const { duration, output, result } = event.bundleEndData();
4474
- await listener({
4475
- code: "BUNDLE_END",
4476
- duration,
4477
- output: [output],
4478
- result
4479
- });
4480
- break;
4481
- case "ERROR":
4482
- const data = event.bundleErrorData();
4483
- await listener({
4484
- code: "ERROR",
4485
- error: normalizeErrors(data.error),
4486
- result: data.result
4487
- });
4488
- break;
4489
- default:
4490
- await listener({ code: code$1 });
4491
- break;
4492
- }
4493
- }
4494
- break;
4495
- case "change":
4496
- for (const listener of listeners) {
4497
- const { path: path$2, kind } = event.watchChangeData();
4498
- await listener(path$2, { event: kind });
4499
- }
4500
- break;
4501
- default: throw new Error(`Unknown event: ${event}`);
4502
- }
4503
- }
4504
- async close() {
4505
- clearInterval(this.timer);
4506
- }
4507
- };
4508
-
4509
- //#endregion
4510
- //#region src/api/watch/watcher.ts
4511
- var Watcher = class {
4512
- closed;
4513
- inner;
4514
- emitter;
4515
- stopWorkers;
4516
- constructor(emitter, inner, stopWorkers) {
4517
- this.closed = false;
4518
- this.inner = inner;
4519
- this.emitter = emitter;
4520
- const originClose = emitter.close.bind(emitter);
4521
- emitter.close = async () => {
4522
- await this.close();
4523
- originClose();
4524
- };
4525
- this.stopWorkers = stopWorkers;
4526
- }
4527
- async close() {
4528
- if (this.closed) return;
4529
- this.closed = true;
4530
- for (const stop of this.stopWorkers) await stop?.();
4531
- await this.inner.close();
4532
- (0, src_rolldown_binding_wasi_cjs.shutdownAsyncRuntime)();
4533
- }
4534
- start() {
4535
- process.nextTick(() => this.inner.start(this.emitter.onEvent.bind(this.emitter)));
4536
- }
4537
- };
4538
- async function createWatcher(emitter, input) {
4539
- const options = require_dist.arraify(input);
4540
- const bundlerOptions = await Promise.all(options.map((option) => require_dist.arraify(option.output || {}).map(async (output) => {
4541
- const inputOptions = await PluginDriver.callOptionsHook(option, true);
4542
- return createBundlerOptions(inputOptions, output, true);
4543
- })).flat());
4544
- const notifyOptions = getValidNotifyOption(bundlerOptions);
4545
- const bindingWatcher = new src_rolldown_binding_wasi_cjs.BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions);
4546
- const watcher = new Watcher(emitter, bindingWatcher, bundlerOptions.map((option) => option.stopWorkers));
4547
- watcher.start();
4548
- }
4549
- function getValidNotifyOption(bundlerOptions) {
4550
- let result;
4551
- for (const option of bundlerOptions) if (option.inputOptions.watch) {
4552
- const notifyOption = option.inputOptions.watch.notify;
4553
- if (notifyOption) if (result) {
4554
- option.onLog(LOG_LEVEL_WARN, require_parse_ast_index.logMultiplyNotifyOption());
4555
- return result;
4556
- } else result = notifyOption;
4557
- }
4558
- }
4559
-
4560
- //#endregion
4561
- //#region src/api/watch/index.ts
4562
- const watch = (input) => {
4563
- const emitter = new WatcherEmitter();
4564
- createWatcher(emitter, input);
4565
- return emitter;
4566
- };
4567
-
4568
- //#endregion
4569
- //#region src/utils/define-config.ts
4570
- function defineConfig(config) {
4571
- return config;
4572
- }
4573
-
4574
- //#endregion
4575
- //#region src/index.ts
4576
- const VERSION = version;
4577
-
4578
- //#endregion
4579
- Object.defineProperty(exports, 'PluginContextData', {
4580
- enumerable: true,
4581
- get: function () {
4582
- return PluginContextData;
4583
- }
4584
- });
4585
- Object.defineProperty(exports, 'PluginDriver', {
4586
- enumerable: true,
4587
- get: function () {
4588
- return PluginDriver;
4589
- }
4590
- });
4591
- Object.defineProperty(exports, 'VERSION', {
4592
- enumerable: true,
4593
- get: function () {
4594
- return VERSION;
4595
- }
4596
- });
4597
- Object.defineProperty(exports, 'ansis_default', {
4598
- enumerable: true,
4599
- get: function () {
4600
- return ansis_default;
4601
- }
4602
- });
4603
- Object.defineProperty(exports, 'assetPlugin', {
4604
- enumerable: true,
4605
- get: function () {
4606
- return assetPlugin;
4607
- }
4608
- });
4609
- Object.defineProperty(exports, 'bindingifyPlugin', {
4610
- enumerable: true,
4611
- get: function () {
4612
- return bindingifyPlugin;
4613
- }
4614
- });
4615
- Object.defineProperty(exports, 'build', {
4616
- enumerable: true,
4617
- get: function () {
4618
- return build;
4619
- }
4620
- });
4621
- Object.defineProperty(exports, 'buildImportAnalysisPlugin', {
4622
- enumerable: true,
4623
- get: function () {
4624
- return buildImportAnalysisPlugin;
4625
- }
4626
- });
4627
- Object.defineProperty(exports, 'createBuiltinPlugin', {
4628
- enumerable: true,
4629
- get: function () {
4630
- return createBuiltinPlugin;
4631
- }
4632
- });
4633
- Object.defineProperty(exports, 'createBundlerImpl', {
4634
- enumerable: true,
4635
- get: function () {
4636
- return createBundlerImpl;
4637
- }
4638
- });
4639
- Object.defineProperty(exports, 'createBundlerOptions', {
4640
- enumerable: true,
4641
- get: function () {
4642
- return createBundlerOptions;
4643
- }
4644
- });
4645
- Object.defineProperty(exports, 'defineConfig', {
4646
- enumerable: true,
4647
- get: function () {
4648
- return defineConfig;
4649
- }
4650
- });
4651
- Object.defineProperty(exports, 'description', {
4652
- enumerable: true,
4653
- get: function () {
4654
- return description$1;
4655
- }
4656
- });
4657
- Object.defineProperty(exports, 'dynamicImportVarsPlugin', {
4658
- enumerable: true,
4659
- get: function () {
4660
- return dynamicImportVarsPlugin;
4661
- }
4662
- });
4663
- Object.defineProperty(exports, 'esmExternalRequirePlugin', {
4664
- enumerable: true,
4665
- get: function () {
4666
- return esmExternalRequirePlugin;
4667
- }
4668
- });
4669
- Object.defineProperty(exports, 'getInputCliKeys', {
4670
- enumerable: true,
4671
- get: function () {
4672
- return getInputCliKeys;
4673
- }
4674
- });
4675
- Object.defineProperty(exports, 'getJsonSchema', {
4676
- enumerable: true,
4677
- get: function () {
4678
- return getJsonSchema;
4679
- }
4680
- });
4681
- Object.defineProperty(exports, 'getOutputCliKeys', {
4682
- enumerable: true,
4683
- get: function () {
4684
- return getOutputCliKeys;
4685
- }
4686
- });
4687
- Object.defineProperty(exports, 'handleOutputErrors', {
4688
- enumerable: true,
4689
- get: function () {
4690
- return handleOutputErrors;
4691
- }
4692
- });
4693
- Object.defineProperty(exports, 'importGlobPlugin', {
4694
- enumerable: true,
4695
- get: function () {
4696
- return importGlobPlugin;
4697
- }
4698
- });
4699
- Object.defineProperty(exports, 'isolatedDeclarationPlugin', {
4700
- enumerable: true,
4701
- get: function () {
4702
- return isolatedDeclarationPlugin;
4703
- }
4704
- });
4705
- Object.defineProperty(exports, 'jsonPlugin', {
4706
- enumerable: true,
4707
- get: function () {
4708
- return jsonPlugin;
4709
- }
4710
- });
4711
- Object.defineProperty(exports, 'loadFallbackPlugin', {
4712
- enumerable: true,
4713
- get: function () {
4714
- return loadFallbackPlugin;
4715
- }
4716
- });
4717
- Object.defineProperty(exports, 'manifestPlugin', {
4718
- enumerable: true,
4719
- get: function () {
4720
- return manifestPlugin;
4721
- }
4722
- });
4723
- Object.defineProperty(exports, 'modulePreloadPolyfillPlugin', {
4724
- enumerable: true,
4725
- get: function () {
4726
- return modulePreloadPolyfillPlugin;
4727
- }
4728
- });
4729
- Object.defineProperty(exports, 'normalizedStringOrRegex', {
4730
- enumerable: true,
4731
- get: function () {
4732
- return normalizedStringOrRegex;
4733
- }
4734
- });
4735
- Object.defineProperty(exports, 'reporterPlugin', {
4736
- enumerable: true,
4737
- get: function () {
4738
- return reporterPlugin;
4739
- }
4740
- });
4741
- Object.defineProperty(exports, 'rolldown', {
4742
- enumerable: true,
4743
- get: function () {
4744
- return rolldown;
4745
- }
4746
- });
4747
- Object.defineProperty(exports, 'validateCliOptions', {
4748
- enumerable: true,
4749
- get: function () {
4750
- return validateCliOptions;
4751
- }
4752
- });
4753
- Object.defineProperty(exports, 'version', {
4754
- enumerable: true,
4755
- get: function () {
4756
- return version;
4757
- }
4758
- });
4759
- Object.defineProperty(exports, 'viteResolvePlugin', {
4760
- enumerable: true,
4761
- get: function () {
4762
- return viteResolvePlugin;
4763
- }
4764
- });
4765
- Object.defineProperty(exports, 'wasmFallbackPlugin', {
4766
- enumerable: true,
4767
- get: function () {
4768
- return wasmFallbackPlugin;
4769
- }
4770
- });
4771
- Object.defineProperty(exports, 'wasmHelperPlugin', {
4772
- enumerable: true,
4773
- get: function () {
4774
- return wasmHelperPlugin;
4775
- }
4776
- });
4777
- Object.defineProperty(exports, 'watch', {
4778
- enumerable: true,
4779
- get: function () {
4780
- return watch;
4781
- }
4782
- });
4783
- Object.defineProperty(exports, 'webWorkerPostPlugin', {
4784
- enumerable: true,
4785
- get: function () {
4786
- return webWorkerPostPlugin;
4787
- }
4788
- });