rolldown 0.14.0 → 0.15.0-commit.6d5a1b0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli.cjs +960 -966
- package/dist/cjs/experimental-index.cjs +68 -26
- package/dist/cjs/index.cjs +6 -8
- package/dist/cjs/parallel-plugin-worker.cjs +20 -14
- package/dist/cjs/parallel-plugin.cjs +1 -3
- package/dist/esm/cli.mjs +914 -922
- package/dist/esm/experimental-index.mjs +44 -7
- package/dist/esm/index.mjs +2 -4
- package/dist/esm/parallel-plugin-worker.mjs +15 -10
- package/dist/esm/parallel-plugin.mjs +1 -3
- package/dist/shared/{chunk-JoMxl5V2.cjs → chunk-BFvIen8E.cjs} +13 -11
- package/dist/shared/{consola.36c0034f-HcmWcfPe.cjs → consola_36c0034f-B7L-radJ.cjs} +249 -295
- package/dist/shared/{consola.36c0034f-Xyw7SC_7.mjs → consola_36c0034f-D9ce-831.mjs} +221 -286
- package/dist/shared/{prompt-9Ij3R3TG.cjs → prompt-BiXtYIJ2.cjs} +157 -204
- package/dist/shared/{prompt-hoPhcrA-.mjs → prompt-DlQ-08lk.mjs} +125 -174
- package/dist/shared/src-CTTOsHx-.cjs +2985 -0
- package/dist/shared/src-DcKnw9Hv.mjs +2851 -0
- package/dist/tsconfig.dts.tsbuildinfo +1 -0
- package/dist/types/api/build.d.ts +16 -0
- package/dist/types/api/experimental.d.ts +7 -0
- package/dist/types/api/rolldown/index.d.ts +3 -0
- package/dist/types/api/rolldown/rolldown-build.d.ts +12 -0
- package/dist/types/api/watch/index.d.ts +3 -0
- package/dist/types/{watcher.d.ts → api/watch/watch-emitter.d.ts} +17 -17
- package/dist/types/api/watch/watcher.d.ts +13 -0
- package/dist/types/binding.d.ts +273 -49
- package/dist/types/builtin-plugin/alias-plugin.d.ts +10 -0
- package/dist/types/builtin-plugin/constructors.d.ts +16 -0
- package/dist/types/builtin-plugin/replace-plugin.d.ts +28 -0
- package/dist/types/{options/normalized-ecma-transform-plugin-config.d.ts → builtin-plugin/transform-plugin.d.ts} +2 -1
- package/dist/types/builtin-plugin/utils.d.ts +8 -0
- package/dist/types/cli/arguments/index.d.ts +5 -3
- package/dist/types/cli/arguments/normalize.d.ts +2 -6
- package/dist/types/cli/arguments/schema.d.ts +10 -309
- package/dist/types/cli/colors.d.ts +11 -1
- package/dist/types/cli/load-config.d.ts +3 -0
- package/dist/types/cli/logger.d.ts +5 -0
- package/dist/types/constants/plugin.d.ts +10 -1
- package/dist/types/experimental-index.d.ts +5 -2
- package/dist/types/index.d.ts +13 -10
- package/dist/types/log/logger.d.ts +2 -16
- package/dist/types/log/logging.d.ts +11 -8
- package/dist/types/log/logs.d.ts +3 -0
- package/dist/types/options/input-options-schema.d.ts +4 -0
- package/dist/types/options/input-options.d.ts +89 -430
- package/dist/types/options/normalized-input-options.d.ts +17 -11
- package/dist/types/options/normalized-output-options.d.ts +60 -21
- package/dist/types/options/output-options-schema.d.ts +3 -0
- package/dist/types/options/output-options.d.ts +73 -265
- package/dist/types/options/watch-options.d.ts +5 -0
- package/dist/types/plugin/bindingify-build-hooks.d.ts +9 -11
- package/dist/types/plugin/bindingify-hook-filter.d.ts +5 -5
- package/dist/types/plugin/bindingify-output-hooks.d.ts +13 -16
- package/dist/types/plugin/bindingify-plugin.d.ts +12 -3
- package/dist/types/plugin/bindingify-watch-hooks.d.ts +3 -5
- package/dist/types/plugin/hook-filter.d.ts +1 -1
- package/dist/types/plugin/index.d.ts +21 -18
- package/dist/types/plugin/minimal-plugin-context.d.ts +15 -0
- package/dist/types/plugin/plugin-context-data.d.ts +4 -4
- package/dist/types/plugin/plugin-context.d.ts +9 -4
- package/dist/types/plugin/plugin-driver.d.ts +4 -5
- package/dist/types/plugin/transform-plugin-context.d.ts +4 -3
- package/dist/types/rollup-types.d.ts +1 -1
- package/dist/types/rollup.d.ts +4 -0
- package/dist/types/treeshake/index.d.ts +0 -12
- package/dist/types/treeshake/module-side-effects.d.ts +14 -15
- package/dist/types/types/rolldown-output.d.ts +17 -2
- package/dist/types/types/utils.d.ts +1 -0
- package/dist/types/utils/bindingify-input-options.d.ts +7 -0
- package/dist/types/utils/bindingify-output-options.d.ts +3 -0
- package/dist/types/utils/create-bundler-option.d.ts +11 -0
- package/dist/types/utils/define-config.d.ts +3 -0
- package/dist/types/utils/error.d.ts +2 -0
- package/dist/types/utils/misc.d.ts +1 -0
- package/dist/types/utils/normalize-hook.d.ts +1 -1
- package/dist/types/utils/normalize-plugin-option.d.ts +8 -3
- package/dist/types/{options/utils.d.ts → utils/normalize-string-or-regex.d.ts} +1 -1
- package/dist/types/utils/transform-rendered-chunk.d.ts +4 -0
- package/dist/types/utils/transform-rendered-module.d.ts +3 -0
- package/dist/types/utils/transform-sourcemap.d.ts +2 -0
- package/dist/types/utils/transform-to-rollup-output.d.ts +1 -0
- package/dist/types/utils/zod-ext.d.ts +6 -5
- package/package.json +31 -23
- package/dist/shared/rolldown-binding.wasi.cjs +0 -187
- package/dist/shared/src_index-3pqhEViJ.cjs +0 -2785
- package/dist/shared/src_index-ywYMd4vB.mjs +0 -2786
- package/dist/shared/wasi-worker-browser.mjs +0 -39
- package/dist/shared/wasi-worker.mjs +0 -63
- package/dist/shared/watcher-worker.js +0 -1
- package/dist/types/cli/utils.d.ts +0 -6
- package/dist/types/constants/types.d.ts +0 -1
- package/dist/types/options/bindingify-input-options.d.ts +0 -4
- package/dist/types/options/bindingify-output-options.d.ts +0 -3
- package/dist/types/options/normalized-alias-plugin-config.d.ts +0 -8
- package/dist/types/options/watch-option.d.ts +0 -5
- package/dist/types/plugin/builtin-plugin.d.ts +0 -81
- package/dist/types/rolldown-build.d.ts +0 -10
- package/dist/types/rolldown.d.ts +0 -12
- package/dist/types/types/rendered-module.d.ts +0 -2
- package/dist/types/utils/normalize-input-options.d.ts +0 -3
- package/dist/types/utils/normalize-output-options.d.ts +0 -3
- package/dist/types/utils/normalize-tree-shake.d.ts +0 -3
- /package/dist/types/{utils/type-assert.d.ts → types/assert.d.ts} +0 -0
package/dist/cjs/cli.cjs
CHANGED
|
@@ -1,128 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
const require_chunk = require('../shared/chunk-BFvIen8E.cjs');
|
|
3
|
+
const require_src = require('../shared/src-CTTOsHx-.cjs');
|
|
4
|
+
const require_consola_36c0034f = require('../shared/consola_36c0034f-B7L-radJ.cjs');
|
|
5
|
+
const node_fs = require_chunk.__toESM(require("node:fs"));
|
|
6
|
+
const zod = require_chunk.__toESM(require("zod"));
|
|
7
|
+
const node_path = require_chunk.__toESM(require("node:path"));
|
|
8
|
+
const node_process = require_chunk.__toESM(require("node:process"));
|
|
9
|
+
const node_perf_hooks = require_chunk.__toESM(require("node:perf_hooks"));
|
|
10
|
+
const tty = require_chunk.__toESM(require("tty"));
|
|
11
|
+
const node_util = require_chunk.__toESM(require("node:util"));
|
|
12
|
+
const node_tty = require_chunk.__toESM(require("node:tty"));
|
|
13
|
+
const node_url = require_chunk.__toESM(require("node:url"));
|
|
2
14
|
|
|
3
|
-
const { __export, __toESM } = require("../shared/chunk-JoMxl5V2.cjs");
|
|
4
|
-
const { LogLevelOptionSchema, LogLevelSchema, LogLevelWithErrorSchema, RollupLogSchema, RollupLogWithStringSchema, arraify, description, rolldown, version, watch } = require("../shared/src_index-3pqhEViJ.cjs");
|
|
5
|
-
const { createConsola } = require("../shared/consola.36c0034f-HcmWcfPe.cjs");
|
|
6
|
-
const { default: nodePath, default: path } = __toESM(require("node:path"));
|
|
7
|
-
const { ZodFirstPartyTypeKind, ZodFirstPartyTypeKind: ZodFirstPartyTypeKind$1, ZodFirstPartyTypeKind: ZodFirstPartyTypeKind$2, z, z: z$1, z: z$2, z: z$3 } = __toESM(require("zod"));
|
|
8
|
-
const { default: process$1, env } = __toESM(require("node:process"));
|
|
9
|
-
const { performance } = __toESM(require("node:perf_hooks"));
|
|
10
|
-
const { pathToFileURL } = __toESM(require("node:url"));
|
|
11
|
-
const { parseArgs } = __toESM(require("node:util"));
|
|
12
|
-
const tty = __toESM(require("node:tty"));
|
|
13
|
-
|
|
14
|
-
//#region src/cli/utils.ts
|
|
15
|
-
const logger = process.env.ROLLDOWN_TEST ? createTestingLogger() : createConsola({formatOptions: {date: false}});
|
|
16
|
-
function createTestingLogger() {
|
|
17
|
-
const types = ["silent", "fatal", "error", "warn", "log", "info", "success", "fail", "ready", "start", "box", "debug", "trace", "verbose",];
|
|
18
|
-
const ret = Object.create(null);
|
|
19
|
-
for (const type of types) {
|
|
20
|
-
ret[type] = console.log;
|
|
21
|
-
}
|
|
22
|
-
return ret;
|
|
23
|
-
}
|
|
24
|
-
async function ensureConfig(configPath) {
|
|
25
|
-
if (!isSupportedFormat(configPath)) {
|
|
26
|
-
throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${nodePath.extname(configPath)}\``);
|
|
27
|
-
}
|
|
28
|
-
const fileUrl = (pathToFileURL(configPath)).toString();
|
|
29
|
-
const configExports = await import(fileUrl);
|
|
30
|
-
return configExports.default;
|
|
31
|
-
}
|
|
32
|
-
const SUPPORTED_CONFIG_FORMATS = [".js", ".mjs", ".cjs"];
|
|
33
|
-
function isSupportedFormat(configPath) {
|
|
34
|
-
const ext = nodePath.extname(configPath);
|
|
35
|
-
return SUPPORTED_CONFIG_FORMATS.includes(ext);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
//#endregion
|
|
39
|
-
//#region ../../node_modules/.pnpm/colorette@2.0.20/node_modules/colorette/index.js
|
|
40
|
-
const { env: env$1 = {}, argv: argv = [], platform: platform = "" } = typeof process === "undefined" ? {} : process;
|
|
41
|
-
const isDisabled = "NO_COLOR"in env$1 || argv.includes("--no-color");
|
|
42
|
-
const isForced = "FORCE_COLOR"in env$1 || argv.includes("--color");
|
|
43
|
-
const isWindows = platform === "win32";
|
|
44
|
-
const isDumbTerminal = env$1.TERM === "dumb";
|
|
45
|
-
const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env$1.TERM && !isDumbTerminal;
|
|
46
|
-
const isCI = "CI"in env$1 && ("GITHUB_ACTIONS"in env$1 || "GITLAB_CI"in env$1 || "CIRCLECI"in env$1);
|
|
47
|
-
const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
|
|
48
|
-
const replaceClose = (index, string, close, replace, head = string.substring(0, index) + replace, tail = string.substring(index + close.length), next = tail.indexOf(close)) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
|
|
49
|
-
const clearBleed = (index, string, open, close, replace) => index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
|
|
50
|
-
const filterEmpty = (open, close, replace = open, at = open.length + 1) => (string) => string || !(string === "" || string === undefined) ? clearBleed(("" + string).indexOf(close, at), string, open, close, replace) : "";
|
|
51
|
-
const init = (open, close, replace) => filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`, replace);
|
|
52
|
-
const colors = {
|
|
53
|
-
reset: init(0, 0),
|
|
54
|
-
bold: init(1, 22, "\x1B[22m\x1B[1m"),
|
|
55
|
-
dim: init(2, 22, "\x1B[22m\x1B[2m"),
|
|
56
|
-
italic: init(3, 23),
|
|
57
|
-
underline: init(4, 24),
|
|
58
|
-
inverse: init(7, 27),
|
|
59
|
-
hidden: init(8, 28),
|
|
60
|
-
strikethrough: init(9, 29),
|
|
61
|
-
black: init(30, 39),
|
|
62
|
-
red: init(31, 39),
|
|
63
|
-
green: init(32, 39),
|
|
64
|
-
yellow: init(33, 39),
|
|
65
|
-
blue: init(34, 39),
|
|
66
|
-
magenta: init(35, 39),
|
|
67
|
-
cyan: init(36, 39),
|
|
68
|
-
white: init(37, 39),
|
|
69
|
-
gray: init(90, 39),
|
|
70
|
-
bgBlack: init(40, 49),
|
|
71
|
-
bgRed: init(41, 49),
|
|
72
|
-
bgGreen: init(42, 49),
|
|
73
|
-
bgYellow: init(43, 49),
|
|
74
|
-
bgBlue: init(44, 49),
|
|
75
|
-
bgMagenta: init(45, 49),
|
|
76
|
-
bgCyan: init(46, 49),
|
|
77
|
-
bgWhite: init(47, 49),
|
|
78
|
-
blackBright: init(90, 39),
|
|
79
|
-
redBright: init(91, 39),
|
|
80
|
-
greenBright: init(92, 39),
|
|
81
|
-
yellowBright: init(93, 39),
|
|
82
|
-
blueBright: init(94, 39),
|
|
83
|
-
magentaBright: init(95, 39),
|
|
84
|
-
cyanBright: init(96, 39),
|
|
85
|
-
whiteBright: init(97, 39),
|
|
86
|
-
bgBlackBright: init(100, 49),
|
|
87
|
-
bgRedBright: init(101, 49),
|
|
88
|
-
bgGreenBright: init(102, 49),
|
|
89
|
-
bgYellowBright: init(103, 49),
|
|
90
|
-
bgBlueBright: init(104, 49),
|
|
91
|
-
bgMagentaBright: init(105, 49),
|
|
92
|
-
bgCyanBright: init(106, 49),
|
|
93
|
-
bgWhiteBright: init(107, 49)
|
|
94
|
-
};
|
|
95
|
-
const createColors = ({ useColor: useColor = isColorSupported } = {}) => useColor ? colors : (Object.keys(colors)).reduce((colors$1, key) => ({
|
|
96
|
-
...colors$1,
|
|
97
|
-
[key]: String
|
|
98
|
-
}), {});
|
|
99
|
-
const { reset: reset, bold: bold$1, dim: dim$1, italic: italic, underline: underline$1, inverse: inverse, hidden: hidden, strikethrough: strikethrough, black: black, red: red$1, green: green$1, yellow: yellow$1, blue: blue, magenta: magenta, cyan: cyan$1, white: white, gray: gray$1, bgBlack: bgBlack, bgRed: bgRed, bgGreen: bgGreen, bgYellow: bgYellow, bgBlue: bgBlue, bgMagenta: bgMagenta, bgCyan: bgCyan, bgWhite: bgWhite, blackBright: blackBright, redBright: redBright, greenBright: greenBright, yellowBright: yellowBright, blueBright: blueBright, magentaBright: magentaBright, cyanBright: cyanBright, whiteBright: whiteBright, bgBlackBright: bgBlackBright, bgRedBright: bgRedBright, bgGreenBright: bgGreenBright, bgYellowBright: bgYellowBright, bgBlueBright: bgBlueBright, bgMagentaBright: bgMagentaBright, bgCyanBright: bgCyanBright, bgWhiteBright: bgWhiteBright } = createColors();
|
|
100
|
-
|
|
101
|
-
//#endregion
|
|
102
|
-
//#region src/cli/colors.ts
|
|
103
|
-
var colors_ns = {};
|
|
104
|
-
__export(colors_ns, {
|
|
105
|
-
bold: () => bold,
|
|
106
|
-
cyan: () => cyan,
|
|
107
|
-
dim: () => dim,
|
|
108
|
-
gray: () => gray,
|
|
109
|
-
green: () => green,
|
|
110
|
-
red: () => red,
|
|
111
|
-
underline: () => underline,
|
|
112
|
-
yellow: () => yellow
|
|
113
|
-
});
|
|
114
|
-
const { bold: bold, cyan: cyan, dim: dim, gray: gray, green: green, red: red, underline: underline, yellow: yellow } = createColors({useColor: env.FORCE_COLOR !== "0" && !env.NO_COLOR});
|
|
115
|
-
|
|
116
|
-
//#endregion
|
|
117
15
|
//#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/signals.js
|
|
118
16
|
const signals = [];
|
|
119
17
|
signals.push("SIGHUP", "SIGINT", "SIGTERM");
|
|
120
|
-
if (process.platform !== "win32")
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
18
|
+
if (process.platform !== "win32") signals.push(
|
|
19
|
+
"SIGALRM",
|
|
20
|
+
"SIGABRT",
|
|
21
|
+
"SIGVTALRM",
|
|
22
|
+
"SIGXCPU",
|
|
23
|
+
"SIGXFSZ",
|
|
24
|
+
"SIGUSR2",
|
|
25
|
+
"SIGTRAP",
|
|
26
|
+
"SIGSYS",
|
|
27
|
+
"SIGQUIT",
|
|
28
|
+
"SIGIOT"
|
|
29
|
+
// should detect profiler and enable/disable accordingly.
|
|
30
|
+
// see #21
|
|
31
|
+
// 'SIGPROF'
|
|
32
|
+
);
|
|
33
|
+
if (process.platform === "linux") signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");
|
|
126
34
|
|
|
127
35
|
//#endregion
|
|
128
36
|
//#region ../../node_modules/.pnpm/signal-exit@4.1.0/node_modules/signal-exit/dist/mjs/index.js
|
|
@@ -130,7 +38,7 @@ const processOk = (process$3) => !!process$3 && typeof process$3 === "object" &&
|
|
|
130
38
|
const kExitEmitter = Symbol.for("signal-exit emitter");
|
|
131
39
|
const global = globalThis;
|
|
132
40
|
const ObjectDefineProperty = Object.defineProperty.bind(Object);
|
|
133
|
-
|
|
41
|
+
var Emitter = class {
|
|
134
42
|
emitted = {
|
|
135
43
|
afterExit: false,
|
|
136
44
|
exit: false
|
|
@@ -142,9 +50,7 @@ class Emitter {
|
|
|
142
50
|
count = 0;
|
|
143
51
|
id = Math.random();
|
|
144
52
|
constructor() {
|
|
145
|
-
if (global[kExitEmitter])
|
|
146
|
-
return global[kExitEmitter];
|
|
147
|
-
}
|
|
53
|
+
if (global[kExitEmitter]) return global[kExitEmitter];
|
|
148
54
|
ObjectDefineProperty(global, kExitEmitter, {
|
|
149
55
|
value: this,
|
|
150
56
|
writable: false,
|
|
@@ -158,31 +64,20 @@ class Emitter {
|
|
|
158
64
|
removeListener(ev, fn) {
|
|
159
65
|
const list = this.listeners[ev];
|
|
160
66
|
const i = list.indexOf(fn);
|
|
161
|
-
if (i === -1)
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
if (i === 0 && list.length === 1) {
|
|
165
|
-
list.length = 0;
|
|
166
|
-
} else {
|
|
167
|
-
list.splice(i, 1);
|
|
168
|
-
}
|
|
67
|
+
if (i === -1) return;
|
|
68
|
+
if (i === 0 && list.length === 1) list.length = 0;
|
|
69
|
+
else list.splice(i, 1);
|
|
169
70
|
}
|
|
170
71
|
emit(ev, code, signal) {
|
|
171
|
-
if (this.emitted[ev])
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
72
|
+
if (this.emitted[ev]) return false;
|
|
174
73
|
this.emitted[ev] = true;
|
|
175
74
|
let ret = false;
|
|
176
|
-
for (const fn of this.listeners[ev])
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
if (ev === "exit") {
|
|
180
|
-
ret = this.emit("afterExit", code, signal) || ret;
|
|
181
|
-
}
|
|
75
|
+
for (const fn of this.listeners[ev]) ret = fn(code, signal) === true || ret;
|
|
76
|
+
if (ev === "exit") ret = this.emit("afterExit", code, signal) || ret;
|
|
182
77
|
return ret;
|
|
183
78
|
}
|
|
184
|
-
}
|
|
185
|
-
|
|
79
|
+
};
|
|
80
|
+
var SignalExitBase = class {};
|
|
186
81
|
const signalExitWrap = (handler) => {
|
|
187
82
|
return {
|
|
188
83
|
onExit(cb, opts) {
|
|
@@ -196,14 +91,14 @@ const signalExitWrap = (handler) => {
|
|
|
196
91
|
}
|
|
197
92
|
};
|
|
198
93
|
};
|
|
199
|
-
|
|
94
|
+
var SignalExitFallback = class extends SignalExitBase {
|
|
200
95
|
onExit() {
|
|
201
96
|
return () => {};
|
|
202
97
|
}
|
|
203
98
|
load() {}
|
|
204
99
|
unload() {}
|
|
205
|
-
}
|
|
206
|
-
|
|
100
|
+
};
|
|
101
|
+
var SignalExit = class extends SignalExitBase {
|
|
207
102
|
#hupSig = process$2.platform === "win32" ? "SIGINT" : "SIGHUP";
|
|
208
103
|
#emitter = new Emitter();
|
|
209
104
|
#process;
|
|
@@ -215,53 +110,39 @@ class SignalExit extends SignalExitBase {
|
|
|
215
110
|
super();
|
|
216
111
|
this.#process = process$3;
|
|
217
112
|
this.#sigListeners = {};
|
|
218
|
-
for (const sig of signals) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (!ret) process$3.kill(process$3.pid, s);
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
}
|
|
113
|
+
for (const sig of signals) this.#sigListeners[sig] = () => {
|
|
114
|
+
const listeners = this.#process.listeners(sig);
|
|
115
|
+
let { count } = this.#emitter;
|
|
116
|
+
const p = process$3;
|
|
117
|
+
if (typeof p.__signal_exit_emitter__ === "object" && typeof p.__signal_exit_emitter__.count === "number") count += p.__signal_exit_emitter__.count;
|
|
118
|
+
if (listeners.length === count) {
|
|
119
|
+
this.unload();
|
|
120
|
+
const ret = this.#emitter.emit("exit", null, sig);
|
|
121
|
+
const s = sig === "SIGHUP" ? this.#hupSig : sig;
|
|
122
|
+
if (!ret) process$3.kill(process$3.pid, s);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
234
125
|
this.#originalProcessReallyExit = process$3.reallyExit;
|
|
235
126
|
this.#originalProcessEmit = process$3.emit;
|
|
236
127
|
}
|
|
237
128
|
onExit(cb, opts) {
|
|
238
|
-
if (!processOk(this.#process)) {
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
if (this.#loaded === false) {
|
|
242
|
-
this.load();
|
|
243
|
-
}
|
|
129
|
+
if (!processOk(this.#process)) return () => {};
|
|
130
|
+
if (this.#loaded === false) this.load();
|
|
244
131
|
const ev = opts?.alwaysLast ? "afterExit" : "exit";
|
|
245
132
|
this.#emitter.on(ev, cb);
|
|
246
133
|
return () => {
|
|
247
134
|
this.#emitter.removeListener(ev, cb);
|
|
248
|
-
if (this.#emitter.listeners["exit"].length === 0 && this.#emitter.listeners["afterExit"].length === 0)
|
|
249
|
-
this.unload();
|
|
250
|
-
}
|
|
135
|
+
if (this.#emitter.listeners["exit"].length === 0 && this.#emitter.listeners["afterExit"].length === 0) this.unload();
|
|
251
136
|
};
|
|
252
137
|
}
|
|
253
138
|
load() {
|
|
254
|
-
if (this.#loaded)
|
|
255
|
-
return;
|
|
256
|
-
}
|
|
139
|
+
if (this.#loaded) return;
|
|
257
140
|
this.#loaded = true;
|
|
258
141
|
this.#emitter.count += 1;
|
|
259
|
-
for (const sig of signals) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
} catch (_) {}
|
|
264
|
-
}
|
|
142
|
+
for (const sig of signals) try {
|
|
143
|
+
const fn = this.#sigListeners[sig];
|
|
144
|
+
if (fn) this.#process.on(sig, fn);
|
|
145
|
+
} catch (_) {}
|
|
265
146
|
this.#process.emit = (ev, ...a) => {
|
|
266
147
|
return this.#processEmit(ev, ...a);
|
|
267
148
|
};
|
|
@@ -270,15 +151,11 @@ class SignalExit extends SignalExitBase {
|
|
|
270
151
|
};
|
|
271
152
|
}
|
|
272
153
|
unload() {
|
|
273
|
-
if (!this.#loaded)
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
154
|
+
if (!this.#loaded) return;
|
|
276
155
|
this.#loaded = false;
|
|
277
156
|
signals.forEach((sig) => {
|
|
278
157
|
const listener = this.#sigListeners[sig];
|
|
279
|
-
if (!listener)
|
|
280
|
-
throw new Error("Listener not defined for signal: " + sig);
|
|
281
|
-
}
|
|
158
|
+
if (!listener) throw new Error("Listener not defined for signal: " + sig);
|
|
282
159
|
try {
|
|
283
160
|
this.#process.removeListener(sig, listener);
|
|
284
161
|
} catch (_) {}
|
|
@@ -288,9 +165,7 @@ class SignalExit extends SignalExitBase {
|
|
|
288
165
|
this.#emitter.count -= 1;
|
|
289
166
|
}
|
|
290
167
|
#processReallyExit(code) {
|
|
291
|
-
if (!processOk(this.#process))
|
|
292
|
-
return 0;
|
|
293
|
-
}
|
|
168
|
+
if (!processOk(this.#process)) return 0;
|
|
294
169
|
this.#process.exitCode = code || 0;
|
|
295
170
|
this.#emitter.emit("exit", this.#process.exitCode, null);
|
|
296
171
|
return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode);
|
|
@@ -298,78 +173,256 @@ class SignalExit extends SignalExitBase {
|
|
|
298
173
|
#processEmit(ev, ...args) {
|
|
299
174
|
const og = this.#originalProcessEmit;
|
|
300
175
|
if (ev === "exit" && processOk(this.#process)) {
|
|
301
|
-
if (typeof args[0] === "number")
|
|
302
|
-
this.#process.exitCode = args[0];
|
|
303
|
-
}
|
|
176
|
+
if (typeof args[0] === "number") this.#process.exitCode = args[0];
|
|
304
177
|
const ret = og.call(this.#process, ev, ...args);
|
|
305
178
|
this.#emitter.emit("exit", this.#process.exitCode, null);
|
|
306
179
|
return ret;
|
|
307
|
-
} else
|
|
308
|
-
return og.call(this.#process, ev, ...args);
|
|
309
|
-
}
|
|
180
|
+
} else return og.call(this.#process, ev, ...args);
|
|
310
181
|
}
|
|
311
|
-
}
|
|
182
|
+
};
|
|
312
183
|
const process$2 = globalThis.process;
|
|
313
|
-
const { onExit
|
|
184
|
+
const { onExit, load, unload } = signalExitWrap(processOk(process$2) ? new SignalExit(process$2) : new SignalExitFallback());
|
|
185
|
+
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region ../../node_modules/.pnpm/colorette@2.0.20/node_modules/colorette/index.js
|
|
188
|
+
const { env: env$1 = {}, argv = [], platform = "" } = typeof process === "undefined" ? {} : process;
|
|
189
|
+
const isDisabled = "NO_COLOR" in env$1 || argv.includes("--no-color");
|
|
190
|
+
const isForced = "FORCE_COLOR" in env$1 || argv.includes("--color");
|
|
191
|
+
const isWindows = platform === "win32";
|
|
192
|
+
const isDumbTerminal = env$1.TERM === "dumb";
|
|
193
|
+
const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env$1.TERM && !isDumbTerminal;
|
|
194
|
+
const isCI = "CI" in env$1 && ("GITHUB_ACTIONS" in env$1 || "GITLAB_CI" in env$1 || "CIRCLECI" in env$1);
|
|
195
|
+
const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
|
|
196
|
+
const replaceClose = (index, string, close, replace, head = string.substring(0, index) + replace, tail = string.substring(index + close.length), next = tail.indexOf(close)) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
|
|
197
|
+
const clearBleed = (index, string, open, close, replace) => index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
|
|
198
|
+
const filterEmpty = (open, close, replace = open, at = open.length + 1) => (string) => string || !(string === "" || string === undefined) ? clearBleed(("" + string).indexOf(close, at), string, open, close, replace) : "";
|
|
199
|
+
const init = (open, close, replace) => filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`, replace);
|
|
200
|
+
const colors$1 = {
|
|
201
|
+
reset: init(0, 0),
|
|
202
|
+
bold: init(1, 22, "\x1B[22m\x1B[1m"),
|
|
203
|
+
dim: init(2, 22, "\x1B[22m\x1B[2m"),
|
|
204
|
+
italic: init(3, 23),
|
|
205
|
+
underline: init(4, 24),
|
|
206
|
+
inverse: init(7, 27),
|
|
207
|
+
hidden: init(8, 28),
|
|
208
|
+
strikethrough: init(9, 29),
|
|
209
|
+
black: init(30, 39),
|
|
210
|
+
red: init(31, 39),
|
|
211
|
+
green: init(32, 39),
|
|
212
|
+
yellow: init(33, 39),
|
|
213
|
+
blue: init(34, 39),
|
|
214
|
+
magenta: init(35, 39),
|
|
215
|
+
cyan: init(36, 39),
|
|
216
|
+
white: init(37, 39),
|
|
217
|
+
gray: init(90, 39),
|
|
218
|
+
bgBlack: init(40, 49),
|
|
219
|
+
bgRed: init(41, 49),
|
|
220
|
+
bgGreen: init(42, 49),
|
|
221
|
+
bgYellow: init(43, 49),
|
|
222
|
+
bgBlue: init(44, 49),
|
|
223
|
+
bgMagenta: init(45, 49),
|
|
224
|
+
bgCyan: init(46, 49),
|
|
225
|
+
bgWhite: init(47, 49),
|
|
226
|
+
blackBright: init(90, 39),
|
|
227
|
+
redBright: init(91, 39),
|
|
228
|
+
greenBright: init(92, 39),
|
|
229
|
+
yellowBright: init(93, 39),
|
|
230
|
+
blueBright: init(94, 39),
|
|
231
|
+
magentaBright: init(95, 39),
|
|
232
|
+
cyanBright: init(96, 39),
|
|
233
|
+
whiteBright: init(97, 39),
|
|
234
|
+
bgBlackBright: init(100, 49),
|
|
235
|
+
bgRedBright: init(101, 49),
|
|
236
|
+
bgGreenBright: init(102, 49),
|
|
237
|
+
bgYellowBright: init(103, 49),
|
|
238
|
+
bgBlueBright: init(104, 49),
|
|
239
|
+
bgMagentaBright: init(105, 49),
|
|
240
|
+
bgCyanBright: init(106, 49),
|
|
241
|
+
bgWhiteBright: init(107, 49)
|
|
242
|
+
};
|
|
243
|
+
const createColors = ({ useColor = isColorSupported } = {}) => useColor ? colors$1 : Object.keys(colors$1).reduce((colors$2, key) => ({
|
|
244
|
+
...colors$2,
|
|
245
|
+
[key]: String
|
|
246
|
+
}), {});
|
|
247
|
+
const { reset, bold: bold$1, dim: dim$1, italic, underline: underline$1, inverse, hidden, strikethrough, black, red: red$1, green: green$1, yellow: yellow$1, blue, magenta, cyan: cyan$1, white, gray: gray$1, bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, blackBright, redBright, greenBright, yellowBright, blueBright, magentaBright, cyanBright, whiteBright, bgBlackBright, bgRedBright, bgGreenBright, bgYellowBright, bgBlueBright, bgMagentaBright, bgCyanBright, bgWhiteBright } = createColors();
|
|
248
|
+
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/cli/colors.ts
|
|
251
|
+
const { bold, cyan, dim, gray, green, red, underline, yellow } = createColors({ useColor: node_process.env.FORCE_COLOR !== "0" && !node_process.env.NO_COLOR });
|
|
252
|
+
const colors = {
|
|
253
|
+
bold,
|
|
254
|
+
cyan,
|
|
255
|
+
dim,
|
|
256
|
+
gray,
|
|
257
|
+
green,
|
|
258
|
+
red,
|
|
259
|
+
underline,
|
|
260
|
+
yellow
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region src/cli/logger.ts
|
|
265
|
+
const logger = process.env.ROLLDOWN_TEST ? createTestingLogger() : require_consola_36c0034f.createConsola({ formatOptions: { date: false } });
|
|
266
|
+
function createTestingLogger() {
|
|
267
|
+
const types = [
|
|
268
|
+
"silent",
|
|
269
|
+
"fatal",
|
|
270
|
+
"error",
|
|
271
|
+
"warn",
|
|
272
|
+
"log",
|
|
273
|
+
"info",
|
|
274
|
+
"success",
|
|
275
|
+
"fail",
|
|
276
|
+
"ready",
|
|
277
|
+
"start",
|
|
278
|
+
"box",
|
|
279
|
+
"debug",
|
|
280
|
+
"trace",
|
|
281
|
+
"verbose"
|
|
282
|
+
];
|
|
283
|
+
const ret = Object.create(null);
|
|
284
|
+
for (const type of types) ret[type] = console.log;
|
|
285
|
+
return ret;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/cli/load-config.ts
|
|
290
|
+
async function loadTsConfig(configFile) {
|
|
291
|
+
const file = await bundleTsConfig(configFile);
|
|
292
|
+
try {
|
|
293
|
+
return (await import((0, node_url.pathToFileURL)(file).href)).default;
|
|
294
|
+
} finally {
|
|
295
|
+
node_fs.default.unlink(file, () => {});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
async function bundleTsConfig(configFile) {
|
|
299
|
+
const dirnameVarName = "injected_original_dirname";
|
|
300
|
+
const filenameVarName = "injected_original_filename";
|
|
301
|
+
const importMetaUrlVarName = "injected_original_import_meta_url";
|
|
302
|
+
const bundle = await require_src.rolldown({
|
|
303
|
+
input: configFile,
|
|
304
|
+
platform: "node",
|
|
305
|
+
resolve: { mainFields: ["main"] },
|
|
306
|
+
define: {
|
|
307
|
+
__dirname: dirnameVarName,
|
|
308
|
+
__filename: filenameVarName,
|
|
309
|
+
"import.meta.url": importMetaUrlVarName,
|
|
310
|
+
"import.meta.dirname": dirnameVarName,
|
|
311
|
+
"import.meta.filename": filenameVarName
|
|
312
|
+
},
|
|
313
|
+
treeshake: false,
|
|
314
|
+
external: [/^[\w@][^:]/],
|
|
315
|
+
plugins: [{
|
|
316
|
+
name: "inject-file-scope-variables",
|
|
317
|
+
transform: {
|
|
318
|
+
filter: { id: /\.[cm]?[jt]s$/ },
|
|
319
|
+
async handler(code, id) {
|
|
320
|
+
const injectValues = `const ${dirnameVarName} = ${JSON.stringify(node_path.default.dirname(id))};` + `const ${filenameVarName} = ${JSON.stringify(id)};` + `const ${importMetaUrlVarName} = ${JSON.stringify((0, node_url.pathToFileURL)(id).href)};`;
|
|
321
|
+
return {
|
|
322
|
+
code: injectValues + code,
|
|
323
|
+
map: null
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}]
|
|
328
|
+
});
|
|
329
|
+
const result = await bundle.write({
|
|
330
|
+
dir: node_path.default.dirname(configFile),
|
|
331
|
+
format: "esm",
|
|
332
|
+
sourcemap: "inline",
|
|
333
|
+
entryFileNames: "rolldown.config.[hash].js"
|
|
334
|
+
});
|
|
335
|
+
return result.output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
|
|
336
|
+
}
|
|
337
|
+
const SUPPORTED_JS_CONFIG_FORMATS = [
|
|
338
|
+
".js",
|
|
339
|
+
".mjs",
|
|
340
|
+
".cjs"
|
|
341
|
+
];
|
|
342
|
+
const SUPPORTED_TS_CONFIG_FORMATS = [
|
|
343
|
+
".ts",
|
|
344
|
+
".mts",
|
|
345
|
+
".cts"
|
|
346
|
+
];
|
|
347
|
+
const SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
|
|
348
|
+
async function loadConfig(configPath) {
|
|
349
|
+
const ext = node_path.default.extname(configPath);
|
|
350
|
+
try {
|
|
351
|
+
if (SUPPORTED_JS_CONFIG_FORMATS.includes(ext) || process.env.NODE_OPTIONS?.includes("--import=tsx") && SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return (await import((0, node_url.pathToFileURL)(configPath).href)).default;
|
|
352
|
+
else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return await loadTsConfig(configPath);
|
|
353
|
+
else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
|
|
354
|
+
} catch (err) {
|
|
355
|
+
throw new Error("Error happened while loading config.", { cause: err });
|
|
356
|
+
}
|
|
357
|
+
}
|
|
314
358
|
|
|
315
359
|
//#endregion
|
|
316
360
|
//#region src/cli/commands/bundle.ts
|
|
317
361
|
async function bundleWithConfig(configPath, cliOptions) {
|
|
318
|
-
const config = await
|
|
362
|
+
const config = await loadConfig(configPath);
|
|
319
363
|
if (!config) {
|
|
320
364
|
logger.error(`No configuration found at ${config}`);
|
|
321
365
|
process.exit(1);
|
|
322
366
|
}
|
|
323
|
-
const configList = arraify(config);
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}
|
|
367
|
+
const configList = require_src.arraify(config);
|
|
368
|
+
const operation = cliOptions.watch ? watchInner : bundleInner;
|
|
369
|
+
for (const config$1 of configList) await operation(config$1, cliOptions);
|
|
327
370
|
}
|
|
328
371
|
async function bundleWithCliOptions(cliOptions) {
|
|
329
372
|
if (cliOptions.output.dir) {
|
|
330
|
-
cliOptions.watch ?
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
373
|
+
const operation = cliOptions.watch ? watchInner : bundleInner;
|
|
374
|
+
await operation({}, cliOptions);
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
if (cliOptions.watch) {
|
|
378
|
+
logger.error("You must specify `output.dir` to use watch mode");
|
|
379
|
+
process.exit(1);
|
|
380
|
+
}
|
|
381
|
+
const build = await require_src.rolldown(cliOptions.input);
|
|
382
|
+
try {
|
|
383
|
+
const { output: outputs } = await build.generate(cliOptions.output);
|
|
384
|
+
if (outputs.length === 0) {
|
|
338
385
|
logger.error("No output generated");
|
|
339
386
|
process.exit(1);
|
|
340
|
-
} else {
|
|
341
|
-
logger.log(output[0].code);
|
|
342
387
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
388
|
+
for (const file of outputs) {
|
|
389
|
+
if (outputs.length > 1) logger.log(`\n${colors.cyan(colors.bold(`|→ ${file.fileName}:`))}\n`);
|
|
390
|
+
console.log(file.type === "asset" ? file.source : file.code);
|
|
391
|
+
}
|
|
392
|
+
} finally {
|
|
393
|
+
await build.close();
|
|
346
394
|
}
|
|
347
395
|
}
|
|
348
396
|
async function watchInner(options$1, cliOptions) {
|
|
349
|
-
const watcher = await watch({
|
|
397
|
+
const watcher = await require_src.watch({
|
|
350
398
|
...options$1,
|
|
351
|
-
...cliOptions.input
|
|
399
|
+
...cliOptions.input,
|
|
400
|
+
output: {
|
|
401
|
+
...options$1?.output,
|
|
402
|
+
...cliOptions.output
|
|
403
|
+
}
|
|
352
404
|
});
|
|
353
405
|
onExit((code) => {
|
|
354
|
-
|
|
406
|
+
Promise.resolve(watcher.close()).finally(() => {
|
|
355
407
|
process.exit(typeof code === "number" ? code : 0);
|
|
356
408
|
});
|
|
357
409
|
return true;
|
|
358
410
|
});
|
|
359
411
|
const changedFile = [];
|
|
360
412
|
watcher.on("change", (id, event) => {
|
|
361
|
-
if (event.event === "update")
|
|
362
|
-
changedFile.push(id);
|
|
363
|
-
}
|
|
413
|
+
if (event.event === "update") changedFile.push(id);
|
|
364
414
|
});
|
|
365
415
|
watcher.on("event", (event) => {
|
|
366
416
|
switch (event.code) {
|
|
367
417
|
case "BUNDLE_START":
|
|
368
|
-
logger.log(`Found ${bold(
|
|
418
|
+
if (changedFile.length > 0) logger.log(`Found ${colors.bold(changedFile.map(relativeId).join(", "))} changed, rebuilding...`);
|
|
369
419
|
changedFile.length = 0;
|
|
370
420
|
break;
|
|
371
421
|
case "BUNDLE_END":
|
|
372
|
-
logger.success(`Rebuilt ${bold(relativeId(event.output[0]))} in ${bold(ms(event.duration))}.`);
|
|
422
|
+
logger.success(`Rebuilt ${colors.bold(relativeId(event.output[0]))} in ${colors.bold(ms(event.duration))}.`);
|
|
423
|
+
break;
|
|
424
|
+
case "ERROR":
|
|
425
|
+
logger.error(event.error);
|
|
373
426
|
break;
|
|
374
427
|
default: break;
|
|
375
428
|
}
|
|
@@ -377,20 +430,24 @@ async function watchInner(options$1, cliOptions) {
|
|
|
377
430
|
logger.log(`Waiting for changes...`);
|
|
378
431
|
}
|
|
379
432
|
async function bundleInner(options$1, cliOptions) {
|
|
380
|
-
const startTime = performance.now();
|
|
381
|
-
const build = await rolldown({
|
|
433
|
+
const startTime = node_perf_hooks.performance.now();
|
|
434
|
+
const build = await require_src.rolldown({
|
|
382
435
|
...options$1,
|
|
383
436
|
...cliOptions.input
|
|
384
437
|
});
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
438
|
+
try {
|
|
439
|
+
const bundleOutput = await build.write({
|
|
440
|
+
...options$1?.output,
|
|
441
|
+
...cliOptions.output
|
|
442
|
+
});
|
|
443
|
+
const endTime = node_perf_hooks.performance.now();
|
|
444
|
+
printBundleOutputPretty(bundleOutput);
|
|
445
|
+
logger.log(``);
|
|
446
|
+
const duration = endTime - startTime;
|
|
447
|
+
logger.success(`Finished in ${colors.bold(ms(duration))}`);
|
|
448
|
+
} finally {
|
|
449
|
+
await build.close();
|
|
450
|
+
}
|
|
394
451
|
}
|
|
395
452
|
function printBundleOutputPretty(output) {
|
|
396
453
|
const outputEntries = collectOutputEntries(output.output);
|
|
@@ -408,14 +465,10 @@ function collectOutputLayoutAdjustmentSizes(entries) {
|
|
|
408
465
|
let longest = 0;
|
|
409
466
|
let biggestSize = 0;
|
|
410
467
|
for (const entry of entries) {
|
|
411
|
-
if (entry.fileName.length > longest)
|
|
412
|
-
|
|
413
|
-
}
|
|
414
|
-
if (entry.size > biggestSize) {
|
|
415
|
-
biggestSize = entry.size;
|
|
416
|
-
}
|
|
468
|
+
if (entry.fileName.length > longest) longest = entry.fileName.length;
|
|
469
|
+
if (entry.size > biggestSize) biggestSize = entry.size;
|
|
417
470
|
}
|
|
418
|
-
const sizePad =
|
|
471
|
+
const sizePad = displaySize(biggestSize).length;
|
|
419
472
|
return {
|
|
420
473
|
longest,
|
|
421
474
|
biggestSize,
|
|
@@ -427,7 +480,7 @@ const numberFormatter = new Intl.NumberFormat("en", {
|
|
|
427
480
|
minimumFractionDigits: 2
|
|
428
481
|
});
|
|
429
482
|
function displaySize(bytes) {
|
|
430
|
-
return `${numberFormatter.format(bytes /
|
|
483
|
+
return `${numberFormatter.format(bytes / 1e3)} kB`;
|
|
431
484
|
}
|
|
432
485
|
const CHUNK_GROUPS = [{
|
|
433
486
|
type: "asset",
|
|
@@ -435,34 +488,30 @@ const CHUNK_GROUPS = [{
|
|
|
435
488
|
}, {
|
|
436
489
|
type: "chunk",
|
|
437
490
|
color: "cyan"
|
|
438
|
-
}
|
|
491
|
+
}];
|
|
439
492
|
function printOutputEntries(entries, sizeAdjustment, distPath) {
|
|
440
493
|
for (const group of CHUNK_GROUPS) {
|
|
441
494
|
const filtered = entries.filter((e) => e.type === group.type);
|
|
442
|
-
if (!filtered.length)
|
|
443
|
-
continue;
|
|
444
|
-
}
|
|
495
|
+
if (!filtered.length) continue;
|
|
445
496
|
for (const entry of filtered.sort((a, z$4) => a.size - z$4.size)) {
|
|
446
|
-
let log = dim(withTrailingSlash(distPath));
|
|
447
|
-
log +=
|
|
448
|
-
log += dim(entry.type);
|
|
449
|
-
log += dim(` │ size: ${
|
|
497
|
+
let log = colors.dim(withTrailingSlash(distPath));
|
|
498
|
+
log += colors[group.color](entry.fileName.padEnd(sizeAdjustment.longest + 2));
|
|
499
|
+
log += colors.dim(entry.type);
|
|
500
|
+
log += colors.dim(` │ size: ${displaySize(entry.size).padStart(sizeAdjustment.sizePad)}`);
|
|
450
501
|
logger.log(log);
|
|
451
502
|
}
|
|
452
503
|
}
|
|
453
504
|
}
|
|
454
|
-
function withTrailingSlash(path$
|
|
455
|
-
if (path$
|
|
456
|
-
|
|
457
|
-
}
|
|
458
|
-
return path$1;
|
|
505
|
+
function withTrailingSlash(path$2) {
|
|
506
|
+
if (path$2[path$2.length - 1] !== "/") return `${path$2}/`;
|
|
507
|
+
return path$2;
|
|
459
508
|
}
|
|
460
509
|
function ms(duration) {
|
|
461
|
-
return duration <
|
|
510
|
+
return duration < 1e3 ? `${duration.toFixed(2)} ms` : `${(duration / 1e3).toFixed(2)} s`;
|
|
462
511
|
}
|
|
463
512
|
function relativeId(id) {
|
|
464
|
-
if (!
|
|
465
|
-
return
|
|
513
|
+
if (!node_path.default.isAbsolute(id)) return id;
|
|
514
|
+
return node_path.default.relative(node_path.default.resolve(), id);
|
|
466
515
|
}
|
|
467
516
|
|
|
468
517
|
//#endregion
|
|
@@ -501,16 +550,24 @@ const getDefaultOptions = (options$1) => typeof options$1 === "string" ? {
|
|
|
501
550
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/Refs.js
|
|
502
551
|
const getRefs = (options$1) => {
|
|
503
552
|
const _options = getDefaultOptions(options$1);
|
|
504
|
-
const currentPath = _options.name !== undefined ? [
|
|
553
|
+
const currentPath = _options.name !== undefined ? [
|
|
554
|
+
..._options.basePath,
|
|
555
|
+
_options.definitionPath,
|
|
556
|
+
_options.name
|
|
557
|
+
] : _options.basePath;
|
|
505
558
|
return {
|
|
506
559
|
..._options,
|
|
507
|
-
currentPath
|
|
560
|
+
currentPath,
|
|
508
561
|
propertyPath: undefined,
|
|
509
|
-
seen: new Map(
|
|
562
|
+
seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [def._def, {
|
|
510
563
|
def: def._def,
|
|
511
|
-
path: [
|
|
564
|
+
path: [
|
|
565
|
+
..._options.basePath,
|
|
566
|
+
_options.definitionPath,
|
|
567
|
+
name
|
|
568
|
+
],
|
|
512
569
|
jsonSchema: undefined
|
|
513
|
-
}
|
|
570
|
+
}]))
|
|
514
571
|
};
|
|
515
572
|
};
|
|
516
573
|
|
|
@@ -518,12 +575,10 @@ const getRefs = (options$1) => {
|
|
|
518
575
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/errorMessages.js
|
|
519
576
|
function addErrorMessage(res, key, errorMessage, refs) {
|
|
520
577
|
if (!refs?.errorMessages) return;
|
|
521
|
-
if (errorMessage) {
|
|
522
|
-
res.errorMessage
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
};
|
|
526
|
-
}
|
|
578
|
+
if (errorMessage) res.errorMessage = {
|
|
579
|
+
...res.errorMessage,
|
|
580
|
+
[key]: errorMessage
|
|
581
|
+
};
|
|
527
582
|
}
|
|
528
583
|
function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
|
|
529
584
|
res[key] = value;
|
|
@@ -539,19 +594,13 @@ function parseAnyDef() {
|
|
|
539
594
|
//#endregion
|
|
540
595
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/array.js
|
|
541
596
|
function parseArrayDef(def, refs) {
|
|
542
|
-
const res = {type: "array"};
|
|
543
|
-
if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
if (def.minLength) {
|
|
550
|
-
setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
|
|
551
|
-
}
|
|
552
|
-
if (def.maxLength) {
|
|
553
|
-
setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
|
|
554
|
-
}
|
|
597
|
+
const res = { type: "array" };
|
|
598
|
+
if (def.type?._def && def.type?._def?.typeName !== zod.ZodFirstPartyTypeKind.ZodAny) res.items = parseDef(def.type._def, {
|
|
599
|
+
...refs,
|
|
600
|
+
currentPath: [...refs.currentPath, "items"]
|
|
601
|
+
});
|
|
602
|
+
if (def.minLength) setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
|
|
603
|
+
if (def.maxLength) setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
|
|
555
604
|
if (def.exactLength) {
|
|
556
605
|
setResponseValueAndErrors(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
|
|
557
606
|
setResponseValueAndErrors(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
|
|
@@ -567,40 +616,26 @@ function parseBigintDef(def, refs) {
|
|
|
567
616
|
format: "int64"
|
|
568
617
|
};
|
|
569
618
|
if (!def.checks) return res;
|
|
570
|
-
for (const check of def.checks) {
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
} else {
|
|
591
|
-
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
592
|
-
}
|
|
593
|
-
} else {
|
|
594
|
-
if (!check.inclusive) {
|
|
595
|
-
res.exclusiveMaximum = true;
|
|
596
|
-
}
|
|
597
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
598
|
-
}
|
|
599
|
-
break;
|
|
600
|
-
case "multipleOf":
|
|
601
|
-
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
602
|
-
break;
|
|
603
|
-
}
|
|
619
|
+
for (const check of def.checks) switch (check.kind) {
|
|
620
|
+
case "min":
|
|
621
|
+
if (refs.target === "jsonSchema7") if (check.inclusive) setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
622
|
+
else setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
623
|
+
else {
|
|
624
|
+
if (!check.inclusive) res.exclusiveMinimum = true;
|
|
625
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
626
|
+
}
|
|
627
|
+
break;
|
|
628
|
+
case "max":
|
|
629
|
+
if (refs.target === "jsonSchema7") if (check.inclusive) setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
630
|
+
else setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
631
|
+
else {
|
|
632
|
+
if (!check.inclusive) res.exclusiveMaximum = true;
|
|
633
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
634
|
+
}
|
|
635
|
+
break;
|
|
636
|
+
case "multipleOf":
|
|
637
|
+
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
638
|
+
break;
|
|
604
639
|
}
|
|
605
640
|
return res;
|
|
606
641
|
}
|
|
@@ -608,7 +643,7 @@ function parseBigintDef(def, refs) {
|
|
|
608
643
|
//#endregion
|
|
609
644
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js
|
|
610
645
|
function parseBooleanDef() {
|
|
611
|
-
return {type: "boolean"};
|
|
646
|
+
return { type: "boolean" };
|
|
612
647
|
}
|
|
613
648
|
|
|
614
649
|
//#endregion
|
|
@@ -627,9 +662,7 @@ const parseCatchDef = (def, refs) => {
|
|
|
627
662
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/date.js
|
|
628
663
|
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
629
664
|
const strategy = overrideDateStrategy ?? refs.dateStrategy;
|
|
630
|
-
if (Array.isArray(strategy)) {
|
|
631
|
-
return {anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))};
|
|
632
|
-
}
|
|
665
|
+
if (Array.isArray(strategy)) return { anyOf: strategy.map((item, i) => parseDateDef(def, refs, item)) };
|
|
633
666
|
switch (strategy) {
|
|
634
667
|
case "string":
|
|
635
668
|
case "format:date-time": return {
|
|
@@ -648,18 +681,14 @@ const integerDateParser = (def, refs) => {
|
|
|
648
681
|
type: "integer",
|
|
649
682
|
format: "unix-time"
|
|
650
683
|
};
|
|
651
|
-
if (refs.target === "openApi3")
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
case "max":
|
|
660
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
661
|
-
break;
|
|
662
|
-
}
|
|
684
|
+
if (refs.target === "openApi3") return res;
|
|
685
|
+
for (const check of def.checks) switch (check.kind) {
|
|
686
|
+
case "min":
|
|
687
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
688
|
+
break;
|
|
689
|
+
case "max":
|
|
690
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
691
|
+
break;
|
|
663
692
|
}
|
|
664
693
|
return res;
|
|
665
694
|
};
|
|
@@ -691,33 +720,37 @@ function parseEnumDef(def) {
|
|
|
691
720
|
//#endregion
|
|
692
721
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js
|
|
693
722
|
const isJsonSchema7AllOfType = (type) => {
|
|
694
|
-
if ("type"in type && type.type === "string") return false;
|
|
695
|
-
return "allOf"in type;
|
|
723
|
+
if ("type" in type && type.type === "string") return false;
|
|
724
|
+
return "allOf" in type;
|
|
696
725
|
};
|
|
697
726
|
function parseIntersectionDef(def, refs) {
|
|
698
727
|
const allOf = [parseDef(def.left._def, {
|
|
699
728
|
...refs,
|
|
700
|
-
currentPath: [
|
|
729
|
+
currentPath: [
|
|
730
|
+
...refs.currentPath,
|
|
731
|
+
"allOf",
|
|
732
|
+
"0"
|
|
733
|
+
]
|
|
701
734
|
}), parseDef(def.right._def, {
|
|
702
735
|
...refs,
|
|
703
|
-
currentPath: [
|
|
704
|
-
|
|
705
|
-
|
|
736
|
+
currentPath: [
|
|
737
|
+
...refs.currentPath,
|
|
738
|
+
"allOf",
|
|
739
|
+
"1"
|
|
740
|
+
]
|
|
741
|
+
})].filter((x) => !!x);
|
|
742
|
+
let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? { unevaluatedProperties: false } : undefined;
|
|
706
743
|
const mergedAllOf = [];
|
|
707
744
|
allOf.forEach((schema$1) => {
|
|
708
745
|
if (isJsonSchema7AllOfType(schema$1)) {
|
|
709
746
|
mergedAllOf.push(...schema$1.allOf);
|
|
710
|
-
if (schema$1.unevaluatedProperties === undefined)
|
|
711
|
-
unevaluatedProperties = undefined;
|
|
712
|
-
}
|
|
747
|
+
if (schema$1.unevaluatedProperties === undefined) unevaluatedProperties = undefined;
|
|
713
748
|
} else {
|
|
714
749
|
let nestedSchema = schema$1;
|
|
715
|
-
if ("additionalProperties"in schema$1 && schema$1.additionalProperties === false) {
|
|
716
|
-
const { additionalProperties
|
|
750
|
+
if ("additionalProperties" in schema$1 && schema$1.additionalProperties === false) {
|
|
751
|
+
const { additionalProperties,...rest } = schema$1;
|
|
717
752
|
nestedSchema = rest;
|
|
718
|
-
} else
|
|
719
|
-
unevaluatedProperties = undefined;
|
|
720
|
-
}
|
|
753
|
+
} else unevaluatedProperties = undefined;
|
|
721
754
|
mergedAllOf.push(nestedSchema);
|
|
722
755
|
}
|
|
723
756
|
});
|
|
@@ -731,15 +764,11 @@ function parseIntersectionDef(def, refs) {
|
|
|
731
764
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js
|
|
732
765
|
function parseLiteralDef(def, refs) {
|
|
733
766
|
const parsedType = typeof def.value;
|
|
734
|
-
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
740
|
-
enum: [def.value]
|
|
741
|
-
};
|
|
742
|
-
}
|
|
767
|
+
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") return { type: Array.isArray(def.value) ? "array" : "object" };
|
|
768
|
+
if (refs.target === "openApi3") return {
|
|
769
|
+
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
770
|
+
enum: [def.value]
|
|
771
|
+
};
|
|
743
772
|
return {
|
|
744
773
|
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
745
774
|
const: def.value
|
|
@@ -755,9 +784,7 @@ const zodPatterns = {
|
|
|
755
784
|
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
756
785
|
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
757
786
|
emoji: () => {
|
|
758
|
-
if (emojiRegex === undefined) {
|
|
759
|
-
emojiRegex = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
|
|
760
|
-
}
|
|
787
|
+
if (emojiRegex === undefined) emojiRegex = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
|
|
761
788
|
return emojiRegex;
|
|
762
789
|
},
|
|
763
790
|
uuid: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,
|
|
@@ -767,170 +794,148 @@ const zodPatterns = {
|
|
|
767
794
|
nanoid: /^[a-zA-Z0-9_-]{21}$/
|
|
768
795
|
};
|
|
769
796
|
function parseStringDef(def, refs) {
|
|
770
|
-
const res = {type: "string"};
|
|
797
|
+
const res = { type: "string" };
|
|
771
798
|
function processPattern(value) {
|
|
772
799
|
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(value) : value;
|
|
773
800
|
}
|
|
774
|
-
if (def.checks) {
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
case "email":
|
|
784
|
-
|
|
785
|
-
case "format:email":
|
|
786
|
-
addFormat(res, "email", check.message, refs);
|
|
787
|
-
break;
|
|
788
|
-
case "format:idn-email":
|
|
789
|
-
addFormat(res, "idn-email", check.message, refs);
|
|
790
|
-
break;
|
|
791
|
-
case "pattern:zod":
|
|
792
|
-
addPattern(res, zodPatterns.email, check.message, refs);
|
|
793
|
-
break;
|
|
794
|
-
}
|
|
795
|
-
break;
|
|
796
|
-
case "url":
|
|
797
|
-
addFormat(res, "uri", check.message, refs);
|
|
798
|
-
break;
|
|
799
|
-
case "uuid":
|
|
800
|
-
addFormat(res, "uuid", check.message, refs);
|
|
801
|
-
break;
|
|
802
|
-
case "regex":
|
|
803
|
-
addPattern(res, check.regex, check.message, refs);
|
|
801
|
+
if (def.checks) for (const check of def.checks) switch (check.kind) {
|
|
802
|
+
case "min":
|
|
803
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
804
|
+
break;
|
|
805
|
+
case "max":
|
|
806
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
807
|
+
break;
|
|
808
|
+
case "email":
|
|
809
|
+
switch (refs.emailStrategy) {
|
|
810
|
+
case "format:email":
|
|
811
|
+
addFormat(res, "email", check.message, refs);
|
|
804
812
|
break;
|
|
805
|
-
case "
|
|
806
|
-
|
|
813
|
+
case "format:idn-email":
|
|
814
|
+
addFormat(res, "idn-email", check.message, refs);
|
|
807
815
|
break;
|
|
808
|
-
case "
|
|
809
|
-
addPattern(res, zodPatterns.
|
|
816
|
+
case "pattern:zod":
|
|
817
|
+
addPattern(res, zodPatterns.email, check.message, refs);
|
|
810
818
|
break;
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
819
|
+
}
|
|
820
|
+
break;
|
|
821
|
+
case "url":
|
|
822
|
+
addFormat(res, "uri", check.message, refs);
|
|
823
|
+
break;
|
|
824
|
+
case "uuid":
|
|
825
|
+
addFormat(res, "uuid", check.message, refs);
|
|
826
|
+
break;
|
|
827
|
+
case "regex":
|
|
828
|
+
addPattern(res, check.regex, check.message, refs);
|
|
829
|
+
break;
|
|
830
|
+
case "cuid":
|
|
831
|
+
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
832
|
+
break;
|
|
833
|
+
case "cuid2":
|
|
834
|
+
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
835
|
+
break;
|
|
836
|
+
case "startsWith":
|
|
837
|
+
addPattern(res, RegExp(`^${processPattern(check.value)}`), check.message, refs);
|
|
838
|
+
break;
|
|
839
|
+
case "endsWith":
|
|
840
|
+
addPattern(res, RegExp(`${processPattern(check.value)}$`), check.message, refs);
|
|
841
|
+
break;
|
|
842
|
+
case "datetime":
|
|
843
|
+
addFormat(res, "date-time", check.message, refs);
|
|
844
|
+
break;
|
|
845
|
+
case "date":
|
|
846
|
+
addFormat(res, "date", check.message, refs);
|
|
847
|
+
break;
|
|
848
|
+
case "time":
|
|
849
|
+
addFormat(res, "time", check.message, refs);
|
|
850
|
+
break;
|
|
851
|
+
case "duration":
|
|
852
|
+
addFormat(res, "duration", check.message, refs);
|
|
853
|
+
break;
|
|
854
|
+
case "length":
|
|
855
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
856
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
857
|
+
break;
|
|
858
|
+
case "includes": {
|
|
859
|
+
addPattern(res, RegExp(processPattern(check.value)), check.message, refs);
|
|
860
|
+
break;
|
|
861
|
+
}
|
|
862
|
+
case "ip": {
|
|
863
|
+
if (check.version !== "v6") addFormat(res, "ipv4", check.message, refs);
|
|
864
|
+
if (check.version !== "v4") addFormat(res, "ipv6", check.message, refs);
|
|
865
|
+
break;
|
|
866
|
+
}
|
|
867
|
+
case "emoji":
|
|
868
|
+
addPattern(res, zodPatterns.emoji, check.message, refs);
|
|
869
|
+
break;
|
|
870
|
+
case "ulid": {
|
|
871
|
+
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
872
|
+
break;
|
|
873
|
+
}
|
|
874
|
+
case "base64": {
|
|
875
|
+
switch (refs.base64Strategy) {
|
|
876
|
+
case "format:binary": {
|
|
877
|
+
addFormat(res, "binary", check.message, refs);
|
|
844
878
|
break;
|
|
845
879
|
}
|
|
846
|
-
case "
|
|
847
|
-
|
|
848
|
-
break;
|
|
849
|
-
case "ulid": {
|
|
850
|
-
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
880
|
+
case "contentEncoding:base64": {
|
|
881
|
+
setResponseValueAndErrors(res, "contentEncoding", "base64", check.message, refs);
|
|
851
882
|
break;
|
|
852
883
|
}
|
|
853
|
-
case "
|
|
854
|
-
|
|
855
|
-
case "format:binary": {
|
|
856
|
-
addFormat(res, "binary", check.message, refs);
|
|
857
|
-
break;
|
|
858
|
-
}
|
|
859
|
-
case "contentEncoding:base64": {
|
|
860
|
-
setResponseValueAndErrors(res, "contentEncoding", "base64", check.message, refs);
|
|
861
|
-
break;
|
|
862
|
-
}
|
|
863
|
-
case "pattern:zod": {
|
|
864
|
-
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
865
|
-
break;
|
|
866
|
-
}
|
|
867
|
-
}
|
|
884
|
+
case "pattern:zod": {
|
|
885
|
+
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
868
886
|
break;
|
|
869
887
|
}
|
|
870
|
-
case "nanoid": {
|
|
871
|
-
addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
872
|
-
}
|
|
873
|
-
case "toLowerCase":
|
|
874
|
-
case "toUpperCase":
|
|
875
|
-
case "trim": break;
|
|
876
|
-
default: ((_) => {})(check);
|
|
877
888
|
}
|
|
889
|
+
break;
|
|
878
890
|
}
|
|
891
|
+
case "nanoid": addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
892
|
+
case "toLowerCase":
|
|
893
|
+
case "toUpperCase":
|
|
894
|
+
case "trim": break;
|
|
895
|
+
default: ((_) => {})(check);
|
|
879
896
|
}
|
|
880
897
|
return res;
|
|
881
898
|
}
|
|
882
|
-
const escapeNonAlphaNumeric = (value) =>
|
|
899
|
+
const escapeNonAlphaNumeric = (value) => Array.from(value).map((c) => /[a-zA-Z0-9]/.test(c) ? c : `\\${c}`).join("");
|
|
883
900
|
const addFormat = (schema$1, value, message, refs) => {
|
|
884
901
|
if (schema$1.format || schema$1.anyOf?.some((x) => x.format)) {
|
|
885
|
-
if (!schema$1.anyOf)
|
|
886
|
-
schema$1.anyOf = [];
|
|
887
|
-
}
|
|
902
|
+
if (!schema$1.anyOf) schema$1.anyOf = [];
|
|
888
903
|
if (schema$1.format) {
|
|
889
904
|
schema$1.anyOf.push({
|
|
890
905
|
format: schema$1.format,
|
|
891
|
-
...schema$1.errorMessage && refs.errorMessages && {errorMessage: {format: schema$1.errorMessage.format}}
|
|
906
|
+
...schema$1.errorMessage && refs.errorMessages && { errorMessage: { format: schema$1.errorMessage.format } }
|
|
892
907
|
});
|
|
893
908
|
delete schema$1.format;
|
|
894
909
|
if (schema$1.errorMessage) {
|
|
895
910
|
delete schema$1.errorMessage.format;
|
|
896
|
-
if (
|
|
897
|
-
delete schema$1.errorMessage;
|
|
898
|
-
}
|
|
911
|
+
if (Object.keys(schema$1.errorMessage).length === 0) delete schema$1.errorMessage;
|
|
899
912
|
}
|
|
900
913
|
}
|
|
901
914
|
schema$1.anyOf.push({
|
|
902
915
|
format: value,
|
|
903
|
-
...message && refs.errorMessages && {errorMessage: {format: message}}
|
|
916
|
+
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
904
917
|
});
|
|
905
|
-
} else
|
|
906
|
-
setResponseValueAndErrors(schema$1, "format", value, message, refs);
|
|
907
|
-
}
|
|
918
|
+
} else setResponseValueAndErrors(schema$1, "format", value, message, refs);
|
|
908
919
|
};
|
|
909
920
|
const addPattern = (schema$1, regex, message, refs) => {
|
|
910
921
|
if (schema$1.pattern || schema$1.allOf?.some((x) => x.pattern)) {
|
|
911
|
-
if (!schema$1.allOf)
|
|
912
|
-
schema$1.allOf = [];
|
|
913
|
-
}
|
|
922
|
+
if (!schema$1.allOf) schema$1.allOf = [];
|
|
914
923
|
if (schema$1.pattern) {
|
|
915
924
|
schema$1.allOf.push({
|
|
916
925
|
pattern: schema$1.pattern,
|
|
917
|
-
...schema$1.errorMessage && refs.errorMessages && {errorMessage: {pattern: schema$1.errorMessage.pattern}}
|
|
926
|
+
...schema$1.errorMessage && refs.errorMessages && { errorMessage: { pattern: schema$1.errorMessage.pattern } }
|
|
918
927
|
});
|
|
919
928
|
delete schema$1.pattern;
|
|
920
929
|
if (schema$1.errorMessage) {
|
|
921
930
|
delete schema$1.errorMessage.pattern;
|
|
922
|
-
if (
|
|
923
|
-
delete schema$1.errorMessage;
|
|
924
|
-
}
|
|
931
|
+
if (Object.keys(schema$1.errorMessage).length === 0) delete schema$1.errorMessage;
|
|
925
932
|
}
|
|
926
933
|
}
|
|
927
934
|
schema$1.allOf.push({
|
|
928
935
|
pattern: processRegExp(regex, refs),
|
|
929
|
-
...message && refs.errorMessages && {errorMessage: {pattern: message}}
|
|
936
|
+
...message && refs.errorMessages && { errorMessage: { pattern: message } }
|
|
930
937
|
});
|
|
931
|
-
} else
|
|
932
|
-
setResponseValueAndErrors(schema$1, "pattern", processRegExp(regex, refs), message, refs);
|
|
933
|
-
}
|
|
938
|
+
} else setResponseValueAndErrors(schema$1, "pattern", processRegExp(regex, refs), message, refs);
|
|
934
939
|
};
|
|
935
940
|
const processRegExp = (regexOrFunction, refs) => {
|
|
936
941
|
const regex = typeof regexOrFunction === "function" ? regexOrFunction() : regexOrFunction;
|
|
@@ -961,9 +966,7 @@ const processRegExp = (regexOrFunction, refs) => {
|
|
|
961
966
|
} else if (source[i + 1] === "-" && source[i + 2]?.match(/[a-z]/)) {
|
|
962
967
|
pattern += source[i];
|
|
963
968
|
inCharRange = true;
|
|
964
|
-
} else {
|
|
965
|
-
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
966
|
-
}
|
|
969
|
+
} else pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
967
970
|
continue;
|
|
968
971
|
}
|
|
969
972
|
} else if (source[i].match(/[a-z]/)) {
|
|
@@ -985,13 +988,9 @@ const processRegExp = (regexOrFunction, refs) => {
|
|
|
985
988
|
continue;
|
|
986
989
|
}
|
|
987
990
|
pattern += source[i];
|
|
988
|
-
if (source[i] === "\\")
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
inCharGroup = false;
|
|
992
|
-
} else if (!inCharGroup && source[i] === "[") {
|
|
993
|
-
inCharGroup = true;
|
|
994
|
-
}
|
|
991
|
+
if (source[i] === "\\") isEscaped = true;
|
|
992
|
+
else if (inCharGroup && source[i] === "]") inCharGroup = false;
|
|
993
|
+
else if (!inCharGroup && source[i] === "[") inCharGroup = true;
|
|
995
994
|
}
|
|
996
995
|
try {
|
|
997
996
|
const regexTest = new RegExp(pattern);
|
|
@@ -1005,20 +1004,22 @@ const processRegExp = (regexOrFunction, refs) => {
|
|
|
1005
1004
|
//#endregion
|
|
1006
1005
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
1007
1006
|
function parseRecordDef(def, refs) {
|
|
1008
|
-
if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1007
|
+
if (refs.target === "openApi3" && def.keyType?._def.typeName === zod.ZodFirstPartyTypeKind.ZodEnum) return {
|
|
1008
|
+
type: "object",
|
|
1009
|
+
required: def.keyType._def.values,
|
|
1010
|
+
properties: def.keyType._def.values.reduce((acc, key) => ({
|
|
1011
|
+
...acc,
|
|
1012
|
+
[key]: parseDef(def.valueType._def, {
|
|
1013
|
+
...refs,
|
|
1014
|
+
currentPath: [
|
|
1015
|
+
...refs.currentPath,
|
|
1016
|
+
"properties",
|
|
1017
|
+
key
|
|
1018
|
+
]
|
|
1019
|
+
}) ?? {}
|
|
1020
|
+
}), {}),
|
|
1021
|
+
additionalProperties: false
|
|
1022
|
+
};
|
|
1022
1023
|
const schema$1 = {
|
|
1023
1024
|
type: "object",
|
|
1024
1025
|
additionalProperties: parseDef(def.valueType._def, {
|
|
@@ -1026,22 +1027,19 @@ function parseRecordDef(def, refs) {
|
|
|
1026
1027
|
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1027
1028
|
}) ?? {}
|
|
1028
1029
|
};
|
|
1029
|
-
if (refs.target === "openApi3")
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
if (def.keyType?._def.typeName === ZodFirstPartyTypeKind$1.ZodString && def.keyType._def.checks?.length) {
|
|
1033
|
-
const { type: type,...keyType } = parseStringDef(def.keyType._def, refs);
|
|
1030
|
+
if (refs.target === "openApi3") return schema$1;
|
|
1031
|
+
if (def.keyType?._def.typeName === zod.ZodFirstPartyTypeKind.ZodString && def.keyType._def.checks?.length) {
|
|
1032
|
+
const { type,...keyType } = parseStringDef(def.keyType._def, refs);
|
|
1034
1033
|
return {
|
|
1035
1034
|
...schema$1,
|
|
1036
1035
|
propertyNames: keyType
|
|
1037
1036
|
};
|
|
1038
|
-
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
const { type: type,...keyType } = parseBrandedDef(def.keyType._def, refs);
|
|
1037
|
+
} else if (def.keyType?._def.typeName === zod.ZodFirstPartyTypeKind.ZodEnum) return {
|
|
1038
|
+
...schema$1,
|
|
1039
|
+
propertyNames: { enum: def.keyType._def.values }
|
|
1040
|
+
};
|
|
1041
|
+
else if (def.keyType?._def.typeName === zod.ZodFirstPartyTypeKind.ZodBranded && def.keyType._def.type._def.typeName === zod.ZodFirstPartyTypeKind.ZodString && def.keyType._def.type._def.checks?.length) {
|
|
1042
|
+
const { type,...keyType } = parseBrandedDef(def.keyType._def, refs);
|
|
1045
1043
|
return {
|
|
1046
1044
|
...schema$1,
|
|
1047
1045
|
propertyNames: keyType
|
|
@@ -1053,16 +1051,24 @@ function parseRecordDef(def, refs) {
|
|
|
1053
1051
|
//#endregion
|
|
1054
1052
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/map.js
|
|
1055
1053
|
function parseMapDef(def, refs) {
|
|
1056
|
-
if (refs.mapStrategy === "record")
|
|
1057
|
-
return parseRecordDef(def, refs);
|
|
1058
|
-
}
|
|
1054
|
+
if (refs.mapStrategy === "record") return parseRecordDef(def, refs);
|
|
1059
1055
|
const keys = parseDef(def.keyType._def, {
|
|
1060
1056
|
...refs,
|
|
1061
|
-
currentPath: [
|
|
1057
|
+
currentPath: [
|
|
1058
|
+
...refs.currentPath,
|
|
1059
|
+
"items",
|
|
1060
|
+
"items",
|
|
1061
|
+
"0"
|
|
1062
|
+
]
|
|
1062
1063
|
}) || {};
|
|
1063
1064
|
const values = parseDef(def.valueType._def, {
|
|
1064
1065
|
...refs,
|
|
1065
|
-
currentPath: [
|
|
1066
|
+
currentPath: [
|
|
1067
|
+
...refs.currentPath,
|
|
1068
|
+
"items",
|
|
1069
|
+
"items",
|
|
1070
|
+
"1"
|
|
1071
|
+
]
|
|
1066
1072
|
}) || {};
|
|
1067
1073
|
return {
|
|
1068
1074
|
type: "array",
|
|
@@ -1080,7 +1086,7 @@ function parseMapDef(def, refs) {
|
|
|
1080
1086
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js
|
|
1081
1087
|
function parseNativeEnumDef(def) {
|
|
1082
1088
|
const object = def.values;
|
|
1083
|
-
const actualKeys =
|
|
1089
|
+
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
1084
1090
|
return typeof object[object[key]] !== "number";
|
|
1085
1091
|
});
|
|
1086
1092
|
const actualValues = actualKeys.map((key) => object[key]);
|
|
@@ -1094,7 +1100,7 @@ function parseNativeEnumDef(def) {
|
|
|
1094
1100
|
//#endregion
|
|
1095
1101
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/never.js
|
|
1096
1102
|
function parseNeverDef() {
|
|
1097
|
-
return {not: {}};
|
|
1103
|
+
return { not: {} };
|
|
1098
1104
|
}
|
|
1099
1105
|
|
|
1100
1106
|
//#endregion
|
|
@@ -1103,7 +1109,7 @@ function parseNullDef(refs) {
|
|
|
1103
1109
|
return refs.target === "openApi3" ? {
|
|
1104
1110
|
enum: ["null"],
|
|
1105
1111
|
nullable: true
|
|
1106
|
-
} : {type: "null"};
|
|
1112
|
+
} : { type: "null" };
|
|
1107
1113
|
}
|
|
1108
1114
|
|
|
1109
1115
|
//#endregion
|
|
@@ -1123,7 +1129,7 @@ function parseUnionDef(def, refs) {
|
|
|
1123
1129
|
const type = primitiveMappings[x._def.typeName];
|
|
1124
1130
|
return type && !types$1.includes(type) ? [...types$1, type] : types$1;
|
|
1125
1131
|
}, []);
|
|
1126
|
-
return {type: types.length > 1 ? types : types[0]};
|
|
1132
|
+
return { type: types.length > 1 ? types : types[0] };
|
|
1127
1133
|
} else if (options$1.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
1128
1134
|
const types = options$1.reduce((acc, x) => {
|
|
1129
1135
|
const type = typeof x._def.value;
|
|
@@ -1148,40 +1154,46 @@ function parseUnionDef(def, refs) {
|
|
|
1148
1154
|
}, [])
|
|
1149
1155
|
};
|
|
1150
1156
|
}
|
|
1151
|
-
} else if (options$1.every((x) => x._def.typeName === "ZodEnum")) {
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
};
|
|
1156
|
-
}
|
|
1157
|
+
} else if (options$1.every((x) => x._def.typeName === "ZodEnum")) return {
|
|
1158
|
+
type: "string",
|
|
1159
|
+
enum: options$1.reduce((acc, x) => [...acc, ...x._def.values.filter((x$1) => !acc.includes(x$1))], [])
|
|
1160
|
+
};
|
|
1157
1161
|
return asAnyOf(def, refs);
|
|
1158
1162
|
}
|
|
1159
1163
|
const asAnyOf = (def, refs) => {
|
|
1160
|
-
const anyOf = (
|
|
1164
|
+
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef(x._def, {
|
|
1161
1165
|
...refs,
|
|
1162
|
-
currentPath: [
|
|
1163
|
-
|
|
1164
|
-
|
|
1166
|
+
currentPath: [
|
|
1167
|
+
...refs.currentPath,
|
|
1168
|
+
"anyOf",
|
|
1169
|
+
`${i}`
|
|
1170
|
+
]
|
|
1171
|
+
})).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
|
|
1172
|
+
return anyOf.length ? { anyOf } : undefined;
|
|
1165
1173
|
};
|
|
1166
1174
|
|
|
1167
1175
|
//#endregion
|
|
1168
1176
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js
|
|
1169
1177
|
function parseNullableDef(def, refs) {
|
|
1170
|
-
if ([
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
+
if ([
|
|
1179
|
+
"ZodString",
|
|
1180
|
+
"ZodNumber",
|
|
1181
|
+
"ZodBigInt",
|
|
1182
|
+
"ZodBoolean",
|
|
1183
|
+
"ZodNull"
|
|
1184
|
+
].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
1185
|
+
if (refs.target === "openApi3") return {
|
|
1186
|
+
type: primitiveMappings[def.innerType._def.typeName],
|
|
1187
|
+
nullable: true
|
|
1188
|
+
};
|
|
1189
|
+
return { type: [primitiveMappings[def.innerType._def.typeName], "null"] };
|
|
1178
1190
|
}
|
|
1179
1191
|
if (refs.target === "openApi3") {
|
|
1180
1192
|
const base$1 = parseDef(def.innerType._def, {
|
|
1181
1193
|
...refs,
|
|
1182
1194
|
currentPath: [...refs.currentPath]
|
|
1183
1195
|
});
|
|
1184
|
-
if (base$1 && "$ref"in base$1) return {
|
|
1196
|
+
if (base$1 && "$ref" in base$1) return {
|
|
1185
1197
|
allOf: [base$1],
|
|
1186
1198
|
nullable: true
|
|
1187
1199
|
};
|
|
@@ -1192,54 +1204,44 @@ function parseNullableDef(def, refs) {
|
|
|
1192
1204
|
}
|
|
1193
1205
|
const base = parseDef(def.innerType._def, {
|
|
1194
1206
|
...refs,
|
|
1195
|
-
currentPath: [
|
|
1207
|
+
currentPath: [
|
|
1208
|
+
...refs.currentPath,
|
|
1209
|
+
"anyOf",
|
|
1210
|
+
"0"
|
|
1211
|
+
]
|
|
1196
1212
|
});
|
|
1197
|
-
return base && {anyOf: [base, {type: "null"}]};
|
|
1213
|
+
return base && { anyOf: [base, { type: "null" }] };
|
|
1198
1214
|
}
|
|
1199
1215
|
|
|
1200
1216
|
//#endregion
|
|
1201
1217
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/number.js
|
|
1202
1218
|
function parseNumberDef(def, refs) {
|
|
1203
|
-
const res = {type: "number"};
|
|
1219
|
+
const res = { type: "number" };
|
|
1204
1220
|
if (!def.checks) return res;
|
|
1205
|
-
for (const check of def.checks) {
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
} else {
|
|
1230
|
-
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
1231
|
-
}
|
|
1232
|
-
} else {
|
|
1233
|
-
if (!check.inclusive) {
|
|
1234
|
-
res.exclusiveMaximum = true;
|
|
1235
|
-
}
|
|
1236
|
-
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
1237
|
-
}
|
|
1238
|
-
break;
|
|
1239
|
-
case "multipleOf":
|
|
1240
|
-
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
1241
|
-
break;
|
|
1242
|
-
}
|
|
1221
|
+
for (const check of def.checks) switch (check.kind) {
|
|
1222
|
+
case "int":
|
|
1223
|
+
res.type = "integer";
|
|
1224
|
+
addErrorMessage(res, "type", check.message, refs);
|
|
1225
|
+
break;
|
|
1226
|
+
case "min":
|
|
1227
|
+
if (refs.target === "jsonSchema7") if (check.inclusive) setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
1228
|
+
else setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
1229
|
+
else {
|
|
1230
|
+
if (!check.inclusive) res.exclusiveMinimum = true;
|
|
1231
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
1232
|
+
}
|
|
1233
|
+
break;
|
|
1234
|
+
case "max":
|
|
1235
|
+
if (refs.target === "jsonSchema7") if (check.inclusive) setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
1236
|
+
else setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
1237
|
+
else {
|
|
1238
|
+
if (!check.inclusive) res.exclusiveMaximum = true;
|
|
1239
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
1240
|
+
}
|
|
1241
|
+
break;
|
|
1242
|
+
case "multipleOf":
|
|
1243
|
+
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
1244
|
+
break;
|
|
1243
1245
|
}
|
|
1244
1246
|
return res;
|
|
1245
1247
|
}
|
|
@@ -1247,27 +1249,32 @@ function parseNumberDef(def, refs) {
|
|
|
1247
1249
|
//#endregion
|
|
1248
1250
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/object.js
|
|
1249
1251
|
function decideAdditionalProperties(def, refs) {
|
|
1250
|
-
if (refs.removeAdditionalStrategy === "strict") {
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1259
|
-
}) ?? true;
|
|
1260
|
-
}
|
|
1252
|
+
if (refs.removeAdditionalStrategy === "strict") return def.catchall._def.typeName === "ZodNever" ? def.unknownKeys !== "strict" : parseDef(def.catchall._def, {
|
|
1253
|
+
...refs,
|
|
1254
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1255
|
+
}) ?? true;
|
|
1256
|
+
else return def.catchall._def.typeName === "ZodNever" ? def.unknownKeys === "passthrough" : parseDef(def.catchall._def, {
|
|
1257
|
+
...refs,
|
|
1258
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1259
|
+
}) ?? true;
|
|
1261
1260
|
}
|
|
1262
1261
|
function parseObjectDef(def, refs) {
|
|
1263
1262
|
const result = {
|
|
1264
1263
|
type: "object",
|
|
1265
|
-
...
|
|
1264
|
+
...Object.entries(def.shape()).reduce((acc, [propName, propDef]) => {
|
|
1266
1265
|
if (propDef === undefined || propDef._def === undefined) return acc;
|
|
1267
1266
|
const parsedDef = parseDef(propDef._def, {
|
|
1268
1267
|
...refs,
|
|
1269
|
-
currentPath: [
|
|
1270
|
-
|
|
1268
|
+
currentPath: [
|
|
1269
|
+
...refs.currentPath,
|
|
1270
|
+
"properties",
|
|
1271
|
+
propName
|
|
1272
|
+
],
|
|
1273
|
+
propertyPath: [
|
|
1274
|
+
...refs.currentPath,
|
|
1275
|
+
"properties",
|
|
1276
|
+
propName
|
|
1277
|
+
]
|
|
1271
1278
|
});
|
|
1272
1279
|
if (parsedDef === undefined) return acc;
|
|
1273
1280
|
return {
|
|
@@ -1290,33 +1297,40 @@ function parseObjectDef(def, refs) {
|
|
|
1290
1297
|
//#endregion
|
|
1291
1298
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js
|
|
1292
1299
|
const parseOptionalDef = (def, refs) => {
|
|
1293
|
-
if (refs.currentPath.toString() === refs.propertyPath?.toString())
|
|
1294
|
-
return parseDef(def.innerType._def, refs);
|
|
1295
|
-
}
|
|
1300
|
+
if (refs.currentPath.toString() === refs.propertyPath?.toString()) return parseDef(def.innerType._def, refs);
|
|
1296
1301
|
const innerSchema = parseDef(def.innerType._def, {
|
|
1297
1302
|
...refs,
|
|
1298
|
-
currentPath: [
|
|
1303
|
+
currentPath: [
|
|
1304
|
+
...refs.currentPath,
|
|
1305
|
+
"anyOf",
|
|
1306
|
+
"1"
|
|
1307
|
+
]
|
|
1299
1308
|
});
|
|
1300
|
-
return innerSchema ? {anyOf: [{not: {}}, innerSchema
|
|
1309
|
+
return innerSchema ? { anyOf: [{ not: {} }, innerSchema] } : {};
|
|
1301
1310
|
};
|
|
1302
1311
|
|
|
1303
1312
|
//#endregion
|
|
1304
1313
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js
|
|
1305
1314
|
const parsePipelineDef = (def, refs) => {
|
|
1306
|
-
if (refs.pipeStrategy === "input")
|
|
1307
|
-
|
|
1308
|
-
} else if (refs.pipeStrategy === "output") {
|
|
1309
|
-
return parseDef(def.out._def, refs);
|
|
1310
|
-
}
|
|
1315
|
+
if (refs.pipeStrategy === "input") return parseDef(def.in._def, refs);
|
|
1316
|
+
else if (refs.pipeStrategy === "output") return parseDef(def.out._def, refs);
|
|
1311
1317
|
const a = parseDef(def.in._def, {
|
|
1312
1318
|
...refs,
|
|
1313
|
-
currentPath: [
|
|
1319
|
+
currentPath: [
|
|
1320
|
+
...refs.currentPath,
|
|
1321
|
+
"allOf",
|
|
1322
|
+
"0"
|
|
1323
|
+
]
|
|
1314
1324
|
});
|
|
1315
1325
|
const b = parseDef(def.out._def, {
|
|
1316
1326
|
...refs,
|
|
1317
|
-
currentPath: [
|
|
1327
|
+
currentPath: [
|
|
1328
|
+
...refs.currentPath,
|
|
1329
|
+
"allOf",
|
|
1330
|
+
a ? "1" : "0"
|
|
1331
|
+
]
|
|
1318
1332
|
});
|
|
1319
|
-
return {allOf: [a, b].filter((x) => x !== undefined)};
|
|
1333
|
+
return { allOf: [a, b].filter((x) => x !== undefined) };
|
|
1320
1334
|
};
|
|
1321
1335
|
|
|
1322
1336
|
//#endregion
|
|
@@ -1337,48 +1351,49 @@ function parseSetDef(def, refs) {
|
|
|
1337
1351
|
uniqueItems: true,
|
|
1338
1352
|
items
|
|
1339
1353
|
};
|
|
1340
|
-
if (def.minSize)
|
|
1341
|
-
|
|
1342
|
-
}
|
|
1343
|
-
if (def.maxSize) {
|
|
1344
|
-
setResponseValueAndErrors(schema$1, "maxItems", def.maxSize.value, def.maxSize.message, refs);
|
|
1345
|
-
}
|
|
1354
|
+
if (def.minSize) setResponseValueAndErrors(schema$1, "minItems", def.minSize.value, def.minSize.message, refs);
|
|
1355
|
+
if (def.maxSize) setResponseValueAndErrors(schema$1, "maxItems", def.maxSize.value, def.maxSize.message, refs);
|
|
1346
1356
|
return schema$1;
|
|
1347
1357
|
}
|
|
1348
1358
|
|
|
1349
1359
|
//#endregion
|
|
1350
1360
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js
|
|
1351
1361
|
function parseTupleDef(def, refs) {
|
|
1352
|
-
if (def.rest) {
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1362
|
+
if (def.rest) return {
|
|
1363
|
+
type: "array",
|
|
1364
|
+
minItems: def.items.length,
|
|
1365
|
+
items: def.items.map((x, i) => parseDef(x._def, {
|
|
1366
|
+
...refs,
|
|
1367
|
+
currentPath: [
|
|
1368
|
+
...refs.currentPath,
|
|
1369
|
+
"items",
|
|
1370
|
+
`${i}`
|
|
1371
|
+
]
|
|
1372
|
+
})).reduce((acc, x) => x === undefined ? acc : [...acc, x], []),
|
|
1373
|
+
additionalItems: parseDef(def.rest._def, {
|
|
1374
|
+
...refs,
|
|
1375
|
+
currentPath: [...refs.currentPath, "additionalItems"]
|
|
1376
|
+
})
|
|
1377
|
+
};
|
|
1378
|
+
else return {
|
|
1379
|
+
type: "array",
|
|
1380
|
+
minItems: def.items.length,
|
|
1381
|
+
maxItems: def.items.length,
|
|
1382
|
+
items: def.items.map((x, i) => parseDef(x._def, {
|
|
1383
|
+
...refs,
|
|
1384
|
+
currentPath: [
|
|
1385
|
+
...refs.currentPath,
|
|
1386
|
+
"items",
|
|
1387
|
+
`${i}`
|
|
1388
|
+
]
|
|
1389
|
+
})).reduce((acc, x) => x === undefined ? acc : [...acc, x], [])
|
|
1390
|
+
};
|
|
1376
1391
|
}
|
|
1377
1392
|
|
|
1378
1393
|
//#endregion
|
|
1379
1394
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js
|
|
1380
1395
|
function parseUndefinedDef() {
|
|
1381
|
-
return {not: {}};
|
|
1396
|
+
return { not: {} };
|
|
1382
1397
|
}
|
|
1383
1398
|
|
|
1384
1399
|
//#endregion
|
|
@@ -1399,15 +1414,11 @@ function parseDef(def, refs, forceResolution = false) {
|
|
|
1399
1414
|
const seenItem = refs.seen.get(def);
|
|
1400
1415
|
if (refs.override) {
|
|
1401
1416
|
const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
|
|
1402
|
-
if (overrideResult !== ignoreOverride)
|
|
1403
|
-
return overrideResult;
|
|
1404
|
-
}
|
|
1417
|
+
if (overrideResult !== ignoreOverride) return overrideResult;
|
|
1405
1418
|
}
|
|
1406
1419
|
if (seenItem && !forceResolution) {
|
|
1407
1420
|
const seenSchema = get$ref(seenItem, refs);
|
|
1408
|
-
if (seenSchema !== undefined)
|
|
1409
|
-
return seenSchema;
|
|
1410
|
-
}
|
|
1421
|
+
if (seenSchema !== undefined) return seenSchema;
|
|
1411
1422
|
}
|
|
1412
1423
|
const newItem = {
|
|
1413
1424
|
def,
|
|
@@ -1416,16 +1427,14 @@ function parseDef(def, refs, forceResolution = false) {
|
|
|
1416
1427
|
};
|
|
1417
1428
|
refs.seen.set(def, newItem);
|
|
1418
1429
|
const jsonSchema = selectParser(def, def.typeName, refs);
|
|
1419
|
-
if (jsonSchema)
|
|
1420
|
-
addMeta(def, refs, jsonSchema);
|
|
1421
|
-
}
|
|
1430
|
+
if (jsonSchema) addMeta(def, refs, jsonSchema);
|
|
1422
1431
|
newItem.jsonSchema = jsonSchema;
|
|
1423
1432
|
return jsonSchema;
|
|
1424
1433
|
}
|
|
1425
1434
|
const get$ref = (item, refs) => {
|
|
1426
1435
|
switch (refs.$refStrategy) {
|
|
1427
|
-
case "root": return {$ref: item.path.join("/")};
|
|
1428
|
-
case "relative": return {$ref: getRelativePath(refs.currentPath, item.path)};
|
|
1436
|
+
case "root": return { $ref: item.path.join("/") };
|
|
1437
|
+
case "relative": return { $ref: getRelativePath(refs.currentPath, item.path) };
|
|
1429
1438
|
case "none":
|
|
1430
1439
|
case "seen": {
|
|
1431
1440
|
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
@@ -1438,58 +1447,54 @@ const get$ref = (item, refs) => {
|
|
|
1438
1447
|
};
|
|
1439
1448
|
const getRelativePath = (pathA, pathB) => {
|
|
1440
1449
|
let i = 0;
|
|
1441
|
-
for (; i < pathA.length && i < pathB.length; i++)
|
|
1442
|
-
if (pathA[i] !== pathB[i]) break;
|
|
1443
|
-
}
|
|
1450
|
+
for (; i < pathA.length && i < pathB.length; i++) if (pathA[i] !== pathB[i]) break;
|
|
1444
1451
|
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
1445
1452
|
};
|
|
1446
1453
|
const selectParser = (def, typeName, refs) => {
|
|
1447
1454
|
switch (typeName) {
|
|
1448
|
-
case ZodFirstPartyTypeKind.ZodString: return parseStringDef(def, refs);
|
|
1449
|
-
case ZodFirstPartyTypeKind.ZodNumber: return parseNumberDef(def, refs);
|
|
1450
|
-
case ZodFirstPartyTypeKind.ZodObject: return parseObjectDef(def, refs);
|
|
1451
|
-
case ZodFirstPartyTypeKind.ZodBigInt: return parseBigintDef(def, refs);
|
|
1452
|
-
case ZodFirstPartyTypeKind.ZodBoolean: return parseBooleanDef();
|
|
1453
|
-
case ZodFirstPartyTypeKind.ZodDate: return parseDateDef(def, refs);
|
|
1454
|
-
case ZodFirstPartyTypeKind.ZodUndefined: return parseUndefinedDef();
|
|
1455
|
-
case ZodFirstPartyTypeKind.ZodNull: return parseNullDef(refs);
|
|
1456
|
-
case ZodFirstPartyTypeKind.ZodArray: return parseArrayDef(def, refs);
|
|
1457
|
-
case ZodFirstPartyTypeKind.ZodUnion:
|
|
1458
|
-
case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: return parseUnionDef(def, refs);
|
|
1459
|
-
case ZodFirstPartyTypeKind.ZodIntersection: return parseIntersectionDef(def, refs);
|
|
1460
|
-
case ZodFirstPartyTypeKind.ZodTuple: return parseTupleDef(def, refs);
|
|
1461
|
-
case ZodFirstPartyTypeKind.ZodRecord: return parseRecordDef(def, refs);
|
|
1462
|
-
case ZodFirstPartyTypeKind.ZodLiteral: return parseLiteralDef(def, refs);
|
|
1463
|
-
case ZodFirstPartyTypeKind.ZodEnum: return parseEnumDef(def);
|
|
1464
|
-
case ZodFirstPartyTypeKind.ZodNativeEnum: return parseNativeEnumDef(def);
|
|
1465
|
-
case ZodFirstPartyTypeKind.ZodNullable: return parseNullableDef(def, refs);
|
|
1466
|
-
case ZodFirstPartyTypeKind.ZodOptional: return parseOptionalDef(def, refs);
|
|
1467
|
-
case ZodFirstPartyTypeKind.ZodMap: return parseMapDef(def, refs);
|
|
1468
|
-
case ZodFirstPartyTypeKind.ZodSet: return parseSetDef(def, refs);
|
|
1469
|
-
case ZodFirstPartyTypeKind.ZodLazy: return parseDef(
|
|
1470
|
-
case ZodFirstPartyTypeKind.ZodPromise: return parsePromiseDef(def, refs);
|
|
1471
|
-
case ZodFirstPartyTypeKind.ZodNaN:
|
|
1472
|
-
case ZodFirstPartyTypeKind.ZodNever: return parseNeverDef();
|
|
1473
|
-
case ZodFirstPartyTypeKind.ZodEffects: return parseEffectsDef(def, refs);
|
|
1474
|
-
case ZodFirstPartyTypeKind.ZodAny: return parseAnyDef();
|
|
1475
|
-
case ZodFirstPartyTypeKind.ZodUnknown: return parseUnknownDef();
|
|
1476
|
-
case ZodFirstPartyTypeKind.ZodDefault: return parseDefaultDef(def, refs);
|
|
1477
|
-
case ZodFirstPartyTypeKind.ZodBranded: return parseBrandedDef(def, refs);
|
|
1478
|
-
case ZodFirstPartyTypeKind.ZodReadonly: return parseReadonlyDef(def, refs);
|
|
1479
|
-
case ZodFirstPartyTypeKind.ZodCatch: return parseCatchDef(def, refs);
|
|
1480
|
-
case ZodFirstPartyTypeKind.ZodPipeline: return parsePipelineDef(def, refs);
|
|
1481
|
-
case ZodFirstPartyTypeKind.ZodFunction:
|
|
1482
|
-
case ZodFirstPartyTypeKind.ZodVoid:
|
|
1483
|
-
case ZodFirstPartyTypeKind.ZodSymbol: return undefined;
|
|
1455
|
+
case zod.ZodFirstPartyTypeKind.ZodString: return parseStringDef(def, refs);
|
|
1456
|
+
case zod.ZodFirstPartyTypeKind.ZodNumber: return parseNumberDef(def, refs);
|
|
1457
|
+
case zod.ZodFirstPartyTypeKind.ZodObject: return parseObjectDef(def, refs);
|
|
1458
|
+
case zod.ZodFirstPartyTypeKind.ZodBigInt: return parseBigintDef(def, refs);
|
|
1459
|
+
case zod.ZodFirstPartyTypeKind.ZodBoolean: return parseBooleanDef();
|
|
1460
|
+
case zod.ZodFirstPartyTypeKind.ZodDate: return parseDateDef(def, refs);
|
|
1461
|
+
case zod.ZodFirstPartyTypeKind.ZodUndefined: return parseUndefinedDef();
|
|
1462
|
+
case zod.ZodFirstPartyTypeKind.ZodNull: return parseNullDef(refs);
|
|
1463
|
+
case zod.ZodFirstPartyTypeKind.ZodArray: return parseArrayDef(def, refs);
|
|
1464
|
+
case zod.ZodFirstPartyTypeKind.ZodUnion:
|
|
1465
|
+
case zod.ZodFirstPartyTypeKind.ZodDiscriminatedUnion: return parseUnionDef(def, refs);
|
|
1466
|
+
case zod.ZodFirstPartyTypeKind.ZodIntersection: return parseIntersectionDef(def, refs);
|
|
1467
|
+
case zod.ZodFirstPartyTypeKind.ZodTuple: return parseTupleDef(def, refs);
|
|
1468
|
+
case zod.ZodFirstPartyTypeKind.ZodRecord: return parseRecordDef(def, refs);
|
|
1469
|
+
case zod.ZodFirstPartyTypeKind.ZodLiteral: return parseLiteralDef(def, refs);
|
|
1470
|
+
case zod.ZodFirstPartyTypeKind.ZodEnum: return parseEnumDef(def);
|
|
1471
|
+
case zod.ZodFirstPartyTypeKind.ZodNativeEnum: return parseNativeEnumDef(def);
|
|
1472
|
+
case zod.ZodFirstPartyTypeKind.ZodNullable: return parseNullableDef(def, refs);
|
|
1473
|
+
case zod.ZodFirstPartyTypeKind.ZodOptional: return parseOptionalDef(def, refs);
|
|
1474
|
+
case zod.ZodFirstPartyTypeKind.ZodMap: return parseMapDef(def, refs);
|
|
1475
|
+
case zod.ZodFirstPartyTypeKind.ZodSet: return parseSetDef(def, refs);
|
|
1476
|
+
case zod.ZodFirstPartyTypeKind.ZodLazy: return parseDef(def.getter()._def, refs);
|
|
1477
|
+
case zod.ZodFirstPartyTypeKind.ZodPromise: return parsePromiseDef(def, refs);
|
|
1478
|
+
case zod.ZodFirstPartyTypeKind.ZodNaN:
|
|
1479
|
+
case zod.ZodFirstPartyTypeKind.ZodNever: return parseNeverDef();
|
|
1480
|
+
case zod.ZodFirstPartyTypeKind.ZodEffects: return parseEffectsDef(def, refs);
|
|
1481
|
+
case zod.ZodFirstPartyTypeKind.ZodAny: return parseAnyDef();
|
|
1482
|
+
case zod.ZodFirstPartyTypeKind.ZodUnknown: return parseUnknownDef();
|
|
1483
|
+
case zod.ZodFirstPartyTypeKind.ZodDefault: return parseDefaultDef(def, refs);
|
|
1484
|
+
case zod.ZodFirstPartyTypeKind.ZodBranded: return parseBrandedDef(def, refs);
|
|
1485
|
+
case zod.ZodFirstPartyTypeKind.ZodReadonly: return parseReadonlyDef(def, refs);
|
|
1486
|
+
case zod.ZodFirstPartyTypeKind.ZodCatch: return parseCatchDef(def, refs);
|
|
1487
|
+
case zod.ZodFirstPartyTypeKind.ZodPipeline: return parsePipelineDef(def, refs);
|
|
1488
|
+
case zod.ZodFirstPartyTypeKind.ZodFunction:
|
|
1489
|
+
case zod.ZodFirstPartyTypeKind.ZodVoid:
|
|
1490
|
+
case zod.ZodFirstPartyTypeKind.ZodSymbol: return undefined;
|
|
1484
1491
|
default: return ((_) => undefined)(typeName);
|
|
1485
1492
|
}
|
|
1486
1493
|
};
|
|
1487
1494
|
const addMeta = (def, refs, jsonSchema) => {
|
|
1488
1495
|
if (def.description) {
|
|
1489
1496
|
jsonSchema.description = def.description;
|
|
1490
|
-
if (refs.markdownDescription)
|
|
1491
|
-
jsonSchema.markdownDescription = def.description;
|
|
1492
|
-
}
|
|
1497
|
+
if (refs.markdownDescription) jsonSchema.markdownDescription = def.description;
|
|
1493
1498
|
}
|
|
1494
1499
|
return jsonSchema;
|
|
1495
1500
|
};
|
|
@@ -1498,119 +1503,130 @@ const addMeta = (def, refs, jsonSchema) => {
|
|
|
1498
1503
|
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.5_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js
|
|
1499
1504
|
const zodToJsonSchema = (schema$1, options$1) => {
|
|
1500
1505
|
const refs = getRefs(options$1);
|
|
1501
|
-
const definitions = typeof options$1 === "object" && options$1.definitions ?
|
|
1506
|
+
const definitions = typeof options$1 === "object" && options$1.definitions ? Object.entries(options$1.definitions).reduce((acc, [name$1, schema$2]) => ({
|
|
1502
1507
|
...acc,
|
|
1503
1508
|
[name$1]: parseDef(schema$2._def, {
|
|
1504
1509
|
...refs,
|
|
1505
|
-
currentPath: [
|
|
1510
|
+
currentPath: [
|
|
1511
|
+
...refs.basePath,
|
|
1512
|
+
refs.definitionPath,
|
|
1513
|
+
name$1
|
|
1514
|
+
]
|
|
1506
1515
|
}, true) ?? {}
|
|
1507
1516
|
}), {}) : undefined;
|
|
1508
1517
|
const name = typeof options$1 === "string" ? options$1 : options$1?.nameStrategy === "title" ? undefined : options$1?.name;
|
|
1509
1518
|
const main$1 = parseDef(schema$1._def, name === undefined ? refs : {
|
|
1510
1519
|
...refs,
|
|
1511
|
-
currentPath: [
|
|
1520
|
+
currentPath: [
|
|
1521
|
+
...refs.basePath,
|
|
1522
|
+
refs.definitionPath,
|
|
1523
|
+
name
|
|
1524
|
+
]
|
|
1512
1525
|
}, false) ?? {};
|
|
1513
1526
|
const title = typeof options$1 === "object" && options$1.name !== undefined && options$1.nameStrategy === "title" ? options$1.name : undefined;
|
|
1514
|
-
if (title !== undefined)
|
|
1515
|
-
main$1.title = title;
|
|
1516
|
-
}
|
|
1527
|
+
if (title !== undefined) main$1.title = title;
|
|
1517
1528
|
const combined = name === undefined ? definitions ? {
|
|
1518
1529
|
...main$1,
|
|
1519
1530
|
[refs.definitionPath]: definitions
|
|
1520
1531
|
} : main$1 : {
|
|
1521
|
-
$ref: [
|
|
1532
|
+
$ref: [
|
|
1533
|
+
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
1534
|
+
refs.definitionPath,
|
|
1535
|
+
name
|
|
1536
|
+
].join("/"),
|
|
1522
1537
|
[refs.definitionPath]: {
|
|
1523
1538
|
...definitions,
|
|
1524
1539
|
[name]: main$1
|
|
1525
1540
|
}
|
|
1526
1541
|
};
|
|
1527
|
-
if (refs.target === "jsonSchema7")
|
|
1528
|
-
|
|
1529
|
-
} else if (refs.target === "jsonSchema2019-09") {
|
|
1530
|
-
combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
|
|
1531
|
-
}
|
|
1542
|
+
if (refs.target === "jsonSchema7") combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
1543
|
+
else if (refs.target === "jsonSchema2019-09") combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
|
|
1532
1544
|
return combined;
|
|
1533
1545
|
};
|
|
1534
1546
|
|
|
1535
1547
|
//#endregion
|
|
1536
1548
|
//#region src/utils/zod-ext.ts
|
|
1537
|
-
const stringOrRegExp = () =>
|
|
1538
|
-
const optionalStringArray = () =>
|
|
1549
|
+
const stringOrRegExp = () => zod.z.string().or(zod.z.instanceof(RegExp));
|
|
1550
|
+
const optionalStringArray = () => zod.z.string().array().optional();
|
|
1539
1551
|
const returnTrue = () => true;
|
|
1540
|
-
const phantom = () => z
|
|
1552
|
+
const phantom = () => zod.z.custom(returnTrue);
|
|
1541
1553
|
const voidNullableWith = (t) => {
|
|
1542
|
-
return
|
|
1554
|
+
return voidNullable().or(t);
|
|
1543
1555
|
};
|
|
1544
1556
|
const voidNullable = () => {
|
|
1545
|
-
return
|
|
1557
|
+
return zod.z.void().or(zod.z.null()).or(zod.z.undefined());
|
|
1546
1558
|
};
|
|
1547
1559
|
|
|
1548
1560
|
//#endregion
|
|
1549
|
-
//#region src/options/input-options.ts
|
|
1550
|
-
const inputOptionSchema =
|
|
1551
|
-
const externalSchema =
|
|
1552
|
-
const moduleTypesSchema = z
|
|
1553
|
-
const jsxOptionsSchema = z
|
|
1554
|
-
mode:
|
|
1555
|
-
factory:
|
|
1556
|
-
fragment:
|
|
1557
|
-
importSource:
|
|
1558
|
-
jsxImportSource:
|
|
1559
|
-
refresh:
|
|
1560
|
-
development:
|
|
1561
|
+
//#region src/options/input-options-schema.ts
|
|
1562
|
+
const inputOptionSchema = zod.z.string().or(zod.z.string().array()).or(zod.z.record(zod.z.string()));
|
|
1563
|
+
const externalSchema = stringOrRegExp().or(stringOrRegExp().array()).or(zod.z.function().args(zod.z.string(), zod.z.string().optional(), zod.z.boolean()).returns(voidNullableWith(zod.z.boolean())));
|
|
1564
|
+
const moduleTypesSchema = zod.z.record(zod.z.literal("js").or(zod.z.literal("jsx")).or(zod.z.literal("ts")).or(zod.z.literal("tsx")).or(zod.z.literal("json")).or(zod.z.literal("text")).or(zod.z.literal("base64")).or(zod.z.literal("dataurl")).or(zod.z.literal("binary")).or(zod.z.literal("empty")).or(zod.z.literal("css")));
|
|
1565
|
+
const jsxOptionsSchema = zod.z.strictObject({
|
|
1566
|
+
mode: zod.z.literal("classic").or(zod.z.literal("automatic")).describe("Jsx transformation mode").optional(),
|
|
1567
|
+
factory: zod.z.string().describe("Jsx element transformation").optional(),
|
|
1568
|
+
fragment: zod.z.string().describe("Jsx fragment transformation").optional(),
|
|
1569
|
+
importSource: zod.z.string().describe("Import the factory of element and fragment if mode is classic").optional(),
|
|
1570
|
+
jsxImportSource: zod.z.string().describe("Import the factory of element and fragment if mode is automatic").optional(),
|
|
1571
|
+
refresh: zod.z.boolean().describe("React refresh transformation").optional(),
|
|
1572
|
+
development: zod.z.boolean().describe("Development specific information").optional()
|
|
1561
1573
|
});
|
|
1562
|
-
const stringOrRegExpSchema =
|
|
1563
|
-
const watchOptionsSchema = z
|
|
1564
|
-
skipWrite:
|
|
1565
|
-
notify:
|
|
1566
|
-
pollInterval:
|
|
1567
|
-
compareContents:
|
|
1568
|
-
})
|
|
1574
|
+
const stringOrRegExpSchema = stringOrRegExp().or(stringOrRegExp().array());
|
|
1575
|
+
const watchOptionsSchema = zod.z.strictObject({
|
|
1576
|
+
skipWrite: zod.z.boolean().describe("Skip the bundle.write() step").optional(),
|
|
1577
|
+
notify: zod.z.strictObject({
|
|
1578
|
+
pollInterval: zod.z.number().optional(),
|
|
1579
|
+
compareContents: zod.z.boolean().optional()
|
|
1580
|
+
}).describe("Notify options").optional(),
|
|
1569
1581
|
include: stringOrRegExpSchema.optional(),
|
|
1570
1582
|
exclude: stringOrRegExpSchema.optional(),
|
|
1571
|
-
chokidar:
|
|
1583
|
+
chokidar: zod.z.any().optional()
|
|
1572
1584
|
});
|
|
1573
|
-
const
|
|
1585
|
+
const checksOptionsSchema = zod.z.strictObject({ circularDependency: zod.z.boolean().describe("Wether to emit warnings when detecting circular dependencies").optional() });
|
|
1586
|
+
const inputOptionsSchema = zod.z.strictObject({
|
|
1574
1587
|
input: inputOptionSchema.optional(),
|
|
1575
|
-
plugins:
|
|
1588
|
+
plugins: phantom().optional(),
|
|
1576
1589
|
external: externalSchema.optional(),
|
|
1577
|
-
resolve:
|
|
1578
|
-
alias:
|
|
1579
|
-
aliasFields:
|
|
1590
|
+
resolve: zod.z.strictObject({
|
|
1591
|
+
alias: zod.z.record(zod.z.array(zod.z.string()).or(zod.z.string())).optional(),
|
|
1592
|
+
aliasFields: zod.z.array(zod.z.array(zod.z.string())).optional(),
|
|
1580
1593
|
conditionNames: optionalStringArray(),
|
|
1581
|
-
extensionAlias:
|
|
1582
|
-
exportsFields:
|
|
1594
|
+
extensionAlias: zod.z.record(zod.z.string(), zod.z.array(zod.z.string())).optional(),
|
|
1595
|
+
exportsFields: zod.z.array(zod.z.array(zod.z.string())).optional(),
|
|
1583
1596
|
extensions: optionalStringArray(),
|
|
1584
1597
|
mainFields: optionalStringArray(),
|
|
1585
1598
|
mainFiles: optionalStringArray(),
|
|
1586
1599
|
modules: optionalStringArray(),
|
|
1587
|
-
symlinks:
|
|
1588
|
-
tsconfigFilename:
|
|
1589
|
-
})
|
|
1590
|
-
cwd:
|
|
1591
|
-
platform:
|
|
1592
|
-
shimMissingExports:
|
|
1593
|
-
treeshake:
|
|
1594
|
-
logLevel:
|
|
1595
|
-
onLog:
|
|
1596
|
-
onwarn:
|
|
1597
|
-
moduleTypes:
|
|
1598
|
-
experimental:
|
|
1599
|
-
enableComposingJsPlugins:
|
|
1600
|
-
strictExecutionOrder:
|
|
1601
|
-
disableLiveBindings:
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1600
|
+
symlinks: zod.z.boolean().optional(),
|
|
1601
|
+
tsconfigFilename: zod.z.string().optional()
|
|
1602
|
+
}).optional(),
|
|
1603
|
+
cwd: zod.z.string().describe("Current working directory").optional(),
|
|
1604
|
+
platform: zod.z.literal("node").or(zod.z.literal("browser")).or(zod.z.literal("neutral")).describe(`Platform for which the code should be generated (node, ${colors.underline("browser")}, neutral)`).optional(),
|
|
1605
|
+
shimMissingExports: zod.z.boolean().describe(`Create shim variables for missing exports`).optional(),
|
|
1606
|
+
treeshake: require_src.TreeshakingOptionsSchema.optional(),
|
|
1607
|
+
logLevel: require_src.LogLevelOptionSchema.describe(`Log level (${colors.dim("silent")}, ${colors.underline(colors.gray("info"))}, debug, ${colors.yellow("warn")})`).optional(),
|
|
1608
|
+
onLog: zod.z.function().args(require_src.LogLevelSchema, require_src.RollupLogSchema, zod.z.function().args(require_src.LogLevelWithErrorSchema, require_src.RollupLogWithStringSchema)).optional(),
|
|
1609
|
+
onwarn: zod.z.function().args(require_src.RollupLogSchema, zod.z.function().args(require_src.RollupLogWithStringSchema.or(zod.z.function().returns(require_src.RollupLogWithStringSchema)))).optional(),
|
|
1610
|
+
moduleTypes: moduleTypesSchema.describe("Module types for customized extensions").optional(),
|
|
1611
|
+
experimental: zod.z.strictObject({
|
|
1612
|
+
enableComposingJsPlugins: zod.z.boolean().optional(),
|
|
1613
|
+
strictExecutionOrder: zod.z.boolean().optional(),
|
|
1614
|
+
disableLiveBindings: zod.z.boolean().optional(),
|
|
1615
|
+
resolveNewUrlToAsset: zod.z.boolean().optional()
|
|
1616
|
+
}).optional(),
|
|
1617
|
+
define: zod.z.record(zod.z.string()).describe("Define global variables").optional(),
|
|
1618
|
+
inject: zod.z.record(zod.z.string().or(zod.z.tuple([zod.z.string(), zod.z.string()]))).optional(),
|
|
1619
|
+
profilerNames: zod.z.boolean().optional(),
|
|
1606
1620
|
jsx: jsxOptionsSchema.optional(),
|
|
1607
|
-
watch:
|
|
1621
|
+
watch: watchOptionsSchema.or(zod.z.literal(false)).optional(),
|
|
1622
|
+
dropLabels: zod.z.array(zod.z.string()).describe("Remove labeled statements with these label names").optional(),
|
|
1623
|
+
checks: checksOptionsSchema.optional()
|
|
1608
1624
|
});
|
|
1609
|
-
const inputCliOptionsSchema =
|
|
1610
|
-
external:
|
|
1611
|
-
inject:
|
|
1612
|
-
treeshake:
|
|
1613
|
-
})
|
|
1625
|
+
const inputCliOptionsSchema = inputOptionsSchema.extend({
|
|
1626
|
+
external: zod.z.array(zod.z.string()).describe("Comma-separated list of module ids to exclude from the bundle `<module-id>,...`").optional(),
|
|
1627
|
+
inject: zod.z.record(zod.z.string()).describe("Inject import statements on demand").optional(),
|
|
1628
|
+
treeshake: zod.z.boolean().describe("enable treeshaking").default(true).optional()
|
|
1629
|
+
}).omit({
|
|
1614
1630
|
input: true,
|
|
1615
1631
|
plugins: true,
|
|
1616
1632
|
onwarn: true,
|
|
@@ -1622,70 +1638,76 @@ const inputCliOptionsSchema = (inputOptionsSchema.extend({
|
|
|
1622
1638
|
});
|
|
1623
1639
|
|
|
1624
1640
|
//#endregion
|
|
1625
|
-
//#region src/options/output-options.ts
|
|
1626
|
-
const ModuleFormatSchema =
|
|
1627
|
-
const addonFunctionSchema =
|
|
1628
|
-
const chunkFileNamesFunctionSchema =
|
|
1629
|
-
const
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
assetFileNames:
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1641
|
+
//#region src/options/output-options-schema.ts
|
|
1642
|
+
const ModuleFormatSchema = zod.z.literal("es").or(zod.z.literal("cjs")).or(zod.z.literal("esm")).or(zod.z.literal("module")).or(zod.z.literal("commonjs")).or(zod.z.literal("iife")).or(zod.z.literal("umd")).describe(`Output format of the generated bundle (supports ${colors.underline("esm")}, cjs, and iife)`);
|
|
1643
|
+
const addonFunctionSchema = zod.z.function().args(phantom()).returns(zod.z.string().or(zod.z.promise(zod.z.string())));
|
|
1644
|
+
const chunkFileNamesFunctionSchema = zod.z.function().args(phantom()).returns(zod.z.string());
|
|
1645
|
+
const GlobalsFunctionSchema = zod.z.function().args(zod.z.string()).returns(zod.z.string());
|
|
1646
|
+
const outputOptionsSchema = zod.z.strictObject({
|
|
1647
|
+
dir: zod.z.string().describe("Output directory, defaults to `dist` if `file` is not set").optional(),
|
|
1648
|
+
file: zod.z.string().describe("Single output file").optional(),
|
|
1649
|
+
exports: zod.z.literal("auto").or(zod.z.literal("named")).or(zod.z.literal("default")).or(zod.z.literal("none")).describe(`Specify a export mode (${colors.underline("auto")}, named, default, none)`).optional(),
|
|
1650
|
+
hashCharacters: zod.z.literal("base64").or(zod.z.literal("base36")).or(zod.z.literal("hex")).describe("Use the specified character set for file hashes").optional(),
|
|
1651
|
+
format: ModuleFormatSchema.optional(),
|
|
1652
|
+
sourcemap: zod.z.boolean().or(zod.z.literal("inline")).or(zod.z.literal("hidden")).describe(`Generate sourcemap (\`-s inline\` for inline, or ${colors.bold("pass the `-s` on the last argument if you want to generate `.map` file")})`).optional(),
|
|
1653
|
+
sourcemapIgnoreList: zod.z.boolean().or(phantom()).optional(),
|
|
1654
|
+
sourcemapPathTransform: phantom().optional(),
|
|
1655
|
+
banner: zod.z.string().or(addonFunctionSchema).optional(),
|
|
1656
|
+
footer: zod.z.string().or(addonFunctionSchema).optional(),
|
|
1657
|
+
intro: zod.z.string().or(addonFunctionSchema).optional(),
|
|
1658
|
+
outro: zod.z.string().or(addonFunctionSchema).optional(),
|
|
1659
|
+
extend: zod.z.boolean().describe("Extend global variable defined by name in IIFE / UMD formats").optional(),
|
|
1660
|
+
esModule: zod.z.literal("if-default-prop").or(zod.z.boolean()).optional(),
|
|
1661
|
+
assetFileNames: zod.z.string().describe("Name pattern for asset files").optional(),
|
|
1662
|
+
entryFileNames: zod.z.string().or(chunkFileNamesFunctionSchema).describe("Name pattern for emitted entry chunks").optional(),
|
|
1663
|
+
chunkFileNames: zod.z.string().or(chunkFileNamesFunctionSchema).describe("Name pattern for emitted secondary chunks").optional(),
|
|
1664
|
+
cssEntryFileNames: zod.z.string().or(chunkFileNamesFunctionSchema).describe("Name pattern for emitted css entry chunks").optional(),
|
|
1665
|
+
cssChunkFileNames: zod.z.string().or(chunkFileNamesFunctionSchema).describe("Name pattern for emitted css secondary chunks").optional(),
|
|
1666
|
+
minify: zod.z.boolean().describe("Minify the bundled file.").optional(),
|
|
1667
|
+
name: zod.z.string().describe("Name for UMD / IIFE format outputs").optional(),
|
|
1668
|
+
globals: zod.z.record(zod.z.string()).or(GlobalsFunctionSchema).describe("Global variable of UMD / IIFE dependencies (syntax: `key=value`)").optional(),
|
|
1669
|
+
externalLiveBindings: zod.z.boolean().describe("external live bindings").default(true).optional(),
|
|
1670
|
+
inlineDynamicImports: zod.z.boolean().describe("Inline dynamic imports").default(false).optional(),
|
|
1671
|
+
advancedChunks: zod.z.strictObject({
|
|
1672
|
+
minSize: zod.z.number().optional(),
|
|
1673
|
+
minShareCount: zod.z.number().optional(),
|
|
1674
|
+
groups: zod.z.array(zod.z.strictObject({
|
|
1675
|
+
name: zod.z.string(),
|
|
1676
|
+
test: zod.z.string().or(zod.z.instanceof(RegExp)).optional(),
|
|
1677
|
+
priority: zod.z.number().optional(),
|
|
1678
|
+
minSize: zod.z.number().optional(),
|
|
1679
|
+
minShareCount: zod.z.number().optional()
|
|
1680
|
+
})).optional()
|
|
1681
|
+
}).optional(),
|
|
1682
|
+
comments: zod.z.enum(["none", "preserve-legal"]).describe("Control comments in the output").optional()
|
|
1662
1683
|
});
|
|
1663
1684
|
const getAddonDescription = (placement, wrapper) => {
|
|
1664
|
-
return `
|
|
1685
|
+
return `Code to insert the ${colors.bold(placement)} of the bundled file (${colors.bold(wrapper)} the wrapper function)`;
|
|
1665
1686
|
};
|
|
1666
|
-
const outputCliOptionsSchema =
|
|
1667
|
-
banner:
|
|
1668
|
-
footer:
|
|
1669
|
-
intro:
|
|
1670
|
-
outro:
|
|
1671
|
-
esModule:
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
})
|
|
1687
|
+
const outputCliOptionsSchema = outputOptionsSchema.extend({
|
|
1688
|
+
banner: zod.z.string().describe(getAddonDescription("top", "outside")).optional(),
|
|
1689
|
+
footer: zod.z.string().describe(getAddonDescription("bottom", "outside")).optional(),
|
|
1690
|
+
intro: zod.z.string().describe(getAddonDescription("top", "inside")).optional(),
|
|
1691
|
+
outro: zod.z.string().describe(getAddonDescription("bottom", "inside")).optional(),
|
|
1692
|
+
esModule: zod.z.boolean().describe("Always generate `__esModule` marks in non-ESM formats, defaults to `if-default-prop` (use `--no-esModule` to always disable)").optional(),
|
|
1693
|
+
globals: zod.z.record(zod.z.string()).describe("Global variable of UMD / IIFE dependencies (syntax: `key=value`)").optional(),
|
|
1694
|
+
advancedChunks: zod.z.strictObject({
|
|
1695
|
+
minSize: zod.z.number().describe("Minimum size of the chunk").optional(),
|
|
1696
|
+
minShareCount: zod.z.number().describe("Minimum share count of the chunk").optional()
|
|
1697
|
+
}).optional()
|
|
1698
|
+
}).omit({
|
|
1677
1699
|
sourcemapPathTransform: true,
|
|
1678
1700
|
sourcemapIgnoreList: true
|
|
1679
1701
|
});
|
|
1680
1702
|
|
|
1681
1703
|
//#endregion
|
|
1682
1704
|
//#region src/cli/arguments/schema.ts
|
|
1683
|
-
const cliOptionsSchema =
|
|
1684
|
-
config:
|
|
1685
|
-
help:
|
|
1686
|
-
version:
|
|
1687
|
-
watch:
|
|
1688
|
-
})
|
|
1705
|
+
const cliOptionsSchema = zod.z.strictObject({
|
|
1706
|
+
config: zod.z.string().or(zod.z.boolean()).describe("Path to the config file (default: `rolldown.config.js`)").optional(),
|
|
1707
|
+
help: zod.z.boolean().describe("Show help").optional(),
|
|
1708
|
+
version: zod.z.boolean().describe("Show version number").optional(),
|
|
1709
|
+
watch: zod.z.boolean().describe("Watch files in bundle and rebuild on changes").optional()
|
|
1710
|
+
}).merge(inputCliOptionsSchema).merge(outputCliOptionsSchema);
|
|
1689
1711
|
const schema = zodToJsonSchema(cliOptionsSchema);
|
|
1690
1712
|
|
|
1691
1713
|
//#endregion
|
|
@@ -1696,23 +1718,24 @@ const alias = {
|
|
|
1696
1718
|
hint: "filename",
|
|
1697
1719
|
default: "rolldown.config.js"
|
|
1698
1720
|
},
|
|
1699
|
-
help: {abbreviation: "h"},
|
|
1700
|
-
version: {abbreviation: "v"},
|
|
1701
|
-
watch: {abbreviation: "w"},
|
|
1702
|
-
dir: {abbreviation: "d"},
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1721
|
+
help: { abbreviation: "h" },
|
|
1722
|
+
version: { abbreviation: "v" },
|
|
1723
|
+
watch: { abbreviation: "w" },
|
|
1724
|
+
dir: { abbreviation: "d" },
|
|
1725
|
+
file: { abbreviation: "o" },
|
|
1726
|
+
external: { abbreviation: "e" },
|
|
1727
|
+
format: { abbreviation: "f" },
|
|
1728
|
+
name: { abbreviation: "n" },
|
|
1729
|
+
globals: { abbreviation: "g" },
|
|
1707
1730
|
sourcemap: {
|
|
1708
1731
|
abbreviation: "s",
|
|
1709
1732
|
default: true
|
|
1710
1733
|
},
|
|
1711
|
-
minify: {abbreviation: "m"},
|
|
1712
|
-
platform: {abbreviation: "p"},
|
|
1713
|
-
assetFileNames: {hint: "name"},
|
|
1714
|
-
chunkFileNames: {hint: "name"},
|
|
1715
|
-
entryFileNames: {hint: "name"},
|
|
1734
|
+
minify: { abbreviation: "m" },
|
|
1735
|
+
platform: { abbreviation: "p" },
|
|
1736
|
+
assetFileNames: { hint: "name" },
|
|
1737
|
+
chunkFileNames: { hint: "name" },
|
|
1738
|
+
entryFileNames: { hint: "name" },
|
|
1716
1739
|
externalLiveBindings: {
|
|
1717
1740
|
default: true,
|
|
1718
1741
|
reverse: true
|
|
@@ -1721,13 +1744,13 @@ const alias = {
|
|
|
1721
1744
|
default: true,
|
|
1722
1745
|
reverse: true
|
|
1723
1746
|
},
|
|
1724
|
-
moduleTypes: {hint: "types"}
|
|
1747
|
+
moduleTypes: { hint: "types" }
|
|
1725
1748
|
};
|
|
1726
1749
|
|
|
1727
1750
|
//#endregion
|
|
1728
1751
|
//#region src/cli/arguments/utils.ts
|
|
1729
1752
|
function getSchemaType(schema$1) {
|
|
1730
|
-
if ("anyOf"in schema$1) {
|
|
1753
|
+
if ("anyOf" in schema$1) {
|
|
1731
1754
|
const types = schema$1.anyOf.map((s) => getSchemaType(s));
|
|
1732
1755
|
if (types.includes("object")) return "object";
|
|
1733
1756
|
else if (types.includes("array")) return "array";
|
|
@@ -1735,38 +1758,28 @@ else if (types.includes("string")) return "string";
|
|
|
1735
1758
|
else if (types.includes("number")) return "number";
|
|
1736
1759
|
else if (types.includes("boolean")) return "boolean";
|
|
1737
1760
|
}
|
|
1738
|
-
if ("type"in schema$1)
|
|
1739
|
-
return schema$1.type;
|
|
1740
|
-
}
|
|
1761
|
+
if ("type" in schema$1) return schema$1.type;
|
|
1741
1762
|
return "object";
|
|
1742
1763
|
}
|
|
1743
1764
|
function flattenSchema(schema$1, base = {}, parent = "") {
|
|
1744
1765
|
for (const [k, value] of Object.entries(schema$1)) {
|
|
1745
1766
|
const key = parent ? `${parent}.${k}` : k;
|
|
1746
|
-
if (getSchemaType(value) === "object")
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
} else {
|
|
1750
|
-
base[key] = value;
|
|
1751
|
-
}
|
|
1752
|
-
} else {
|
|
1753
|
-
base[key] = value;
|
|
1754
|
-
}
|
|
1767
|
+
if (getSchemaType(value) === "object") if ("properties" in value) flattenSchema(value.properties, base, key);
|
|
1768
|
+
else base[key] = value;
|
|
1769
|
+
else base[key] = value;
|
|
1755
1770
|
}
|
|
1756
1771
|
return base;
|
|
1757
1772
|
}
|
|
1758
|
-
function setNestedProperty(obj, path$
|
|
1759
|
-
const keys = path$
|
|
1773
|
+
function setNestedProperty(obj, path$2, value) {
|
|
1774
|
+
const keys = path$2.split(".");
|
|
1760
1775
|
let current = obj;
|
|
1761
1776
|
for (let i = 0; i < keys.length - 1; i++) {
|
|
1762
|
-
if (!current[keys[i]]) {
|
|
1763
|
-
current[keys[i]] = {};
|
|
1764
|
-
}
|
|
1777
|
+
if (!current[keys[i]]) current[keys[i]] = {};
|
|
1765
1778
|
current = current[keys[i]];
|
|
1766
1779
|
}
|
|
1767
1780
|
const finalKey = keys[keys.length - 1];
|
|
1768
1781
|
Object.defineProperty(current, finalKey, {
|
|
1769
|
-
value
|
|
1782
|
+
value,
|
|
1770
1783
|
writable: true,
|
|
1771
1784
|
enumerable: true,
|
|
1772
1785
|
configurable: true
|
|
@@ -1797,62 +1810,54 @@ function normalizeCliOptions(cliOptions, positionals) {
|
|
|
1797
1810
|
version: options$1.version ?? false,
|
|
1798
1811
|
watch: options$1.watch ?? false
|
|
1799
1812
|
};
|
|
1800
|
-
if (typeof options$1.config === "string")
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1813
|
+
if (typeof options$1.config === "string") result.config = options$1.config ? options$1.config : "rolldown.config.js";
|
|
1814
|
+
const reservedKeys = [
|
|
1815
|
+
"help",
|
|
1816
|
+
"version",
|
|
1817
|
+
"config",
|
|
1818
|
+
"watch"
|
|
1819
|
+
];
|
|
1820
|
+
const keysOfInput = inputCliOptionsSchema.keyof()._def.values;
|
|
1821
|
+
const keysOfOutput = outputCliOptionsSchema.keyof()._def.values;
|
|
1806
1822
|
for (let [key, value] of Object.entries(options$1)) {
|
|
1807
1823
|
const keys = key.split(".");
|
|
1808
1824
|
const [primary] = keys;
|
|
1809
|
-
if (keysOfInput.includes(primary))
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
setNestedProperty(result.output, key, value);
|
|
1813
|
-
} else if (!reservedKeys.includes(key)) {
|
|
1825
|
+
if (keysOfInput.includes(primary)) setNestedProperty(result.input, key, value);
|
|
1826
|
+
else if (keysOfOutput.includes(primary)) setNestedProperty(result.output, key, value);
|
|
1827
|
+
else if (!reservedKeys.includes(key)) {
|
|
1814
1828
|
logger.error(`Unknown option: ${key}`);
|
|
1815
1829
|
process.exit(1);
|
|
1816
1830
|
}
|
|
1817
1831
|
}
|
|
1818
|
-
if (!result.config && positionals.length > 0)
|
|
1819
|
-
result.input.input = positionals;
|
|
1820
|
-
}
|
|
1832
|
+
if (!result.config && positionals.length > 0) result.input.input = positionals;
|
|
1821
1833
|
return result;
|
|
1822
1834
|
}
|
|
1823
1835
|
|
|
1824
1836
|
//#endregion
|
|
1825
1837
|
//#region src/cli/arguments/index.ts
|
|
1826
1838
|
const flattenedSchema = flattenSchema(schema.properties);
|
|
1827
|
-
const options = Object.fromEntries(
|
|
1828
|
-
const config =
|
|
1839
|
+
const options = Object.fromEntries(Object.entries(flattenedSchema).map(([key, schema$1]) => {
|
|
1840
|
+
const config = Object.getOwnPropertyDescriptor(alias, key)?.value;
|
|
1829
1841
|
const type = getSchemaType(schema$1);
|
|
1830
1842
|
const result = {
|
|
1831
1843
|
type: type === "boolean" ? "boolean" : "string",
|
|
1832
1844
|
description: schema$1?.description ?? config?.description ?? "",
|
|
1833
1845
|
hint: config?.hint
|
|
1834
1846
|
};
|
|
1835
|
-
if (config && config?.abbreviation)
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
if (config && config.reverse) {
|
|
1839
|
-
if (result.description.startsWith("enable")) {
|
|
1840
|
-
result.description = result.description.replace("enable", "disable");
|
|
1841
|
-
} else {
|
|
1842
|
-
result.description = `disable ${result.description}`;
|
|
1843
|
-
}
|
|
1844
|
-
}
|
|
1847
|
+
if (config && config?.abbreviation) result.short = config?.abbreviation;
|
|
1848
|
+
if (config && config.reverse) if (result.description.startsWith("enable")) result.description = result.description.replace("enable", "disable");
|
|
1849
|
+
else result.description = `disable ${result.description}`;
|
|
1845
1850
|
key = camelCaseToKebabCase(key);
|
|
1846
1851
|
return [config?.reverse ? `no-${key}` : key, result];
|
|
1847
1852
|
}));
|
|
1848
1853
|
function parseCliArguments() {
|
|
1849
|
-
const { values
|
|
1854
|
+
const { values, tokens, positionals } = (0, node_util.parseArgs)({
|
|
1850
1855
|
options,
|
|
1851
1856
|
tokens: true,
|
|
1852
1857
|
allowPositionals: true,
|
|
1853
1858
|
strict: false
|
|
1854
1859
|
});
|
|
1855
|
-
|
|
1860
|
+
tokens.filter((token) => token.kind === "option").forEach((option) => {
|
|
1856
1861
|
let negative = false;
|
|
1857
1862
|
if (option.name.startsWith("no-")) {
|
|
1858
1863
|
const name = kebabCaseToCamelCase(option.name.substring(3));
|
|
@@ -1872,7 +1877,7 @@ function parseCliArguments() {
|
|
|
1872
1877
|
let type = getSchemaType(originalType);
|
|
1873
1878
|
if (type === "string" && typeof option.value !== "string") {
|
|
1874
1879
|
let opt = option;
|
|
1875
|
-
let defaultValue =
|
|
1880
|
+
let defaultValue = Object.getOwnPropertyDescriptor(alias, opt.name)?.value;
|
|
1876
1881
|
Object.defineProperty(values, opt.name, {
|
|
1877
1882
|
value: defaultValue.default ?? "",
|
|
1878
1883
|
enumerable: true,
|
|
@@ -1880,117 +1885,106 @@ function parseCliArguments() {
|
|
|
1880
1885
|
writable: true
|
|
1881
1886
|
});
|
|
1882
1887
|
} else if (type === "object" && typeof option.value === "string") {
|
|
1883
|
-
const [key, value] =
|
|
1884
|
-
if (!values[option.name]) {
|
|
1885
|
-
|
|
1886
|
-
value: {},
|
|
1887
|
-
enumerable: true,
|
|
1888
|
-
configurable: true,
|
|
1889
|
-
writable: true
|
|
1890
|
-
});
|
|
1891
|
-
}
|
|
1892
|
-
if (key && value) {
|
|
1893
|
-
Object.defineProperty(values[option.name], key, {
|
|
1894
|
-
value,
|
|
1895
|
-
enumerable: true,
|
|
1896
|
-
configurable: true,
|
|
1897
|
-
writable: true
|
|
1898
|
-
});
|
|
1899
|
-
}
|
|
1900
|
-
} else if (type === "array" && typeof option.value === "string") {
|
|
1901
|
-
if (!values[option.name]) {
|
|
1902
|
-
Object.defineProperty(values, option.name, {
|
|
1903
|
-
value: [],
|
|
1904
|
-
enumerable: true,
|
|
1905
|
-
configurable: true,
|
|
1906
|
-
writable: true
|
|
1907
|
-
});
|
|
1908
|
-
}
|
|
1909
|
-
;
|
|
1910
|
-
values[option.name].push(option.value);
|
|
1911
|
-
} else if (type === "boolean") {
|
|
1912
|
-
Object.defineProperty(values, option.name, {
|
|
1913
|
-
value: !negative,
|
|
1888
|
+
const [key, value] = option.value.split(",").map((x) => x.split("="))[0];
|
|
1889
|
+
if (!values[option.name]) Object.defineProperty(values, option.name, {
|
|
1890
|
+
value: {},
|
|
1914
1891
|
enumerable: true,
|
|
1915
1892
|
configurable: true,
|
|
1916
1893
|
writable: true
|
|
1917
1894
|
});
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
value: option.value ?? "",
|
|
1895
|
+
if (key && value) Object.defineProperty(values[option.name], key, {
|
|
1896
|
+
value,
|
|
1921
1897
|
enumerable: true,
|
|
1922
1898
|
configurable: true,
|
|
1923
1899
|
writable: true
|
|
1924
1900
|
});
|
|
1925
|
-
}
|
|
1901
|
+
} else if (type === "array" && typeof option.value === "string") {
|
|
1902
|
+
if (!values[option.name]) Object.defineProperty(values, option.name, {
|
|
1903
|
+
value: [],
|
|
1904
|
+
enumerable: true,
|
|
1905
|
+
configurable: true,
|
|
1906
|
+
writable: true
|
|
1907
|
+
});
|
|
1908
|
+
values[option.name].push(option.value);
|
|
1909
|
+
} else if (type === "boolean") Object.defineProperty(values, option.name, {
|
|
1910
|
+
value: !negative,
|
|
1911
|
+
enumerable: true,
|
|
1912
|
+
configurable: true,
|
|
1913
|
+
writable: true
|
|
1914
|
+
});
|
|
1915
|
+
else Object.defineProperty(values, option.name, {
|
|
1916
|
+
value: option.value ?? "",
|
|
1917
|
+
enumerable: true,
|
|
1918
|
+
configurable: true,
|
|
1919
|
+
writable: true
|
|
1920
|
+
});
|
|
1926
1921
|
});
|
|
1927
1922
|
return normalizeCliOptions(values, positionals);
|
|
1928
1923
|
}
|
|
1929
1924
|
|
|
1930
1925
|
//#endregion
|
|
1931
1926
|
//#region src/cli/commands/help.ts
|
|
1932
|
-
const introduction = `${gray(`${description} (rolldown v${version})`)}
|
|
1927
|
+
const introduction = `${colors.gray(`${require_src.description} (rolldown v${require_src.version})`)}
|
|
1933
1928
|
|
|
1934
|
-
${bold(underline("USAGE"))} ${cyan("rolldown -c <config>")} or ${cyan("rolldown <input> <options>")}`;
|
|
1935
|
-
const examples = [
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
},
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1929
|
+
${colors.bold(colors.underline("USAGE"))} ${colors.cyan("rolldown -c <config>")} or ${colors.cyan("rolldown <input> <options>")}`;
|
|
1930
|
+
const examples = [
|
|
1931
|
+
{
|
|
1932
|
+
title: "Bundle with a config file `rolldown.config.mjs`",
|
|
1933
|
+
command: "rolldown -c rolldown.config.mjs"
|
|
1934
|
+
},
|
|
1935
|
+
{
|
|
1936
|
+
title: "Bundle the `src/main.ts` to `dist` with `cjs` format",
|
|
1937
|
+
command: "rolldown src/main.ts -d dist -f cjs"
|
|
1938
|
+
},
|
|
1939
|
+
{
|
|
1940
|
+
title: "Bundle the `src/main.ts` and handle the `.png` assets to Data URL",
|
|
1941
|
+
command: "rolldown src/main.ts -d dist --moduleTypes .png=dataurl"
|
|
1942
|
+
},
|
|
1943
|
+
{
|
|
1944
|
+
title: "Bundle the `src/main.tsx` and minify the output with sourcemap",
|
|
1945
|
+
command: "rolldown src/main.tsx -d dist -m -s"
|
|
1946
|
+
},
|
|
1947
|
+
{
|
|
1948
|
+
title: "Create self-executing IIFE using external jQuery as `$` and `_`",
|
|
1949
|
+
command: "rolldown src/main.ts -d dist -n bundle -f iife -e jQuery,window._ -g jQuery=$"
|
|
1950
|
+
}
|
|
1951
|
+
];
|
|
1952
|
+
const notes = [
|
|
1953
|
+
"Due to the API limitation, you need to pass `-s` for `.map` sourcemap file as the last argument.",
|
|
1954
|
+
"If you are using the configuration, please pass the `-c` as the last argument if you ignore the default configuration file.",
|
|
1955
|
+
"CLI options will override the configuration file.",
|
|
1956
|
+
"For more information, please visit https://rolldown.rs/."
|
|
1957
|
+
];
|
|
1952
1958
|
function showHelp() {
|
|
1953
1959
|
logger.log(introduction);
|
|
1954
1960
|
logger.log("");
|
|
1955
|
-
logger.log(`${bold(underline("OPTIONS"))}`);
|
|
1961
|
+
logger.log(`${colors.bold(colors.underline("OPTIONS"))}`);
|
|
1956
1962
|
logger.log("");
|
|
1957
|
-
logger.log(
|
|
1958
|
-
if (options[a].short && !options[b].short)
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
if (!options[a].short && options[b].short) {
|
|
1962
|
-
return 1;
|
|
1963
|
-
}
|
|
1964
|
-
if (options[a].short && options[b].short) {
|
|
1965
|
-
return options[a].short.localeCompare(options[b].short);
|
|
1966
|
-
}
|
|
1963
|
+
logger.log(Object.entries(options).sort(([a], [b]) => {
|
|
1964
|
+
if (options[a].short && !options[b].short) return -1;
|
|
1965
|
+
if (!options[a].short && options[b].short) return 1;
|
|
1966
|
+
if (options[a].short && options[b].short) return options[a].short.localeCompare(options[b].short);
|
|
1967
1967
|
return a.localeCompare(b);
|
|
1968
|
-
})
|
|
1968
|
+
}).map(([option, { type, short, hint, description: description$1 }]) => {
|
|
1969
1969
|
let optionStr = ` --${option} `;
|
|
1970
1970
|
option = camelCaseToKebabCase(option);
|
|
1971
|
-
if (short) {
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
}
|
|
1977
|
-
if (description$1 && description$1.length > 0) {
|
|
1978
|
-
description$1 = description$1[0].toUpperCase() + description$1.slice(1);
|
|
1979
|
-
}
|
|
1980
|
-
return cyan(optionStr.padEnd(30)) + description$1 + (description$1 && description$1?.endsWith(".") ? "" : ".");
|
|
1981
|
-
})).join("\n"));
|
|
1971
|
+
if (short) optionStr += `-${short}, `;
|
|
1972
|
+
if (type === "string") optionStr += `<${hint ?? option}>`;
|
|
1973
|
+
if (description$1 && description$1.length > 0) description$1 = description$1[0].toUpperCase() + description$1.slice(1);
|
|
1974
|
+
return colors.cyan(optionStr.padEnd(30)) + description$1 + (description$1 && description$1?.endsWith(".") ? "" : ".");
|
|
1975
|
+
}).join("\n"));
|
|
1982
1976
|
logger.log("");
|
|
1983
|
-
logger.log(`${bold(underline("EXAMPLES"))}`);
|
|
1977
|
+
logger.log(`${colors.bold(colors.underline("EXAMPLES"))}`);
|
|
1984
1978
|
logger.log("");
|
|
1985
|
-
examples.forEach(({ title
|
|
1979
|
+
examples.forEach(({ title, command }, ord) => {
|
|
1986
1980
|
logger.log(` ${ord + 1}. ${title}:`);
|
|
1987
|
-
logger.log(` ${cyan(command)}`);
|
|
1981
|
+
logger.log(` ${colors.cyan(command)}`);
|
|
1988
1982
|
logger.log("");
|
|
1989
1983
|
});
|
|
1990
|
-
logger.log(`${bold(underline("NOTES"))}`);
|
|
1984
|
+
logger.log(`${colors.bold(colors.underline("NOTES"))}`);
|
|
1991
1985
|
logger.log("");
|
|
1992
1986
|
notes.forEach((note) => {
|
|
1993
|
-
logger.log(` * ${gray(note)}`);
|
|
1987
|
+
logger.log(` * ${colors.gray(note)}`);
|
|
1994
1988
|
});
|
|
1995
1989
|
}
|
|
1996
1990
|
|
|
@@ -2002,19 +1996,19 @@ async function main() {
|
|
|
2002
1996
|
await bundleWithConfig(cliOptions.config, cliOptions);
|
|
2003
1997
|
return;
|
|
2004
1998
|
}
|
|
2005
|
-
if ("input"in cliOptions.input) {
|
|
1999
|
+
if ("input" in cliOptions.input) {
|
|
2006
2000
|
await bundleWithCliOptions(cliOptions);
|
|
2007
2001
|
return;
|
|
2008
2002
|
}
|
|
2009
2003
|
if (cliOptions.version) {
|
|
2010
|
-
logger.log(`rolldown v${version}`);
|
|
2004
|
+
logger.log(`rolldown v${require_src.version}`);
|
|
2011
2005
|
return;
|
|
2012
2006
|
}
|
|
2013
2007
|
showHelp();
|
|
2014
2008
|
}
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2009
|
+
main().catch((err) => {
|
|
2010
|
+
console.error(err);
|
|
2011
|
+
node_process.default.exit(1);
|
|
2018
2012
|
});
|
|
2019
2013
|
|
|
2020
|
-
//#endregion
|
|
2014
|
+
//#endregion
|