rolldown 1.0.0-beta.9-commit.0ec9e7d → 1.0.0-rc.1

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