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