@karmaniverous/get-dotenv 6.0.0-1 → 6.1.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.
Files changed (62) hide show
  1. package/README.md +91 -379
  2. package/dist/cli.d.ts +569 -0
  3. package/dist/cli.mjs +18877 -0
  4. package/dist/cliHost.d.ts +528 -184
  5. package/dist/cliHost.mjs +1977 -1428
  6. package/dist/config.d.ts +191 -14
  7. package/dist/config.mjs +266 -81
  8. package/dist/env-overlay.d.ts +223 -16
  9. package/dist/env-overlay.mjs +185 -4
  10. package/dist/getdotenv.cli.mjs +18025 -3196
  11. package/dist/index.d.ts +623 -256
  12. package/dist/index.mjs +18045 -3206
  13. package/dist/plugins-aws.d.ts +221 -91
  14. package/dist/plugins-aws.mjs +2411 -369
  15. package/dist/plugins-batch.d.ts +300 -103
  16. package/dist/plugins-batch.mjs +2560 -484
  17. package/dist/plugins-cmd.d.ts +229 -106
  18. package/dist/plugins-cmd.mjs +2518 -790
  19. package/dist/plugins-init.d.ts +221 -95
  20. package/dist/plugins-init.mjs +2170 -105
  21. package/dist/plugins.d.ts +246 -125
  22. package/dist/plugins.mjs +17941 -1968
  23. package/dist/templates/cli/index.ts +25 -0
  24. package/{templates/cli/ts → dist/templates/cli}/plugins/hello.ts +13 -9
  25. package/dist/templates/config/js/getdotenv.config.js +20 -0
  26. package/dist/templates/config/json/local/getdotenv.config.local.json +7 -0
  27. package/dist/templates/config/json/public/getdotenv.config.json +9 -0
  28. package/dist/templates/config/public/getdotenv.config.json +8 -0
  29. package/dist/templates/config/ts/getdotenv.config.ts +28 -0
  30. package/dist/templates/config/yaml/local/getdotenv.config.local.yaml +7 -0
  31. package/dist/templates/config/yaml/public/getdotenv.config.yaml +7 -0
  32. package/dist/templates/getdotenv.config.js +20 -0
  33. package/dist/templates/getdotenv.config.json +9 -0
  34. package/dist/templates/getdotenv.config.local.json +7 -0
  35. package/dist/templates/getdotenv.config.local.yaml +7 -0
  36. package/dist/templates/getdotenv.config.ts +28 -0
  37. package/dist/templates/getdotenv.config.yaml +7 -0
  38. package/dist/templates/hello.ts +42 -0
  39. package/dist/templates/index.ts +25 -0
  40. package/dist/templates/js/getdotenv.config.js +20 -0
  41. package/dist/templates/json/local/getdotenv.config.local.json +7 -0
  42. package/dist/templates/json/public/getdotenv.config.json +9 -0
  43. package/dist/templates/local/getdotenv.config.local.json +7 -0
  44. package/dist/templates/local/getdotenv.config.local.yaml +7 -0
  45. package/dist/templates/plugins/hello.ts +42 -0
  46. package/dist/templates/public/getdotenv.config.json +9 -0
  47. package/dist/templates/public/getdotenv.config.yaml +7 -0
  48. package/dist/templates/ts/getdotenv.config.ts +28 -0
  49. package/dist/templates/yaml/local/getdotenv.config.local.yaml +7 -0
  50. package/dist/templates/yaml/public/getdotenv.config.yaml +7 -0
  51. package/getdotenv.config.json +1 -19
  52. package/package.json +42 -39
  53. package/templates/cli/index.ts +25 -0
  54. package/templates/cli/plugins/hello.ts +42 -0
  55. package/templates/config/js/getdotenv.config.js +8 -3
  56. package/templates/config/json/public/getdotenv.config.json +0 -3
  57. package/templates/config/public/getdotenv.config.json +0 -5
  58. package/templates/config/ts/getdotenv.config.ts +8 -3
  59. package/templates/config/yaml/public/getdotenv.config.yaml +0 -3
  60. package/dist/plugins-demo.d.ts +0 -204
  61. package/dist/plugins-demo.mjs +0 -496
  62. 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
- type RootOptionsShape = {
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
- entropyWhitelist?: string[];
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
- * Scripts table shape (configurable shell type).
93
+ * Definition for a single script entry.
48
94
  */
49
- type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<string, string | {
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
- /** Build a sanitized env for child processes from base + overlay. */
60
- declare const buildSpawnEnv: (base?: NodeJS.ProcessEnv, overlay?: Record<string, string | undefined>) => NodeJS.ProcessEnv;
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.ZodOptional<z.ZodUnknown>;
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
- * Canonical CLI options type derived from the Zod schema output.
103
- * Includes CLI-only flags (debug/strict/capture/trace/redaction/entropy),
104
- * stringly paths/vars, and inherited programmatic fields (minus normalized
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.ZodOptional<z.ZodUnknown>;
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?: 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
- type GetDotenvConfig<Vars extends ProcessEnv, Env extends string = string> = {
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
- scripts?: Scripts;
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,199 @@ declare function getDotenv<Vars extends ProcessEnv>(options: Partial<GetDotenvOp
331
390
  vars: Vars;
332
391
  }): Promise<ProcessEnv & Vars>;
333
392
 
334
- /** src/types/deepReadonly.ts
335
- * Utility DeepReadonly type for downstream DX.
336
- * Compile-time only; no runtime footprint.
393
+ /**
394
+ * Unify Scripts via the generic ScriptsTable<TShell> so shell types propagate.
337
395
  */
338
- type DeepReadonly<T> = T extends (...args: unknown[]) => unknown ? T : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepReadonly<U>> : T extends Array<infer U> ? ReadonlyArray<DeepReadonly<U>> : T extends object ? {
339
- readonly [K in keyof T]: DeepReadonly<T[K]>;
340
- } : T;
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
- * Deeply interpolate string leaves against envRef.
344
- * Arrays are not recursed into; they are returned unchanged.
415
+ * Configuration context used for generating dynamic help descriptions.
416
+ * Contains merged CLI options and plugin configuration slices.
345
417
  *
346
- * @typeParam T - Shape of the input value.
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
- /** Per-invocation context shared with plugins and actions. */
357
- type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
358
- optionsResolved: TOptions;
359
- dotenv: ProcessEnv;
360
- plugins?: Record<string, unknown>;
361
- pluginConfigs?: Record<string, unknown>;
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
+ /**
571
+ * Helper to decide whether to capture child stdio.
572
+ * Checks GETDOTENV_STDIO env var or the provided bag capture flag.
573
+ */
574
+ declare const shouldCapture: (bagCapture?: boolean) => boolean;
575
+
576
+ /** src/cliHost/GetDotenvCli.ts
577
+ * Plugin-first CLI host for get-dotenv with Commander generics preserved.
578
+ * Public surface implements GetDotenvCliPublic and provides:
579
+ * - attachRootOptions (builder-only; no public override wiring)
580
+ * - resolveAndLoad (strict resolve + context compute)
581
+ * - getCtx/hasCtx accessors
582
+ * - ns() for typed subcommand creation with duplicate-name guard
583
+ * - grouped help rendering with dynamic option descriptions
584
+ */
585
+
363
586
  declare const CTX_SYMBOL: unique symbol;
364
587
  declare const OPTS_SYMBOL: unique symbol;
365
588
  declare const HELP_HEADER_SYMBOL: unique symbol;
@@ -372,11 +595,13 @@ declare const HELP_HEADER_SYMBOL: unique symbol;
372
595
  * - Provide a namespacing helper (ns).
373
596
  * - Support composable plugins with parent → children install and afterResolve.
374
597
  */
375
- declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOptions> extends Command implements GetDotenvCliPublic<TOptions> {
598
+ 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
599
  /** Registered top-level plugins (composition happens via .use()) */
377
600
  private _plugins;
378
601
  /** One-time installation guard */
379
602
  private _installed;
603
+ /** In-flight installation promise to guard against concurrent installs */
604
+ private _installing?;
380
605
  /** Optional header line to prepend in help output */
381
606
  private [HELP_HEADER_SYMBOL];
382
607
  /** Context/options stored under symbols (typed) */
@@ -386,8 +611,13 @@ declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOption
386
611
  * Create a subcommand using the same subclass, preserving helpers like
387
612
  * dynamicOption on children.
388
613
  */
389
- createCommand(name?: string): Command;
614
+ createCommand(name?: string): GetDotenvCli<TOptions>;
390
615
  constructor(alias?: string);
616
+ /**
617
+ * Attach legacy/base root flags to this CLI instance.
618
+ * Delegates to the pure builder in attachRootOptions.ts.
619
+ */
620
+ attachRootOptions(defaults?: Partial<RootOptionsShape>): this;
391
621
  /**
392
622
  * Resolve options (strict) and compute dotenv context.
393
623
  * Stores the context on the instance under a symbol.
@@ -397,37 +627,30 @@ declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOption
397
627
  * afterResolve hooks. Useful for top-level help rendering to avoid
398
628
  * long-running side-effects while still evaluating dynamic help text.
399
629
  */
400
- resolveAndLoad(customOptions?: Partial<TOptions>, opts?: {
401
- runAfterResolve?: boolean;
402
- }): Promise<GetDotenvCliCtx<TOptions>>;
630
+ resolveAndLoad(customOptions?: Partial<TOptions>, opts?: ResolveAndLoadOptions): Promise<GetDotenvCliCtx<TOptions>>;
403
631
  /**
404
632
  * Create a Commander Option that computes its description at help time.
405
633
  * The returned Option may be configured (conflicts, default, parser) and
406
634
  * added via addOption().
407
635
  */
408
- createDynamicOption(flags: string, desc: (cfg: ResolvedHelpConfig & {
409
- plugins: Record<string, unknown>;
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;
636
+ createDynamicOption<Usage extends string>(flags: Usage, desc: (cfg: ResolvedHelpConfig) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option<Usage>;
637
+ createDynamicOption<Usage extends string, TValue = unknown>(flags: Usage, desc: (cfg: ResolvedHelpConfig) => string, parser: (value: string, previous?: TValue) => TValue, defaultValue?: TValue): Option<Usage>;
421
638
  /**
422
639
  * Evaluate dynamic descriptions for this command and all descendants using
423
640
  * the provided resolved configuration. Mutates the Option.description in
424
641
  * place so Commander help renders updated text.
425
642
  */
426
643
  evaluateDynamicOptions(resolved: ResolvedHelpConfig): void;
644
+ /** Internal: climb to the true root (host) command. */
645
+ private _root;
427
646
  /**
428
647
  * Retrieve the current invocation context (if any).
429
648
  */
430
- getCtx(): GetDotenvCliCtx<TOptions> | undefined;
649
+ getCtx(): GetDotenvCliCtx<TOptions>;
650
+ /**
651
+ * Check whether a context has been resolved (non-throwing guard).
652
+ */
653
+ hasCtx(): boolean;
431
654
  /**
432
655
  * Retrieve the merged root CLI options bag (if set by passOptions()).
433
656
  * Downstream-safe: no generics required.
@@ -435,25 +658,25 @@ declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOption
435
658
  getOptions(): GetDotenvCliOptions | undefined;
436
659
  /** Internal: set the merged root options bag for this run. */
437
660
  _setOptionsBag(bag: GetDotenvCliOptions): void;
438
- /** Convenience helper to create a namespaced subcommand. */
439
- ns(name: string): Command;
661
+ /**
662
+ * Convenience helper to create a namespaced subcommand with argument inference.
663
+ * This mirrors Commander generics so downstream chaining stays fully typed.
664
+ */
665
+ ns<Usage extends string>(name: Usage): GetDotenvCliPublic<TOptions, [
666
+ ...TArgs,
667
+ ...InferCommandArguments<Usage>
668
+ ], {}, TOpts & TGlobal>;
440
669
  /**
441
670
  * Tag options added during the provided callback as 'app' for grouped help.
442
671
  * Allows downstream apps to demarcate their root-level options.
443
672
  */
444
- tagAppOptions<T>(fn: (root: Command) => T): T;
673
+ tagAppOptions<T>(fn: (root: CommandUnknownOpts) => T): T;
445
674
  /**
446
675
  * Branding helper: set CLI name/description/version and optional help header.
447
676
  * If version is omitted and importMetaUrl is provided, attempts to read the
448
677
  * nearest package.json version (best-effort; non-fatal on failure).
449
678
  */
450
- brand(args: {
451
- name?: string;
452
- description?: string;
453
- version?: string;
454
- importMetaUrl?: string;
455
- helpHeader?: string;
456
- }): Promise<this>;
679
+ brand(args: BrandOptions): Promise<this>;
457
680
  /**
458
681
  * Insert grouped plugin/app options between "Options" and "Commands" for
459
682
  * hybrid ordering. Applies to root and any parent command.
@@ -467,7 +690,7 @@ declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOption
467
690
  * Register a plugin for installation (parent level).
468
691
  * Installation occurs on first resolveAndLoad() (or explicit install()).
469
692
  */
470
- use(plugin: GetDotenvCliPlugin<TOptions>): this;
693
+ use(plugin: GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal>, override?: PluginNamespaceOverride): this;
471
694
  /**
472
695
  * Install all registered plugins in parent → children (pre-order).
473
696
  * Runs only once per CLI instance.
@@ -479,152 +702,296 @@ declare class GetDotenvCli$1<TOptions extends GetDotenvOptions = GetDotenvOption
479
702
  private _runAfterResolve;
480
703
  }
481
704
 
482
- /** src/cliHost/definePlugin.ts
483
- * Plugin contracts for the GetDotenv CLI host.
705
+ /**
706
+ * Retrieve the merged root options bag from the current command context.
707
+ * Climbs to the root `GetDotenvCli` instance to access the persisted options.
484
708
  *
485
- * This module exposes a structural public interface for the host that plugins
486
- * should use (GetDotenvCliPublic). Using a structural type at the seam avoids
487
- * nominal class identity issues (private fields) in downstream consumers.
709
+ * @param cmd - The current command instance (thisCommand).
710
+ * @throws Error if the root is not a GetDotenvCli or options are missing.
488
711
  */
712
+ declare const readMergedOptions: (cmd: CommandUnknownOpts) => GetDotenvCliOptions;
489
713
 
490
714
  /**
491
- * Structural public interface for the host exposed to plugins.
492
- * - Extends Commander.Command so plugins can attach options/commands/hooks.
493
- * - Adds host-specific helpers used by built-in plugins.
715
+ * Build a sanitized environment object for spawning child processes.
716
+ * Merges `base` and `overlay`, drops undefined values, and handles platform-specific
717
+ * normalization (e.g. case-insensitivity on Windows).
494
718
  *
495
- * Purpose: remove nominal class identity (private fields) from the plugin seam
496
- * to avoid TS2379 under exactOptionalPropertyTypes in downstream consumers.
719
+ * @param base - Base environment (usually `process.env`).
720
+ * @param overlay - Environment variables to overlay.
497
721
  */
498
- interface GetDotenvCliPublic<TOptions extends GetDotenvOptions = GetDotenvOptions> extends Command {
499
- ns(name: string): Command;
500
- getCtx(): GetDotenvCliCtx<TOptions> | undefined;
501
- resolveAndLoad(customOptions?: Partial<TOptions>, opts?: {
502
- runAfterResolve?: boolean;
503
- }): Promise<GetDotenvCliCtx<TOptions>>;
504
- setOptionGroup(opt: Option, group: string): void;
505
- /**
506
- * Create a dynamic option whose description is computed at help time
507
- * from the resolved configuration.
508
- */
509
- createDynamicOption(flags: string, desc: (cfg: ResolvedHelpConfig & {
510
- plugins: Record<string, unknown>;
511
- }) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option;
512
- createDynamicOption<TValue = unknown>(flags: string, desc: (cfg: ResolvedHelpConfig & {
513
- plugins: Record<string, unknown>;
514
- }) => string, parser: (value: string, previous?: TValue) => TValue, defaultValue?: TValue): Option;
515
- }
516
- /** Public plugin contract used by the GetDotenv CLI host. */
517
- interface GetDotenvCliPlugin<TOptions extends GetDotenvOptions = GetDotenvOptions> {
518
- id?: string;
722
+ declare const buildSpawnEnv: (base?: NodeJS.ProcessEnv, overlay?: Record<string, string | undefined>) => NodeJS.ProcessEnv;
723
+
724
+ /**
725
+ * Create a get-dotenv CLI host with included plugins.
726
+ *
727
+ * Options:
728
+ * - alias: command name used for help/argv scaffolding (default: "getdotenv")
729
+ * - branding: optional help header; when omitted, brand() uses "<alias> v<version>"
730
+ *
731
+ * Usage:
732
+ * ```ts
733
+ * import { createCli } from '@karmaniverous/get-dotenv';
734
+ *
735
+ * await createCli({
736
+ * alias: 'getdotenv',
737
+ * branding: 'getdotenv vX.Y.Z'
738
+ * })();
739
+ * ```
740
+ */
741
+ type CreateCliOptions = {
519
742
  /**
520
- * Setup phase: register commands and wiring on the provided CLI instance.
521
- * Runs parent children (pre-order).
743
+ * CLI command name used for help and argv scaffolding.
744
+ * Defaults to `'getdotenv'` when omitted.
522
745
  */
523
- setup: (cli: GetDotenvCliPublic<TOptions>) => void | Promise<void>;
746
+ alias?: string;
524
747
  /**
525
- * After the dotenv context is resolved, initialize any clients/secrets
526
- * or attach per-plugin state under ctx.plugins (by convention).
527
- * Runs parent → children (pre-order).
748
+ * Optional help header text. When omitted, brand() uses
749
+ * `"<alias> v<resolved-version>"` if a version can be read.
528
750
  */
529
- afterResolve?: (cli: GetDotenvCliPublic<TOptions>, ctx: GetDotenvCliCtx<TOptions>) => void | Promise<void>;
751
+ branding?: string;
530
752
  /**
531
- * Zod schema for this plugin's config slice (from config.plugins[id]).
532
- * Enforced object-like (ZodObject) to simplify code paths and inference.
753
+ * Optional composer to wire the CLI (plugins/options). If not provided,
754
+ * the shipped default wiring is applied. Any `configureOutput`/`exitOverride`
755
+ * you call here override the defaults.
533
756
  */
534
- configSchema?: ZodObject;
757
+ compose?: (program: GetDotenvCli) => GetDotenvCli;
535
758
  /**
536
- * Compositional children. Installed after the parent per pre-order.
759
+ * Root defaults applied once before composition. These are used by flag declaration
760
+ * and merge-time defaults (and top-level -h parity labels).
761
+ * Note: shipped CLI does not force loadProcess OFF; base defaults apply unless set here.
537
762
  */
538
- children: GetDotenvCliPlugin<TOptions>[];
763
+ rootOptionDefaults?: Partial<RootOptionsShape>;
539
764
  /**
540
- * Compose a child plugin. Returns the parent to enable chaining.
765
+ * Visibility map to hide families/singles from root help. When a key is false,
766
+ * the corresponding option(s) are hidden (via hideHelp) after flags are declared.
541
767
  */
542
- use: (child: GetDotenvCliPlugin<TOptions>) => GetDotenvCliPlugin<TOptions>;
543
- }
768
+ rootOptionVisibility?: Partial<Record<keyof RootOptionsShape, boolean>>;
769
+ };
544
770
  /**
545
- * Compile-time helper type: the plugin object returned by definePlugin always
546
- * includes the instance-bound helpers as required members. Keeping the public
547
- * interface optional preserves compatibility for ad-hoc/test plugins, while
548
- * return types from definePlugin provide stronger DX for shipped/typed plugins.
771
+ * Create a configured get-dotenv CLI host.
772
+ * Applies defaults, installs root hooks, and composes plugins.
773
+ * Returns a runner function that accepts an argv array.
549
774
  */
550
- type PluginWithInstanceHelpers<TOptions extends GetDotenvOptions = GetDotenvOptions, TConfig = unknown> = GetDotenvCliPlugin<TOptions> & {
551
- readConfig<TCfg = TConfig>(cli: GetDotenvCliPublic<TOptions>): Readonly<TCfg>;
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
- };
775
+ declare function createCli(opts?: CreateCliOptions): (argv?: string[]) => Promise<void>;
776
+
556
777
  /**
557
- * Public spec type for defining a plugin with optional children.
558
- * Exported to ensure TypeDoc links and navigation resolve correctly.
778
+ * Base root CLI defaults (shared; kept untyped here to avoid cross-layer deps).
779
+ * Used as the bottom layer for CLI option resolution.
559
780
  */
560
- type DefineSpec<TOptions extends GetDotenvOptions = GetDotenvOptions> = Omit<GetDotenvCliPlugin<TOptions>, 'children' | 'use'> & {
561
- children?: GetDotenvCliPlugin<TOptions>[];
781
+ /**
782
+ * Default values for root CLI options used by the host and helpers as the
783
+ * baseline layer during option resolution.
784
+ *
785
+ * These defaults correspond to the "stringly" root surface (see `RootOptionsShape`)
786
+ * and are merged by precedence with create-time overrides and any discovered
787
+ * configuration `rootOptionDefaults` before CLI flags are applied.
788
+ */
789
+ declare const baseRootOptionDefaults: {
790
+ readonly dotenvToken: ".env";
791
+ readonly loadProcess: true;
792
+ readonly logger: Console;
793
+ readonly warnEntropy: true;
794
+ readonly entropyThreshold: 3.8;
795
+ readonly entropyMinLength: 16;
796
+ readonly entropyWhitelist: readonly ["^GIT_", "^npm_", "^CI$", "SHLVL"];
797
+ readonly paths: "./";
798
+ readonly pathsDelimiter: " ";
799
+ readonly privateToken: "local";
800
+ readonly scripts: {
801
+ readonly 'git-status': {
802
+ readonly cmd: "git branch --show-current && git status -s -u";
803
+ readonly shell: true;
804
+ };
805
+ };
806
+ readonly shell: true;
807
+ readonly vars: "";
808
+ readonly varsAssignor: "=";
809
+ readonly varsDelimiter: " ";
562
810
  };
811
+
563
812
  /**
564
- * Define a GetDotenv CLI plugin with compositional helpers.
813
+ * Configuration options for entropy analysis.
565
814
  *
566
- * @example
567
- * const parent = definePlugin({ id: 'p', setup(cli) { /* omitted *\/ } })
568
- * .use(childA)
569
- * .use(childB);
815
+ * @public
816
+ */
817
+ interface EntropyOptions {
818
+ /** Enable entropy warnings. */
819
+ warnEntropy?: boolean;
820
+ /** Entropy threshold (bits/char). */
821
+ entropyThreshold?: number;
822
+ /** Minimum string length to check. */
823
+ entropyMinLength?: number;
824
+ /** Whitelist of regex patterns to ignore. */
825
+ entropyWhitelist?: Array<string | RegExp>;
826
+ }
827
+ /**
828
+ * Maybe emit a one-line entropy warning for a key.
829
+ * Caller supplies an `emit(line)` function; the helper ensures once-per-key.
830
+ */
831
+ declare const maybeWarnEntropy: (key: string, value: string | undefined, origin: "dotenv" | "parent" | "unset", opts: EntropyOptions | undefined, emit: (line: string) => void) => void;
832
+
833
+ /** src/diagnostics/redact.ts
834
+ * Presentation-only redaction utilities for logs/trace.
835
+ * - Default secret-like key patterns: SECRET, TOKEN, PASSWORD, API_KEY, KEY
836
+ * - Optional custom patterns (regex strings) may be provided.
837
+ * - Never alters runtime env; only affects displayed values.
570
838
  */
571
- declare function definePlugin<TOptions extends GetDotenvOptions, Schema extends ZodObject>(spec: Omit<DefineSpec<TOptions>, 'configSchema'> & {
572
- configSchema: Schema;
573
- }): PluginWithInstanceHelpers<TOptions, z.output<Schema>>;
574
- declare function definePlugin<TOptions extends GetDotenvOptions>(spec: DefineSpec<TOptions>): PluginWithInstanceHelpers<TOptions, {}>;
575
839
 
576
840
  /**
577
- * Infer the compile-time plugin config type from a plugin instance created by definePlugin.
578
- * Returns a deeply readonly view to discourage mutation at call sites.
841
+ * Configuration options for secret redaction.
842
+ *
843
+ * @public
579
844
  */
580
- type InferPluginConfig<P> = P extends PluginWithInstanceHelpers<GetDotenvOptions, infer C> ? Readonly<C> : never;
845
+ interface RedactOptions {
846
+ /** Enable redaction. */
847
+ redact?: boolean;
848
+ /** Regex patterns for keys to redact. */
849
+ redactPatterns?: Array<string | RegExp>;
850
+ }
851
+ /**
852
+ * Redact a single displayed value according to key/patterns.
853
+ * Returns the original value when redaction is disabled or key is not matched.
854
+ */
855
+ declare const redactDisplay: (key: string, value: string | undefined, opts?: RedactOptions) => string | undefined;
856
+ /**
857
+ * Produce a shallow redacted copy of an env-like object for display.
858
+ */
859
+ declare const redactObject: (obj: ProcessEnv, opts?: RedactOptions) => Record<string, string | undefined>;
581
860
 
582
861
  /**
583
- * GetDotenvCli with root helpers as real class methods.
584
- * - attachRootOptions: installs legacy/base root flags on the command.
585
- * - passOptions: merges flags (parent \< current), computes dotenv context once,
586
- * runs validation, and persists merged options for nested flows.
862
+ * Options for tracing composed child environment variables.
863
+ *
864
+ * Presentation-only: values are never mutated; output is written to {@link write}.
865
+ *
866
+ * @public
587
867
  */
588
- declare class GetDotenvCli extends GetDotenvCli$1 {
868
+ interface TraceChildEnvOptions extends Pick<RedactOptions, 'redact' | 'redactPatterns'>, EntropyOptions {
589
869
  /**
590
- * Attach legacy root flags to this CLI instance. Defaults come from
591
- * baseRootOptionDefaults when none are provided.
870
+ * Parent process environment (source).
592
871
  */
593
- attachRootOptions(defaults?: Partial<RootOptionsShape>): this;
872
+ parentEnv: ProcessEnv;
873
+ /**
874
+ * Composed dotenv map (target).
875
+ */
876
+ dotenv: ProcessEnv;
877
+ /**
878
+ * Optional subset of keys to trace. When omitted, all keys are traced.
879
+ */
880
+ keys?: string[];
594
881
  /**
595
- * Install preSubcommand/preAction hooks that:
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).
882
+ * Sink for trace lines (e.g., write to stderr).
600
883
  */
601
- passOptions(defaults?: Partial<RootOptionsShape>): this;
884
+ write: (line: string) => void;
602
885
  }
603
886
  /**
604
- * Helper to retrieve the merged root options bag from any action handler
605
- * that only has access to thisCommand. Avoids structural casts.
887
+ * Trace child env composition with redaction and entropy warnings.
888
+ * Presentation-only: does not mutate env; writes lines via the provided sink.
606
889
  */
607
- declare const readMergedOptions: (cmd: Command) => GetDotenvCliOptions | undefined;
890
+ declare function traceChildEnv(opts: TraceChildEnvOptions): void;
608
891
 
609
892
  /**
610
- * Create a get-dotenv CLI host with included plugins.
893
+ * Recursively expands environment variables in a string. Variables may be
894
+ * presented with optional default as `$VAR[:default]` or `${VAR[:default]}`.
895
+ * Unknown variables will expand to an empty string.
611
896
  *
897
+ * @param value - The string to expand.
898
+ * @param ref - The reference object to use for variable expansion.
899
+ * @returns The expanded string.
900
+ *
901
+ * @example
902
+ * ```ts
903
+ * process.env.FOO = 'bar';
904
+ * dotenvExpand('Hello $FOO'); // "Hello bar"
905
+ * dotenvExpand('Hello $BAZ:world'); // "Hello world"
906
+ * ```
907
+ *
908
+ * @remarks
909
+ * The expansion is recursive. If a referenced variable itself contains
910
+ * references, those will also be expanded until a stable value is reached.
911
+ * Escaped references (e.g. `\$FOO`) are preserved as literals.
912
+ */
913
+ declare const dotenvExpand: (value: string | undefined, ref?: ProcessEnv) => string | undefined;
914
+ /**
915
+ * Options for {@link dotenvExpandAll}.
916
+ *
917
+ * @public
918
+ */
919
+ interface DotenvExpandAllOptions {
920
+ /**
921
+ * The reference object to use for expansion (defaults to process.env).
922
+ */
923
+ ref?: Record<string, string | undefined>;
924
+ /**
925
+ * Whether to progressively add expanded values to the set of reference keys.
926
+ */
927
+ progressive?: boolean;
928
+ }
929
+ /**
930
+ * Recursively expands environment variables in the values of a JSON object.
931
+ * Variables may be presented with optional default as `$VAR[:default]` or
932
+ * `${VAR[:default]}`. Unknown variables will expand to an empty string.
933
+ *
934
+ * @param values - The values object to expand.
935
+ * @param options - Expansion options.
936
+ * @returns The value object with expanded string values.
937
+ *
938
+ * @example
939
+ * ```ts
940
+ * process.env.FOO = 'bar';
941
+ * dotenvExpandAll({ A: '$FOO', B: 'x${FOO}y' });
942
+ * // => { A: "bar", B: "xbary" }
943
+ * ```
944
+ *
945
+ * @remarks
612
946
  * Options:
613
- * - alias: command name used for help/argv scaffolding (default: "getdotenv")
614
- * - branding: optional help header; when omitted, brand() uses "\<alias\> v\<version\>"
947
+ * - ref: The reference object to use for expansion (defaults to process.env).
948
+ * - progressive: Whether to progressively add expanded values to the set of
949
+ * reference keys.
615
950
  *
616
- * Usage:
617
- * import \{ createCli \} from '\@karmaniverous/get-dotenv';
618
- * await createCli(\{ alias: 'getdotenv', branding: 'getdotenv vX.Y.Z' \})
619
- * .run(process.argv.slice(2));
951
+ * When `progressive` is true, each expanded key becomes available for
952
+ * subsequent expansions in the same object (left-to-right by object key order).
620
953
  */
621
- type CreateCliOptions = {
622
- alias?: string;
623
- branding?: string;
624
- };
625
- declare function createCli(opts?: CreateCliOptions): {
626
- run: (argv: string[]) => Promise<void>;
954
+ declare function dotenvExpandAll<T extends Record<string, string | undefined> | Readonly<Record<string, string | undefined>>>(values: T, options?: DotenvExpandAllOptions): Record<string, string | undefined> & {
955
+ [K in keyof T]: string | undefined;
627
956
  };
957
+ /**
958
+ * Recursively expands environment variables in a string using `process.env` as
959
+ * the expansion reference. Variables may be presented with optional default as
960
+ * `$VAR[:default]` or `${VAR[:default]}`. Unknown variables will expand to an
961
+ * empty string.
962
+ *
963
+ * @param value - The string to expand.
964
+ * @returns The expanded string.
965
+ *
966
+ * @example
967
+ * ```ts
968
+ * process.env.FOO = 'bar';
969
+ * dotenvExpandFromProcessEnv('Hello $FOO'); // "Hello bar"
970
+ * ```
971
+ */
972
+ declare const dotenvExpandFromProcessEnv: (value: string | undefined) => string | undefined;
973
+
974
+ /**
975
+ * Deep interpolation utility for string leaves.
976
+ * - Expands string values using dotenv-style expansion against the provided envRef.
977
+ * - Preserves non-strings as-is.
978
+ * - Does not recurse into arrays (arrays are returned unchanged).
979
+ *
980
+ * Intended for:
981
+ * - Phase C option/config interpolation after composing ctx.dotenv.
982
+ * - Per-plugin config slice interpolation before afterResolve.
983
+ */
984
+
985
+ /**
986
+ * Deeply interpolate string leaves against envRef.
987
+ * Arrays are not recursed into; they are returned unchanged.
988
+ *
989
+ * @typeParam T - Shape of the input value.
990
+ * @param value - Input value (object/array/primitive).
991
+ * @param envRef - Reference environment for interpolation.
992
+ * @returns A new value with string leaves interpolated.
993
+ */
994
+ declare const interpolateDeep: <T>(value: T, envRef: ProcessEnv) => T;
628
995
 
629
- export { GetDotenvCli, buildSpawnEnv, createCli, defineDynamic, defineGetDotenvConfig, definePlugin, defineScripts, dotenvExpand, dotenvExpandAll, dotenvExpandFromProcessEnv, getDotenv, getDotenvCliOptions2Options, interpolateDeep, readMergedOptions };
630
- export type { CreateCliOptions, DeepReadonly, DynamicFn, DynamicMap, GetDotenvCliOptions, GetDotenvCliPlugin, GetDotenvCliPublic, GetDotenvConfig, GetDotenvDynamic, GetDotenvOptions, InferGetDotenvVarsFromConfig, InferPluginConfig, PluginWithInstanceHelpers, ProcessEnv, ScriptsTable };
996
+ export { GetDotenvCli, baseRootOptionDefaults, buildSpawnEnv, createCli, defineDynamic, defineGetDotenvConfig, definePlugin, defineScripts, dotenvExpand, dotenvExpandAll, dotenvExpandFromProcessEnv, getDotenv, getDotenvCliOptions2Options, interpolateDeep, maybeWarnEntropy, readMergedOptions, redactDisplay, redactObject, shouldCapture, traceChildEnv };
997
+ export type { CreateCliOptions, DynamicFn, DynamicMap, EntropyOptions, GetDotenvCliOptions, GetDotenvCliPlugin, GetDotenvCliPublic, GetDotenvConfig, GetDotenvDynamic, GetDotenvOptions, InferGetDotenvVarsFromConfig, InferPluginConfig, PluginWithInstanceHelpers, ProcessEnv, RedactOptions, ScriptsTable, TraceChildEnvOptions };