@karmaniverous/get-dotenv 5.2.6 → 6.0.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -70
- package/dist/cliHost.d.ts +232 -226
- package/dist/cliHost.mjs +777 -545
- package/dist/config.d.ts +7 -2
- package/dist/env-overlay.d.ts +21 -9
- package/dist/env-overlay.mjs +14 -19
- package/dist/getdotenv.cli.mjs +1366 -1163
- package/dist/index.d.ts +415 -242
- package/dist/index.mjs +1364 -1414
- package/dist/plugins-aws.d.ts +149 -94
- package/dist/plugins-aws.mjs +307 -195
- package/dist/plugins-batch.d.ts +153 -99
- package/dist/plugins-batch.mjs +277 -95
- package/dist/plugins-cmd.d.ts +140 -94
- package/dist/plugins-cmd.mjs +636 -502
- package/dist/plugins-demo.d.ts +140 -94
- package/dist/plugins-demo.mjs +237 -46
- package/dist/plugins-init.d.ts +140 -94
- package/dist/plugins-init.mjs +129 -12
- package/dist/plugins.d.ts +166 -103
- package/dist/plugins.mjs +977 -840
- package/package.json +15 -53
- package/templates/cli/ts/plugins/hello.ts +27 -6
- package/templates/config/js/getdotenv.config.js +1 -1
- package/templates/config/ts/getdotenv.config.ts +9 -2
- package/dist/cliHost.cjs +0 -1875
- package/dist/cliHost.d.cts +0 -409
- package/dist/cliHost.d.mts +0 -409
- package/dist/config.cjs +0 -252
- package/dist/config.d.cts +0 -55
- package/dist/config.d.mts +0 -55
- package/dist/env-overlay.cjs +0 -163
- package/dist/env-overlay.d.cts +0 -50
- package/dist/env-overlay.d.mts +0 -50
- package/dist/index.cjs +0 -4140
- package/dist/index.d.cts +0 -457
- package/dist/index.d.mts +0 -457
- package/dist/plugins-aws.cjs +0 -667
- package/dist/plugins-aws.d.cts +0 -158
- package/dist/plugins-aws.d.mts +0 -158
- package/dist/plugins-batch.cjs +0 -616
- package/dist/plugins-batch.d.cts +0 -180
- package/dist/plugins-batch.d.mts +0 -180
- package/dist/plugins-cmd.cjs +0 -1113
- package/dist/plugins-cmd.d.cts +0 -178
- package/dist/plugins-cmd.d.mts +0 -178
- package/dist/plugins-demo.cjs +0 -307
- package/dist/plugins-demo.d.cts +0 -158
- package/dist/plugins-demo.d.mts +0 -158
- package/dist/plugins-init.cjs +0 -289
- package/dist/plugins-init.d.cts +0 -162
- package/dist/plugins-init.d.mts +0 -162
- package/dist/plugins.cjs +0 -2283
- package/dist/plugins.d.cts +0 -210
- package/dist/plugins.d.mts +0 -210
package/dist/cliHost.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import {
|
|
1
|
+
import { Command, Option } from 'commander';
|
|
2
|
+
import { z, ZodObject } from 'zod';
|
|
3
|
+
export { z } from 'zod';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Minimal root options shape shared by CLI and generator layers.
|
|
@@ -47,12 +48,34 @@ type RootOptionsShape = {
|
|
|
47
48
|
*/
|
|
48
49
|
type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<string, string | {
|
|
49
50
|
cmd: string;
|
|
50
|
-
shell?: TShell;
|
|
51
|
+
shell?: TShell | undefined;
|
|
51
52
|
}>;
|
|
52
53
|
|
|
54
|
+
declare const getDotenvOptionsSchemaResolved: z.ZodObject<{
|
|
55
|
+
defaultEnv: z.ZodOptional<z.ZodString>;
|
|
56
|
+
dotenvToken: z.ZodOptional<z.ZodString>;
|
|
57
|
+
dynamicPath: z.ZodOptional<z.ZodString>;
|
|
58
|
+
dynamic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
59
|
+
env: z.ZodOptional<z.ZodString>;
|
|
60
|
+
excludeDynamic: z.ZodOptional<z.ZodBoolean>;
|
|
61
|
+
excludeEnv: z.ZodOptional<z.ZodBoolean>;
|
|
62
|
+
excludeGlobal: z.ZodOptional<z.ZodBoolean>;
|
|
63
|
+
excludePrivate: z.ZodOptional<z.ZodBoolean>;
|
|
64
|
+
excludePublic: z.ZodOptional<z.ZodBoolean>;
|
|
65
|
+
loadProcess: z.ZodOptional<z.ZodBoolean>;
|
|
66
|
+
log: z.ZodOptional<z.ZodBoolean>;
|
|
67
|
+
logger: z.ZodOptional<z.ZodUnknown>;
|
|
68
|
+
outputPath: z.ZodOptional<z.ZodString>;
|
|
69
|
+
paths: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
70
|
+
privateToken: z.ZodOptional<z.ZodString>;
|
|
71
|
+
vars: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodString>>>;
|
|
72
|
+
}, z.core.$strip>;
|
|
73
|
+
|
|
53
74
|
/**
|
|
54
75
|
* A minimal representation of an environment key/value mapping.
|
|
55
|
-
* Values may be `undefined` to represent "unset".
|
|
76
|
+
* Values may be `undefined` to represent "unset".
|
|
77
|
+
*/
|
|
78
|
+
type ProcessEnv = Record<string, string | undefined>;
|
|
56
79
|
/**
|
|
57
80
|
* Dynamic variable function signature. Receives the current expanded variables
|
|
58
81
|
* and the selected environment (if any), and returns either a string to set
|
|
@@ -62,173 +85,203 @@ type GetDotenvDynamicFunction = (vars: ProcessEnv, env: string | undefined) => s
|
|
|
62
85
|
type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
|
|
63
86
|
type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
|
|
64
87
|
/**
|
|
65
|
-
*
|
|
88
|
+
* Canonical programmatic options type (schema-derived).
|
|
89
|
+
* This type is the single source of truth for programmatic options.
|
|
66
90
|
*/
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* default target environment (used if `env` is not provided)
|
|
70
|
-
*/
|
|
71
|
-
defaultEnv?: string;
|
|
72
|
-
/**
|
|
73
|
-
* token indicating a dotenv file
|
|
74
|
-
*/
|
|
75
|
-
dotenvToken: string;
|
|
91
|
+
type GetDotenvOptions = z.output<typeof getDotenvOptionsSchemaResolved> & {
|
|
76
92
|
/**
|
|
77
|
-
*
|
|
93
|
+
* Compile-time overlay: narrowed logger for DX (schema stores unknown).
|
|
78
94
|
*/
|
|
79
|
-
|
|
95
|
+
logger?: Logger;
|
|
80
96
|
/**
|
|
81
|
-
*
|
|
82
|
-
* over {@link GetDotenvOptions.dynamicPath}.
|
|
97
|
+
* Compile-time overlay: narrowed dynamic map for DX (schema stores unknown).
|
|
83
98
|
*/
|
|
84
99
|
dynamic?: GetDotenvDynamic;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
declare const getDotenvCliOptionsSchemaResolved: z.ZodObject<{
|
|
103
|
+
defaultEnv: z.ZodOptional<z.ZodString>;
|
|
104
|
+
dotenvToken: z.ZodOptional<z.ZodString>;
|
|
105
|
+
dynamicPath: z.ZodOptional<z.ZodString>;
|
|
106
|
+
dynamic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
107
|
+
env: z.ZodOptional<z.ZodString>;
|
|
108
|
+
excludeDynamic: z.ZodOptional<z.ZodBoolean>;
|
|
109
|
+
excludeEnv: z.ZodOptional<z.ZodBoolean>;
|
|
110
|
+
excludeGlobal: z.ZodOptional<z.ZodBoolean>;
|
|
111
|
+
excludePrivate: z.ZodOptional<z.ZodBoolean>;
|
|
112
|
+
excludePublic: z.ZodOptional<z.ZodBoolean>;
|
|
113
|
+
loadProcess: z.ZodOptional<z.ZodBoolean>;
|
|
114
|
+
log: z.ZodOptional<z.ZodBoolean>;
|
|
115
|
+
logger: z.ZodOptional<z.ZodUnknown>;
|
|
116
|
+
outputPath: z.ZodOptional<z.ZodString>;
|
|
117
|
+
privateToken: z.ZodOptional<z.ZodString>;
|
|
118
|
+
debug: z.ZodOptional<z.ZodBoolean>;
|
|
119
|
+
strict: z.ZodOptional<z.ZodBoolean>;
|
|
120
|
+
capture: z.ZodOptional<z.ZodBoolean>;
|
|
121
|
+
trace: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
|
|
122
|
+
redact: z.ZodOptional<z.ZodBoolean>;
|
|
123
|
+
warnEntropy: z.ZodOptional<z.ZodBoolean>;
|
|
124
|
+
entropyThreshold: z.ZodOptional<z.ZodNumber>;
|
|
125
|
+
entropyMinLength: z.ZodOptional<z.ZodNumber>;
|
|
126
|
+
entropyWhitelist: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
127
|
+
redactPatterns: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
128
|
+
paths: z.ZodOptional<z.ZodString>;
|
|
129
|
+
pathsDelimiter: z.ZodOptional<z.ZodString>;
|
|
130
|
+
pathsDelimiterPattern: z.ZodOptional<z.ZodString>;
|
|
131
|
+
scripts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
132
|
+
shell: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>;
|
|
133
|
+
vars: z.ZodOptional<z.ZodString>;
|
|
134
|
+
varsAssignor: z.ZodOptional<z.ZodString>;
|
|
135
|
+
varsAssignorPattern: z.ZodOptional<z.ZodString>;
|
|
136
|
+
varsDelimiter: z.ZodOptional<z.ZodString>;
|
|
137
|
+
varsDelimiterPattern: z.ZodOptional<z.ZodString>;
|
|
138
|
+
}, z.core.$strip>;
|
|
139
|
+
|
|
140
|
+
type Scripts = ScriptsTable;
|
|
141
|
+
/**
|
|
142
|
+
* Canonical CLI options type derived from the Zod schema output.
|
|
143
|
+
* Includes CLI-only flags (debug/strict/capture/trace/redaction/entropy),
|
|
144
|
+
* stringly paths/vars, and inherited programmatic fields (minus normalized
|
|
145
|
+
* shapes that are handled by resolution).
|
|
146
|
+
*/
|
|
147
|
+
type GetDotenvCliOptions = z.output<typeof getDotenvCliOptionsSchemaResolved> & {
|
|
85
148
|
/**
|
|
86
|
-
*
|
|
87
|
-
*/
|
|
88
|
-
env?: string;
|
|
89
|
-
/**
|
|
90
|
-
* exclude dynamic variables from loading
|
|
91
|
-
*/
|
|
92
|
-
excludeDynamic?: boolean;
|
|
93
|
-
/**
|
|
94
|
-
* exclude environment-specific variables from loading
|
|
95
|
-
*/
|
|
96
|
-
excludeEnv?: boolean;
|
|
97
|
-
/**
|
|
98
|
-
* exclude global variables from loading
|
|
99
|
-
*/
|
|
100
|
-
excludeGlobal?: boolean;
|
|
101
|
-
/**
|
|
102
|
-
* exclude private variables from loading
|
|
103
|
-
*/
|
|
104
|
-
excludePrivate?: boolean;
|
|
105
|
-
/**
|
|
106
|
-
* exclude public variables from loading
|
|
107
|
-
*/
|
|
108
|
-
excludePublic?: boolean;
|
|
109
|
-
/**
|
|
110
|
-
* load dotenv variables to `process.env`
|
|
111
|
-
*/
|
|
112
|
-
loadProcess?: boolean;
|
|
113
|
-
/**
|
|
114
|
-
* log loaded dotenv variables to `logger`
|
|
115
|
-
*/
|
|
116
|
-
log?: boolean;
|
|
117
|
-
/**
|
|
118
|
-
* logger object (defaults to console)
|
|
149
|
+
* Compile-only overlay for DX: logger narrowed from unknown.
|
|
119
150
|
*/
|
|
120
151
|
logger?: Logger;
|
|
121
152
|
/**
|
|
122
|
-
*
|
|
153
|
+
* Compile-only overlay for DX: scripts narrowed from Record\<string, unknown\>.
|
|
123
154
|
*/
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
* array of input directory paths
|
|
127
|
-
*/
|
|
128
|
-
paths?: string[];
|
|
129
|
-
/**
|
|
130
|
-
* filename token indicating private variables
|
|
131
|
-
*/
|
|
132
|
-
privateToken?: string;
|
|
133
|
-
/**
|
|
134
|
-
* explicit variables to include
|
|
135
|
-
*/
|
|
136
|
-
vars?: ProcessEnv;
|
|
137
|
-
/**
|
|
138
|
-
* Reserved: config loader flag (no-op).
|
|
139
|
-
* The plugin-first host and generator paths already use the config
|
|
140
|
-
* loader/overlay pipeline unconditionally (no-op when no config files
|
|
141
|
-
* are present). This flag is accepted for forward compatibility but
|
|
142
|
-
* currently has no effect.
|
|
143
|
-
*/
|
|
144
|
-
useConfigLoader?: boolean;
|
|
145
|
-
}
|
|
155
|
+
scripts?: Scripts;
|
|
156
|
+
};
|
|
146
157
|
|
|
147
|
-
type
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
158
|
+
type ResolvedHelpConfig = Partial<GetDotenvCliOptions> & {
|
|
159
|
+
plugins: Record<string, unknown>;
|
|
160
|
+
};
|
|
161
|
+
/** Per-invocation context shared with plugins and actions. */
|
|
162
|
+
type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
|
|
163
|
+
optionsResolved: TOptions;
|
|
164
|
+
dotenv: ProcessEnv;
|
|
165
|
+
plugins?: Record<string, unknown>;
|
|
166
|
+
pluginConfigs?: Record<string, unknown>;
|
|
167
|
+
};
|
|
168
|
+
declare const CTX_SYMBOL: unique symbol;
|
|
169
|
+
declare const OPTS_SYMBOL: unique symbol;
|
|
170
|
+
declare const HELP_HEADER_SYMBOL: unique symbol;
|
|
151
171
|
/**
|
|
152
|
-
*
|
|
172
|
+
* Plugin-first CLI host for get-dotenv. Extends Commander.Command.
|
|
173
|
+
*
|
|
174
|
+
* Responsibilities:
|
|
175
|
+
* - Resolve options strictly and compute dotenv context (resolveAndLoad).
|
|
176
|
+
* - Expose a stable accessor for the current context (getCtx).
|
|
177
|
+
* - Provide a namespacing helper (ns).
|
|
178
|
+
* - Support composable plugins with parent → children install and afterResolve.
|
|
153
179
|
*/
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
180
|
+
declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOptions> extends Command implements GetDotenvCliPublic<TOptions> {
|
|
181
|
+
/** Registered top-level plugins (composition happens via .use()) */
|
|
182
|
+
private _plugins;
|
|
183
|
+
/** One-time installation guard */
|
|
184
|
+
private _installed;
|
|
185
|
+
/** Optional header line to prepend in help output */
|
|
186
|
+
private [HELP_HEADER_SYMBOL];
|
|
187
|
+
/** Context/options stored under symbols (typed) */
|
|
188
|
+
private [CTX_SYMBOL]?;
|
|
189
|
+
private [OPTS_SYMBOL]?;
|
|
159
190
|
/**
|
|
160
|
-
*
|
|
161
|
-
*
|
|
191
|
+
* Create a subcommand using the same subclass, preserving helpers like
|
|
192
|
+
* dynamicOption on children.
|
|
162
193
|
*/
|
|
163
|
-
|
|
194
|
+
createCommand(name?: string): Command;
|
|
195
|
+
constructor(alias?: string);
|
|
164
196
|
/**
|
|
165
|
-
*
|
|
197
|
+
* Resolve options (strict) and compute dotenv context.
|
|
198
|
+
* Stores the context on the instance under a symbol.
|
|
199
|
+
*
|
|
200
|
+
* Options:
|
|
201
|
+
* - opts.runAfterResolve (default true): when false, skips running plugin
|
|
202
|
+
* afterResolve hooks. Useful for top-level help rendering to avoid
|
|
203
|
+
* long-running side-effects while still evaluating dynamic help text.
|
|
166
204
|
*/
|
|
167
|
-
|
|
205
|
+
resolveAndLoad(customOptions?: Partial<TOptions>, opts?: {
|
|
206
|
+
runAfterResolve?: boolean;
|
|
207
|
+
}): Promise<GetDotenvCliCtx<TOptions>>;
|
|
168
208
|
/**
|
|
169
|
-
*
|
|
209
|
+
* Create a Commander Option that computes its description at help time.
|
|
210
|
+
* The returned Option may be configured (conflicts, default, parser) and
|
|
211
|
+
* added via addOption().
|
|
170
212
|
*/
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
213
|
+
createDynamicOption(flags: string, desc: (cfg: ResolvedHelpConfig & {
|
|
214
|
+
plugins: Record<string, unknown>;
|
|
215
|
+
}) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option;
|
|
216
|
+
createDynamicOption<TValue = unknown>(flags: string, desc: (cfg: ResolvedHelpConfig & {
|
|
217
|
+
plugins: Record<string, unknown>;
|
|
218
|
+
}) => string, parser: (value: string, previous?: TValue) => TValue, defaultValue?: TValue): Option;
|
|
176
219
|
/**
|
|
177
|
-
*
|
|
178
|
-
*
|
|
220
|
+
* Chainable helper mirroring .option(), but with a dynamic description.
|
|
221
|
+
* Equivalent to addOption(createDynamicOption(...)).
|
|
179
222
|
*/
|
|
180
|
-
|
|
223
|
+
dynamicOption(flags: string, desc: (cfg: ResolvedHelpConfig & {
|
|
224
|
+
plugins: Record<string, unknown>;
|
|
225
|
+
}) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): this;
|
|
181
226
|
/**
|
|
182
|
-
*
|
|
227
|
+
* Evaluate dynamic descriptions for this command and all descendants using
|
|
228
|
+
* the provided resolved configuration. Mutates the Option.description in
|
|
229
|
+
* place so Commander help renders updated text.
|
|
183
230
|
*/
|
|
184
|
-
|
|
231
|
+
evaluateDynamicOptions(resolved: ResolvedHelpConfig): void;
|
|
185
232
|
/**
|
|
186
|
-
*
|
|
187
|
-
* `pathsDelimiterPattern` is not provided.
|
|
233
|
+
* Retrieve the current invocation context (if any).
|
|
188
234
|
*/
|
|
189
|
-
|
|
235
|
+
getCtx(): GetDotenvCliCtx<TOptions> | undefined;
|
|
190
236
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
237
|
+
* Retrieve the merged root CLI options bag (if set by passOptions()).
|
|
238
|
+
* Downstream-safe: no generics required.
|
|
193
239
|
*/
|
|
194
|
-
|
|
240
|
+
getOptions(): GetDotenvCliOptions | undefined;
|
|
241
|
+
/** Internal: set the merged root options bag for this run. */
|
|
242
|
+
_setOptionsBag(bag: GetDotenvCliOptions): void;
|
|
243
|
+
/** Convenience helper to create a namespaced subcommand. */
|
|
244
|
+
ns(name: string): Command;
|
|
195
245
|
/**
|
|
196
|
-
*
|
|
246
|
+
* Tag options added during the provided callback as 'app' for grouped help.
|
|
247
|
+
* Allows downstream apps to demarcate their root-level options.
|
|
197
248
|
*/
|
|
198
|
-
|
|
249
|
+
tagAppOptions<T>(fn: (root: Command) => T): T;
|
|
199
250
|
/**
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
* parser. Otherwise the user may provide a specific shell string (e.g.
|
|
204
|
-
* `/bin/bash`)
|
|
251
|
+
* Branding helper: set CLI name/description/version and optional help header.
|
|
252
|
+
* If version is omitted and importMetaUrl is provided, attempts to read the
|
|
253
|
+
* nearest package.json version (best-effort; non-fatal on failure).
|
|
205
254
|
*/
|
|
206
|
-
|
|
255
|
+
brand(args: {
|
|
256
|
+
name?: string;
|
|
257
|
+
description?: string;
|
|
258
|
+
version?: string;
|
|
259
|
+
importMetaUrl?: string;
|
|
260
|
+
helpHeader?: string;
|
|
261
|
+
}): Promise<this>;
|
|
207
262
|
/**
|
|
208
|
-
*
|
|
209
|
-
*
|
|
263
|
+
* Insert grouped plugin/app options between "Options" and "Commands" for
|
|
264
|
+
* hybrid ordering. Applies to root and any parent command.
|
|
210
265
|
*/
|
|
211
|
-
|
|
266
|
+
helpInformation(): string;
|
|
212
267
|
/**
|
|
213
|
-
*
|
|
214
|
-
* `varsDelimiterPattern` is not provided.
|
|
268
|
+
* Public: tag an Option with a display group for help (root/app/plugin:<id>).
|
|
215
269
|
*/
|
|
216
|
-
|
|
270
|
+
setOptionGroup(opt: Option, group: string): void;
|
|
217
271
|
/**
|
|
218
|
-
*
|
|
219
|
-
*
|
|
272
|
+
* Register a plugin for installation (parent level).
|
|
273
|
+
* Installation occurs on first resolveAndLoad() (or explicit install()).
|
|
220
274
|
*/
|
|
221
|
-
|
|
275
|
+
use(plugin: GetDotenvCliPlugin<TOptions>): this;
|
|
222
276
|
/**
|
|
223
|
-
*
|
|
224
|
-
*
|
|
277
|
+
* Install all registered plugins in parent → children (pre-order).
|
|
278
|
+
* Runs only once per CLI instance.
|
|
225
279
|
*/
|
|
226
|
-
|
|
280
|
+
install(): Promise<void>;
|
|
227
281
|
/**
|
|
228
|
-
*
|
|
229
|
-
* pairs. Supersedes `varsDelimiter`.
|
|
282
|
+
* Run afterResolve hooks for all plugins (parent → children).
|
|
230
283
|
*/
|
|
231
|
-
|
|
284
|
+
private _runAfterResolve;
|
|
232
285
|
}
|
|
233
286
|
|
|
234
287
|
/** src/cliHost/definePlugin.ts
|
|
@@ -247,134 +300,89 @@ interface GetDotenvCliOptions extends Omit<GetDotenvOptions, 'paths' | 'vars'> {
|
|
|
247
300
|
* Purpose: remove nominal class identity (private fields) from the plugin seam
|
|
248
301
|
* to avoid TS2379 under exactOptionalPropertyTypes in downstream consumers.
|
|
249
302
|
*/
|
|
250
|
-
|
|
251
|
-
ns
|
|
252
|
-
getCtx
|
|
253
|
-
resolveAndLoad
|
|
254
|
-
|
|
303
|
+
interface GetDotenvCliPublic<TOptions extends GetDotenvOptions = GetDotenvOptions> extends Command {
|
|
304
|
+
ns(name: string): Command;
|
|
305
|
+
getCtx(): GetDotenvCliCtx<TOptions> | undefined;
|
|
306
|
+
resolveAndLoad(customOptions?: Partial<TOptions>, opts?: {
|
|
307
|
+
runAfterResolve?: boolean;
|
|
308
|
+
}): Promise<GetDotenvCliCtx<TOptions>>;
|
|
309
|
+
setOptionGroup(opt: Option, group: string): void;
|
|
310
|
+
/**
|
|
311
|
+
* Create a dynamic option whose description is computed at help time
|
|
312
|
+
* from the resolved configuration.
|
|
313
|
+
*/
|
|
314
|
+
createDynamicOption(flags: string, desc: (cfg: ResolvedHelpConfig & {
|
|
315
|
+
plugins: Record<string, unknown>;
|
|
316
|
+
}) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option;
|
|
317
|
+
createDynamicOption<TValue = unknown>(flags: string, desc: (cfg: ResolvedHelpConfig & {
|
|
318
|
+
plugins: Record<string, unknown>;
|
|
319
|
+
}) => string, parser: (value: string, previous?: TValue) => TValue, defaultValue?: TValue): Option;
|
|
320
|
+
}
|
|
255
321
|
/** Public plugin contract used by the GetDotenv CLI host. */
|
|
256
|
-
interface GetDotenvCliPlugin {
|
|
322
|
+
interface GetDotenvCliPlugin<TOptions extends GetDotenvOptions = GetDotenvOptions> {
|
|
257
323
|
id?: string;
|
|
258
324
|
/**
|
|
259
325
|
* Setup phase: register commands and wiring on the provided CLI instance.
|
|
260
326
|
* Runs parent → children (pre-order).
|
|
261
327
|
*/
|
|
262
|
-
setup: (cli: GetDotenvCliPublic) => void | Promise<void>;
|
|
328
|
+
setup: (cli: GetDotenvCliPublic<TOptions>) => void | Promise<void>;
|
|
263
329
|
/**
|
|
264
330
|
* After the dotenv context is resolved, initialize any clients/secrets
|
|
265
331
|
* or attach per-plugin state under ctx.plugins (by convention).
|
|
266
332
|
* Runs parent → children (pre-order).
|
|
267
333
|
*/
|
|
268
|
-
afterResolve?: (cli: GetDotenvCliPublic
|
|
334
|
+
afterResolve?: (cli: GetDotenvCliPublic<TOptions>, ctx: GetDotenvCliCtx<TOptions>) => void | Promise<void>;
|
|
269
335
|
/**
|
|
270
|
-
*
|
|
271
|
-
*
|
|
336
|
+
* Zod schema for this plugin's config slice (from config.plugins[id]).
|
|
337
|
+
* Enforced object-like (ZodObject) to simplify code paths and inference.
|
|
272
338
|
*/
|
|
273
|
-
configSchema?:
|
|
339
|
+
configSchema?: ZodObject;
|
|
274
340
|
/**
|
|
275
341
|
* Compositional children. Installed after the parent per pre-order.
|
|
276
342
|
*/
|
|
277
|
-
children: GetDotenvCliPlugin[];
|
|
343
|
+
children: GetDotenvCliPlugin<TOptions>[];
|
|
278
344
|
/**
|
|
279
345
|
* Compose a child plugin. Returns the parent to enable chaining.
|
|
280
346
|
*/
|
|
281
|
-
use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin
|
|
347
|
+
use: (child: GetDotenvCliPlugin<TOptions>) => GetDotenvCliPlugin<TOptions>;
|
|
282
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* Compile-time helper type: the plugin object returned by definePlugin always
|
|
351
|
+
* includes the instance-bound helpers as required members. Keeping the public
|
|
352
|
+
* interface optional preserves compatibility for ad-hoc/test plugins, while
|
|
353
|
+
* return types from definePlugin provide stronger DX for shipped/typed plugins.
|
|
354
|
+
*/
|
|
355
|
+
type PluginWithInstanceHelpers<TOptions extends GetDotenvOptions = GetDotenvOptions, TConfig = unknown> = GetDotenvCliPlugin<TOptions> & {
|
|
356
|
+
readConfig<TCfg = TConfig>(cli: GetDotenvCliPublic<TOptions>): Readonly<TCfg>;
|
|
357
|
+
createPluginDynamicOption<TCfg = TConfig>(cli: GetDotenvCliPublic<TOptions>, flags: string, desc: (cfg: ResolvedHelpConfig & {
|
|
358
|
+
plugins: Record<string, unknown>;
|
|
359
|
+
}, pluginCfg: Readonly<TCfg>) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option;
|
|
360
|
+
};
|
|
283
361
|
/**
|
|
284
362
|
* Public spec type for defining a plugin with optional children.
|
|
285
363
|
* Exported to ensure TypeDoc links and navigation resolve correctly.
|
|
286
364
|
*/
|
|
287
|
-
type DefineSpec = Omit<GetDotenvCliPlugin
|
|
288
|
-
children?: GetDotenvCliPlugin[];
|
|
365
|
+
type DefineSpec<TOptions extends GetDotenvOptions = GetDotenvOptions> = Omit<GetDotenvCliPlugin<TOptions>, 'children' | 'use'> & {
|
|
366
|
+
children?: GetDotenvCliPlugin<TOptions>[];
|
|
289
367
|
};
|
|
290
368
|
/**
|
|
291
369
|
* Define a GetDotenv CLI plugin with compositional helpers.
|
|
292
370
|
*
|
|
293
371
|
* @example
|
|
294
|
-
* const parent = definePlugin(
|
|
372
|
+
* const parent = definePlugin({ id: 'p', setup(cli) { /* omitted *\/ } })
|
|
295
373
|
* .use(childA)
|
|
296
374
|
* .use(childB);
|
|
297
375
|
*/
|
|
298
|
-
declare
|
|
376
|
+
declare function definePlugin<TOptions extends GetDotenvOptions, Schema extends ZodObject>(spec: Omit<DefineSpec<TOptions>, 'configSchema'> & {
|
|
377
|
+
configSchema: Schema;
|
|
378
|
+
}): PluginWithInstanceHelpers<TOptions, z.output<Schema>>;
|
|
379
|
+
declare function definePlugin<TOptions extends GetDotenvOptions>(spec: DefineSpec<TOptions>): PluginWithInstanceHelpers<TOptions, {}>;
|
|
299
380
|
|
|
300
|
-
/** * Per-invocation context shared with plugins and actions. */
|
|
301
|
-
type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
|
|
302
|
-
optionsResolved: TOptions;
|
|
303
|
-
dotenv: ProcessEnv;
|
|
304
|
-
plugins?: Record<string, unknown>;
|
|
305
|
-
pluginConfigs?: Record<string, unknown>;
|
|
306
|
-
};
|
|
307
|
-
declare const HELP_HEADER_SYMBOL: unique symbol;
|
|
308
381
|
/**
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
* Responsibilities:
|
|
312
|
-
* - Resolve options strictly and compute dotenv context (resolveAndLoad).
|
|
313
|
-
* - Expose a stable accessor for the current context (getCtx).
|
|
314
|
-
* - Provide a namespacing helper (ns).
|
|
315
|
-
* - Support composable plugins with parent → children install and afterResolve.
|
|
316
|
-
*
|
|
317
|
-
* NOTE: This host is additive and does not alter the legacy CLI.
|
|
382
|
+
* Infer the compile-time plugin config type from a plugin instance created by definePlugin.
|
|
383
|
+
* Returns a deeply readonly view to discourage mutation at call sites.
|
|
318
384
|
*/
|
|
319
|
-
|
|
320
|
-
#private;
|
|
321
|
-
/** Registered top-level plugins (composition happens via .use()) */
|
|
322
|
-
private _plugins;
|
|
323
|
-
/** One-time installation guard */
|
|
324
|
-
private _installed;
|
|
325
|
-
/** Optional header line to prepend in help output */
|
|
326
|
-
private [HELP_HEADER_SYMBOL];
|
|
327
|
-
constructor(alias?: string);
|
|
328
|
-
/**
|
|
329
|
-
* Resolve options (strict) and compute dotenv context. * Stores the context on the instance under a symbol.
|
|
330
|
-
*/
|
|
331
|
-
resolveAndLoad(customOptions?: Partial<TOptions>): Promise<GetDotenvCliCtx<TOptions>>;
|
|
332
|
-
/**
|
|
333
|
-
* Retrieve the current invocation context (if any).
|
|
334
|
-
*/
|
|
335
|
-
getCtx(): GetDotenvCliCtx<TOptions> | undefined;
|
|
336
|
-
/**
|
|
337
|
-
* Retrieve the merged root CLI options bag (if set by passOptions()).
|
|
338
|
-
* Downstream-safe: no generics required.
|
|
339
|
-
*/
|
|
340
|
-
getOptions(): GetDotenvCliOptions | undefined;
|
|
341
|
-
/** Internal: set the merged root options bag for this run. */
|
|
342
|
-
_setOptionsBag(bag: GetDotenvCliOptions): void;
|
|
343
|
-
/** * Convenience helper to create a namespaced subcommand.
|
|
344
|
-
*/
|
|
345
|
-
ns(name: string): Command;
|
|
346
|
-
/**
|
|
347
|
-
* Tag options added during the provided callback as 'app' for grouped help.
|
|
348
|
-
* Allows downstream apps to demarcate their root-level options.
|
|
349
|
-
*/
|
|
350
|
-
tagAppOptions<T>(fn: (root: Command) => T): T;
|
|
351
|
-
/**
|
|
352
|
-
* Branding helper: set CLI name/description/version and optional help header.
|
|
353
|
-
* If version is omitted and importMetaUrl is provided, attempts to read the
|
|
354
|
-
* nearest package.json version (best-effort; non-fatal on failure).
|
|
355
|
-
*/
|
|
356
|
-
brand(args: {
|
|
357
|
-
name?: string;
|
|
358
|
-
description?: string;
|
|
359
|
-
version?: string;
|
|
360
|
-
importMetaUrl?: string;
|
|
361
|
-
helpHeader?: string;
|
|
362
|
-
}): Promise<this>;
|
|
363
|
-
/**
|
|
364
|
-
* Register a plugin for installation (parent level).
|
|
365
|
-
* Installation occurs on first resolveAndLoad() (or explicit install()).
|
|
366
|
-
*/
|
|
367
|
-
use(plugin: GetDotenvCliPlugin): this;
|
|
368
|
-
/**
|
|
369
|
-
* Install all registered plugins in parent → children (pre-order).
|
|
370
|
-
* Runs only once per CLI instance.
|
|
371
|
-
*/
|
|
372
|
-
install(): Promise<void>;
|
|
373
|
-
/**
|
|
374
|
-
* Run afterResolve hooks for all plugins (parent → children).
|
|
375
|
-
*/
|
|
376
|
-
private _runAfterResolve;
|
|
377
|
-
}
|
|
385
|
+
type InferPluginConfig<P> = P extends PluginWithInstanceHelpers<GetDotenvOptions, infer C> ? Readonly<C> : never;
|
|
378
386
|
|
|
379
387
|
/**
|
|
380
388
|
* GetDotenvCli with root helpers as real class methods.
|
|
@@ -387,9 +395,7 @@ declare class GetDotenvCli extends GetDotenvCli$1 {
|
|
|
387
395
|
* Attach legacy root flags to this CLI instance. Defaults come from
|
|
388
396
|
* baseRootOptionDefaults when none are provided.
|
|
389
397
|
*/
|
|
390
|
-
attachRootOptions(defaults?: Partial<RootOptionsShape
|
|
391
|
-
includeCommandOption?: boolean;
|
|
392
|
-
}): this;
|
|
398
|
+
attachRootOptions(defaults?: Partial<RootOptionsShape>): this;
|
|
393
399
|
/**
|
|
394
400
|
* Install preSubcommand/preAction hooks that:
|
|
395
401
|
* - Merge options (parent round-trip + current invocation) using resolveCliOptions.
|
|
@@ -406,4 +412,4 @@ declare class GetDotenvCli extends GetDotenvCli$1 {
|
|
|
406
412
|
declare const readMergedOptions: (cmd: Command) => GetDotenvCliOptions | undefined;
|
|
407
413
|
|
|
408
414
|
export { GetDotenvCli, definePlugin, readMergedOptions };
|
|
409
|
-
export type { DefineSpec, GetDotenvCliCtx, GetDotenvCliOptions, GetDotenvCliPlugin, GetDotenvCliPublic, ScriptsTable };
|
|
415
|
+
export type { DefineSpec, GetDotenvCliCtx, GetDotenvCliOptions, GetDotenvCliPlugin, GetDotenvCliPublic, InferPluginConfig, PluginWithInstanceHelpers, ScriptsTable };
|