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