gunshi 0.37.2 → 0.37.3

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/bone.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { i as Args, n as ArgSchema, r as ArgValues, u as ArgToken } from "./resolver-D7DEcpu-.js";
2
- import { C as NormalizeToGunshiParams, D as SubCommandable, E as RenderingOptions, O as ValidationErrorsDecorator, S as MergeGunshiExtensions, T as RendererDecorator, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, d as CommandLoader, f as CommandRunner, g as ExtractArgExplicitlyProvided, h as ExtendContext, i as CommandCallMode, l as CommandEnvironment, m as DefaultGunshiParams, n as CliOptions, o as CommandContextCore, p as Commandable, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-CdM9C6VD.js";
1
+ import { i as Args, l as ArgToken, n as ArgSchema, r as ArgValues } from "./resolver-CbDvcwY3.js";
2
+ import { C as NormalizeToGunshiParams, D as SubCommandable, E as RenderingOptions, O as ValidationErrorsDecorator, S as MergeGunshiExtensions, T as RendererDecorator, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, d as CommandLoader, f as CommandRunner, g as ExtractArgExplicitlyProvided, h as ExtendContext, i as CommandCallMode, l as CommandEnvironment, m as DefaultGunshiParams, n as CliOptions, o as CommandContextCore, p as Commandable, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-H9nag_2Z.js";
3
3
 
4
4
  //#region src/cli/bone.d.ts
5
5
  /**
package/lib/bone.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as cliCore } from "./core-Ce6x0is5.js";
1
+ import { t as cliCore } from "./core-CLzX86kY.js";
2
2
  //#region src/cli/bone.ts
3
3
  /**
4
4
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -1,7 +1,7 @@
1
- import { r as hasPriorityValidationError } from "./error-CBijJN5L.js";
2
- import { t as plugin } from "./plugin-Cvf6mYto.js";
3
- import { a as namespacedId, o as COMMON_ARGS, t as renderer } from "./src-yiBqxwCm.js";
4
- import { t as cliCore } from "./core-Ce6x0is5.js";
1
+ import { r as hasPriorityValidationError } from "./error-B5QxSzk9.js";
2
+ import { t as plugin } from "./plugin-DneW3Toi.js";
3
+ import { a as namespacedId, o as COMMON_ARGS, t as renderer } from "./src-80_afJQM.js";
4
+ import { t as cliCore } from "./core-CLzX86kY.js";
5
5
  //#region ../plugin-global/src/types.ts
6
6
  /**
7
7
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -1,6 +1,6 @@
1
- import { i as Args, n as ArgSchema } from "./resolver-D7DEcpu-.js";
1
+ import { i as Args, n as ArgSchema } from "./resolver-CbDvcwY3.js";
2
2
 
3
- //#region ../../node_modules/.pnpm/args-tokens@0.28.2/node_modules/args-tokens/lib/combinators.d.ts
3
+ //#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/combinators.d.ts
4
4
 
5
5
  //#region src/combinators.d.ts
6
6
  /**
@@ -671,7 +671,6 @@ declare function merge<T extends Args[]>(...schemas: T): MergeArgs<T>;
671
671
  */
672
672
  declare function extend<T extends Args, U extends Args>(base: T, overrides: U): Omit<T, keyof U> & U;
673
673
  //#endregion
674
- //#endregion
675
674
  //#region src/combinators.d.ts
676
675
  /**
677
676
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -1,6 +1,6 @@
1
- import { t as formatChoices } from "./utils-oPJNnmOb.js";
2
- import { n as ArgsValidationErrorKeys, t as ArgsValidationError } from "./resolver-dsINFnU2.js";
3
- //#region ../../node_modules/.pnpm/args-tokens@0.28.2/node_modules/args-tokens/lib/combinators.js
1
+ import { t as formatChoices } from "./utils-DbRhwNIU.js";
2
+ import { n as ArgsValidationErrorKeys, t as ArgsValidationError } from "./resolver-D5skgYcF.js";
3
+ //#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/combinators.js
4
4
  /**
5
5
  * Parser combinator factory functions for composable argument schema construction.
6
6
  *
package/lib/context.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { i as Args, r as ArgValues, u as ArgToken } from "./resolver-D7DEcpu-.js";
2
- import { _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, g as ExtractArgExplicitlyProvided, h as ExtendContext, i as CommandCallMode, m as DefaultGunshiParams, n as CliOptions, r as Command, s as CommandContextExtension, x as LazyCommand, y as GunshiParams } from "./types-CdM9C6VD.js";
1
+ import { i as Args, l as ArgToken, r as ArgValues } from "./resolver-CbDvcwY3.js";
2
+ import { _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, g as ExtractArgExplicitlyProvided, h as ExtendContext, i as CommandCallMode, m as DefaultGunshiParams, n as CliOptions, r as Command, s as CommandContextExtension, x as LazyCommand, y as GunshiParams } from "./types-H9nag_2Z.js";
3
3
 
4
4
  //#region src/context.d.ts
5
5
 
@@ -1,8 +1,8 @@
1
1
  import { i as NOOP, r as CLI_OPTIONS_DEFAULT, t as createCommandContext } from "./context-CAPhwgJJ.js";
2
- import { n as kebabnize } from "./utils-oPJNnmOb.js";
2
+ import { n as kebabnize } from "./utils-DbRhwNIU.js";
3
3
  import { create, getCommandSubCommands, isLazyCommand, resolveLazyCommand } from "./utils.js";
4
- import { a as parseArgs, i as resolveArgs, n as ArgsValidationErrorKeys, t as ArgsValidationError } from "./resolver-dsINFnU2.js";
5
- import { n as CommandNotFoundErrorKeys, r as hasPriorityValidationError, t as CommandNotFoundError } from "./error-CBijJN5L.js";
4
+ import { a as parseArgs, i as resolveArgs, n as ArgsValidationErrorKeys, t as ArgsValidationError } from "./resolver-D5skgYcF.js";
5
+ import { n as CommandNotFoundErrorKeys, r as hasPriorityValidationError, t as CommandNotFoundError } from "./error-B5QxSzk9.js";
6
6
  //#region src/decorators.ts
7
7
  /**
8
8
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -1,5 +1,5 @@
1
- import { i as Args, n as ArgSchema, r as ArgValues } from "./resolver-D7DEcpu-.js";
2
- import { C as NormalizeToGunshiParams, _ as ExtractArgs, b as GunshiParamsConstraint, d as CommandLoader, f as CommandRunner, h as ExtendContext, m as DefaultGunshiParams, r as Command, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-CdM9C6VD.js";
1
+ import { i as Args, n as ArgSchema, r as ArgValues } from "./resolver-CbDvcwY3.js";
2
+ import { C as NormalizeToGunshiParams, _ as ExtractArgs, b as GunshiParamsConstraint, d as CommandLoader, f as CommandRunner, h as ExtendContext, m as DefaultGunshiParams, r as Command, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-H9nag_2Z.js";
3
3
  import { CommandContextParams, createCommandContext } from "./context.js";
4
4
 
5
5
  //#region src/definition.d.ts
@@ -0,0 +1,139 @@
1
+ import { n as ArgsValidationErrorKeys, r as isArgsValidationError$1, t as ArgsValidationError } from "./resolver-D5skgYcF.js";
2
+ //#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/index.js
3
+ /**
4
+ * @author kazuya kawaguchi (a.k.a. kazupon)
5
+ * @license MIT
6
+ */
7
+ /**
8
+ * @author kazuya kawaguchi (a.k.a. kazupon)
9
+ * @license MIT
10
+ */
11
+ //#endregion
12
+ //#region src/error.ts
13
+ /**
14
+ * @author kazuya kawaguchi (a.k.a. kazupon)
15
+ * @license MIT
16
+ */
17
+ /**
18
+ * Command not found error resource keys.
19
+ */
20
+ const CommandNotFoundErrorKeys = { notFound: "err:cmd:not-found" };
21
+ /**
22
+ * Brand that marks {@link CommandNotFoundError} instances.
23
+ *
24
+ * The brand is looked up in the global symbol registry with `Symbol.for`, so it stays
25
+ * identical across bundled copies of gunshi (`gunshi`, `@gunshi/plugin`, `@gunshi/bone`)
26
+ * and across realms. It lets {@link isCommandNotFoundError} recognize errors created by
27
+ * another copy, where `instanceof` cannot match.
28
+ */
29
+ const COMMAND_NOT_FOUND_ERROR_BRAND = Symbol.for("gunshi.CommandNotFoundError");
30
+ /**
31
+ * Error raised when a command cannot be resolved.
32
+ *
33
+ * Each instance carries a non-enumerable brand keyed by
34
+ * `Symbol.for('gunshi.CommandNotFoundError')`, so that {@link isCommandNotFoundError}
35
+ * recognizes it even when it was created by another bundled copy of gunshi.
36
+ */
37
+ var CommandNotFoundError = class extends Error {
38
+ code;
39
+ values;
40
+ commandName;
41
+ candidates;
42
+ commandPath;
43
+ /**
44
+ * Create a command-not-found error.
45
+ *
46
+ * @param message - Fallback error message
47
+ * @param options - Command-not-found metadata
48
+ */
49
+ constructor(message, options) {
50
+ super(message, { cause: options.cause });
51
+ this.name = "CommandNotFoundError";
52
+ this.code = options.code;
53
+ this.values = options.values || {};
54
+ this.commandName = options.commandName;
55
+ this.candidates = options.candidates || [];
56
+ this.commandPath = options.commandPath || [];
57
+ Object.defineProperty(this, COMMAND_NOT_FOUND_ERROR_BRAND, {
58
+ value: true,
59
+ enumerable: false,
60
+ writable: false,
61
+ configurable: false
62
+ });
63
+ }
64
+ };
65
+ /**
66
+ * Check whether an error is a {@link CommandNotFoundError}.
67
+ *
68
+ * `instanceof` alone is not enough: `@gunshi/plugin` is bundled with its own copy of this
69
+ * class (`noExternal: ['gunshi/plugin']`), so an error thrown by `gunshi` is never an instance
70
+ * of the class a plugin imports. Errors from another copy are recognized through the
71
+ * `Symbol.for('gunshi.CommandNotFoundError')` brand, which does not depend on `error.name`.
72
+ *
73
+ * @param error - An unknown error
74
+ * @returns `true` if the error is a {@link CommandNotFoundError}
75
+ */
76
+ function isCommandNotFoundError(error) {
77
+ if (error instanceof CommandNotFoundError) return true;
78
+ if (!isRecord(error) || !hasCommandNotFoundErrorShape(error)) return false;
79
+ if (Object.hasOwn(error, COMMAND_NOT_FOUND_ERROR_BRAND) && error[COMMAND_NOT_FOUND_ERROR_BRAND] === true) return true;
80
+ return error instanceof Error && error.name === "CommandNotFoundError";
81
+ }
82
+ /**
83
+ * Check whether an error is an {@link ArgsValidationError}.
84
+ *
85
+ * Prefer this over the `args-tokens` guard of the same name. Both recognize errors from another
86
+ * bundled copy through the `Symbol.for('args-tokens.ArgsValidationError')` brand that
87
+ * `args-tokens` 0.29.0 or later sets, including subclasses such as `ArgResolveError` that
88
+ * override `name` with the argument name. This guard additionally:
89
+ *
90
+ * - recognizes direct `ArgsValidationError` instances from copies bundling `args-tokens`
91
+ * older than 0.29.0, which do not set the brand
92
+ * - checks that `code` and `values` of an error from another copy have the expected types
93
+ *
94
+ * The guard narrows only to {@link ArgsValidationError}: across copies,
95
+ * `instanceof ArgResolveError` still fails, so do not rely on `type` or `schema` for such errors.
96
+ *
97
+ * @param error - An unknown error
98
+ * @returns `true` if the error is an {@link ArgsValidationError}
99
+ */
100
+ function isArgsValidationError(error) {
101
+ if (error instanceof ArgsValidationError) return true;
102
+ if (!isRecord(error) || !hasArgsValidationErrorShape(error)) return false;
103
+ if (isArgsValidationError$1(error)) return true;
104
+ return error instanceof Error && error.name === "ArgsValidationError";
105
+ }
106
+ function isRecord(value) {
107
+ return typeof value === "object" && value !== null;
108
+ }
109
+ function isStringArray(value) {
110
+ return Array.isArray(value) && value.every((item) => typeof item === "string");
111
+ }
112
+ /**
113
+ * Check whether `code` is an own or inherited property that is a string or `undefined`.
114
+ *
115
+ * Constructors always assign `code`, even when the option is omitted.
116
+ *
117
+ * @param error - An error from another copy
118
+ * @returns `true` if `code` has the expected type
119
+ */
120
+ function hasOptionalStringCode(error) {
121
+ return "code" in error && (error.code === void 0 || typeof error.code === "string");
122
+ }
123
+ function hasCommandNotFoundErrorShape(error) {
124
+ return hasOptionalStringCode(error) && isRecord(error.values) && typeof error.commandName === "string" && isStringArray(error.candidates) && isStringArray(error.commandPath);
125
+ }
126
+ function hasArgsValidationErrorShape(error) {
127
+ return hasOptionalStringCode(error) && isRecord(error.values);
128
+ }
129
+ /**
130
+ * Check whether validation errors should be handled before version, help, or command execution.
131
+ *
132
+ * @param error - An aggregate validation error
133
+ * @returns `true` if the validation error must be handled with priority
134
+ */
135
+ function hasPriorityValidationError(error) {
136
+ return error?.errors.some((error) => isCommandNotFoundError(error) || isArgsValidationError(error) && error.code === ArgsValidationErrorKeys.unknownOption) ?? false;
137
+ }
138
+ //#endregion
139
+ export { isCommandNotFoundError as a, isArgsValidationError as i, CommandNotFoundErrorKeys as n, hasPriorityValidationError as r, CommandNotFoundError as t };
@@ -1,4 +1,5 @@
1
- import { m as DefaultGunshiParams, n as CliOptions } from "./types-CdM9C6VD.js";
1
+ import { a as ArgsValidationError } from "./resolver-CbDvcwY3.js";
2
+ import { m as DefaultGunshiParams, n as CliOptions } from "./types-H9nag_2Z.js";
2
3
 
3
4
  //#region src/constants.d.ts
4
5
  /**
@@ -9,10 +10,6 @@ declare const ANONYMOUS_COMMAND_NAME = "(anonymous)";
9
10
  declare const CLI_OPTIONS_DEFAULT: CliOptions<DefaultGunshiParams>;
10
11
  //#endregion
11
12
  //#region src/error.d.ts
12
- /**
13
- * @author kazuya kawaguchi (a.k.a. kazupon)
14
- * @license MIT
15
- */
16
13
  /**
17
14
  * Command not found error resource keys.
18
15
  */
@@ -54,6 +51,10 @@ type CommandNotFoundErrorOptions = {
54
51
  };
55
52
  /**
56
53
  * Error raised when a command cannot be resolved.
54
+ *
55
+ * Each instance carries a non-enumerable brand keyed by
56
+ * `Symbol.for('gunshi.CommandNotFoundError')`, so that {@link isCommandNotFoundError}
57
+ * recognizes it even when it was created by another bundled copy of gunshi.
57
58
  */
58
59
  declare class CommandNotFoundError extends Error {
59
60
  readonly code?: CommandNotFoundErrorCode;
@@ -72,10 +73,34 @@ declare class CommandNotFoundError extends Error {
72
73
  /**
73
74
  * Check whether an error is a {@link CommandNotFoundError}.
74
75
  *
76
+ * `instanceof` alone is not enough: `@gunshi/plugin` is bundled with its own copy of this
77
+ * class (`noExternal: ['gunshi/plugin']`), so an error thrown by `gunshi` is never an instance
78
+ * of the class a plugin imports. Errors from another copy are recognized through the
79
+ * `Symbol.for('gunshi.CommandNotFoundError')` brand, which does not depend on `error.name`.
80
+ *
75
81
  * @param error - An unknown error
76
82
  * @returns `true` if the error is a {@link CommandNotFoundError}
77
83
  */
78
84
  declare function isCommandNotFoundError(error: unknown): error is CommandNotFoundError;
85
+ /**
86
+ * Check whether an error is an {@link ArgsValidationError}.
87
+ *
88
+ * Prefer this over the `args-tokens` guard of the same name. Both recognize errors from another
89
+ * bundled copy through the `Symbol.for('args-tokens.ArgsValidationError')` brand that
90
+ * `args-tokens` 0.29.0 or later sets, including subclasses such as `ArgResolveError` that
91
+ * override `name` with the argument name. This guard additionally:
92
+ *
93
+ * - recognizes direct `ArgsValidationError` instances from copies bundling `args-tokens`
94
+ * older than 0.29.0, which do not set the brand
95
+ * - checks that `code` and `values` of an error from another copy have the expected types
96
+ *
97
+ * The guard narrows only to {@link ArgsValidationError}: across copies,
98
+ * `instanceof ArgResolveError` still fails, so do not rely on `type` or `schema` for such errors.
99
+ *
100
+ * @param error - An unknown error
101
+ * @returns `true` if the error is an {@link ArgsValidationError}
102
+ */
103
+ declare function isArgsValidationError(error: unknown): error is ArgsValidationError;
79
104
  /**
80
105
  * Check whether validation errors should be handled before version, help, or command execution.
81
106
  *
@@ -84,4 +109,4 @@ declare function isCommandNotFoundError(error: unknown): error is CommandNotFoun
84
109
  */
85
110
  declare function hasPriorityValidationError(error: AggregateError | undefined): boolean;
86
111
  //#endregion
87
- export { hasPriorityValidationError as a, CLI_OPTIONS_DEFAULT as c, CommandNotFoundErrorOptions as i, CommandNotFoundErrorCode as n, isCommandNotFoundError as o, CommandNotFoundErrorKeys as r, ANONYMOUS_COMMAND_NAME as s, CommandNotFoundError as t };
112
+ export { hasPriorityValidationError as a, ANONYMOUS_COMMAND_NAME as c, CommandNotFoundErrorOptions as i, CLI_OPTIONS_DEFAULT as l, CommandNotFoundErrorCode as n, isArgsValidationError as o, CommandNotFoundErrorKeys as r, isCommandNotFoundError as s, CommandNotFoundError as t };
@@ -1,4 +1,4 @@
1
- import { b as GunshiParamsConstraint, m as DefaultGunshiParams, n as CliOptions, r as Command, x as LazyCommand } from "./types-CdM9C6VD.js";
1
+ import { b as GunshiParamsConstraint, m as DefaultGunshiParams, n as CliOptions, r as Command, x as LazyCommand } from "./types-H9nag_2Z.js";
2
2
 
3
3
  //#region src/generator.d.ts
4
4
 
package/lib/generator.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { create } from "./utils.js";
2
- import { t as cli } from "./cli-xU__0QWJ.js";
2
+ import { t as cli } from "./cli-BnmSo-DW.js";
3
3
  //#region src/generator.ts
4
4
  /**
5
5
  * The entry for usage generator.
package/lib/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { a as ArgsValidationError, c as isArgsValidationError, d as parseArgs, i as Args, l as resolveArgs, n as ArgSchema, o as ArgsValidationErrorCode, r as ArgValues, s as ArgsValidationErrorKeys, u as ArgToken } from "./resolver-D7DEcpu-.js";
2
- import { A as Plugin, C as NormalizeToGunshiParams, D as SubCommandable, E as RenderingOptions, F as PluginWithExtension, I as PluginWithoutExtension, L as plugin, M as PluginExtension, N as PluginFunction, O as ValidationErrorsDecorator, P as PluginOptions, R as PluginContext, S as MergeGunshiExtensions, T as RendererDecorator, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, d as CommandLoader, f as CommandRunner, g as ExtractArgExplicitlyProvided, h as ExtendContext, i as CommandCallMode, j as PluginDependency, k as OnPluginExtension, l as CommandEnvironment, m as DefaultGunshiParams, n as CliOptions, o as CommandContextCore, p as Commandable, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-CdM9C6VD.js";
1
+ import { a as ArgsValidationError, c as resolveArgs, i as Args, l as ArgToken, n as ArgSchema, o as ArgsValidationErrorCode, r as ArgValues, s as ArgsValidationErrorKeys, u as parseArgs } from "./resolver-CbDvcwY3.js";
2
+ import { A as Plugin, C as NormalizeToGunshiParams, D as SubCommandable, E as RenderingOptions, F as PluginWithExtension, I as PluginWithoutExtension, L as plugin, M as PluginExtension, N as PluginFunction, O as ValidationErrorsDecorator, P as PluginOptions, R as PluginContext, S as MergeGunshiExtensions, T as RendererDecorator, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, d as CommandLoader, f as CommandRunner, g as ExtractArgExplicitlyProvided, h as ExtendContext, i as CommandCallMode, j as PluginDependency, k as OnPluginExtension, l as CommandEnvironment, m as DefaultGunshiParams, n as CliOptions, o as CommandContextCore, p as Commandable, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-H9nag_2Z.js";
3
3
  import { CommandContextParams, createCommandContext } from "./context.js";
4
4
  import { define, defineWithTypes, lazy, lazyWithTypes } from "./definition.js";
5
- import { a as hasPriorityValidationError, i as CommandNotFoundErrorOptions, n as CommandNotFoundErrorCode, o as isCommandNotFoundError, r as CommandNotFoundErrorKeys, s as ANONYMOUS_COMMAND_NAME, t as CommandNotFoundError } from "./error-Ck8cJsi0.js";
5
+ import { a as hasPriorityValidationError, c as ANONYMOUS_COMMAND_NAME, i as CommandNotFoundErrorOptions, n as CommandNotFoundErrorCode, o as isArgsValidationError, r as CommandNotFoundErrorKeys, s as isCommandNotFoundError, t as CommandNotFoundError } from "./error-DHF6LJCG.js";
6
6
 
7
7
  //#region ../plugin-i18n/src/types.d.ts
8
8
  /**
package/lib/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { n as ANONYMOUS_COMMAND_NAME, t as createCommandContext } from "./context-CAPhwgJJ.js";
2
- import { a as parseArgs, i as resolveArgs, n as ArgsValidationErrorKeys, r as isArgsValidationError, t as ArgsValidationError } from "./resolver-dsINFnU2.js";
3
- import { i as isCommandNotFoundError, n as CommandNotFoundErrorKeys, r as hasPriorityValidationError, t as CommandNotFoundError } from "./error-CBijJN5L.js";
4
- import { t as plugin } from "./plugin-Cvf6mYto.js";
5
- import { a as namespacedId } from "./src-yiBqxwCm.js";
6
- import { t as cli } from "./cli-xU__0QWJ.js";
2
+ import { a as parseArgs, i as resolveArgs, n as ArgsValidationErrorKeys, t as ArgsValidationError } from "./resolver-D5skgYcF.js";
3
+ import { a as isCommandNotFoundError, i as isArgsValidationError, n as CommandNotFoundErrorKeys, r as hasPriorityValidationError, t as CommandNotFoundError } from "./error-B5QxSzk9.js";
4
+ import { t as plugin } from "./plugin-DneW3Toi.js";
5
+ import { a as namespacedId } from "./src-80_afJQM.js";
6
+ import { t as cli } from "./cli-BnmSo-DW.js";
7
7
  import { define, defineWithTypes, lazy, lazyWithTypes } from "./definition.js";
8
8
  //#region ../plugin-i18n/src/translation.ts
9
9
  /**
@@ -1,4 +1,4 @@
1
- import "./error-CBijJN5L.js";
1
+ import "./error-B5QxSzk9.js";
2
2
  //#region src/plugin/core.ts
3
3
  /**
4
4
  * @author kazuya kawaguchi (a.k.a. kazupon)
package/lib/plugin.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { a as ArgsValidationError, c as isArgsValidationError, i as Args, n as ArgSchema, o as ArgsValidationErrorCode, r as ArgValues, s as ArgsValidationErrorKeys, u as ArgToken } from "./resolver-D7DEcpu-.js";
2
- import { A as Plugin, C as NormalizeToGunshiParams, F as PluginWithExtension, I as PluginWithoutExtension, L as plugin, M as PluginExtension, N as PluginFunction, O as ValidationErrorsDecorator, P as PluginOptions, R as PluginContext, S as MergeGunshiExtensions, T as RendererDecorator, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, f as CommandRunner, h as ExtendContext, j as PluginDependency, k as OnPluginExtension, m as DefaultGunshiParams, o as CommandContextCore, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-CdM9C6VD.js";
1
+ import { a as ArgsValidationError, i as Args, l as ArgToken, n as ArgSchema, o as ArgsValidationErrorCode, r as ArgValues, s as ArgsValidationErrorKeys } from "./resolver-CbDvcwY3.js";
2
+ import { A as Plugin, C as NormalizeToGunshiParams, F as PluginWithExtension, I as PluginWithoutExtension, L as plugin, M as PluginExtension, N as PluginFunction, O as ValidationErrorsDecorator, P as PluginOptions, R as PluginContext, S as MergeGunshiExtensions, T as RendererDecorator, _ as ExtractArgs, a as CommandContext, b as GunshiParamsConstraint, c as CommandDecorator, f as CommandRunner, h as ExtendContext, j as PluginDependency, k as OnPluginExtension, m as DefaultGunshiParams, o as CommandContextCore, r as Command, s as CommandContextExtension, t as Awaitable, u as CommandExamplesFetcher, v as ExtractExtensions, w as Prettify, x as LazyCommand, y as GunshiParams } from "./types-H9nag_2Z.js";
3
3
  import { CommandContextParams, createCommandContext } from "./context.js";
4
- import { a as hasPriorityValidationError, c as CLI_OPTIONS_DEFAULT, i as CommandNotFoundErrorOptions, n as CommandNotFoundErrorCode, o as isCommandNotFoundError, r as CommandNotFoundErrorKeys, s as ANONYMOUS_COMMAND_NAME, t as CommandNotFoundError } from "./error-Ck8cJsi0.js";
4
+ import { a as hasPriorityValidationError, c as ANONYMOUS_COMMAND_NAME, i as CommandNotFoundErrorOptions, l as CLI_OPTIONS_DEFAULT, n as CommandNotFoundErrorCode, o as isArgsValidationError, r as CommandNotFoundErrorKeys, s as isCommandNotFoundError, t as CommandNotFoundError } from "./error-DHF6LJCG.js";
5
5
 
6
6
  //#region src/plugin.d.ts
7
7
  /**
package/lib/plugin.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as ANONYMOUS_COMMAND_NAME, r as CLI_OPTIONS_DEFAULT, t as createCommandContext } from "./context-CAPhwgJJ.js";
2
- import { n as ArgsValidationErrorKeys, r as isArgsValidationError, t as ArgsValidationError } from "./resolver-dsINFnU2.js";
3
- import { i as isCommandNotFoundError, n as CommandNotFoundErrorKeys, r as hasPriorityValidationError, t as CommandNotFoundError } from "./error-CBijJN5L.js";
4
- import { t as plugin } from "./plugin-Cvf6mYto.js";
2
+ import { n as ArgsValidationErrorKeys, t as ArgsValidationError } from "./resolver-D5skgYcF.js";
3
+ import { a as isCommandNotFoundError, i as isArgsValidationError, n as CommandNotFoundErrorKeys, r as hasPriorityValidationError, t as CommandNotFoundError } from "./error-B5QxSzk9.js";
4
+ import { t as plugin } from "./plugin-DneW3Toi.js";
5
5
  export { ANONYMOUS_COMMAND_NAME, ArgsValidationError, ArgsValidationErrorKeys, CLI_OPTIONS_DEFAULT, CommandNotFoundError, CommandNotFoundErrorKeys, createCommandContext, hasPriorityValidationError, isArgsValidationError, isCommandNotFoundError, plugin };
package/lib/renderer.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as CommandContext, m as DefaultGunshiParams, y as GunshiParams } from "./types-CdM9C6VD.js";
1
+ import { a as CommandContext, m as DefaultGunshiParams, y as GunshiParams } from "./types-H9nag_2Z.js";
2
2
 
3
3
  //#region ../plugin-renderer/src/header.d.ts
4
4
  /**
package/lib/renderer.js CHANGED
@@ -1,4 +1,4 @@
1
- import { i as renderHeader, n as renderValidationErrors, r as renderUsage } from "./src-yiBqxwCm.js";
1
+ import { i as renderHeader, n as renderValidationErrors, r as renderUsage } from "./src-80_afJQM.js";
2
2
  //#region src/renderer.ts
3
3
  /**
4
4
  * @author kazuya kawaguchi (a.k.a. kazupon)
@@ -1,4 +1,4 @@
1
- //#region ../../node_modules/.pnpm/args-tokens@0.28.2/node_modules/args-tokens/lib/parser-DT7Ztcch.d.ts
1
+ //#region ../../node_modules/.pnpm/args-tokens@0.29.0/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.
@@ -88,7 +88,7 @@ declare function parseArgs(args: string[], options?: ParserOptions): ArgToken[];
88
88
  * @returns Whether `arg` is a short option.
89
89
  */
90
90
  //#endregion
91
- //#region ../../node_modules/.pnpm/args-tokens@0.28.2/node_modules/args-tokens/lib/resolver.d.ts
91
+ //#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/resolver.d.ts
92
92
  //#region src/resolver.d.ts
93
93
  /**
94
94
  * An argument schema definition for command-line argument parsing.
@@ -568,6 +568,10 @@ type ArgsValidationErrorCode = (typeof ArgsValidationErrorKeys)[keyof typeof Arg
568
568
  * The `message` remains the English fallback message. Renderers can use `code`
569
569
  * and `values` to localize the error, falling back to `message` when localization
570
570
  * is unavailable.
571
+ *
572
+ * Each instance carries a non-enumerable brand keyed by
573
+ * `Symbol.for('args-tokens.ArgsValidationError')`, which {@link isArgsValidationError}
574
+ * uses to recognize instances created by another bundled copy of `args-tokens`.
571
575
  */
572
576
  declare class ArgsValidationError extends Error {
573
577
  /**
@@ -592,13 +596,6 @@ declare class ArgsValidationError extends Error {
592
596
  cause?: unknown;
593
597
  });
594
598
  }
595
- /**
596
- * Check whether the given value is an {@link ArgsValidationError}.
597
- *
598
- * @param error - value to check
599
- * @returns `true` when the value is an `ArgsValidationError`
600
- */
601
- declare function isArgsValidationError(error: unknown): error is ArgsValidationError;
602
599
  /**
603
600
  * An object that contains {@link ArgSchema | argument schema}.
604
601
  *
@@ -730,8 +727,5 @@ declare function resolveArgs<A extends Args>(args: A, tokens: ArgToken[], {
730
727
  error: AggregateError | undefined;
731
728
  explicit: ArgExplicitlyProvided<A>;
732
729
  };
733
- /**
734
- * An error type for {@link ArgResolveError}.
735
- */
736
730
  //#endregion
737
- export { ArgsValidationError as a, isArgsValidationError as c, parseArgs as d, Args as i, resolveArgs as l, ArgSchema as n, ArgsValidationErrorCode as o, ArgValues as r, ArgsValidationErrorKeys as s, ArgExplicitlyProvided as t, ArgToken as u };
731
+ export { ArgsValidationError as a, resolveArgs as c, Args as i, ArgToken as l, ArgSchema as n, ArgsValidationErrorCode as o, ArgValues as r, ArgsValidationErrorKeys as s, ArgExplicitlyProvided as t, parseArgs as u };
@@ -1,5 +1,5 @@
1
- import { n as kebabnize, t as formatChoices } from "./utils-oPJNnmOb.js";
2
- //#region ../../node_modules/.pnpm/args-tokens@0.28.2/node_modules/args-tokens/lib/parser.js
1
+ import { n as kebabnize, t as formatChoices } from "./utils-DbRhwNIU.js";
2
+ //#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/parser.js
3
3
  /**
4
4
  * forked from `nodejs/node` (`pkgjs/parseargs`)
5
5
  * repository url: https://github.com/nodejs/node (https://github.com/pkgjs/parseargs)
@@ -204,7 +204,7 @@ function hasOptionValue(value) {
204
204
  return !(value == null) && value.codePointAt(0) !== HYPHEN_CODE;
205
205
  }
206
206
  //#endregion
207
- //#region ../../node_modules/.pnpm/args-tokens@0.28.2/node_modules/args-tokens/lib/resolver.js
207
+ //#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/resolver.js
208
208
  /**
209
209
  * Entry point of argument options resolver.
210
210
  *
@@ -229,11 +229,24 @@ const ArgsValidationErrorKeys = {
229
229
  unknownOption: "err:arg:unknown-option"
230
230
  };
231
231
  /**
232
+ * Brand that marks {@link ArgsValidationError} instances.
233
+ *
234
+ * The brand is looked up in the global symbol registry with `Symbol.for`, so it stays
235
+ * identical across bundled copies of this module and across realms. It lets
236
+ * {@link isArgsValidationError} recognize errors created by another copy of `args-tokens`,
237
+ * where `instanceof` cannot match.
238
+ */
239
+ const ARGS_VALIDATION_ERROR_BRAND = Symbol.for("args-tokens.ArgsValidationError");
240
+ /**
232
241
  * An error that contains structured metadata for argument validation failures.
233
242
  *
234
243
  * The `message` remains the English fallback message. Renderers can use `code`
235
244
  * and `values` to localize the error, falling back to `message` when localization
236
245
  * is unavailable.
246
+ *
247
+ * Each instance carries a non-enumerable brand keyed by
248
+ * `Symbol.for('args-tokens.ArgsValidationError')`, which {@link isArgsValidationError}
249
+ * uses to recognize instances created by another bundled copy of `args-tokens`.
237
250
  */
238
251
  var ArgsValidationError = class extends Error {
239
252
  /**
@@ -257,16 +270,35 @@ var ArgsValidationError = class extends Error {
257
270
  this.name = "ArgsValidationError";
258
271
  this.code = options.code;
259
272
  this.values = options.values ?? {};
273
+ Object.defineProperty(this, ARGS_VALIDATION_ERROR_BRAND, {
274
+ value: true,
275
+ enumerable: false,
276
+ writable: false,
277
+ configurable: false
278
+ });
260
279
  }
261
280
  };
262
281
  /**
263
282
  * Check whether the given value is an {@link ArgsValidationError}.
264
283
  *
284
+ * This guard also recognizes errors created by another bundled copy of `args-tokens`
285
+ * (0.29.0 or later), where `instanceof` does not match. Such an error must have an own brand
286
+ * keyed by `Symbol.for('args-tokens.ArgsValidationError')` set to `true`, and a `values` object.
287
+ * The guard does not rely on `error.name`, so subclasses such as {@link ArgResolveError} that
288
+ * override `name` are still recognized.
289
+ *
290
+ * The guard narrows to `ArgsValidationError` only. Across bundled copies,
291
+ * `instanceof ArgResolveError` still does not match.
292
+ *
265
293
  * @param error - value to check
266
294
  * @returns `true` when the value is an `ArgsValidationError`
267
295
  */
268
296
  function isArgsValidationError(error) {
269
- return error instanceof ArgsValidationError;
297
+ if (error instanceof ArgsValidationError) return true;
298
+ if (typeof error !== "object" || error === null) return false;
299
+ if (!Object.hasOwn(error, ARGS_VALIDATION_ERROR_BRAND) || error[ARGS_VALIDATION_ERROR_BRAND] !== true) return false;
300
+ const values = error.values;
301
+ return typeof values === "object" && values !== null;
270
302
  }
271
303
  const SKIP_POSITIONAL_DEFAULT = -1;
272
304
  /**
@@ -649,10 +681,8 @@ function createChoiceError(rawArg, option, schema, actual) {
649
681
  });
650
682
  }
651
683
  function createCustomParseError(error, rawArg, option, schema, value) {
652
- if (isArgsValidationError(error)) {
653
- augmentValidationError(error, rawArg, option, schema, value);
654
- return error;
655
- }
684
+ const reused = reuseValidationError(error, rawArg, option, schema, value);
685
+ if (reused) return reused;
656
686
  const reason = getErrorReason(error);
657
687
  return new ArgsValidationError(reason, {
658
688
  code: ArgsValidationErrorKeys.customParse,
@@ -664,6 +694,26 @@ function createCustomParseError(error, rawArg, option, schema, value) {
664
694
  cause: error
665
695
  });
666
696
  }
697
+ /**
698
+ * Reuse an {@link ArgsValidationError} thrown from a custom `parse` function, filling in missing values.
699
+ *
700
+ * @param error - The value thrown from `parse`
701
+ * @param rawArg - The argument key in the schema
702
+ * @param option - The option name used on the command line
703
+ * @param schema - The argument schema
704
+ * @param value - The raw input value
705
+ * @returns The same error when it can be reused, otherwise `undefined` so the caller wraps it.
706
+ * Inspecting or updating the thrown value can throw, for example when its `values` object is frozen
707
+ * or an accessor throws; such values are not reused, so a custom `parse` cannot make `resolveArgs` throw this way.
708
+ */
709
+ function reuseValidationError(error, rawArg, option, schema, value) {
710
+ try {
711
+ if (isArgsValidationError(error)) {
712
+ augmentValidationError(error, rawArg, option, schema, value);
713
+ return error;
714
+ }
715
+ } catch {}
716
+ }
667
717
  function augmentValidationError(error, rawArg, option, schema, value) {
668
718
  const values = error.values;
669
719
  values.name ??= rawArg;
@@ -1,9 +1,9 @@
1
1
  import "./context-CAPhwgJJ.js";
2
- import { n as kebabnize } from "./utils-oPJNnmOb.js";
2
+ import { n as kebabnize } from "./utils-DbRhwNIU.js";
3
3
  import { resolveLazyCommand } from "./utils.js";
4
- import { n as ArgsValidationErrorKeys, r as isArgsValidationError } from "./resolver-dsINFnU2.js";
5
- import { i as isCommandNotFoundError } from "./error-CBijJN5L.js";
6
- import { t as plugin } from "./plugin-Cvf6mYto.js";
4
+ import { n as ArgsValidationErrorKeys } from "./resolver-D5skgYcF.js";
5
+ import { a as isCommandNotFoundError, i as isArgsValidationError } from "./error-B5QxSzk9.js";
6
+ import { t as plugin } from "./plugin-DneW3Toi.js";
7
7
  /**
8
8
  * @author kazuya kawaguchi (a.k.a. kazupon)
9
9
  * @license MIT
@@ -1,4 +1,4 @@
1
- import { i as Args, n as ArgSchema, r as ArgValues, t as ArgExplicitlyProvided, u as ArgToken } from "./resolver-D7DEcpu-.js";
1
+ import { i as Args, l as ArgToken, n as ArgSchema, r as ArgValues, t as ArgExplicitlyProvided } from "./resolver-CbDvcwY3.js";
2
2
 
3
3
  //#region src/plugin/context.d.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- //#region ../../node_modules/.pnpm/args-tokens@0.28.2/node_modules/args-tokens/lib/utils.js
1
+ //#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/utils.js
2
2
  /**
3
3
  * Entry point of utils.
4
4
  *
package/lib/utils.d.ts CHANGED
@@ -1,6 +1,10 @@
1
- import { b as GunshiParamsConstraint, m as DefaultGunshiParams, p as Commandable, r as Command, x as LazyCommand } from "./types-CdM9C6VD.js";
1
+ import { b as GunshiParamsConstraint, m as DefaultGunshiParams, p as Commandable, r as Command, x as LazyCommand } from "./types-H9nag_2Z.js";
2
2
 
3
- //#region ../../node_modules/.pnpm/args-tokens@0.28.2/node_modules/args-tokens/lib/utils.d.ts
3
+ //#region ../../node_modules/.pnpm/args-tokens@0.29.0/node_modules/args-tokens/lib/utils.d.ts
4
+ /**
5
+ * @author kazuya kawaguchi (a.k.a. kazupon)
6
+ * @license MIT
7
+ */
4
8
 
5
9
  //#region src/utils.d.ts
6
10
  /**
@@ -21,12 +25,6 @@ import { b as GunshiParamsConstraint, m as DefaultGunshiParams, p as Commandable
21
25
  * @returns Converted string into kebab-case.
22
26
  */
23
27
  declare function kebabnize(str: string): string;
24
- /**
25
- * Format allowed argument choices for validation error values and fallback messages.
26
- *
27
- * @param choices - Choice values to format
28
- * @returns JSON-quoted choices joined with `, `.
29
- */
30
28
  //#endregion
31
29
  //#region src/utils.d.ts
32
30
  /**
package/lib/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as kebabnize } from "./utils-oPJNnmOb.js";
1
+ import { n as kebabnize } from "./utils-DbRhwNIU.js";
2
2
  //#region src/utils.ts
3
3
  /**
4
4
  * @author kazuya kawaguchi (a.k.a. kazupon)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gunshi",
3
3
  "description": "Modern javascript command-line library",
4
- "version": "0.37.2",
4
+ "version": "0.37.3",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -108,7 +108,8 @@
108
108
  }
109
109
  },
110
110
  "devDependencies": {
111
- "args-tokens": "^0.28.2",
111
+ "@types/node": "^25.6.2",
112
+ "args-tokens": "^0.29.0",
112
113
  "deno": "^2.7.14",
113
114
  "jsr": "^0.14.3",
114
115
  "jsr-exports-lint": "^0.4.2",
@@ -116,11 +117,11 @@
116
117
  "std-env": "^4.1.0",
117
118
  "tsdown": "0.21.0",
118
119
  "zod": "^4.4.3",
119
- "@gunshi/plugin-i18n": "0.37.2",
120
- "@gunshi/plugin-global": "0.37.2",
121
- "@gunshi/resources": "0.37.2",
122
- "@gunshi/plugin-renderer": "0.37.2",
123
- "@gunshi/shared": "0.37.2"
120
+ "@gunshi/plugin-global": "0.37.3",
121
+ "@gunshi/plugin-i18n": "0.37.3",
122
+ "@gunshi/resources": "0.37.3",
123
+ "@gunshi/shared": "0.37.3",
124
+ "@gunshi/plugin-renderer": "0.37.3"
124
125
  },
125
126
  "scripts": {
126
127
  "build": "tsdown",
@@ -1,65 +0,0 @@
1
- import { n as ArgsValidationErrorKeys, r as isArgsValidationError } from "./resolver-dsINFnU2.js";
2
- //#region ../../node_modules/.pnpm/args-tokens@0.28.2/node_modules/args-tokens/lib/index.js
3
- /**
4
- * @author kazuya kawaguchi (a.k.a. kazupon)
5
- * @license MIT
6
- */
7
- /**
8
- * @author kazuya kawaguchi (a.k.a. kazupon)
9
- * @license MIT
10
- */
11
- //#endregion
12
- //#region src/error.ts
13
- /**
14
- * @author kazuya kawaguchi (a.k.a. kazupon)
15
- * @license MIT
16
- */
17
- /**
18
- * Command not found error resource keys.
19
- */
20
- const CommandNotFoundErrorKeys = { notFound: "err:cmd:not-found" };
21
- /**
22
- * Error raised when a command cannot be resolved.
23
- */
24
- var CommandNotFoundError = class extends Error {
25
- code;
26
- values;
27
- commandName;
28
- candidates;
29
- commandPath;
30
- /**
31
- * Create a command-not-found error.
32
- *
33
- * @param message - Fallback error message
34
- * @param options - Command-not-found metadata
35
- */
36
- constructor(message, options) {
37
- super(message, { cause: options.cause });
38
- this.name = "CommandNotFoundError";
39
- this.code = options.code;
40
- this.values = options.values || {};
41
- this.commandName = options.commandName;
42
- this.candidates = options.candidates || [];
43
- this.commandPath = options.commandPath || [];
44
- }
45
- };
46
- /**
47
- * Check whether an error is a {@link CommandNotFoundError}.
48
- *
49
- * @param error - An unknown error
50
- * @returns `true` if the error is a {@link CommandNotFoundError}
51
- */
52
- function isCommandNotFoundError(error) {
53
- return error instanceof CommandNotFoundError;
54
- }
55
- /**
56
- * Check whether validation errors should be handled before version, help, or command execution.
57
- *
58
- * @param error - An aggregate validation error
59
- * @returns `true` if the validation error must be handled with priority
60
- */
61
- function hasPriorityValidationError(error) {
62
- return error?.errors.some((error) => isCommandNotFoundError(error) || isArgsValidationError(error) && error.code === ArgsValidationErrorKeys.unknownOption) ?? false;
63
- }
64
- //#endregion
65
- export { isCommandNotFoundError as i, CommandNotFoundErrorKeys as n, hasPriorityValidationError as r, CommandNotFoundError as t };