rolldown 0.12.2 → 0.13.0-snapshot-514fd69-20240905003110
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 +1552 -584
- package/dist/cjs/experimental-index.cjs +40 -0
- package/dist/cjs/index.cjs +5 -22
- package/dist/cjs/parallel-plugin-worker.cjs +7 -7
- package/dist/cjs/parallel-plugin.cjs +1 -1
- package/dist/esm/cli.mjs +1549 -583
- package/dist/esm/experimental-index.mjs +23 -0
- package/dist/esm/index.mjs +5 -17
- package/dist/esm/parallel-plugin-worker.mjs +6 -6
- package/dist/esm/parallel-plugin.mjs +1 -1
- package/dist/shared/{chunk-1xb6WR3y.cjs → chunk-gQ4GMlVi.cjs} +3 -2
- package/dist/shared/{consola.36c0034f-N8xiTrv3.cjs → consola.36c0034f-eps_ogJv.cjs} +188 -188
- package/dist/shared/{consola.36c0034f-jtHhMkSX.mjs → consola.36c0034f-m5cABVv4.mjs} +187 -187
- package/dist/shared/package-3VR4tEG7.mjs +9 -0
- package/dist/shared/package-OJCNSbf0.cjs +11 -0
- package/dist/shared/plugin-context-data-AMG1kfMv.mjs +1443 -0
- package/dist/shared/plugin-context-data-S1bXhfAf.cjs +1436 -0
- package/dist/shared/{prompt-pjyLzLci.mjs → prompt-9VjtYvi_.mjs} +182 -182
- package/dist/shared/{prompt-1K6oCkIU.cjs → prompt-Ah5G71p-.cjs} +183 -183
- package/dist/shared/rolldown-NGdGAW73.mjs +1069 -0
- package/dist/shared/rolldown-binding.wasi.cjs +70 -51
- package/dist/shared/rolldown-z62CIhEW.cjs +1085 -0
- package/dist/types/binding.d.ts +329 -14
- package/dist/types/cli/arguments/alias.d.ts +8 -0
- package/dist/types/cli/arguments/index.d.ts +13 -0
- package/dist/types/cli/arguments/normalize.d.ts +15 -0
- package/dist/types/cli/arguments/schema.d.ts +161 -0
- package/dist/types/cli/arguments/utils.d.ts +6 -0
- package/dist/types/cli/commands/bundle.d.ts +3 -1
- package/dist/types/cli/commands/help.d.ts +1 -0
- package/dist/types/cli/utils.d.ts +1 -1
- package/dist/types/constants/plugin-context.d.ts +7 -0
- package/dist/types/constants/plugin.d.ts +36 -0
- package/dist/types/experimental-index.d.ts +5 -0
- package/dist/types/index.d.ts +8 -8
- package/dist/types/options/input-options.d.ts +139 -27
- package/dist/types/options/normalized-alias-plugin-config.d.ts +10 -0
- package/dist/types/options/normalized-ecma-transform-plugin-config.d.ts +8 -0
- package/dist/types/options/normalized-output-options.d.ts +8 -3
- package/dist/types/options/output-options.d.ts +102 -11
- package/dist/types/options/utils.d.ts +2 -0
- package/dist/types/plugin/bindingify-build-hooks.d.ts +9 -8
- package/dist/types/plugin/bindingify-hook-filter.d.ts +5 -0
- package/dist/types/plugin/bindingify-output-hooks.d.ts +11 -7
- package/dist/types/plugin/bindingify-plugin-hook-meta.d.ts +8 -0
- package/dist/types/plugin/bindingify-plugin.d.ts +2 -1
- package/dist/types/plugin/builtin-plugin.d.ts +75 -7
- package/dist/types/plugin/index.d.ts +68 -28
- package/dist/types/plugin/plugin-context-data.d.ts +6 -0
- package/dist/types/plugin/plugin-context.d.ts +18 -8
- package/dist/types/plugin/plugin-driver.d.ts +2 -2
- package/dist/types/rollup.d.ts +1 -0
- package/dist/types/types/rolldown-output.d.ts +1 -0
- package/dist/types/utils/compose-js-plugins.d.ts +2 -0
- package/dist/types/utils/misc.d.ts +1 -0
- package/dist/types/utils/normalize-hook.d.ts +7 -5
- package/dist/types/utils/plugin/index.d.ts +2 -0
- package/dist/types/utils/type-assert.d.ts +1 -0
- package/package.json +30 -22
- package/dist/shared/rolldown-SCF5NBN_.cjs +0 -49
- package/dist/shared/rolldown-kYz4BvAA.mjs +0 -48
- package/dist/shared/utils_index-_DFpKlu1.mjs +0 -1582
- package/dist/shared/utils_index-xb2NoRNm.cjs +0 -1557
- package/dist/types/cli/constants.d.ts +0 -1
- package/dist/types/utils/ensure-array.d.ts +0 -1
- package/dist/types/utils/index.d.ts +0 -9
- /package/dist/types/plugin/{transfrom-plugin-context.d.ts → transform-plugin-context.d.ts} +0 -0
package/dist/cjs/cli.cjs
CHANGED
|
@@ -1,534 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
const {
|
|
5
|
-
const {
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { __export, __toESM } = require("../shared/chunk-gQ4GMlVi.cjs");
|
|
4
|
+
const { LogLevelOptionSchema, LogLevelSchema, LogLevelWithErrorSchema, RollupLogSchema, RollupLogWithStringSchema, arraify } = require("../shared/plugin-context-data-S1bXhfAf.cjs");
|
|
5
|
+
const { rolldown } = require("../shared/rolldown-z62CIhEW.cjs");
|
|
6
|
+
const { description, version } = require("../shared/package-OJCNSbf0.cjs");
|
|
7
|
+
const { createConsola } = require("../shared/consola.36c0034f-eps_ogJv.cjs");
|
|
6
8
|
const { default: nodePath } = __toESM(require("node:path"));
|
|
9
|
+
const { ZodFirstPartyTypeKind, ZodFirstPartyTypeKind: ZodFirstPartyTypeKind$1, ZodFirstPartyTypeKind: ZodFirstPartyTypeKind$2, z, z: z$1, z: z$2, z: z$3 } = __toESM(require("zod"));
|
|
7
10
|
const { default: process$1, env } = __toESM(require("node:process"));
|
|
8
|
-
require("node:util");
|
|
9
|
-
const tty = __toESM(require("node:tty"));
|
|
10
11
|
const { performance } = __toESM(require("node:perf_hooks"));
|
|
12
|
+
const { pathToFileURL } = __toESM(require("node:url"));
|
|
13
|
+
const { parseArgs } = __toESM(require("node:util"));
|
|
14
|
+
const tty = __toESM(require("node:tty"));
|
|
11
15
|
|
|
12
|
-
//#region
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
out[key] = old == null ? nxt : (Array.isArray(old) ? old.concat(nxt) : [old, nxt]);
|
|
20
|
-
}
|
|
21
|
-
module.exports = function(args, opts) {
|
|
22
|
-
args = args || [];
|
|
23
|
-
opts = opts || {};
|
|
24
|
-
var k, arr, arg, name, val, out = {_: []};
|
|
25
|
-
var i = 0, j = 0, idx = 0, len = args.length;
|
|
26
|
-
const alibi = opts.alias !== void 0;
|
|
27
|
-
const strict = opts.unknown !== void 0;
|
|
28
|
-
const defaults = opts.default !== void 0;
|
|
29
|
-
opts.alias = opts.alias || {};
|
|
30
|
-
opts.string = toArr$1(opts.string);
|
|
31
|
-
opts.boolean = toArr$1(opts.boolean);
|
|
32
|
-
if (alibi) {
|
|
33
|
-
for (k in opts.alias) {
|
|
34
|
-
arr = opts.alias[k] = toArr$1(opts.alias[k]);
|
|
35
|
-
for (i = 0; i < arr.length; i++) {
|
|
36
|
-
(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
for (i = opts.boolean.length; i-- > 0;) {
|
|
41
|
-
arr = opts.alias[opts.boolean[i]] || [];
|
|
42
|
-
for (j = arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
|
43
|
-
}
|
|
44
|
-
for (i = opts.string.length; i-- > 0;) {
|
|
45
|
-
arr = opts.alias[opts.string[i]] || [];
|
|
46
|
-
for (j = arr.length; j-- > 0;) opts.string.push(arr[j]);
|
|
47
|
-
}
|
|
48
|
-
if (defaults) {
|
|
49
|
-
for (k in opts.default) {
|
|
50
|
-
name = typeof opts.default[k];
|
|
51
|
-
arr = opts.alias[k] = opts.alias[k] || [];
|
|
52
|
-
if (opts[name] !== void 0) {
|
|
53
|
-
opts[name].push(k);
|
|
54
|
-
for (i = 0; i < arr.length; i++) {
|
|
55
|
-
opts[name].push(arr[i]);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const keys = strict ? Object.keys(opts.alias) : [];
|
|
61
|
-
for (i = 0; i < len; i++) {
|
|
62
|
-
arg = args[i];
|
|
63
|
-
if (arg === '--') {
|
|
64
|
-
out._ = out._.concat(args.slice(++i));
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
for (j = 0; j < arg.length; j++) {
|
|
68
|
-
if (arg.charCodeAt(j) !== 45) break;
|
|
69
|
-
}
|
|
70
|
-
if (j === 0) {
|
|
71
|
-
out._.push(arg);
|
|
72
|
-
} else if (arg.substring(j, j + 3) === 'no-') {
|
|
73
|
-
name = arg.substring(j + 3);
|
|
74
|
-
if (strict && !~keys.indexOf(name)) {
|
|
75
|
-
return opts.unknown(arg);
|
|
76
|
-
}
|
|
77
|
-
out[name] = false;
|
|
78
|
-
} else {
|
|
79
|
-
for (idx = j + 1; idx < arg.length; idx++) {
|
|
80
|
-
if (arg.charCodeAt(idx) === 61) break;
|
|
81
|
-
}
|
|
82
|
-
name = arg.substring(j, idx);
|
|
83
|
-
val = arg.substring(++idx) || (i + 1 === len || ('' + args[i + 1]).charCodeAt(0) === 45 || args[++i]);
|
|
84
|
-
arr = (j === 2 ? [name] : name);
|
|
85
|
-
for (idx = 0; idx < arr.length; idx++) {
|
|
86
|
-
name = arr[idx];
|
|
87
|
-
if (strict && !~keys.indexOf(name)) return opts.unknown('-'.repeat(j) + name);
|
|
88
|
-
toVal$1(out, name, (idx + 1 < arr.length) || val, opts);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (defaults) {
|
|
93
|
-
for (k in opts.default) {
|
|
94
|
-
if (out[k] === void 0) {
|
|
95
|
-
out[k] = opts.default[k];
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (alibi) {
|
|
100
|
-
for (k in out) {
|
|
101
|
-
arr = opts.alias[k] || [];
|
|
102
|
-
while (arr.length > 0) {
|
|
103
|
-
out[arr.shift()] = out[k];
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return out;
|
|
108
|
-
};
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
//#endregion
|
|
112
|
-
//#region ../../node_modules/.pnpm/citty@0.1.6/node_modules/citty/dist/index.mjs
|
|
113
|
-
function toArray(val) {
|
|
114
|
-
if (Array.isArray(val)) {
|
|
115
|
-
return val;
|
|
116
|
-
}
|
|
117
|
-
return val === void 0 ? [] : [val];
|
|
118
|
-
}
|
|
119
|
-
function formatLineColumns(lines, linePrefix = '') {
|
|
120
|
-
const maxLengh = [];
|
|
121
|
-
for (const line of lines) {
|
|
122
|
-
for (const [i, element] of line.entries()) {
|
|
123
|
-
maxLengh[i] = Math.max(maxLengh[i] || 0, element.length);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return lines.map((l) => l.map((c, i) => linePrefix + c[i === 0 ? 'padStart' : 'padEnd'](maxLengh[i])).join(' ')).join('\n');
|
|
127
|
-
}
|
|
128
|
-
function resolveValue(input) {
|
|
129
|
-
return typeof input === 'function' ? input() : input;
|
|
130
|
-
}
|
|
131
|
-
class CLIError extends Error {
|
|
132
|
-
constructor(message, code) {
|
|
133
|
-
super(message);
|
|
134
|
-
this.code = code;
|
|
135
|
-
this.name = 'CLIError';
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
const NUMBER_CHAR_RE = /\d/;
|
|
139
|
-
const STR_SPLITTERS = ['-', '_', '/', '.'];
|
|
140
|
-
function isUppercase(char = '') {
|
|
141
|
-
if (NUMBER_CHAR_RE.test(char)) {
|
|
142
|
-
return void 0;
|
|
143
|
-
}
|
|
144
|
-
return char !== char.toLowerCase();
|
|
145
|
-
}
|
|
146
|
-
function splitByCase(str, separators) {
|
|
147
|
-
const splitters = separators ?? STR_SPLITTERS;
|
|
148
|
-
const parts = [];
|
|
149
|
-
if (!str || typeof str !== 'string') {
|
|
150
|
-
return parts;
|
|
151
|
-
}
|
|
152
|
-
let buff = '';
|
|
153
|
-
let previousUpper;
|
|
154
|
-
let previousSplitter;
|
|
155
|
-
for (const char of str) {
|
|
156
|
-
const isSplitter = splitters.includes(char);
|
|
157
|
-
if (isSplitter === true) {
|
|
158
|
-
parts.push(buff);
|
|
159
|
-
buff = '';
|
|
160
|
-
previousUpper = void 0;
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
const isUpper = isUppercase(char);
|
|
164
|
-
if (previousSplitter === false) {
|
|
165
|
-
if (previousUpper === false && isUpper === true) {
|
|
166
|
-
parts.push(buff);
|
|
167
|
-
buff = char;
|
|
168
|
-
previousUpper = isUpper;
|
|
169
|
-
continue;
|
|
170
|
-
}
|
|
171
|
-
if (previousUpper === true && isUpper === false && buff.length > 1) {
|
|
172
|
-
const lastChar = buff.at(-1);
|
|
173
|
-
parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
|
|
174
|
-
buff = lastChar + char;
|
|
175
|
-
previousUpper = isUpper;
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
buff += char;
|
|
180
|
-
previousUpper = isUpper;
|
|
181
|
-
previousSplitter = isSplitter;
|
|
182
|
-
}
|
|
183
|
-
parts.push(buff);
|
|
184
|
-
return parts;
|
|
185
|
-
}
|
|
186
|
-
function upperFirst(str) {
|
|
187
|
-
return str ? str[0].toUpperCase() + str.slice(1) : '';
|
|
188
|
-
}
|
|
189
|
-
function lowerFirst(str) {
|
|
190
|
-
return str ? str[0].toLowerCase() + str.slice(1) : '';
|
|
191
|
-
}
|
|
192
|
-
function pascalCase(str, opts) {
|
|
193
|
-
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join('') : '';
|
|
194
|
-
}
|
|
195
|
-
function camelCase(str, opts) {
|
|
196
|
-
return lowerFirst(pascalCase(str || '', opts));
|
|
197
|
-
}
|
|
198
|
-
function kebabCase(str, joiner) {
|
|
199
|
-
return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? '-') : '';
|
|
200
|
-
}
|
|
201
|
-
function toArr(any) {
|
|
202
|
-
return any == void 0 ? [] : Array.isArray(any) ? any : [any];
|
|
203
|
-
}
|
|
204
|
-
function toVal(out, key, val, opts) {
|
|
205
|
-
let x;
|
|
206
|
-
const old = out[key];
|
|
207
|
-
const nxt = ~opts.string.indexOf(key) ? val == void 0 || val === true ? '' : String(val) : typeof val === 'boolean' ? val : ~opts.boolean.indexOf(key) ? val === 'false' ? false : val === 'true' || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
|
|
208
|
-
out[key] = old == void 0 ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
|
|
209
|
-
}
|
|
210
|
-
function parseRawArgs(args = [], opts = {}) {
|
|
211
|
-
let k;
|
|
212
|
-
let arr;
|
|
213
|
-
let arg;
|
|
214
|
-
let name;
|
|
215
|
-
let val;
|
|
216
|
-
const out = {_: []};
|
|
217
|
-
let i = 0;
|
|
218
|
-
let j = 0;
|
|
219
|
-
let idx = 0;
|
|
220
|
-
const len = args.length;
|
|
221
|
-
const alibi = opts.alias !== void 0;
|
|
222
|
-
const strict = opts.unknown !== void 0;
|
|
223
|
-
const defaults = opts.default !== void 0;
|
|
224
|
-
opts.alias = opts.alias || {};
|
|
225
|
-
opts.string = toArr(opts.string);
|
|
226
|
-
opts.boolean = toArr(opts.boolean);
|
|
227
|
-
if (alibi) {
|
|
228
|
-
for (k in opts.alias) {
|
|
229
|
-
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
230
|
-
for (i = 0; i < arr.length; i++) {
|
|
231
|
-
(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
for (i = opts.boolean.length; i-- > 0;) {
|
|
236
|
-
arr = opts.alias[opts.boolean[i]] || [];
|
|
237
|
-
for (j = arr.length; j-- > 0;) {
|
|
238
|
-
opts.boolean.push(arr[j]);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
for (i = opts.string.length; i-- > 0;) {
|
|
242
|
-
arr = opts.alias[opts.string[i]] || [];
|
|
243
|
-
for (j = arr.length; j-- > 0;) {
|
|
244
|
-
opts.string.push(arr[j]);
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
if (defaults) {
|
|
248
|
-
for (k in opts.default) {
|
|
249
|
-
name = typeof opts.default[k];
|
|
250
|
-
arr = opts.alias[k] = opts.alias[k] || [];
|
|
251
|
-
if (opts[name] !== void 0) {
|
|
252
|
-
opts[name].push(k);
|
|
253
|
-
for (i = 0; i < arr.length; i++) {
|
|
254
|
-
opts[name].push(arr[i]);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
const keys = strict ? Object.keys(opts.alias) : [];
|
|
260
|
-
for (i = 0; i < len; i++) {
|
|
261
|
-
arg = args[i];
|
|
262
|
-
if (arg === '--') {
|
|
263
|
-
out._ = out._.concat(args.slice(++i));
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
for (j = 0; j < arg.length; j++) {
|
|
267
|
-
if (arg.charCodeAt(j) !== 45) {
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
if (j === 0) {
|
|
272
|
-
out._.push(arg);
|
|
273
|
-
} else if (arg.substring(j, j + 3) === 'no-') {
|
|
274
|
-
name = arg.slice(Math.max(0, j + 3));
|
|
275
|
-
if (strict && !~keys.indexOf(name)) {
|
|
276
|
-
return opts.unknown(arg);
|
|
277
|
-
}
|
|
278
|
-
out[name] = false;
|
|
279
|
-
} else {
|
|
280
|
-
for (idx = j + 1; idx < arg.length; idx++) {
|
|
281
|
-
if (arg.charCodeAt(idx) === 61) {
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
name = arg.substring(j, idx);
|
|
286
|
-
val = arg.slice(Math.max(0, ++idx)) || i + 1 === len || ('' + args[i + 1]).charCodeAt(0) === 45 || args[++i];
|
|
287
|
-
arr = j === 2 ? [name] : name;
|
|
288
|
-
for (idx = 0; idx < arr.length; idx++) {
|
|
289
|
-
name = arr[idx];
|
|
290
|
-
if (strict && !~keys.indexOf(name)) {
|
|
291
|
-
return opts.unknown('-'.repeat(j) + name);
|
|
292
|
-
}
|
|
293
|
-
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
if (defaults) {
|
|
298
|
-
for (k in opts.default) {
|
|
299
|
-
if (out[k] === void 0) {
|
|
300
|
-
out[k] = opts.default[k];
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
if (alibi) {
|
|
305
|
-
for (k in out) {
|
|
306
|
-
arr = opts.alias[k] || [];
|
|
307
|
-
while (arr.length > 0) {
|
|
308
|
-
out[arr.shift()] = out[k];
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return out;
|
|
313
|
-
}
|
|
314
|
-
function parseArgs$1(rawArgs, argsDef) {
|
|
315
|
-
const parseOptions = {
|
|
316
|
-
boolean: [],
|
|
317
|
-
string: [],
|
|
318
|
-
mixed: [],
|
|
319
|
-
alias: {},
|
|
320
|
-
default: {}
|
|
321
|
-
};
|
|
322
|
-
const args = resolveArgs(argsDef);
|
|
323
|
-
for (const arg of args) {
|
|
324
|
-
if (arg.type === 'positional') {
|
|
325
|
-
continue;
|
|
326
|
-
}
|
|
327
|
-
if (arg.type === 'string') {
|
|
328
|
-
parseOptions.string.push(arg.name);
|
|
329
|
-
} else if (arg.type === 'boolean') {
|
|
330
|
-
parseOptions.boolean.push(arg.name);
|
|
331
|
-
}
|
|
332
|
-
if (arg.default !== void 0) {
|
|
333
|
-
parseOptions.default[arg.name] = arg.default;
|
|
334
|
-
}
|
|
335
|
-
if (arg.alias) {
|
|
336
|
-
parseOptions.alias[arg.name] = arg.alias;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
const parsed = parseRawArgs(rawArgs, parseOptions);
|
|
340
|
-
const [ ...positionalArguments] = parsed._;
|
|
341
|
-
const parsedArgsProxy = new Proxy(parsed, {get(target, prop) {
|
|
342
|
-
return target[prop] ?? target[camelCase(prop)] ?? target[kebabCase(prop)];
|
|
343
|
-
}});
|
|
344
|
-
for (const [, arg] of args.entries()) {
|
|
345
|
-
if (arg.type === 'positional') {
|
|
346
|
-
const nextPositionalArgument = positionalArguments.shift();
|
|
347
|
-
if (nextPositionalArgument !== void 0) {
|
|
348
|
-
parsedArgsProxy[arg.name] = nextPositionalArgument;
|
|
349
|
-
} else if (arg.default === void 0 && arg.required !== false) {
|
|
350
|
-
throw new CLIError(`Missing required positional argument: ${arg.name.toUpperCase()}`, 'EARG');
|
|
351
|
-
} else {
|
|
352
|
-
parsedArgsProxy[arg.name] = arg.default;
|
|
353
|
-
}
|
|
354
|
-
} else if (arg.required && parsedArgsProxy[arg.name] === void 0) {
|
|
355
|
-
throw new CLIError(`Missing required argument: --${arg.name}`, 'EARG');
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
return parsedArgsProxy;
|
|
359
|
-
}
|
|
360
|
-
function resolveArgs(argsDef) {
|
|
361
|
-
const args = [];
|
|
362
|
-
for (const [name, argDef] of Object.entries(argsDef || {})) {
|
|
363
|
-
args.push({
|
|
364
|
-
...argDef,
|
|
365
|
-
name,
|
|
366
|
-
alias: toArray(argDef.alias)
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
return args;
|
|
370
|
-
}
|
|
371
|
-
function defineCommand(def) {
|
|
372
|
-
return def;
|
|
373
|
-
}
|
|
374
|
-
async function runCommand(cmd, opts) {
|
|
375
|
-
const cmdArgs = await resolveValue(cmd.args || {});
|
|
376
|
-
const parsedArgs = parseArgs$1(opts.rawArgs, cmdArgs);
|
|
377
|
-
const context = {
|
|
378
|
-
rawArgs: opts.rawArgs,
|
|
379
|
-
args: parsedArgs,
|
|
380
|
-
data: opts.data,
|
|
381
|
-
cmd
|
|
382
|
-
};
|
|
383
|
-
if (typeof cmd.setup === 'function') {
|
|
384
|
-
await cmd.setup(context);
|
|
385
|
-
}
|
|
386
|
-
let result;
|
|
387
|
-
try {
|
|
388
|
-
const subCommands = await resolveValue(cmd.subCommands);
|
|
389
|
-
if (subCommands && Object.keys(subCommands).length > 0) {
|
|
390
|
-
const subCommandArgIndex = opts.rawArgs.findIndex((arg) => !arg.startsWith('-'));
|
|
391
|
-
const subCommandName = opts.rawArgs[subCommandArgIndex];
|
|
392
|
-
if (subCommandName) {
|
|
393
|
-
if (!subCommands[subCommandName]) {
|
|
394
|
-
throw new CLIError(`Unknown command \`${subCommandName}\``, 'E_UNKNOWN_COMMAND');
|
|
395
|
-
}
|
|
396
|
-
const subCommand = await resolveValue(subCommands[subCommandName]);
|
|
397
|
-
if (subCommand) {
|
|
398
|
-
await runCommand(subCommand, {rawArgs: opts.rawArgs.slice(subCommandArgIndex + 1)});
|
|
399
|
-
}
|
|
400
|
-
} else if (!cmd.run) {
|
|
401
|
-
throw new CLIError(`No command specified.`, 'E_NO_COMMAND');
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
if (typeof cmd.run === 'function') {
|
|
405
|
-
result = await cmd.run(context);
|
|
406
|
-
}
|
|
407
|
-
} finally {
|
|
408
|
-
if (typeof cmd.cleanup === 'function') {
|
|
409
|
-
await cmd.cleanup(context);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
return {result};
|
|
413
|
-
}
|
|
414
|
-
async function resolveSubCommand(cmd, rawArgs, parent) {
|
|
415
|
-
const subCommands = await resolveValue(cmd.subCommands);
|
|
416
|
-
if (subCommands && Object.keys(subCommands).length > 0) {
|
|
417
|
-
const subCommandArgIndex = rawArgs.findIndex((arg) => !arg.startsWith('-'));
|
|
418
|
-
const subCommandName = rawArgs[subCommandArgIndex];
|
|
419
|
-
const subCommand = await resolveValue(subCommands[subCommandName]);
|
|
420
|
-
if (subCommand) {
|
|
421
|
-
return resolveSubCommand(subCommand, rawArgs.slice(subCommandArgIndex + 1), cmd);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
return [cmd, parent];
|
|
425
|
-
}
|
|
426
|
-
async function showUsage(cmd, parent) {
|
|
427
|
-
try {
|
|
428
|
-
consola.log(await renderUsage(cmd, parent) + '\n');
|
|
429
|
-
} catch (error) {
|
|
430
|
-
consola.error(error);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
async function renderUsage(cmd, parent) {
|
|
434
|
-
const cmdMeta = await resolveValue(cmd.meta || {});
|
|
435
|
-
const cmdArgs = resolveArgs(await resolveValue(cmd.args || {}));
|
|
436
|
-
const parentMeta = await resolveValue(parent?.meta || {});
|
|
437
|
-
const commandName = `${parentMeta.name ? `${parentMeta.name} ` : ''}` + (cmdMeta.name || process.argv[1]);
|
|
438
|
-
const argLines = [];
|
|
439
|
-
const posLines = [];
|
|
440
|
-
const commandsLines = [];
|
|
441
|
-
const usageLine = [];
|
|
442
|
-
for (const arg of cmdArgs) {
|
|
443
|
-
if (arg.type === 'positional') {
|
|
444
|
-
const name = arg.name.toUpperCase();
|
|
445
|
-
const isRequired = arg.required !== false && arg.default === void 0;
|
|
446
|
-
const defaultHint = arg.default ? `="${arg.default}"` : '';
|
|
447
|
-
posLines.push(['`' + name + defaultHint + '`', arg.description || '', arg.valueHint ? `<${arg.valueHint}>` : '']);
|
|
448
|
-
usageLine.push(isRequired ? `<${name}>` : `[${name}]`);
|
|
449
|
-
} else {
|
|
450
|
-
const isRequired = arg.required === true && arg.default === void 0;
|
|
451
|
-
const argStr = (arg.type === 'boolean' && arg.default === true ? [...(arg.alias || []).map((a) => `--no-${a}`), `--no-${arg.name}`].join(', ') : [...(arg.alias || []).map((a) => `-${a}`), `--${arg.name}`].join(', ')) + (arg.type === 'string' && (arg.valueHint || arg.default) ? `=${arg.valueHint ? `<${arg.valueHint}>` : `"${arg.default || ''}"`}` : '');
|
|
452
|
-
argLines.push(['`' + argStr + (isRequired ? ' (required)' : '') + '`', arg.description || '']);
|
|
453
|
-
if (isRequired) {
|
|
454
|
-
usageLine.push(argStr);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
if (cmd.subCommands) {
|
|
459
|
-
const commandNames = [];
|
|
460
|
-
const subCommands = await resolveValue(cmd.subCommands);
|
|
461
|
-
for (const [name, sub] of Object.entries(subCommands)) {
|
|
462
|
-
const subCmd = await resolveValue(sub);
|
|
463
|
-
const meta = await resolveValue(subCmd?.meta);
|
|
464
|
-
commandsLines.push([`\`${name}\``, meta?.description || '']);
|
|
465
|
-
commandNames.push(name);
|
|
466
|
-
}
|
|
467
|
-
usageLine.push(commandNames.join('|'));
|
|
468
|
-
}
|
|
469
|
-
const usageLines = [];
|
|
470
|
-
const version$1 = cmdMeta.version || parentMeta.version;
|
|
471
|
-
usageLines.push(colors.gray(`${cmdMeta.description} (${commandName + (version$1 ? ` v${version$1}` : '')})`), '');
|
|
472
|
-
const hasOptions = argLines.length > 0 || posLines.length > 0;
|
|
473
|
-
usageLines.push(`${colors.underline(colors.bold('USAGE'))} \`${commandName}${hasOptions ? ' [OPTIONS]' : ''} ${usageLine.join(' ')}\``, '');
|
|
474
|
-
if (posLines.length > 0) {
|
|
475
|
-
usageLines.push(colors.underline(colors.bold('ARGUMENTS')), '');
|
|
476
|
-
usageLines.push(formatLineColumns(posLines, ' '));
|
|
477
|
-
usageLines.push('');
|
|
478
|
-
}
|
|
479
|
-
if (argLines.length > 0) {
|
|
480
|
-
usageLines.push(colors.underline(colors.bold('OPTIONS')), '');
|
|
481
|
-
usageLines.push(formatLineColumns(argLines, ' '));
|
|
482
|
-
usageLines.push('');
|
|
483
|
-
}
|
|
484
|
-
if (commandsLines.length > 0) {
|
|
485
|
-
usageLines.push(colors.underline(colors.bold('COMMANDS')), '');
|
|
486
|
-
usageLines.push(formatLineColumns(commandsLines, ' '));
|
|
487
|
-
usageLines.push('', `Use \`${commandName} <command> --help\` for more information about a command.`);
|
|
488
|
-
}
|
|
489
|
-
return usageLines.filter((l) => typeof l === 'string').join('\n');
|
|
490
|
-
}
|
|
491
|
-
async function runMain(cmd, opts = {}) {
|
|
492
|
-
const rawArgs = opts.rawArgs || process.argv.slice(2);
|
|
493
|
-
const showUsage$1 = opts.showUsage || showUsage;
|
|
494
|
-
try {
|
|
495
|
-
if (rawArgs.includes('--help') || rawArgs.includes('-h')) {
|
|
496
|
-
await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
|
|
497
|
-
process.exit(0);
|
|
498
|
-
} else if (rawArgs.length === 1 && rawArgs[0] === '--version') {
|
|
499
|
-
const meta = typeof cmd.meta === 'function' ? await cmd.meta() : await cmd.meta;
|
|
500
|
-
if (!meta?.version) {
|
|
501
|
-
throw new CLIError('No version specified', 'E_NO_VERSION');
|
|
502
|
-
}
|
|
503
|
-
consola.log(meta.version);
|
|
504
|
-
} else {
|
|
505
|
-
await runCommand(cmd, {rawArgs});
|
|
506
|
-
}
|
|
507
|
-
} catch (error) {
|
|
508
|
-
const isCLIError = error instanceof CLIError;
|
|
509
|
-
if (!isCLIError) {
|
|
510
|
-
consola.error(error, '\n');
|
|
511
|
-
}
|
|
512
|
-
if (isCLIError) {
|
|
513
|
-
await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
|
|
514
|
-
}
|
|
515
|
-
consola.error(error.message);
|
|
516
|
-
process.exit(1);
|
|
16
|
+
//#region src/cli/utils.ts
|
|
17
|
+
const logger = process.env.ROLLDOWN_TEST ? createTestingLogger() : createConsola({formatOptions: {date: false}});
|
|
18
|
+
function createTestingLogger() {
|
|
19
|
+
const types = ["silent", "fatal", "error", "warn", "log", "info", "success", "fail", "ready", "start", "box", "debug", "trace", "verbose",];
|
|
20
|
+
const ret = Object.create(null);
|
|
21
|
+
for (const type of types) {
|
|
22
|
+
ret[type] = console.log;
|
|
517
23
|
}
|
|
24
|
+
return ret;
|
|
518
25
|
}
|
|
519
|
-
|
|
520
|
-
//#endregion
|
|
521
|
-
//#region src/cli/utils.ts
|
|
522
|
-
const logger = createConsola({formatOptions: {date: false}});
|
|
523
26
|
async function ensureConfig(configPath) {
|
|
524
27
|
if (!isSupportedFormat(configPath)) {
|
|
525
|
-
throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(
|
|
28
|
+
throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${nodePath.extname(configPath)}\``);
|
|
526
29
|
}
|
|
527
|
-
const fileUrl = pathToFileURL(configPath).toString();
|
|
30
|
+
const fileUrl = (pathToFileURL(configPath)).toString();
|
|
528
31
|
const configExports = await import(fileUrl);
|
|
529
32
|
return configExports.default;
|
|
530
33
|
}
|
|
531
|
-
const SUPPORTED_CONFIG_FORMATS = [
|
|
34
|
+
const SUPPORTED_CONFIG_FORMATS = [".js", ".mjs", ".cjs"];
|
|
532
35
|
function isSupportedFormat(configPath) {
|
|
533
36
|
const ext = nodePath.extname(configPath);
|
|
534
37
|
return SUPPORTED_CONFIG_FORMATS.includes(ext);
|
|
@@ -536,22 +39,22 @@ function isSupportedFormat(configPath) {
|
|
|
536
39
|
|
|
537
40
|
//#endregion
|
|
538
41
|
//#region ../../node_modules/.pnpm/colorette@2.0.20/node_modules/colorette/index.js
|
|
539
|
-
const { env: env$1 = {}, argv = [], platform =
|
|
540
|
-
const isDisabled =
|
|
541
|
-
const isForced =
|
|
542
|
-
const isWindows = platform ===
|
|
543
|
-
const isDumbTerminal = env$1.TERM ===
|
|
42
|
+
const { env: env$1 = {}, argv: argv = [], platform: platform = "" } = typeof process === "undefined" ? {} : process;
|
|
43
|
+
const isDisabled = "NO_COLOR"in env$1 || argv.includes("--no-color");
|
|
44
|
+
const isForced = "FORCE_COLOR"in env$1 || argv.includes("--color");
|
|
45
|
+
const isWindows = platform === "win32";
|
|
46
|
+
const isDumbTerminal = env$1.TERM === "dumb";
|
|
544
47
|
const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env$1.TERM && !isDumbTerminal;
|
|
545
|
-
const isCI =
|
|
546
|
-
const isColorSupported = !isDisabled && (isForced ||
|
|
48
|
+
const isCI = "CI"in env$1 && ("GITHUB_ACTIONS"in env$1 || "GITLAB_CI"in env$1 || "CIRCLECI"in env$1);
|
|
49
|
+
const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
|
|
547
50
|
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));
|
|
548
51
|
const clearBleed = (index, string, open, close, replace) => index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
|
|
549
|
-
const filterEmpty = (open, close, replace = open, at = open.length + 1) => (string) => string || !(string ===
|
|
52
|
+
const filterEmpty = (open, close, replace = open, at = open.length + 1) => (string) => string || !(string === "" || string === undefined) ? clearBleed(("" + string).indexOf(close, at), string, open, close, replace) : "";
|
|
550
53
|
const init = (open, close, replace) => filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`, replace);
|
|
551
|
-
const colors
|
|
54
|
+
const colors = {
|
|
552
55
|
reset: init(0, 0),
|
|
553
|
-
bold: init(1, 22,
|
|
554
|
-
dim: init(2, 22,
|
|
56
|
+
bold: init(1, 22, "\x1B[22m\x1B[1m"),
|
|
57
|
+
dim: init(2, 22, "\x1B[22m\x1B[2m"),
|
|
555
58
|
italic: init(3, 23),
|
|
556
59
|
underline: init(4, 24),
|
|
557
60
|
inverse: init(7, 27),
|
|
@@ -591,11 +94,11 @@ const colors$1 = {
|
|
|
591
94
|
bgCyanBright: init(106, 49),
|
|
592
95
|
bgWhiteBright: init(107, 49)
|
|
593
96
|
};
|
|
594
|
-
const createColors = ({ useColor = isColorSupported } = {}) => useColor ? colors
|
|
595
|
-
...colors$
|
|
97
|
+
const createColors = ({ useColor: useColor = isColorSupported } = {}) => useColor ? colors : (Object.keys(colors)).reduce((colors$1, key) => ({
|
|
98
|
+
...colors$1,
|
|
596
99
|
[key]: String
|
|
597
100
|
}), {});
|
|
598
|
-
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();
|
|
101
|
+
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();
|
|
599
102
|
|
|
600
103
|
//#endregion
|
|
601
104
|
//#region src/cli/colors.ts
|
|
@@ -610,11 +113,11 @@ __export(colors_ns, {
|
|
|
610
113
|
underline: () => underline,
|
|
611
114
|
yellow: () => yellow
|
|
612
115
|
});
|
|
613
|
-
const { bold, cyan, dim, gray, green, red, underline, yellow } = createColors({useColor: env.FORCE_COLOR !==
|
|
116
|
+
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});
|
|
614
117
|
|
|
615
118
|
//#endregion
|
|
616
119
|
//#region src/cli/commands/bundle.ts
|
|
617
|
-
async function
|
|
120
|
+
async function bundleWithConfig(configPath, cliOptions) {
|
|
618
121
|
const config = await ensureConfig(configPath);
|
|
619
122
|
if (!config) {
|
|
620
123
|
logger.error(`No configuration found at ${config}`);
|
|
@@ -622,28 +125,53 @@ async function bundle(configPath) {
|
|
|
622
125
|
}
|
|
623
126
|
const configList = arraify(config);
|
|
624
127
|
for (const config$1 of configList) {
|
|
625
|
-
await bundleInner(config$1);
|
|
128
|
+
await bundleInner(config$1, cliOptions);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async function bundleWithCliOptions(cliOptions) {
|
|
132
|
+
if (cliOptions.output.dir) {
|
|
133
|
+
await bundleInner({}, cliOptions);
|
|
134
|
+
} else {
|
|
135
|
+
const build = await rolldown(cliOptions.input);
|
|
136
|
+
const { output: output } = await build.generate(cliOptions.output);
|
|
137
|
+
if (output.length > 1) {
|
|
138
|
+
logger.error("Multiple chunks are not supported to display in stdout");
|
|
139
|
+
process.exit(1);
|
|
140
|
+
} else if (output.length === 0) {
|
|
141
|
+
logger.error("No output generated");
|
|
142
|
+
process.exit(1);
|
|
143
|
+
} else {
|
|
144
|
+
logger.log(output[0].code);
|
|
145
|
+
}
|
|
626
146
|
}
|
|
627
147
|
}
|
|
628
|
-
async function bundleInner(options) {
|
|
148
|
+
async function bundleInner(options$1, cliOptions) {
|
|
629
149
|
const startTime = performance.now();
|
|
630
|
-
const build = await rolldown(
|
|
631
|
-
|
|
150
|
+
const build = await rolldown({
|
|
151
|
+
...options$1,
|
|
152
|
+
...cliOptions.input
|
|
153
|
+
});
|
|
154
|
+
const bundleOutput = await build.write({
|
|
155
|
+
...options$1?.output,
|
|
156
|
+
...cliOptions.output
|
|
157
|
+
});
|
|
632
158
|
const endTime = performance.now();
|
|
633
159
|
printBundleOutputPretty(bundleOutput);
|
|
634
160
|
logger.log(``);
|
|
635
|
-
|
|
161
|
+
const duration = endTime - startTime;
|
|
162
|
+
const spent = duration < 1000 ? `${duration.toFixed(2)} ms` : `${(duration / 1000).toFixed(2)} s`;
|
|
163
|
+
logger.success(`Finished in ${bold(spent)}`);
|
|
636
164
|
}
|
|
637
165
|
function printBundleOutputPretty(output) {
|
|
638
166
|
const outputEntries = collectOutputEntries(output.output);
|
|
639
167
|
const outputLayoutSizes = collectOutputLayoutAdjustmentSizes(outputEntries);
|
|
640
|
-
printOutputEntries(outputEntries, outputLayoutSizes,
|
|
168
|
+
printOutputEntries(outputEntries, outputLayoutSizes, "<DIR>");
|
|
641
169
|
}
|
|
642
170
|
function collectOutputEntries(output) {
|
|
643
171
|
return output.map((chunk) => ({
|
|
644
172
|
type: chunk.type,
|
|
645
173
|
fileName: chunk.fileName,
|
|
646
|
-
size: chunk.type ===
|
|
174
|
+
size: chunk.type === "chunk" ? chunk.code.length : chunk.source.length
|
|
647
175
|
}));
|
|
648
176
|
}
|
|
649
177
|
function collectOutputLayoutAdjustmentSizes(entries) {
|
|
@@ -657,14 +185,14 @@ function collectOutputLayoutAdjustmentSizes(entries) {
|
|
|
657
185
|
biggestSize = entry.size;
|
|
658
186
|
}
|
|
659
187
|
}
|
|
660
|
-
const sizePad = displaySize(biggestSize).length;
|
|
188
|
+
const sizePad = (displaySize(biggestSize)).length;
|
|
661
189
|
return {
|
|
662
190
|
longest,
|
|
663
191
|
biggestSize,
|
|
664
192
|
sizePad
|
|
665
193
|
};
|
|
666
194
|
}
|
|
667
|
-
const numberFormatter = new Intl.NumberFormat(
|
|
195
|
+
const numberFormatter = new Intl.NumberFormat("en", {
|
|
668
196
|
maximumFractionDigits: 2,
|
|
669
197
|
minimumFractionDigits: 2
|
|
670
198
|
});
|
|
@@ -672,11 +200,11 @@ function displaySize(bytes) {
|
|
|
672
200
|
return `${numberFormatter.format(bytes / 1000)} kB`;
|
|
673
201
|
}
|
|
674
202
|
const CHUNK_GROUPS = [{
|
|
675
|
-
type:
|
|
676
|
-
color:
|
|
203
|
+
type: "asset",
|
|
204
|
+
color: "green"
|
|
677
205
|
}, {
|
|
678
|
-
type:
|
|
679
|
-
color:
|
|
206
|
+
type: "chunk",
|
|
207
|
+
color: "cyan"
|
|
680
208
|
},];
|
|
681
209
|
function printOutputEntries(entries, sizeAdjustment, distPath) {
|
|
682
210
|
for (const group of CHUNK_GROUPS) {
|
|
@@ -684,65 +212,1505 @@ function printOutputEntries(entries, sizeAdjustment, distPath) {
|
|
|
684
212
|
if (!filtered.length) {
|
|
685
213
|
continue;
|
|
686
214
|
}
|
|
687
|
-
for (const entry of filtered.sort((a, z) => a.size - z.size)) {
|
|
215
|
+
for (const entry of filtered.sort((a, z$4) => a.size - z$4.size)) {
|
|
688
216
|
let log = dim(withTrailingSlash(distPath));
|
|
689
217
|
log += colors_ns[group.color](entry.fileName.padEnd(sizeAdjustment.longest + 2));
|
|
690
218
|
log += dim(entry.type);
|
|
691
|
-
log += dim(` │ size: ${displaySize(entry.size).padStart(sizeAdjustment.sizePad)}`);
|
|
219
|
+
log += dim(` │ size: ${(displaySize(entry.size)).padStart(sizeAdjustment.sizePad)}`);
|
|
692
220
|
logger.log(log);
|
|
693
221
|
}
|
|
694
222
|
}
|
|
695
223
|
}
|
|
696
224
|
function withTrailingSlash(path) {
|
|
697
|
-
if (path[path.length - 1] !==
|
|
225
|
+
if (path[path.length - 1] !== "/") {
|
|
698
226
|
return `${path}/`;
|
|
699
227
|
}
|
|
700
228
|
return path;
|
|
701
229
|
}
|
|
702
230
|
|
|
703
231
|
//#endregion
|
|
704
|
-
//#region
|
|
705
|
-
const
|
|
706
|
-
const
|
|
232
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
233
|
+
const ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
234
|
+
const defaultOptions = {
|
|
235
|
+
name: undefined,
|
|
236
|
+
$refStrategy: "root",
|
|
237
|
+
basePath: ["#"],
|
|
238
|
+
effectStrategy: "input",
|
|
239
|
+
pipeStrategy: "all",
|
|
240
|
+
dateStrategy: "format:date-time",
|
|
241
|
+
mapStrategy: "entries",
|
|
242
|
+
removeAdditionalStrategy: "passthrough",
|
|
243
|
+
definitionPath: "definitions",
|
|
244
|
+
target: "jsonSchema7",
|
|
245
|
+
strictUnions: false,
|
|
246
|
+
definitions: {},
|
|
247
|
+
errorMessages: false,
|
|
248
|
+
markdownDescription: false,
|
|
249
|
+
patternStrategy: "escape",
|
|
250
|
+
applyRegexFlags: false,
|
|
251
|
+
emailStrategy: "format:email",
|
|
252
|
+
base64Strategy: "contentEncoding:base64",
|
|
253
|
+
nameStrategy: "ref"
|
|
254
|
+
};
|
|
255
|
+
const getDefaultOptions = (options$1) => typeof options$1 === "string" ? {
|
|
256
|
+
...defaultOptions,
|
|
257
|
+
name: options$1
|
|
258
|
+
} : {
|
|
259
|
+
...defaultOptions,
|
|
260
|
+
...options$1
|
|
261
|
+
};
|
|
707
262
|
|
|
708
263
|
//#endregion
|
|
709
|
-
//#region
|
|
710
|
-
const
|
|
264
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/Refs.js
|
|
265
|
+
const getRefs = (options$1) => {
|
|
266
|
+
const _options = getDefaultOptions(options$1);
|
|
267
|
+
const currentPath = _options.name !== undefined ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
268
|
+
return {
|
|
269
|
+
..._options,
|
|
270
|
+
currentPath: currentPath,
|
|
271
|
+
propertyPath: undefined,
|
|
272
|
+
seen: new Map((Object.entries(_options.definitions)).map(([name, def]) => [def._def, {
|
|
273
|
+
def: def._def,
|
|
274
|
+
path: [..._options.basePath, _options.definitionPath, name],
|
|
275
|
+
jsonSchema: undefined
|
|
276
|
+
},]))
|
|
277
|
+
};
|
|
278
|
+
};
|
|
711
279
|
|
|
712
280
|
//#endregion
|
|
713
|
-
//#region
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
281
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/errorMessages.js
|
|
282
|
+
function addErrorMessage(res, key, errorMessage, refs) {
|
|
283
|
+
if (!refs?.errorMessages) return;
|
|
284
|
+
if (errorMessage) {
|
|
285
|
+
res.errorMessage = {
|
|
286
|
+
...res.errorMessage,
|
|
287
|
+
[key]: errorMessage
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
|
|
292
|
+
res[key] = value;
|
|
293
|
+
addErrorMessage(res, key, errorMessage, refs);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/any.js
|
|
298
|
+
function parseAnyDef() {
|
|
299
|
+
return {};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
//#endregion
|
|
303
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/array.js
|
|
304
|
+
function parseArrayDef(def, refs) {
|
|
305
|
+
const res = {type: "array"};
|
|
306
|
+
if (def.type?._def?.typeName !== ZodFirstPartyTypeKind$2.ZodAny) {
|
|
307
|
+
res.items = parseDef(def.type._def, {
|
|
308
|
+
...refs,
|
|
309
|
+
currentPath: [...refs.currentPath, "items"]
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
if (def.minLength) {
|
|
313
|
+
setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
|
|
314
|
+
}
|
|
315
|
+
if (def.maxLength) {
|
|
316
|
+
setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
|
|
317
|
+
}
|
|
318
|
+
if (def.exactLength) {
|
|
319
|
+
setResponseValueAndErrors(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
|
|
320
|
+
setResponseValueAndErrors(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
|
|
321
|
+
}
|
|
322
|
+
return res;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
//#endregion
|
|
326
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js
|
|
327
|
+
function parseBigintDef(def, refs) {
|
|
328
|
+
const res = {
|
|
329
|
+
type: "integer",
|
|
330
|
+
format: "int64"
|
|
331
|
+
};
|
|
332
|
+
if (!def.checks) return res;
|
|
333
|
+
for (const check of def.checks) {
|
|
334
|
+
switch (check.kind) {
|
|
335
|
+
case "min":
|
|
336
|
+
if (refs.target === "jsonSchema7") {
|
|
337
|
+
if (check.inclusive) {
|
|
338
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
339
|
+
} else {
|
|
340
|
+
setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
341
|
+
}
|
|
342
|
+
} else {
|
|
343
|
+
if (!check.inclusive) {
|
|
344
|
+
res.exclusiveMinimum = true;
|
|
345
|
+
}
|
|
346
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
347
|
+
}
|
|
348
|
+
break;
|
|
349
|
+
case "max":
|
|
350
|
+
if (refs.target === "jsonSchema7") {
|
|
351
|
+
if (check.inclusive) {
|
|
352
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
353
|
+
} else {
|
|
354
|
+
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
355
|
+
}
|
|
356
|
+
} else {
|
|
357
|
+
if (!check.inclusive) {
|
|
358
|
+
res.exclusiveMaximum = true;
|
|
359
|
+
}
|
|
360
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
361
|
+
}
|
|
362
|
+
break;
|
|
363
|
+
case "multipleOf":
|
|
364
|
+
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return res;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
//#endregion
|
|
372
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js
|
|
373
|
+
function parseBooleanDef() {
|
|
374
|
+
return {type: "boolean"};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
//#endregion
|
|
378
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js
|
|
379
|
+
function parseBrandedDef(_def, refs) {
|
|
380
|
+
return parseDef(_def.type._def, refs);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
//#endregion
|
|
384
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js
|
|
385
|
+
const parseCatchDef = (def, refs) => {
|
|
386
|
+
return parseDef(def.innerType._def, refs);
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
//#endregion
|
|
390
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/date.js
|
|
391
|
+
function parseDateDef(def, refs, overrideDateStrategy) {
|
|
392
|
+
const strategy = overrideDateStrategy ?? refs.dateStrategy;
|
|
393
|
+
if (Array.isArray(strategy)) {
|
|
394
|
+
return {anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))};
|
|
395
|
+
}
|
|
396
|
+
switch (strategy) {
|
|
397
|
+
case "string":
|
|
398
|
+
case "format:date-time": return {
|
|
399
|
+
type: "string",
|
|
400
|
+
format: "date-time"
|
|
401
|
+
};
|
|
402
|
+
case "format:date": return {
|
|
403
|
+
type: "string",
|
|
404
|
+
format: "date"
|
|
405
|
+
};
|
|
406
|
+
case "integer": return integerDateParser(def, refs);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
const integerDateParser = (def, refs) => {
|
|
410
|
+
const res = {
|
|
411
|
+
type: "integer",
|
|
412
|
+
format: "unix-time"
|
|
413
|
+
};
|
|
414
|
+
if (refs.target === "openApi3") {
|
|
415
|
+
return res;
|
|
416
|
+
}
|
|
417
|
+
for (const check of def.checks) {
|
|
418
|
+
switch (check.kind) {
|
|
419
|
+
case "min":
|
|
420
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
421
|
+
break;
|
|
422
|
+
case "max":
|
|
423
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return res;
|
|
428
|
+
};
|
|
429
|
+
|
|
430
|
+
//#endregion
|
|
431
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/default.js
|
|
432
|
+
function parseDefaultDef(_def, refs) {
|
|
433
|
+
return {
|
|
434
|
+
...parseDef(_def.innerType._def, refs),
|
|
435
|
+
default: _def.defaultValue()
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
//#endregion
|
|
440
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js
|
|
441
|
+
function parseEffectsDef(_def, refs) {
|
|
442
|
+
return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : {};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
//#endregion
|
|
446
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js
|
|
447
|
+
function parseEnumDef(def) {
|
|
448
|
+
return {
|
|
449
|
+
type: "string",
|
|
450
|
+
enum: def.values
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
//#endregion
|
|
455
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js
|
|
456
|
+
const isJsonSchema7AllOfType = (type) => {
|
|
457
|
+
if ("type"in type && type.type === "string") return false;
|
|
458
|
+
return "allOf"in type;
|
|
459
|
+
};
|
|
460
|
+
function parseIntersectionDef(def, refs) {
|
|
461
|
+
const allOf = [parseDef(def.left._def, {
|
|
462
|
+
...refs,
|
|
463
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
464
|
+
}), parseDef(def.right._def, {
|
|
465
|
+
...refs,
|
|
466
|
+
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
467
|
+
}),].filter((x) => !!x);
|
|
468
|
+
let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? {unevaluatedProperties: false} : undefined;
|
|
469
|
+
const mergedAllOf = [];
|
|
470
|
+
allOf.forEach((schema$1) => {
|
|
471
|
+
if (isJsonSchema7AllOfType(schema$1)) {
|
|
472
|
+
mergedAllOf.push(...schema$1.allOf);
|
|
473
|
+
if (schema$1.unevaluatedProperties === undefined) {
|
|
474
|
+
unevaluatedProperties = undefined;
|
|
475
|
+
}
|
|
476
|
+
} else {
|
|
477
|
+
let nestedSchema = schema$1;
|
|
478
|
+
if ("additionalProperties"in schema$1 && schema$1.additionalProperties === false) {
|
|
479
|
+
const { additionalProperties: additionalProperties,...rest } = schema$1;
|
|
480
|
+
nestedSchema = rest;
|
|
481
|
+
} else {
|
|
482
|
+
unevaluatedProperties = undefined;
|
|
483
|
+
}
|
|
484
|
+
mergedAllOf.push(nestedSchema);
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
return mergedAllOf.length ? {
|
|
488
|
+
allOf: mergedAllOf,
|
|
489
|
+
...unevaluatedProperties
|
|
490
|
+
} : undefined;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
//#endregion
|
|
494
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js
|
|
495
|
+
function parseLiteralDef(def, refs) {
|
|
496
|
+
const parsedType = typeof def.value;
|
|
497
|
+
if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
|
|
498
|
+
return {type: Array.isArray(def.value) ? "array" : "object"};
|
|
499
|
+
}
|
|
500
|
+
if (refs.target === "openApi3") {
|
|
501
|
+
return {
|
|
502
|
+
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
503
|
+
enum: [def.value]
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
return {
|
|
507
|
+
type: parsedType === "bigint" ? "integer" : parsedType,
|
|
508
|
+
const: def.value
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
//#endregion
|
|
513
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
|
|
514
|
+
let emojiRegex;
|
|
515
|
+
const zodPatterns = {
|
|
516
|
+
cuid: /^[cC][^\s-]{8,}$/,
|
|
517
|
+
cuid2: /^[0-9a-z]+$/,
|
|
518
|
+
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
519
|
+
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
520
|
+
emoji: () => {
|
|
521
|
+
if (emojiRegex === undefined) {
|
|
522
|
+
emojiRegex = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
|
|
523
|
+
}
|
|
524
|
+
return emojiRegex;
|
|
720
525
|
},
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
526
|
+
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}$/,
|
|
527
|
+
ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
|
|
528
|
+
ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
|
|
529
|
+
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
530
|
+
nanoid: /^[a-zA-Z0-9_-]{21}$/
|
|
531
|
+
};
|
|
532
|
+
function parseStringDef(def, refs) {
|
|
533
|
+
const res = {type: "string"};
|
|
534
|
+
function processPattern(value) {
|
|
535
|
+
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(value) : value;
|
|
536
|
+
}
|
|
537
|
+
if (def.checks) {
|
|
538
|
+
for (const check of def.checks) {
|
|
539
|
+
switch (check.kind) {
|
|
540
|
+
case "min":
|
|
541
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
542
|
+
break;
|
|
543
|
+
case "max":
|
|
544
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
545
|
+
break;
|
|
546
|
+
case "email":
|
|
547
|
+
switch (refs.emailStrategy) {
|
|
548
|
+
case "format:email":
|
|
549
|
+
addFormat(res, "email", check.message, refs);
|
|
550
|
+
break;
|
|
551
|
+
case "format:idn-email":
|
|
552
|
+
addFormat(res, "idn-email", check.message, refs);
|
|
553
|
+
break;
|
|
554
|
+
case "pattern:zod":
|
|
555
|
+
addPattern(res, zodPatterns.email, check.message, refs);
|
|
556
|
+
break;
|
|
557
|
+
}
|
|
558
|
+
break;
|
|
559
|
+
case "url":
|
|
560
|
+
addFormat(res, "uri", check.message, refs);
|
|
561
|
+
break;
|
|
562
|
+
case "uuid":
|
|
563
|
+
addFormat(res, "uuid", check.message, refs);
|
|
564
|
+
break;
|
|
565
|
+
case "regex":
|
|
566
|
+
addPattern(res, check.regex, check.message, refs);
|
|
567
|
+
break;
|
|
568
|
+
case "cuid":
|
|
569
|
+
addPattern(res, zodPatterns.cuid, check.message, refs);
|
|
570
|
+
break;
|
|
571
|
+
case "cuid2":
|
|
572
|
+
addPattern(res, zodPatterns.cuid2, check.message, refs);
|
|
573
|
+
break;
|
|
574
|
+
case "startsWith":
|
|
575
|
+
addPattern(res, RegExp(`^${processPattern(check.value)}`), check.message, refs);
|
|
576
|
+
break;
|
|
577
|
+
case "endsWith":
|
|
578
|
+
addPattern(res, RegExp(`${processPattern(check.value)}$`), check.message, refs);
|
|
579
|
+
break;
|
|
580
|
+
case "datetime":
|
|
581
|
+
addFormat(res, "date-time", check.message, refs);
|
|
582
|
+
break;
|
|
583
|
+
case "date":
|
|
584
|
+
addFormat(res, "date", check.message, refs);
|
|
585
|
+
break;
|
|
586
|
+
case "time":
|
|
587
|
+
addFormat(res, "time", check.message, refs);
|
|
588
|
+
break;
|
|
589
|
+
case "duration":
|
|
590
|
+
addFormat(res, "duration", check.message, refs);
|
|
591
|
+
break;
|
|
592
|
+
case "length":
|
|
593
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
|
|
594
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
|
|
595
|
+
break;
|
|
596
|
+
case "includes": {
|
|
597
|
+
addPattern(res, RegExp(processPattern(check.value)), check.message, refs);
|
|
598
|
+
break;
|
|
599
|
+
}
|
|
600
|
+
case "ip": {
|
|
601
|
+
if (check.version !== "v6") {
|
|
602
|
+
addFormat(res, "ipv4", check.message, refs);
|
|
603
|
+
}
|
|
604
|
+
if (check.version !== "v4") {
|
|
605
|
+
addFormat(res, "ipv6", check.message, refs);
|
|
606
|
+
}
|
|
607
|
+
break;
|
|
608
|
+
}
|
|
609
|
+
case "emoji":
|
|
610
|
+
addPattern(res, zodPatterns.emoji, check.message, refs);
|
|
611
|
+
break;
|
|
612
|
+
case "ulid": {
|
|
613
|
+
addPattern(res, zodPatterns.ulid, check.message, refs);
|
|
614
|
+
break;
|
|
615
|
+
}
|
|
616
|
+
case "base64": {
|
|
617
|
+
switch (refs.base64Strategy) {
|
|
618
|
+
case "format:binary": {
|
|
619
|
+
addFormat(res, "binary", check.message, refs);
|
|
620
|
+
break;
|
|
621
|
+
}
|
|
622
|
+
case "contentEncoding:base64": {
|
|
623
|
+
setResponseValueAndErrors(res, "contentEncoding", "base64", check.message, refs);
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
case "pattern:zod": {
|
|
627
|
+
addPattern(res, zodPatterns.base64, check.message, refs);
|
|
628
|
+
break;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
break;
|
|
632
|
+
}
|
|
633
|
+
case "nanoid": {
|
|
634
|
+
addPattern(res, zodPatterns.nanoid, check.message, refs);
|
|
635
|
+
}
|
|
636
|
+
case "toLowerCase":
|
|
637
|
+
case "toUpperCase":
|
|
638
|
+
case "trim": break;
|
|
639
|
+
default: ((_) => {})(check);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
return res;
|
|
644
|
+
}
|
|
645
|
+
const escapeNonAlphaNumeric = (value) => ((Array.from(value)).map((c) => /[a-zA-Z0-9]/.test(c) ? c : `\\${c}`)).join("");
|
|
646
|
+
const addFormat = (schema$1, value, message, refs) => {
|
|
647
|
+
if (schema$1.format || schema$1.anyOf?.some((x) => x.format)) {
|
|
648
|
+
if (!schema$1.anyOf) {
|
|
649
|
+
schema$1.anyOf = [];
|
|
650
|
+
}
|
|
651
|
+
if (schema$1.format) {
|
|
652
|
+
schema$1.anyOf.push({
|
|
653
|
+
format: schema$1.format,
|
|
654
|
+
...schema$1.errorMessage && refs.errorMessages && {errorMessage: {format: schema$1.errorMessage.format}}
|
|
655
|
+
});
|
|
656
|
+
delete schema$1.format;
|
|
657
|
+
if (schema$1.errorMessage) {
|
|
658
|
+
delete schema$1.errorMessage.format;
|
|
659
|
+
if ((Object.keys(schema$1.errorMessage)).length === 0) {
|
|
660
|
+
delete schema$1.errorMessage;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
schema$1.anyOf.push({
|
|
665
|
+
format: value,
|
|
666
|
+
...message && refs.errorMessages && {errorMessage: {format: message}}
|
|
667
|
+
});
|
|
668
|
+
} else {
|
|
669
|
+
setResponseValueAndErrors(schema$1, "format", value, message, refs);
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
const addPattern = (schema$1, regex, message, refs) => {
|
|
673
|
+
if (schema$1.pattern || schema$1.allOf?.some((x) => x.pattern)) {
|
|
674
|
+
if (!schema$1.allOf) {
|
|
675
|
+
schema$1.allOf = [];
|
|
676
|
+
}
|
|
677
|
+
if (schema$1.pattern) {
|
|
678
|
+
schema$1.allOf.push({
|
|
679
|
+
pattern: schema$1.pattern,
|
|
680
|
+
...schema$1.errorMessage && refs.errorMessages && {errorMessage: {pattern: schema$1.errorMessage.pattern}}
|
|
681
|
+
});
|
|
682
|
+
delete schema$1.pattern;
|
|
683
|
+
if (schema$1.errorMessage) {
|
|
684
|
+
delete schema$1.errorMessage.pattern;
|
|
685
|
+
if ((Object.keys(schema$1.errorMessage)).length === 0) {
|
|
686
|
+
delete schema$1.errorMessage;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
schema$1.allOf.push({
|
|
691
|
+
pattern: processRegExp(regex, refs),
|
|
692
|
+
...message && refs.errorMessages && {errorMessage: {pattern: message}}
|
|
693
|
+
});
|
|
694
|
+
} else {
|
|
695
|
+
setResponseValueAndErrors(schema$1, "pattern", processRegExp(regex, refs), message, refs);
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
const processRegExp = (regexOrFunction, refs) => {
|
|
699
|
+
const regex = typeof regexOrFunction === "function" ? regexOrFunction() : regexOrFunction;
|
|
700
|
+
if (!refs.applyRegexFlags || !regex.flags) return regex.source;
|
|
701
|
+
const flags = {
|
|
702
|
+
i: regex.flags.includes("i"),
|
|
703
|
+
m: regex.flags.includes("m"),
|
|
704
|
+
s: regex.flags.includes("s")
|
|
705
|
+
};
|
|
706
|
+
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
707
|
+
let pattern = "";
|
|
708
|
+
let isEscaped = false;
|
|
709
|
+
let inCharGroup = false;
|
|
710
|
+
let inCharRange = false;
|
|
711
|
+
for (let i = 0; i < source.length; i++) {
|
|
712
|
+
if (isEscaped) {
|
|
713
|
+
pattern += source[i];
|
|
714
|
+
isEscaped = false;
|
|
715
|
+
continue;
|
|
716
|
+
}
|
|
717
|
+
if (flags.i) {
|
|
718
|
+
if (inCharGroup) {
|
|
719
|
+
if (source[i].match(/[a-z]/)) {
|
|
720
|
+
if (inCharRange) {
|
|
721
|
+
pattern += source[i];
|
|
722
|
+
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
723
|
+
inCharRange = false;
|
|
724
|
+
} else if (source[i + 1] === "-" && source[i + 2]?.match(/[a-z]/)) {
|
|
725
|
+
pattern += source[i];
|
|
726
|
+
inCharRange = true;
|
|
727
|
+
} else {
|
|
728
|
+
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
729
|
+
}
|
|
730
|
+
continue;
|
|
731
|
+
}
|
|
732
|
+
} else if (source[i].match(/[a-z]/)) {
|
|
733
|
+
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
734
|
+
continue;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
if (flags.m) {
|
|
738
|
+
if (source[i] === "^") {
|
|
739
|
+
pattern += `(^|(?<=[\r\n]))`;
|
|
740
|
+
continue;
|
|
741
|
+
} else if (source[i] === "$") {
|
|
742
|
+
pattern += `($|(?=[\r\n]))`;
|
|
743
|
+
continue;
|
|
744
|
+
}
|
|
731
745
|
}
|
|
746
|
+
if (flags.s && source[i] === ".") {
|
|
747
|
+
pattern += inCharGroup ? `${source[i]}\r\n` : `[${source[i]}\r\n]`;
|
|
748
|
+
continue;
|
|
749
|
+
}
|
|
750
|
+
pattern += source[i];
|
|
751
|
+
if (source[i] === "\\") {
|
|
752
|
+
isEscaped = true;
|
|
753
|
+
} else if (inCharGroup && source[i] === "]") {
|
|
754
|
+
inCharGroup = false;
|
|
755
|
+
} else if (!inCharGroup && source[i] === "[") {
|
|
756
|
+
inCharGroup = true;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
try {
|
|
760
|
+
const regexTest = new RegExp(pattern);
|
|
761
|
+
} catch {
|
|
762
|
+
console.warn(`Could not convert regex pattern at ${refs.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`);
|
|
763
|
+
return regex.source;
|
|
764
|
+
}
|
|
765
|
+
return pattern;
|
|
766
|
+
};
|
|
767
|
+
|
|
768
|
+
//#endregion
|
|
769
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
770
|
+
function parseRecordDef(def, refs) {
|
|
771
|
+
if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind$1.ZodEnum) {
|
|
772
|
+
return {
|
|
773
|
+
type: "object",
|
|
774
|
+
required: def.keyType._def.values,
|
|
775
|
+
properties: def.keyType._def.values.reduce((acc, key) => ({
|
|
776
|
+
...acc,
|
|
777
|
+
[key]: parseDef(def.valueType._def, {
|
|
778
|
+
...refs,
|
|
779
|
+
currentPath: [...refs.currentPath, "properties", key]
|
|
780
|
+
}) ?? {}
|
|
781
|
+
}), {}),
|
|
782
|
+
additionalProperties: false
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
const schema$1 = {
|
|
786
|
+
type: "object",
|
|
787
|
+
additionalProperties: parseDef(def.valueType._def, {
|
|
788
|
+
...refs,
|
|
789
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
790
|
+
}) ?? {}
|
|
791
|
+
};
|
|
792
|
+
if (refs.target === "openApi3") {
|
|
793
|
+
return schema$1;
|
|
794
|
+
}
|
|
795
|
+
if (def.keyType?._def.typeName === ZodFirstPartyTypeKind$1.ZodString && def.keyType._def.checks?.length) {
|
|
796
|
+
const keyType = (Object.entries(parseStringDef(def.keyType._def, refs))).reduce((acc, [key, value]) => key === "type" ? acc : {
|
|
797
|
+
...acc,
|
|
798
|
+
[key]: value
|
|
799
|
+
}, {});
|
|
800
|
+
return {
|
|
801
|
+
...schema$1,
|
|
802
|
+
propertyNames: keyType
|
|
803
|
+
};
|
|
804
|
+
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind$1.ZodEnum) {
|
|
805
|
+
return {
|
|
806
|
+
...schema$1,
|
|
807
|
+
propertyNames: {enum: def.keyType._def.values}
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
return schema$1;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
//#endregion
|
|
814
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/map.js
|
|
815
|
+
function parseMapDef(def, refs) {
|
|
816
|
+
if (refs.mapStrategy === "record") {
|
|
817
|
+
return parseRecordDef(def, refs);
|
|
818
|
+
}
|
|
819
|
+
const keys = parseDef(def.keyType._def, {
|
|
820
|
+
...refs,
|
|
821
|
+
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
822
|
+
}) || {};
|
|
823
|
+
const values = parseDef(def.valueType._def, {
|
|
824
|
+
...refs,
|
|
825
|
+
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
826
|
+
}) || {};
|
|
827
|
+
return {
|
|
828
|
+
type: "array",
|
|
829
|
+
maxItems: 125,
|
|
830
|
+
items: {
|
|
831
|
+
type: "array",
|
|
832
|
+
items: [keys, values],
|
|
833
|
+
minItems: 2,
|
|
834
|
+
maxItems: 2
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
//#endregion
|
|
840
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js
|
|
841
|
+
function parseNativeEnumDef(def) {
|
|
842
|
+
const object = def.values;
|
|
843
|
+
const actualKeys = (Object.keys(def.values)).filter((key) => {
|
|
844
|
+
return typeof object[object[key]] !== "number";
|
|
845
|
+
});
|
|
846
|
+
const actualValues = actualKeys.map((key) => object[key]);
|
|
847
|
+
const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
|
|
848
|
+
return {
|
|
849
|
+
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
850
|
+
enum: actualValues
|
|
851
|
+
};
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
//#endregion
|
|
855
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/never.js
|
|
856
|
+
function parseNeverDef() {
|
|
857
|
+
return {not: {}};
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
//#endregion
|
|
861
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/null.js
|
|
862
|
+
function parseNullDef(refs) {
|
|
863
|
+
return refs.target === "openApi3" ? {
|
|
864
|
+
enum: ["null"],
|
|
865
|
+
nullable: true
|
|
866
|
+
} : {type: "null"};
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
//#endregion
|
|
870
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/union.js
|
|
871
|
+
const primitiveMappings = {
|
|
872
|
+
ZodString: "string",
|
|
873
|
+
ZodNumber: "number",
|
|
874
|
+
ZodBigInt: "integer",
|
|
875
|
+
ZodBoolean: "boolean",
|
|
876
|
+
ZodNull: "null"
|
|
877
|
+
};
|
|
878
|
+
function parseUnionDef(def, refs) {
|
|
879
|
+
if (refs.target === "openApi3") return asAnyOf(def, refs);
|
|
880
|
+
const options$1 = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
881
|
+
if (options$1.every((x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length))) {
|
|
882
|
+
const types = options$1.reduce((types$1, x) => {
|
|
883
|
+
const type = primitiveMappings[x._def.typeName];
|
|
884
|
+
return type && !types$1.includes(type) ? [...types$1, type] : types$1;
|
|
885
|
+
}, []);
|
|
886
|
+
return {type: types.length > 1 ? types : types[0]};
|
|
887
|
+
} else if (options$1.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
888
|
+
const types = options$1.reduce((acc, x) => {
|
|
889
|
+
const type = typeof x._def.value;
|
|
890
|
+
switch (type) {
|
|
891
|
+
case "string":
|
|
892
|
+
case "number":
|
|
893
|
+
case "boolean": return [...acc, type];
|
|
894
|
+
case "bigint": return [...acc, "integer"];
|
|
895
|
+
case "object": if (x._def.value === null) return [...acc, "null"];
|
|
896
|
+
case "symbol":
|
|
897
|
+
case "undefined":
|
|
898
|
+
case "function":
|
|
899
|
+
default: return acc;
|
|
900
|
+
}
|
|
901
|
+
}, []);
|
|
902
|
+
if (types.length === options$1.length) {
|
|
903
|
+
const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
|
|
904
|
+
return {
|
|
905
|
+
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
906
|
+
enum: options$1.reduce((acc, x) => {
|
|
907
|
+
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
908
|
+
}, [])
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
} else if (options$1.every((x) => x._def.typeName === "ZodEnum")) {
|
|
912
|
+
return {
|
|
913
|
+
type: "string",
|
|
914
|
+
enum: options$1.reduce((acc, x) => [...acc, ...x._def.values.filter((x$1) => !acc.includes(x$1)),], [])
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
return asAnyOf(def, refs);
|
|
918
|
+
}
|
|
919
|
+
const asAnyOf = (def, refs) => {
|
|
920
|
+
const anyOf = ((def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef(x._def, {
|
|
921
|
+
...refs,
|
|
922
|
+
currentPath: [...refs.currentPath, "anyOf", `${i}`]
|
|
923
|
+
}))).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && (Object.keys(x)).length > 0));
|
|
924
|
+
return anyOf.length ? {anyOf} : undefined;
|
|
925
|
+
};
|
|
926
|
+
|
|
927
|
+
//#endregion
|
|
928
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js
|
|
929
|
+
function parseNullableDef(def, refs) {
|
|
930
|
+
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
931
|
+
if (refs.target === "openApi3") {
|
|
932
|
+
return {
|
|
933
|
+
type: primitiveMappings[def.innerType._def.typeName],
|
|
934
|
+
nullable: true
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
return {type: [primitiveMappings[def.innerType._def.typeName], "null",]};
|
|
938
|
+
}
|
|
939
|
+
if (refs.target === "openApi3") {
|
|
940
|
+
const base$1 = parseDef(def.innerType._def, {
|
|
941
|
+
...refs,
|
|
942
|
+
currentPath: [...refs.currentPath]
|
|
943
|
+
});
|
|
944
|
+
if (base$1 && "$ref"in base$1) return {
|
|
945
|
+
allOf: [base$1],
|
|
946
|
+
nullable: true
|
|
947
|
+
};
|
|
948
|
+
return base$1 && {
|
|
949
|
+
...base$1,
|
|
950
|
+
nullable: true
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
const base = parseDef(def.innerType._def, {
|
|
954
|
+
...refs,
|
|
955
|
+
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
956
|
+
});
|
|
957
|
+
return base && {anyOf: [base, {type: "null"}]};
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
//#endregion
|
|
961
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/number.js
|
|
962
|
+
function parseNumberDef(def, refs) {
|
|
963
|
+
const res = {type: "number"};
|
|
964
|
+
if (!def.checks) return res;
|
|
965
|
+
for (const check of def.checks) {
|
|
966
|
+
switch (check.kind) {
|
|
967
|
+
case "int":
|
|
968
|
+
res.type = "integer";
|
|
969
|
+
addErrorMessage(res, "type", check.message, refs);
|
|
970
|
+
break;
|
|
971
|
+
case "min":
|
|
972
|
+
if (refs.target === "jsonSchema7") {
|
|
973
|
+
if (check.inclusive) {
|
|
974
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
975
|
+
} else {
|
|
976
|
+
setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
|
|
977
|
+
}
|
|
978
|
+
} else {
|
|
979
|
+
if (!check.inclusive) {
|
|
980
|
+
res.exclusiveMinimum = true;
|
|
981
|
+
}
|
|
982
|
+
setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
|
|
983
|
+
}
|
|
984
|
+
break;
|
|
985
|
+
case "max":
|
|
986
|
+
if (refs.target === "jsonSchema7") {
|
|
987
|
+
if (check.inclusive) {
|
|
988
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
989
|
+
} else {
|
|
990
|
+
setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
|
|
991
|
+
}
|
|
992
|
+
} else {
|
|
993
|
+
if (!check.inclusive) {
|
|
994
|
+
res.exclusiveMaximum = true;
|
|
995
|
+
}
|
|
996
|
+
setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
|
|
997
|
+
}
|
|
998
|
+
break;
|
|
999
|
+
case "multipleOf":
|
|
1000
|
+
setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
|
|
1001
|
+
break;
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
return res;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
//#endregion
|
|
1008
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/object.js
|
|
1009
|
+
function decideAdditionalProperties(def, refs) {
|
|
1010
|
+
if (refs.removeAdditionalStrategy === "strict") {
|
|
1011
|
+
return def.catchall._def.typeName === "ZodNever" ? def.unknownKeys !== "strict" : parseDef(def.catchall._def, {
|
|
1012
|
+
...refs,
|
|
1013
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1014
|
+
}) ?? true;
|
|
1015
|
+
} else {
|
|
1016
|
+
return def.catchall._def.typeName === "ZodNever" ? def.unknownKeys === "passthrough" : parseDef(def.catchall._def, {
|
|
1017
|
+
...refs,
|
|
1018
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
1019
|
+
}) ?? true;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
function parseObjectDef(def, refs) {
|
|
1023
|
+
const result = {
|
|
1024
|
+
type: "object",
|
|
1025
|
+
...(Object.entries(def.shape())).reduce((acc, [propName, propDef]) => {
|
|
1026
|
+
if (propDef === undefined || propDef._def === undefined) return acc;
|
|
1027
|
+
const parsedDef = parseDef(propDef._def, {
|
|
1028
|
+
...refs,
|
|
1029
|
+
currentPath: [...refs.currentPath, "properties", propName],
|
|
1030
|
+
propertyPath: [...refs.currentPath, "properties", propName]
|
|
1031
|
+
});
|
|
1032
|
+
if (parsedDef === undefined) return acc;
|
|
1033
|
+
return {
|
|
1034
|
+
properties: {
|
|
1035
|
+
...acc.properties,
|
|
1036
|
+
[propName]: parsedDef
|
|
1037
|
+
},
|
|
1038
|
+
required: propDef.isOptional() ? acc.required : [...acc.required, propName]
|
|
1039
|
+
};
|
|
1040
|
+
}, {
|
|
1041
|
+
properties: {},
|
|
1042
|
+
required: []
|
|
1043
|
+
}),
|
|
1044
|
+
additionalProperties: decideAdditionalProperties(def, refs)
|
|
1045
|
+
};
|
|
1046
|
+
if (!result.required.length) delete result.required;
|
|
1047
|
+
return result;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
//#endregion
|
|
1051
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js
|
|
1052
|
+
const parseOptionalDef = (def, refs) => {
|
|
1053
|
+
if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
|
|
1054
|
+
return parseDef(def.innerType._def, refs);
|
|
1055
|
+
}
|
|
1056
|
+
const innerSchema = parseDef(def.innerType._def, {
|
|
1057
|
+
...refs,
|
|
1058
|
+
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
1059
|
+
});
|
|
1060
|
+
return innerSchema ? {anyOf: [{not: {}}, innerSchema,]} : {};
|
|
1061
|
+
};
|
|
1062
|
+
|
|
1063
|
+
//#endregion
|
|
1064
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js
|
|
1065
|
+
const parsePipelineDef = (def, refs) => {
|
|
1066
|
+
if (refs.pipeStrategy === "input") {
|
|
1067
|
+
return parseDef(def.in._def, refs);
|
|
1068
|
+
} else if (refs.pipeStrategy === "output") {
|
|
1069
|
+
return parseDef(def.out._def, refs);
|
|
1070
|
+
}
|
|
1071
|
+
const a = parseDef(def.in._def, {
|
|
1072
|
+
...refs,
|
|
1073
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
1074
|
+
});
|
|
1075
|
+
const b = parseDef(def.out._def, {
|
|
1076
|
+
...refs,
|
|
1077
|
+
currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
|
|
1078
|
+
});
|
|
1079
|
+
return {allOf: [a, b].filter((x) => x !== undefined)};
|
|
1080
|
+
};
|
|
1081
|
+
|
|
1082
|
+
//#endregion
|
|
1083
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js
|
|
1084
|
+
function parsePromiseDef(def, refs) {
|
|
1085
|
+
return parseDef(def.type._def, refs);
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
//#endregion
|
|
1089
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/set.js
|
|
1090
|
+
function parseSetDef(def, refs) {
|
|
1091
|
+
const items = parseDef(def.valueType._def, {
|
|
1092
|
+
...refs,
|
|
1093
|
+
currentPath: [...refs.currentPath, "items"]
|
|
1094
|
+
});
|
|
1095
|
+
const schema$1 = {
|
|
1096
|
+
type: "array",
|
|
1097
|
+
uniqueItems: true,
|
|
1098
|
+
items
|
|
1099
|
+
};
|
|
1100
|
+
if (def.minSize) {
|
|
1101
|
+
setResponseValueAndErrors(schema$1, "minItems", def.minSize.value, def.minSize.message, refs);
|
|
1102
|
+
}
|
|
1103
|
+
if (def.maxSize) {
|
|
1104
|
+
setResponseValueAndErrors(schema$1, "maxItems", def.maxSize.value, def.maxSize.message, refs);
|
|
1105
|
+
}
|
|
1106
|
+
return schema$1;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
//#endregion
|
|
1110
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js
|
|
1111
|
+
function parseTupleDef(def, refs) {
|
|
1112
|
+
if (def.rest) {
|
|
1113
|
+
return {
|
|
1114
|
+
type: "array",
|
|
1115
|
+
minItems: def.items.length,
|
|
1116
|
+
items: (def.items.map((x, i) => parseDef(x._def, {
|
|
1117
|
+
...refs,
|
|
1118
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1119
|
+
}))).reduce((acc, x) => x === undefined ? acc : [...acc, x], []),
|
|
1120
|
+
additionalItems: parseDef(def.rest._def, {
|
|
1121
|
+
...refs,
|
|
1122
|
+
currentPath: [...refs.currentPath, "additionalItems"]
|
|
1123
|
+
})
|
|
1124
|
+
};
|
|
1125
|
+
} else {
|
|
1126
|
+
return {
|
|
1127
|
+
type: "array",
|
|
1128
|
+
minItems: def.items.length,
|
|
1129
|
+
maxItems: def.items.length,
|
|
1130
|
+
items: (def.items.map((x, i) => parseDef(x._def, {
|
|
1131
|
+
...refs,
|
|
1132
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
1133
|
+
}))).reduce((acc, x) => x === undefined ? acc : [...acc, x], [])
|
|
1134
|
+
};
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
//#endregion
|
|
1139
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js
|
|
1140
|
+
function parseUndefinedDef() {
|
|
1141
|
+
return {not: {}};
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
//#endregion
|
|
1145
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js
|
|
1146
|
+
function parseUnknownDef() {
|
|
1147
|
+
return {};
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
//#endregion
|
|
1151
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js
|
|
1152
|
+
const parseReadonlyDef = (def, refs) => {
|
|
1153
|
+
return parseDef(def.innerType._def, refs);
|
|
1154
|
+
};
|
|
1155
|
+
|
|
1156
|
+
//#endregion
|
|
1157
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/parseDef.js
|
|
1158
|
+
function parseDef(def, refs, forceResolution = false) {
|
|
1159
|
+
const seenItem = refs.seen.get(def);
|
|
1160
|
+
if (refs.override) {
|
|
1161
|
+
const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
|
|
1162
|
+
if (overrideResult !== ignoreOverride) {
|
|
1163
|
+
return overrideResult;
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
if (seenItem && !forceResolution) {
|
|
1167
|
+
const seenSchema = get$ref(seenItem, refs);
|
|
1168
|
+
if (seenSchema !== undefined) {
|
|
1169
|
+
return seenSchema;
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
const newItem = {
|
|
1173
|
+
def,
|
|
1174
|
+
path: refs.currentPath,
|
|
1175
|
+
jsonSchema: undefined
|
|
1176
|
+
};
|
|
1177
|
+
refs.seen.set(def, newItem);
|
|
1178
|
+
const jsonSchema = selectParser(def, def.typeName, refs);
|
|
1179
|
+
if (jsonSchema) {
|
|
1180
|
+
addMeta(def, refs, jsonSchema);
|
|
1181
|
+
}
|
|
1182
|
+
newItem.jsonSchema = jsonSchema;
|
|
1183
|
+
return jsonSchema;
|
|
1184
|
+
}
|
|
1185
|
+
const get$ref = (item, refs) => {
|
|
1186
|
+
switch (refs.$refStrategy) {
|
|
1187
|
+
case "root": return {$ref: item.path.join("/")};
|
|
1188
|
+
case "relative": return {$ref: getRelativePath(refs.currentPath, item.path)};
|
|
1189
|
+
case "none":
|
|
1190
|
+
case "seen": {
|
|
1191
|
+
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
1192
|
+
console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
|
|
1193
|
+
return {};
|
|
1194
|
+
}
|
|
1195
|
+
return refs.$refStrategy === "seen" ? {} : undefined;
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
};
|
|
1199
|
+
const getRelativePath = (pathA, pathB) => {
|
|
1200
|
+
let i = 0;
|
|
1201
|
+
for (; i < pathA.length && i < pathB.length; i++) {
|
|
1202
|
+
if (pathA[i] !== pathB[i]) break;
|
|
1203
|
+
}
|
|
1204
|
+
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
1205
|
+
};
|
|
1206
|
+
const selectParser = (def, typeName, refs) => {
|
|
1207
|
+
switch (typeName) {
|
|
1208
|
+
case ZodFirstPartyTypeKind.ZodString: return parseStringDef(def, refs);
|
|
1209
|
+
case ZodFirstPartyTypeKind.ZodNumber: return parseNumberDef(def, refs);
|
|
1210
|
+
case ZodFirstPartyTypeKind.ZodObject: return parseObjectDef(def, refs);
|
|
1211
|
+
case ZodFirstPartyTypeKind.ZodBigInt: return parseBigintDef(def, refs);
|
|
1212
|
+
case ZodFirstPartyTypeKind.ZodBoolean: return parseBooleanDef();
|
|
1213
|
+
case ZodFirstPartyTypeKind.ZodDate: return parseDateDef(def, refs);
|
|
1214
|
+
case ZodFirstPartyTypeKind.ZodUndefined: return parseUndefinedDef();
|
|
1215
|
+
case ZodFirstPartyTypeKind.ZodNull: return parseNullDef(refs);
|
|
1216
|
+
case ZodFirstPartyTypeKind.ZodArray: return parseArrayDef(def, refs);
|
|
1217
|
+
case ZodFirstPartyTypeKind.ZodUnion:
|
|
1218
|
+
case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: return parseUnionDef(def, refs);
|
|
1219
|
+
case ZodFirstPartyTypeKind.ZodIntersection: return parseIntersectionDef(def, refs);
|
|
1220
|
+
case ZodFirstPartyTypeKind.ZodTuple: return parseTupleDef(def, refs);
|
|
1221
|
+
case ZodFirstPartyTypeKind.ZodRecord: return parseRecordDef(def, refs);
|
|
1222
|
+
case ZodFirstPartyTypeKind.ZodLiteral: return parseLiteralDef(def, refs);
|
|
1223
|
+
case ZodFirstPartyTypeKind.ZodEnum: return parseEnumDef(def);
|
|
1224
|
+
case ZodFirstPartyTypeKind.ZodNativeEnum: return parseNativeEnumDef(def);
|
|
1225
|
+
case ZodFirstPartyTypeKind.ZodNullable: return parseNullableDef(def, refs);
|
|
1226
|
+
case ZodFirstPartyTypeKind.ZodOptional: return parseOptionalDef(def, refs);
|
|
1227
|
+
case ZodFirstPartyTypeKind.ZodMap: return parseMapDef(def, refs);
|
|
1228
|
+
case ZodFirstPartyTypeKind.ZodSet: return parseSetDef(def, refs);
|
|
1229
|
+
case ZodFirstPartyTypeKind.ZodLazy: return parseDef((def.getter())._def, refs);
|
|
1230
|
+
case ZodFirstPartyTypeKind.ZodPromise: return parsePromiseDef(def, refs);
|
|
1231
|
+
case ZodFirstPartyTypeKind.ZodNaN:
|
|
1232
|
+
case ZodFirstPartyTypeKind.ZodNever: return parseNeverDef();
|
|
1233
|
+
case ZodFirstPartyTypeKind.ZodEffects: return parseEffectsDef(def, refs);
|
|
1234
|
+
case ZodFirstPartyTypeKind.ZodAny: return parseAnyDef();
|
|
1235
|
+
case ZodFirstPartyTypeKind.ZodUnknown: return parseUnknownDef();
|
|
1236
|
+
case ZodFirstPartyTypeKind.ZodDefault: return parseDefaultDef(def, refs);
|
|
1237
|
+
case ZodFirstPartyTypeKind.ZodBranded: return parseBrandedDef(def, refs);
|
|
1238
|
+
case ZodFirstPartyTypeKind.ZodReadonly: return parseReadonlyDef(def, refs);
|
|
1239
|
+
case ZodFirstPartyTypeKind.ZodCatch: return parseCatchDef(def, refs);
|
|
1240
|
+
case ZodFirstPartyTypeKind.ZodPipeline: return parsePipelineDef(def, refs);
|
|
1241
|
+
case ZodFirstPartyTypeKind.ZodFunction:
|
|
1242
|
+
case ZodFirstPartyTypeKind.ZodVoid:
|
|
1243
|
+
case ZodFirstPartyTypeKind.ZodSymbol: return undefined;
|
|
1244
|
+
default: return ((_) => undefined)(typeName);
|
|
1245
|
+
}
|
|
1246
|
+
};
|
|
1247
|
+
const addMeta = (def, refs, jsonSchema) => {
|
|
1248
|
+
if (def.description) {
|
|
1249
|
+
jsonSchema.description = def.description;
|
|
1250
|
+
if (refs.markdownDescription) {
|
|
1251
|
+
jsonSchema.markdownDescription = def.description;
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
return jsonSchema;
|
|
1255
|
+
};
|
|
1256
|
+
|
|
1257
|
+
//#endregion
|
|
1258
|
+
//#region ../../node_modules/.pnpm/zod-to-json-schema@3.23.2_zod@3.23.8/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js
|
|
1259
|
+
const zodToJsonSchema = (schema$1, options$1) => {
|
|
1260
|
+
const refs = getRefs(options$1);
|
|
1261
|
+
const definitions = typeof options$1 === "object" && options$1.definitions ? (Object.entries(options$1.definitions)).reduce((acc, [name$1, schema$2]) => ({
|
|
1262
|
+
...acc,
|
|
1263
|
+
[name$1]: parseDef(schema$2._def, {
|
|
1264
|
+
...refs,
|
|
1265
|
+
currentPath: [...refs.basePath, refs.definitionPath, name$1]
|
|
1266
|
+
}, true) ?? {}
|
|
1267
|
+
}), {}) : undefined;
|
|
1268
|
+
const name = typeof options$1 === "string" ? options$1 : options$1?.nameStrategy === "title" ? undefined : options$1?.name;
|
|
1269
|
+
const main$1 = parseDef(schema$1._def, name === undefined ? refs : {
|
|
1270
|
+
...refs,
|
|
1271
|
+
currentPath: [...refs.basePath, refs.definitionPath, name]
|
|
1272
|
+
}, false) ?? {};
|
|
1273
|
+
const title = typeof options$1 === "object" && options$1.name !== undefined && options$1.nameStrategy === "title" ? options$1.name : undefined;
|
|
1274
|
+
if (title !== undefined) {
|
|
1275
|
+
main$1.title = title;
|
|
1276
|
+
}
|
|
1277
|
+
const combined = name === undefined ? definitions ? {
|
|
1278
|
+
...main$1,
|
|
1279
|
+
[refs.definitionPath]: definitions
|
|
1280
|
+
} : main$1 : {
|
|
1281
|
+
$ref: [...refs.$refStrategy === "relative" ? [] : refs.basePath, refs.definitionPath, name,].join("/"),
|
|
1282
|
+
[refs.definitionPath]: {
|
|
1283
|
+
...definitions,
|
|
1284
|
+
[name]: main$1
|
|
1285
|
+
}
|
|
1286
|
+
};
|
|
1287
|
+
if (refs.target === "jsonSchema7") {
|
|
1288
|
+
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
1289
|
+
} else if (refs.target === "jsonSchema2019-09") {
|
|
1290
|
+
combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
|
|
1291
|
+
}
|
|
1292
|
+
return combined;
|
|
1293
|
+
};
|
|
1294
|
+
|
|
1295
|
+
//#endregion
|
|
1296
|
+
//#region src/utils/zod-ext.ts
|
|
1297
|
+
const stringOrRegExp = () => (z$3.string()).or(z$3.instanceof(RegExp));
|
|
1298
|
+
const optionalStringArray = () => ((z$3.string()).array()).optional();
|
|
1299
|
+
const returnTrue = () => true;
|
|
1300
|
+
const phantom = () => z$3.custom(returnTrue);
|
|
1301
|
+
const voidNullableWith = (t) => {
|
|
1302
|
+
return (voidNullable()).or(t);
|
|
1303
|
+
};
|
|
1304
|
+
const voidNullable = () => {
|
|
1305
|
+
return ((z$3.void()).or(z$3.null())).or(z$3.undefined());
|
|
1306
|
+
};
|
|
1307
|
+
|
|
1308
|
+
//#endregion
|
|
1309
|
+
//#region src/options/input-options.ts
|
|
1310
|
+
const inputOptionSchema = ((z$2.string()).or((z$2.string()).array())).or(z$2.record(z$2.string()));
|
|
1311
|
+
const externalSchema = ((stringOrRegExp()).or((stringOrRegExp()).array())).or(((z$2.function()).args(z$2.string(), (z$2.string()).optional(), z$2.boolean())).returns(voidNullableWith(z$2.boolean())));
|
|
1312
|
+
const moduleTypesSchema = z$2.record((((((((((z$2.literal("js")).or(z$2.literal("jsx"))).or(z$2.literal("ts"))).or(z$2.literal("tsx"))).or(z$2.literal("json"))).or(z$2.literal("text"))).or(z$2.literal("base64"))).or(z$2.literal("dataurl"))).or(z$2.literal("binary"))).or(z$2.literal("empty")));
|
|
1313
|
+
const inputOptionsSchema = z$2.strictObject({
|
|
1314
|
+
input: inputOptionSchema.optional(),
|
|
1315
|
+
plugins: ((phantom()).array()).optional(),
|
|
1316
|
+
external: externalSchema.optional(),
|
|
1317
|
+
resolve: (z$2.strictObject({
|
|
1318
|
+
alias: (z$2.record(z$2.string())).optional(),
|
|
1319
|
+
aliasFields: (z$2.array(z$2.array(z$2.string()))).optional(),
|
|
1320
|
+
conditionNames: optionalStringArray(),
|
|
1321
|
+
exportsFields: (z$2.array(z$2.array(z$2.string()))).optional(),
|
|
1322
|
+
extensions: optionalStringArray(),
|
|
1323
|
+
mainFields: optionalStringArray(),
|
|
1324
|
+
mainFiles: optionalStringArray(),
|
|
1325
|
+
modules: optionalStringArray(),
|
|
1326
|
+
symlinks: (z$2.boolean()).optional(),
|
|
1327
|
+
tsconfigFilename: (z$2.string()).optional()
|
|
1328
|
+
})).optional(),
|
|
1329
|
+
cwd: ((z$2.string()).describe("current working directory.")).optional(),
|
|
1330
|
+
platform: ((((z$2.literal("node")).or(z$2.literal("browser"))).or(z$2.literal("neutral"))).describe(`platform for which the code should be generated (node, ${underline("browser")}, neutral).`)).optional(),
|
|
1331
|
+
shimMissingExports: (z$2.boolean()).optional(),
|
|
1332
|
+
treeshake: (phantom()).optional(),
|
|
1333
|
+
logLevel: (LogLevelOptionSchema.describe(`log level (${dim("silent")}, ${underline(gray("info"))}, debug, ${yellow("warn")})`)).optional(),
|
|
1334
|
+
onLog: ((z$2.function()).args(LogLevelSchema, RollupLogSchema, (z$2.function()).args(LogLevelWithErrorSchema, RollupLogWithStringSchema))).optional(),
|
|
1335
|
+
onwarn: ((z$2.function()).args(RollupLogSchema, (z$2.function()).args(RollupLogWithStringSchema.or((z$2.function()).returns(RollupLogWithStringSchema))))).optional(),
|
|
1336
|
+
moduleTypes: (moduleTypesSchema.describe("module types for customized extensions.")).optional(),
|
|
1337
|
+
experimental: (z$2.strictObject({enableComposingJsPlugins: (z$2.boolean()).optional()})).optional(),
|
|
1338
|
+
define: ((z$2.record(z$2.string())).describe("define global variables")).optional(),
|
|
1339
|
+
inject: (z$2.record((z$2.string()).or(z$2.tuple([z$2.string(), z$2.string()])))).optional()
|
|
1340
|
+
});
|
|
1341
|
+
const inputCliOptionsSchema = (inputOptionsSchema.extend({
|
|
1342
|
+
external: ((z$2.array(z$2.string())).describe("Comma-separated list of module ids to exclude from the bundle `<module-id>,...`")).optional(),
|
|
1343
|
+
inject: ((z$2.record(z$2.string())).describe("inject import statements on demand")).optional(),
|
|
1344
|
+
treeshake: (((z$2.boolean()).describe("enable treeshaking")).default(true)).optional()
|
|
1345
|
+
})).omit({
|
|
1346
|
+
input: true,
|
|
1347
|
+
plugins: true,
|
|
1348
|
+
onwarn: true,
|
|
1349
|
+
onLog: true,
|
|
1350
|
+
resolve: true,
|
|
1351
|
+
experimental: true
|
|
1352
|
+
});
|
|
1353
|
+
|
|
1354
|
+
//#endregion
|
|
1355
|
+
//#region src/options/output-options.ts
|
|
1356
|
+
const ModuleFormatSchema = (((((((z$1.literal("es")).or(z$1.literal("cjs"))).or(z$1.literal("esm"))).or(z$1.literal("module"))).or(z$1.literal("commonjs"))).or(z$1.literal("iife"))).describe(`output format of the generated bundle (supports ${underline("esm")}, cjs, and iife).`)).optional();
|
|
1357
|
+
const addonFunctionSchema = ((z$1.function()).args(phantom())).returns((z$1.string()).or(z$1.promise(z$1.string())));
|
|
1358
|
+
const chunkFileNamesFunctionSchema = ((z$1.function()).args(phantom())).returns(z$1.string());
|
|
1359
|
+
const outputOptionsSchema = z$1.strictObject({
|
|
1360
|
+
dir: ((z$1.string()).describe("Output directory, defaults to `dist`.")).optional(),
|
|
1361
|
+
exports: (((((z$1.literal("auto")).or(z$1.literal("named"))).or(z$1.literal("default"))).or(z$1.literal("none"))).describe(`specify a export mode (${underline("auto")}, named, default, none)`)).optional(),
|
|
1362
|
+
format: ModuleFormatSchema,
|
|
1363
|
+
sourcemap: ((((z$1.boolean()).or(z$1.literal("inline"))).or(z$1.literal("hidden"))).describe(`generate sourcemap (\`-s inline\` for inline, or ${bold("pass the `-s` on the last argument if you want to generate `.map` file")}).`)).optional(),
|
|
1364
|
+
sourcemapIgnoreList: ((z$1.boolean()).or(phantom())).optional(),
|
|
1365
|
+
sourcemapPathTransform: (phantom()).optional(),
|
|
1366
|
+
banner: ((z$1.string()).or(addonFunctionSchema)).optional(),
|
|
1367
|
+
footer: ((z$1.string()).or(addonFunctionSchema)).optional(),
|
|
1368
|
+
intro: ((z$1.string()).or(addonFunctionSchema)).optional(),
|
|
1369
|
+
outro: ((z$1.string()).or(addonFunctionSchema)).optional(),
|
|
1370
|
+
extend: ((z$1.boolean()).describe("extend global variable defined by name in IIFE or UMD formats")).optional(),
|
|
1371
|
+
esModule: ((z$1.literal("if-default-prop")).or(z$1.boolean())).optional(),
|
|
1372
|
+
entryFileNames: ((z$1.string()).or(chunkFileNamesFunctionSchema)).optional(),
|
|
1373
|
+
chunkFileNames: ((z$1.string()).or(chunkFileNamesFunctionSchema)).optional(),
|
|
1374
|
+
assetFileNames: (z$1.string()).optional(),
|
|
1375
|
+
minify: ((z$1.boolean()).describe("minify the bundled file.")).optional(),
|
|
1376
|
+
name: ((z$1.string()).describe("name for UMD / IIFE format outputs")).optional(),
|
|
1377
|
+
globals: ((z$1.record(z$1.string())).describe("Comma-separated list of `module-id:global` pairs (`<module-id>:<global>,...`)")).optional(),
|
|
1378
|
+
externalLiveBindings: (((z$1.boolean()).describe("use external live bindings")).default(true)).optional(),
|
|
1379
|
+
inlineDynamicImports: (((z$1.boolean()).describe("inline dynamic imports")).default(false)).optional()
|
|
1380
|
+
});
|
|
1381
|
+
const getAddonDescription = (placement, wrapper) => {
|
|
1382
|
+
return `code to insert the ${bold(placement)} of the bundled file (${bold(wrapper)} the wrapper function).`;
|
|
1383
|
+
};
|
|
1384
|
+
const outputCliOptionsSchema = (outputOptionsSchema.extend({
|
|
1385
|
+
banner: ((z$1.string()).describe(getAddonDescription("top", "outside"))).optional(),
|
|
1386
|
+
footer: ((z$1.string()).describe(getAddonDescription("bottom", "outside"))).optional(),
|
|
1387
|
+
intro: ((z$1.string()).describe(getAddonDescription("top", "inside"))).optional(),
|
|
1388
|
+
outro: ((z$1.string()).describe(getAddonDescription("bottom", "inside"))).optional(),
|
|
1389
|
+
esModule: ((z$1.boolean()).describe("always generate `__esModule` marks in non-ESM formats, defaults to `if-default-prop` (use `--no-esModule` to always disable).")).optional(),
|
|
1390
|
+
sourcemapIgnoreList: (z$1.boolean()).optional(),
|
|
1391
|
+
sourcemapPathTransform: (z$1.undefined()).optional()
|
|
1392
|
+
})).omit({sourcemapPathTransform: true});
|
|
1393
|
+
|
|
1394
|
+
//#endregion
|
|
1395
|
+
//#region src/cli/arguments/schema.ts
|
|
1396
|
+
const cliOptionsSchema = ((z.strictObject({
|
|
1397
|
+
config: (((z.string()).or(z.boolean())).describe("Path to the config file (default: `rollup.config.js`)")).optional(),
|
|
1398
|
+
help: ((z.boolean()).describe("Show help")).optional(),
|
|
1399
|
+
version: ((z.boolean()).describe("Show version number")).optional()
|
|
1400
|
+
})).merge(inputCliOptionsSchema)).merge(outputCliOptionsSchema);
|
|
1401
|
+
const schema = zodToJsonSchema(cliOptionsSchema);
|
|
1402
|
+
|
|
1403
|
+
//#endregion
|
|
1404
|
+
//#region src/cli/arguments/alias.ts
|
|
1405
|
+
const alias = {
|
|
1406
|
+
config: {
|
|
1407
|
+
abbreviation: "c",
|
|
1408
|
+
description: "Use config file",
|
|
1409
|
+
hint: "filename",
|
|
1410
|
+
default: "rolldown.config.js"
|
|
732
1411
|
},
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
1412
|
+
help: {abbreviation: "h"},
|
|
1413
|
+
version: {abbreviation: "v"},
|
|
1414
|
+
dir: {abbreviation: "d"},
|
|
1415
|
+
external: {abbreviation: "e"},
|
|
1416
|
+
format: {abbreviation: "f"},
|
|
1417
|
+
name: {abbreviation: "n"},
|
|
1418
|
+
globals: {abbreviation: "g"},
|
|
1419
|
+
sourcemap: {
|
|
1420
|
+
abbreviation: "s",
|
|
1421
|
+
default: false
|
|
1422
|
+
},
|
|
1423
|
+
minify: {abbreviation: "m"},
|
|
1424
|
+
platform: {abbreviation: "p"},
|
|
1425
|
+
assetFileNames: {hint: "name"},
|
|
1426
|
+
chunkFileNames: {hint: "name"},
|
|
1427
|
+
entryFileNames: {hint: "name"},
|
|
1428
|
+
externalLiveBindings: {default: true},
|
|
1429
|
+
treeshake: {default: true},
|
|
1430
|
+
moduleTypes: {hint: "types"}
|
|
1431
|
+
};
|
|
1432
|
+
|
|
1433
|
+
//#endregion
|
|
1434
|
+
//#region src/cli/arguments/utils.ts
|
|
1435
|
+
function getSchemaType(schema$1) {
|
|
1436
|
+
if ("type"in schema$1) {
|
|
1437
|
+
return schema$1.type;
|
|
1438
|
+
}
|
|
1439
|
+
if ("anyOf"in schema$1) {
|
|
1440
|
+
const types = schema$1.anyOf.map((s) => getSchemaType(s));
|
|
1441
|
+
if (types.includes("object")) return "object";
|
|
1442
|
+
else if (types.includes("array")) return "array";
|
|
1443
|
+
else if (types.includes("string")) return "string";
|
|
1444
|
+
else if (types.includes("number")) return "number";
|
|
1445
|
+
else if (types.includes("boolean")) return "boolean";
|
|
1446
|
+
}
|
|
1447
|
+
return "object";
|
|
1448
|
+
}
|
|
1449
|
+
function flattenSchema(schema$1, base = {}, parent = "") {
|
|
1450
|
+
for (const [k, value] of Object.entries(schema$1)) {
|
|
1451
|
+
const key = parent ? `${parent}.${k}` : k;
|
|
1452
|
+
if (getSchemaType(value) === "object") {
|
|
1453
|
+
if ("properties"in value) {
|
|
1454
|
+
flattenSchema(value.properties, base, key);
|
|
1455
|
+
} else {
|
|
1456
|
+
base[key] = value;
|
|
739
1457
|
}
|
|
740
|
-
|
|
741
|
-
|
|
1458
|
+
} else {
|
|
1459
|
+
base[key] = value;
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
return base;
|
|
1463
|
+
}
|
|
1464
|
+
function setNestedProperty(obj, path, value) {
|
|
1465
|
+
const keys = path.split(".");
|
|
1466
|
+
let current = obj;
|
|
1467
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
1468
|
+
if (!current[keys[i]]) {
|
|
1469
|
+
current[keys[i]] = {};
|
|
742
1470
|
}
|
|
743
|
-
|
|
1471
|
+
current = current[keys[i]];
|
|
744
1472
|
}
|
|
1473
|
+
const finalKey = keys[keys.length - 1];
|
|
1474
|
+
Object.defineProperty(current, finalKey, {
|
|
1475
|
+
value: value,
|
|
1476
|
+
writable: true,
|
|
1477
|
+
enumerable: true,
|
|
1478
|
+
configurable: true
|
|
1479
|
+
});
|
|
1480
|
+
}
|
|
1481
|
+
function camelCaseToKebabCase(str) {
|
|
1482
|
+
return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
1483
|
+
}
|
|
1484
|
+
function kebabCaseToCamelCase(str) {
|
|
1485
|
+
return str.replace(/-./g, (match) => match[1].toUpperCase());
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
//#endregion
|
|
1489
|
+
//#region src/cli/arguments/normalize.ts
|
|
1490
|
+
function normalizeCliOptions(cliOptions, positionals) {
|
|
1491
|
+
const parsed = cliOptionsSchema.safeParse(cliOptions);
|
|
1492
|
+
const options$1 = parsed.data ?? {};
|
|
1493
|
+
if (!parsed.success) {
|
|
1494
|
+
parsed.error.errors.forEach((error) => {
|
|
1495
|
+
logger.error(`Invalid value for option: ${error.path.join(", ")}. ${error.message}. You can use \`rolldown -h\` to see the help.`);
|
|
1496
|
+
});
|
|
1497
|
+
process.exit(1);
|
|
1498
|
+
}
|
|
1499
|
+
const result = {
|
|
1500
|
+
input: {},
|
|
1501
|
+
output: {},
|
|
1502
|
+
help: options$1.help ?? false,
|
|
1503
|
+
version: options$1.version ?? false
|
|
1504
|
+
};
|
|
1505
|
+
if (typeof options$1.config === "string") {
|
|
1506
|
+
result.config = options$1.config ? options$1.config : "rolldown.config.js";
|
|
1507
|
+
}
|
|
1508
|
+
const reservedKeys = ["help", "version", "config"];
|
|
1509
|
+
const keysOfInput = (inputCliOptionsSchema.keyof())._def.values;
|
|
1510
|
+
const keysOfOutput = (outputCliOptionsSchema.keyof())._def.values;
|
|
1511
|
+
for (let [key, value] of Object.entries(options$1)) {
|
|
1512
|
+
const keys = key.split(".");
|
|
1513
|
+
const [primary] = keys;
|
|
1514
|
+
if (keysOfInput.includes(primary)) {
|
|
1515
|
+
setNestedProperty(result.input, key, value);
|
|
1516
|
+
} else if (keysOfOutput.includes(primary)) {
|
|
1517
|
+
setNestedProperty(result.output, key, value);
|
|
1518
|
+
} else if (!reservedKeys.includes(key)) {
|
|
1519
|
+
logger.error(`Unknown option: ${key}`);
|
|
1520
|
+
process.exit(1);
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
if (!result.config && positionals.length > 0) {
|
|
1524
|
+
result.input.input = positionals;
|
|
1525
|
+
}
|
|
1526
|
+
return result;
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
//#endregion
|
|
1530
|
+
//#region src/cli/arguments/index.ts
|
|
1531
|
+
const flattenedSchema = flattenSchema(schema.properties);
|
|
1532
|
+
const options = Object.fromEntries((Object.entries(flattenedSchema)).map(([key, schema$1]) => {
|
|
1533
|
+
const config = (Object.getOwnPropertyDescriptor(alias, key))?.value;
|
|
1534
|
+
const type = getSchemaType(schema$1);
|
|
1535
|
+
const result = {
|
|
1536
|
+
type: type === "boolean" ? "boolean" : "string",
|
|
1537
|
+
description: schema$1?.description ?? config?.description ?? "",
|
|
1538
|
+
hint: config?.hint
|
|
1539
|
+
};
|
|
1540
|
+
if (config && config?.abbreviation) {
|
|
1541
|
+
result.short = config?.abbreviation;
|
|
1542
|
+
}
|
|
1543
|
+
key = camelCaseToKebabCase(key);
|
|
1544
|
+
return [typeof config?.default === "boolean" && config?.default ? `no-${key}` : key, result,];
|
|
1545
|
+
}));
|
|
1546
|
+
function parseCliArguments() {
|
|
1547
|
+
const { values: values, tokens: tokens, positionals: positionals } = parseArgs({
|
|
1548
|
+
options,
|
|
1549
|
+
tokens: true,
|
|
1550
|
+
allowPositionals: true,
|
|
1551
|
+
strict: false
|
|
1552
|
+
});
|
|
1553
|
+
(tokens.filter((token) => token.kind === "option")).forEach((option) => {
|
|
1554
|
+
let negative = false;
|
|
1555
|
+
if (option.name.startsWith("no-")) {
|
|
1556
|
+
const name = kebabCaseToCamelCase(option.name.substring(3));
|
|
1557
|
+
if (name in flattenedSchema) {
|
|
1558
|
+
delete values[option.name];
|
|
1559
|
+
option.name = name;
|
|
1560
|
+
negative = true;
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
delete values[option.name];
|
|
1564
|
+
option.name = kebabCaseToCamelCase(option.name);
|
|
1565
|
+
let originalType = flattenedSchema[option.name];
|
|
1566
|
+
if (!originalType) {
|
|
1567
|
+
logger.warn(`Invalid option: ${option.rawName}. We will ignore this option.`);
|
|
1568
|
+
return;
|
|
1569
|
+
}
|
|
1570
|
+
let type = getSchemaType(originalType);
|
|
1571
|
+
if (type === "object" && typeof option.value === "string") {
|
|
1572
|
+
const [key, value] = ((option.value?.split(",")).map((x) => x.split("=")))[0];
|
|
1573
|
+
if (!values[option.name]) {
|
|
1574
|
+
Object.defineProperty(values, option.name, {
|
|
1575
|
+
value: {},
|
|
1576
|
+
enumerable: true,
|
|
1577
|
+
configurable: true,
|
|
1578
|
+
writable: true
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
if (key && value) {
|
|
1582
|
+
Object.defineProperty(values[option.name], key, {
|
|
1583
|
+
value,
|
|
1584
|
+
enumerable: true,
|
|
1585
|
+
configurable: true,
|
|
1586
|
+
writable: true
|
|
1587
|
+
});
|
|
1588
|
+
}
|
|
1589
|
+
} else if (type === "array" && typeof option.value === "string") {
|
|
1590
|
+
if (!values[option.name]) {
|
|
1591
|
+
Object.defineProperty(values, option.name, {
|
|
1592
|
+
value: [],
|
|
1593
|
+
enumerable: true,
|
|
1594
|
+
configurable: true,
|
|
1595
|
+
writable: true
|
|
1596
|
+
});
|
|
1597
|
+
}
|
|
1598
|
+
;
|
|
1599
|
+
values[option.name].push(option.value);
|
|
1600
|
+
} else if (type === "boolean") {
|
|
1601
|
+
Object.defineProperty(values, option.name, {
|
|
1602
|
+
value: !negative,
|
|
1603
|
+
enumerable: true,
|
|
1604
|
+
configurable: true,
|
|
1605
|
+
writable: true
|
|
1606
|
+
});
|
|
1607
|
+
} else {
|
|
1608
|
+
Object.defineProperty(values, option.name, {
|
|
1609
|
+
value: option.value ?? "",
|
|
1610
|
+
enumerable: true,
|
|
1611
|
+
configurable: true,
|
|
1612
|
+
writable: true
|
|
1613
|
+
});
|
|
1614
|
+
}
|
|
1615
|
+
});
|
|
1616
|
+
return normalizeCliOptions(values, positionals);
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
//#endregion
|
|
1620
|
+
//#region src/cli/commands/help.ts
|
|
1621
|
+
const introduction = `${gray(`${description} (rolldown v${version})`)}
|
|
1622
|
+
|
|
1623
|
+
${bold(underline("USAGE"))} ${cyan("rolldown -c <config>")} or ${cyan("rolldown <input> <options>")}`;
|
|
1624
|
+
const examples = [{
|
|
1625
|
+
title: "Bundle with a config file `rolldown.config.mjs`",
|
|
1626
|
+
command: "rolldown -c rolldown.config.mjs"
|
|
1627
|
+
}, {
|
|
1628
|
+
title: "Bundle the `src/main.ts` to `dist` with `cjs` format",
|
|
1629
|
+
command: "rolldown src/main.ts -d dist -f cjs"
|
|
1630
|
+
}, {
|
|
1631
|
+
title: "Bundle the `src/main.ts` and handle the `.png` assets to Data URL",
|
|
1632
|
+
command: "rolldown src/main.ts -d dist --moduleTypes .png=dataurl"
|
|
1633
|
+
}, {
|
|
1634
|
+
title: "Bundle the `src/main.tsx` and minify the output with sourcemap",
|
|
1635
|
+
command: "rolldown src/main.tsx -d dist -m -s"
|
|
1636
|
+
}, {
|
|
1637
|
+
title: "Create self-executing IIFE using external jQuery as `$` and `_`",
|
|
1638
|
+
command: "rolldown src/main.ts -d dist -n bundle -f iife -e jQuery,window._ -g jQuery=$"
|
|
1639
|
+
},];
|
|
1640
|
+
const notes = ["Due to the API limitation, you need to pass `-s` for `.map` sourcemap file as the last argument.", "If you are using the configuration, please pass the `-c` as the last argument if you ignore the default configuration file.", "CLI options will override the configuration file.", "For more information, please visit https://rolldown.rs/.",];
|
|
1641
|
+
function showHelp() {
|
|
1642
|
+
logger.log(introduction);
|
|
1643
|
+
logger.log("");
|
|
1644
|
+
logger.log(`${bold(underline("OPTIONS"))}`);
|
|
1645
|
+
logger.log("");
|
|
1646
|
+
logger.log((((Object.entries(options)).sort(([a], [b]) => {
|
|
1647
|
+
if (options[a].short && !options[b].short) {
|
|
1648
|
+
return -1;
|
|
1649
|
+
}
|
|
1650
|
+
if (!options[a].short && options[b].short) {
|
|
1651
|
+
return 1;
|
|
1652
|
+
}
|
|
1653
|
+
if (options[a].short && options[b].short) {
|
|
1654
|
+
return options[a].short.localeCompare(options[b].short);
|
|
1655
|
+
}
|
|
1656
|
+
return a.localeCompare(b);
|
|
1657
|
+
})).map(([option, { type: type, short: short, hint: hint, description: description$1 }]) => {
|
|
1658
|
+
let optionStr = " ";
|
|
1659
|
+
const config = (Object.getOwnPropertyDescriptor(alias, option) ?? {}).value ?? {};
|
|
1660
|
+
option = camelCaseToKebabCase(option);
|
|
1661
|
+
if (typeof config.default === "boolean" && type === "boolean" && config.default) {
|
|
1662
|
+
optionStr += `--no-${option}`;
|
|
1663
|
+
description$1 = `Do not ${description$1}`;
|
|
1664
|
+
} else {
|
|
1665
|
+
optionStr += `--${option} `;
|
|
1666
|
+
}
|
|
1667
|
+
if (short) {
|
|
1668
|
+
optionStr += `-${short}, `;
|
|
1669
|
+
}
|
|
1670
|
+
if (type === "string") {
|
|
1671
|
+
optionStr += `<${hint ?? option}>`;
|
|
1672
|
+
}
|
|
1673
|
+
if (description$1 && description$1.length > 0) {
|
|
1674
|
+
description$1 = description$1[0].toUpperCase() + description$1.slice(1);
|
|
1675
|
+
}
|
|
1676
|
+
return cyan(optionStr.padEnd(30)) + description$1 + (description$1 && description$1?.endsWith(".") ? "" : ".");
|
|
1677
|
+
})).join("\n"));
|
|
1678
|
+
logger.log("");
|
|
1679
|
+
logger.log(`${bold(underline("EXAMPLES"))}`);
|
|
1680
|
+
logger.log("");
|
|
1681
|
+
examples.forEach(({ title: title, command: command }, ord) => {
|
|
1682
|
+
logger.log(` ${ord + 1}. ${title}:`);
|
|
1683
|
+
logger.log(` ${cyan(command)}`);
|
|
1684
|
+
logger.log("");
|
|
1685
|
+
});
|
|
1686
|
+
logger.log(`${bold(underline("NOTES"))}`);
|
|
1687
|
+
logger.log("");
|
|
1688
|
+
notes.forEach((note) => {
|
|
1689
|
+
logger.log(` * ${gray(note)}`);
|
|
1690
|
+
});
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
//#endregion
|
|
1694
|
+
//#region src/cli/index.ts
|
|
1695
|
+
async function main() {
|
|
1696
|
+
const cliOptions = parseCliArguments();
|
|
1697
|
+
if (cliOptions.config) {
|
|
1698
|
+
await bundleWithConfig(cliOptions.config, cliOptions);
|
|
1699
|
+
return;
|
|
1700
|
+
}
|
|
1701
|
+
if ("input"in cliOptions.input) {
|
|
1702
|
+
await bundleWithCliOptions(cliOptions);
|
|
1703
|
+
return;
|
|
1704
|
+
}
|
|
1705
|
+
if (cliOptions.version) {
|
|
1706
|
+
logger.log(`rolldown v${version}`);
|
|
1707
|
+
return;
|
|
1708
|
+
}
|
|
1709
|
+
showHelp();
|
|
1710
|
+
}
|
|
1711
|
+
(main()).catch((err) => {
|
|
1712
|
+
logger.error(err);
|
|
1713
|
+
process$1.exit(1);
|
|
745
1714
|
});
|
|
746
|
-
runMain(main);
|
|
747
1715
|
|
|
748
|
-
//#endregion
|
|
1716
|
+
//#endregion
|