@gunshi/bone 0.37.0 → 0.37.2

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/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- //#region ../../node_modules/.pnpm/args-tokens@0.28.0/node_modules/args-tokens/lib/parser-DT7Ztcch.d.ts
1
+ //#region ../../node_modules/.pnpm/args-tokens@0.28.2/node_modules/args-tokens/lib/parser-DT7Ztcch.d.ts
2
2
  //#region src/parser.d.ts
3
3
  /**
4
4
  * Entry point of argument parser.
@@ -55,7 +55,7 @@ interface ArgToken {
55
55
  * Parser Options.
56
56
  */
57
57
  //#endregion
58
- //#region ../../node_modules/.pnpm/args-tokens@0.28.0/node_modules/args-tokens/lib/resolver.d.ts
58
+ //#region ../../node_modules/.pnpm/args-tokens@0.28.2/node_modules/args-tokens/lib/resolver.d.ts
59
59
  //#region src/resolver.d.ts
60
60
  /**
61
61
  * An argument schema definition for command-line argument parsing.
@@ -548,7 +548,7 @@ type ResolveOptionValue<A extends ArgSchema, T> = A['multiple'] extends true ? T
548
548
  *
549
549
  * @internal
550
550
  */
551
- type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -readonly [Arg in keyof A]?: V[Arg] } & FilterArgs<A, V, 'default'> & FilterArgs<A, V, 'required'> & FilterPositionalArgs<A, V> extends infer P ? { [K in keyof P]: P[K] } : never;
551
+ type ResolveArgValues<A extends Args, V extends Record<keyof A, unknown>> = { -readonly [Arg in keyof A]?: V[Arg] } & FilterArgs<A, V, 'default'> & FilterArgs<A, V, 'required'> & FilterPositionalArgs<A, V> extends (infer P) ? { [K in keyof P]: P[K] } : never;
552
552
  /**
553
553
  * Filters the arguments based on their default values.
554
554
  *
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- //#region ../../node_modules/.pnpm/args-tokens@0.28.0/node_modules/args-tokens/lib/parser.js
1
+ //#region ../../node_modules/.pnpm/args-tokens@0.28.2/node_modules/args-tokens/lib/parser.js
2
2
  /**
3
3
  * forked from `nodejs/node` (`pkgjs/parseargs`)
4
4
  * repository url: https://github.com/nodejs/node (https://github.com/pkgjs/parseargs)
@@ -203,7 +203,7 @@ function hasOptionValue(value) {
203
203
  return !(value == null) && value.codePointAt(0) !== HYPHEN_CODE;
204
204
  }
205
205
  //#endregion
206
- //#region ../../node_modules/.pnpm/args-tokens@0.28.0/node_modules/args-tokens/lib/utils.js
206
+ //#region ../../node_modules/.pnpm/args-tokens@0.28.2/node_modules/args-tokens/lib/utils.js
207
207
  /**
208
208
  * Entry point of utils.
209
209
  *
@@ -234,7 +234,7 @@ function formatChoices(choices) {
234
234
  return choices.map((value) => JSON.stringify(value)).join(", ");
235
235
  }
236
236
  //#endregion
237
- //#region ../../node_modules/.pnpm/args-tokens@0.28.0/node_modules/args-tokens/lib/resolver.js
237
+ //#region ../../node_modules/.pnpm/args-tokens@0.28.2/node_modules/args-tokens/lib/resolver.js
238
238
  /**
239
239
  * Entry point of argument options resolver.
240
240
  *
@@ -336,9 +336,17 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
336
336
  const rest = [];
337
337
  const optionTokens = [];
338
338
  const positionalTokens = [];
339
+ const argEntries = Object.entries(args);
339
340
  let currentLongOption;
340
341
  let currentShortOption;
341
342
  const expandableShortOptions = [];
343
+ function getOptionName(rawArg, schema) {
344
+ return toKebab || schema.toKebab ? kebabnize(rawArg) : rawArg;
345
+ }
346
+ function checkLongTokenName(option, schema, token) {
347
+ if (token.rawName == void 0 || !hasLongOptionPrefix(token.rawName)) return false;
348
+ return token.name === option || schema.type === "boolean" && schema.negatable === true && token.name === `no-${option}`;
349
+ }
342
350
  function toShortValue() {
343
351
  if (expandableShortOptions.length === 0) return;
344
352
  else {
@@ -366,6 +374,13 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
366
374
  * separate tokens into positionals, long and short options, after that resolve values
367
375
  */
368
376
  const schemas = Object.values(args);
377
+ const booleanLongOptionNames = /* @__PURE__ */ new Set();
378
+ for (const [rawArg, schema] of Object.entries(args)) {
379
+ if (schema.type !== "boolean") continue;
380
+ const arg = toKebab || schema.toKebab ? kebabnize(rawArg) : rawArg;
381
+ booleanLongOptionNames.add(arg);
382
+ if (schema.negatable === true) booleanLongOptionNames.add(`no-${arg}`);
383
+ }
369
384
  let terminated = false;
370
385
  for (let i = 0; i < tokens.length; i++) {
371
386
  const token = tokens[i];
@@ -374,46 +389,52 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
374
389
  rest.push(token.value);
375
390
  continue;
376
391
  }
377
- if (currentShortOption) if (schemas.find((schema) => schema.short === currentShortOption.name && schema.type === "boolean")) {
378
- positionalTokens.push({ ...token });
379
- applyShortOptionValue();
380
- } else applyShortOptionValue(token.value);
381
- else if (currentLongOption) if (args[currentLongOption.name]?.type === "boolean") {
382
- positionalTokens.push({ ...token });
383
- applyLongOptionValue();
384
- } else applyLongOptionValue(token.value);
385
- else positionalTokens.push({ ...token });
386
- } else if (token.kind === "option") if (token.rawName) {
387
- if (hasLongOptionPrefix(token.rawName)) {
388
- applyLongOptionValue();
389
- if (token.inlineValue) optionTokens.push({ ...token });
390
- else currentLongOption = { ...token };
391
- applyShortOptionValue();
392
- } else if (isShortOption(token.rawName)) if (currentShortOption) {
393
- if (currentShortOption.index === token.index) if (shortGrouping) {
392
+ if (currentShortOption) {
393
+ if (schemas.find((schema) => schema.short === currentShortOption.name && schema.type === "boolean")) {
394
+ positionalTokens.push({ ...token });
395
+ applyShortOptionValue();
396
+ } else applyShortOptionValue(token.value);
397
+ } else if (currentLongOption) {
398
+ if (booleanLongOptionNames.has(currentLongOption.name)) {
399
+ positionalTokens.push({ ...token });
400
+ applyLongOptionValue();
401
+ } else applyLongOptionValue(token.value);
402
+ } else positionalTokens.push({ ...token });
403
+ } else if (token.kind === "option") {
404
+ if (token.rawName) {
405
+ if (hasLongOptionPrefix(token.rawName)) {
406
+ applyLongOptionValue();
407
+ if (token.inlineValue) optionTokens.push({ ...token });
408
+ else currentLongOption = { ...token };
409
+ applyShortOptionValue();
410
+ } else if (isShortOption(token.rawName)) {
411
+ if (currentShortOption) {
412
+ if (currentShortOption.index === token.index) {
413
+ if (shortGrouping) {
414
+ currentShortOption.value = token.value;
415
+ optionTokens.push({ ...currentShortOption });
416
+ currentShortOption = { ...token };
417
+ } else expandableShortOptions.push({ ...token });
418
+ } else {
419
+ currentShortOption.value = toShortValue();
420
+ optionTokens.push({ ...currentShortOption });
421
+ currentShortOption = { ...token };
422
+ }
423
+ applyLongOptionValue();
424
+ } else {
425
+ currentShortOption = { ...token };
426
+ applyLongOptionValue();
427
+ }
428
+ }
429
+ } else {
430
+ if (currentShortOption && currentShortOption.index == token.index && token.inlineValue) {
394
431
  currentShortOption.value = token.value;
395
432
  optionTokens.push({ ...currentShortOption });
396
- currentShortOption = { ...token };
397
- } else expandableShortOptions.push({ ...token });
398
- else {
399
- currentShortOption.value = toShortValue();
400
- optionTokens.push({ ...currentShortOption });
401
- currentShortOption = { ...token };
433
+ currentShortOption = void 0;
402
434
  }
403
435
  applyLongOptionValue();
404
- } else {
405
- currentShortOption = { ...token };
406
- applyLongOptionValue();
407
436
  }
408
437
  } else {
409
- if (currentShortOption && currentShortOption.index == token.index && token.inlineValue) {
410
- currentShortOption.value = token.value;
411
- optionTokens.push({ ...currentShortOption });
412
- currentShortOption = void 0;
413
- }
414
- applyLongOptionValue();
415
- }
416
- else {
417
438
  if (token.kind === "option-terminator") terminated = true;
418
439
  applyLongOptionValue();
419
440
  applyShortOptionValue();
@@ -431,11 +452,7 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
431
452
  const errors = [];
432
453
  const explicit = Object.create(null);
433
454
  const actualInputNames = /* @__PURE__ */ new Map();
434
- const argEntries = Object.entries(args);
435
455
  let requiredPositionalsAfter;
436
- function checkTokenName(option, schema, token) {
437
- return token.name === (schema.type === "boolean" ? schema.negatable && token.name?.startsWith("no-") ? `no-${option}` : option : option);
438
- }
439
456
  const positionalItemCount = tokens.filter((token) => token.kind === "positional").length;
440
457
  function getPositionalSkipIndex() {
441
458
  return Math.min(skipPositionalIndex, positionalItemCount);
@@ -446,7 +463,7 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
446
463
  }
447
464
  let positionalsCount = 0;
448
465
  for (const [rawArg, schema] of argEntries) {
449
- const arg = toKebab || schema.toKebab ? kebabnize(rawArg) : rawArg;
466
+ const arg = getOptionName(rawArg, schema);
450
467
  explicit[rawArg] = false;
451
468
  if (schema.type === "positional") {
452
469
  if (skipPositionalIndex > SKIP_POSITIONAL_DEFAULT) while (positionalsCount <= getPositionalSkipIndex()) positionalsCount++;
@@ -500,7 +517,7 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
500
517
  }
501
518
  if (schema.required) {
502
519
  if (!optionTokens.find((token) => {
503
- return schema.short && token.name === schema.short || token.rawName && hasLongOptionPrefix(token.rawName) && token.name === arg;
520
+ return schema.short && token.name === schema.short && token.rawName != void 0 && isShortOption(token.rawName) || checkLongTokenName(arg, schema, token);
504
521
  })) {
505
522
  errors.push(createRequireError(rawArg, arg, schema));
506
523
  continue;
@@ -508,14 +525,15 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
508
525
  }
509
526
  for (let i = 0; i < optionTokens.length; i++) {
510
527
  const token = optionTokens[i];
511
- if (checkTokenName(arg, schema, token) && token.rawName != void 0 && hasLongOptionPrefix(token.rawName) || schema.short === token.name && token.rawName != void 0 && isShortOption(token.rawName)) {
528
+ if (checkLongTokenName(arg, schema, token) || schema.short === token.name && token.rawName != void 0 && isShortOption(token.rawName)) {
512
529
  const invalid = validateRequire(token, rawArg, arg, schema);
513
530
  if (invalid) {
514
531
  errors.push(invalid);
515
532
  continue;
516
533
  }
517
534
  explicit[rawArg] = true;
518
- const actualInputName = isShortOption(token.rawName) ? `-${token.name}` : `--${arg}`;
535
+ const rawName = token.rawName;
536
+ const actualInputName = isShortOption(rawName) ? `-${token.name}` : rawName;
519
537
  actualInputNames.set(rawArg, actualInputName);
520
538
  const [parsedValue, error] = parse(token, rawArg, arg, schema);
521
539
  if (error) errors.push(error);
@@ -708,7 +726,7 @@ function checkConflicts(args, explicit, toKebab, actualInputNames) {
708
726
  return [];
709
727
  }
710
728
  //#endregion
711
- //#region ../../node_modules/.pnpm/args-tokens@0.28.0/node_modules/args-tokens/lib/index.js
729
+ //#region ../../node_modules/.pnpm/args-tokens@0.28.2/node_modules/args-tokens/lib/index.js
712
730
  /**
713
731
  * @author kazuya kawaguchi (a.k.a. kazupon)
714
732
  * @license MIT
@@ -1354,27 +1372,28 @@ function getPositionalTokens(tokens) {
1354
1372
  function resolveCommandTree(tokens, entry, options) {
1355
1373
  const positionals = getPositionalTokens(tokens);
1356
1374
  function resolveAsEntry() {
1357
- if (typeof entry === "function") if ("commandName" in entry && entry.commandName) return {
1358
- commandName: entry.commandName,
1359
- command: entry,
1360
- callMode: "entry",
1361
- commandPath: [],
1362
- depth: 0,
1363
- omitted: options.subCommands.size > 0 && !positionals[0],
1364
- levelSubCommands: options.subCommands.size > 0 ? options.subCommands : void 0
1365
- };
1366
- else return {
1367
- command: {
1368
- run: entry,
1369
- entry: true
1370
- },
1371
- callMode: "entry",
1372
- commandPath: [],
1373
- depth: 0,
1374
- omitted: options.subCommands.size > 0 && !positionals[0],
1375
- levelSubCommands: options.subCommands.size > 0 ? options.subCommands : void 0
1376
- };
1377
- else if (typeof entry === "object") return {
1375
+ if (typeof entry === "function") {
1376
+ if ("commandName" in entry && entry.commandName) return {
1377
+ commandName: entry.commandName,
1378
+ command: entry,
1379
+ callMode: "entry",
1380
+ commandPath: [],
1381
+ depth: 0,
1382
+ omitted: options.subCommands.size > 0 && !positionals[0],
1383
+ levelSubCommands: options.subCommands.size > 0 ? options.subCommands : void 0
1384
+ };
1385
+ else return {
1386
+ command: {
1387
+ run: entry,
1388
+ entry: true
1389
+ },
1390
+ callMode: "entry",
1391
+ commandPath: [],
1392
+ depth: 0,
1393
+ omitted: options.subCommands.size > 0 && !positionals[0],
1394
+ levelSubCommands: options.subCommands.size > 0 ? options.subCommands : void 0
1395
+ };
1396
+ } else if (typeof entry === "object") return {
1378
1397
  commandName: resolveEntryName(entry),
1379
1398
  command: entry,
1380
1399
  callMode: "entry",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gunshi/bone",
3
3
  "description": "gunshi minimum",
4
- "version": "0.37.0",
4
+ "version": "0.37.2",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -56,10 +56,10 @@
56
56
  "jsr-exports-lint": "^0.4.2",
57
57
  "publint": "^0.3.20",
58
58
  "tsdown": "0.21.0",
59
- "@gunshi/definition": "0.37.0",
60
- "@gunshi/plugin-global": "0.37.0",
61
- "@gunshi/plugin-renderer": "0.37.0",
62
- "gunshi": "0.37.0"
59
+ "@gunshi/plugin-global": "0.37.2",
60
+ "@gunshi/definition": "0.37.2",
61
+ "@gunshi/plugin-renderer": "0.37.2",
62
+ "gunshi": "0.37.2"
63
63
  },
64
64
  "scripts": {
65
65
  "build": "tsdown",