@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/index.d.ts
CHANGED
|
@@ -1,64 +1,146 @@
|
|
|
1
1
|
import { z, ZodObject } from 'zod';
|
|
2
2
|
export { z } from 'zod';
|
|
3
|
-
import { Command, Option } from 'commander';
|
|
3
|
+
import { OptionValues, Command, InferCommandArguments, Option, CommandUnknownOpts } from '@commander-js/extra-typings';
|
|
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>>;
|
|
53
105
|
/**
|
|
54
106
|
* Identity helper to define a scripts table while preserving a concrete TShell
|
|
55
107
|
* type parameter in downstream inference.
|
|
56
108
|
*/
|
|
57
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
|
+
}
|
|
58
138
|
|
|
59
|
-
/**
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
*/
|
|
62
144
|
declare const getDotenvCliOptionsSchemaResolved: z.ZodObject<{
|
|
63
145
|
defaultEnv: z.ZodOptional<z.ZodString>;
|
|
64
146
|
dotenvToken: z.ZodOptional<z.ZodString>;
|
|
@@ -72,7 +154,7 @@ declare const getDotenvCliOptionsSchemaResolved: z.ZodObject<{
|
|
|
72
154
|
excludePublic: z.ZodOptional<z.ZodBoolean>;
|
|
73
155
|
loadProcess: z.ZodOptional<z.ZodBoolean>;
|
|
74
156
|
log: z.ZodOptional<z.ZodBoolean>;
|
|
75
|
-
logger: z.
|
|
157
|
+
logger: z.ZodDefault<z.ZodUnknown>;
|
|
76
158
|
outputPath: z.ZodOptional<z.ZodString>;
|
|
77
159
|
privateToken: z.ZodOptional<z.ZodString>;
|
|
78
160
|
debug: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -97,24 +179,11 @@ declare const getDotenvCliOptionsSchemaResolved: z.ZodObject<{
|
|
|
97
179
|
varsDelimiterPattern: z.ZodOptional<z.ZodString>;
|
|
98
180
|
}, z.core.$strip>;
|
|
99
181
|
|
|
100
|
-
type Scripts = ScriptsTable;
|
|
101
182
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
* shapes that are handled by resolution).
|
|
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.
|
|
106
186
|
*/
|
|
107
|
-
type GetDotenvCliOptions = z.output<typeof getDotenvCliOptionsSchemaResolved> & {
|
|
108
|
-
/**
|
|
109
|
-
* Compile-only overlay for DX: logger narrowed from unknown.
|
|
110
|
-
*/
|
|
111
|
-
logger?: Logger;
|
|
112
|
-
/**
|
|
113
|
-
* Compile-only overlay for DX: scripts narrowed from Record\<string, unknown\>.
|
|
114
|
-
*/
|
|
115
|
-
scripts?: Scripts;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
187
|
declare const getDotenvOptionsSchemaResolved: z.ZodObject<{
|
|
119
188
|
defaultEnv: z.ZodOptional<z.ZodString>;
|
|
120
189
|
dotenvToken: z.ZodOptional<z.ZodString>;
|
|
@@ -128,15 +197,36 @@ declare const getDotenvOptionsSchemaResolved: z.ZodObject<{
|
|
|
128
197
|
excludePublic: z.ZodOptional<z.ZodBoolean>;
|
|
129
198
|
loadProcess: z.ZodOptional<z.ZodBoolean>;
|
|
130
199
|
log: z.ZodOptional<z.ZodBoolean>;
|
|
131
|
-
logger: z.
|
|
200
|
+
logger: z.ZodDefault<z.ZodUnknown>;
|
|
132
201
|
outputPath: z.ZodOptional<z.ZodString>;
|
|
133
202
|
paths: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
134
203
|
privateToken: z.ZodOptional<z.ZodString>;
|
|
135
204
|
vars: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodString>>>;
|
|
136
205
|
}, z.core.$strip>;
|
|
137
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
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Compatibility shape for root options allowing string inputs for vars/paths.
|
|
219
|
+
* Used during CLI argument parsing before normalization.
|
|
220
|
+
*/
|
|
138
221
|
type RootOptionsShapeCompat = Omit<RootOptionsShape, 'vars' | 'paths'> & {
|
|
222
|
+
/**
|
|
223
|
+
* Extra variables as either a space‑delimited string of assignments
|
|
224
|
+
* (e.g., `"FOO=1 BAR=2"`) or an object map of `string | undefined` values.
|
|
225
|
+
*/
|
|
139
226
|
vars?: string | Record<string, string | undefined>;
|
|
227
|
+
/**
|
|
228
|
+
* Dotenv search paths as a space‑delimited string or a pre‑split string[].
|
|
229
|
+
*/
|
|
140
230
|
paths?: string | string[];
|
|
141
231
|
};
|
|
142
232
|
/**
|
|
@@ -150,7 +240,14 @@ type ProcessEnv = Record<string, string | undefined>;
|
|
|
150
240
|
* or `undefined` to unset/skip the variable.
|
|
151
241
|
*/
|
|
152
242
|
type GetDotenvDynamicFunction = (vars: ProcessEnv, env: string | undefined) => string | undefined;
|
|
243
|
+
/**
|
|
244
|
+
* A map of dynamic variable definitions.
|
|
245
|
+
* Keys are variable names; values are either literal strings or functions.
|
|
246
|
+
*/
|
|
153
247
|
type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
|
|
248
|
+
/**
|
|
249
|
+
* Logger interface compatible with `console` or a subset thereof.
|
|
250
|
+
*/
|
|
154
251
|
type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
|
|
155
252
|
/**
|
|
156
253
|
* Canonical programmatic options type (schema-derived).
|
|
@@ -160,7 +257,7 @@ type GetDotenvOptions = z.output<typeof getDotenvOptionsSchemaResolved> & {
|
|
|
160
257
|
/**
|
|
161
258
|
* Compile-time overlay: narrowed logger for DX (schema stores unknown).
|
|
162
259
|
*/
|
|
163
|
-
logger
|
|
260
|
+
logger: Logger;
|
|
164
261
|
/**
|
|
165
262
|
* Compile-time overlay: narrowed dynamic map for DX (schema stores unknown).
|
|
166
263
|
*/
|
|
@@ -189,21 +286,53 @@ declare function defineDynamic<T extends GetDotenvDynamic>(d: T): T;
|
|
|
189
286
|
*
|
|
190
287
|
* Compile-time only; the runtime loader remains schema-driven.
|
|
191
288
|
*/
|
|
192
|
-
|
|
289
|
+
interface GetDotenvConfig<Vars extends ProcessEnv, Env extends string = string> {
|
|
290
|
+
/**
|
|
291
|
+
* Operational root defaults applied by the host (collapsed families; stringly form).
|
|
292
|
+
*/
|
|
293
|
+
rootOptionDefaults?: Partial<RootOptionsShape>;
|
|
294
|
+
/** Token indicating a dotenv file. */
|
|
193
295
|
dotenvToken?: string;
|
|
296
|
+
/** Token indicating private variables. */
|
|
194
297
|
privateToken?: string;
|
|
298
|
+
/** Paths to search for dotenv files. */
|
|
195
299
|
paths?: string | string[];
|
|
300
|
+
/** Whether to load variables into `process.env`. */
|
|
196
301
|
loadProcess?: boolean;
|
|
302
|
+
/** Whether to log loaded variables. */
|
|
197
303
|
log?: boolean;
|
|
304
|
+
/** Shell execution strategy. */
|
|
198
305
|
shell?: string | boolean;
|
|
199
|
-
|
|
306
|
+
/** Scripts table. */
|
|
307
|
+
scripts?: ScriptsTable;
|
|
308
|
+
/** Keys required to be present in the final environment. */
|
|
200
309
|
requiredKeys?: string[];
|
|
310
|
+
/** Validation schema (e.g. Zod). */
|
|
201
311
|
schema?: unknown;
|
|
312
|
+
/** Global variables. */
|
|
202
313
|
vars?: Vars;
|
|
314
|
+
/** Environment-specific variables. */
|
|
203
315
|
envVars?: Record<Env, Partial<Vars>>;
|
|
316
|
+
/** Dynamic variable definitions. */
|
|
204
317
|
dynamic?: DynamicMap<Vars>;
|
|
318
|
+
/** Plugin configuration slices. */
|
|
205
319
|
plugins?: Record<string, unknown>;
|
|
206
|
-
}
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Define a strongly‑typed get‑dotenv configuration document for JS/TS authoring.
|
|
323
|
+
*
|
|
324
|
+
* This helper is compile‑time only: it returns the input unchanged at runtime,
|
|
325
|
+
* but enables rich TypeScript inference for `vars`, `envVars`, and `dynamic`,
|
|
326
|
+
* and validates property names and value shapes as you author the config.
|
|
327
|
+
*
|
|
328
|
+
* @typeParam Vars - The string‑valued env map your project uses (for example,
|
|
329
|
+
* `{ APP_SETTING?: string }`). Keys propagate to `dynamic` function arguments.
|
|
330
|
+
* @typeParam Env - Allowed environment names used for `envVars` (defaults to `string`).
|
|
331
|
+
* @typeParam T - The full config type being produced (defaults to `GetDotenvConfig<Vars, Env>`).
|
|
332
|
+
* This type parameter is rarely supplied explicitly.
|
|
333
|
+
* @param cfg - The configuration object literal.
|
|
334
|
+
* @returns The same `cfg` value, with its type preserved for inference.
|
|
335
|
+
*/
|
|
207
336
|
declare function defineGetDotenvConfig<Vars extends ProcessEnv, Env extends string = string, T extends GetDotenvConfig<Vars, Env> = GetDotenvConfig<Vars, Env>>(cfg: T): T;
|
|
208
337
|
/**
|
|
209
338
|
* Compile-time helper to derive the Vars shape from a typed getdotenv config document.
|
|
@@ -220,76 +349,6 @@ type InferGetDotenvVarsFromConfig<T> = T extends {
|
|
|
220
349
|
*/
|
|
221
350
|
declare const getDotenvCliOptions2Options: ({ paths, pathsDelimiter, pathsDelimiterPattern, vars, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, debug: _debug, scripts: _scripts, ...rest }: RootOptionsShapeCompat) => GetDotenvOptions;
|
|
222
351
|
|
|
223
|
-
/**
|
|
224
|
-
* Recursively expands environment variables in a string. Variables may be
|
|
225
|
-
* presented with optional default as `$VAR[:default]` or `${VAR[:default]}`.
|
|
226
|
-
* Unknown variables will expand to an empty string.
|
|
227
|
-
*
|
|
228
|
-
* @param value - The string to expand.
|
|
229
|
-
* @param ref - The reference object to use for variable expansion.
|
|
230
|
-
* @returns The expanded string.
|
|
231
|
-
*
|
|
232
|
-
* @example
|
|
233
|
-
* ```ts
|
|
234
|
-
* process.env.FOO = 'bar';
|
|
235
|
-
* dotenvExpand('Hello $FOO'); // "Hello bar"
|
|
236
|
-
* dotenvExpand('Hello $BAZ:world'); // "Hello world"
|
|
237
|
-
* ```
|
|
238
|
-
*
|
|
239
|
-
* @remarks
|
|
240
|
-
* The expansion is recursive. If a referenced variable itself contains
|
|
241
|
-
* references, those will also be expanded until a stable value is reached.
|
|
242
|
-
* Escaped references (e.g. `\$FOO`) are preserved as literals.
|
|
243
|
-
*/
|
|
244
|
-
declare const dotenvExpand: (value: string | undefined, ref?: ProcessEnv) => string | undefined;
|
|
245
|
-
/**
|
|
246
|
-
* Recursively expands environment variables in the values of a JSON object.
|
|
247
|
-
* Variables may be presented with optional default as `$VAR[:default]` or
|
|
248
|
-
* `${VAR[:default]}`. Unknown variables will expand to an empty string.
|
|
249
|
-
*
|
|
250
|
-
* @param values - The values object to expand.
|
|
251
|
-
* @param options - Expansion options.
|
|
252
|
-
* @returns The value object with expanded string values.
|
|
253
|
-
*
|
|
254
|
-
* @example
|
|
255
|
-
* ```ts
|
|
256
|
-
* process.env.FOO = 'bar';
|
|
257
|
-
* dotenvExpandAll({ A: '$FOO', B: 'x${FOO}y' });
|
|
258
|
-
* // => { A: "bar", B: "xbary" }
|
|
259
|
-
* ```
|
|
260
|
-
*
|
|
261
|
-
* @remarks
|
|
262
|
-
* Options:
|
|
263
|
-
* - ref: The reference object to use for expansion (defaults to process.env).
|
|
264
|
-
* - progressive: Whether to progressively add expanded values to the set of
|
|
265
|
-
* reference keys.
|
|
266
|
-
*
|
|
267
|
-
* When `progressive` is true, each expanded key becomes available for
|
|
268
|
-
* subsequent expansions in the same object (left-to-right by object key order).
|
|
269
|
-
*/
|
|
270
|
-
declare function dotenvExpandAll<T extends Record<string, string | undefined> | Readonly<Record<string, string | undefined>>>(values: T, options?: {
|
|
271
|
-
ref?: Record<string, string | undefined>;
|
|
272
|
-
progressive?: boolean;
|
|
273
|
-
}): Record<string, string | undefined> & {
|
|
274
|
-
[K in keyof T]: string | undefined;
|
|
275
|
-
};
|
|
276
|
-
/**
|
|
277
|
-
* Recursively expands environment variables in a string using `process.env` as
|
|
278
|
-
* the expansion reference. Variables may be presented with optional default as
|
|
279
|
-
* `$VAR[:default]` or `${VAR[:default]}`. Unknown variables will expand to an
|
|
280
|
-
* empty string.
|
|
281
|
-
*
|
|
282
|
-
* @param value - The string to expand.
|
|
283
|
-
* @returns The expanded string.
|
|
284
|
-
*
|
|
285
|
-
* @example
|
|
286
|
-
* ```ts
|
|
287
|
-
* process.env.FOO = 'bar';
|
|
288
|
-
* dotenvExpandFromProcessEnv('Hello $FOO'); // "Hello bar"
|
|
289
|
-
* ```
|
|
290
|
-
*/
|
|
291
|
-
declare const dotenvExpandFromProcessEnv: (value: string | undefined) => string | undefined;
|
|
292
|
-
|
|
293
352
|
/**
|
|
294
353
|
* Asynchronously process dotenv files of the form `.env[.<ENV>][.<PRIVATE_TOKEN>]`
|
|
295
354
|
*
|
|
@@ -331,35 +390,193 @@ declare function getDotenv<Vars extends ProcessEnv>(options: Partial<GetDotenvOp
|
|
|
331
390
|
vars: Vars;
|
|
332
391
|
}): Promise<ProcessEnv & Vars>;
|
|
333
392
|
|
|
334
|
-
/**
|
|
335
|
-
*
|
|
336
|
-
* Compile-time only; no runtime footprint.
|
|
393
|
+
/**
|
|
394
|
+
* Unify Scripts via the generic ScriptsTable<TShell> so shell types propagate.
|
|
337
395
|
*/
|
|
338
|
-
type
|
|
339
|
-
|
|
340
|
-
|
|
396
|
+
type Scripts = ScriptsTable;
|
|
397
|
+
/**
|
|
398
|
+
* Canonical CLI options type derived from the Zod schema output.
|
|
399
|
+
* Includes CLI-only flags (debug/strict/capture/trace/redaction/entropy),
|
|
400
|
+
* stringly paths/vars, and inherited programmatic fields (minus normalized
|
|
401
|
+
* shapes that are handled by resolution).
|
|
402
|
+
*/
|
|
403
|
+
type GetDotenvCliOptions = z.output<typeof getDotenvCliOptionsSchemaResolved> & {
|
|
404
|
+
/**
|
|
405
|
+
* Compile-only overlay for DX: logger narrowed from unknown.
|
|
406
|
+
*/
|
|
407
|
+
logger: Logger;
|
|
408
|
+
/**
|
|
409
|
+
* Compile-only overlay for DX: scripts narrowed from Record\<string, unknown\>.
|
|
410
|
+
*/
|
|
411
|
+
scripts?: Scripts;
|
|
412
|
+
};
|
|
341
413
|
|
|
342
414
|
/**
|
|
343
|
-
*
|
|
344
|
-
*
|
|
415
|
+
* Configuration context used for generating dynamic help descriptions.
|
|
416
|
+
* Contains merged CLI options and plugin configuration slices.
|
|
345
417
|
*
|
|
346
|
-
* @
|
|
347
|
-
* @param value - Input value (object/array/primitive).
|
|
348
|
-
* @param envRef - Reference environment for interpolation.
|
|
349
|
-
* @returns A new value with string leaves interpolated.
|
|
418
|
+
* @public
|
|
350
419
|
*/
|
|
351
|
-
declare const interpolateDeep: <T>(value: T, envRef: ProcessEnv) => T;
|
|
352
|
-
|
|
353
420
|
type ResolvedHelpConfig = Partial<GetDotenvCliOptions> & {
|
|
421
|
+
/**
|
|
422
|
+
* Per‑plugin configuration slices keyed by realized mount path
|
|
423
|
+
* (e.g., `"aws"` or `"aws/whoami"`), used for dynamic help text.
|
|
424
|
+
*/
|
|
354
425
|
plugins: Record<string, unknown>;
|
|
355
426
|
};
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
427
|
+
|
|
428
|
+
/** src/cliHost/definePlugin/contracts.ts
|
|
429
|
+
* Public contracts for plugin authoring (types only).
|
|
430
|
+
* - No runtime logic or state.
|
|
431
|
+
* - Safe to import broadly without introducing cycles.
|
|
432
|
+
*/
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Options for resolving and loading the configuration.
|
|
436
|
+
*
|
|
437
|
+
* @public
|
|
438
|
+
*/
|
|
439
|
+
interface ResolveAndLoadOptions {
|
|
440
|
+
/**
|
|
441
|
+
* When false, skips running plugin afterResolve hooks.
|
|
442
|
+
* Useful for top-level help rendering to avoid long-running side-effects
|
|
443
|
+
* while still evaluating dynamic help text.
|
|
444
|
+
*
|
|
445
|
+
* @default true
|
|
446
|
+
*/
|
|
447
|
+
runAfterResolve?: boolean;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Structural public interface for the host exposed to plugins.
|
|
451
|
+
* - Extends Commander.Command so plugins can attach options/commands/hooks.
|
|
452
|
+
* - Adds host-specific helpers used by built-in plugins.
|
|
453
|
+
*
|
|
454
|
+
* Purpose: remove nominal class identity (private fields) from the plugin seam
|
|
455
|
+
* to avoid TS2379 under exactOptionalPropertyTypes in downstream consumers.
|
|
456
|
+
*/
|
|
457
|
+
interface GetDotenvCliPublic<TOptions extends GetDotenvOptions = GetDotenvOptions, TArgs extends unknown[] = [], TOpts extends OptionValues = {}, TGlobal extends OptionValues = {}> extends Command<TArgs, TOpts, TGlobal> {
|
|
458
|
+
/**
|
|
459
|
+
* Create a namespaced child command with argument inference.
|
|
460
|
+
* Mirrors Commander generics so downstream chaining remains fully typed.
|
|
461
|
+
*/
|
|
462
|
+
ns<Usage extends string>(name: Usage): GetDotenvCliPublic<TOptions, [
|
|
463
|
+
...TArgs,
|
|
464
|
+
...InferCommandArguments<Usage>
|
|
465
|
+
], {}, TOpts & TGlobal>;
|
|
466
|
+
/** Return the current context; throws if not yet resolved. */
|
|
467
|
+
getCtx(): GetDotenvCliCtx<TOptions>;
|
|
468
|
+
/** Check whether a context has been resolved (non-throwing). */
|
|
469
|
+
hasCtx(): boolean;
|
|
470
|
+
resolveAndLoad(customOptions?: Partial<TOptions>, opts?: ResolveAndLoadOptions): Promise<GetDotenvCliCtx<TOptions>>;
|
|
471
|
+
setOptionGroup(opt: Option, group: string): void;
|
|
472
|
+
/**
|
|
473
|
+
* Create a dynamic option whose description is computed at help time
|
|
474
|
+
* from the resolved configuration.
|
|
475
|
+
*/
|
|
476
|
+
createDynamicOption<Usage extends string>(flags: Usage, desc: (cfg: ResolvedHelpConfig) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option<Usage>;
|
|
477
|
+
createDynamicOption<Usage extends string, TValue = unknown>(flags: Usage, desc: (cfg: ResolvedHelpConfig) => string, parser: (value: string, previous?: TValue) => TValue, defaultValue?: TValue): Option<Usage>;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Optional overrides for plugin composition.
|
|
481
|
+
*
|
|
482
|
+
* @public
|
|
483
|
+
*/
|
|
484
|
+
interface PluginNamespaceOverride {
|
|
485
|
+
/**
|
|
486
|
+
* Override the default namespace for this plugin instance.
|
|
487
|
+
*/
|
|
488
|
+
ns?: string;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* An entry in the plugin children array.
|
|
492
|
+
*
|
|
493
|
+
* @public
|
|
494
|
+
*/
|
|
495
|
+
interface PluginChildEntry<TOptions extends GetDotenvOptions = GetDotenvOptions, TArgs extends unknown[] = [], TOpts extends OptionValues = {}, TGlobal extends OptionValues = {}> {
|
|
496
|
+
/** The child plugin instance to mount under this parent. */
|
|
497
|
+
plugin: GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal>;
|
|
498
|
+
/**
|
|
499
|
+
* Optional namespace override for the child when mounted under the parent.
|
|
500
|
+
* When provided, this name is used instead of the child's default `ns`.
|
|
501
|
+
*/
|
|
502
|
+
override: PluginNamespaceOverride | undefined;
|
|
503
|
+
}
|
|
504
|
+
/** Public plugin contract used by the GetDotenv CLI host. */
|
|
505
|
+
interface GetDotenvCliPlugin<TOptions extends GetDotenvOptions = GetDotenvOptions, TArgs extends unknown[] = [], TOpts extends OptionValues = {}, TGlobal extends OptionValues = {}> {
|
|
506
|
+
/** Namespace (required): the command name where this plugin is mounted. */
|
|
507
|
+
ns: string;
|
|
508
|
+
/**
|
|
509
|
+
* Setup phase: register commands and wiring on the provided mount.
|
|
510
|
+
* Runs parent → children (pre-order). Return nothing (void).
|
|
511
|
+
*/
|
|
512
|
+
setup: (cli: GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal>) => void | Promise<void>;
|
|
513
|
+
/**
|
|
514
|
+
* After the dotenv context is resolved, initialize any clients/secrets
|
|
515
|
+
* or attach per-plugin state under ctx.plugins (by convention).
|
|
516
|
+
* Runs parent → children (pre-order).
|
|
517
|
+
*/
|
|
518
|
+
afterResolve?: (cli: GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal>, ctx: GetDotenvCliCtx<TOptions>) => void | Promise<void>;
|
|
519
|
+
/** Zod schema for this plugin's config slice (from config.plugins[…]). */
|
|
520
|
+
configSchema?: ZodObject;
|
|
521
|
+
/**
|
|
522
|
+
* Compositional children, with optional per-child overrides (e.g., ns).
|
|
523
|
+
* Installed after the parent per pre-order.
|
|
524
|
+
*/
|
|
525
|
+
children: Array<PluginChildEntry<TOptions, TArgs, TOpts, TGlobal>>;
|
|
526
|
+
/**
|
|
527
|
+
* Compose a child plugin with optional override (ns). Returns the parent
|
|
528
|
+
* to enable chaining.
|
|
529
|
+
*/
|
|
530
|
+
use: (child: GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal>, override?: PluginNamespaceOverride) => GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal>;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Compile-time helper type: the plugin object returned by definePlugin always
|
|
534
|
+
* includes the instance-bound helpers as required members. Keeping the public
|
|
535
|
+
* interface optional preserves compatibility for ad-hoc/test plugins, while
|
|
536
|
+
* return types from definePlugin provide stronger DX for shipped/typed plugins.
|
|
537
|
+
*/
|
|
538
|
+
interface PluginWithInstanceHelpers<TOptions extends GetDotenvOptions = GetDotenvOptions, TConfig = unknown, TArgs extends unknown[] = [], TOpts extends OptionValues = {}, TGlobal extends OptionValues = {}> extends GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal> {
|
|
539
|
+
readConfig<TCfg = TConfig>(cli: GetDotenvCliPublic<TOptions, unknown[], OptionValues, OptionValues>): Readonly<TCfg>;
|
|
540
|
+
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>;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Public spec type for defining a plugin with compositional helpers.
|
|
544
|
+
*/
|
|
545
|
+
type DefineSpec<TOptions extends GetDotenvOptions = GetDotenvOptions, TArgs extends unknown[] = [], TOpts extends OptionValues = {}, TGlobal extends OptionValues = {}> = Omit<GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal>, 'children' | 'use' | 'setup'> & {
|
|
546
|
+
/**
|
|
547
|
+
* Required namespace and setup function. The host creates the mount and
|
|
548
|
+
* passes it into setup; return void | Promise<void>.
|
|
549
|
+
*/
|
|
550
|
+
ns: string;
|
|
551
|
+
setup: (cli: GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal>) => void | Promise<void>;
|
|
362
552
|
};
|
|
553
|
+
/**
|
|
554
|
+
* Helper to infer the configuration type from a `PluginWithInstanceHelpers` type.
|
|
555
|
+
*/
|
|
556
|
+
type InferPluginConfig<P> = P extends PluginWithInstanceHelpers<GetDotenvOptions, infer C> ? Readonly<C> : never;
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Define a GetDotenv CLI plugin with compositional helpers.
|
|
560
|
+
*
|
|
561
|
+
* @example
|
|
562
|
+
* const p = definePlugin(\{ ns: 'aws', setup(cli) \{ /* wire subcommands *\/ \} \})
|
|
563
|
+
* .use(child, \{ ns: 'whoami' \});
|
|
564
|
+
*/
|
|
565
|
+
declare function definePlugin<TOptions extends GetDotenvOptions, Schema extends ZodObject>(spec: Omit<DefineSpec<TOptions>, 'configSchema'> & {
|
|
566
|
+
configSchema: Schema;
|
|
567
|
+
}): PluginWithInstanceHelpers<TOptions, z.output<Schema>>;
|
|
568
|
+
declare function definePlugin<TOptions extends GetDotenvOptions>(spec: DefineSpec<TOptions>): PluginWithInstanceHelpers<TOptions, {}>;
|
|
569
|
+
|
|
570
|
+
/** src/cliHost/GetDotenvCli.ts
|
|
571
|
+
* Plugin-first CLI host for get-dotenv with Commander generics preserved.
|
|
572
|
+
* Public surface implements GetDotenvCliPublic and provides:
|
|
573
|
+
* - attachRootOptions (builder-only; no public override wiring)
|
|
574
|
+
* - resolveAndLoad (strict resolve + context compute)
|
|
575
|
+
* - getCtx/hasCtx accessors
|
|
576
|
+
* - ns() for typed subcommand creation with duplicate-name guard
|
|
577
|
+
* - grouped help rendering with dynamic option descriptions
|
|
578
|
+
*/
|
|
579
|
+
|
|
363
580
|
declare const CTX_SYMBOL: unique symbol;
|
|
364
581
|
declare const OPTS_SYMBOL: unique symbol;
|
|
365
582
|
declare const HELP_HEADER_SYMBOL: unique symbol;
|
|
@@ -372,11 +589,13 @@ declare const HELP_HEADER_SYMBOL: unique symbol;
|
|
|
372
589
|
* - Provide a namespacing helper (ns).
|
|
373
590
|
* - Support composable plugins with parent → children install and afterResolve.
|
|
374
591
|
*/
|
|
375
|
-
declare class GetDotenvCli
|
|
592
|
+
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> {
|
|
376
593
|
/** Registered top-level plugins (composition happens via .use()) */
|
|
377
594
|
private _plugins;
|
|
378
595
|
/** One-time installation guard */
|
|
379
596
|
private _installed;
|
|
597
|
+
/** In-flight installation promise to guard against concurrent installs */
|
|
598
|
+
private _installing?;
|
|
380
599
|
/** Optional header line to prepend in help output */
|
|
381
600
|
private [HELP_HEADER_SYMBOL];
|
|
382
601
|
/** Context/options stored under symbols (typed) */
|
|
@@ -386,8 +605,13 @@ declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOption
|
|
|
386
605
|
* Create a subcommand using the same subclass, preserving helpers like
|
|
387
606
|
* dynamicOption on children.
|
|
388
607
|
*/
|
|
389
|
-
createCommand(name?: string):
|
|
608
|
+
createCommand(name?: string): GetDotenvCli<TOptions>;
|
|
390
609
|
constructor(alias?: string);
|
|
610
|
+
/**
|
|
611
|
+
* Attach legacy/base root flags to this CLI instance.
|
|
612
|
+
* Delegates to the pure builder in attachRootOptions.ts.
|
|
613
|
+
*/
|
|
614
|
+
attachRootOptions(defaults?: Partial<RootOptionsShape>): this;
|
|
391
615
|
/**
|
|
392
616
|
* Resolve options (strict) and compute dotenv context.
|
|
393
617
|
* Stores the context on the instance under a symbol.
|
|
@@ -397,37 +621,30 @@ declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOption
|
|
|
397
621
|
* afterResolve hooks. Useful for top-level help rendering to avoid
|
|
398
622
|
* long-running side-effects while still evaluating dynamic help text.
|
|
399
623
|
*/
|
|
400
|
-
resolveAndLoad(customOptions?: Partial<TOptions>, opts?:
|
|
401
|
-
runAfterResolve?: boolean;
|
|
402
|
-
}): Promise<GetDotenvCliCtx<TOptions>>;
|
|
624
|
+
resolveAndLoad(customOptions?: Partial<TOptions>, opts?: ResolveAndLoadOptions): Promise<GetDotenvCliCtx<TOptions>>;
|
|
403
625
|
/**
|
|
404
626
|
* Create a Commander Option that computes its description at help time.
|
|
405
627
|
* The returned Option may be configured (conflicts, default, parser) and
|
|
406
628
|
* added via addOption().
|
|
407
629
|
*/
|
|
408
|
-
createDynamicOption(flags:
|
|
409
|
-
|
|
410
|
-
}) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option;
|
|
411
|
-
createDynamicOption<TValue = unknown>(flags: string, desc: (cfg: ResolvedHelpConfig & {
|
|
412
|
-
plugins: Record<string, unknown>;
|
|
413
|
-
}) => string, parser: (value: string, previous?: TValue) => TValue, defaultValue?: TValue): Option;
|
|
414
|
-
/**
|
|
415
|
-
* Chainable helper mirroring .option(), but with a dynamic description.
|
|
416
|
-
* Equivalent to addOption(createDynamicOption(...)).
|
|
417
|
-
*/
|
|
418
|
-
dynamicOption(flags: string, desc: (cfg: ResolvedHelpConfig & {
|
|
419
|
-
plugins: Record<string, unknown>;
|
|
420
|
-
}) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): this;
|
|
630
|
+
createDynamicOption<Usage extends string>(flags: Usage, desc: (cfg: ResolvedHelpConfig) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option<Usage>;
|
|
631
|
+
createDynamicOption<Usage extends string, TValue = unknown>(flags: Usage, desc: (cfg: ResolvedHelpConfig) => string, parser: (value: string, previous?: TValue) => TValue, defaultValue?: TValue): Option<Usage>;
|
|
421
632
|
/**
|
|
422
633
|
* Evaluate dynamic descriptions for this command and all descendants using
|
|
423
634
|
* the provided resolved configuration. Mutates the Option.description in
|
|
424
635
|
* place so Commander help renders updated text.
|
|
425
636
|
*/
|
|
426
637
|
evaluateDynamicOptions(resolved: ResolvedHelpConfig): void;
|
|
638
|
+
/** Internal: climb to the true root (host) command. */
|
|
639
|
+
private _root;
|
|
427
640
|
/**
|
|
428
641
|
* Retrieve the current invocation context (if any).
|
|
429
642
|
*/
|
|
430
|
-
getCtx(): GetDotenvCliCtx<TOptions
|
|
643
|
+
getCtx(): GetDotenvCliCtx<TOptions>;
|
|
644
|
+
/**
|
|
645
|
+
* Check whether a context has been resolved (non-throwing guard).
|
|
646
|
+
*/
|
|
647
|
+
hasCtx(): boolean;
|
|
431
648
|
/**
|
|
432
649
|
* Retrieve the merged root CLI options bag (if set by passOptions()).
|
|
433
650
|
* Downstream-safe: no generics required.
|
|
@@ -435,25 +652,25 @@ declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOption
|
|
|
435
652
|
getOptions(): GetDotenvCliOptions | undefined;
|
|
436
653
|
/** Internal: set the merged root options bag for this run. */
|
|
437
654
|
_setOptionsBag(bag: GetDotenvCliOptions): void;
|
|
438
|
-
/**
|
|
439
|
-
|
|
655
|
+
/**
|
|
656
|
+
* Convenience helper to create a namespaced subcommand with argument inference.
|
|
657
|
+
* This mirrors Commander generics so downstream chaining stays fully typed.
|
|
658
|
+
*/
|
|
659
|
+
ns<Usage extends string>(name: Usage): GetDotenvCliPublic<TOptions, [
|
|
660
|
+
...TArgs,
|
|
661
|
+
...InferCommandArguments<Usage>
|
|
662
|
+
], {}, TOpts & TGlobal>;
|
|
440
663
|
/**
|
|
441
664
|
* Tag options added during the provided callback as 'app' for grouped help.
|
|
442
665
|
* Allows downstream apps to demarcate their root-level options.
|
|
443
666
|
*/
|
|
444
|
-
tagAppOptions<T>(fn: (root:
|
|
667
|
+
tagAppOptions<T>(fn: (root: CommandUnknownOpts) => T): T;
|
|
445
668
|
/**
|
|
446
669
|
* Branding helper: set CLI name/description/version and optional help header.
|
|
447
670
|
* If version is omitted and importMetaUrl is provided, attempts to read the
|
|
448
671
|
* nearest package.json version (best-effort; non-fatal on failure).
|
|
449
672
|
*/
|
|
450
|
-
brand(args:
|
|
451
|
-
name?: string;
|
|
452
|
-
description?: string;
|
|
453
|
-
version?: string;
|
|
454
|
-
importMetaUrl?: string;
|
|
455
|
-
helpHeader?: string;
|
|
456
|
-
}): Promise<this>;
|
|
673
|
+
brand(args: BrandOptions): Promise<this>;
|
|
457
674
|
/**
|
|
458
675
|
* Insert grouped plugin/app options between "Options" and "Commands" for
|
|
459
676
|
* hybrid ordering. Applies to root and any parent command.
|
|
@@ -467,7 +684,7 @@ declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOption
|
|
|
467
684
|
* Register a plugin for installation (parent level).
|
|
468
685
|
* Installation occurs on first resolveAndLoad() (or explicit install()).
|
|
469
686
|
*/
|
|
470
|
-
use(plugin: GetDotenvCliPlugin<TOptions
|
|
687
|
+
use(plugin: GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal>, override?: PluginNamespaceOverride): this;
|
|
471
688
|
/**
|
|
472
689
|
* Install all registered plugins in parent → children (pre-order).
|
|
473
690
|
* Runs only once per CLI instance.
|
|
@@ -479,152 +696,216 @@ declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOption
|
|
|
479
696
|
private _runAfterResolve;
|
|
480
697
|
}
|
|
481
698
|
|
|
482
|
-
/**
|
|
483
|
-
*
|
|
699
|
+
/**
|
|
700
|
+
* Retrieve the merged root options bag from the current command context.
|
|
701
|
+
* Climbs to the root `GetDotenvCli` instance to access the persisted options.
|
|
484
702
|
*
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
* nominal class identity issues (private fields) in downstream consumers.
|
|
703
|
+
* @param cmd - The current command instance (thisCommand).
|
|
704
|
+
* @throws Error if the root is not a GetDotenvCli or options are missing.
|
|
488
705
|
*/
|
|
706
|
+
declare const readMergedOptions: (cmd: CommandUnknownOpts) => GetDotenvCliOptions;
|
|
489
707
|
|
|
490
708
|
/**
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
*
|
|
709
|
+
* Build a sanitized environment object for spawning child processes.
|
|
710
|
+
* Merges `base` and `overlay`, drops undefined values, and handles platform-specific
|
|
711
|
+
* normalization (e.g. case-insensitivity on Windows).
|
|
494
712
|
*
|
|
495
|
-
*
|
|
496
|
-
*
|
|
713
|
+
* @param base - Base environment (usually `process.env`).
|
|
714
|
+
* @param overlay - Environment variables to overlay.
|
|
497
715
|
*/
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
id?: string;
|
|
716
|
+
declare const buildSpawnEnv: (base?: NodeJS.ProcessEnv, overlay?: Record<string, string | undefined>) => NodeJS.ProcessEnv;
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Create a get-dotenv CLI host with included plugins.
|
|
720
|
+
*
|
|
721
|
+
* Options:
|
|
722
|
+
* - alias: command name used for help/argv scaffolding (default: "getdotenv")
|
|
723
|
+
* - branding: optional help header; when omitted, brand() uses "<alias> v<version>"
|
|
724
|
+
*
|
|
725
|
+
* Usage:
|
|
726
|
+
* ```ts
|
|
727
|
+
* import { createCli } from '@karmaniverous/get-dotenv';
|
|
728
|
+
*
|
|
729
|
+
* await createCli({
|
|
730
|
+
* alias: 'getdotenv',
|
|
731
|
+
* branding: 'getdotenv vX.Y.Z'
|
|
732
|
+
* })();
|
|
733
|
+
* ```
|
|
734
|
+
*/
|
|
735
|
+
type CreateCliOptions = {
|
|
519
736
|
/**
|
|
520
|
-
*
|
|
521
|
-
*
|
|
737
|
+
* CLI command name used for help and argv scaffolding.
|
|
738
|
+
* Defaults to `'getdotenv'` when omitted.
|
|
522
739
|
*/
|
|
523
|
-
|
|
740
|
+
alias?: string;
|
|
524
741
|
/**
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
* Runs parent → children (pre-order).
|
|
742
|
+
* Optional help header text. When omitted, brand() uses
|
|
743
|
+
* `"<alias> v<resolved-version>"` if a version can be read.
|
|
528
744
|
*/
|
|
529
|
-
|
|
745
|
+
branding?: string;
|
|
530
746
|
/**
|
|
531
|
-
*
|
|
532
|
-
*
|
|
747
|
+
* Optional composer to wire the CLI (plugins/options). If not provided,
|
|
748
|
+
* the shipped default wiring is applied. Any `configureOutput`/`exitOverride`
|
|
749
|
+
* you call here override the defaults.
|
|
533
750
|
*/
|
|
534
|
-
|
|
751
|
+
compose?: (program: GetDotenvCli) => GetDotenvCli;
|
|
535
752
|
/**
|
|
536
|
-
*
|
|
753
|
+
* Root defaults applied once before composition. These are used by flag declaration
|
|
754
|
+
* and merge-time defaults (and top-level -h parity labels).
|
|
755
|
+
* Note: shipped CLI does not force loadProcess OFF; base defaults apply unless set here.
|
|
537
756
|
*/
|
|
538
|
-
|
|
757
|
+
rootOptionDefaults?: Partial<RootOptionsShape>;
|
|
539
758
|
/**
|
|
540
|
-
*
|
|
759
|
+
* Visibility map to hide families/singles from root help. When a key is false,
|
|
760
|
+
* the corresponding option(s) are hidden (via hideHelp) after flags are declared.
|
|
541
761
|
*/
|
|
542
|
-
|
|
543
|
-
}
|
|
762
|
+
rootOptionVisibility?: Partial<Record<keyof RootOptionsShape, boolean>>;
|
|
763
|
+
};
|
|
544
764
|
/**
|
|
545
|
-
*
|
|
546
|
-
*
|
|
547
|
-
*
|
|
548
|
-
* return types from definePlugin provide stronger DX for shipped/typed plugins.
|
|
765
|
+
* Create a configured get-dotenv CLI host.
|
|
766
|
+
* Applies defaults, installs root hooks, and composes plugins.
|
|
767
|
+
* Returns a runner function that accepts an argv array.
|
|
549
768
|
*/
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
createPluginDynamicOption<TCfg = TConfig>(cli: GetDotenvCliPublic<TOptions>, flags: string, desc: (cfg: ResolvedHelpConfig & {
|
|
553
|
-
plugins: Record<string, unknown>;
|
|
554
|
-
}, pluginCfg: Readonly<TCfg>) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option;
|
|
555
|
-
};
|
|
769
|
+
declare function createCli(opts?: CreateCliOptions): (argv?: string[]) => Promise<void>;
|
|
770
|
+
|
|
556
771
|
/**
|
|
557
|
-
*
|
|
558
|
-
*
|
|
772
|
+
* Base root CLI defaults (shared; kept untyped here to avoid cross-layer deps).
|
|
773
|
+
* Used as the bottom layer for CLI option resolution.
|
|
559
774
|
*/
|
|
560
|
-
type DefineSpec<TOptions extends GetDotenvOptions = GetDotenvOptions> = Omit<GetDotenvCliPlugin<TOptions>, 'children' | 'use'> & {
|
|
561
|
-
children?: GetDotenvCliPlugin<TOptions>[];
|
|
562
|
-
};
|
|
563
775
|
/**
|
|
564
|
-
*
|
|
776
|
+
* Default values for root CLI options used by the host and helpers as the
|
|
777
|
+
* baseline layer during option resolution.
|
|
565
778
|
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
* .use(childB);
|
|
779
|
+
* These defaults correspond to the "stringly" root surface (see `RootOptionsShape`)
|
|
780
|
+
* and are merged by precedence with create-time overrides and any discovered
|
|
781
|
+
* configuration `rootOptionDefaults` before CLI flags are applied.
|
|
570
782
|
*/
|
|
571
|
-
declare
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
783
|
+
declare const baseRootOptionDefaults: {
|
|
784
|
+
readonly dotenvToken: ".env";
|
|
785
|
+
readonly loadProcess: true;
|
|
786
|
+
readonly logger: Console;
|
|
787
|
+
readonly warnEntropy: true;
|
|
788
|
+
readonly entropyThreshold: 3.8;
|
|
789
|
+
readonly entropyMinLength: 16;
|
|
790
|
+
readonly entropyWhitelist: readonly ["^GIT_", "^npm_", "^CI$", "SHLVL"];
|
|
791
|
+
readonly paths: "./";
|
|
792
|
+
readonly pathsDelimiter: " ";
|
|
793
|
+
readonly privateToken: "local";
|
|
794
|
+
readonly scripts: {
|
|
795
|
+
readonly 'git-status': {
|
|
796
|
+
readonly cmd: "git branch --show-current && git status -s -u";
|
|
797
|
+
readonly shell: true;
|
|
798
|
+
};
|
|
799
|
+
};
|
|
800
|
+
readonly shell: true;
|
|
801
|
+
readonly vars: "";
|
|
802
|
+
readonly varsAssignor: "=";
|
|
803
|
+
readonly varsDelimiter: " ";
|
|
804
|
+
};
|
|
575
805
|
|
|
576
806
|
/**
|
|
577
|
-
*
|
|
578
|
-
*
|
|
807
|
+
* Recursively expands environment variables in a string. Variables may be
|
|
808
|
+
* presented with optional default as `$VAR[:default]` or `${VAR[:default]}`.
|
|
809
|
+
* Unknown variables will expand to an empty string.
|
|
810
|
+
*
|
|
811
|
+
* @param value - The string to expand.
|
|
812
|
+
* @param ref - The reference object to use for variable expansion.
|
|
813
|
+
* @returns The expanded string.
|
|
814
|
+
*
|
|
815
|
+
* @example
|
|
816
|
+
* ```ts
|
|
817
|
+
* process.env.FOO = 'bar';
|
|
818
|
+
* dotenvExpand('Hello $FOO'); // "Hello bar"
|
|
819
|
+
* dotenvExpand('Hello $BAZ:world'); // "Hello world"
|
|
820
|
+
* ```
|
|
821
|
+
*
|
|
822
|
+
* @remarks
|
|
823
|
+
* The expansion is recursive. If a referenced variable itself contains
|
|
824
|
+
* references, those will also be expanded until a stable value is reached.
|
|
825
|
+
* Escaped references (e.g. `\$FOO`) are preserved as literals.
|
|
579
826
|
*/
|
|
580
|
-
|
|
581
|
-
|
|
827
|
+
declare const dotenvExpand: (value: string | undefined, ref?: ProcessEnv) => string | undefined;
|
|
582
828
|
/**
|
|
583
|
-
*
|
|
584
|
-
*
|
|
585
|
-
*
|
|
586
|
-
* runs validation, and persists merged options for nested flows.
|
|
829
|
+
* Options for {@link dotenvExpandAll}.
|
|
830
|
+
*
|
|
831
|
+
* @public
|
|
587
832
|
*/
|
|
588
|
-
|
|
833
|
+
interface DotenvExpandAllOptions {
|
|
589
834
|
/**
|
|
590
|
-
*
|
|
591
|
-
* baseRootOptionDefaults when none are provided.
|
|
835
|
+
* The reference object to use for expansion (defaults to process.env).
|
|
592
836
|
*/
|
|
593
|
-
|
|
837
|
+
ref?: Record<string, string | undefined>;
|
|
594
838
|
/**
|
|
595
|
-
*
|
|
596
|
-
* - Merge options (parent round-trip + current invocation) using resolveCliOptions.
|
|
597
|
-
* - Persist the merged bag on the current command and on the host (for ergonomics).
|
|
598
|
-
* - Compute the dotenv context once via resolveAndLoad(serviceOptions).
|
|
599
|
-
* - Validate the composed env against discovered config (warn or --strict fail).
|
|
839
|
+
* Whether to progressively add expanded values to the set of reference keys.
|
|
600
840
|
*/
|
|
601
|
-
|
|
841
|
+
progressive?: boolean;
|
|
602
842
|
}
|
|
603
843
|
/**
|
|
604
|
-
*
|
|
605
|
-
*
|
|
844
|
+
* Recursively expands environment variables in the values of a JSON object.
|
|
845
|
+
* Variables may be presented with optional default as `$VAR[:default]` or
|
|
846
|
+
* `${VAR[:default]}`. Unknown variables will expand to an empty string.
|
|
847
|
+
*
|
|
848
|
+
* @param values - The values object to expand.
|
|
849
|
+
* @param options - Expansion options.
|
|
850
|
+
* @returns The value object with expanded string values.
|
|
851
|
+
*
|
|
852
|
+
* @example
|
|
853
|
+
* ```ts
|
|
854
|
+
* process.env.FOO = 'bar';
|
|
855
|
+
* dotenvExpandAll({ A: '$FOO', B: 'x${FOO}y' });
|
|
856
|
+
* // => { A: "bar", B: "xbary" }
|
|
857
|
+
* ```
|
|
858
|
+
*
|
|
859
|
+
* @remarks
|
|
860
|
+
* Options:
|
|
861
|
+
* - ref: The reference object to use for expansion (defaults to process.env).
|
|
862
|
+
* - progressive: Whether to progressively add expanded values to the set of
|
|
863
|
+
* reference keys.
|
|
864
|
+
*
|
|
865
|
+
* When `progressive` is true, each expanded key becomes available for
|
|
866
|
+
* subsequent expansions in the same object (left-to-right by object key order).
|
|
867
|
+
*/
|
|
868
|
+
declare function dotenvExpandAll<T extends Record<string, string | undefined> | Readonly<Record<string, string | undefined>>>(values: T, options?: DotenvExpandAllOptions): Record<string, string | undefined> & {
|
|
869
|
+
[K in keyof T]: string | undefined;
|
|
870
|
+
};
|
|
871
|
+
/**
|
|
872
|
+
* Recursively expands environment variables in a string using `process.env` as
|
|
873
|
+
* the expansion reference. Variables may be presented with optional default as
|
|
874
|
+
* `$VAR[:default]` or `${VAR[:default]}`. Unknown variables will expand to an
|
|
875
|
+
* empty string.
|
|
876
|
+
*
|
|
877
|
+
* @param value - The string to expand.
|
|
878
|
+
* @returns The expanded string.
|
|
879
|
+
*
|
|
880
|
+
* @example
|
|
881
|
+
* ```ts
|
|
882
|
+
* process.env.FOO = 'bar';
|
|
883
|
+
* dotenvExpandFromProcessEnv('Hello $FOO'); // "Hello bar"
|
|
884
|
+
* ```
|
|
606
885
|
*/
|
|
607
|
-
declare const
|
|
886
|
+
declare const dotenvExpandFromProcessEnv: (value: string | undefined) => string | undefined;
|
|
608
887
|
|
|
609
888
|
/**
|
|
610
|
-
*
|
|
889
|
+
* Deep interpolation utility for string leaves.
|
|
890
|
+
* - Expands string values using dotenv-style expansion against the provided envRef.
|
|
891
|
+
* - Preserves non-strings as-is.
|
|
892
|
+
* - Does not recurse into arrays (arrays are returned unchanged).
|
|
611
893
|
*
|
|
612
|
-
*
|
|
613
|
-
* -
|
|
614
|
-
* -
|
|
894
|
+
* Intended for:
|
|
895
|
+
* - Phase C option/config interpolation after composing ctx.dotenv.
|
|
896
|
+
* - Per-plugin config slice interpolation before afterResolve.
|
|
897
|
+
*/
|
|
898
|
+
|
|
899
|
+
/**
|
|
900
|
+
* Deeply interpolate string leaves against envRef.
|
|
901
|
+
* Arrays are not recursed into; they are returned unchanged.
|
|
615
902
|
*
|
|
616
|
-
*
|
|
617
|
-
*
|
|
618
|
-
*
|
|
619
|
-
*
|
|
903
|
+
* @typeParam T - Shape of the input value.
|
|
904
|
+
* @param value - Input value (object/array/primitive).
|
|
905
|
+
* @param envRef - Reference environment for interpolation.
|
|
906
|
+
* @returns A new value with string leaves interpolated.
|
|
620
907
|
*/
|
|
621
|
-
|
|
622
|
-
alias?: string;
|
|
623
|
-
branding?: string;
|
|
624
|
-
};
|
|
625
|
-
declare function createCli(opts?: CreateCliOptions): {
|
|
626
|
-
run: (argv: string[]) => Promise<void>;
|
|
627
|
-
};
|
|
908
|
+
declare const interpolateDeep: <T>(value: T, envRef: ProcessEnv) => T;
|
|
628
909
|
|
|
629
|
-
export { GetDotenvCli, buildSpawnEnv, createCli, defineDynamic, defineGetDotenvConfig, definePlugin, defineScripts, dotenvExpand, dotenvExpandAll, dotenvExpandFromProcessEnv, getDotenv, getDotenvCliOptions2Options, interpolateDeep, readMergedOptions };
|
|
630
|
-
export type { CreateCliOptions,
|
|
910
|
+
export { GetDotenvCli, baseRootOptionDefaults, buildSpawnEnv, createCli, defineDynamic, defineGetDotenvConfig, definePlugin, defineScripts, dotenvExpand, dotenvExpandAll, dotenvExpandFromProcessEnv, getDotenv, getDotenvCliOptions2Options, interpolateDeep, readMergedOptions };
|
|
911
|
+
export type { CreateCliOptions, DynamicFn, DynamicMap, GetDotenvCliOptions, GetDotenvCliPlugin, GetDotenvCliPublic, GetDotenvConfig, GetDotenvDynamic, GetDotenvOptions, InferGetDotenvVarsFromConfig, InferPluginConfig, PluginWithInstanceHelpers, ProcessEnv, ScriptsTable };
|