UNPKG

rolldown

Version:

Fast JavaScript/TypeScript bundler in Rust with Rollup-compatible API.

1,556 lines (1,547 loc) • 74.5 kB
import { t as require_binding } from "./binding-JavE2bkj.mjs"; import { i as logInputHookInOutputPlugin, n as error } from "./logs-CSQ_UMWp.mjs"; import { i as unimplemented } from "./misc-CxyvWjTr.mjs"; import { C as LOG_LEVEL_INFO, S as LOG_LEVEL_ERROR, T as logLevelPriority, _ as VERSION, b as normalizeLog, c as transformToRollupOutput, d as __decorate, g as MinimalPluginContextImpl, h as PlainObjectLike, m as lazyProp, n as BuiltinPlugin, p as transformAssetSource, u as transformRenderedChunk, w as LOG_LEVEL_WARN, x as LOG_LEVEL_DEBUG } from "./normalize-string-or-regex-Bu88lzEx.mjs"; import { c as normalizeHook, i as transformModuleInfo, s as unwrapBindingResult, t as bindingifyInputOptions } from "./bindingify-input-options-C8RwNEVu.mjs"; import { Worker } from "node:worker_threads"; import path from "node:path"; import { styleText } from "node:util"; import os from "node:os"; //#region src/log/logger.ts function getLogger(plugins, onLog, logLevel, watchMode) { const minimalPriority = logLevelPriority[logLevel]; const logger = (level, log, skipped = /* @__PURE__ */ new Set()) => { if (logLevelPriority[level] < minimalPriority) return; for (const plugin of getSortedPlugins("onLog", plugins)) { if (skipped.has(plugin)) continue; const { onLog: pluginOnLog } = plugin; if (pluginOnLog) { const getLogHandler = (level$1) => { if (logLevelPriority[level$1] < minimalPriority) return () => {}; return (log$1) => logger(level$1, normalizeLog(log$1), new Set(skipped).add(plugin)); }; if (("handler" in pluginOnLog ? pluginOnLog.handler : pluginOnLog).call({ debug: getLogHandler(LOG_LEVEL_DEBUG), error: (log$1) => error(normalizeLog(log$1)), info: getLogHandler(LOG_LEVEL_INFO), meta: { rollupVersion: "4.23.0", rolldownVersion: VERSION, watchMode }, warn: getLogHandler(LOG_LEVEL_WARN), pluginName: plugin.name || "unknown" }, level, log) === false) return; } } onLog(level, log); }; return logger; } const getOnLog = (config, logLevel, printLog = defaultPrintLog) => { const { onwarn, onLog } = config; const defaultOnLog = getDefaultOnLog(printLog, onwarn); if (onLog) { const minimalPriority = logLevelPriority[logLevel]; return (level, log) => onLog(level, addLogToString(log), (level$1, handledLog) => { if (level$1 === LOG_LEVEL_ERROR) return error(normalizeLog(handledLog)); if (logLevelPriority[level$1] >= minimalPriority) defaultOnLog(level$1, normalizeLog(handledLog)); }); } return defaultOnLog; }; const getDefaultOnLog = (printLog, onwarn) => onwarn ? (level, log) => { if (level === LOG_LEVEL_WARN) onwarn(addLogToString(log), (warning) => printLog(LOG_LEVEL_WARN, normalizeLog(warning))); else printLog(level, log); } : printLog; const addLogToString = (log) => { Object.defineProperty(log, "toString", { value: () => getExtendedLogMessage(log), writable: true }); return log; }; const defaultPrintLog = (level, log) => { const message = getExtendedLogMessage(log); switch (level) { case LOG_LEVEL_WARN: return console.warn(message); case LOG_LEVEL_DEBUG: return console.debug(message); default: return console.info(message); } }; const getExtendedLogMessage = (log) => { let prefix = ""; if (log.plugin) prefix += `(${log.plugin} plugin) `; if (log.loc) prefix += `${relativeId(log.loc.file)} (${log.loc.line}:${log.loc.column}) `; return prefix + log.message; }; function relativeId(id) { if (!path.isAbsolute(id)) return id; return path.relative(path.resolve(), id); } //#endregion //#region src/constants/plugin.ts const ENUMERATED_INPUT_PLUGIN_HOOK_NAMES = [ "options", "buildStart", "resolveId", "load", "transform", "moduleParsed", "buildEnd", "onLog", "resolveDynamicImport", "closeBundle", "closeWatcher", "watchChange" ]; const ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES = [ "augmentChunkHash", "outputOptions", "renderChunk", "renderStart", "renderError", "writeBundle", "generateBundle" ]; const ENUMERATED_PLUGIN_HOOK_NAMES = [ ...ENUMERATED_INPUT_PLUGIN_HOOK_NAMES, ...ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES, "footer", "banner", "intro", "outro" ]; /** * Names of all defined hooks. It's like * ```js * const DEFINED_HOOK_NAMES ={ * options: 'options', * buildStart: 'buildStart', * ... * } * ``` */ const DEFINED_HOOK_NAMES = { [ENUMERATED_PLUGIN_HOOK_NAMES[0]]: ENUMERATED_PLUGIN_HOOK_NAMES[0], [ENUMERATED_PLUGIN_HOOK_NAMES[1]]: ENUMERATED_PLUGIN_HOOK_NAMES[1], [ENUMERATED_PLUGIN_HOOK_NAMES[2]]: ENUMERATED_PLUGIN_HOOK_NAMES[2], [ENUMERATED_PLUGIN_HOOK_NAMES[3]]: ENUMERATED_PLUGIN_HOOK_NAMES[3], [ENUMERATED_PLUGIN_HOOK_NAMES[4]]: ENUMERATED_PLUGIN_HOOK_NAMES[4], [ENUMERATED_PLUGIN_HOOK_NAMES[5]]: ENUMERATED_PLUGIN_HOOK_NAMES[5], [ENUMERATED_PLUGIN_HOOK_NAMES[6]]: ENUMERATED_PLUGIN_HOOK_NAMES[6], [ENUMERATED_PLUGIN_HOOK_NAMES[7]]: ENUMERATED_PLUGIN_HOOK_NAMES[7], [ENUMERATED_PLUGIN_HOOK_NAMES[8]]: ENUMERATED_PLUGIN_HOOK_NAMES[8], [ENUMERATED_PLUGIN_HOOK_NAMES[9]]: ENUMERATED_PLUGIN_HOOK_NAMES[9], [ENUMERATED_PLUGIN_HOOK_NAMES[10]]: ENUMERATED_PLUGIN_HOOK_NAMES[10], [ENUMERATED_PLUGIN_HOOK_NAMES[11]]: ENUMERATED_PLUGIN_HOOK_NAMES[11], [ENUMERATED_PLUGIN_HOOK_NAMES[12]]: ENUMERATED_PLUGIN_HOOK_NAMES[12], [ENUMERATED_PLUGIN_HOOK_NAMES[13]]: ENUMERATED_PLUGIN_HOOK_NAMES[13], [ENUMERATED_PLUGIN_HOOK_NAMES[14]]: ENUMERATED_PLUGIN_HOOK_NAMES[14], [ENUMERATED_PLUGIN_HOOK_NAMES[15]]: ENUMERATED_PLUGIN_HOOK_NAMES[15], [ENUMERATED_PLUGIN_HOOK_NAMES[16]]: ENUMERATED_PLUGIN_HOOK_NAMES[16], [ENUMERATED_PLUGIN_HOOK_NAMES[17]]: ENUMERATED_PLUGIN_HOOK_NAMES[17], [ENUMERATED_PLUGIN_HOOK_NAMES[18]]: ENUMERATED_PLUGIN_HOOK_NAMES[18], [ENUMERATED_PLUGIN_HOOK_NAMES[19]]: ENUMERATED_PLUGIN_HOOK_NAMES[19], [ENUMERATED_PLUGIN_HOOK_NAMES[20]]: ENUMERATED_PLUGIN_HOOK_NAMES[20], [ENUMERATED_PLUGIN_HOOK_NAMES[21]]: ENUMERATED_PLUGIN_HOOK_NAMES[21], [ENUMERATED_PLUGIN_HOOK_NAMES[22]]: ENUMERATED_PLUGIN_HOOK_NAMES[22] }; //#endregion //#region src/utils/async-flatten.ts async function asyncFlatten(array$1) { do array$1 = (await Promise.all(array$1)).flat(Infinity); while (array$1.some((v) => v?.then)); return array$1; } //#endregion //#region src/utils/normalize-plugin-option.ts const normalizePluginOption = async (plugins) => (await asyncFlatten([plugins])).filter(Boolean); function checkOutputPluginOption(plugins, onLog) { for (const plugin of plugins) for (const hook of ENUMERATED_INPUT_PLUGIN_HOOK_NAMES) if (hook in plugin) { delete plugin[hook]; onLog(LOG_LEVEL_WARN, logInputHookInOutputPlugin(plugin.name, hook)); } return plugins; } function normalizePlugins(plugins, anonymousPrefix) { for (const [index, plugin] of plugins.entries()) { if ("_parallel" in plugin) continue; if (plugin instanceof BuiltinPlugin) continue; if (!plugin.name) plugin.name = `${anonymousPrefix}${index + 1}`; } return plugins; } const ANONYMOUS_PLUGIN_PREFIX = "at position "; const ANONYMOUS_OUTPUT_PLUGIN_PREFIX = "at output position "; //#endregion //#region src/plugin/plugin-driver.ts var PluginDriver = class { static async callOptionsHook(inputOptions, watchMode = false) { const logLevel = inputOptions.logLevel || LOG_LEVEL_INFO; const plugins = getSortedPlugins("options", getObjectPlugins(await normalizePluginOption(inputOptions.plugins))); const logger = getLogger(plugins, getOnLog(inputOptions, logLevel), logLevel, watchMode); for (const plugin of plugins) { const name = plugin.name || "unknown"; const options = plugin.options; if (options) { const { handler } = normalizeHook(options); const result = await handler.call(new MinimalPluginContextImpl(logger, logLevel, name, watchMode, "onLog"), inputOptions); if (result) inputOptions = result; } } return inputOptions; } static callOutputOptionsHook(rawPlugins, outputOptions, onLog, logLevel, watchMode) { const sortedPlugins = getSortedPlugins("outputOptions", getObjectPlugins(rawPlugins)); for (const plugin of sortedPlugins) { const name = plugin.name || "unknown"; const options = plugin.outputOptions; if (options) { const { handler } = normalizeHook(options); const result = handler.call(new MinimalPluginContextImpl(onLog, logLevel, name, watchMode), outputOptions); if (result) outputOptions = result; } } return outputOptions; } }; function getObjectPlugins(plugins) { return plugins.filter((plugin) => { if (!plugin) return; if ("_parallel" in plugin) return; if (plugin instanceof BuiltinPlugin) return; return plugin; }); } function getSortedPlugins(hookName, plugins) { const pre = []; const normal = []; const post = []; for (const plugin of plugins) { const hook = plugin[hookName]; if (hook) { if (typeof hook === "object") { if (hook.order === "pre") { pre.push(plugin); continue; } if (hook.order === "post") { post.push(plugin); continue; } } normal.push(plugin); } } return [ ...pre, ...normal, ...post ]; } //#endregion //#region ../../node_modules/.pnpm/valibot@1.1.0_typescript@5.9.3/node_modules/valibot/dist/index.js var store; /* @__NO_SIDE_EFFECTS__ */ function getGlobalConfig(config2) { return { lang: config2?.lang ?? store?.lang, message: config2?.message, abortEarly: config2?.abortEarly ?? store?.abortEarly, abortPipeEarly: config2?.abortPipeEarly ?? store?.abortPipeEarly }; } var store2; /* @__NO_SIDE_EFFECTS__ */ function getGlobalMessage(lang) { return store2?.get(lang); } var store3; /* @__NO_SIDE_EFFECTS__ */ function getSchemaMessage(lang) { return store3?.get(lang); } var store4; /* @__NO_SIDE_EFFECTS__ */ function getSpecificMessage(reference, lang) { return store4?.get(reference)?.get(lang); } /* @__NO_SIDE_EFFECTS__ */ function _stringify(input) { const type = typeof input; if (type === "string") return `"${input}"`; if (type === "number" || type === "bigint" || type === "boolean") return `${input}`; if (type === "object" || type === "function") return (input && Object.getPrototypeOf(input)?.constructor?.name) ?? "null"; return type; } function _addIssue(context, label, dataset, config2, other) { const input = other && "input" in other ? other.input : dataset.value; const expected = other?.expected ?? context.expects ?? null; const received = other?.received ?? /* @__PURE__ */ _stringify(input); const issue = { kind: context.kind, type: context.type, input, expected, received, message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`, requirement: context.requirement, path: other?.path, issues: other?.issues, lang: config2.lang, abortEarly: config2.abortEarly, abortPipeEarly: config2.abortPipeEarly }; const isSchema = context.kind === "schema"; const message2 = other?.message ?? context.message ?? /* @__PURE__ */ getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? /* @__PURE__ */ getSchemaMessage(issue.lang) : null) ?? config2.message ?? /* @__PURE__ */ getGlobalMessage(issue.lang); if (message2 !== void 0) issue.message = typeof message2 === "function" ? message2(issue) : message2; if (isSchema) dataset.typed = false; if (dataset.issues) dataset.issues.push(issue); else dataset.issues = [issue]; } /* @__NO_SIDE_EFFECTS__ */ function _getStandardProps(context) { return { version: 1, vendor: "valibot", validate(value2) { return context["~run"]({ value: value2 }, /* @__PURE__ */ getGlobalConfig()); } }; } /* @__NO_SIDE_EFFECTS__ */ function _isValidObjectKey(object2, key) { return Object.hasOwn(object2, key) && key !== "__proto__" && key !== "prototype" && key !== "constructor"; } /* @__NO_SIDE_EFFECTS__ */ function _joinExpects(values2, separator) { const list = [...new Set(values2)]; if (list.length > 1) return `(${list.join(` ${separator} `)})`; return list[0] ?? "never"; } var ValiError = class extends Error { /** * Creates a Valibot error with useful information. * * @param issues The error issues. */ constructor(issues) { super(issues[0].message); this.name = "ValiError"; this.issues = issues; } }; /* @__NO_SIDE_EFFECTS__ */ function args(schema) { return { kind: "transformation", type: "args", reference: args, async: false, schema, "~run"(dataset, config2) { const func = dataset.value; dataset.value = (...args_) => { const argsDataset = this.schema["~run"]({ value: args_ }, config2); if (argsDataset.issues) throw new ValiError(argsDataset.issues); return func(...argsDataset.value); }; return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function awaitAsync() { return { kind: "transformation", type: "await", reference: awaitAsync, async: true, async "~run"(dataset) { dataset.value = await dataset.value; return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function description(description_) { return { kind: "metadata", type: "description", reference: description, description: description_ }; } /* @__NO_SIDE_EFFECTS__ */ function returns(schema) { return { kind: "transformation", type: "returns", reference: returns, async: false, schema, "~run"(dataset, config2) { const func = dataset.value; dataset.value = (...args_) => { const returnsDataset = this.schema["~run"]({ value: func(...args_) }, config2); if (returnsDataset.issues) throw new ValiError(returnsDataset.issues); return returnsDataset.value; }; return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function returnsAsync(schema) { return { kind: "transformation", type: "returns", reference: returnsAsync, async: false, schema, "~run"(dataset, config2) { const func = dataset.value; dataset.value = async (...args_) => { const returnsDataset = await this.schema["~run"]({ value: await func(...args_) }, config2); if (returnsDataset.issues) throw new ValiError(returnsDataset.issues); return returnsDataset.value; }; return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function getFallback(schema, dataset, config2) { return typeof schema.fallback === "function" ? schema.fallback(dataset, config2) : schema.fallback; } /* @__NO_SIDE_EFFECTS__ */ function getDefault(schema, dataset, config2) { return typeof schema.default === "function" ? schema.default(dataset, config2) : schema.default; } /* @__NO_SIDE_EFFECTS__ */ function any() { return { kind: "schema", type: "any", reference: any, expects: "any", async: false, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset) { dataset.typed = true; return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function array(item, message2) { return { kind: "schema", type: "array", reference: array, expects: "Array", async: false, item, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { const input = dataset.value; if (Array.isArray(input)) { dataset.typed = true; dataset.value = []; for (let key = 0; key < input.length; key++) { const value2 = input[key]; const itemDataset = this.item["~run"]({ value: value2 }, config2); if (itemDataset.issues) { const pathItem = { type: "array", origin: "value", input, key, value: value2 }; for (const issue of itemDataset.issues) { if (issue.path) issue.path.unshift(pathItem); else issue.path = [pathItem]; dataset.issues?.push(issue); } if (!dataset.issues) dataset.issues = itemDataset.issues; if (config2.abortEarly) { dataset.typed = false; break; } } if (!itemDataset.typed) dataset.typed = false; dataset.value.push(itemDataset.value); } } else _addIssue(this, "type", dataset, config2); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function boolean(message2) { return { kind: "schema", type: "boolean", reference: boolean, expects: "boolean", async: false, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { if (typeof dataset.value === "boolean") dataset.typed = true; else _addIssue(this, "type", dataset, config2); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function custom(check2, message2) { return { kind: "schema", type: "custom", reference: custom, expects: "unknown", async: false, check: check2, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { if (this.check(dataset.value)) dataset.typed = true; else _addIssue(this, "type", dataset, config2); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function function_(message2) { return { kind: "schema", type: "function", reference: function_, expects: "Function", async: false, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { if (typeof dataset.value === "function") dataset.typed = true; else _addIssue(this, "type", dataset, config2); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function instance(class_, message2) { return { kind: "schema", type: "instance", reference: instance, expects: class_.name, async: false, class: class_, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { if (dataset.value instanceof this.class) dataset.typed = true; else _addIssue(this, "type", dataset, config2); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function literal(literal_, message2) { return { kind: "schema", type: "literal", reference: literal, expects: /* @__PURE__ */ _stringify(literal_), async: false, literal: literal_, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { if (dataset.value === this.literal) dataset.typed = true; else _addIssue(this, "type", dataset, config2); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function looseObject(entries2, message2) { return { kind: "schema", type: "loose_object", reference: looseObject, expects: "Object", async: false, entries: entries2, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { const input = dataset.value; if (input && typeof input === "object") { dataset.typed = true; dataset.value = {}; for (const key in this.entries) { const valueSchema = this.entries[key]; if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) { const value2 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema); const valueDataset = valueSchema["~run"]({ value: value2 }, config2); if (valueDataset.issues) { const pathItem = { type: "object", origin: "value", input, key, value: value2 }; for (const issue of valueDataset.issues) { if (issue.path) issue.path.unshift(pathItem); else issue.path = [pathItem]; dataset.issues?.push(issue); } if (!dataset.issues) dataset.issues = valueDataset.issues; if (config2.abortEarly) { dataset.typed = false; break; } } if (!valueDataset.typed) dataset.typed = false; dataset.value[key] = valueDataset.value; } else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema); else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") { _addIssue(this, "key", dataset, config2, { input: void 0, expected: `"${key}"`, path: [{ type: "object", origin: "key", input, key, value: input[key] }] }); if (config2.abortEarly) break; } } if (!dataset.issues || !config2.abortEarly) { for (const key in input) if (/* @__PURE__ */ _isValidObjectKey(input, key) && !(key in this.entries)) dataset.value[key] = input[key]; } } else _addIssue(this, "type", dataset, config2); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function never(message2) { return { kind: "schema", type: "never", reference: never, expects: "never", async: false, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { _addIssue(this, "type", dataset, config2); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function nullish(wrapped, default_) { return { kind: "schema", type: "nullish", reference: nullish, expects: `(${wrapped.expects} | null | undefined)`, async: false, wrapped, default: default_, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { if (dataset.value === null || dataset.value === void 0) { if (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config2); if (dataset.value === null || dataset.value === void 0) { dataset.typed = true; return dataset; } } return this.wrapped["~run"](dataset, config2); } }; } /* @__NO_SIDE_EFFECTS__ */ function number(message2) { return { kind: "schema", type: "number", reference: number, expects: "number", async: false, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { if (typeof dataset.value === "number" && !isNaN(dataset.value)) dataset.typed = true; else _addIssue(this, "type", dataset, config2); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function object(entries2, message2) { return { kind: "schema", type: "object", reference: object, expects: "Object", async: false, entries: entries2, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { const input = dataset.value; if (input && typeof input === "object") { dataset.typed = true; dataset.value = {}; for (const key in this.entries) { const valueSchema = this.entries[key]; if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) { const value2 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema); const valueDataset = valueSchema["~run"]({ value: value2 }, config2); if (valueDataset.issues) { const pathItem = { type: "object", origin: "value", input, key, value: value2 }; for (const issue of valueDataset.issues) { if (issue.path) issue.path.unshift(pathItem); else issue.path = [pathItem]; dataset.issues?.push(issue); } if (!dataset.issues) dataset.issues = valueDataset.issues; if (config2.abortEarly) { dataset.typed = false; break; } } if (!valueDataset.typed) dataset.typed = false; dataset.value[key] = valueDataset.value; } else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema); else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") { _addIssue(this, "key", dataset, config2, { input: void 0, expected: `"${key}"`, path: [{ type: "object", origin: "key", input, key, value: input[key] }] }); if (config2.abortEarly) break; } } } else _addIssue(this, "type", dataset, config2); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function optional(wrapped, default_) { return { kind: "schema", type: "optional", reference: optional, expects: `(${wrapped.expects} | undefined)`, async: false, wrapped, default: default_, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { if (dataset.value === void 0) { if (this.default !== void 0) dataset.value = /* @__PURE__ */ getDefault(this, dataset, config2); if (dataset.value === void 0) { dataset.typed = true; return dataset; } } return this.wrapped["~run"](dataset, config2); } }; } /* @__NO_SIDE_EFFECTS__ */ function picklist(options, message2) { return { kind: "schema", type: "picklist", reference: picklist, expects: /* @__PURE__ */ _joinExpects(options.map(_stringify), "|"), async: false, options, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { if (this.options.includes(dataset.value)) dataset.typed = true; else _addIssue(this, "type", dataset, config2); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function promise(message2) { return { kind: "schema", type: "promise", reference: promise, expects: "Promise", async: false, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { if (dataset.value instanceof Promise) dataset.typed = true; else _addIssue(this, "type", dataset, config2); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function record(key, value2, message2) { return { kind: "schema", type: "record", reference: record, expects: "Object", async: false, key, value: value2, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { const input = dataset.value; if (input && typeof input === "object") { dataset.typed = true; dataset.value = {}; for (const entryKey in input) if (/* @__PURE__ */ _isValidObjectKey(input, entryKey)) { const entryValue = input[entryKey]; const keyDataset = this.key["~run"]({ value: entryKey }, config2); if (keyDataset.issues) { const pathItem = { type: "object", origin: "key", input, key: entryKey, value: entryValue }; for (const issue of keyDataset.issues) { issue.path = [pathItem]; dataset.issues?.push(issue); } if (!dataset.issues) dataset.issues = keyDataset.issues; if (config2.abortEarly) { dataset.typed = false; break; } } const valueDataset = this.value["~run"]({ value: entryValue }, config2); if (valueDataset.issues) { const pathItem = { type: "object", origin: "value", input, key: entryKey, value: entryValue }; for (const issue of valueDataset.issues) { if (issue.path) issue.path.unshift(pathItem); else issue.path = [pathItem]; dataset.issues?.push(issue); } if (!dataset.issues) dataset.issues = valueDataset.issues; if (config2.abortEarly) { dataset.typed = false; break; } } if (!keyDataset.typed || !valueDataset.typed) dataset.typed = false; if (keyDataset.typed) dataset.value[keyDataset.value] = valueDataset.value; } } else _addIssue(this, "type", dataset, config2); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function strictObject(entries2, message2) { return { kind: "schema", type: "strict_object", reference: strictObject, expects: "Object", async: false, entries: entries2, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { const input = dataset.value; if (input && typeof input === "object") { dataset.typed = true; dataset.value = {}; for (const key in this.entries) { const valueSchema = this.entries[key]; if (key in input || (valueSchema.type === "exact_optional" || valueSchema.type === "optional" || valueSchema.type === "nullish") && valueSchema.default !== void 0) { const value2 = key in input ? input[key] : /* @__PURE__ */ getDefault(valueSchema); const valueDataset = valueSchema["~run"]({ value: value2 }, config2); if (valueDataset.issues) { const pathItem = { type: "object", origin: "value", input, key, value: value2 }; for (const issue of valueDataset.issues) { if (issue.path) issue.path.unshift(pathItem); else issue.path = [pathItem]; dataset.issues?.push(issue); } if (!dataset.issues) dataset.issues = valueDataset.issues; if (config2.abortEarly) { dataset.typed = false; break; } } if (!valueDataset.typed) dataset.typed = false; dataset.value[key] = valueDataset.value; } else if (valueSchema.fallback !== void 0) dataset.value[key] = /* @__PURE__ */ getFallback(valueSchema); else if (valueSchema.type !== "exact_optional" && valueSchema.type !== "optional" && valueSchema.type !== "nullish") { _addIssue(this, "key", dataset, config2, { input: void 0, expected: `"${key}"`, path: [{ type: "object", origin: "key", input, key, value: input[key] }] }); if (config2.abortEarly) break; } } if (!dataset.issues || !config2.abortEarly) { for (const key in input) if (!(key in this.entries)) { _addIssue(this, "key", dataset, config2, { input: key, expected: "never", path: [{ type: "object", origin: "key", input, key, value: input[key] }] }); break; } } } else _addIssue(this, "type", dataset, config2); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function string(message2) { return { kind: "schema", type: "string", reference: string, expects: "string", async: false, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { if (typeof dataset.value === "string") dataset.typed = true; else _addIssue(this, "type", dataset, config2); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function tuple(items, message2) { return { kind: "schema", type: "tuple", reference: tuple, expects: "Array", async: false, items, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { const input = dataset.value; if (Array.isArray(input)) { dataset.typed = true; dataset.value = []; for (let key = 0; key < this.items.length; key++) { const value2 = input[key]; const itemDataset = this.items[key]["~run"]({ value: value2 }, config2); if (itemDataset.issues) { const pathItem = { type: "array", origin: "value", input, key, value: value2 }; for (const issue of itemDataset.issues) { if (issue.path) issue.path.unshift(pathItem); else issue.path = [pathItem]; dataset.issues?.push(issue); } if (!dataset.issues) dataset.issues = itemDataset.issues; if (config2.abortEarly) { dataset.typed = false; break; } } if (!itemDataset.typed) dataset.typed = false; dataset.value.push(itemDataset.value); } } else _addIssue(this, "type", dataset, config2); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function undefined_(message2) { return { kind: "schema", type: "undefined", reference: undefined_, expects: "undefined", async: false, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { if (dataset.value === void 0) dataset.typed = true; else _addIssue(this, "type", dataset, config2); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function _subIssues(datasets) { let issues; if (datasets) for (const dataset of datasets) if (issues) issues.push(...dataset.issues); else issues = dataset.issues; return issues; } /* @__NO_SIDE_EFFECTS__ */ function union(options, message2) { return { kind: "schema", type: "union", reference: union, expects: /* @__PURE__ */ _joinExpects(options.map((option) => option.expects), "|"), async: false, options, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { let validDataset; let typedDatasets; let untypedDatasets; for (const schema of this.options) { const optionDataset = schema["~run"]({ value: dataset.value }, config2); if (optionDataset.typed) if (optionDataset.issues) if (typedDatasets) typedDatasets.push(optionDataset); else typedDatasets = [optionDataset]; else { validDataset = optionDataset; break; } else if (untypedDatasets) untypedDatasets.push(optionDataset); else untypedDatasets = [optionDataset]; } if (validDataset) return validDataset; if (typedDatasets) { if (typedDatasets.length === 1) return typedDatasets[0]; _addIssue(this, "type", dataset, config2, { issues: /* @__PURE__ */ _subIssues(typedDatasets) }); dataset.typed = true; } else if (untypedDatasets?.length === 1) return untypedDatasets[0]; else _addIssue(this, "type", dataset, config2, { issues: /* @__PURE__ */ _subIssues(untypedDatasets) }); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function unionAsync(options, message2) { return { kind: "schema", type: "union", reference: unionAsync, expects: /* @__PURE__ */ _joinExpects(options.map((option) => option.expects), "|"), async: true, options, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, async "~run"(dataset, config2) { let validDataset; let typedDatasets; let untypedDatasets; for (const schema of this.options) { const optionDataset = await schema["~run"]({ value: dataset.value }, config2); if (optionDataset.typed) if (optionDataset.issues) if (typedDatasets) typedDatasets.push(optionDataset); else typedDatasets = [optionDataset]; else { validDataset = optionDataset; break; } else if (untypedDatasets) untypedDatasets.push(optionDataset); else untypedDatasets = [optionDataset]; } if (validDataset) return validDataset; if (typedDatasets) { if (typedDatasets.length === 1) return typedDatasets[0]; _addIssue(this, "type", dataset, config2, { issues: /* @__PURE__ */ _subIssues(typedDatasets) }); dataset.typed = true; } else if (untypedDatasets?.length === 1) return untypedDatasets[0]; else _addIssue(this, "type", dataset, config2, { issues: /* @__PURE__ */ _subIssues(untypedDatasets) }); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function void_(message2) { return { kind: "schema", type: "void", reference: void_, expects: "void", async: false, message: message2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { if (dataset.value === void 0) dataset.typed = true; else _addIssue(this, "type", dataset, config2); return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function keyof(schema, message2) { return /* @__PURE__ */ picklist(Object.keys(schema.entries), message2); } /* @__NO_SIDE_EFFECTS__ */ function omit(schema, keys) { const entries2 = { ...schema.entries }; for (const key of keys) delete entries2[key]; return { ...schema, entries: entries2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); } }; } /* @__NO_SIDE_EFFECTS__ */ function partial(schema, keys) { const entries2 = {}; for (const key in schema.entries) entries2[key] = !keys || keys.includes(key) ? /* @__PURE__ */ optional(schema.entries[key]) : schema.entries[key]; return { ...schema, entries: entries2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); } }; } /* @__NO_SIDE_EFFECTS__ */ function pipe(...pipe2) { return { ...pipe2[0], pipe: pipe2, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, "~run"(dataset, config2) { for (const item of pipe2) if (item.kind !== "metadata") { if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) { dataset.typed = false; break; } if (!dataset.issues || !config2.abortEarly && !config2.abortPipeEarly) dataset = item["~run"](dataset, config2); } return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function pipeAsync(...pipe2) { return { ...pipe2[0], pipe: pipe2, async: true, get "~standard"() { return /* @__PURE__ */ _getStandardProps(this); }, async "~run"(dataset, config2) { for (const item of pipe2) if (item.kind !== "metadata") { if (dataset.issues && (item.kind === "schema" || item.kind === "transformation")) { dataset.typed = false; break; } if (!dataset.issues || !config2.abortEarly && !config2.abortPipeEarly) dataset = await item["~run"](dataset, config2); } return dataset; } }; } /* @__NO_SIDE_EFFECTS__ */ function safeParse(schema, input, config2) { const dataset = schema["~run"]({ value: input }, /* @__PURE__ */ getGlobalConfig(config2)); return { typed: dataset.typed, success: !dataset.issues, output: dataset.value, issues: dataset.issues }; } //#endregion //#region src/utils/flatten-valibot-schema.ts function unwrapSchema(schema) { if (!schema) return schema; if (schema.type === "optional" && schema.wrapped) return unwrapSchema(schema.wrapped); if (schema.type === "nullable" && schema.wrapped) return unwrapSchema(schema.wrapped); if (schema.type === "nullish" && schema.wrapped) return unwrapSchema(schema.wrapped); return schema; } function getValibotSchemaType(schema) { if (!schema) return "any"; if (schema.type) switch (schema.type) { case "string": return "string"; case "number": return "number"; case "boolean": return "boolean"; case "array": return "array"; case "object": case "strict_object": case "loose_object": return "object"; case "union": return "union"; case "literal": return typeof schema.literal; case "record": return "object"; case "optional": return getValibotSchemaType(schema.wrapped); case "nullable": return getValibotSchemaType(schema.wrapped); case "nullish": return getValibotSchemaType(schema.wrapped); case "never": return "never"; case "any": return "any"; case "custom": return "any"; case "function": return "never"; case "instance": return "object"; default: return "any"; } return "any"; } function getValibotDescription(schema) { if (!schema) return void 0; if (schema.pipe && Array.isArray(schema.pipe)) { for (const action of schema.pipe) if (action.type === "description" && action.description) return action.description; } if (schema.type === "optional" && schema.wrapped) return getValibotDescription(schema.wrapped); } function flattenValibotSchema(schema, result = {}, prefix = "") { if (!schema || typeof schema !== "object") return result; if (schema.type === "strict_object" || schema.type === "object" || schema.type === "loose_object") { if (schema.entries && typeof schema.entries === "object") for (const [key, value] of Object.entries(schema.entries)) { const fullKey = prefix ? `${prefix}.${key}` : key; const valueSchema = value; const type = getValibotSchemaType(valueSchema); const description$1 = getValibotDescription(valueSchema); if (type === "object") { const unwrappedSchema = unwrapSchema(valueSchema); if (unwrappedSchema && unwrappedSchema.entries) flattenValibotSchema(unwrappedSchema, result, fullKey); else result[fullKey] = { type, description: description$1 }; } else result[fullKey] = { type, description: description$1 }; } } return result; } //#endregion //#region src/utils/style-text.ts /** * Cross-platform styleText utility that works in both Node.js and browser environments * In Node.js, it uses the native `styleText` from `node:util` * In browser, it provides empty styling functions for compatibility */ function styleText$1(...args$1) { return styleText(...args$1); } //#endregion //#region src/utils/validator.ts const StringOrRegExpSchema = union([string(), instance(RegExp)]); function vFunction() { return function_(); } const LogLevelSchema = union([ literal("debug"), literal("info"), literal("warn") ]); const LogLevelOptionSchema = union([LogLevelSchema, literal("silent")]); const LogLevelWithErrorSchema = union([LogLevelSchema, literal("error")]); const RollupLogSchema = any(); const RollupLogWithStringSchema = union([RollupLogSchema, string()]); const InputOptionSchema = union([ string(), array(string()), record(string(), string()) ]); const ExternalOptionFunctionSchema = pipe(vFunction(), args(tuple([ string(), optional(string()), boolean() ])), returns(nullish(boolean()))); const ExternalOptionSchema = union([ StringOrRegExpSchema, array(StringOrRegExpSchema), ExternalOptionFunctionSchema ]); const ModuleTypesSchema = record(string(), union([ literal("asset"), literal("base64"), literal("binary"), literal("css"), literal("dataurl"), literal("empty"), literal("js"), literal("json"), literal("jsx"), literal("text"), literal("ts"), literal("tsx") ])); const JsxOptionsSchema = strictObject({ runtime: pipe(optional(union([literal("classic"), literal("automatic")])), description("Which runtime to use")), development: pipe(optional(boolean()), description("Development specific information")), throwIfNamespace: pipe(optional(boolean()), description("Toggles whether to throw an error when a tag name uses an XML namespace")), importSource: pipe(optional(string()), description("Import the factory of element and fragment if mode is classic")), pragma: pipe(optional(string()), description("Jsx element transformation")), pragmaFrag: pipe(optional(string()), description("Jsx fragment transformation")), refresh: pipe(optional(boolean()), description("Enable react fast refresh")) }); const HelperModeSchema = union([literal("Runtime"), literal("External")]); const DecoratorOptionSchema = object({ legacy: optional(boolean()), emitDecoratorMetadata: optional(boolean()) }); const HelpersSchema = object({ mode: optional(HelperModeSchema) }); const RewriteImportExtensionsSchema = union([ literal("rewrite"), literal("remove"), boolean() ]); const TypescriptSchema = object({ jsxPragma: optional(string()), jsxPragmaFrag: optional(string()), onlyRemoveTypeImports: optional(boolean()), allowNamespaces: optional(boolean()), allowDeclareFields: optional(boolean()), declaration: optional(object({ stripInternal: optional(boolean()), sourcemap: optional(boolean()) })), rewriteImportExtensions: optional(RewriteImportExtensionsSchema) }); const AssumptionsSchema = object({ ignoreFunctionLength: optional(boolean()), noDocumentAll: optional(boolean()), objectRestNoSymbols: optional(boolean()), pureGetters: optional(boolean()), setPublicClassFields: optional(boolean()) }); const TransformOptionsSchema = object({ assumptions: optional(AssumptionsSchema), typescript: optional(TypescriptSchema), helpers: optional(HelpersSchema), decorators: optional(DecoratorOptionSchema), jsx: optional(union([ literal(false), literal("preserve"), literal("react"), literal("react-jsx"), JsxOptionsSchema ])), target: pipe(optional(union([string(), array(string())])), description("The JavaScript target environment")), define: pipe(optional(record(string(), string())), description("Define global variables")), inject: pipe(optional(record(string(), union([string(), tuple([string(), string()])]))), description("Inject import statements on demand")), dropLabels: pipe(optional(array(string())), description("Remove labeled statements with these label names")) }); const WatchOptionsSchema = strictObject({ chokidar: optional(never(`The "watch.chokidar" option is deprecated, please use "watch.notify" instead of it`)), exclude: optional(union([StringOrRegExpSchema, array(StringOrRegExpSchema)])), include: optional(union([StringOrRegExpSchema, array(StringOrRegExpSchema)])), notify: pipe(optional(strictObject({ compareContents: optional(boolean()), pollInterval: optional(number()) })), description("Notify options")), skipWrite: pipe(optional(boolean()), description("Skip the bundle.write() step")), buildDelay: pipe(optional(number()), description("Throttle watch rebuilds")), clearScreen: pipe(optional(boolean()), description("Whether to clear the screen when a rebuild is triggered")), onInvalidate: pipe(optional(pipe(function_(), args(tuple([string()])))), description("An optional function that will be called immediately every time a module changes that is part of the build.")) }); const ChecksOptionsSchema = strictObject({ circularDependency: pipe(optional(boolean()), description("Whether to emit warning when detecting circular dependency")), eval: pipe(optional(boolean()), description("Whether to emit warning when detecting eval")), missingGlobalName: pipe(optional(boolean()), description("Whether to emit warning when detecting missing global name")), missingNameOptionForIifeExport: pipe(optional(boolean()), description("Whether to emit warning when detecting missing name option for iife export")), mixedExport: pipe(optional(boolean()), description("Whether to emit warning when detecting mixed export")), unresolvedEntry: pipe(optional(boolean()), description("Whether to emit warning when detecting unresolved entry")), unresolvedImport: pipe(optional(boolean()), description("Whether to emit warning when detecting unresolved import")), filenameConflict: pipe(optional(boolean()), description("Whether to emit warning when detecting filename conflict")), commonJsVariableInEsm: pipe(optional(boolean()), description("Whether to emit warning when detecting common js variable in esm")), importIsUndefined: pipe(optional(boolean()), description("Whether to emit warning when detecting import is undefined")), emptyImportMeta: pipe(optional(boolean()), description("Whether to emit warning when detecting empty import meta")), configurationFieldConflict: pipe(optional(boolean()), description("Whether to emit warning when detecting configuration field conflict")), preferBuiltinFeature: pipe(optional(boolean()), description("Whether to emit warning when detecting prefer builtin feature")), couldNotCleanDirectory: pipe(optional(boolean()), description("Whether to emit warning when detecting could not clean directory")) }); const CompressOptionsKeepNamesSchema = strictObject({ function: boolean(), class: boolean() }); const CompressOptionsSchema = strictObject({ target: optional(union([ literal("esnext"), literal("es2015"), literal("es2016"), literal("es2017"), literal("es2018"), literal("es2019"), literal("es2020"), literal("es2021"), literal("es2022"), literal("es2023"), literal("es2024") ])), dropConsole: optional(boolean()), dropDebugger: optional(boolean()), keepNames: optional(CompressOptionsKeepNamesSchema), unused: optional(union([boolean(), literal("keep_assign")])) }); const MangleOptionsKeepNamesSchema = strictObject({ function: boolean(), class: boolean() }); const MangleOptionsSchema = strictObject({ toplevel: optional(boolean()), keepNames: optional(union([boolean(), MangleOptionsKeepNamesSchema])), debug: optional(boolean()) }); const CodegenOptionsSchema = strictObject({ removeWhitespace: optional(boolean()) }); const MinifyOptionsSchema = strictObject({ compress: optional(union([boolean(), CompressOptionsSchema])), mangle: optional(union([boolean(), MangleOptionsSchema])), codegen: optional(union([boolean(), CodegenOptionsSchema])) }); const ResolveOptionsSchema = strictObject({ alias: optional(record(string(), union([ literal(false), string(), array(string()) ]))), aliasFields: optional(array(array(string()))), conditionNames: optional(array(string())), extensionAlias: optional(record(string(), array(string()))), exportsFields: optional(array(array(string()))), extensions: optional(array(string())), mainFields: optional(array(string())), mainFiles: optional(array(string())), modules: optional(array(string())), symlinks: optional(boolean()), yarnPnp: optional(boolean()) }); const TreeshakingOptionsSchema = union([boolean(), looseObject({ annotations: optional(boolean()), manualPureFunctions: optional(array(string())), unknownGlobalSideEffects: optional(boolean()), commonjs: optional(boolean()), propertyReadSideEffects: optional(union([literal(false), literal("always")])), propertyWriteSideEffects: optional(union([literal(false), literal("always")])) })]); const OptimizationOptionsSchema = strictObject({ inlineConst: pipe(optional(union([boolean(), strictObject({ mode: optional(union([literal("all"), literal("smart")])), pass: optional(number()) })])), description("Enable crossmodule constant inlining")), pifeForModuleWrappers: pipe(optional(boolean()), description("Use PIFE pattern for module wrappers")) }); const LogOrStringHandlerSchema = pipe(vFunction(), args(tuple([LogLevelWithErrorSchema, RollupLogWithStringSchema]))); const OnLogSchema = pipe(vFunction(), args(tuple([ LogLevelSchema, RollupLogSchema, LogOrStringHandlerSchema ]))); const OnwarnSchema = pipe(vFunction(), args(tuple([RollupLogSchema, pipe(vFunction(), args(tuple([union([RollupLogWithStringSchema, pipe(vFunction(), returns(RollupLogWithStringSchema))])])))]))); const HmrSchema = union([boolean(), strictObject({ new: optional(boolean()), port: optional(number()), host: optional(string()), implement: o