@boneskull/bargs 0.1.1
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/LICENSE +55 -0
- package/README.md +483 -0
- package/dist/bargs.cjs +167 -0
- package/dist/bargs.cjs.map +1 -0
- package/dist/bargs.d.cts +31 -0
- package/dist/bargs.d.cts.map +1 -0
- package/dist/bargs.d.ts +31 -0
- package/dist/bargs.d.ts.map +1 -0
- package/dist/bargs.js +163 -0
- package/dist/bargs.js.map +1 -0
- package/dist/errors.cjs +57 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +40 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.ts +40 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +51 -0
- package/dist/errors.js.map +1 -0
- package/dist/help.cjs +309 -0
- package/dist/help.cjs.map +1 -0
- package/dist/help.d.cts +21 -0
- package/dist/help.d.cts.map +1 -0
- package/dist/help.d.ts +21 -0
- package/dist/help.d.ts.map +1 -0
- package/dist/help.js +304 -0
- package/dist/help.js.map +1 -0
- package/dist/index.cjs +63 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +96 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/opt.cjs +205 -0
- package/dist/opt.cjs.map +1 -0
- package/dist/opt.d.cts +145 -0
- package/dist/opt.d.cts.map +1 -0
- package/dist/opt.d.ts +145 -0
- package/dist/opt.d.ts.map +1 -0
- package/dist/opt.js +202 -0
- package/dist/opt.js.map +1 -0
- package/dist/osc.cjs +190 -0
- package/dist/osc.cjs.map +1 -0
- package/dist/osc.d.cts +30 -0
- package/dist/osc.d.cts.map +1 -0
- package/dist/osc.d.ts +30 -0
- package/dist/osc.d.ts.map +1 -0
- package/dist/osc.js +181 -0
- package/dist/osc.js.map +1 -0
- package/dist/parser.cjs +293 -0
- package/dist/parser.cjs.map +1 -0
- package/dist/parser.d.cts +47 -0
- package/dist/parser.d.cts.map +1 -0
- package/dist/parser.d.ts +47 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +285 -0
- package/dist/parser.js.map +1 -0
- package/dist/theme.cjs +203 -0
- package/dist/theme.cjs.map +1 -0
- package/dist/theme.d.cts +227 -0
- package/dist/theme.d.cts.map +1 -0
- package/dist/theme.d.ts +227 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +198 -0
- package/dist/theme.js.map +1 -0
- package/dist/types.cjs +18 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +244 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +244 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +17 -0
- package/dist/types.js.map +1 -0
- package/dist/validate.cjs +452 -0
- package/dist/validate.cjs.map +1 -0
- package/dist/validate.d.cts +28 -0
- package/dist/validate.d.cts.map +1 -0
- package/dist/validate.d.ts +28 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +448 -0
- package/dist/validate.js.map +1 -0
- package/dist/version.cjs +134 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.d.cts +27 -0
- package/dist/version.d.cts.map +1 -0
- package/dist/version.d.ts +27 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +129 -0
- package/dist/version.js.map +1 -0
- package/package.json +149 -0
package/dist/validate.js
ADDED
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration validation for bargs.
|
|
3
|
+
*
|
|
4
|
+
* Validates bargs configuration objects at runtime before parsing, ensuring:
|
|
5
|
+
*
|
|
6
|
+
* - Required properties are present and correctly typed
|
|
7
|
+
* - Option definitions have valid type discriminators and defaults
|
|
8
|
+
* - Aliases are single characters with no conflicts
|
|
9
|
+
* - Positional schemas have variadic args last and required args before optional
|
|
10
|
+
* - Command handlers are properly defined
|
|
11
|
+
* - Command-based CLIs don't have top-level positionals or handlers
|
|
12
|
+
*
|
|
13
|
+
* Throws {@link ValidationError} with detailed path information when invalid.
|
|
14
|
+
*
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
17
|
+
import { ValidationError } from "./errors.js";
|
|
18
|
+
/** Valid option type discriminators */
|
|
19
|
+
const VALID_OPTION_TYPES = [
|
|
20
|
+
'string',
|
|
21
|
+
'boolean',
|
|
22
|
+
'number',
|
|
23
|
+
'enum',
|
|
24
|
+
'array',
|
|
25
|
+
'count',
|
|
26
|
+
];
|
|
27
|
+
/** Valid positional type discriminators */
|
|
28
|
+
const VALID_POSITIONAL_TYPES = [
|
|
29
|
+
'string',
|
|
30
|
+
'number',
|
|
31
|
+
'enum',
|
|
32
|
+
'variadic',
|
|
33
|
+
];
|
|
34
|
+
/** Valid array/variadic item types */
|
|
35
|
+
const VALID_ITEM_TYPES = ['string', 'number'];
|
|
36
|
+
// ─── Primitive Helpers ──────────────────────────────────────────────────────
|
|
37
|
+
const isObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
38
|
+
const isFunction = (value) => typeof value === 'function';
|
|
39
|
+
const isStringArray = (value) => Array.isArray(value) && value.every((v) => typeof v === 'string');
|
|
40
|
+
const isNumberArray = (value) => Array.isArray(value) && value.every((v) => typeof v === 'number');
|
|
41
|
+
// ─── Option Validation ──────────────────────────────────────────────────────
|
|
42
|
+
/**
|
|
43
|
+
* Validate a single option definition.
|
|
44
|
+
*/
|
|
45
|
+
const validateOption = (name, opt, path, allAliases) => {
|
|
46
|
+
if (!isObject(opt)) {
|
|
47
|
+
throw new ValidationError(path, 'option must be an object');
|
|
48
|
+
}
|
|
49
|
+
// Validate type discriminator
|
|
50
|
+
const type = opt['type'];
|
|
51
|
+
if (typeof type !== 'string') {
|
|
52
|
+
throw new ValidationError(`${path}.type`, 'must be a string');
|
|
53
|
+
}
|
|
54
|
+
if (!VALID_OPTION_TYPES.includes(type)) {
|
|
55
|
+
throw new ValidationError(`${path}.type`, `must be one of: ${VALID_OPTION_TYPES.join(', ')}`);
|
|
56
|
+
}
|
|
57
|
+
// Validate optional description
|
|
58
|
+
if (opt['description'] !== undefined &&
|
|
59
|
+
typeof opt['description'] !== 'string') {
|
|
60
|
+
throw new ValidationError(`${path}.description`, 'must be a string');
|
|
61
|
+
}
|
|
62
|
+
// Validate optional group
|
|
63
|
+
if (opt['group'] !== undefined && typeof opt['group'] !== 'string') {
|
|
64
|
+
throw new ValidationError(`${path}.group`, 'must be a string');
|
|
65
|
+
}
|
|
66
|
+
// Validate optional hidden
|
|
67
|
+
if (opt['hidden'] !== undefined && typeof opt['hidden'] !== 'boolean') {
|
|
68
|
+
throw new ValidationError(`${path}.hidden`, 'must be a boolean');
|
|
69
|
+
}
|
|
70
|
+
// Validate optional required
|
|
71
|
+
if (opt['required'] !== undefined && typeof opt['required'] !== 'boolean') {
|
|
72
|
+
throw new ValidationError(`${path}.required`, 'must be a boolean');
|
|
73
|
+
}
|
|
74
|
+
// Validate aliases
|
|
75
|
+
if (opt['aliases'] !== undefined) {
|
|
76
|
+
if (!isStringArray(opt['aliases'])) {
|
|
77
|
+
throw new ValidationError(`${path}.aliases`, 'must be an array of strings');
|
|
78
|
+
}
|
|
79
|
+
for (let i = 0; i < opt['aliases'].length; i++) {
|
|
80
|
+
const alias = opt['aliases'][i];
|
|
81
|
+
if (alias.length !== 1) {
|
|
82
|
+
throw new ValidationError(`${path}.aliases[${i}]`, `alias must be a single character, got "${alias}"`);
|
|
83
|
+
}
|
|
84
|
+
// Check for duplicates
|
|
85
|
+
const existingOption = allAliases.get(alias);
|
|
86
|
+
if (existingOption !== undefined) {
|
|
87
|
+
throw new ValidationError(`${path}.aliases[${i}]`, `alias "${alias}" is already used by option "${existingOption}"`);
|
|
88
|
+
}
|
|
89
|
+
allAliases.set(alias, name);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Type-specific validation
|
|
93
|
+
switch (type) {
|
|
94
|
+
case 'array': {
|
|
95
|
+
const items = opt['items'];
|
|
96
|
+
if (typeof items !== 'string') {
|
|
97
|
+
throw new ValidationError(`${path}.items`, 'must be "string" or "number"');
|
|
98
|
+
}
|
|
99
|
+
if (!VALID_ITEM_TYPES.includes(items)) {
|
|
100
|
+
throw new ValidationError(`${path}.items`, 'must be "string" or "number"');
|
|
101
|
+
}
|
|
102
|
+
if (opt['default'] !== undefined) {
|
|
103
|
+
if (items === 'string') {
|
|
104
|
+
if (!isStringArray(opt['default'])) {
|
|
105
|
+
throw new ValidationError(`${path}.default`, 'must be an array of strings');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
if (!isNumberArray(opt['default'])) {
|
|
110
|
+
throw new ValidationError(`${path}.default`, 'must be an array of numbers');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
case 'boolean':
|
|
117
|
+
if (opt['default'] !== undefined && typeof opt['default'] !== 'boolean') {
|
|
118
|
+
throw new ValidationError(`${path}.default`, 'must be a boolean');
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
case 'count':
|
|
122
|
+
if (opt['default'] !== undefined && typeof opt['default'] !== 'number') {
|
|
123
|
+
throw new ValidationError(`${path}.default`, 'must be a number');
|
|
124
|
+
}
|
|
125
|
+
break;
|
|
126
|
+
case 'enum': {
|
|
127
|
+
const choices = opt['choices'];
|
|
128
|
+
if (!isStringArray(choices)) {
|
|
129
|
+
throw new ValidationError(`${path}.choices`, 'must be a non-empty array of strings');
|
|
130
|
+
}
|
|
131
|
+
if (choices.length === 0) {
|
|
132
|
+
throw new ValidationError(`${path}.choices`, 'must not be empty');
|
|
133
|
+
}
|
|
134
|
+
if (opt['default'] !== undefined) {
|
|
135
|
+
if (typeof opt['default'] !== 'string') {
|
|
136
|
+
throw new ValidationError(`${path}.default`, 'must be a string');
|
|
137
|
+
}
|
|
138
|
+
if (!choices.includes(opt['default'])) {
|
|
139
|
+
throw new ValidationError(`${path}.default`, `must be one of the choices: ${choices.join(', ')}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
case 'number':
|
|
145
|
+
if (opt['default'] !== undefined && typeof opt['default'] !== 'number') {
|
|
146
|
+
throw new ValidationError(`${path}.default`, 'must be a number');
|
|
147
|
+
}
|
|
148
|
+
break;
|
|
149
|
+
case 'string':
|
|
150
|
+
if (opt['default'] !== undefined && typeof opt['default'] !== 'string') {
|
|
151
|
+
throw new ValidationError(`${path}.default`, 'must be a string');
|
|
152
|
+
}
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Validate an options schema.
|
|
158
|
+
*/
|
|
159
|
+
const validateOptionsSchema = (schema, path, allAliases = new Map()) => {
|
|
160
|
+
if (schema === undefined) {
|
|
161
|
+
return; // optional
|
|
162
|
+
}
|
|
163
|
+
if (!isObject(schema)) {
|
|
164
|
+
throw new ValidationError(path, 'must be an object');
|
|
165
|
+
}
|
|
166
|
+
for (const [name, opt] of Object.entries(schema)) {
|
|
167
|
+
validateOption(name, opt, `${path}.${name}`, allAliases);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
// ─── Positional Validation ──────────────────────────────────────────────────
|
|
171
|
+
/**
|
|
172
|
+
* Validate a single positional definition.
|
|
173
|
+
*/
|
|
174
|
+
const validatePositional = (index, pos, path) => {
|
|
175
|
+
if (!isObject(pos)) {
|
|
176
|
+
throw new ValidationError(path, 'positional must be an object');
|
|
177
|
+
}
|
|
178
|
+
// Validate type discriminator
|
|
179
|
+
const type = pos['type'];
|
|
180
|
+
if (typeof type !== 'string') {
|
|
181
|
+
throw new ValidationError(`${path}.type`, 'must be a string');
|
|
182
|
+
}
|
|
183
|
+
if (!VALID_POSITIONAL_TYPES.includes(type)) {
|
|
184
|
+
throw new ValidationError(`${path}.type`, `must be one of: ${VALID_POSITIONAL_TYPES.join(', ')}`);
|
|
185
|
+
}
|
|
186
|
+
// Validate optional description
|
|
187
|
+
if (pos['description'] !== undefined &&
|
|
188
|
+
typeof pos['description'] !== 'string') {
|
|
189
|
+
throw new ValidationError(`${path}.description`, 'must be a string');
|
|
190
|
+
}
|
|
191
|
+
// Validate optional name
|
|
192
|
+
if (pos['name'] !== undefined && typeof pos['name'] !== 'string') {
|
|
193
|
+
throw new ValidationError(`${path}.name`, 'must be a string');
|
|
194
|
+
}
|
|
195
|
+
// Validate optional required
|
|
196
|
+
if (pos['required'] !== undefined && typeof pos['required'] !== 'boolean') {
|
|
197
|
+
throw new ValidationError(`${path}.required`, 'must be a boolean');
|
|
198
|
+
}
|
|
199
|
+
// Type-specific validation
|
|
200
|
+
switch (type) {
|
|
201
|
+
case 'enum': {
|
|
202
|
+
const choices = pos['choices'];
|
|
203
|
+
if (!isStringArray(choices)) {
|
|
204
|
+
throw new ValidationError(`${path}.choices`, 'must be a non-empty array of strings');
|
|
205
|
+
}
|
|
206
|
+
if (choices.length === 0) {
|
|
207
|
+
throw new ValidationError(`${path}.choices`, 'must not be empty');
|
|
208
|
+
}
|
|
209
|
+
if (pos['default'] !== undefined) {
|
|
210
|
+
if (typeof pos['default'] !== 'string') {
|
|
211
|
+
throw new ValidationError(`${path}.default`, 'must be a string');
|
|
212
|
+
}
|
|
213
|
+
if (!choices.includes(pos['default'])) {
|
|
214
|
+
throw new ValidationError(`${path}.default`, `must be one of the choices: ${choices.join(', ')}`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
case 'number':
|
|
220
|
+
if (pos['default'] !== undefined && typeof pos['default'] !== 'number') {
|
|
221
|
+
throw new ValidationError(`${path}.default`, 'must be a number');
|
|
222
|
+
}
|
|
223
|
+
break;
|
|
224
|
+
case 'string':
|
|
225
|
+
if (pos['default'] !== undefined && typeof pos['default'] !== 'string') {
|
|
226
|
+
throw new ValidationError(`${path}.default`, 'must be a string');
|
|
227
|
+
}
|
|
228
|
+
break;
|
|
229
|
+
case 'variadic': {
|
|
230
|
+
const items = pos['items'];
|
|
231
|
+
if (typeof items !== 'string') {
|
|
232
|
+
throw new ValidationError(`${path}.items`, 'must be "string" or "number"');
|
|
233
|
+
}
|
|
234
|
+
if (!VALID_ITEM_TYPES.includes(items)) {
|
|
235
|
+
throw new ValidationError(`${path}.items`, 'must be "string" or "number"');
|
|
236
|
+
}
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Validate a positionals schema. Checks:
|
|
243
|
+
*
|
|
244
|
+
* - Each positional has valid structure
|
|
245
|
+
* - Variadic positional (if present) is last
|
|
246
|
+
* - Required positionals don't follow optional ones
|
|
247
|
+
*/
|
|
248
|
+
const validatePositionalsSchema = (schema, path) => {
|
|
249
|
+
if (schema === undefined) {
|
|
250
|
+
return; // optional
|
|
251
|
+
}
|
|
252
|
+
if (!Array.isArray(schema)) {
|
|
253
|
+
throw new ValidationError(path, 'must be an array');
|
|
254
|
+
}
|
|
255
|
+
// Validate each positional
|
|
256
|
+
for (let i = 0; i < schema.length; i++) {
|
|
257
|
+
validatePositional(i, schema[i], `${path}[${i}]`);
|
|
258
|
+
}
|
|
259
|
+
// Check variadic is last
|
|
260
|
+
const variadicIndex = schema.findIndex((p) => isObject(p) && p['type'] === 'variadic');
|
|
261
|
+
if (variadicIndex !== -1 && variadicIndex !== schema.length - 1) {
|
|
262
|
+
throw new ValidationError(`${path}[${variadicIndex}]`, 'variadic positional must be the last positional argument');
|
|
263
|
+
}
|
|
264
|
+
// Check required doesn't follow optional
|
|
265
|
+
let seenOptional = false;
|
|
266
|
+
for (let i = 0; i < schema.length; i++) {
|
|
267
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
268
|
+
const pos = schema[i];
|
|
269
|
+
if (!isObject(pos)) {
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
const isOptional = pos['required'] !== true &&
|
|
273
|
+
!('default' in pos && pos['default'] !== undefined);
|
|
274
|
+
const isVariadic = pos['type'] === 'variadic';
|
|
275
|
+
if (isOptional) {
|
|
276
|
+
seenOptional = true;
|
|
277
|
+
}
|
|
278
|
+
else if (seenOptional && !isVariadic) {
|
|
279
|
+
throw new ValidationError(`${path}[${i}]`, 'required positional cannot follow an optional positional');
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
// ─── Handler Validation ─────────────────────────────────────────────────────
|
|
284
|
+
/**
|
|
285
|
+
* Validate a handler (function or array of functions).
|
|
286
|
+
*/
|
|
287
|
+
const validateHandler = (handler, path) => {
|
|
288
|
+
if (handler === undefined) {
|
|
289
|
+
return; // handlers are optional in some contexts
|
|
290
|
+
}
|
|
291
|
+
if (Array.isArray(handler)) {
|
|
292
|
+
if (handler.length === 0) {
|
|
293
|
+
throw new ValidationError(path, 'handler array must not be empty');
|
|
294
|
+
}
|
|
295
|
+
for (let i = 0; i < handler.length; i++) {
|
|
296
|
+
if (!isFunction(handler[i])) {
|
|
297
|
+
throw new ValidationError(`${path}[${i}]`, 'must be a function');
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
else if (!isFunction(handler)) {
|
|
302
|
+
throw new ValidationError(path, 'must be a function or array of functions');
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
// ─── Command Validation ─────────────────────────────────────────────────────
|
|
306
|
+
/**
|
|
307
|
+
* Validate a single command configuration.
|
|
308
|
+
*/
|
|
309
|
+
const validateCommand = (name, cmd, path, globalAliases) => {
|
|
310
|
+
if (!isObject(cmd)) {
|
|
311
|
+
throw new ValidationError(path, 'command must be an object');
|
|
312
|
+
}
|
|
313
|
+
// description is required
|
|
314
|
+
if (typeof cmd['description'] !== 'string') {
|
|
315
|
+
throw new ValidationError(`${path}.description`, 'must be a string');
|
|
316
|
+
}
|
|
317
|
+
// handler is required for commands
|
|
318
|
+
if (cmd['handler'] === undefined) {
|
|
319
|
+
throw new ValidationError(`${path}.handler`, 'is required');
|
|
320
|
+
}
|
|
321
|
+
validateHandler(cmd['handler'], `${path}.handler`);
|
|
322
|
+
// Validate options (command-local aliases only, no collision with globals)
|
|
323
|
+
// Create a new alias map that includes global aliases for collision detection
|
|
324
|
+
const commandAliases = new Map(globalAliases);
|
|
325
|
+
validateOptionsSchema(cmd['options'], `${path}.options`, commandAliases);
|
|
326
|
+
// Validate positionals
|
|
327
|
+
validatePositionalsSchema(cmd['positionals'], `${path}.positionals`);
|
|
328
|
+
};
|
|
329
|
+
/**
|
|
330
|
+
* Validate commands record.
|
|
331
|
+
*/
|
|
332
|
+
const validateCommands = (commands, path, globalAliases) => {
|
|
333
|
+
if (!isObject(commands)) {
|
|
334
|
+
throw new ValidationError(path, 'must be an object');
|
|
335
|
+
}
|
|
336
|
+
const commandNames = Object.keys(commands);
|
|
337
|
+
if (commandNames.length === 0) {
|
|
338
|
+
throw new ValidationError(path, 'must have at least one command');
|
|
339
|
+
}
|
|
340
|
+
for (const [name, cmd] of Object.entries(commands)) {
|
|
341
|
+
validateCommand(name, cmd, `${path}.${name}`, globalAliases);
|
|
342
|
+
}
|
|
343
|
+
return new Set(commandNames);
|
|
344
|
+
};
|
|
345
|
+
// ─── Main Config Validation ─────────────────────────────────────────────────
|
|
346
|
+
/**
|
|
347
|
+
* Validate base config properties common to both simple and command-based CLIs.
|
|
348
|
+
*/
|
|
349
|
+
const validateBaseConfig = (config, path) => {
|
|
350
|
+
if (!isObject(config)) {
|
|
351
|
+
throw new ValidationError(path, 'config must be an object');
|
|
352
|
+
}
|
|
353
|
+
// name is required
|
|
354
|
+
if (typeof config['name'] !== 'string') {
|
|
355
|
+
throw new ValidationError(`${path}.name`, 'must be a string');
|
|
356
|
+
}
|
|
357
|
+
if (config['name'].length === 0) {
|
|
358
|
+
throw new ValidationError(`${path}.name`, 'must not be empty');
|
|
359
|
+
}
|
|
360
|
+
// description is optional
|
|
361
|
+
if (config['description'] !== undefined &&
|
|
362
|
+
typeof config['description'] !== 'string') {
|
|
363
|
+
throw new ValidationError(`${path}.description`, 'must be a string');
|
|
364
|
+
}
|
|
365
|
+
// version is optional
|
|
366
|
+
if (config['version'] !== undefined &&
|
|
367
|
+
typeof config['version'] !== 'string') {
|
|
368
|
+
throw new ValidationError(`${path}.version`, 'must be a string');
|
|
369
|
+
}
|
|
370
|
+
// args is optional
|
|
371
|
+
if (config['args'] !== undefined && !isStringArray(config['args'])) {
|
|
372
|
+
throw new ValidationError(`${path}.args`, 'must be an array of strings');
|
|
373
|
+
}
|
|
374
|
+
// Validate options
|
|
375
|
+
const aliases = new Map();
|
|
376
|
+
validateOptionsSchema(config['options'], `${path}.options`, aliases);
|
|
377
|
+
return { aliases, configObj: config };
|
|
378
|
+
};
|
|
379
|
+
/**
|
|
380
|
+
* Check if config appears to be a command-based CLI. Returns true if commands
|
|
381
|
+
* property exists (even if empty - validation will catch that).
|
|
382
|
+
*/
|
|
383
|
+
const isCommandConfig = (config) => {
|
|
384
|
+
return config['commands'] !== undefined;
|
|
385
|
+
};
|
|
386
|
+
/**
|
|
387
|
+
* Validate a simple CLI config (no commands).
|
|
388
|
+
*/
|
|
389
|
+
const validateSimpleConfig = (config, path, _aliases) => {
|
|
390
|
+
// Validate positionals
|
|
391
|
+
validatePositionalsSchema(config['positionals'], `${path}.positionals`);
|
|
392
|
+
// Validate handler (optional for simple CLI)
|
|
393
|
+
validateHandler(config['handler'], `${path}.handler`);
|
|
394
|
+
};
|
|
395
|
+
/**
|
|
396
|
+
* Validate a command-based CLI config.
|
|
397
|
+
*/
|
|
398
|
+
const validateCommandConfig = (config, path, aliases) => {
|
|
399
|
+
// Commands must exist and have entries
|
|
400
|
+
const commandNames = validateCommands(config['commands'], `${path}.commands`, aliases);
|
|
401
|
+
// Positionals should not be present at top level
|
|
402
|
+
if (config['positionals'] !== undefined) {
|
|
403
|
+
const positionals = config['positionals'];
|
|
404
|
+
if (Array.isArray(positionals) && positionals.length > 0) {
|
|
405
|
+
throw new ValidationError(`${path}.positionals`, 'top-level positionals are not allowed in command-based CLIs (define them per-command)');
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
// handler should not be present (use defaultHandler instead)
|
|
409
|
+
if (config['handler'] !== undefined) {
|
|
410
|
+
throw new ValidationError(`${path}.handler`, 'use defaultHandler for command-based CLIs');
|
|
411
|
+
}
|
|
412
|
+
// Validate defaultHandler
|
|
413
|
+
const defaultHandler = config['defaultHandler'];
|
|
414
|
+
if (defaultHandler !== undefined) {
|
|
415
|
+
if (typeof defaultHandler === 'string') {
|
|
416
|
+
// Must reference an existing command
|
|
417
|
+
if (!commandNames.has(defaultHandler)) {
|
|
418
|
+
throw new ValidationError(`${path}.defaultHandler`, `must reference an existing command, got "${defaultHandler}"`);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
else if (Array.isArray(defaultHandler)) {
|
|
422
|
+
// Array of handlers
|
|
423
|
+
validateHandler(defaultHandler, `${path}.defaultHandler`);
|
|
424
|
+
}
|
|
425
|
+
else if (!isFunction(defaultHandler)) {
|
|
426
|
+
throw new ValidationError(`${path}.defaultHandler`, 'must be a function, array of functions, or command name string');
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
/**
|
|
431
|
+
* Validate a bargs configuration object. Throws ValidationError if invalid.
|
|
432
|
+
*
|
|
433
|
+
* This validates both simple CLI configs (BargsConfig) and command-based CLI
|
|
434
|
+
* configs (BargsConfigWithCommands).
|
|
435
|
+
*
|
|
436
|
+
* @param config - The configuration to validate
|
|
437
|
+
* @throws ValidationError if the config is invalid
|
|
438
|
+
*/
|
|
439
|
+
export const validateConfig = (config) => {
|
|
440
|
+
const { aliases, configObj } = validateBaseConfig(config, 'config');
|
|
441
|
+
if (isCommandConfig(configObj)) {
|
|
442
|
+
validateCommandConfig(configObj, 'config', aliases);
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
validateSimpleConfig(configObj, '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C5B,MAUK,EACC,EAAE;IACR,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,kBAAkB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAEpE,IAAI,eAAe,CAAC,SAAS,CAAC,EAAE,CAAC;QAC/B,qBAAqB,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtD,CAAC;SAAM,CAAC;QACN,oBAAoB,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC;AACH,CAAC,CAAC"}
|
package/dist/version.cjs
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Package version and metadata detection utilities.
|
|
4
|
+
*
|
|
5
|
+
* Provides functions to locate and read `package.json` files by walking up the
|
|
6
|
+
* directory tree, extracting version strings, and gathering package metadata
|
|
7
|
+
* (homepage, repository URLs) for automatic epilog generation in help output.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.readPackageInfoSync = exports.detectVersion = void 0;
|
|
13
|
+
const node_fs_1 = require("node:fs");
|
|
14
|
+
const promises_1 = require("node:fs/promises");
|
|
15
|
+
const node_path_1 = require("node:path");
|
|
16
|
+
/**
|
|
17
|
+
* Normalize a repository URL to clean HTTPS format. Strips leading `git+` and
|
|
18
|
+
* trailing `.git`.
|
|
19
|
+
*/
|
|
20
|
+
const normalizeRepoUrl = (url) => {
|
|
21
|
+
return url.replace(/^git\+/, '').replace(/\.git$/, '');
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Validate that a URL is HTTPS. Returns the URL if valid, undefined otherwise.
|
|
25
|
+
*/
|
|
26
|
+
const validateHttpsUrl = (url) => {
|
|
27
|
+
if (!url) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
return url.startsWith('https://') ? url : undefined;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Extract repository URL from package.json repository field. Handles both
|
|
34
|
+
* string and object forms.
|
|
35
|
+
*/
|
|
36
|
+
const extractRepoUrl = (repository) => {
|
|
37
|
+
if (!repository) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
const rawUrl = typeof repository === 'string' ? repository : repository.url;
|
|
41
|
+
if (!rawUrl) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const normalized = normalizeRepoUrl(rawUrl);
|
|
45
|
+
return validateHttpsUrl(normalized);
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Find package.json by walking up from startDir (async).
|
|
49
|
+
*/
|
|
50
|
+
const findPackageJson = async (startDir) => {
|
|
51
|
+
let dir = startDir;
|
|
52
|
+
let prevDir = '';
|
|
53
|
+
while (dir !== prevDir) {
|
|
54
|
+
const pkgPath = (0, node_path_1.join)(dir, 'package.json');
|
|
55
|
+
try {
|
|
56
|
+
await (0, promises_1.readFile)(pkgPath, 'utf-8');
|
|
57
|
+
return pkgPath;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
prevDir = dir;
|
|
61
|
+
dir = (0, node_path_1.dirname)(dir);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Find package.json by walking up from startDir (sync).
|
|
68
|
+
*/
|
|
69
|
+
const findPackageJsonSync = (startDir) => {
|
|
70
|
+
let dir = startDir;
|
|
71
|
+
let prevDir = '';
|
|
72
|
+
while (dir !== prevDir) {
|
|
73
|
+
const pkgPath = (0, node_path_1.join)(dir, 'package.json');
|
|
74
|
+
try {
|
|
75
|
+
(0, node_fs_1.readFileSync)(pkgPath, 'utf-8');
|
|
76
|
+
return pkgPath;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
prevDir = dir;
|
|
80
|
+
dir = (0, node_path_1.dirname)(dir);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Read version from package.json (async).
|
|
87
|
+
*/
|
|
88
|
+
const readVersionFromPackageJson = async (pkgPath) => {
|
|
89
|
+
try {
|
|
90
|
+
const content = await (0, promises_1.readFile)(pkgPath, 'utf-8');
|
|
91
|
+
const pkg = JSON.parse(content);
|
|
92
|
+
return pkg.version;
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Detect version: use provided version or read from nearest package.json.
|
|
100
|
+
*/
|
|
101
|
+
const detectVersion = async (providedVersion, startDir = process.cwd()) => {
|
|
102
|
+
if (providedVersion) {
|
|
103
|
+
return providedVersion;
|
|
104
|
+
}
|
|
105
|
+
const pkgPath = await findPackageJson(startDir);
|
|
106
|
+
if (!pkgPath) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
return readVersionFromPackageJson(pkgPath);
|
|
110
|
+
};
|
|
111
|
+
exports.detectVersion = detectVersion;
|
|
112
|
+
/**
|
|
113
|
+
* Read package info (homepage, repository) from package.json synchronously.
|
|
114
|
+
* Returns only HTTPS URLs; other URL schemes are omitted.
|
|
115
|
+
*/
|
|
116
|
+
const readPackageInfoSync = (startDir = process.cwd()) => {
|
|
117
|
+
const pkgPath = findPackageJsonSync(startDir);
|
|
118
|
+
if (!pkgPath) {
|
|
119
|
+
return {};
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
const content = (0, node_fs_1.readFileSync)(pkgPath, 'utf-8');
|
|
123
|
+
const pkg = JSON.parse(content);
|
|
124
|
+
return {
|
|
125
|
+
homepage: validateHttpsUrl(pkg.homepage),
|
|
126
|
+
repository: extractRepoUrl(pkg.repository),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return {};
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
exports.readPackageInfoSync = readPackageInfoSync;
|
|
134
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAEH,qCAAuC;AACvC,+CAA4C;AAC5C,yCAA0C;AA4B1C;;;GAGG;AACH,MAAM,gBAAgB,GAAG,CAAC,GAAW,EAAU,EAAE;IAC/C,OAAO,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AACzD,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,gBAAgB,GAAG,CAAC,GAAuB,EAAsB,EAAE;IACvE,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;AACtD,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,cAAc,GAAG,CACrB,UAAgD,EAC5B,EAAE;IACtB,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,MAAM,GAAG,OAAO,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC;IAC5E,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,UAAU,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC5C,OAAO,gBAAgB,CAAC,UAAU,CAAC,CAAC;AACtC,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,eAAe,GAAG,KAAK,EAC3B,QAAgB,EACa,EAAE;IAC/B,IAAI,GAAG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ate and read `package.json` files by walking up the
|
|
5
|
+
* directory tree, extracting version strings, and gathering package metadata
|
|
6
|
+
* (homepage, repository URLs) for automatic epilog generation in help output.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Package info extracted from `package.json` for epilog generation.
|
|
12
|
+
*/
|
|
13
|
+
interface PackageInfo {
|
|
14
|
+
homepage?: string;
|
|
15
|
+
repository?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Detect version: use provided version or read from nearest package.json.
|
|
19
|
+
*/
|
|
20
|
+
export declare const detectVersion: (providedVersion: string | undefined, startDir?: string) => Promise<string | undefined>;
|
|
21
|
+
/**
|
|
22
|
+
* Read package info (homepage, repository) from package.json synchronously.
|
|
23
|
+
* Returns only HTTPS URLs; other URL schemes are omitted.
|
|
24
|
+
*/
|
|
25
|
+
export declare const readPackageInfoSync: (startDir?: string) => PackageInfo;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH;;GAEG;AACH,UAAU,WAAW;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAqHD;;GAEG;AACH,eAAO,MAAM,aAAa,GACxB,iBAAiB,MAAM,GAAG,SAAS,EACnC,WAAU,MAAsB,KAC/B,OAAO,CAAC,MAAM,GAAG,SAAS,CAW5B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAC9B,WAAU,MAAsB,KAC/B,WAiBF,CAAC"}
|