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