@gunshi/bone 0.36.0 → 0.37.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/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.1/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.1/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.
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.1/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.1/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.1/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];
@@ -378,7 +393,7 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
378
393
  positionalTokens.push({ ...token });
379
394
  applyShortOptionValue();
380
395
  } else applyShortOptionValue(token.value);
381
- else if (currentLongOption) if (args[currentLongOption.name]?.type === "boolean") {
396
+ else if (currentLongOption) if (booleanLongOptionNames.has(currentLongOption.name)) {
382
397
  positionalTokens.push({ ...token });
383
398
  applyLongOptionValue();
384
399
  } else applyLongOptionValue(token.value);
@@ -431,11 +446,7 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
431
446
  const errors = [];
432
447
  const explicit = Object.create(null);
433
448
  const actualInputNames = /* @__PURE__ */ new Map();
434
- const argEntries = Object.entries(args);
435
449
  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
450
  const positionalItemCount = tokens.filter((token) => token.kind === "positional").length;
440
451
  function getPositionalSkipIndex() {
441
452
  return Math.min(skipPositionalIndex, positionalItemCount);
@@ -446,7 +457,7 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
446
457
  }
447
458
  let positionalsCount = 0;
448
459
  for (const [rawArg, schema] of argEntries) {
449
- const arg = toKebab || schema.toKebab ? kebabnize(rawArg) : rawArg;
460
+ const arg = getOptionName(rawArg, schema);
450
461
  explicit[rawArg] = false;
451
462
  if (schema.type === "positional") {
452
463
  if (skipPositionalIndex > SKIP_POSITIONAL_DEFAULT) while (positionalsCount <= getPositionalSkipIndex()) positionalsCount++;
@@ -500,7 +511,7 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
500
511
  }
501
512
  if (schema.required) {
502
513
  if (!optionTokens.find((token) => {
503
- return schema.short && token.name === schema.short || token.rawName && hasLongOptionPrefix(token.rawName) && token.name === arg;
514
+ return schema.short && token.name === schema.short && token.rawName != void 0 && isShortOption(token.rawName) || checkLongTokenName(arg, schema, token);
504
515
  })) {
505
516
  errors.push(createRequireError(rawArg, arg, schema));
506
517
  continue;
@@ -508,14 +519,15 @@ function resolveArgs(args, tokens, { shortGrouping = false, skipPositional = SKI
508
519
  }
509
520
  for (let i = 0; i < optionTokens.length; i++) {
510
521
  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)) {
522
+ if (checkLongTokenName(arg, schema, token) || schema.short === token.name && token.rawName != void 0 && isShortOption(token.rawName)) {
512
523
  const invalid = validateRequire(token, rawArg, arg, schema);
513
524
  if (invalid) {
514
525
  errors.push(invalid);
515
526
  continue;
516
527
  }
517
528
  explicit[rawArg] = true;
518
- const actualInputName = isShortOption(token.rawName) ? `-${token.name}` : `--${arg}`;
529
+ const rawName = token.rawName;
530
+ const actualInputName = isShortOption(rawName) ? `-${token.name}` : rawName;
519
531
  actualInputNames.set(rawArg, actualInputName);
520
532
  const [parsedValue, error] = parse(token, rawArg, arg, schema);
521
533
  if (error) errors.push(error);
@@ -708,7 +720,7 @@ function checkConflicts(args, explicit, toKebab, actualInputNames) {
708
720
  return [];
709
721
  }
710
722
  //#endregion
711
- //#region ../../node_modules/.pnpm/args-tokens@0.28.0/node_modules/args-tokens/lib/index.js
723
+ //#region ../../node_modules/.pnpm/args-tokens@0.28.1/node_modules/args-tokens/lib/index.js
712
724
  /**
713
725
  * @author kazuya kawaguchi (a.k.a. kazupon)
714
726
  * @license MIT
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gunshi/bone",
3
3
  "description": "gunshi minimum",
4
- "version": "0.36.0",
4
+ "version": "0.37.1",
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.36.0",
60
- "@gunshi/plugin-global": "0.36.0",
61
- "@gunshi/plugin-renderer": "0.36.0",
62
- "gunshi": "0.36.0"
59
+ "@gunshi/plugin-global": "0.37.1",
60
+ "@gunshi/definition": "0.37.1",
61
+ "@gunshi/plugin-renderer": "0.37.1",
62
+ "gunshi": "0.37.1"
63
63
  },
64
64
  "scripts": {
65
65
  "build": "tsdown",