@karmaniverous/get-dotenv 6.0.0-1 → 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 +91 -379
- package/dist/cli.d.ts +569 -0
- package/dist/cli.mjs +18788 -0
- package/dist/cliHost.d.ts +515 -184
- package/dist/cliHost.mjs +1931 -1428
- package/dist/config.d.ts +187 -14
- package/dist/config.mjs +256 -81
- package/dist/env-overlay.d.ts +212 -16
- package/dist/env-overlay.mjs +168 -4
- package/dist/getdotenv.cli.mjs +18227 -3487
- package/dist/index.d.ts +541 -260
- package/dist/index.mjs +18294 -3556
- package/dist/plugins-aws.d.ts +221 -91
- package/dist/plugins-aws.mjs +2360 -361
- package/dist/plugins-batch.d.ts +300 -103
- package/dist/plugins-batch.mjs +2519 -484
- package/dist/plugins-cmd.d.ts +229 -106
- package/dist/plugins-cmd.mjs +2480 -793
- package/dist/plugins-init.d.ts +221 -95
- package/dist/plugins-init.mjs +2102 -104
- package/dist/plugins.d.ts +246 -125
- package/dist/plugins.mjs +17861 -1973
- package/dist/templates/cli/index.ts +26 -0
- package/{templates/cli/ts → dist/templates/cli}/plugins/hello.ts +11 -6
- 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 +42 -39
- package/templates/cli/index.ts +26 -0
- package/templates/cli/plugins/hello.ts +43 -0
- package/templates/config/js/getdotenv.config.js +8 -3
- 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 +9 -4
- package/templates/config/yaml/public/getdotenv.config.yaml +0 -3
- package/dist/plugins-demo.d.ts +0 -204
- package/dist/plugins-demo.mjs +0 -496
- package/templates/cli/ts/index.ts +0 -9
package/dist/cliHost.d.ts
CHANGED
|
@@ -1,56 +1,189 @@
|
|
|
1
|
-
import { Command, Option } from 'commander';
|
|
1
|
+
import { OptionValues, Command, InferCommandArguments, Option, CommandUnknownOpts } from '@commander-js/extra-typings';
|
|
2
2
|
import { z, ZodObject } from 'zod';
|
|
3
3
|
export { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Minimal root options shape shared by CLI and generator layers.
|
|
7
7
|
* Keep keys optional to respect exactOptionalPropertyTypes semantics.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
8
10
|
*/
|
|
9
|
-
|
|
11
|
+
interface RootOptionsShape {
|
|
12
|
+
/** Target environment (dotenv-expanded). */
|
|
10
13
|
env?: string;
|
|
14
|
+
/** Explicit variable overrides (dotenv-expanded). */
|
|
11
15
|
vars?: string;
|
|
16
|
+
/** Command to execute (dotenv-expanded). */
|
|
12
17
|
command?: string;
|
|
18
|
+
/** Output path for the consolidated environment file (dotenv-expanded). */
|
|
13
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
|
+
*/
|
|
14
26
|
shell?: string | boolean;
|
|
27
|
+
/** Whether to load variables into `process.env`. */
|
|
15
28
|
loadProcess?: boolean;
|
|
29
|
+
/** Exclude all variables from loading. */
|
|
16
30
|
excludeAll?: boolean;
|
|
31
|
+
/** Exclude dynamic variables. */
|
|
17
32
|
excludeDynamic?: boolean;
|
|
33
|
+
/** Exclude environment-specific variables. */
|
|
18
34
|
excludeEnv?: boolean;
|
|
35
|
+
/** Exclude global variables. */
|
|
19
36
|
excludeGlobal?: boolean;
|
|
37
|
+
/** Exclude private variables. */
|
|
20
38
|
excludePrivate?: boolean;
|
|
39
|
+
/** Exclude public variables. */
|
|
21
40
|
excludePublic?: boolean;
|
|
41
|
+
/** Enable console logging of loaded variables. */
|
|
22
42
|
log?: boolean;
|
|
43
|
+
/** Enable debug logging to stderr. */
|
|
23
44
|
debug?: boolean;
|
|
45
|
+
/** Capture child process stdio (useful for tests/CI). */
|
|
24
46
|
capture?: boolean;
|
|
47
|
+
/** Fail on validation errors (schema/requiredKeys). */
|
|
25
48
|
strict?: boolean;
|
|
49
|
+
/** Enable presentation-time redaction of secret-like keys. */
|
|
26
50
|
redact?: boolean;
|
|
51
|
+
/** Enable entropy warnings for high-entropy values. */
|
|
27
52
|
warnEntropy?: boolean;
|
|
53
|
+
/** Entropy threshold (bits/char) for warnings (default 3.8). */
|
|
28
54
|
entropyThreshold?: number;
|
|
55
|
+
/** Minimum string length to check for entropy (default 16). */
|
|
29
56
|
entropyMinLength?: number;
|
|
30
|
-
|
|
57
|
+
/** Regex patterns for keys to exclude from entropy checks. */
|
|
58
|
+
entropyWhitelist?: ReadonlyArray<string>;
|
|
59
|
+
/** Additional regex patterns for keys to redact. */
|
|
31
60
|
redactPatterns?: string[];
|
|
61
|
+
/** Default target environment when not specified. */
|
|
32
62
|
defaultEnv?: string;
|
|
63
|
+
/** Token indicating a dotenv file (default: ".env"). */
|
|
33
64
|
dotenvToken?: string;
|
|
65
|
+
/** Path to dynamic variables module (default: undefined). */
|
|
34
66
|
dynamicPath?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Emit diagnostics for child env composition.
|
|
69
|
+
* - `true`: trace all keys.
|
|
70
|
+
* - `string[]`: trace selected keys.
|
|
71
|
+
*/
|
|
35
72
|
trace?: boolean | string[];
|
|
73
|
+
/** Paths to search for dotenv files (space-delimited string or array). */
|
|
36
74
|
paths?: string;
|
|
75
|
+
/** Delimiter for paths string (default: space). */
|
|
37
76
|
pathsDelimiter?: string;
|
|
77
|
+
/** Regex pattern for paths delimiter. */
|
|
38
78
|
pathsDelimiterPattern?: string;
|
|
79
|
+
/** Token indicating private variables (default: "local"). */
|
|
39
80
|
privateToken?: string;
|
|
81
|
+
/** Delimiter for vars string (default: space). */
|
|
40
82
|
varsDelimiter?: string;
|
|
83
|
+
/** Regex pattern for vars delimiter. */
|
|
41
84
|
varsDelimiterPattern?: string;
|
|
85
|
+
/** Assignment operator for vars (default: "="). */
|
|
42
86
|
varsAssignor?: string;
|
|
87
|
+
/** Regex pattern for vars assignment operator. */
|
|
43
88
|
varsAssignorPattern?: string;
|
|
89
|
+
/** Table of named scripts for execution. */
|
|
44
90
|
scripts?: ScriptsTable;
|
|
45
|
-
}
|
|
91
|
+
}
|
|
46
92
|
/**
|
|
47
|
-
*
|
|
93
|
+
* Definition for a single script entry.
|
|
48
94
|
*/
|
|
49
|
-
|
|
95
|
+
interface ScriptDef<TShell extends string | boolean = string | boolean> {
|
|
96
|
+
/** The command string to execute. */
|
|
50
97
|
cmd: string;
|
|
98
|
+
/** Shell override for this script. */
|
|
51
99
|
shell?: TShell | undefined;
|
|
52
|
-
}
|
|
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
|
+
}
|
|
53
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
|
+
*/
|
|
54
187
|
declare const getDotenvOptionsSchemaResolved: z.ZodObject<{
|
|
55
188
|
defaultEnv: z.ZodOptional<z.ZodString>;
|
|
56
189
|
dotenvToken: z.ZodOptional<z.ZodString>;
|
|
@@ -64,13 +197,23 @@ declare const getDotenvOptionsSchemaResolved: z.ZodObject<{
|
|
|
64
197
|
excludePublic: z.ZodOptional<z.ZodBoolean>;
|
|
65
198
|
loadProcess: z.ZodOptional<z.ZodBoolean>;
|
|
66
199
|
log: z.ZodOptional<z.ZodBoolean>;
|
|
67
|
-
logger: z.
|
|
200
|
+
logger: z.ZodDefault<z.ZodUnknown>;
|
|
68
201
|
outputPath: z.ZodOptional<z.ZodString>;
|
|
69
202
|
paths: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
70
203
|
privateToken: z.ZodOptional<z.ZodString>;
|
|
71
204
|
vars: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodString>>>;
|
|
72
205
|
}, z.core.$strip>;
|
|
73
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
|
+
*/
|
|
216
|
+
|
|
74
217
|
/**
|
|
75
218
|
* A minimal representation of an environment key/value mapping.
|
|
76
219
|
* Values may be `undefined` to represent "unset".
|
|
@@ -82,7 +225,14 @@ type ProcessEnv = Record<string, string | undefined>;
|
|
|
82
225
|
* or `undefined` to unset/skip the variable.
|
|
83
226
|
*/
|
|
84
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
|
+
*/
|
|
85
232
|
type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
|
|
233
|
+
/**
|
|
234
|
+
* Logger interface compatible with `console` or a subset thereof.
|
|
235
|
+
*/
|
|
86
236
|
type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
|
|
87
237
|
/**
|
|
88
238
|
* Canonical programmatic options type (schema-derived).
|
|
@@ -92,51 +242,16 @@ type GetDotenvOptions = z.output<typeof getDotenvOptionsSchemaResolved> & {
|
|
|
92
242
|
/**
|
|
93
243
|
* Compile-time overlay: narrowed logger for DX (schema stores unknown).
|
|
94
244
|
*/
|
|
95
|
-
logger
|
|
245
|
+
logger: Logger;
|
|
96
246
|
/**
|
|
97
247
|
* Compile-time overlay: narrowed dynamic map for DX (schema stores unknown).
|
|
98
248
|
*/
|
|
99
249
|
dynamic?: GetDotenvDynamic;
|
|
100
250
|
};
|
|
101
251
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Unify Scripts via the generic ScriptsTable<TShell> so shell types propagate.
|
|
254
|
+
*/
|
|
140
255
|
type Scripts = ScriptsTable;
|
|
141
256
|
/**
|
|
142
257
|
* Canonical CLI options type derived from the Zod schema output.
|
|
@@ -148,23 +263,246 @@ type GetDotenvCliOptions = z.output<typeof getDotenvCliOptionsSchemaResolved> &
|
|
|
148
263
|
/**
|
|
149
264
|
* Compile-only overlay for DX: logger narrowed from unknown.
|
|
150
265
|
*/
|
|
151
|
-
logger
|
|
266
|
+
logger: Logger;
|
|
152
267
|
/**
|
|
153
268
|
* Compile-only overlay for DX: scripts narrowed from Record\<string, unknown\>.
|
|
154
269
|
*/
|
|
155
270
|
scripts?: Scripts;
|
|
156
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>;
|
|
157
277
|
|
|
278
|
+
/**
|
|
279
|
+
* Configuration context used for generating dynamic help descriptions.
|
|
280
|
+
* Contains merged CLI options and plugin configuration slices.
|
|
281
|
+
*
|
|
282
|
+
* @public
|
|
283
|
+
*/
|
|
158
284
|
type ResolvedHelpConfig = Partial<GetDotenvCliOptions> & {
|
|
285
|
+
/**
|
|
286
|
+
* Per‑plugin configuration slices keyed by realized mount path
|
|
287
|
+
* (e.g., `"aws"` or `"aws/whoami"`), used for dynamic help text.
|
|
288
|
+
*/
|
|
159
289
|
plugins: Record<string, unknown>;
|
|
160
290
|
};
|
|
161
|
-
/**
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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 {
|
|
309
|
+
/**
|
|
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
|
|
315
|
+
*/
|
|
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 {
|
|
354
|
+
/**
|
|
355
|
+
* Override the default namespace for this plugin instance.
|
|
356
|
+
*/
|
|
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>;
|
|
367
|
+
/**
|
|
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`.
|
|
370
|
+
*/
|
|
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;
|
|
377
|
+
/**
|
|
378
|
+
* Setup phase: register commands and wiring on the provided mount.
|
|
379
|
+
* Runs parent → children (pre-order). Return nothing (void).
|
|
380
|
+
*/
|
|
381
|
+
setup: (cli: GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal>) => void | Promise<void>;
|
|
382
|
+
/**
|
|
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).
|
|
386
|
+
*/
|
|
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;
|
|
390
|
+
/**
|
|
391
|
+
* Compositional children, with optional per-child overrides (e.g., ns).
|
|
392
|
+
* Installed after the parent per pre-order.
|
|
393
|
+
*/
|
|
394
|
+
children: Array<PluginChildEntry<TOptions, TArgs, TOpts, TGlobal>>;
|
|
395
|
+
/**
|
|
396
|
+
* Compose a child plugin with optional override (ns). Returns the parent
|
|
397
|
+
* to enable chaining.
|
|
398
|
+
*/
|
|
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'> & {
|
|
415
|
+
/**
|
|
416
|
+
* Required namespace and setup function. The host creates the mount and
|
|
417
|
+
* passes it into setup; return void | Promise<void>.
|
|
418
|
+
*/
|
|
419
|
+
ns: string;
|
|
420
|
+
setup: (cli: GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal>) => void | Promise<void>;
|
|
167
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;
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Define a GetDotenv CLI plugin with compositional helpers.
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* const p = definePlugin(\{ ns: 'aws', setup(cli) \{ /* wire subcommands *\/ \} \})
|
|
432
|
+
* .use(child, \{ ns: 'whoami' \});
|
|
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, {}>;
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Options for runCommandResult (buffered execution).
|
|
441
|
+
*
|
|
442
|
+
* @public
|
|
443
|
+
*/
|
|
444
|
+
interface RunCommandResultOptions {
|
|
445
|
+
/**
|
|
446
|
+
* Working directory for the child process.
|
|
447
|
+
*/
|
|
448
|
+
cwd?: string | URL;
|
|
449
|
+
/**
|
|
450
|
+
* Environment variables for the child process. Undefined values are dropped.
|
|
451
|
+
*/
|
|
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 {
|
|
464
|
+
/**
|
|
465
|
+
* Working directory for the child process.
|
|
466
|
+
*/
|
|
467
|
+
cwd?: string | URL;
|
|
468
|
+
/**
|
|
469
|
+
* Environment variables for the child process. Undefined values are dropped.
|
|
470
|
+
*/
|
|
471
|
+
env?: NodeJS.ProcessEnv;
|
|
472
|
+
/**
|
|
473
|
+
* Stdio strategy for the child process.
|
|
474
|
+
*/
|
|
475
|
+
stdio?: 'inherit' | 'pipe';
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
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).
|
|
482
|
+
*/
|
|
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
|
|
504
|
+
*/
|
|
505
|
+
|
|
168
506
|
declare const CTX_SYMBOL: unique symbol;
|
|
169
507
|
declare const OPTS_SYMBOL: unique symbol;
|
|
170
508
|
declare const HELP_HEADER_SYMBOL: unique symbol;
|
|
@@ -177,11 +515,13 @@ declare const HELP_HEADER_SYMBOL: unique symbol;
|
|
|
177
515
|
* - Provide a namespacing helper (ns).
|
|
178
516
|
* - Support composable plugins with parent → children install and afterResolve.
|
|
179
517
|
*/
|
|
180
|
-
declare class GetDotenvCli
|
|
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> {
|
|
181
519
|
/** Registered top-level plugins (composition happens via .use()) */
|
|
182
520
|
private _plugins;
|
|
183
521
|
/** One-time installation guard */
|
|
184
522
|
private _installed;
|
|
523
|
+
/** In-flight installation promise to guard against concurrent installs */
|
|
524
|
+
private _installing?;
|
|
185
525
|
/** Optional header line to prepend in help output */
|
|
186
526
|
private [HELP_HEADER_SYMBOL];
|
|
187
527
|
/** Context/options stored under symbols (typed) */
|
|
@@ -191,8 +531,13 @@ declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOption
|
|
|
191
531
|
* Create a subcommand using the same subclass, preserving helpers like
|
|
192
532
|
* dynamicOption on children.
|
|
193
533
|
*/
|
|
194
|
-
createCommand(name?: string):
|
|
534
|
+
createCommand(name?: string): GetDotenvCli<TOptions>;
|
|
195
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;
|
|
196
541
|
/**
|
|
197
542
|
* Resolve options (strict) and compute dotenv context.
|
|
198
543
|
* Stores the context on the instance under a symbol.
|
|
@@ -202,37 +547,30 @@ declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOption
|
|
|
202
547
|
* afterResolve hooks. Useful for top-level help rendering to avoid
|
|
203
548
|
* long-running side-effects while still evaluating dynamic help text.
|
|
204
549
|
*/
|
|
205
|
-
resolveAndLoad(customOptions?: Partial<TOptions>, opts?:
|
|
206
|
-
runAfterResolve?: boolean;
|
|
207
|
-
}): Promise<GetDotenvCliCtx<TOptions>>;
|
|
550
|
+
resolveAndLoad(customOptions?: Partial<TOptions>, opts?: ResolveAndLoadOptions): Promise<GetDotenvCliCtx<TOptions>>;
|
|
208
551
|
/**
|
|
209
552
|
* Create a Commander Option that computes its description at help time.
|
|
210
553
|
* The returned Option may be configured (conflicts, default, parser) and
|
|
211
554
|
* added via addOption().
|
|
212
555
|
*/
|
|
213
|
-
createDynamicOption(flags:
|
|
214
|
-
|
|
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;
|
|
219
|
-
/**
|
|
220
|
-
* Chainable helper mirroring .option(), but with a dynamic description.
|
|
221
|
-
* Equivalent to addOption(createDynamicOption(...)).
|
|
222
|
-
*/
|
|
223
|
-
dynamicOption(flags: string, desc: (cfg: ResolvedHelpConfig & {
|
|
224
|
-
plugins: Record<string, unknown>;
|
|
225
|
-
}) => 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>;
|
|
226
558
|
/**
|
|
227
559
|
* Evaluate dynamic descriptions for this command and all descendants using
|
|
228
560
|
* the provided resolved configuration. Mutates the Option.description in
|
|
229
561
|
* place so Commander help renders updated text.
|
|
230
562
|
*/
|
|
231
563
|
evaluateDynamicOptions(resolved: ResolvedHelpConfig): void;
|
|
564
|
+
/** Internal: climb to the true root (host) command. */
|
|
565
|
+
private _root;
|
|
232
566
|
/**
|
|
233
567
|
* Retrieve the current invocation context (if any).
|
|
234
568
|
*/
|
|
235
|
-
getCtx(): GetDotenvCliCtx<TOptions
|
|
569
|
+
getCtx(): GetDotenvCliCtx<TOptions>;
|
|
570
|
+
/**
|
|
571
|
+
* Check whether a context has been resolved (non-throwing guard).
|
|
572
|
+
*/
|
|
573
|
+
hasCtx(): boolean;
|
|
236
574
|
/**
|
|
237
575
|
* Retrieve the merged root CLI options bag (if set by passOptions()).
|
|
238
576
|
* Downstream-safe: no generics required.
|
|
@@ -240,25 +578,25 @@ declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOption
|
|
|
240
578
|
getOptions(): GetDotenvCliOptions | undefined;
|
|
241
579
|
/** Internal: set the merged root options bag for this run. */
|
|
242
580
|
_setOptionsBag(bag: GetDotenvCliOptions): void;
|
|
243
|
-
/**
|
|
244
|
-
|
|
581
|
+
/**
|
|
582
|
+
* Convenience helper to create a namespaced subcommand with argument inference.
|
|
583
|
+
* This mirrors Commander generics so downstream chaining stays fully typed.
|
|
584
|
+
*/
|
|
585
|
+
ns<Usage extends string>(name: Usage): GetDotenvCliPublic<TOptions, [
|
|
586
|
+
...TArgs,
|
|
587
|
+
...InferCommandArguments<Usage>
|
|
588
|
+
], {}, TOpts & TGlobal>;
|
|
245
589
|
/**
|
|
246
590
|
* Tag options added during the provided callback as 'app' for grouped help.
|
|
247
591
|
* Allows downstream apps to demarcate their root-level options.
|
|
248
592
|
*/
|
|
249
|
-
tagAppOptions<T>(fn: (root:
|
|
593
|
+
tagAppOptions<T>(fn: (root: CommandUnknownOpts) => T): T;
|
|
250
594
|
/**
|
|
251
595
|
* Branding helper: set CLI name/description/version and optional help header.
|
|
252
596
|
* If version is omitted and importMetaUrl is provided, attempts to read the
|
|
253
597
|
* nearest package.json version (best-effort; non-fatal on failure).
|
|
254
598
|
*/
|
|
255
|
-
brand(args:
|
|
256
|
-
name?: string;
|
|
257
|
-
description?: string;
|
|
258
|
-
version?: string;
|
|
259
|
-
importMetaUrl?: string;
|
|
260
|
-
helpHeader?: string;
|
|
261
|
-
}): Promise<this>;
|
|
599
|
+
brand(args: BrandOptions): Promise<this>;
|
|
262
600
|
/**
|
|
263
601
|
* Insert grouped plugin/app options between "Options" and "Commands" for
|
|
264
602
|
* hybrid ordering. Applies to root and any parent command.
|
|
@@ -272,7 +610,7 @@ declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOption
|
|
|
272
610
|
* Register a plugin for installation (parent level).
|
|
273
611
|
* Installation occurs on first resolveAndLoad() (or explicit install()).
|
|
274
612
|
*/
|
|
275
|
-
use(plugin: GetDotenvCliPlugin<TOptions
|
|
613
|
+
use(plugin: GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal>, override?: PluginNamespaceOverride): this;
|
|
276
614
|
/**
|
|
277
615
|
* Install all registered plugins in parent → children (pre-order).
|
|
278
616
|
* Runs only once per CLI instance.
|
|
@@ -284,132 +622,125 @@ declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOption
|
|
|
284
622
|
private _runAfterResolve;
|
|
285
623
|
}
|
|
286
624
|
|
|
287
|
-
/** src/cliHost/
|
|
288
|
-
*
|
|
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.
|
|
289
631
|
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
|
|
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.
|
|
293
639
|
*/
|
|
294
640
|
|
|
295
641
|
/**
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
|
|
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.
|
|
299
648
|
*
|
|
300
|
-
*
|
|
301
|
-
* to avoid TS2379 under exactOptionalPropertyTypes in downstream consumers.
|
|
649
|
+
* @param s - Input string.
|
|
302
650
|
*/
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
interface GetDotenvCliPlugin<TOptions extends GetDotenvOptions = GetDotenvOptions> {
|
|
323
|
-
id?: string;
|
|
324
|
-
/**
|
|
325
|
-
* Setup phase: register commands and wiring on the provided CLI instance.
|
|
326
|
-
* Runs parent → children (pre-order).
|
|
327
|
-
*/
|
|
328
|
-
setup: (cli: GetDotenvCliPublic<TOptions>) => void | Promise<void>;
|
|
329
|
-
/**
|
|
330
|
-
* After the dotenv context is resolved, initialize any clients/secrets
|
|
331
|
-
* or attach per-plugin state under ctx.plugins (by convention).
|
|
332
|
-
* Runs parent → children (pre-order).
|
|
333
|
-
*/
|
|
334
|
-
afterResolve?: (cli: GetDotenvCliPublic<TOptions>, ctx: GetDotenvCliCtx<TOptions>) => void | Promise<void>;
|
|
335
|
-
/**
|
|
336
|
-
* Zod schema for this plugin's config slice (from config.plugins[id]).
|
|
337
|
-
* Enforced object-like (ZodObject) to simplify code paths and inference.
|
|
338
|
-
*/
|
|
339
|
-
configSchema?: ZodObject;
|
|
340
|
-
/**
|
|
341
|
-
* Compositional children. Installed after the parent per pre-order.
|
|
342
|
-
*/
|
|
343
|
-
children: GetDotenvCliPlugin<TOptions>[];
|
|
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>;
|
|
344
670
|
/**
|
|
345
|
-
*
|
|
671
|
+
* The realized mount path for this plugin (root alias excluded), e.g. "aws/whoami".
|
|
346
672
|
*/
|
|
347
|
-
|
|
673
|
+
path: string;
|
|
348
674
|
}
|
|
675
|
+
|
|
349
676
|
/**
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
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.
|
|
354
682
|
*/
|
|
355
|
-
|
|
356
|
-
|
|
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
|
-
};
|
|
683
|
+
declare const readMergedOptions: (cmd: CommandUnknownOpts) => GetDotenvCliOptions;
|
|
684
|
+
|
|
361
685
|
/**
|
|
362
|
-
*
|
|
363
|
-
*
|
|
686
|
+
* Batch services (neutral): resolve command and shell settings.
|
|
687
|
+
* Shared by the generator path and the batch plugin to avoid circular deps.
|
|
364
688
|
*/
|
|
365
|
-
|
|
366
|
-
children?: GetDotenvCliPlugin<TOptions>[];
|
|
367
|
-
};
|
|
689
|
+
|
|
368
690
|
/**
|
|
369
|
-
*
|
|
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.
|
|
370
693
|
*
|
|
371
|
-
* @
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
* .use(childB);
|
|
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).
|
|
375
697
|
*/
|
|
376
|
-
declare
|
|
377
|
-
configSchema: Schema;
|
|
378
|
-
}): PluginWithInstanceHelpers<TOptions, z.output<Schema>>;
|
|
379
|
-
declare function definePlugin<TOptions extends GetDotenvOptions>(spec: DefineSpec<TOptions>): PluginWithInstanceHelpers<TOptions, {}>;
|
|
380
|
-
|
|
698
|
+
declare const resolveCommand: (scripts: ScriptsTable | undefined, command: string) => string;
|
|
381
699
|
/**
|
|
382
|
-
*
|
|
383
|
-
*
|
|
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).
|
|
384
707
|
*/
|
|
385
|
-
|
|
708
|
+
declare const resolveShell: <TShell extends string | boolean>(scripts: ScriptsTable<TShell> | undefined, command: string, shell: TShell | undefined) => TShell | false;
|
|
386
709
|
|
|
387
710
|
/**
|
|
388
|
-
*
|
|
389
|
-
* - attachRootOptions: installs legacy/base root flags on the command.
|
|
390
|
-
* - passOptions: merges flags (parent \< current), computes dotenv context once,
|
|
391
|
-
* runs validation, and persists merged options for nested flows.
|
|
711
|
+
* Result of CLI option resolution.
|
|
392
712
|
*/
|
|
393
|
-
|
|
713
|
+
interface ResolveCliOptionsResult<T> {
|
|
394
714
|
/**
|
|
395
|
-
*
|
|
396
|
-
*
|
|
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.
|
|
397
718
|
*/
|
|
398
|
-
|
|
719
|
+
merged: T;
|
|
399
720
|
/**
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
* - Persist the merged bag on the current command and on the host (for ergonomics).
|
|
403
|
-
* - Compute the dotenv context once via resolveAndLoad(serviceOptions).
|
|
404
|
-
* - 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.
|
|
405
723
|
*/
|
|
406
|
-
|
|
724
|
+
command?: string;
|
|
407
725
|
}
|
|
408
726
|
/**
|
|
409
|
-
*
|
|
410
|
-
*
|
|
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.
|
|
411
742
|
*/
|
|
412
|
-
declare const
|
|
743
|
+
declare const buildSpawnEnv: (base?: NodeJS.ProcessEnv, overlay?: Record<string, string | undefined>) => NodeJS.ProcessEnv;
|
|
413
744
|
|
|
414
|
-
export { GetDotenvCli, definePlugin, readMergedOptions };
|
|
415
|
-
export type { DefineSpec, GetDotenvCliCtx, GetDotenvCliOptions, GetDotenvCliPlugin, GetDotenvCliPublic, InferPluginConfig, PluginWithInstanceHelpers, 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 };
|