optionkit 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +133 -2
- package/dist/_generated/catalog.d.ts +6 -0
- package/dist/_generated/catalog.d.ts.map +1 -0
- package/dist/_generated/catalog.js +7 -0
- package/dist/_generated/catalog.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/optionkit.d.ts +122 -0
- package/dist/optionkit.d.ts.map +1 -0
- package/dist/optionkit.js +501 -0
- package/dist/optionkit.js.map +1 -0
- package/dist/resolve.d.ts +5 -0
- package/dist/resolve.d.ts.map +1 -0
- package/dist/resolve.js +61 -0
- package/dist/resolve.js.map +1 -0
- package/package.json +87 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 optionkit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,134 @@
|
|
|
1
|
-
#
|
|
1
|
+
# optionkit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`optionkit` turns a Zod configuration schema into CLI options. It adds
|
|
4
|
+
environment-variable bindings, adds unambiguous short flags, and lazily loads
|
|
5
|
+
the CLI stack without making Fireargs, Commander, or Zod runtime dependencies
|
|
6
|
+
of this package.
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { createOptionKit } from 'optionkit';
|
|
10
|
+
|
|
11
|
+
const { f, z } = await createOptionKit({ moduleUrl: import.meta.url });
|
|
12
|
+
|
|
13
|
+
const appOptionsSchema = z.object({
|
|
14
|
+
port: z.number().default(3000).describe('Port to listen on.'),
|
|
15
|
+
debug: z.boolean().default(false).describe('Write diagnostics to stderr.'),
|
|
16
|
+
logLevel: z.enum(['info', 'warn', 'error']).default('info')
|
|
17
|
+
.describe('Minimum log level.'),
|
|
18
|
+
}).readonly();
|
|
19
|
+
|
|
20
|
+
const serve = f.command({ name: 'serve', description: 'Start the server.' })
|
|
21
|
+
.input(appOptionsSchema)
|
|
22
|
+
.output(z.void())
|
|
23
|
+
.handler(async config => {
|
|
24
|
+
await startServer(config);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
await serve.parseAsync(process.argv);
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
If the consuming package is named `my-app`, the fields above receive
|
|
31
|
+
`MY_APP_PORT`, `MY_APP_DEBUG`, and `MY_APP_LOG_LEVEL`. `port`, `debug`, and
|
|
32
|
+
`logLevel` also receive `-p`, `-d`, and `-l` because their initials do not
|
|
33
|
+
conflict. When two options share an initial, neither gets that automatic short
|
|
34
|
+
flag.
|
|
35
|
+
|
|
36
|
+
Adaptation happens at each command's `.input(...)` boundary. Subcommands need no
|
|
37
|
+
special handling: build each leaf from its own schema, then mount the leaves with
|
|
38
|
+
`f.program(...).router({ serve, status })`. Environment and short-flag conflicts
|
|
39
|
+
are calculated independently for each leaf.
|
|
40
|
+
|
|
41
|
+
## Lazy CLI dependencies
|
|
42
|
+
|
|
43
|
+
optionkit first resolves Fireargs and Zod from the consuming CLI package. If
|
|
44
|
+
they are unavailable, it detects the package manager from the invocation
|
|
45
|
+
directory and installs the pinned Fireargs and Zod ranges from the consuming
|
|
46
|
+
package root. `cacheDirectory` opts into an isolated install explicitly; there
|
|
47
|
+
is no default versioned cache. Fireargs' package metadata supplies its remaining
|
|
48
|
+
peer dependencies. Optionkit restores the consuming manifest and lockfile
|
|
49
|
+
byte-for-byte after installation, and installer output stays silent so JSON
|
|
50
|
+
output is not polluted.
|
|
51
|
+
|
|
52
|
+
Only `@antfu/install-pkg` is a runtime dependency of optionkit. Fireargs,
|
|
53
|
+
Zod, and `clean-stack` are development dependencies whose ranges are generated
|
|
54
|
+
into the build from the catalog in `pnpm-workspace.yaml`. A matching root
|
|
55
|
+
catalog keeps Bun compatible, and verification fails if the two catalogs
|
|
56
|
+
diverge. `src/_generated/catalog.ts` is a one-to-one runtime mirror of the root
|
|
57
|
+
catalog. The stack cleaner is installed separately and best-effort: a failure
|
|
58
|
+
never prevents the CLI from starting, and `formatError` falls back to the
|
|
59
|
+
original stack. Fireargs and Zod are also declared as optional peers, so a
|
|
60
|
+
consumer's compatible installation is reused without making either package a
|
|
61
|
+
required install.
|
|
62
|
+
|
|
63
|
+
Use the returned `z` when the consuming package does not otherwise depend on
|
|
64
|
+
Zod. It always comes from the same dependency location as the CLI adapter:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
const { f, z } = await createOptionKit({ moduleUrl: import.meta.url });
|
|
68
|
+
const input = z.object({ verbose: z.boolean().default(false) });
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Use `environmentPrefix` or `projectName` to override automatic package-name
|
|
72
|
+
translation. Per-field `env` and `short` values can be overridden or disabled:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
await createOptionKit({
|
|
76
|
+
environmentPrefix: 'SERVICE',
|
|
77
|
+
fields: {
|
|
78
|
+
debug: { env: false, short: 'x' },
|
|
79
|
+
},
|
|
80
|
+
moduleUrl: import.meta.url,
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Array, tuple, object, and record options with generated environment bindings try
|
|
85
|
+
JSON first because an environment variable supplies only one string. For example,
|
|
86
|
+
`APP_TAGS='["one","two"]'` and `APP_ENV='{"PORT":"3000"}'` become their
|
|
87
|
+
corresponding Zod input values. Arrays also accept comma- or whitespace-delimited
|
|
88
|
+
shell words, including quotes and backslash escapes. If decoding does not apply,
|
|
89
|
+
the original string reaches Zod as the final authority. Fireargs continues to
|
|
90
|
+
handle scalar coercion. The same structured syntax works when passed as a flag.
|
|
91
|
+
A consumer-supplied Fireargs `parse` function is forwarded unchanged and takes
|
|
92
|
+
precedence over this augmentation. Every other per-option Fireargs configuration
|
|
93
|
+
field is forwarded as well; command and program configuration remains available
|
|
94
|
+
through the returned `f` namespace.
|
|
95
|
+
|
|
96
|
+
Fireargs programs currently show help when invoked without a subcommand. Optionkit
|
|
97
|
+
does not override that dispatch: Commander only exposes a clean default-command
|
|
98
|
+
switch while adding a command, whereas Fireargs owns that mounting step. A shim
|
|
99
|
+
would either depend on Commander internals or duplicate Fireargs routing.
|
|
100
|
+
|
|
101
|
+
`resolvePackage` and `importPackageIfAvailable` expose the same resolve-first
|
|
102
|
+
behavior for other optional integrations. They only suppress a genuinely
|
|
103
|
+
missing package; initialization errors from an installed package still surface.
|
|
104
|
+
|
|
105
|
+
## Pyfig migration
|
|
106
|
+
|
|
107
|
+
Pyfig can keep `pyfigOptionsSchema` as its API source of truth. Its CLI only
|
|
108
|
+
needs to replace the manual loader; Optionkit adapts every command input:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
const { f, z } = await createOptionKit({
|
|
112
|
+
log,
|
|
113
|
+
moduleUrl: import.meta.url,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const createInput = (passthrough = false) => pyfigOptionsSchema.unwrap().extend({
|
|
117
|
+
...(passthrough ? { args: f.argument().schema(passthroughArguments) } : {}),
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The command, router, output schemas, handlers, and passthrough behavior do not
|
|
122
|
+
change. `PYFIG_*` names and conflict-free short flags are derived automatically.
|
|
123
|
+
Pyfig needs only `optionkit` for its CLI integration; it does not need its own
|
|
124
|
+
Fireargs peer metadata, Fireargs development dependency, or install helper.
|
|
125
|
+
|
|
126
|
+
## Install
|
|
127
|
+
|
|
128
|
+
```sh
|
|
129
|
+
bun add optionkit
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/_generated/catalog.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO;aAClB,aAAa,EAAE,QAAQ;aACvB,QAAU,EAAE,QAAQ;aACpB,GAAK,EAAE,QAAQ;CACP,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/_generated/catalog.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,aAAa,EAAE,QAAQ;IACvB,UAAU,EAAE,QAAQ;IACpB,KAAK,EAAE,QAAQ;CACP,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { createOptionKit, type ArgumentConfiguration, type CliCommand, type CliParseOptions, type CliProgram, type CliRoute, type CommandConfiguration, type CreateOptionKitSettings, type FieldBuilder, type OptionConfiguration, type OptionKit, type OptionKitAdapter, type OptionKitLogger, type ProgramConfiguration, } from './optionkit.js';
|
|
2
|
+
export { importPackageIfAvailable, resolvePackage } from './resolve.js';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,oBAAoB,GAC1B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,GAchB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { ZodArray, ZodBoolean, ZodNumber, ZodObject, ZodReadonly, ZodString, ZodType } from 'zod';
|
|
2
|
+
type ZodNamespace = typeof import('zod').z;
|
|
3
|
+
type ZodShape = Record<string, ZodType>;
|
|
4
|
+
type ObjectSchema = ZodObject<ZodShape> | ZodReadonly<ZodObject<ZodShape>>;
|
|
5
|
+
type SchemaInput<Schema extends ZodType> = import('zod').input<Schema>;
|
|
6
|
+
type SchemaOutput<Schema extends ZodType> = import('zod').output<Schema>;
|
|
7
|
+
export interface OptionConfiguration<Value = unknown> {
|
|
8
|
+
/** Long flag without dashes. Defaults to the kebab-case field key. */
|
|
9
|
+
name?: string;
|
|
10
|
+
/** Override the generated environment variable, or disable it for this field. */
|
|
11
|
+
env?: string | false;
|
|
12
|
+
/** Override the generated short flag, or disable it for this field. */
|
|
13
|
+
short?: string | false;
|
|
14
|
+
conflicts?: string | string[];
|
|
15
|
+
implies?: Record<string, unknown>;
|
|
16
|
+
hidden?: boolean;
|
|
17
|
+
preset?: unknown;
|
|
18
|
+
helpGroup?: string;
|
|
19
|
+
defaultDescription?: string;
|
|
20
|
+
/** Fireargs parser for one CLI or environment string; disables automatic decoding. */
|
|
21
|
+
parse?: (value: string) => Value;
|
|
22
|
+
}
|
|
23
|
+
export interface ArgumentConfiguration<Value = unknown> {
|
|
24
|
+
name?: string;
|
|
25
|
+
defaultDescription?: string;
|
|
26
|
+
parse?: (value: string) => Value;
|
|
27
|
+
}
|
|
28
|
+
export type CommandConfiguration = Record<string, unknown>;
|
|
29
|
+
export type ProgramConfiguration = Record<string, unknown>;
|
|
30
|
+
export interface CliParseOptions {
|
|
31
|
+
from?: 'electron' | 'node' | 'user';
|
|
32
|
+
}
|
|
33
|
+
export interface CliRoute {
|
|
34
|
+
readonly type: 'command' | 'program';
|
|
35
|
+
helpInformation(): string;
|
|
36
|
+
parseAsync(argv?: readonly string[], options?: CliParseOptions): Promise<unknown>;
|
|
37
|
+
}
|
|
38
|
+
export interface CliCommand extends CliRoute {
|
|
39
|
+
readonly type: 'command';
|
|
40
|
+
}
|
|
41
|
+
export interface CliProgram extends CliRoute {
|
|
42
|
+
readonly type: 'program';
|
|
43
|
+
}
|
|
44
|
+
export interface CommandContext {
|
|
45
|
+
readonly command: CliCommand;
|
|
46
|
+
readonly json: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface RenderContext<Input> {
|
|
49
|
+
readonly command: CliCommand;
|
|
50
|
+
readonly input: Input;
|
|
51
|
+
readonly json: false;
|
|
52
|
+
}
|
|
53
|
+
export interface FieldBuilder<Value = never> {
|
|
54
|
+
string(): ZodString;
|
|
55
|
+
number(): ZodNumber;
|
|
56
|
+
boolean(): ZodBoolean;
|
|
57
|
+
enum<const Values extends readonly [string, ...string[]]>(values: Values): ZodType<Values[number]>;
|
|
58
|
+
array<Inner extends ZodType>(inner: Inner): ZodArray<Inner>;
|
|
59
|
+
schema<Schema extends ZodType>(schema: Schema): Schema;
|
|
60
|
+
}
|
|
61
|
+
interface HandlerBuilder<Input extends ObjectSchema, Output extends ZodType> {
|
|
62
|
+
handler(handler: (input: SchemaOutput<Input>, context: CommandContext) => SchemaInput<Output> | Promise<SchemaInput<Output>>): CliCommand;
|
|
63
|
+
}
|
|
64
|
+
interface OutputBuilder<Input extends ObjectSchema, Output extends ZodType> extends HandlerBuilder<Input, Output> {
|
|
65
|
+
render(render: (output: SchemaOutput<Output>, context: RenderContext<SchemaOutput<Input>>) => string | void | Promise<string | void>): HandlerBuilder<Input, Output>;
|
|
66
|
+
}
|
|
67
|
+
export interface OptionKitAdapter {
|
|
68
|
+
argument<Value = never>(configuration?: ArgumentConfiguration<Value>): FieldBuilder<Value>;
|
|
69
|
+
command(configuration?: CommandConfiguration): {
|
|
70
|
+
input<Input extends ObjectSchema>(schema: Input): {
|
|
71
|
+
output<Output extends ZodType>(schema: Output): OutputBuilder<Input, Output>;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
option<Value = never>(configuration?: OptionConfiguration<Value>): FieldBuilder<Value>;
|
|
75
|
+
program(configuration?: ProgramConfiguration): {
|
|
76
|
+
router(routes: Readonly<Record<string, CliRoute>>): CliProgram;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export type OptionKitLogger = (message: string, details?: Readonly<Record<string, unknown>>) => void;
|
|
80
|
+
export interface CreateOptionKitSettings {
|
|
81
|
+
/** Module URL for the consuming CLI; used to find its nearest package.json. */
|
|
82
|
+
moduleUrl?: string | URL;
|
|
83
|
+
/** Explicit consuming package root when moduleUrl discovery is not appropriate. */
|
|
84
|
+
packageRoot?: string;
|
|
85
|
+
/** Override the consuming package name used to derive the environment prefix. */
|
|
86
|
+
projectName?: string;
|
|
87
|
+
/** Override the generated prefix, or disable environment bindings. */
|
|
88
|
+
environmentPrefix?: string | false;
|
|
89
|
+
/** Generate non-conflicting single-letter flags. Defaults to true. */
|
|
90
|
+
shortFlags?: boolean;
|
|
91
|
+
/** Letters that automatic short-flag generation must not use. */
|
|
92
|
+
reservedShortFlags?: readonly string[];
|
|
93
|
+
/** Per-field CLI metadata applied after generated values. */
|
|
94
|
+
fields?: Readonly<Record<string, OptionConfiguration>>;
|
|
95
|
+
/** Working directory used to detect the caller's package manager. */
|
|
96
|
+
invocationDirectory?: string;
|
|
97
|
+
/** Explicit isolated install directory. By default, missing packages install at packageRoot. */
|
|
98
|
+
cacheDirectory?: string;
|
|
99
|
+
/** Optional diagnostics sink. optionkit never writes install progress itself. */
|
|
100
|
+
log?: OptionKitLogger;
|
|
101
|
+
}
|
|
102
|
+
export interface OptionKit {
|
|
103
|
+
/** CLI builder namespace, loaded from the project or the lazy cache. */
|
|
104
|
+
f: OptionKitAdapter;
|
|
105
|
+
/** Zod from the same dependency location as the CLI adapter. */
|
|
106
|
+
z: ZodNamespace;
|
|
107
|
+
/** Prefix used for generated environment variables, including its trailing underscore. */
|
|
108
|
+
environmentPrefix: string | false;
|
|
109
|
+
/** The consuming package root discovered for this CLI. */
|
|
110
|
+
packageRoot: string;
|
|
111
|
+
/** Where the CLI dependencies were resolved or installed. */
|
|
112
|
+
dependencySource: 'cache' | 'package-root' | 'project';
|
|
113
|
+
/** Render an error with clean-stack when the optional dependency is available. */
|
|
114
|
+
formatError: (error: unknown) => string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Load the CLI adapter on demand. Every command input is transparently augmented
|
|
118
|
+
* with environment bindings and conflict-free short flags.
|
|
119
|
+
*/
|
|
120
|
+
export declare function createOptionKit(settings?: CreateOptionKitSettings): Promise<Opt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C7B,gGAAgG;IAChG,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iFAAiF;IACjF,GAAG,CAAC,EAAE,eAAe,CAAC;CACvB;AAED,MAAM,WAAW,SAAS;IACxB,wEAAwE;IACxE,CAAC,EAAE,gBAAgB,CAAC;IACpB,gEAAgE;IAChE,CAAC,EAAE,YAAY,CAAC;IAChB,0FAA0F;IAC1F,iBAAiB,EAAE,MAAM,GAAG,KAAK,CAAC;IAClC,0DAA0D;IAC1D,WAAW,EAAE,MAAM,CAAC;IACpB,6DAA6D;IAC7D,gBAAgB,EAAE,OAAO,GAAG,cAAc,GAAG,SAAS,CAAC;IACvD,kFAAkF;IAClF,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC;CACzC;AAUD;;;GAGG;AACH,wBAAsB,eAAe,CACnC,QAAQ,GAAE,uBAA4B,GACrC,OAAO,CAAC,SAAS,CAAC,CAgBpB"}
|
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import { access, mkdir, readFile, realpath, rm, stat, writeFile } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { detectPackageManager, installPackage } from '@antfu/install-pkg';
|
|
6
|
+
import { catalog } from './_generated/catalog.js';
|
|
7
|
+
import { importPackageIfAvailable, resolvePackage } from './resolve.js';
|
|
8
|
+
const REQUIRED_CLI_DEPENDENCY_SPECIFIERS = [
|
|
9
|
+
`fireargs@${catalog.fireargs}`,
|
|
10
|
+
`zod@${catalog.zod}`,
|
|
11
|
+
];
|
|
12
|
+
const CLEAN_STACK_SPECIFIER = `clean-stack@${catalog['clean-stack']}`;
|
|
13
|
+
const installPromises = new Map();
|
|
14
|
+
const cleanStackPromises = new Map();
|
|
15
|
+
/**
|
|
16
|
+
* Load the CLI adapter on demand. Every command input is transparently augmented
|
|
17
|
+
* with environment bindings and conflict-free short flags.
|
|
18
|
+
*/
|
|
19
|
+
export async function createOptionKit(settings = {}) {
|
|
20
|
+
const packageInfo = await consumingPackage(settings);
|
|
21
|
+
const loaded = await loadDependencies(packageInfo.root, settings);
|
|
22
|
+
const environmentPrefix = resolveEnvironmentPrefix(settings.environmentPrefix, settings.projectName ?? packageInfo.name);
|
|
23
|
+
return {
|
|
24
|
+
f: createAdapter(loaded.f, loaded.z, environmentPrefix, settings),
|
|
25
|
+
z: loaded.z,
|
|
26
|
+
environmentPrefix,
|
|
27
|
+
packageRoot: packageInfo.root,
|
|
28
|
+
dependencySource: loaded.source,
|
|
29
|
+
formatError: error => formatError(error, loaded.cleanStack),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
async function consumingPackage(settings) {
|
|
33
|
+
const root = settings.packageRoot
|
|
34
|
+
? path.resolve(settings.packageRoot)
|
|
35
|
+
: await findPackageRoot(await discoveryStart(settings.moduleUrl));
|
|
36
|
+
const manifest = JSON.parse(await readFile(path.join(root, 'package.json'), 'utf8'));
|
|
37
|
+
const name = settings.projectName ?? manifest.name;
|
|
38
|
+
if (typeof name !== 'string' || name.trim() === '') {
|
|
39
|
+
throw new TypeError('The consuming package must have a name or set projectName.');
|
|
40
|
+
}
|
|
41
|
+
return { name, root };
|
|
42
|
+
}
|
|
43
|
+
async function discoveryStart(moduleUrl) {
|
|
44
|
+
const candidate = moduleUrl === undefined
|
|
45
|
+
? process.argv[1] ?? process.cwd()
|
|
46
|
+
: moduleUrl instanceof URL || moduleUrl.startsWith('file:')
|
|
47
|
+
? fileURLToPath(moduleUrl)
|
|
48
|
+
: moduleUrl;
|
|
49
|
+
const absolute = path.resolve(candidate);
|
|
50
|
+
try {
|
|
51
|
+
return await realpath(absolute);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return absolute;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function findPackageRoot(start) {
|
|
58
|
+
let current;
|
|
59
|
+
try {
|
|
60
|
+
current = (await stat(start)).isDirectory() ? start : path.dirname(start);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
current = path.extname(start) === '' ? start : path.dirname(start);
|
|
64
|
+
}
|
|
65
|
+
while (true) {
|
|
66
|
+
const manifest = path.join(current, 'package.json');
|
|
67
|
+
try {
|
|
68
|
+
await access(manifest, constants.R_OK);
|
|
69
|
+
return current;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
const parent = path.dirname(current);
|
|
73
|
+
if (parent === current) {
|
|
74
|
+
throw new Error(`Could not find a package.json above ${JSON.stringify(start)}.`);
|
|
75
|
+
}
|
|
76
|
+
current = parent;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function loadDependencies(packageRoot, settings) {
|
|
81
|
+
const project = await importDependencies(packageRoot);
|
|
82
|
+
const invocationDirectory = path.resolve(settings.invocationDirectory ?? process.cwd());
|
|
83
|
+
const detected = await detectPackageManager(invocationDirectory);
|
|
84
|
+
const packageManager = detected ?? 'npm';
|
|
85
|
+
const installRoot = path.resolve(settings.cacheDirectory ?? packageRoot);
|
|
86
|
+
const installSource = settings.cacheDirectory ? 'cache' : 'package-root';
|
|
87
|
+
if (settings.cacheDirectory)
|
|
88
|
+
await ensureCachePackage(installRoot);
|
|
89
|
+
if (project) {
|
|
90
|
+
const projectCleanStack = await importCleanStack(packageRoot, settings.log);
|
|
91
|
+
const cleanStack = projectCleanStack ?? await cachedCleanStack(installRoot, packageManager, settings.log);
|
|
92
|
+
return { ...project, cleanStack, source: 'project' };
|
|
93
|
+
}
|
|
94
|
+
let installation = installPromises.get(installRoot);
|
|
95
|
+
if (!installation) {
|
|
96
|
+
installation = installAndImport(installRoot, packageManager, installSource, settings.log);
|
|
97
|
+
installPromises.set(installRoot, installation);
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
return await installation;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
installPromises.delete(installRoot);
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function installAndImport(installRoot, packageManager, source, log) {
|
|
108
|
+
const cleanStack = await cachedCleanStack(installRoot, packageManager, log);
|
|
109
|
+
const existing = await importDependencies(installRoot);
|
|
110
|
+
if (existing)
|
|
111
|
+
return { ...existing, cleanStack, source };
|
|
112
|
+
log?.('Installing required CLI dependencies.', {
|
|
113
|
+
installDirectory: installRoot,
|
|
114
|
+
packages: REQUIRED_CLI_DEPENDENCY_SPECIFIERS,
|
|
115
|
+
packageManager,
|
|
116
|
+
});
|
|
117
|
+
try {
|
|
118
|
+
await installWithoutSaving(REQUIRED_CLI_DEPENDENCY_SPECIFIERS, installRoot, packageManager);
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
log?.('Could not install required CLI dependencies.', {
|
|
122
|
+
error: formatError(error, cleanStack),
|
|
123
|
+
});
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
const installed = await importDependencies(installRoot);
|
|
127
|
+
if (!installed) {
|
|
128
|
+
const unresolved = ['fireargs', 'zod'].filter(name => !resolvePackage(name, installRoot));
|
|
129
|
+
throw new Error(`CLI dependencies were installed but ${unresolved.join(' and ') || 'their exports'} could not be resolved from ${installRoot}.`);
|
|
130
|
+
}
|
|
131
|
+
log?.('Required CLI dependencies are ready.', { installDirectory: installRoot });
|
|
132
|
+
return { ...installed, cleanStack, source };
|
|
133
|
+
}
|
|
134
|
+
async function importDependencies(root) {
|
|
135
|
+
const [adapter, zod] = await Promise.all([
|
|
136
|
+
importPackageIfAvailable('fireargs', root),
|
|
137
|
+
importPackageIfAvailable('zod', root),
|
|
138
|
+
]);
|
|
139
|
+
if (!adapter || !zod)
|
|
140
|
+
return undefined;
|
|
141
|
+
const requiredBuilders = ['argument', 'command', 'option', 'program'];
|
|
142
|
+
if (!adapter.f || requiredBuilders.some(name => typeof adapter.f[name] !== 'function')) {
|
|
143
|
+
throw new TypeError('The resolved CLI adapter does not expose its required builder functions.');
|
|
144
|
+
}
|
|
145
|
+
if (!zod.z || typeof zod.z.object !== 'function') {
|
|
146
|
+
throw new TypeError('The resolved Zod package does not expose z.object().');
|
|
147
|
+
}
|
|
148
|
+
return { f: adapter.f, z: zod.z };
|
|
149
|
+
}
|
|
150
|
+
async function cachedCleanStack(cacheRoot, packageManager, log) {
|
|
151
|
+
let installation = cleanStackPromises.get(cacheRoot);
|
|
152
|
+
if (!installation) {
|
|
153
|
+
installation = installCleanStack(cacheRoot, packageManager, log);
|
|
154
|
+
cleanStackPromises.set(cacheRoot, installation);
|
|
155
|
+
}
|
|
156
|
+
return installation;
|
|
157
|
+
}
|
|
158
|
+
async function installCleanStack(installRoot, packageManager, log) {
|
|
159
|
+
const existing = await importCleanStack(installRoot, log);
|
|
160
|
+
if (existing)
|
|
161
|
+
return existing;
|
|
162
|
+
log?.('Installing optional stack cleaner.', {
|
|
163
|
+
installDirectory: installRoot,
|
|
164
|
+
package: CLEAN_STACK_SPECIFIER,
|
|
165
|
+
packageManager,
|
|
166
|
+
});
|
|
167
|
+
try {
|
|
168
|
+
await installWithoutSaving(CLEAN_STACK_SPECIFIER, installRoot, packageManager);
|
|
169
|
+
const installed = await importCleanStack(installRoot, log);
|
|
170
|
+
if (installed)
|
|
171
|
+
log?.('Optional stack cleaner is ready.', { installDirectory: installRoot });
|
|
172
|
+
return installed;
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
log?.('Optional stack cleaner is unavailable.', { error: formatError(error) });
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async function importCleanStack(root, log) {
|
|
180
|
+
try {
|
|
181
|
+
return (await importPackageIfAvailable('clean-stack', root))
|
|
182
|
+
?.default;
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
log?.('Optional stack cleaner could not be loaded.', { error: formatError(error) });
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function formatError(error, cleanStack) {
|
|
190
|
+
const stack = error instanceof Error
|
|
191
|
+
? error.stack ?? `${error.name}: ${error.message}`
|
|
192
|
+
: String(error);
|
|
193
|
+
if (!cleanStack)
|
|
194
|
+
return stack;
|
|
195
|
+
try {
|
|
196
|
+
return cleanStack(stack, { pretty: true });
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
return stack;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
async function ensureCachePackage(cacheRoot) {
|
|
203
|
+
await mkdir(cacheRoot, { recursive: true });
|
|
204
|
+
const manifest = path.join(cacheRoot, 'package.json');
|
|
205
|
+
try {
|
|
206
|
+
await writeFile(manifest, `${JSON.stringify({ name: 'optionkit-cli-cache', private: true, type: 'module' }, null, 2)}\n`, { encoding: 'utf8', flag: 'wx' });
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
if (!(error instanceof Error && 'code' in error && error.code === 'EEXIST'))
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const INSTALL_STATE_FILES = [
|
|
214
|
+
'package.json',
|
|
215
|
+
'bun.lock',
|
|
216
|
+
'bun.lockb',
|
|
217
|
+
'package-lock.json',
|
|
218
|
+
'pnpm-lock.yaml',
|
|
219
|
+
'yarn.lock',
|
|
220
|
+
];
|
|
221
|
+
async function installWithoutSaving(packages, installRoot, packageManager) {
|
|
222
|
+
const snapshots = new Map();
|
|
223
|
+
for (const name of INSTALL_STATE_FILES) {
|
|
224
|
+
const filename = path.join(installRoot, name);
|
|
225
|
+
try {
|
|
226
|
+
snapshots.set(filename, await readFile(filename));
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
if (!(error instanceof Error && 'code' in error && error.code === 'ENOENT'))
|
|
230
|
+
throw error;
|
|
231
|
+
snapshots.set(filename, undefined);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
await installPackage(packages, {
|
|
236
|
+
additionalArgs: agent => noSaveArguments(agent),
|
|
237
|
+
cwd: installRoot,
|
|
238
|
+
packageManager,
|
|
239
|
+
preferOffline: true,
|
|
240
|
+
silent: true,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
finally {
|
|
244
|
+
for (const [filename, content] of snapshots) {
|
|
245
|
+
if (content)
|
|
246
|
+
await writeFile(filename, content);
|
|
247
|
+
else
|
|
248
|
+
await rm(filename, { force: true });
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function noSaveArguments(agent) {
|
|
253
|
+
if (agent === 'bun')
|
|
254
|
+
return ['--no-save'];
|
|
255
|
+
if (agent === 'npm')
|
|
256
|
+
return ['--no-save', '--package-lock=false'];
|
|
257
|
+
if (agent === 'pnpm')
|
|
258
|
+
return ['--lockfile=false'];
|
|
259
|
+
if (agent === 'yarn')
|
|
260
|
+
return ['--no-lockfile'];
|
|
261
|
+
return [];
|
|
262
|
+
}
|
|
263
|
+
function createAdapter(adapter, zod, environmentPrefix, settings) {
|
|
264
|
+
return {
|
|
265
|
+
...adapter,
|
|
266
|
+
command(configuration = {}) {
|
|
267
|
+
const builder = adapter.command(configuration);
|
|
268
|
+
return {
|
|
269
|
+
input(schema) {
|
|
270
|
+
const adapted = adaptInputSchema(schema, adapter, zod, environmentPrefix, settings);
|
|
271
|
+
return builder.input(adapted);
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
function adaptInputSchema(schema, adapter, zod, environmentPrefix, settings) {
|
|
278
|
+
const object = objectSchema(schema);
|
|
279
|
+
const shape = object.shape;
|
|
280
|
+
const registered = Object.fromEntries(Object.entries(shape).flatMap(([key, field]) => {
|
|
281
|
+
const configuration = registeredFieldConfiguration(field, zod);
|
|
282
|
+
return configuration ? [[key, configuration]] : [];
|
|
283
|
+
}));
|
|
284
|
+
const configurations = optionConfigurations(shape, environmentPrefix, zod, settings, registered);
|
|
285
|
+
const fields = Object.fromEntries(Object.entries(shape).map(([key, field]) => {
|
|
286
|
+
if (registered[key]?.kind === 'argument')
|
|
287
|
+
return [key, field];
|
|
288
|
+
return [key, adapter.option(configurations[key]).schema(field)];
|
|
289
|
+
}));
|
|
290
|
+
return object.safeExtend(fields);
|
|
291
|
+
}
|
|
292
|
+
function objectShape(schema) {
|
|
293
|
+
return objectSchema(schema).shape;
|
|
294
|
+
}
|
|
295
|
+
function objectSchema(schema) {
|
|
296
|
+
let candidate = schema;
|
|
297
|
+
while (candidate && typeof candidate === 'object') {
|
|
298
|
+
if ('shape' in candidate) {
|
|
299
|
+
const shape = candidate.shape;
|
|
300
|
+
if (shape && typeof shape === 'object')
|
|
301
|
+
return candidate;
|
|
302
|
+
}
|
|
303
|
+
if (!('unwrap' in candidate) || typeof candidate.unwrap !== 'function')
|
|
304
|
+
break;
|
|
305
|
+
candidate = candidate.unwrap();
|
|
306
|
+
}
|
|
307
|
+
throw new TypeError('createOptionKit requires a Zod object schema, optionally wrapped as readonly.');
|
|
308
|
+
}
|
|
309
|
+
function resolveEnvironmentPrefix(configured, projectName) {
|
|
310
|
+
if (configured === false)
|
|
311
|
+
return false;
|
|
312
|
+
const translated = toEnvironmentKey(configured ?? projectName);
|
|
313
|
+
if (!translated)
|
|
314
|
+
throw new TypeError('The environment prefix must contain a letter or number.');
|
|
315
|
+
return `${translated}_`;
|
|
316
|
+
}
|
|
317
|
+
function optionConfigurations(shape, environmentPrefix, zod, settings, registered = {}) {
|
|
318
|
+
const keys = Object.keys(shape).filter(key => registered[key]?.kind !== 'argument');
|
|
319
|
+
const overrides = Object.fromEntries(keys.map(key => {
|
|
320
|
+
const existing = registered[key];
|
|
321
|
+
const existingOption = existing?.kind === 'option'
|
|
322
|
+
? Object.fromEntries(Object.entries(existing).filter(([name]) => name !== 'kind'))
|
|
323
|
+
: {};
|
|
324
|
+
return [key, { ...settings.fields?.[key], ...existingOption }];
|
|
325
|
+
}));
|
|
326
|
+
const shorts = generatedShortFlags(keys, overrides, settings);
|
|
327
|
+
return Object.fromEntries(keys.map(key => {
|
|
328
|
+
const override = overrides?.[key];
|
|
329
|
+
const generated = {};
|
|
330
|
+
if (environmentPrefix !== false && override?.env !== false) {
|
|
331
|
+
generated.env = override?.env ?? `${environmentPrefix}${toEnvironmentKey(key)}`;
|
|
332
|
+
const kind = structuredValueKind(shape[key], zod);
|
|
333
|
+
if (kind && !override?.parse)
|
|
334
|
+
generated.parse = structuredValueParser(kind);
|
|
335
|
+
}
|
|
336
|
+
if (override?.short !== false && (override?.short ?? shorts[key])) {
|
|
337
|
+
generated.short = typeof override?.short === 'string'
|
|
338
|
+
? normalizeShort(override.short, key)
|
|
339
|
+
: shorts[key];
|
|
340
|
+
}
|
|
341
|
+
if (override) {
|
|
342
|
+
const { env: _env, short: _short, parse, ...rest } = override;
|
|
343
|
+
Object.assign(generated, rest);
|
|
344
|
+
if (parse)
|
|
345
|
+
generated.parse = parse;
|
|
346
|
+
}
|
|
347
|
+
return [key, generated];
|
|
348
|
+
}));
|
|
349
|
+
}
|
|
350
|
+
function registeredFieldConfiguration(schema, zod, seen = new Set()) {
|
|
351
|
+
if (seen.has(schema))
|
|
352
|
+
return undefined;
|
|
353
|
+
seen.add(schema);
|
|
354
|
+
const metadata = zod.globalRegistry.get(schema);
|
|
355
|
+
const registered = metadata?.fireargs;
|
|
356
|
+
if (registered && typeof registered === 'object' && 'kind' in registered) {
|
|
357
|
+
const kind = registered.kind;
|
|
358
|
+
if (kind === 'argument' || kind === 'option') {
|
|
359
|
+
return registered;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (schema instanceof zod.ZodPipe) {
|
|
363
|
+
return registeredFieldConfiguration(schema.in, zod, seen);
|
|
364
|
+
}
|
|
365
|
+
const wrapper = schema;
|
|
366
|
+
return typeof wrapper.unwrap === 'function'
|
|
367
|
+
? registeredFieldConfiguration(wrapper.unwrap(), zod, seen)
|
|
368
|
+
: undefined;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Fireargs handles structured argv values, but an environment variable reaches
|
|
372
|
+
* Commander as one string. Detect only unambiguous JSON containers so scalar
|
|
373
|
+
* coercion and Fireargs' native parsing remain untouched.
|
|
374
|
+
*/
|
|
375
|
+
function structuredValueKind(schema, zod, seen = new Set()) {
|
|
376
|
+
if (!schema || seen.has(schema))
|
|
377
|
+
return undefined;
|
|
378
|
+
seen.add(schema);
|
|
379
|
+
if (schema instanceof zod.ZodArray || schema instanceof zod.ZodTuple)
|
|
380
|
+
return 'array';
|
|
381
|
+
if (schema instanceof zod.ZodObject || schema instanceof zod.ZodRecord)
|
|
382
|
+
return 'object';
|
|
383
|
+
if (schema instanceof zod.ZodUnion) {
|
|
384
|
+
const kinds = schema.options.map(option => (structuredValueKind(option, zod, new Set(seen)))).filter((kind) => kind !== undefined);
|
|
385
|
+
const unique = new Set(kinds);
|
|
386
|
+
return unique.size === 1 ? kinds[0] : undefined;
|
|
387
|
+
}
|
|
388
|
+
if (schema instanceof zod.ZodPipe) {
|
|
389
|
+
return structuredValueKind(schema.in, zod, seen);
|
|
390
|
+
}
|
|
391
|
+
const wrapper = schema;
|
|
392
|
+
return typeof wrapper.unwrap === 'function'
|
|
393
|
+
? structuredValueKind(wrapper.unwrap(), zod, seen)
|
|
394
|
+
: undefined;
|
|
395
|
+
}
|
|
396
|
+
function structuredValueParser(kind) {
|
|
397
|
+
return ((value) => {
|
|
398
|
+
try {
|
|
399
|
+
return JSON.parse(value);
|
|
400
|
+
}
|
|
401
|
+
catch {
|
|
402
|
+
// A non-JSON string may still be useful to an array schema or a union.
|
|
403
|
+
}
|
|
404
|
+
return kind === 'array' ? splitArrayValue(value) ?? value : value;
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
/** Split comma- or whitespace-delimited shell words without interpreting operators. */
|
|
408
|
+
function splitArrayValue(value) {
|
|
409
|
+
const result = [];
|
|
410
|
+
let token = '';
|
|
411
|
+
let quote;
|
|
412
|
+
let escaped = false;
|
|
413
|
+
let started = false;
|
|
414
|
+
for (const character of value) {
|
|
415
|
+
if (escaped) {
|
|
416
|
+
token += character;
|
|
417
|
+
escaped = false;
|
|
418
|
+
started = true;
|
|
419
|
+
}
|
|
420
|
+
else if (character === '\\') {
|
|
421
|
+
escaped = true;
|
|
422
|
+
started = true;
|
|
423
|
+
}
|
|
424
|
+
else if (quote) {
|
|
425
|
+
if (character === quote)
|
|
426
|
+
quote = undefined;
|
|
427
|
+
else
|
|
428
|
+
token += character;
|
|
429
|
+
started = true;
|
|
430
|
+
}
|
|
431
|
+
else if (character === '"' || character === "'") {
|
|
432
|
+
quote = character;
|
|
433
|
+
started = true;
|
|
434
|
+
}
|
|
435
|
+
else if (character === ',' || /\s/u.test(character)) {
|
|
436
|
+
if (started)
|
|
437
|
+
result.push(token);
|
|
438
|
+
token = '';
|
|
439
|
+
started = false;
|
|
440
|
+
}
|
|
441
|
+
else {
|
|
442
|
+
token += character;
|
|
443
|
+
started = true;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (quote || escaped)
|
|
447
|
+
return undefined;
|
|
448
|
+
if (started)
|
|
449
|
+
result.push(token);
|
|
450
|
+
return result;
|
|
451
|
+
}
|
|
452
|
+
function generatedShortFlags(keys, overrides, settings) {
|
|
453
|
+
if (settings.shortFlags === false)
|
|
454
|
+
return {};
|
|
455
|
+
const reserved = new Set(['h', ...(settings.reservedShortFlags ?? [])].map(value => value.toLowerCase()));
|
|
456
|
+
const explicit = new Map();
|
|
457
|
+
for (const key of keys) {
|
|
458
|
+
const value = overrides?.[key]?.short;
|
|
459
|
+
if (typeof value !== 'string')
|
|
460
|
+
continue;
|
|
461
|
+
const normalized = normalizeShort(value, key);
|
|
462
|
+
const owner = explicit.get(normalized);
|
|
463
|
+
if (owner)
|
|
464
|
+
throw new TypeError(`Short flag -${normalized} is configured for both ${owner} and ${key}.`);
|
|
465
|
+
if (reserved.has(normalized))
|
|
466
|
+
throw new TypeError(`Short flag -${normalized} is reserved.`);
|
|
467
|
+
explicit.set(normalized, key);
|
|
468
|
+
}
|
|
469
|
+
const candidates = new Map();
|
|
470
|
+
for (const key of keys) {
|
|
471
|
+
if (overrides?.[key]?.short !== undefined)
|
|
472
|
+
continue;
|
|
473
|
+
const longName = overrides?.[key]?.name ?? key;
|
|
474
|
+
const candidate = toEnvironmentKey(longName).charAt(0).toLowerCase();
|
|
475
|
+
if (!candidate || reserved.has(candidate) || explicit.has(candidate))
|
|
476
|
+
continue;
|
|
477
|
+
candidates.set(candidate, [...(candidates.get(candidate) ?? []), key]);
|
|
478
|
+
}
|
|
479
|
+
const result = {};
|
|
480
|
+
for (const [candidate, owners] of candidates) {
|
|
481
|
+
if (owners.length === 1)
|
|
482
|
+
result[owners[0]] = candidate;
|
|
483
|
+
}
|
|
484
|
+
return result;
|
|
485
|
+
}
|
|
486
|
+
function normalizeShort(value, key) {
|
|
487
|
+
const normalized = value.replace(/^-+/u, '').toLowerCase();
|
|
488
|
+
if (!/^[a-z0-9]$/u.test(normalized)) {
|
|
489
|
+
throw new TypeError(`Short flag for ${key} must be one letter or digit.`);
|
|
490
|
+
}
|
|
491
|
+
return normalized;
|
|
492
|
+
}
|
|
493
|
+
function toEnvironmentKey(value) {
|
|
494
|
+
return value
|
|
495
|
+
.replace(/([a-z0-9])([A-Z])/gu, '$1_$2')
|
|
496
|
+
.replace(/^@/u, '')
|
|
497
|
+
.replace(/[^a-zA-Z0-9]+/gu, '_')
|
|
498
|
+
.replace(/^_+|_+$/gu, '')
|
|
499
|
+
.toUpperCase();
|
|
500
|
+
}
|
|
501
|
+
//# sourceMappingURL=optionkit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optionkit.js","sourceRoot":"","sources":["../src/optionkit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,SA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B,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;SACxB,WAAW,EAAE,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Resolve a package from an explicit package root without importing it. */
|
|
2
|
+
export declare function resolvePackage(packageName: string, packageRoot: string): string | undefined;
|
|
3
|
+
/** Import a package only when it is already resolvable from the supplied package root. */
|
|
4
|
+
export declare function importPackageIfAvailable<Module = unknown>(packageName: string, packageRoot: string): Promise<Module | undefined>;
|
|
5
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAKA,4EAA4E;AAC5E,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAQ3F;AAED,0FAA0F;AAC1F,wBAAsB,wBAAwB,CAAC,MAAM,GAAG,OAAO,EAC7D,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAI7B"}
|
package/dist/resolve.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
/** Resolve a package from an explicit package root without importing it. */
|
|
6
|
+
export function resolvePackage(packageName, packageRoot) {
|
|
7
|
+
const resolver = createRequire(path.join(path.resolve(packageRoot), 'package.json'));
|
|
8
|
+
try {
|
|
9
|
+
return resolver.resolve(packageName);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
if (isMissingModule(error))
|
|
13
|
+
return resolveInstalledPackage(packageName, packageRoot);
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Import a package only when it is already resolvable from the supplied package root. */
|
|
18
|
+
export async function importPackageIfAvailable(packageName, packageRoot) {
|
|
19
|
+
const resolved = resolvePackage(packageName, packageRoot);
|
|
20
|
+
if (!resolved)
|
|
21
|
+
return undefined;
|
|
22
|
+
return import(pathToFileURL(resolved).href);
|
|
23
|
+
}
|
|
24
|
+
function isMissingModule(error) {
|
|
25
|
+
return error instanceof Error && 'code' in error && error.code === 'MODULE_NOT_FOUND';
|
|
26
|
+
}
|
|
27
|
+
/** Bypass Node's cached miss after a package was installed during this process. */
|
|
28
|
+
function resolveInstalledPackage(packageName, packageRoot) {
|
|
29
|
+
if (!/^(?:@[a-z0-9._~-]+\/)?[a-z0-9._~-]+$/iu.test(packageName))
|
|
30
|
+
return undefined;
|
|
31
|
+
const directory = path.join(path.resolve(packageRoot), 'node_modules', ...packageName.split('/'));
|
|
32
|
+
const manifestPath = path.join(directory, 'package.json');
|
|
33
|
+
if (!existsSync(manifestPath))
|
|
34
|
+
return undefined;
|
|
35
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
36
|
+
const entry = rootExport(manifest.exports)
|
|
37
|
+
?? stringValue(manifest.module)
|
|
38
|
+
?? stringValue(manifest.main)
|
|
39
|
+
?? './index.js';
|
|
40
|
+
const resolved = path.resolve(directory, entry);
|
|
41
|
+
return existsSync(resolved) ? resolved : undefined;
|
|
42
|
+
}
|
|
43
|
+
function rootExport(value) {
|
|
44
|
+
if (typeof value === 'string')
|
|
45
|
+
return value;
|
|
46
|
+
if (!value || typeof value !== 'object')
|
|
47
|
+
return undefined;
|
|
48
|
+
const record = value;
|
|
49
|
+
if (record['.'] !== undefined)
|
|
50
|
+
return rootExport(record['.']);
|
|
51
|
+
for (const condition of ['import', 'node', 'default', 'require']) {
|
|
52
|
+
const resolved = rootExport(record[condition]);
|
|
53
|
+
if (resolved)
|
|
54
|
+
return resolved;
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
function stringValue(value) {
|
|
59
|
+
return typeof value === 'string' ? value : undefined;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,4EAA4E;AAC5E,MAAM,UAAU,cAAc,CAAC,WAAmB,EAAE,WAAmB;IACrE,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC;IACrF,IAAI,CAAC;QACH,OAAO,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACvC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,eAAe,CAAC,KAAK,CAAC;YAAE,OAAO,uBAAuB,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;QACrF,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,0FAA0F;AAC1F,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,WAAmB,EACnB,WAAmB;IAEnB,MAAM,QAAQ,GAAG,cAAc,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;IAC1D,IAAI,CAAC,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChC,OAAO,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAoB,CAAC;AACjE,CAAC;AAED,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAA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,CAAC;IAC9D,KAAK,MAAM,SAAS,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC;QACjE,MAAM,QAAQ,GAAG,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;QAC/C,IAAI,QAAQ;YAAE,OAAO,QAAQ,CAAC;IAChC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AACvD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,89 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "optionkit",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Turn Zod configuration schemas into zero-setup CLI options.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist/",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "bun run scripts/build.ts",
|
|
22
|
+
"generate": "bun run scripts/generate-catalog.ts",
|
|
23
|
+
"test": "bun run generate && bun test",
|
|
24
|
+
"test:packed": "bun run build && bun run scripts/test-packed.ts",
|
|
25
|
+
"typecheck": "bun run generate && tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.scripts.json && tsc --noEmit -p tests/tsconfig.json",
|
|
26
|
+
"verify": "bun run typecheck && bun test && bun run build",
|
|
27
|
+
"release": "bun run scripts/release.ts",
|
|
28
|
+
"release:pack": "bun run scripts/pack-for-publish.ts",
|
|
29
|
+
"prepack": "bun run scripts/prepack.ts"
|
|
30
|
+
},
|
|
31
|
+
"keywords": [
|
|
32
|
+
"args",
|
|
33
|
+
"cli",
|
|
34
|
+
"config",
|
|
35
|
+
"environment",
|
|
36
|
+
"fireargs",
|
|
37
|
+
"zod"
|
|
38
|
+
],
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/regbo/optionkit.git"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/regbo/optionkit/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/regbo/optionkit#readme",
|
|
48
|
+
"workspaces": [
|
|
49
|
+
"."
|
|
50
|
+
],
|
|
51
|
+
"catalog": {
|
|
52
|
+
"clean-stack": "^7.0.0",
|
|
53
|
+
"fireargs": "^0.6.2",
|
|
54
|
+
"zod": "^4.6.7"
|
|
55
|
+
},
|
|
56
|
+
"sideEffects": false,
|
|
57
|
+
"engines": {
|
|
58
|
+
"node": ">=18"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@antfu/install-pkg": "^2.1.0"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"fireargs": "catalog:",
|
|
65
|
+
"zod": "catalog:"
|
|
66
|
+
},
|
|
67
|
+
"peerDependenciesMeta": {
|
|
68
|
+
"fireargs": {
|
|
69
|
+
"optional": true
|
|
70
|
+
},
|
|
71
|
+
"zod": {
|
|
72
|
+
"optional": true
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@types/bun": "^1.4.4",
|
|
77
|
+
"@types/node": "^26.6.6",
|
|
78
|
+
"clean-stack": "catalog:",
|
|
79
|
+
"fireargs": "catalog:",
|
|
80
|
+
"typescript": "^7.0.2",
|
|
81
|
+
"zod": "catalog:"
|
|
82
|
+
},
|
|
83
|
+
"packageManager": "bun@1.4.4",
|
|
84
|
+
"publishConfig": {
|
|
85
|
+
"access": "public",
|
|
86
|
+
"provenance": true,
|
|
87
|
+
"registry": "https://registry.npmjs.org"
|
|
88
|
+
}
|
|
89
|
+
}
|