@karmaniverous/get-dotenv 6.0.0-0 → 6.0.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 +86 -334
- package/dist/cli.d.ts +569 -0
- package/dist/cli.mjs +18788 -0
- package/dist/cliHost.d.ts +548 -253
- package/dist/cliHost.mjs +1990 -1458
- package/dist/config.d.ts +192 -14
- package/dist/config.mjs +256 -81
- package/dist/env-overlay.d.ts +226 -18
- package/dist/env-overlay.mjs +181 -22
- package/dist/getdotenv.cli.mjs +18166 -3437
- package/dist/index.d.ts +729 -136
- package/dist/index.mjs +18207 -3457
- package/dist/plugins-aws.d.ts +289 -104
- package/dist/plugins-aws.mjs +2462 -350
- package/dist/plugins-batch.d.ts +355 -105
- package/dist/plugins-batch.mjs +2595 -420
- package/dist/plugins-cmd.d.ts +287 -118
- package/dist/plugins-cmd.mjs +2661 -839
- package/dist/plugins-init.d.ts +272 -100
- package/dist/plugins-init.mjs +2152 -37
- package/dist/plugins.d.ts +323 -140
- package/dist/plugins.mjs +18006 -2025
- package/dist/templates/cli/index.ts +26 -0
- package/dist/templates/cli/plugins/hello.ts +43 -0
- package/dist/templates/config/js/getdotenv.config.js +20 -0
- package/dist/templates/config/json/local/getdotenv.config.local.json +7 -0
- package/dist/templates/config/json/public/getdotenv.config.json +9 -0
- package/dist/templates/config/public/getdotenv.config.json +8 -0
- package/dist/templates/config/ts/getdotenv.config.ts +28 -0
- package/dist/templates/config/yaml/local/getdotenv.config.local.yaml +7 -0
- package/dist/templates/config/yaml/public/getdotenv.config.yaml +7 -0
- package/dist/templates/getdotenv.config.js +20 -0
- package/dist/templates/getdotenv.config.json +9 -0
- package/dist/templates/getdotenv.config.local.json +7 -0
- package/dist/templates/getdotenv.config.local.yaml +7 -0
- package/dist/templates/getdotenv.config.ts +28 -0
- package/dist/templates/getdotenv.config.yaml +7 -0
- package/dist/templates/hello.ts +43 -0
- package/dist/templates/index.ts +26 -0
- package/dist/templates/js/getdotenv.config.js +20 -0
- package/dist/templates/json/local/getdotenv.config.local.json +7 -0
- package/dist/templates/json/public/getdotenv.config.json +9 -0
- package/dist/templates/local/getdotenv.config.local.json +7 -0
- package/dist/templates/local/getdotenv.config.local.yaml +7 -0
- package/dist/templates/plugins/hello.ts +43 -0
- package/dist/templates/public/getdotenv.config.json +9 -0
- package/dist/templates/public/getdotenv.config.yaml +7 -0
- package/dist/templates/ts/getdotenv.config.ts +28 -0
- package/dist/templates/yaml/local/getdotenv.config.local.yaml +7 -0
- package/dist/templates/yaml/public/getdotenv.config.yaml +7 -0
- package/getdotenv.config.json +1 -19
- package/package.json +52 -89
- package/templates/cli/index.ts +26 -0
- package/templates/cli/plugins/hello.ts +43 -0
- package/templates/config/js/getdotenv.config.js +9 -4
- package/templates/config/json/public/getdotenv.config.json +0 -3
- package/templates/config/public/getdotenv.config.json +0 -5
- package/templates/config/ts/getdotenv.config.ts +17 -5
- package/templates/config/yaml/public/getdotenv.config.yaml +0 -3
- package/dist/cliHost.cjs +0 -2078
- package/dist/cliHost.d.cts +0 -451
- package/dist/cliHost.d.mts +0 -451
- 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 -4077
- package/dist/index.d.cts +0 -318
- package/dist/index.d.mts +0 -318
- package/dist/plugins-aws.cjs +0 -666
- package/dist/plugins-aws.d.cts +0 -158
- package/dist/plugins-aws.d.mts +0 -158
- package/dist/plugins-batch.cjs +0 -658
- package/dist/plugins-batch.d.cts +0 -181
- package/dist/plugins-batch.d.mts +0 -181
- package/dist/plugins-cmd.cjs +0 -1112
- package/dist/plugins-cmd.d.cts +0 -178
- package/dist/plugins-cmd.d.mts +0 -178
- package/dist/plugins-demo.cjs +0 -352
- package/dist/plugins-demo.d.cts +0 -158
- package/dist/plugins-demo.d.mts +0 -158
- package/dist/plugins-demo.d.ts +0 -158
- package/dist/plugins-demo.mjs +0 -350
- 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 -2327
- package/dist/plugins.d.cts +0 -211
- package/dist/plugins.d.mts +0 -211
- package/templates/cli/ts/index.ts +0 -9
- package/templates/cli/ts/plugins/hello.ts +0 -17
package/dist/cliHost.d.ts
CHANGED
|
@@ -1,312 +1,510 @@
|
|
|
1
|
-
import { Command, Option } from 'commander';
|
|
2
|
-
import {
|
|
1
|
+
import { OptionValues, Command, InferCommandArguments, Option, CommandUnknownOpts } from '@commander-js/extra-typings';
|
|
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.
|
|
6
7
|
* Keep keys optional to respect exactOptionalPropertyTypes semantics.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
7
10
|
*/
|
|
8
|
-
|
|
11
|
+
interface RootOptionsShape {
|
|
12
|
+
/** Target environment (dotenv-expanded). */
|
|
9
13
|
env?: string;
|
|
14
|
+
/** Explicit variable overrides (dotenv-expanded). */
|
|
10
15
|
vars?: string;
|
|
16
|
+
/** Command to execute (dotenv-expanded). */
|
|
11
17
|
command?: string;
|
|
18
|
+
/** Output path for the consolidated environment file (dotenv-expanded). */
|
|
12
19
|
outputPath?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Shell execution strategy.
|
|
22
|
+
* - `true`: use default OS shell.
|
|
23
|
+
* - `false`: use plain execution (no shell).
|
|
24
|
+
* - string: use specific shell path.
|
|
25
|
+
*/
|
|
13
26
|
shell?: string | boolean;
|
|
27
|
+
/** Whether to load variables into `process.env`. */
|
|
14
28
|
loadProcess?: boolean;
|
|
29
|
+
/** Exclude all variables from loading. */
|
|
15
30
|
excludeAll?: boolean;
|
|
31
|
+
/** Exclude dynamic variables. */
|
|
16
32
|
excludeDynamic?: boolean;
|
|
33
|
+
/** Exclude environment-specific variables. */
|
|
17
34
|
excludeEnv?: boolean;
|
|
35
|
+
/** Exclude global variables. */
|
|
18
36
|
excludeGlobal?: boolean;
|
|
37
|
+
/** Exclude private variables. */
|
|
19
38
|
excludePrivate?: boolean;
|
|
39
|
+
/** Exclude public variables. */
|
|
20
40
|
excludePublic?: boolean;
|
|
41
|
+
/** Enable console logging of loaded variables. */
|
|
21
42
|
log?: boolean;
|
|
43
|
+
/** Enable debug logging to stderr. */
|
|
22
44
|
debug?: boolean;
|
|
45
|
+
/** Capture child process stdio (useful for tests/CI). */
|
|
23
46
|
capture?: boolean;
|
|
47
|
+
/** Fail on validation errors (schema/requiredKeys). */
|
|
24
48
|
strict?: boolean;
|
|
49
|
+
/** Enable presentation-time redaction of secret-like keys. */
|
|
25
50
|
redact?: boolean;
|
|
51
|
+
/** Enable entropy warnings for high-entropy values. */
|
|
26
52
|
warnEntropy?: boolean;
|
|
53
|
+
/** Entropy threshold (bits/char) for warnings (default 3.8). */
|
|
27
54
|
entropyThreshold?: number;
|
|
55
|
+
/** Minimum string length to check for entropy (default 16). */
|
|
28
56
|
entropyMinLength?: number;
|
|
29
|
-
|
|
57
|
+
/** Regex patterns for keys to exclude from entropy checks. */
|
|
58
|
+
entropyWhitelist?: ReadonlyArray<string>;
|
|
59
|
+
/** Additional regex patterns for keys to redact. */
|
|
30
60
|
redactPatterns?: string[];
|
|
61
|
+
/** Default target environment when not specified. */
|
|
31
62
|
defaultEnv?: string;
|
|
63
|
+
/** Token indicating a dotenv file (default: ".env"). */
|
|
32
64
|
dotenvToken?: string;
|
|
65
|
+
/** Path to dynamic variables module (default: undefined). */
|
|
33
66
|
dynamicPath?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Emit diagnostics for child env composition.
|
|
69
|
+
* - `true`: trace all keys.
|
|
70
|
+
* - `string[]`: trace selected keys.
|
|
71
|
+
*/
|
|
34
72
|
trace?: boolean | string[];
|
|
73
|
+
/** Paths to search for dotenv files (space-delimited string or array). */
|
|
35
74
|
paths?: string;
|
|
75
|
+
/** Delimiter for paths string (default: space). */
|
|
36
76
|
pathsDelimiter?: string;
|
|
77
|
+
/** Regex pattern for paths delimiter. */
|
|
37
78
|
pathsDelimiterPattern?: string;
|
|
79
|
+
/** Token indicating private variables (default: "local"). */
|
|
38
80
|
privateToken?: string;
|
|
81
|
+
/** Delimiter for vars string (default: space). */
|
|
39
82
|
varsDelimiter?: string;
|
|
83
|
+
/** Regex pattern for vars delimiter. */
|
|
40
84
|
varsDelimiterPattern?: string;
|
|
85
|
+
/** Assignment operator for vars (default: "="). */
|
|
41
86
|
varsAssignor?: string;
|
|
87
|
+
/** Regex pattern for vars assignment operator. */
|
|
42
88
|
varsAssignorPattern?: string;
|
|
89
|
+
/** Table of named scripts for execution. */
|
|
43
90
|
scripts?: ScriptsTable;
|
|
44
|
-
}
|
|
91
|
+
}
|
|
45
92
|
/**
|
|
46
|
-
*
|
|
93
|
+
* Definition for a single script entry.
|
|
47
94
|
*/
|
|
48
|
-
|
|
95
|
+
interface ScriptDef<TShell extends string | boolean = string | boolean> {
|
|
96
|
+
/** The command string to execute. */
|
|
49
97
|
cmd: string;
|
|
50
|
-
|
|
51
|
-
|
|
98
|
+
/** Shell override for this script. */
|
|
99
|
+
shell?: TShell | undefined;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Scripts table shape.
|
|
103
|
+
*/
|
|
104
|
+
type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<string, string | ScriptDef<TShell>>;
|
|
105
|
+
/**
|
|
106
|
+
* Identity helper to define a scripts table while preserving a concrete TShell
|
|
107
|
+
* type parameter in downstream inference.
|
|
108
|
+
*/
|
|
109
|
+
declare const defineScripts: <TShell extends string | boolean>() => <T extends ScriptsTable<TShell>>(t: T) => T;
|
|
110
|
+
/**
|
|
111
|
+
* Per-invocation context shared with plugins and actions.
|
|
112
|
+
*
|
|
113
|
+
* @public
|
|
114
|
+
*/
|
|
115
|
+
interface GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> {
|
|
116
|
+
optionsResolved: TOptions;
|
|
117
|
+
dotenv: ProcessEnv;
|
|
118
|
+
plugins?: Record<string, unknown>;
|
|
119
|
+
pluginConfigs?: Record<string, unknown>;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Options for branding the CLI.
|
|
123
|
+
*
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
interface BrandOptions {
|
|
127
|
+
/** CLI name. */
|
|
128
|
+
name?: string;
|
|
129
|
+
/** CLI description. */
|
|
130
|
+
description?: string;
|
|
131
|
+
/** CLI version string. */
|
|
132
|
+
version?: string;
|
|
133
|
+
/** Import URL for resolving package version. */
|
|
134
|
+
importMetaUrl?: string;
|
|
135
|
+
/** Custom help header text. */
|
|
136
|
+
helpHeader?: string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Resolved CLI options schema.
|
|
141
|
+
* For the current step this mirrors the RAW schema; later stages may further
|
|
142
|
+
* narrow types post-resolution in the host pipeline.
|
|
143
|
+
*/
|
|
144
|
+
declare const getDotenvCliOptionsSchemaResolved: z.ZodObject<{
|
|
145
|
+
defaultEnv: z.ZodOptional<z.ZodString>;
|
|
146
|
+
dotenvToken: z.ZodOptional<z.ZodString>;
|
|
147
|
+
dynamicPath: z.ZodOptional<z.ZodString>;
|
|
148
|
+
dynamic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
149
|
+
env: z.ZodOptional<z.ZodString>;
|
|
150
|
+
excludeDynamic: z.ZodOptional<z.ZodBoolean>;
|
|
151
|
+
excludeEnv: z.ZodOptional<z.ZodBoolean>;
|
|
152
|
+
excludeGlobal: z.ZodOptional<z.ZodBoolean>;
|
|
153
|
+
excludePrivate: z.ZodOptional<z.ZodBoolean>;
|
|
154
|
+
excludePublic: z.ZodOptional<z.ZodBoolean>;
|
|
155
|
+
loadProcess: z.ZodOptional<z.ZodBoolean>;
|
|
156
|
+
log: z.ZodOptional<z.ZodBoolean>;
|
|
157
|
+
logger: z.ZodDefault<z.ZodUnknown>;
|
|
158
|
+
outputPath: z.ZodOptional<z.ZodString>;
|
|
159
|
+
privateToken: z.ZodOptional<z.ZodString>;
|
|
160
|
+
debug: z.ZodOptional<z.ZodBoolean>;
|
|
161
|
+
strict: z.ZodOptional<z.ZodBoolean>;
|
|
162
|
+
capture: z.ZodOptional<z.ZodBoolean>;
|
|
163
|
+
trace: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
|
|
164
|
+
redact: z.ZodOptional<z.ZodBoolean>;
|
|
165
|
+
warnEntropy: z.ZodOptional<z.ZodBoolean>;
|
|
166
|
+
entropyThreshold: z.ZodOptional<z.ZodNumber>;
|
|
167
|
+
entropyMinLength: z.ZodOptional<z.ZodNumber>;
|
|
168
|
+
entropyWhitelist: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
169
|
+
redactPatterns: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
170
|
+
paths: z.ZodOptional<z.ZodString>;
|
|
171
|
+
pathsDelimiter: z.ZodOptional<z.ZodString>;
|
|
172
|
+
pathsDelimiterPattern: z.ZodOptional<z.ZodString>;
|
|
173
|
+
scripts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
174
|
+
shell: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>;
|
|
175
|
+
vars: z.ZodOptional<z.ZodString>;
|
|
176
|
+
varsAssignor: z.ZodOptional<z.ZodString>;
|
|
177
|
+
varsAssignorPattern: z.ZodOptional<z.ZodString>;
|
|
178
|
+
varsDelimiter: z.ZodOptional<z.ZodString>;
|
|
179
|
+
varsDelimiterPattern: z.ZodOptional<z.ZodString>;
|
|
180
|
+
}, z.core.$strip>;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Resolved programmatic options schema (post-inheritance).
|
|
184
|
+
* For now, this mirrors the RAW schema; future stages may materialize defaults
|
|
185
|
+
* and narrow shapes as resolution is wired into the host.
|
|
186
|
+
*/
|
|
187
|
+
declare const getDotenvOptionsSchemaResolved: z.ZodObject<{
|
|
188
|
+
defaultEnv: z.ZodOptional<z.ZodString>;
|
|
189
|
+
dotenvToken: z.ZodOptional<z.ZodString>;
|
|
190
|
+
dynamicPath: z.ZodOptional<z.ZodString>;
|
|
191
|
+
dynamic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
192
|
+
env: z.ZodOptional<z.ZodString>;
|
|
193
|
+
excludeDynamic: z.ZodOptional<z.ZodBoolean>;
|
|
194
|
+
excludeEnv: z.ZodOptional<z.ZodBoolean>;
|
|
195
|
+
excludeGlobal: z.ZodOptional<z.ZodBoolean>;
|
|
196
|
+
excludePrivate: z.ZodOptional<z.ZodBoolean>;
|
|
197
|
+
excludePublic: z.ZodOptional<z.ZodBoolean>;
|
|
198
|
+
loadProcess: z.ZodOptional<z.ZodBoolean>;
|
|
199
|
+
log: z.ZodOptional<z.ZodBoolean>;
|
|
200
|
+
logger: z.ZodDefault<z.ZodUnknown>;
|
|
201
|
+
outputPath: z.ZodOptional<z.ZodString>;
|
|
202
|
+
paths: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
203
|
+
privateToken: z.ZodOptional<z.ZodString>;
|
|
204
|
+
vars: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodString>>>;
|
|
205
|
+
}, z.core.$strip>;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Canonical programmatic options and helpers for get-dotenv.
|
|
209
|
+
*
|
|
210
|
+
* Requirements addressed:
|
|
211
|
+
* - GetDotenvOptions derives from the Zod schema output (single source of truth).
|
|
212
|
+
* - Removed deprecated/compat flags from the public shape (e.g., useConfigLoader).
|
|
213
|
+
* - Provide Vars-aware defineDynamic and a typed config builder defineGetDotenvConfig\<Vars, Env\>().
|
|
214
|
+
* - Preserve existing behavior for defaults resolution and compat converters.
|
|
215
|
+
*/
|
|
52
216
|
|
|
53
217
|
/**
|
|
54
218
|
* A minimal representation of an environment key/value mapping.
|
|
55
|
-
* Values may be `undefined` to represent "unset".
|
|
219
|
+
* Values may be `undefined` to represent "unset".
|
|
220
|
+
*/
|
|
221
|
+
type ProcessEnv = Record<string, string | undefined>;
|
|
56
222
|
/**
|
|
57
223
|
* Dynamic variable function signature. Receives the current expanded variables
|
|
58
224
|
* and the selected environment (if any), and returns either a string to set
|
|
59
225
|
* or `undefined` to unset/skip the variable.
|
|
60
226
|
*/
|
|
61
227
|
type GetDotenvDynamicFunction = (vars: ProcessEnv, env: string | undefined) => string | undefined;
|
|
228
|
+
/**
|
|
229
|
+
* A map of dynamic variable definitions.
|
|
230
|
+
* Keys are variable names; values are either literal strings or functions.
|
|
231
|
+
*/
|
|
62
232
|
type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
|
|
233
|
+
/**
|
|
234
|
+
* Logger interface compatible with `console` or a subset thereof.
|
|
235
|
+
*/
|
|
63
236
|
type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
|
|
64
237
|
/**
|
|
65
|
-
*
|
|
238
|
+
* Canonical programmatic options type (schema-derived).
|
|
239
|
+
* This type is the single source of truth for programmatic options.
|
|
66
240
|
*/
|
|
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;
|
|
241
|
+
type GetDotenvOptions = z.output<typeof getDotenvOptionsSchemaResolved> & {
|
|
76
242
|
/**
|
|
77
|
-
*
|
|
243
|
+
* Compile-time overlay: narrowed logger for DX (schema stores unknown).
|
|
78
244
|
*/
|
|
79
|
-
|
|
245
|
+
logger: Logger;
|
|
80
246
|
/**
|
|
81
|
-
*
|
|
82
|
-
* over {@link GetDotenvOptions.dynamicPath}.
|
|
247
|
+
* Compile-time overlay: narrowed dynamic map for DX (schema stores unknown).
|
|
83
248
|
*/
|
|
84
249
|
dynamic?: GetDotenvDynamic;
|
|
85
|
-
|
|
86
|
-
* target environment
|
|
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)
|
|
119
|
-
*/
|
|
120
|
-
logger?: Logger;
|
|
121
|
-
/**
|
|
122
|
-
* if populated, writes consolidated dotenv file to this path (follows dotenvExpand rules)
|
|
123
|
-
*/
|
|
124
|
-
outputPath?: string;
|
|
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
|
-
}
|
|
250
|
+
};
|
|
146
251
|
|
|
147
|
-
type Scripts = Record<string, string | {
|
|
148
|
-
cmd: string;
|
|
149
|
-
shell?: string | boolean;
|
|
150
|
-
}>;
|
|
151
252
|
/**
|
|
152
|
-
*
|
|
253
|
+
* Unify Scripts via the generic ScriptsTable<TShell> so shell types propagate.
|
|
153
254
|
*/
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
*/
|
|
163
|
-
strict?: boolean;
|
|
164
|
-
/**
|
|
165
|
-
* Redaction (presentation): mask secret-like values in logs/trace.
|
|
166
|
-
*/
|
|
167
|
-
redact?: boolean;
|
|
168
|
-
/**
|
|
169
|
-
* Entropy warnings (presentation): emit once-per-key warnings for high-entropy values.
|
|
170
|
-
*/
|
|
171
|
-
warnEntropy?: boolean;
|
|
172
|
-
entropyThreshold?: number;
|
|
173
|
-
entropyMinLength?: number;
|
|
174
|
-
entropyWhitelist?: string[];
|
|
175
|
-
redactPatterns?: string[];
|
|
255
|
+
type Scripts = ScriptsTable;
|
|
256
|
+
/**
|
|
257
|
+
* Canonical CLI options type derived from the Zod schema output.
|
|
258
|
+
* Includes CLI-only flags (debug/strict/capture/trace/redaction/entropy),
|
|
259
|
+
* stringly paths/vars, and inherited programmatic fields (minus normalized
|
|
260
|
+
* shapes that are handled by resolution).
|
|
261
|
+
*/
|
|
262
|
+
type GetDotenvCliOptions = z.output<typeof getDotenvCliOptionsSchemaResolved> & {
|
|
176
263
|
/**
|
|
177
|
-
*
|
|
178
|
-
* Useful for tests/CI. Default behavior is streaming via stdio: 'inherit'.
|
|
264
|
+
* Compile-only overlay for DX: logger narrowed from unknown.
|
|
179
265
|
*/
|
|
180
|
-
|
|
266
|
+
logger: Logger;
|
|
181
267
|
/**
|
|
182
|
-
*
|
|
268
|
+
* Compile-only overlay for DX: scripts narrowed from Record\<string, unknown\>.
|
|
183
269
|
*/
|
|
184
|
-
|
|
270
|
+
scripts?: Scripts;
|
|
271
|
+
};
|
|
272
|
+
/**
|
|
273
|
+
* Base CLI options derived from the shared root option defaults.
|
|
274
|
+
* Used for type-safe initialization of CLI options bags.
|
|
275
|
+
*/
|
|
276
|
+
declare const baseGetDotenvCliOptions: Partial<GetDotenvCliOptions>;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Configuration context used for generating dynamic help descriptions.
|
|
280
|
+
* Contains merged CLI options and plugin configuration slices.
|
|
281
|
+
*
|
|
282
|
+
* @public
|
|
283
|
+
*/
|
|
284
|
+
type ResolvedHelpConfig = Partial<GetDotenvCliOptions> & {
|
|
185
285
|
/**
|
|
186
|
-
*
|
|
187
|
-
* `
|
|
286
|
+
* Per‑plugin configuration slices keyed by realized mount path
|
|
287
|
+
* (e.g., `"aws"` or `"aws/whoami"`), used for dynamic help text.
|
|
188
288
|
*/
|
|
189
|
-
|
|
289
|
+
plugins: Record<string, unknown>;
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* Build a help-time configuration bag for dynamic option descriptions.
|
|
293
|
+
* Centralizes construction and reduces inline casts at call sites.
|
|
294
|
+
*/
|
|
295
|
+
declare const toHelpConfig: (merged: Partial<GetDotenvCliOptions> | Partial<RootOptionsShape>, plugins: Record<string, unknown> | undefined) => ResolvedHelpConfig;
|
|
296
|
+
|
|
297
|
+
/** src/cliHost/definePlugin/contracts.ts
|
|
298
|
+
* Public contracts for plugin authoring (types only).
|
|
299
|
+
* - No runtime logic or state.
|
|
300
|
+
* - Safe to import broadly without introducing cycles.
|
|
301
|
+
*/
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Options for resolving and loading the configuration.
|
|
305
|
+
*
|
|
306
|
+
* @public
|
|
307
|
+
*/
|
|
308
|
+
interface ResolveAndLoadOptions {
|
|
190
309
|
/**
|
|
191
|
-
*
|
|
192
|
-
*
|
|
310
|
+
* When false, skips running plugin afterResolve hooks.
|
|
311
|
+
* Useful for top-level help rendering to avoid long-running side-effects
|
|
312
|
+
* while still evaluating dynamic help text.
|
|
313
|
+
*
|
|
314
|
+
* @default true
|
|
193
315
|
*/
|
|
194
|
-
|
|
316
|
+
runAfterResolve?: boolean;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Structural public interface for the host exposed to plugins.
|
|
320
|
+
* - Extends Commander.Command so plugins can attach options/commands/hooks.
|
|
321
|
+
* - Adds host-specific helpers used by built-in plugins.
|
|
322
|
+
*
|
|
323
|
+
* Purpose: remove nominal class identity (private fields) from the plugin seam
|
|
324
|
+
* to avoid TS2379 under exactOptionalPropertyTypes in downstream consumers.
|
|
325
|
+
*/
|
|
326
|
+
interface GetDotenvCliPublic<TOptions extends GetDotenvOptions = GetDotenvOptions, TArgs extends unknown[] = [], TOpts extends OptionValues = {}, TGlobal extends OptionValues = {}> extends Command<TArgs, TOpts, TGlobal> {
|
|
327
|
+
/**
|
|
328
|
+
* Create a namespaced child command with argument inference.
|
|
329
|
+
* Mirrors Commander generics so downstream chaining remains fully typed.
|
|
330
|
+
*/
|
|
331
|
+
ns<Usage extends string>(name: Usage): GetDotenvCliPublic<TOptions, [
|
|
332
|
+
...TArgs,
|
|
333
|
+
...InferCommandArguments<Usage>
|
|
334
|
+
], {}, TOpts & TGlobal>;
|
|
335
|
+
/** Return the current context; throws if not yet resolved. */
|
|
336
|
+
getCtx(): GetDotenvCliCtx<TOptions>;
|
|
337
|
+
/** Check whether a context has been resolved (non-throwing). */
|
|
338
|
+
hasCtx(): boolean;
|
|
339
|
+
resolveAndLoad(customOptions?: Partial<TOptions>, opts?: ResolveAndLoadOptions): Promise<GetDotenvCliCtx<TOptions>>;
|
|
340
|
+
setOptionGroup(opt: Option, group: string): void;
|
|
341
|
+
/**
|
|
342
|
+
* Create a dynamic option whose description is computed at help time
|
|
343
|
+
* from the resolved configuration.
|
|
344
|
+
*/
|
|
345
|
+
createDynamicOption<Usage extends string>(flags: Usage, desc: (cfg: ResolvedHelpConfig) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option<Usage>;
|
|
346
|
+
createDynamicOption<Usage extends string, TValue = unknown>(flags: Usage, desc: (cfg: ResolvedHelpConfig) => string, parser: (value: string, previous?: TValue) => TValue, defaultValue?: TValue): Option<Usage>;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Optional overrides for plugin composition.
|
|
350
|
+
*
|
|
351
|
+
* @public
|
|
352
|
+
*/
|
|
353
|
+
interface PluginNamespaceOverride {
|
|
195
354
|
/**
|
|
196
|
-
*
|
|
355
|
+
* Override the default namespace for this plugin instance.
|
|
197
356
|
*/
|
|
198
|
-
|
|
357
|
+
ns?: string;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* An entry in the plugin children array.
|
|
361
|
+
*
|
|
362
|
+
* @public
|
|
363
|
+
*/
|
|
364
|
+
interface PluginChildEntry<TOptions extends GetDotenvOptions = GetDotenvOptions, TArgs extends unknown[] = [], TOpts extends OptionValues = {}, TGlobal extends OptionValues = {}> {
|
|
365
|
+
/** The child plugin instance to mount under this parent. */
|
|
366
|
+
plugin: GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal>;
|
|
199
367
|
/**
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
* execa parser. If `true`, commands are executed using the default OS shell
|
|
203
|
-
* parser. Otherwise the user may provide a specific shell string (e.g.
|
|
204
|
-
* `/bin/bash`)
|
|
368
|
+
* Optional namespace override for the child when mounted under the parent.
|
|
369
|
+
* When provided, this name is used instead of the child's default `ns`.
|
|
205
370
|
*/
|
|
206
|
-
|
|
371
|
+
override: PluginNamespaceOverride | undefined;
|
|
372
|
+
}
|
|
373
|
+
/** Public plugin contract used by the GetDotenv CLI host. */
|
|
374
|
+
interface GetDotenvCliPlugin<TOptions extends GetDotenvOptions = GetDotenvOptions, TArgs extends unknown[] = [], TOpts extends OptionValues = {}, TGlobal extends OptionValues = {}> {
|
|
375
|
+
/** Namespace (required): the command name where this plugin is mounted. */
|
|
376
|
+
ns: string;
|
|
207
377
|
/**
|
|
208
|
-
*
|
|
209
|
-
*
|
|
378
|
+
* Setup phase: register commands and wiring on the provided mount.
|
|
379
|
+
* Runs parent → children (pre-order). Return nothing (void).
|
|
210
380
|
*/
|
|
211
|
-
|
|
381
|
+
setup: (cli: GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal>) => void | Promise<void>;
|
|
212
382
|
/**
|
|
213
|
-
*
|
|
214
|
-
*
|
|
383
|
+
* After the dotenv context is resolved, initialize any clients/secrets
|
|
384
|
+
* or attach per-plugin state under ctx.plugins (by convention).
|
|
385
|
+
* Runs parent → children (pre-order).
|
|
215
386
|
*/
|
|
216
|
-
|
|
387
|
+
afterResolve?: (cli: GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal>, ctx: GetDotenvCliCtx<TOptions>) => void | Promise<void>;
|
|
388
|
+
/** Zod schema for this plugin's config slice (from config.plugins[…]). */
|
|
389
|
+
configSchema?: ZodObject;
|
|
217
390
|
/**
|
|
218
|
-
*
|
|
219
|
-
*
|
|
391
|
+
* Compositional children, with optional per-child overrides (e.g., ns).
|
|
392
|
+
* Installed after the parent per pre-order.
|
|
220
393
|
*/
|
|
221
|
-
|
|
394
|
+
children: Array<PluginChildEntry<TOptions, TArgs, TOpts, TGlobal>>;
|
|
222
395
|
/**
|
|
223
|
-
*
|
|
224
|
-
*
|
|
396
|
+
* Compose a child plugin with optional override (ns). Returns the parent
|
|
397
|
+
* to enable chaining.
|
|
225
398
|
*/
|
|
226
|
-
|
|
399
|
+
use: (child: GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal>, override?: PluginNamespaceOverride) => GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal>;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Compile-time helper type: the plugin object returned by definePlugin always
|
|
403
|
+
* includes the instance-bound helpers as required members. Keeping the public
|
|
404
|
+
* interface optional preserves compatibility for ad-hoc/test plugins, while
|
|
405
|
+
* return types from definePlugin provide stronger DX for shipped/typed plugins.
|
|
406
|
+
*/
|
|
407
|
+
interface PluginWithInstanceHelpers<TOptions extends GetDotenvOptions = GetDotenvOptions, TConfig = unknown, TArgs extends unknown[] = [], TOpts extends OptionValues = {}, TGlobal extends OptionValues = {}> extends GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal> {
|
|
408
|
+
readConfig<TCfg = TConfig>(cli: GetDotenvCliPublic<TOptions, unknown[], OptionValues, OptionValues>): Readonly<TCfg>;
|
|
409
|
+
createPluginDynamicOption<TCfg = TConfig, Usage extends string = string>(cli: GetDotenvCliPublic<TOptions, unknown[], OptionValues, OptionValues>, flags: Usage, desc: (cfg: ResolvedHelpConfig, pluginCfg: Readonly<TCfg>) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option<Usage>;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Public spec type for defining a plugin with compositional helpers.
|
|
413
|
+
*/
|
|
414
|
+
type DefineSpec<TOptions extends GetDotenvOptions = GetDotenvOptions, TArgs extends unknown[] = [], TOpts extends OptionValues = {}, TGlobal extends OptionValues = {}> = Omit<GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal>, 'children' | 'use' | 'setup'> & {
|
|
227
415
|
/**
|
|
228
|
-
*
|
|
229
|
-
*
|
|
416
|
+
* Required namespace and setup function. The host creates the mount and
|
|
417
|
+
* passes it into setup; return void | Promise<void>.
|
|
230
418
|
*/
|
|
231
|
-
|
|
232
|
-
|
|
419
|
+
ns: string;
|
|
420
|
+
setup: (cli: GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal>) => void | Promise<void>;
|
|
421
|
+
};
|
|
422
|
+
/**
|
|
423
|
+
* Helper to infer the configuration type from a `PluginWithInstanceHelpers` type.
|
|
424
|
+
*/
|
|
425
|
+
type InferPluginConfig<P> = P extends PluginWithInstanceHelpers<GetDotenvOptions, infer C> ? Readonly<C> : never;
|
|
233
426
|
|
|
234
|
-
/**
|
|
235
|
-
*
|
|
427
|
+
/**
|
|
428
|
+
* Define a GetDotenv CLI plugin with compositional helpers.
|
|
236
429
|
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
430
|
+
* @example
|
|
431
|
+
* const p = definePlugin(\{ ns: 'aws', setup(cli) \{ /* wire subcommands *\/ \} \})
|
|
432
|
+
* .use(child, \{ ns: 'whoami' \});
|
|
240
433
|
*/
|
|
434
|
+
declare function definePlugin<TOptions extends GetDotenvOptions, Schema extends ZodObject>(spec: Omit<DefineSpec<TOptions>, 'configSchema'> & {
|
|
435
|
+
configSchema: Schema;
|
|
436
|
+
}): PluginWithInstanceHelpers<TOptions, z.output<Schema>>;
|
|
437
|
+
declare function definePlugin<TOptions extends GetDotenvOptions>(spec: DefineSpec<TOptions>): PluginWithInstanceHelpers<TOptions, {}>;
|
|
241
438
|
|
|
242
439
|
/**
|
|
243
|
-
*
|
|
244
|
-
* - Extends Commander.Command so plugins can attach options/commands/hooks.
|
|
245
|
-
* - Adds host-specific helpers used by built-in plugins.
|
|
440
|
+
* Options for runCommandResult (buffered execution).
|
|
246
441
|
*
|
|
247
|
-
*
|
|
248
|
-
* to avoid TS2379 under exactOptionalPropertyTypes in downstream consumers.
|
|
442
|
+
* @public
|
|
249
443
|
*/
|
|
250
|
-
|
|
251
|
-
ns: (name: string) => Command;
|
|
252
|
-
getCtx: () => GetDotenvCliCtx<TOptions> | undefined;
|
|
253
|
-
resolveAndLoad: (customOptions?: Partial<TOptions>) => Promise<GetDotenvCliCtx<TOptions>>;
|
|
254
|
-
};
|
|
255
|
-
/** Public plugin contract used by the GetDotenv CLI host. */
|
|
256
|
-
interface GetDotenvCliPlugin {
|
|
257
|
-
id?: string;
|
|
444
|
+
interface RunCommandResultOptions {
|
|
258
445
|
/**
|
|
259
|
-
*
|
|
260
|
-
* Runs parent → children (pre-order).
|
|
446
|
+
* Working directory for the child process.
|
|
261
447
|
*/
|
|
262
|
-
|
|
448
|
+
cwd?: string | URL;
|
|
263
449
|
/**
|
|
264
|
-
*
|
|
265
|
-
* or attach per-plugin state under ctx.plugins (by convention).
|
|
266
|
-
* Runs parent → children (pre-order).
|
|
450
|
+
* Environment variables for the child process. Undefined values are dropped.
|
|
267
451
|
*/
|
|
268
|
-
|
|
452
|
+
env?: NodeJS.ProcessEnv;
|
|
453
|
+
/**
|
|
454
|
+
* Optional timeout (ms). Kills the child with SIGKILL on expiry.
|
|
455
|
+
*/
|
|
456
|
+
timeoutMs?: number;
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Options for runCommand (execution with optional inherit/pipe).
|
|
460
|
+
*
|
|
461
|
+
* @public
|
|
462
|
+
*/
|
|
463
|
+
interface RunCommandOptions {
|
|
269
464
|
/**
|
|
270
|
-
*
|
|
271
|
-
* When provided, the host validates the merged config under the guarded loader path.
|
|
465
|
+
* Working directory for the child process.
|
|
272
466
|
*/
|
|
273
|
-
|
|
467
|
+
cwd?: string | URL;
|
|
274
468
|
/**
|
|
275
|
-
*
|
|
469
|
+
* Environment variables for the child process. Undefined values are dropped.
|
|
276
470
|
*/
|
|
277
|
-
|
|
471
|
+
env?: NodeJS.ProcessEnv;
|
|
278
472
|
/**
|
|
279
|
-
*
|
|
473
|
+
* Stdio strategy for the child process.
|
|
280
474
|
*/
|
|
281
|
-
|
|
475
|
+
stdio?: 'inherit' | 'pipe';
|
|
282
476
|
}
|
|
283
477
|
/**
|
|
284
|
-
*
|
|
285
|
-
*
|
|
478
|
+
* Execute a command and capture stdout/stderr (buffered).
|
|
479
|
+
* - Preserves plain vs shell behavior and argv/string normalization.
|
|
480
|
+
* - Never re-emits stdout/stderr to parent; returns captured buffers.
|
|
481
|
+
* - Supports optional timeout (ms).
|
|
286
482
|
*/
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
483
|
+
declare function runCommandResult(command: readonly string[], shell: false, opts?: RunCommandResultOptions): Promise<{
|
|
484
|
+
exitCode: number;
|
|
485
|
+
stdout: string;
|
|
486
|
+
stderr: string;
|
|
487
|
+
}>;
|
|
488
|
+
declare function runCommandResult(command: string | readonly string[], shell: string | boolean | URL, opts?: RunCommandResultOptions): Promise<{
|
|
489
|
+
exitCode: number;
|
|
490
|
+
stdout: string;
|
|
491
|
+
stderr: string;
|
|
492
|
+
}>;
|
|
493
|
+
declare function runCommand(command: readonly string[], shell: false, opts: RunCommandOptions): Promise<number>;
|
|
494
|
+
declare function runCommand(command: string | readonly string[], shell: string | boolean | URL, opts: RunCommandOptions): Promise<number>;
|
|
495
|
+
|
|
496
|
+
/** src/cliHost/GetDotenvCli.ts
|
|
497
|
+
* Plugin-first CLI host for get-dotenv with Commander generics preserved.
|
|
498
|
+
* Public surface implements GetDotenvCliPublic and provides:
|
|
499
|
+
* - attachRootOptions (builder-only; no public override wiring)
|
|
500
|
+
* - resolveAndLoad (strict resolve + context compute)
|
|
501
|
+
* - getCtx/hasCtx accessors
|
|
502
|
+
* - ns() for typed subcommand creation with duplicate-name guard
|
|
503
|
+
* - grouped help rendering with dynamic option descriptions
|
|
297
504
|
*/
|
|
298
|
-
declare const definePlugin: (spec: DefineSpec) => GetDotenvCliPlugin;
|
|
299
505
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
};
|
|
303
|
-
/** * Per-invocation context shared with plugins and actions. */
|
|
304
|
-
type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
|
|
305
|
-
optionsResolved: TOptions;
|
|
306
|
-
dotenv: ProcessEnv;
|
|
307
|
-
plugins?: Record<string, unknown>;
|
|
308
|
-
pluginConfigs?: Record<string, unknown>;
|
|
309
|
-
};
|
|
506
|
+
declare const CTX_SYMBOL: unique symbol;
|
|
507
|
+
declare const OPTS_SYMBOL: unique symbol;
|
|
310
508
|
declare const HELP_HEADER_SYMBOL: unique symbol;
|
|
311
509
|
/**
|
|
312
510
|
* Plugin-first CLI host for get-dotenv. Extends Commander.Command.
|
|
@@ -316,23 +514,30 @@ declare const HELP_HEADER_SYMBOL: unique symbol;
|
|
|
316
514
|
* - Expose a stable accessor for the current context (getCtx).
|
|
317
515
|
* - Provide a namespacing helper (ns).
|
|
318
516
|
* - Support composable plugins with parent → children install and afterResolve.
|
|
319
|
-
*
|
|
320
|
-
* NOTE: This host is additive and does not alter the legacy CLI.
|
|
321
517
|
*/
|
|
322
|
-
declare class GetDotenvCli
|
|
323
|
-
#private;
|
|
518
|
+
declare class GetDotenvCli<TOptions extends GetDotenvOptions = GetDotenvOptions, TArgs extends unknown[] = [], TOpts extends OptionValues = {}, TGlobal extends OptionValues = {}> extends Command<TArgs, TOpts, TGlobal> implements GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal> {
|
|
324
519
|
/** Registered top-level plugins (composition happens via .use()) */
|
|
325
520
|
private _plugins;
|
|
326
521
|
/** One-time installation guard */
|
|
327
522
|
private _installed;
|
|
523
|
+
/** In-flight installation promise to guard against concurrent installs */
|
|
524
|
+
private _installing?;
|
|
328
525
|
/** Optional header line to prepend in help output */
|
|
329
526
|
private [HELP_HEADER_SYMBOL];
|
|
527
|
+
/** Context/options stored under symbols (typed) */
|
|
528
|
+
private [CTX_SYMBOL]?;
|
|
529
|
+
private [OPTS_SYMBOL]?;
|
|
330
530
|
/**
|
|
331
531
|
* Create a subcommand using the same subclass, preserving helpers like
|
|
332
532
|
* dynamicOption on children.
|
|
333
533
|
*/
|
|
334
|
-
createCommand(name?: string):
|
|
534
|
+
createCommand(name?: string): GetDotenvCli<TOptions>;
|
|
335
535
|
constructor(alias?: string);
|
|
536
|
+
/**
|
|
537
|
+
* Attach legacy/base root flags to this CLI instance.
|
|
538
|
+
* Delegates to the pure builder in attachRootOptions.ts.
|
|
539
|
+
*/
|
|
540
|
+
attachRootOptions(defaults?: Partial<RootOptionsShape>): this;
|
|
336
541
|
/**
|
|
337
542
|
* Resolve options (strict) and compute dotenv context.
|
|
338
543
|
* Stores the context on the instance under a symbol.
|
|
@@ -342,34 +547,30 @@ declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOption
|
|
|
342
547
|
* afterResolve hooks. Useful for top-level help rendering to avoid
|
|
343
548
|
* long-running side-effects while still evaluating dynamic help text.
|
|
344
549
|
*/
|
|
345
|
-
resolveAndLoad(customOptions?: Partial<TOptions>, opts?:
|
|
346
|
-
runAfterResolve?: boolean;
|
|
347
|
-
}): Promise<GetDotenvCliCtx<TOptions>>;
|
|
550
|
+
resolveAndLoad(customOptions?: Partial<TOptions>, opts?: ResolveAndLoadOptions): Promise<GetDotenvCliCtx<TOptions>>;
|
|
348
551
|
/**
|
|
349
552
|
* Create a Commander Option that computes its description at help time.
|
|
350
553
|
* The returned Option may be configured (conflicts, default, parser) and
|
|
351
554
|
* added via addOption().
|
|
352
555
|
*/
|
|
353
|
-
createDynamicOption<
|
|
354
|
-
|
|
355
|
-
}) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option;
|
|
356
|
-
/**
|
|
357
|
-
* Chainable helper mirroring .option(), but with a dynamic description.
|
|
358
|
-
* Equivalent to addOption(createDynamicOption(...)).
|
|
359
|
-
*/
|
|
360
|
-
dynamicOption<TPlugins = Record<string, unknown>>(flags: string, desc: (cfg: ResolvedHelpConfig & {
|
|
361
|
-
plugins: TPlugins;
|
|
362
|
-
}) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): this;
|
|
556
|
+
createDynamicOption<Usage extends string>(flags: Usage, desc: (cfg: ResolvedHelpConfig) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option<Usage>;
|
|
557
|
+
createDynamicOption<Usage extends string, TValue = unknown>(flags: Usage, desc: (cfg: ResolvedHelpConfig) => string, parser: (value: string, previous?: TValue) => TValue, defaultValue?: TValue): Option<Usage>;
|
|
363
558
|
/**
|
|
364
559
|
* Evaluate dynamic descriptions for this command and all descendants using
|
|
365
560
|
* the provided resolved configuration. Mutates the Option.description in
|
|
366
561
|
* place so Commander help renders updated text.
|
|
367
562
|
*/
|
|
368
563
|
evaluateDynamicOptions(resolved: ResolvedHelpConfig): void;
|
|
564
|
+
/** Internal: climb to the true root (host) command. */
|
|
565
|
+
private _root;
|
|
369
566
|
/**
|
|
370
567
|
* Retrieve the current invocation context (if any).
|
|
371
568
|
*/
|
|
372
|
-
getCtx(): GetDotenvCliCtx<TOptions
|
|
569
|
+
getCtx(): GetDotenvCliCtx<TOptions>;
|
|
570
|
+
/**
|
|
571
|
+
* Check whether a context has been resolved (non-throwing guard).
|
|
572
|
+
*/
|
|
573
|
+
hasCtx(): boolean;
|
|
373
574
|
/**
|
|
374
575
|
* Retrieve the merged root CLI options bag (if set by passOptions()).
|
|
375
576
|
* Downstream-safe: no generics required.
|
|
@@ -377,36 +578,39 @@ declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOption
|
|
|
377
578
|
getOptions(): GetDotenvCliOptions | undefined;
|
|
378
579
|
/** Internal: set the merged root options bag for this run. */
|
|
379
580
|
_setOptionsBag(bag: GetDotenvCliOptions): void;
|
|
380
|
-
/**
|
|
581
|
+
/**
|
|
582
|
+
* Convenience helper to create a namespaced subcommand with argument inference.
|
|
583
|
+
* This mirrors Commander generics so downstream chaining stays fully typed.
|
|
381
584
|
*/
|
|
382
|
-
ns(name:
|
|
585
|
+
ns<Usage extends string>(name: Usage): GetDotenvCliPublic<TOptions, [
|
|
586
|
+
...TArgs,
|
|
587
|
+
...InferCommandArguments<Usage>
|
|
588
|
+
], {}, TOpts & TGlobal>;
|
|
383
589
|
/**
|
|
384
590
|
* Tag options added during the provided callback as 'app' for grouped help.
|
|
385
591
|
* Allows downstream apps to demarcate their root-level options.
|
|
386
592
|
*/
|
|
387
|
-
tagAppOptions<T>(fn: (root:
|
|
593
|
+
tagAppOptions<T>(fn: (root: CommandUnknownOpts) => T): T;
|
|
388
594
|
/**
|
|
389
595
|
* Branding helper: set CLI name/description/version and optional help header.
|
|
390
596
|
* If version is omitted and importMetaUrl is provided, attempts to read the
|
|
391
597
|
* nearest package.json version (best-effort; non-fatal on failure).
|
|
392
598
|
*/
|
|
393
|
-
brand(args:
|
|
394
|
-
name?: string;
|
|
395
|
-
description?: string;
|
|
396
|
-
version?: string;
|
|
397
|
-
importMetaUrl?: string;
|
|
398
|
-
helpHeader?: string;
|
|
399
|
-
}): Promise<this>;
|
|
599
|
+
brand(args: BrandOptions): Promise<this>;
|
|
400
600
|
/**
|
|
401
601
|
* Insert grouped plugin/app options between "Options" and "Commands" for
|
|
402
602
|
* hybrid ordering. Applies to root and any parent command.
|
|
403
603
|
*/
|
|
404
604
|
helpInformation(): string;
|
|
605
|
+
/**
|
|
606
|
+
* Public: tag an Option with a display group for help (root/app/plugin:<id>).
|
|
607
|
+
*/
|
|
608
|
+
setOptionGroup(opt: Option, group: string): void;
|
|
405
609
|
/**
|
|
406
610
|
* Register a plugin for installation (parent level).
|
|
407
611
|
* Installation occurs on first resolveAndLoad() (or explicit install()).
|
|
408
612
|
*/
|
|
409
|
-
use(plugin: GetDotenvCliPlugin): this;
|
|
613
|
+
use(plugin: GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal>, override?: PluginNamespaceOverride): this;
|
|
410
614
|
/**
|
|
411
615
|
* Install all registered plugins in parent → children (pre-order).
|
|
412
616
|
* Runs only once per CLI instance.
|
|
@@ -418,34 +622,125 @@ declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOption
|
|
|
418
622
|
private _runAfterResolve;
|
|
419
623
|
}
|
|
420
624
|
|
|
625
|
+
/** src/cliHost/getRootCommand.ts
|
|
626
|
+
* Typed helper to retrieve the true root command (host) starting from any mount.
|
|
627
|
+
*/
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* Return the top-level root command for a given mount or action's thisCommand.
|
|
631
|
+
*
|
|
632
|
+
* @param cmd - any command (mount or thisCommand inside an action)
|
|
633
|
+
* @returns the root command instance
|
|
634
|
+
*/
|
|
635
|
+
declare const getRootCommand: (cmd: CommandUnknownOpts) => CommandUnknownOpts;
|
|
636
|
+
|
|
637
|
+
/** src/cliHost/invoke.ts
|
|
638
|
+
* Shared helpers for composing child env overlays and preserving argv for Node -e.
|
|
639
|
+
*/
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Compose a child-process env overlay from dotenv and the merged CLI options bag.
|
|
643
|
+
* Returns a shallow object including getDotenvCliOptions when serializable.
|
|
644
|
+
*/
|
|
645
|
+
declare function composeNestedEnv(merged: GetDotenvCliOptions | Record<string, unknown>, dotenv: Record<string, string | undefined>): Record<string, string>;
|
|
646
|
+
/**
|
|
647
|
+
* Strip one layer of symmetric outer quotes (single or double) from a string.
|
|
648
|
+
*
|
|
649
|
+
* @param s - Input string.
|
|
650
|
+
*/
|
|
651
|
+
declare const stripOne: (s: string) => string;
|
|
652
|
+
/**
|
|
653
|
+
* Preserve argv array for Node -e/--eval payloads under shell-off and
|
|
654
|
+
* peel one symmetric outer quote layer from the code argument.
|
|
655
|
+
*/
|
|
656
|
+
declare function maybePreserveNodeEvalArgv(args: string[]): string[];
|
|
657
|
+
|
|
658
|
+
/** src/cliHost/paths.ts
|
|
659
|
+
* Helpers for realized mount paths and plugin tree flattening.
|
|
660
|
+
*/
|
|
661
|
+
|
|
662
|
+
/**
|
|
663
|
+
* A flattened plugin entry with its realized path.
|
|
664
|
+
*
|
|
665
|
+
* @public
|
|
666
|
+
*/
|
|
667
|
+
interface PluginFlattenedEntry<TOptions extends GetDotenvOptions = GetDotenvOptions, TArgs extends unknown[] = [], TOpts extends OptionValues = {}, TGlobal extends OptionValues = {}> {
|
|
668
|
+
/** The plugin instance for this entry in the flattened tree. */
|
|
669
|
+
plugin: GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal>;
|
|
670
|
+
/**
|
|
671
|
+
* The realized mount path for this plugin (root alias excluded), e.g. "aws/whoami".
|
|
672
|
+
*/
|
|
673
|
+
path: string;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* Retrieve the merged root options bag from the current command context.
|
|
678
|
+
* Climbs to the root `GetDotenvCli` instance to access the persisted options.
|
|
679
|
+
*
|
|
680
|
+
* @param cmd - The current command instance (thisCommand).
|
|
681
|
+
* @throws Error if the root is not a GetDotenvCli or options are missing.
|
|
682
|
+
*/
|
|
683
|
+
declare const readMergedOptions: (cmd: CommandUnknownOpts) => GetDotenvCliOptions;
|
|
684
|
+
|
|
421
685
|
/**
|
|
422
|
-
*
|
|
423
|
-
*
|
|
424
|
-
* - passOptions: merges flags (parent \< current), computes dotenv context once,
|
|
425
|
-
* runs validation, and persists merged options for nested flows.
|
|
686
|
+
* Batch services (neutral): resolve command and shell settings.
|
|
687
|
+
* Shared by the generator path and the batch plugin to avoid circular deps.
|
|
426
688
|
*/
|
|
427
|
-
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* Resolve a command string from the {@link ScriptsTable} table.
|
|
692
|
+
* A script may be expressed as a string or an object with a `cmd` property.
|
|
693
|
+
*
|
|
694
|
+
* @param scripts - Optional scripts table.
|
|
695
|
+
* @param command - User-provided command name or string.
|
|
696
|
+
* @returns Resolved command string (falls back to the provided command).
|
|
697
|
+
*/
|
|
698
|
+
declare const resolveCommand: (scripts: ScriptsTable | undefined, command: string) => string;
|
|
699
|
+
/**
|
|
700
|
+
* Resolve the shell setting for a given command:
|
|
701
|
+
* - If the script entry is an object, prefer its `shell` override.
|
|
702
|
+
* - Otherwise use the provided `shell` (string | boolean).
|
|
703
|
+
*
|
|
704
|
+
* @param scripts - Optional scripts table.
|
|
705
|
+
* @param command - User-provided command name or string.
|
|
706
|
+
* @param shell - Global shell preference (string | boolean).
|
|
707
|
+
*/
|
|
708
|
+
declare const resolveShell: <TShell extends string | boolean>(scripts: ScriptsTable<TShell> | undefined, command: string, shell: TShell | undefined) => TShell | false;
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* Result of CLI option resolution.
|
|
712
|
+
*/
|
|
713
|
+
interface ResolveCliOptionsResult<T> {
|
|
428
714
|
/**
|
|
429
|
-
*
|
|
430
|
-
*
|
|
715
|
+
* The merged options object after applying defaults, inherited parent
|
|
716
|
+
* values, and the current CLI flags. This bag is used as the effective
|
|
717
|
+
* root options for the current invocation.
|
|
431
718
|
*/
|
|
432
|
-
|
|
433
|
-
includeCommandOption?: boolean;
|
|
434
|
-
}): this;
|
|
719
|
+
merged: T;
|
|
435
720
|
/**
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
* - Persist the merged bag on the current command and on the host (for ergonomics).
|
|
439
|
-
* - Compute the dotenv context once via resolveAndLoad(serviceOptions).
|
|
440
|
-
* - Validate the composed env against discovered config (warn or --strict fail).
|
|
721
|
+
* Positional command (string) resolved for invokers that accept a command
|
|
722
|
+
* payload (e.g., batch parent or cmd alias). When absent, no command is set.
|
|
441
723
|
*/
|
|
442
|
-
|
|
724
|
+
command?: string;
|
|
443
725
|
}
|
|
444
726
|
/**
|
|
445
|
-
*
|
|
446
|
-
*
|
|
727
|
+
* Merge and normalize raw Commander options (current + parent + defaults)
|
|
728
|
+
* into a GetDotenvCliOptions-like object. Types are intentionally wide to
|
|
729
|
+
* avoid cross-layer coupling; callers may cast as needed.
|
|
730
|
+
*/
|
|
731
|
+
declare const resolveCliOptions: <T extends Partial<RootOptionsShape> & {
|
|
732
|
+
scripts?: ScriptsTable;
|
|
733
|
+
}>(rawCliOptions: unknown, defaults: Partial<T>, parentJson?: string) => ResolveCliOptionsResult<T>;
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Build a sanitized environment object for spawning child processes.
|
|
737
|
+
* Merges `base` and `overlay`, drops undefined values, and handles platform-specific
|
|
738
|
+
* normalization (e.g. case-insensitivity on Windows).
|
|
739
|
+
*
|
|
740
|
+
* @param base - Base environment (usually `process.env`).
|
|
741
|
+
* @param overlay - Environment variables to overlay.
|
|
447
742
|
*/
|
|
448
|
-
declare const
|
|
743
|
+
declare const buildSpawnEnv: (base?: NodeJS.ProcessEnv, overlay?: Record<string, string | undefined>) => NodeJS.ProcessEnv;
|
|
449
744
|
|
|
450
|
-
export { GetDotenvCli, definePlugin, readMergedOptions };
|
|
451
|
-
export type { DefineSpec, GetDotenvCliCtx, GetDotenvCliOptions, GetDotenvCliPlugin, GetDotenvCliPublic, ScriptsTable };
|
|
745
|
+
export { GetDotenvCli, baseGetDotenvCliOptions, buildSpawnEnv, composeNestedEnv, definePlugin, defineScripts, getRootCommand, maybePreserveNodeEvalArgv, readMergedOptions, resolveCliOptions, resolveCommand, resolveShell, runCommand, runCommandResult, stripOne, toHelpConfig };
|
|
746
|
+
export type { BrandOptions, DefineSpec, GetDotenvCliCtx, GetDotenvCliOptions, GetDotenvCliPlugin, GetDotenvCliPublic, InferPluginConfig, PluginChildEntry, PluginFlattenedEntry, PluginNamespaceOverride, PluginWithInstanceHelpers, ResolveAndLoadOptions, ResolveCliOptionsResult, ResolvedHelpConfig, RootOptionsShape, RunCommandOptions, RunCommandResultOptions, ScriptDef, Scripts, ScriptsTable };
|