gunshi 0.19.0 → 0.20.0

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/README.md CHANGED
@@ -99,6 +99,7 @@ About more details and usage, see [documentations](https://gunshi.dev)
99
99
  ## 💁‍♀️ Showcases
100
100
 
101
101
  - [pnpmc](https://github.com/kazupon/pnpmc): PNPM Catalogs Tooling
102
+ - [sourcemap-publisher](https://github.com/es-tooling/sourcemap-publisher): A tool to publish sourcemaps externally and rewrite sourcemap URLs at pre-publish time
102
103
 
103
104
  ## 🙌 Contributing guidelines
104
105
 
@@ -1,6 +1,6 @@
1
- import { COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, create, resolveLazyCommand } from "./utils-DWRmOGGa.js";
2
- import { createCommandContext } from "./context-CBDAvGDh.js";
3
- import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-BDs5T_Z4.js";
1
+ import { COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, create, resolveLazyCommand } from "./utils-STQBqMtf.js";
2
+ import { createCommandContext } from "./context-IwpAqLSL.js";
3
+ import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-BpwhGYRZ.js";
4
4
  import { parseArgs, resolveArgs } from "args-tokens";
5
5
 
6
6
  //#region src/cli.ts
@@ -1,4 +1,4 @@
1
- import { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, DEFAULT_LOCALE$1 as DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, resolveArgKey, resolveLazyCommand } from "./utils-DWRmOGGa.js";
1
+ import { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, DEFAULT_LOCALE$1 as DEFAULT_LOCALE, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, resolveArgKey, resolveExamples, resolveLazyCommand } from "./utils-STQBqMtf.js";
2
2
 
3
3
  //#region src/locales/en-US.json
4
4
  var COMMAND = "COMMAND";
@@ -152,14 +152,11 @@ async function createCommandContext({ args, values, positionals, rest, argv, tok
152
152
  return res;
153
153
  }, create());
154
154
  defaultCommandResource.description = command.description || "";
155
- defaultCommandResource.examples = command.examples || "";
155
+ defaultCommandResource.examples = await resolveExamples(ctx, command.examples);
156
156
  adapter.setResource(DEFAULT_LOCALE, defaultCommandResource);
157
157
  const originalResource = await loadCommandResource(ctx, command);
158
158
  if (originalResource) {
159
- const resource = Object.assign(create(), {
160
- description: originalResource.description,
161
- examples: originalResource.examples
162
- }, originalResource);
159
+ const resource = Object.assign(create(), originalResource, { examples: await resolveExamples(ctx, originalResource.examples) });
163
160
  if (builtInLoadedResources) {
164
161
  resource.help = builtInLoadedResources.help;
165
162
  resource.version = builtInLoadedResources.version;
package/lib/context.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Command, CommandContext, CommandOptions } from "./types-BVZKXMbJ.js";
1
+ import { Command, CommandContext, CommandOptions } from "./types-iztBdPY6.js";
2
2
  import { ArgToken, ArgValues, Args } from "args-tokens";
3
3
 
4
4
  //#region src/context.d.ts
package/lib/context.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./utils-DWRmOGGa.js";
2
- import { createCommandContext } from "./context-CBDAvGDh.js";
1
+ import "./utils-STQBqMtf.js";
2
+ import { createCommandContext } from "./context-IwpAqLSL.js";
3
3
 
4
4
  export { createCommandContext };
@@ -1,4 +1,4 @@
1
- import { Command, CommandLoader, LazyCommand } from "./types-BVZKXMbJ.js";
1
+ import { Command, CommandLoader, LazyCommand } from "./types-iztBdPY6.js";
2
2
  import { ArgSchema, ArgValues as ArgValues$1, Args, Args as Args$1 } from "args-tokens";
3
3
 
4
4
  //#region src/definition.d.ts
@@ -1,3 +1,3 @@
1
- import "./types-BVZKXMbJ.js";
2
- import { ArgSchema, ArgValues, Args, define$1 as define, lazy$1 as lazy } from "./definition-Bdw7cMea.js";
1
+ import "./types-iztBdPY6.js";
2
+ import { ArgSchema, ArgValues, Args, define$1 as define, lazy$1 as lazy } from "./definition-BrCD_SuG.js";
3
3
  export { ArgSchema, ArgValues, Args, define, lazy };
@@ -1,4 +1,4 @@
1
- import { Command, CommandOptions } from "./types-BVZKXMbJ.js";
1
+ import { Command, CommandOptions } from "./types-iztBdPY6.js";
2
2
  import { Args } from "args-tokens";
3
3
 
4
4
  //#region src/generator.d.ts
package/lib/generator.js CHANGED
@@ -1,7 +1,7 @@
1
- import { create } from "./utils-DWRmOGGa.js";
2
- import "./context-CBDAvGDh.js";
3
- import "./renderer-BDs5T_Z4.js";
4
- import { cli } from "./cli-m93bHwFR.js";
1
+ import { create } from "./utils-STQBqMtf.js";
2
+ import "./context-IwpAqLSL.js";
3
+ import "./renderer-BpwhGYRZ.js";
4
+ import { cli } from "./cli-rwwoCHjK.js";
5
5
 
6
6
  //#region src/generator.ts
7
7
  /**
package/lib/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandLoader, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions } from "./types-BVZKXMbJ.js";
2
- import { define$1 as define, lazy$1 as lazy } from "./definition-Bdw7cMea.js";
1
+ import { Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions } from "./types-iztBdPY6.js";
2
+ import { define$1 as define, lazy$1 as lazy } from "./definition-BrCD_SuG.js";
3
3
  import { ArgSchema, ArgValues, Args, Args as Args$1, parseArgs, resolveArgs } from "args-tokens";
4
4
 
5
5
  //#region src/cli.d.ts
@@ -32,4 +32,4 @@ declare class DefaultTranslation implements TranslationAdapter {
32
32
  }
33
33
 
34
34
  //#endregion
35
- export { ArgSchema, ArgValues, Args, Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandLoader, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, DefaultTranslation, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions, cli, define, lazy, parseArgs, resolveArgs };
35
+ export { ArgSchema, ArgValues, Args, Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, DefaultTranslation, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions, cli, define, lazy, parseArgs, resolveArgs };
package/lib/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { DEFAULT_LOCALE$1 as DEFAULT_LOCALE } from "./utils-DWRmOGGa.js";
2
- import { DefaultTranslation } from "./context-CBDAvGDh.js";
1
+ import { DEFAULT_LOCALE$1 as DEFAULT_LOCALE } from "./utils-STQBqMtf.js";
2
+ import { DefaultTranslation } from "./context-IwpAqLSL.js";
3
3
  import { define, lazy } from "./definition-DyVBFqB7.js";
4
- import "./renderer-BDs5T_Z4.js";
5
- import { cli } from "./cli-m93bHwFR.js";
4
+ import "./renderer-BpwhGYRZ.js";
5
+ import { cli } from "./cli-rwwoCHjK.js";
6
6
  import { parseArgs, resolveArgs } from "args-tokens";
7
7
 
8
8
  export { DEFAULT_LOCALE, DefaultTranslation, cli, define, lazy, parseArgs, resolveArgs };
@@ -1,4 +1,4 @@
1
- import { COMMON_ARGS, create, resolveArgKey, resolveBuiltInKey } from "./utils-DWRmOGGa.js";
1
+ import { COMMON_ARGS, create, resolveArgKey, resolveBuiltInKey, resolveExamples } from "./utils-STQBqMtf.js";
2
2
 
3
3
  //#region src/renderer/header.ts
4
4
  /**
@@ -29,7 +29,7 @@ async function renderUsage(ctx) {
29
29
  if (ctx.omitted && await hasCommands(ctx)) messages.push(...await renderCommandsSection(ctx), "");
30
30
  if (hasPositionalArgs(ctx)) messages.push(...await renderPositionalArgsSection(ctx), "");
31
31
  if (hasOptionalArgs(ctx)) messages.push(...await renderOptionalArgsSection(ctx), "");
32
- const examples = renderExamplesSection(ctx);
32
+ const examples = await renderExamplesSection(ctx);
33
33
  if (examples.length > 0) messages.push(...examples, "");
34
34
  return messages.join("\n");
35
35
  }
@@ -60,9 +60,9 @@ async function renderOptionalArgsSection(ctx) {
60
60
  * @param ctx A {@link CommandContext | command context}
61
61
  * @returns A rendered examples section
62
62
  */
63
- function renderExamplesSection(ctx) {
63
+ async function renderExamplesSection(ctx) {
64
64
  const messages = [];
65
- const resolvedExamples = resolveExamples(ctx);
65
+ const resolvedExamples = await resolveExamples$1(ctx);
66
66
  if (resolvedExamples) {
67
67
  const examples = resolvedExamples.split("\n").map((example) => example.padStart(ctx.env.leftMargin + example.length));
68
68
  messages.push(`${ctx.translate(resolveBuiltInKey("EXAMPLES"))}:`, ...examples);
@@ -140,11 +140,11 @@ function resolveDescription(ctx) {
140
140
  * @param ctx A {@link CommandContext | command context}
141
141
  * @returns resolved command examples, if not resolved, return empty string
142
142
  */
143
- function resolveExamples(ctx) {
143
+ async function resolveExamples$1(ctx) {
144
144
  const ret = ctx.translate("examples");
145
145
  if (ret) return ret;
146
146
  const command = ctx.env.subCommands?.get(ctx.name || "");
147
- return command?.examples ?? "";
147
+ return await resolveExamples(ctx, command?.examples);
148
148
  }
149
149
  /**
150
150
  * Check if the command has sub commands
package/lib/renderer.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { CommandContext } from "./types-BVZKXMbJ.js";
1
+ import { CommandContext } from "./types-iztBdPY6.js";
2
2
  import { Args } from "args-tokens";
3
3
 
4
4
  //#region src/renderer/header.d.ts
package/lib/renderer.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./utils-DWRmOGGa.js";
2
- import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-BDs5T_Z4.js";
1
+ import "./utils-STQBqMtf.js";
2
+ import { renderHeader, renderUsage, renderValidationErrors } from "./renderer-BpwhGYRZ.js";
3
3
 
4
4
  export { renderHeader, renderUsage, renderValidationErrors };
@@ -34,29 +34,36 @@ type Awaitable<T> = T | Promise<T>;
34
34
  type RemoveIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K] };
35
35
  /**
36
36
  * Remove index signature from object or record type.
37
+ * @internal
37
38
  */
38
39
  type RemovedIndex<T> = RemoveIndexSignature<{ [K in keyof T]: T[K] }>;
40
+ /** @internal */
39
41
  type KeyOfArgs<A extends Args> = keyof A | { [K in keyof A]: A[K]['type'] extends 'boolean' ? A[K]['negatable'] extends true ? `no-${Extract<K, string>}` : never : never }[keyof A];
40
42
  /**
41
43
  * Generate a namespaced key.
44
+ * @internal
42
45
  */
43
46
  type GenerateNamespacedKey<Key extends string, Prefixed extends string = typeof BUILT_IN_PREFIX> = `${Prefixed}${typeof BUILT_IN_KEY_SEPARATOR}${Key}`;
44
47
  /**
45
48
  * Command i18n built-in arguments keys.
49
+ * @internal
46
50
  */
47
51
  type CommandBuiltinArgsKeys = keyof (typeof constants_d_exports)['COMMON_ARGS'];
48
52
  /**
49
53
  * Command i18n built-in resource keys.
54
+ * @internal
50
55
  */
51
56
  type CommandBuiltinResourceKeys = (typeof constants_d_exports)['COMMAND_BUILTIN_RESOURCE_KEYS'][number];
52
57
  /**
53
58
  * Command i18n built-in keys.
54
59
  * The command i18n built-in keys are used to {@link CommandContext.translate | translate} function.
60
+ * @internal
55
61
  */
56
62
  type CommandBuiltinKeys = GenerateNamespacedKey<CommandBuiltinArgsKeys> | GenerateNamespacedKey<CommandBuiltinResourceKeys> | 'description' | 'examples';
57
63
  /**
58
64
  * Command i18n option keys.
59
65
  * The command i18n option keys are used to {@link CommandContext.translate | translate} function.
66
+ * @internal
60
67
  */
61
68
  type CommandArgKeys<A extends Args> = GenerateNamespacedKey<KeyOfArgs<RemovedIndex<A>>, typeof ARG_PREFIX>;
62
69
  /**
@@ -298,7 +305,7 @@ interface Command<A extends Args = Args> {
298
305
  * Command examples.
299
306
  * examples of how to use the command.
300
307
  */
301
- examples?: string;
308
+ examples?: string | CommandExamplesFetcher<A>;
302
309
  /**
303
310
  * Command runner. it's the command to be executed
304
311
  */
@@ -319,10 +326,16 @@ type CommandResource<A extends Args = Args> = {
319
326
  /**
320
327
  * Examples usage.
321
328
  */
322
- examples: string;
329
+ examples: string | CommandExamplesFetcher<A>;
323
330
  } & { [Arg in GenerateNamespacedKey<KeyOfArgs<RemovedIndex<A>>, typeof ARG_PREFIX>]: string } & {
324
331
  [key: string]: string;
325
332
  };
333
+ /**
334
+ * Command examples fetcher.
335
+ * @param ctx A {@link CommandContext | command context}
336
+ * @returns A fetched command examples.
337
+ */
338
+ type CommandExamplesFetcher<A extends Args = Args, V = ArgValues<A>> = (ctx: Readonly<CommandContext<A, V>>) => Promise<string>;
326
339
  /**
327
340
  * Command resource fetcher.
328
341
  * @param ctx A {@link CommandContext | command context}
@@ -404,4 +417,4 @@ type LazyCommand<A extends Args = Args> = {
404
417
  * Define a command type.
405
418
  */
406
419
  type Commandable<A extends Args> = Command<A> | LazyCommand<A>; //#endregion
407
- export { Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandLoader, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions };
420
+ export { Command, CommandArgKeys, CommandBuiltinArgsKeys, CommandBuiltinKeys, CommandBuiltinResourceKeys, CommandContext, CommandEnvironment, CommandExamplesFetcher, CommandLoader, CommandOptions, CommandResource, CommandResourceFetcher, CommandRunner, Commandable, DEFAULT_LOCALE, GenerateNamespacedKey, KeyOfArgs, LazyCommand, RemovedIndex, TranslationAdapter, TranslationAdapterFactory, TranslationAdapterFactoryOptions };
@@ -71,6 +71,9 @@ function resolveBuiltInKey(key) {
71
71
  function resolveArgKey(key) {
72
72
  return `${ARG_PREFIX}${BUILT_IN_KEY_SEPARATOR}${key}`;
73
73
  }
74
+ async function resolveExamples(ctx, examples) {
75
+ return typeof examples === "string" ? examples : typeof examples === "function" ? await examples(ctx) : "";
76
+ }
74
77
  function mapResourceWithBuiltinKey(resource) {
75
78
  return Object.entries(resource).reduce((acc, [key, value]) => {
76
79
  acc[resolveBuiltInKey(key)] = value;
@@ -93,4 +96,4 @@ function deepFreeze(obj) {
93
96
  }
94
97
 
95
98
  //#endregion
96
- export { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, DEFAULT_LOCALE as DEFAULT_LOCALE$1, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, resolveArgKey, resolveBuiltInKey, resolveLazyCommand };
99
+ export { BUILT_IN_PREFIX, COMMAND_OPTIONS_DEFAULT, COMMON_ARGS, DEFAULT_LOCALE as DEFAULT_LOCALE$1, NOOP, create, deepFreeze, log, mapResourceWithBuiltinKey, resolveArgKey, resolveBuiltInKey, resolveExamples, resolveLazyCommand };
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.19.0",
4
+ "version": "0.20.0",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
7
7
  "email": "kawakazu80@gmail.com"
@@ -103,11 +103,13 @@
103
103
  "eslint-plugin-vue-composable": "^1.0.0",
104
104
  "eslint-plugin-yml": "^1.18.0",
105
105
  "gh-changelogen": "^0.2.8",
106
+ "gunshi019": "npm:gunshi@0.19.0",
106
107
  "jsr": "^0.13.4",
107
108
  "jsr-exports-lint": "^0.2.0",
108
109
  "knip": "^5.53.0",
109
110
  "lint-staged": "^15.5.1",
110
111
  "messageformat": "4.0.0-10",
112
+ "mitata": "^1.0.34",
111
113
  "pkg-pr-new": "^0.0.43",
112
114
  "prettier": "^3.5.3",
113
115
  "publint": "^0.3.12",
@@ -138,6 +140,8 @@
138
140
  ]
139
141
  },
140
142
  "scripts": {
143
+ "bench:mitata": "node --expose-gc bench/mitata.js",
144
+ "bench:vitest": "vitest bench --run",
141
145
  "build": "tsdown",
142
146
  "changelog": "gh-changelogen --repo=kazupon/gunshi",
143
147
  "clean": "git clean -df",
@@ -145,7 +149,7 @@
145
149
  "dev:eslint": "pnpx @eslint/config-inspector --config eslint.config.ts",
146
150
  "dev:typedoc": "typedoc --watch --preserveWatchOutput",
147
151
  "docs:build": "pnpm run docs:build:typedoc && pnpm docs:build:vitepress",
148
- "docs:build:typedoc": "typedoc",
152
+ "docs:build:typedoc": "typedoc --excludeInternal",
149
153
  "docs:build:vitepress": "vitepress build docs",
150
154
  "docs:dev": "pnpm run docs:build:typedoc && pnpm docs:dev:vitepress",
151
155
  "docs:dev:vitepress": "vitepress dev docs",