@karmaniverous/get-dotenv 6.0.0-0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +86 -334
  2. package/dist/cli.d.ts +569 -0
  3. package/dist/cli.mjs +18788 -0
  4. package/dist/cliHost.d.ts +548 -253
  5. package/dist/cliHost.mjs +1990 -1458
  6. package/dist/config.d.ts +192 -14
  7. package/dist/config.mjs +256 -81
  8. package/dist/env-overlay.d.ts +226 -18
  9. package/dist/env-overlay.mjs +181 -22
  10. package/dist/getdotenv.cli.mjs +18166 -3437
  11. package/dist/index.d.ts +729 -136
  12. package/dist/index.mjs +18207 -3457
  13. package/dist/plugins-aws.d.ts +289 -104
  14. package/dist/plugins-aws.mjs +2462 -350
  15. package/dist/plugins-batch.d.ts +355 -105
  16. package/dist/plugins-batch.mjs +2595 -420
  17. package/dist/plugins-cmd.d.ts +287 -118
  18. package/dist/plugins-cmd.mjs +2661 -839
  19. package/dist/plugins-init.d.ts +272 -100
  20. package/dist/plugins-init.mjs +2152 -37
  21. package/dist/plugins.d.ts +323 -140
  22. package/dist/plugins.mjs +18006 -2025
  23. package/dist/templates/cli/index.ts +26 -0
  24. package/dist/templates/cli/plugins/hello.ts +43 -0
  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 +43 -0
  39. package/dist/templates/index.ts +26 -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 +43 -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 +52 -89
  53. package/templates/cli/index.ts +26 -0
  54. package/templates/cli/plugins/hello.ts +43 -0
  55. package/templates/config/js/getdotenv.config.js +9 -4
  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 +17 -5
  59. package/templates/config/yaml/public/getdotenv.config.yaml +0 -3
  60. package/dist/cliHost.cjs +0 -2078
  61. package/dist/cliHost.d.cts +0 -451
  62. package/dist/cliHost.d.mts +0 -451
  63. package/dist/config.cjs +0 -252
  64. package/dist/config.d.cts +0 -55
  65. package/dist/config.d.mts +0 -55
  66. package/dist/env-overlay.cjs +0 -163
  67. package/dist/env-overlay.d.cts +0 -50
  68. package/dist/env-overlay.d.mts +0 -50
  69. package/dist/index.cjs +0 -4077
  70. package/dist/index.d.cts +0 -318
  71. package/dist/index.d.mts +0 -318
  72. package/dist/plugins-aws.cjs +0 -666
  73. package/dist/plugins-aws.d.cts +0 -158
  74. package/dist/plugins-aws.d.mts +0 -158
  75. package/dist/plugins-batch.cjs +0 -658
  76. package/dist/plugins-batch.d.cts +0 -181
  77. package/dist/plugins-batch.d.mts +0 -181
  78. package/dist/plugins-cmd.cjs +0 -1112
  79. package/dist/plugins-cmd.d.cts +0 -178
  80. package/dist/plugins-cmd.d.mts +0 -178
  81. package/dist/plugins-demo.cjs +0 -352
  82. package/dist/plugins-demo.d.cts +0 -158
  83. package/dist/plugins-demo.d.mts +0 -158
  84. package/dist/plugins-demo.d.ts +0 -158
  85. package/dist/plugins-demo.mjs +0 -350
  86. package/dist/plugins-init.cjs +0 -289
  87. package/dist/plugins-init.d.cts +0 -162
  88. package/dist/plugins-init.d.mts +0 -162
  89. package/dist/plugins.cjs +0 -2327
  90. package/dist/plugins.d.cts +0 -211
  91. package/dist/plugins.d.mts +0 -211
  92. package/templates/cli/ts/index.ts +0 -9
  93. package/templates/cli/ts/plugins/hello.ts +0 -17
package/dist/index.d.ts CHANGED
@@ -1,181 +1,807 @@
1
- /** src/cliCore/spawnEnv.ts
2
- * Build a sanitized environment bag for child processes.
3
- *
4
- * Requirements addressed:
5
- * - Provide a single helper (buildSpawnEnv) to normalize/dedupe child env.
6
- * - Drop undefined values (exactOptional semantics).
7
- * - On Windows, dedupe keys case-insensitively and prefer the last value,
8
- * preserving the latest key's casing. Ensure HOME fallback from USERPROFILE.
9
- * Normalize TMP/TEMP consistency when either is present.
10
- * - On POSIX, keep keys as-is; when a temp dir key is present (TMPDIR/TMP/TEMP),
11
- * ensure TMPDIR exists for downstream consumers that expect it.
12
- *
13
- * Adapter responsibility: pure mapping; no business logic.
14
- */
15
- type SpawnEnv = Readonly<Partial<Record<string, string>>>;
16
- /** Build a sanitized env for child processes from base + overlay. */
17
- declare const buildSpawnEnv: (base?: NodeJS.ProcessEnv, overlay?: Record<string, string | undefined>) => SpawnEnv;
1
+ import { z, ZodObject } from 'zod';
2
+ export { z } from 'zod';
3
+ import { OptionValues, Command, InferCommandArguments, Option, CommandUnknownOpts } from '@commander-js/extra-typings';
18
4
 
19
5
  /**
20
6
  * Minimal root options shape shared by CLI and generator layers.
21
7
  * Keep keys optional to respect exactOptionalPropertyTypes semantics.
8
+ *
9
+ * @public
22
10
  */
23
- type RootOptionsShape = {
11
+ interface RootOptionsShape {
12
+ /** Target environment (dotenv-expanded). */
24
13
  env?: string;
14
+ /** Explicit variable overrides (dotenv-expanded). */
25
15
  vars?: string;
16
+ /** Command to execute (dotenv-expanded). */
26
17
  command?: string;
18
+ /** Output path for the consolidated environment file (dotenv-expanded). */
27
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
+ */
28
26
  shell?: string | boolean;
27
+ /** Whether to load variables into `process.env`. */
29
28
  loadProcess?: boolean;
29
+ /** Exclude all variables from loading. */
30
30
  excludeAll?: boolean;
31
+ /** Exclude dynamic variables. */
31
32
  excludeDynamic?: boolean;
33
+ /** Exclude environment-specific variables. */
32
34
  excludeEnv?: boolean;
35
+ /** Exclude global variables. */
33
36
  excludeGlobal?: boolean;
37
+ /** Exclude private variables. */
34
38
  excludePrivate?: boolean;
39
+ /** Exclude public variables. */
35
40
  excludePublic?: boolean;
41
+ /** Enable console logging of loaded variables. */
36
42
  log?: boolean;
43
+ /** Enable debug logging to stderr. */
37
44
  debug?: boolean;
45
+ /** Capture child process stdio (useful for tests/CI). */
38
46
  capture?: boolean;
47
+ /** Fail on validation errors (schema/requiredKeys). */
39
48
  strict?: boolean;
49
+ /** Enable presentation-time redaction of secret-like keys. */
40
50
  redact?: boolean;
51
+ /** Enable entropy warnings for high-entropy values. */
41
52
  warnEntropy?: boolean;
53
+ /** Entropy threshold (bits/char) for warnings (default 3.8). */
42
54
  entropyThreshold?: number;
55
+ /** Minimum string length to check for entropy (default 16). */
43
56
  entropyMinLength?: number;
44
- entropyWhitelist?: string[];
57
+ /** Regex patterns for keys to exclude from entropy checks. */
58
+ entropyWhitelist?: ReadonlyArray<string>;
59
+ /** Additional regex patterns for keys to redact. */
45
60
  redactPatterns?: string[];
61
+ /** Default target environment when not specified. */
46
62
  defaultEnv?: string;
63
+ /** Token indicating a dotenv file (default: ".env"). */
47
64
  dotenvToken?: string;
65
+ /** Path to dynamic variables module (default: undefined). */
48
66
  dynamicPath?: string;
67
+ /**
68
+ * Emit diagnostics for child env composition.
69
+ * - `true`: trace all keys.
70
+ * - `string[]`: trace selected keys.
71
+ */
49
72
  trace?: boolean | string[];
73
+ /** Paths to search for dotenv files (space-delimited string or array). */
50
74
  paths?: string;
75
+ /** Delimiter for paths string (default: space). */
51
76
  pathsDelimiter?: string;
77
+ /** Regex pattern for paths delimiter. */
52
78
  pathsDelimiterPattern?: string;
79
+ /** Token indicating private variables (default: "local"). */
53
80
  privateToken?: string;
81
+ /** Delimiter for vars string (default: space). */
54
82
  varsDelimiter?: string;
83
+ /** Regex pattern for vars delimiter. */
55
84
  varsDelimiterPattern?: string;
85
+ /** Assignment operator for vars (default: "="). */
56
86
  varsAssignor?: string;
87
+ /** Regex pattern for vars assignment operator. */
57
88
  varsAssignorPattern?: string;
89
+ /** Table of named scripts for execution. */
58
90
  scripts?: ScriptsTable;
59
- };
91
+ }
60
92
  /**
61
- * Scripts table shape (configurable shell type).
93
+ * Definition for a single script entry.
62
94
  */
63
- 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. */
64
97
  cmd: string;
65
- shell?: TShell;
66
- }>;
98
+ /** Shell override for this script. */
99
+ shell?: TShell | undefined;
100
+ }
101
+ /**
102
+ * Scripts table shape.
103
+ */
104
+ type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<string, string | ScriptDef<TShell>>;
105
+ /**
106
+ * Identity helper to define a scripts table while preserving a concrete TShell
107
+ * type parameter in downstream inference.
108
+ */
109
+ declare const defineScripts: <TShell extends string | boolean>() => <T extends ScriptsTable<TShell>>(t: T) => T;
110
+ /**
111
+ * Per-invocation context shared with plugins and actions.
112
+ *
113
+ * @public
114
+ */
115
+ interface GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> {
116
+ optionsResolved: TOptions;
117
+ dotenv: ProcessEnv;
118
+ plugins?: Record<string, unknown>;
119
+ pluginConfigs?: Record<string, unknown>;
120
+ }
121
+ /**
122
+ * Options for branding the CLI.
123
+ *
124
+ * @public
125
+ */
126
+ interface BrandOptions {
127
+ /** CLI name. */
128
+ name?: string;
129
+ /** CLI description. */
130
+ description?: string;
131
+ /** CLI version string. */
132
+ version?: string;
133
+ /** Import URL for resolving package version. */
134
+ importMetaUrl?: string;
135
+ /** Custom help header text. */
136
+ helpHeader?: string;
137
+ }
138
+
139
+ /**
140
+ * Resolved CLI options schema.
141
+ * For the current step this mirrors the RAW schema; later stages may further
142
+ * narrow types post-resolution in the host pipeline.
143
+ */
144
+ declare const getDotenvCliOptionsSchemaResolved: z.ZodObject<{
145
+ defaultEnv: z.ZodOptional<z.ZodString>;
146
+ dotenvToken: z.ZodOptional<z.ZodString>;
147
+ dynamicPath: z.ZodOptional<z.ZodString>;
148
+ dynamic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
149
+ env: z.ZodOptional<z.ZodString>;
150
+ excludeDynamic: z.ZodOptional<z.ZodBoolean>;
151
+ excludeEnv: z.ZodOptional<z.ZodBoolean>;
152
+ excludeGlobal: z.ZodOptional<z.ZodBoolean>;
153
+ excludePrivate: z.ZodOptional<z.ZodBoolean>;
154
+ excludePublic: z.ZodOptional<z.ZodBoolean>;
155
+ loadProcess: z.ZodOptional<z.ZodBoolean>;
156
+ log: z.ZodOptional<z.ZodBoolean>;
157
+ logger: z.ZodDefault<z.ZodUnknown>;
158
+ outputPath: z.ZodOptional<z.ZodString>;
159
+ privateToken: z.ZodOptional<z.ZodString>;
160
+ debug: z.ZodOptional<z.ZodBoolean>;
161
+ strict: z.ZodOptional<z.ZodBoolean>;
162
+ capture: z.ZodOptional<z.ZodBoolean>;
163
+ trace: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
164
+ redact: z.ZodOptional<z.ZodBoolean>;
165
+ warnEntropy: z.ZodOptional<z.ZodBoolean>;
166
+ entropyThreshold: z.ZodOptional<z.ZodNumber>;
167
+ entropyMinLength: z.ZodOptional<z.ZodNumber>;
168
+ entropyWhitelist: z.ZodOptional<z.ZodArray<z.ZodString>>;
169
+ redactPatterns: z.ZodOptional<z.ZodArray<z.ZodString>>;
170
+ paths: z.ZodOptional<z.ZodString>;
171
+ pathsDelimiter: z.ZodOptional<z.ZodString>;
172
+ pathsDelimiterPattern: z.ZodOptional<z.ZodString>;
173
+ scripts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
174
+ shell: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>;
175
+ vars: z.ZodOptional<z.ZodString>;
176
+ varsAssignor: z.ZodOptional<z.ZodString>;
177
+ varsAssignorPattern: z.ZodOptional<z.ZodString>;
178
+ varsDelimiter: z.ZodOptional<z.ZodString>;
179
+ varsDelimiterPattern: z.ZodOptional<z.ZodString>;
180
+ }, z.core.$strip>;
181
+
182
+ /**
183
+ * Resolved programmatic options schema (post-inheritance).
184
+ * For now, this mirrors the RAW schema; future stages may materialize defaults
185
+ * and narrow shapes as resolution is wired into the host.
186
+ */
187
+ declare const getDotenvOptionsSchemaResolved: z.ZodObject<{
188
+ defaultEnv: z.ZodOptional<z.ZodString>;
189
+ dotenvToken: z.ZodOptional<z.ZodString>;
190
+ dynamicPath: z.ZodOptional<z.ZodString>;
191
+ dynamic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
192
+ env: z.ZodOptional<z.ZodString>;
193
+ excludeDynamic: z.ZodOptional<z.ZodBoolean>;
194
+ excludeEnv: z.ZodOptional<z.ZodBoolean>;
195
+ excludeGlobal: z.ZodOptional<z.ZodBoolean>;
196
+ excludePrivate: z.ZodOptional<z.ZodBoolean>;
197
+ excludePublic: z.ZodOptional<z.ZodBoolean>;
198
+ loadProcess: z.ZodOptional<z.ZodBoolean>;
199
+ log: z.ZodOptional<z.ZodBoolean>;
200
+ logger: z.ZodDefault<z.ZodUnknown>;
201
+ outputPath: z.ZodOptional<z.ZodString>;
202
+ paths: z.ZodOptional<z.ZodArray<z.ZodString>>;
203
+ privateToken: z.ZodOptional<z.ZodString>;
204
+ vars: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodString>>>;
205
+ }, z.core.$strip>;
67
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
+ */
68
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
+ */
69
226
  vars?: string | Record<string, string | undefined>;
227
+ /**
228
+ * Dotenv search paths as a space‑delimited string or a pre‑split string[].
229
+ */
70
230
  paths?: string | string[];
71
231
  };
72
232
  /**
73
233
  * A minimal representation of an environment key/value mapping.
74
- * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
234
+ * Values may be `undefined` to represent "unset".
235
+ */
236
+ type ProcessEnv = Record<string, string | undefined>;
75
237
  /**
76
238
  * Dynamic variable function signature. Receives the current expanded variables
77
239
  * and the selected environment (if any), and returns either a string to set
78
240
  * or `undefined` to unset/skip the variable.
79
241
  */
80
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
+ */
81
247
  type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
248
+ /**
249
+ * Logger interface compatible with `console` or a subset thereof.
250
+ */
82
251
  type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
83
252
  /**
84
- * Helper to define a dynamic map with strong inference.
253
+ * Canonical programmatic options type (schema-derived).
254
+ * This type is the single source of truth for programmatic options.
255
+ */
256
+ type GetDotenvOptions = z.output<typeof getDotenvOptionsSchemaResolved> & {
257
+ /**
258
+ * Compile-time overlay: narrowed logger for DX (schema stores unknown).
259
+ */
260
+ logger: Logger;
261
+ /**
262
+ * Compile-time overlay: narrowed dynamic map for DX (schema stores unknown).
263
+ */
264
+ dynamic?: GetDotenvDynamic;
265
+ };
266
+ /**
267
+ * Vars-aware dynamic helpers (compile-time DX).
268
+ * DynamicFn: receive the current expanded variables and optional env.
269
+ */
270
+ type DynamicFn<Vars extends Record<string, string | undefined>> = (vars: Vars, env?: string) => string | undefined;
271
+ type DynamicMap<Vars extends Record<string, string | undefined>> = Record<string, DynamicFn<Vars> | ReturnType<DynamicFn<Vars>>>;
272
+ /**
273
+ * Helper to define a dynamic map with strong inference (Vars-aware).
85
274
  *
86
- * @example
87
- * const dynamic = defineDynamic(\{ KEY: (\{ FOO = '' \}) =\> FOO + '-x' \});
275
+ * Overload A (preferred): bind Vars to your intended key set for improved inference.
88
276
  */
89
- declare const defineDynamic: <T extends GetDotenvDynamic>(d: T) => T;
277
+ declare function defineDynamic<Vars extends Record<string, string | undefined>, T extends DynamicMap<Vars>>(d: T): T;
90
278
  /**
91
- * Options passed programmatically to `getDotenv`.
279
+ * Overload B (backward-compatible): generic over legacy GetDotenvDynamic.
280
+ *
281
+ * Accepts legacy GetDotenvDynamic without Vars binding.
92
282
  */
93
- interface GetDotenvOptions {
283
+ declare function defineDynamic<T extends GetDotenvDynamic>(d: T): T;
284
+ /**
285
+ * Typed config shape and builder for authoring JS/TS getdotenv config files.
286
+ *
287
+ * Compile-time only; the runtime loader remains schema-driven.
288
+ */
289
+ interface GetDotenvConfig<Vars extends ProcessEnv, Env extends string = string> {
94
290
  /**
95
- * default target environment (used if `env` is not provided)
291
+ * Operational root defaults applied by the host (collapsed families; stringly form).
96
292
  */
97
- defaultEnv?: string;
293
+ rootOptionDefaults?: Partial<RootOptionsShape>;
294
+ /** Token indicating a dotenv file. */
295
+ dotenvToken?: string;
296
+ /** Token indicating private variables. */
297
+ privateToken?: string;
298
+ /** Paths to search for dotenv files. */
299
+ paths?: string | string[];
300
+ /** Whether to load variables into `process.env`. */
301
+ loadProcess?: boolean;
302
+ /** Whether to log loaded variables. */
303
+ log?: boolean;
304
+ /** Shell execution strategy. */
305
+ shell?: string | boolean;
306
+ /** Scripts table. */
307
+ scripts?: ScriptsTable;
308
+ /** Keys required to be present in the final environment. */
309
+ requiredKeys?: string[];
310
+ /** Validation schema (e.g. Zod). */
311
+ schema?: unknown;
312
+ /** Global variables. */
313
+ vars?: Vars;
314
+ /** Environment-specific variables. */
315
+ envVars?: Record<Env, Partial<Vars>>;
316
+ /** Dynamic variable definitions. */
317
+ dynamic?: DynamicMap<Vars>;
318
+ /** Plugin configuration slices. */
319
+ plugins?: Record<string, unknown>;
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
+ */
336
+ declare function defineGetDotenvConfig<Vars extends ProcessEnv, Env extends string = string, T extends GetDotenvConfig<Vars, Env> = GetDotenvConfig<Vars, Env>>(cfg: T): T;
337
+ /**
338
+ * Compile-time helper to derive the Vars shape from a typed getdotenv config document.
339
+ */
340
+ type InferGetDotenvVarsFromConfig<T> = T extends {
341
+ vars?: infer V;
342
+ } ? V extends Record<string, string | undefined> ? V : never : never;
343
+ /**
344
+ * Converts programmatic CLI options to `getDotenv` options.
345
+ *
346
+ * Accepts "stringly" CLI inputs for vars/paths and normalizes them into
347
+ * the programmatic shape. Preserves exactOptionalPropertyTypes semantics by
348
+ * omitting keys when undefined.
349
+ */
350
+ declare const getDotenvCliOptions2Options: ({ paths, pathsDelimiter, pathsDelimiterPattern, vars, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, debug: _debug, scripts: _scripts, ...rest }: RootOptionsShapeCompat) => GetDotenvOptions;
351
+
352
+ /**
353
+ * Asynchronously process dotenv files of the form `.env[.<ENV>][.<PRIVATE_TOKEN>]`
354
+ *
355
+ * @param options - `GetDotenvOptions` object
356
+ * @returns The combined parsed dotenv object.
357
+ * * @example Load from the project root with default tokens
358
+ * ```ts
359
+ * const vars = await getDotenv();
360
+ * console.log(vars.MY_SETTING);
361
+ * ```
362
+ *
363
+ * @example Load from multiple paths and a specific environment
364
+ * ```ts
365
+ * const vars = await getDotenv({
366
+ * env: 'dev',
367
+ * dotenvToken: '.testenv',
368
+ * privateToken: 'secret',
369
+ * paths: ['./', './packages/app'],
370
+ * });
371
+ * ```
372
+ *
373
+ * @example Use dynamic variables
374
+ * ```ts
375
+ * // .env.js default-exports: { DYNAMIC: ({ PREV }) => `${PREV}-suffix` }
376
+ * const vars = await getDotenv({ dynamicPath: '.env.js' });
377
+ * ```
378
+ *
379
+ * @remarks
380
+ * - When {@link GetDotenvOptions | loadProcess} is true, the resulting variables are merged
381
+ * into `process.env` as a side effect.
382
+ * - When {@link GetDotenvOptions | outputPath} is provided, a consolidated dotenv file is written.
383
+ * The path is resolved after expansion, so it may reference previously loaded vars.
384
+ *
385
+ * @throws Error when a dynamic module is present but cannot be imported.
386
+ * @throws Error when an output path was requested but could not be resolved.
387
+ */
388
+ declare function getDotenv<Vars extends ProcessEnv = ProcessEnv>(options?: Partial<GetDotenvOptions>): Promise<Vars>;
389
+ declare function getDotenv<Vars extends ProcessEnv>(options: Partial<GetDotenvOptions> & {
390
+ vars: Vars;
391
+ }): Promise<ProcessEnv & Vars>;
392
+
393
+ /**
394
+ * Unify Scripts via the generic ScriptsTable<TShell> so shell types propagate.
395
+ */
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> & {
98
404
  /**
99
- * token indicating a dotenv file
405
+ * Compile-only overlay for DX: logger narrowed from unknown.
100
406
  */
101
- dotenvToken: string;
407
+ logger: Logger;
102
408
  /**
103
- * path to JS/TS module default-exporting an object keyed to dynamic variable functions
409
+ * Compile-only overlay for DX: scripts narrowed from Record\<string, unknown\>.
104
410
  */
105
- dynamicPath?: string;
411
+ scripts?: Scripts;
412
+ };
413
+
414
+ /**
415
+ * Configuration context used for generating dynamic help descriptions.
416
+ * Contains merged CLI options and plugin configuration slices.
417
+ *
418
+ * @public
419
+ */
420
+ type ResolvedHelpConfig = Partial<GetDotenvCliOptions> & {
106
421
  /**
107
- * Programmatic dynamic variables map. When provided, this takes precedence
108
- * over {@link GetDotenvOptions.dynamicPath}.
422
+ * Per‑plugin configuration slices keyed by realized mount path
423
+ * (e.g., `"aws"` or `"aws/whoami"`), used for dynamic help text.
109
424
  */
110
- dynamic?: GetDotenvDynamic;
425
+ plugins: Record<string, unknown>;
426
+ };
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 {
111
440
  /**
112
- * target environment
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
113
446
  */
114
- env?: string;
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> {
115
458
  /**
116
- * exclude dynamic variables from loading
459
+ * Create a namespaced child command with argument inference.
460
+ * Mirrors Commander generics so downstream chaining remains fully typed.
117
461
  */
118
- excludeDynamic?: boolean;
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;
119
472
  /**
120
- * exclude environment-specific variables from loading
473
+ * Create a dynamic option whose description is computed at help time
474
+ * from the resolved configuration.
121
475
  */
122
- excludeEnv?: boolean;
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 {
123
485
  /**
124
- * exclude global variables from loading
486
+ * Override the default namespace for this plugin instance.
125
487
  */
126
- excludeGlobal?: boolean;
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>;
127
498
  /**
128
- * exclude private variables from loading
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`.
129
501
  */
130
- excludePrivate?: boolean;
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;
131
508
  /**
132
- * exclude public variables from loading
509
+ * Setup phase: register commands and wiring on the provided mount.
510
+ * Runs parent → children (pre-order). Return nothing (void).
133
511
  */
134
- excludePublic?: boolean;
512
+ setup: (cli: GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal>) => void | Promise<void>;
135
513
  /**
136
- * load dotenv variables to `process.env`
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).
137
517
  */
138
- loadProcess?: boolean;
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;
139
521
  /**
140
- * log loaded dotenv variables to `logger`
522
+ * Compositional children, with optional per-child overrides (e.g., ns).
523
+ * Installed after the parent per pre-order.
141
524
  */
142
- log?: boolean;
525
+ children: Array<PluginChildEntry<TOptions, TArgs, TOpts, TGlobal>>;
143
526
  /**
144
- * logger object (defaults to console)
527
+ * Compose a child plugin with optional override (ns). Returns the parent
528
+ * to enable chaining.
145
529
  */
146
- logger?: Logger;
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'> & {
147
546
  /**
148
- * if populated, writes consolidated dotenv file to this path (follows dotenvExpand rules)
547
+ * Required namespace and setup function. The host creates the mount and
548
+ * passes it into setup; return void | Promise<void>.
149
549
  */
150
- outputPath?: string;
550
+ ns: string;
551
+ setup: (cli: GetDotenvCliPublic<TOptions, TArgs, TOpts, TGlobal>) => void | Promise<void>;
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
+
580
+ declare const CTX_SYMBOL: unique symbol;
581
+ declare const OPTS_SYMBOL: unique symbol;
582
+ declare const HELP_HEADER_SYMBOL: unique symbol;
583
+ /**
584
+ * Plugin-first CLI host for get-dotenv. Extends Commander.Command.
585
+ *
586
+ * Responsibilities:
587
+ * - Resolve options strictly and compute dotenv context (resolveAndLoad).
588
+ * - Expose a stable accessor for the current context (getCtx).
589
+ * - Provide a namespacing helper (ns).
590
+ * - Support composable plugins with parent → children install and afterResolve.
591
+ */
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> {
593
+ /** Registered top-level plugins (composition happens via .use()) */
594
+ private _plugins;
595
+ /** One-time installation guard */
596
+ private _installed;
597
+ /** In-flight installation promise to guard against concurrent installs */
598
+ private _installing?;
599
+ /** Optional header line to prepend in help output */
600
+ private [HELP_HEADER_SYMBOL];
601
+ /** Context/options stored under symbols (typed) */
602
+ private [CTX_SYMBOL]?;
603
+ private [OPTS_SYMBOL]?;
151
604
  /**
152
- * array of input directory paths
605
+ * Create a subcommand using the same subclass, preserving helpers like
606
+ * dynamicOption on children.
153
607
  */
154
- paths?: string[];
608
+ createCommand(name?: string): GetDotenvCli<TOptions>;
609
+ constructor(alias?: string);
155
610
  /**
156
- * filename token indicating private variables
611
+ * Attach legacy/base root flags to this CLI instance.
612
+ * Delegates to the pure builder in attachRootOptions.ts.
157
613
  */
158
- privateToken?: string;
614
+ attachRootOptions(defaults?: Partial<RootOptionsShape>): this;
615
+ /**
616
+ * Resolve options (strict) and compute dotenv context.
617
+ * Stores the context on the instance under a symbol.
618
+ *
619
+ * Options:
620
+ * - opts.runAfterResolve (default true): when false, skips running plugin
621
+ * afterResolve hooks. Useful for top-level help rendering to avoid
622
+ * long-running side-effects while still evaluating dynamic help text.
623
+ */
624
+ resolveAndLoad(customOptions?: Partial<TOptions>, opts?: ResolveAndLoadOptions): Promise<GetDotenvCliCtx<TOptions>>;
625
+ /**
626
+ * Create a Commander Option that computes its description at help time.
627
+ * The returned Option may be configured (conflicts, default, parser) and
628
+ * added via addOption().
629
+ */
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>;
632
+ /**
633
+ * Evaluate dynamic descriptions for this command and all descendants using
634
+ * the provided resolved configuration. Mutates the Option.description in
635
+ * place so Commander help renders updated text.
636
+ */
637
+ evaluateDynamicOptions(resolved: ResolvedHelpConfig): void;
638
+ /** Internal: climb to the true root (host) command. */
639
+ private _root;
640
+ /**
641
+ * Retrieve the current invocation context (if any).
642
+ */
643
+ getCtx(): GetDotenvCliCtx<TOptions>;
644
+ /**
645
+ * Check whether a context has been resolved (non-throwing guard).
646
+ */
647
+ hasCtx(): boolean;
648
+ /**
649
+ * Retrieve the merged root CLI options bag (if set by passOptions()).
650
+ * Downstream-safe: no generics required.
651
+ */
652
+ getOptions(): GetDotenvCliOptions | undefined;
653
+ /** Internal: set the merged root options bag for this run. */
654
+ _setOptionsBag(bag: GetDotenvCliOptions): void;
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>;
663
+ /**
664
+ * Tag options added during the provided callback as 'app' for grouped help.
665
+ * Allows downstream apps to demarcate their root-level options.
666
+ */
667
+ tagAppOptions<T>(fn: (root: CommandUnknownOpts) => T): T;
159
668
  /**
160
- * explicit variables to include
669
+ * Branding helper: set CLI name/description/version and optional help header.
670
+ * If version is omitted and importMetaUrl is provided, attempts to read the
671
+ * nearest package.json version (best-effort; non-fatal on failure).
161
672
  */
162
- vars?: ProcessEnv;
673
+ brand(args: BrandOptions): Promise<this>;
163
674
  /**
164
- * Reserved: config loader flag (no-op).
165
- * The plugin-first host and generator paths already use the config
166
- * loader/overlay pipeline unconditionally (no-op when no config files
167
- * are present). This flag is accepted for forward compatibility but
168
- * currently has no effect.
675
+ * Insert grouped plugin/app options between "Options" and "Commands" for
676
+ * hybrid ordering. Applies to root and any parent command.
169
677
  */
170
- useConfigLoader?: boolean;
678
+ helpInformation(): string;
679
+ /**
680
+ * Public: tag an Option with a display group for help (root/app/plugin:<id>).
681
+ */
682
+ setOptionGroup(opt: Option, group: string): void;
683
+ /**
684
+ * Register a plugin for installation (parent level).
685
+ * Installation occurs on first resolveAndLoad() (or explicit install()).
686
+ */
687
+ use(plugin: GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal>, override?: PluginNamespaceOverride): this;
688
+ /**
689
+ * Install all registered plugins in parent → children (pre-order).
690
+ * Runs only once per CLI instance.
691
+ */
692
+ install(): Promise<void>;
693
+ /**
694
+ * Run afterResolve hooks for all plugins (parent → children).
695
+ */
696
+ private _runAfterResolve;
171
697
  }
698
+
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.
702
+ *
703
+ * @param cmd - The current command instance (thisCommand).
704
+ * @throws Error if the root is not a GetDotenvCli or options are missing.
705
+ */
706
+ declare const readMergedOptions: (cmd: CommandUnknownOpts) => GetDotenvCliOptions;
707
+
708
+ /**
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).
712
+ *
713
+ * @param base - Base environment (usually `process.env`).
714
+ * @param overlay - Environment variables to overlay.
715
+ */
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 = {
736
+ /**
737
+ * CLI command name used for help and argv scaffolding.
738
+ * Defaults to `'getdotenv'` when omitted.
739
+ */
740
+ alias?: string;
741
+ /**
742
+ * Optional help header text. When omitted, brand() uses
743
+ * `"<alias> v<resolved-version>"` if a version can be read.
744
+ */
745
+ branding?: string;
746
+ /**
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.
750
+ */
751
+ compose?: (program: GetDotenvCli) => GetDotenvCli;
752
+ /**
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.
756
+ */
757
+ rootOptionDefaults?: Partial<RootOptionsShape>;
758
+ /**
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.
761
+ */
762
+ rootOptionVisibility?: Partial<Record<keyof RootOptionsShape, boolean>>;
763
+ };
172
764
  /**
173
- * Converts programmatic CLI options to `getDotenv` options. *
174
- * @param cliOptions - CLI options. Defaults to `{}`.
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.
768
+ */
769
+ declare function createCli(opts?: CreateCliOptions): (argv?: string[]) => Promise<void>;
770
+
771
+ /**
772
+ * Base root CLI defaults (shared; kept untyped here to avoid cross-layer deps).
773
+ * Used as the bottom layer for CLI option resolution.
774
+ */
775
+ /**
776
+ * Default values for root CLI options used by the host and helpers as the
777
+ * baseline layer during option resolution.
175
778
  *
176
- * @returns `getDotenv` options.
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.
177
782
  */
178
- declare const getDotenvCliOptions2Options: ({ paths, pathsDelimiter, pathsDelimiterPattern, vars, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, ...rest }: RootOptionsShapeCompat) => GetDotenvOptions;
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
+ };
179
805
 
180
806
  /**
181
807
  * Recursively expands environment variables in a string. Variables may be
@@ -199,6 +825,21 @@ declare const getDotenvCliOptions2Options: ({ paths, pathsDelimiter, pathsDelimi
199
825
  * Escaped references (e.g. `\$FOO`) are preserved as literals.
200
826
  */
201
827
  declare const dotenvExpand: (value: string | undefined, ref?: ProcessEnv) => string | undefined;
828
+ /**
829
+ * Options for {@link dotenvExpandAll}.
830
+ *
831
+ * @public
832
+ */
833
+ interface DotenvExpandAllOptions {
834
+ /**
835
+ * The reference object to use for expansion (defaults to process.env).
836
+ */
837
+ ref?: Record<string, string | undefined>;
838
+ /**
839
+ * Whether to progressively add expanded values to the set of reference keys.
840
+ */
841
+ progressive?: boolean;
842
+ }
202
843
  /**
203
844
  * Recursively expands environment variables in the values of a JSON object.
204
845
  * Variables may be presented with optional default as `$VAR[:default]` or
@@ -224,10 +865,9 @@ declare const dotenvExpand: (value: string | undefined, ref?: ProcessEnv) => str
224
865
  * When `progressive` is true, each expanded key becomes available for
225
866
  * subsequent expansions in the same object (left-to-right by object key order).
226
867
  */
227
- declare const dotenvExpandAll: (values?: ProcessEnv, options?: {
228
- ref?: ProcessEnv;
229
- progressive?: boolean;
230
- }) => Record<string, string | undefined>;
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
+ };
231
871
  /**
232
872
  * Recursively expands environment variables in a string using `process.env` as
233
873
  * the expansion reference. Variables may be presented with optional default as
@@ -246,42 +886,15 @@ declare const dotenvExpandAll: (values?: ProcessEnv, options?: {
246
886
  declare const dotenvExpandFromProcessEnv: (value: string | undefined) => string | undefined;
247
887
 
248
888
  /**
249
- * Asynchronously process dotenv files of the form `.env[.<ENV>][.<PRIVATE_TOKEN>]`
250
- *
251
- * @param options - `GetDotenvOptions` object
252
- * @returns The combined parsed dotenv object.
253
- * * @example Load from the project root with default tokens
254
- * ```ts
255
- * const vars = await getDotenv();
256
- * console.log(vars.MY_SETTING);
257
- * ```
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).
258
893
  *
259
- * @example Load from multiple paths and a specific environment
260
- * ```ts
261
- * const vars = await getDotenv({
262
- * env: 'dev',
263
- * dotenvToken: '.testenv',
264
- * privateToken: 'secret',
265
- * paths: ['./', './packages/app'],
266
- * });
267
- * ```
268
- *
269
- * @example Use dynamic variables
270
- * ```ts
271
- * // .env.js default-exports: { DYNAMIC: ({ PREV }) => `${PREV}-suffix` }
272
- * const vars = await getDotenv({ dynamicPath: '.env.js' });
273
- * ```
274
- *
275
- * @remarks
276
- * - When {@link GetDotenvOptions.loadProcess} is true, the resulting variables are merged
277
- * into `process.env` as a side effect.
278
- * - When {@link GetDotenvOptions.outputPath} is provided, a consolidated dotenv file is written.
279
- * The path is resolved after expansion, so it may reference previously loaded vars.
280
- *
281
- * @throws Error when a dynamic module is present but cannot be imported.
282
- * @throws Error when an output path was requested but could not be resolved.
894
+ * Intended for:
895
+ * - Phase C option/config interpolation after composing ctx.dotenv.
896
+ * - Per-plugin config slice interpolation before afterResolve.
283
897
  */
284
- declare const getDotenv: (options?: Partial<GetDotenvOptions>) => Promise<ProcessEnv>;
285
898
 
286
899
  /**
287
900
  * Deeply interpolate string leaves against envRef.
@@ -294,25 +907,5 @@ declare const getDotenv: (options?: Partial<GetDotenvOptions>) => Promise<Proces
294
907
  */
295
908
  declare const interpolateDeep: <T>(value: T, envRef: ProcessEnv) => T;
296
909
 
297
- /**
298
- * Create a get-dotenv CLI host with included plugins.
299
- *
300
- * Options:
301
- * - alias: command name used for help/argv scaffolding (default: "getdotenv")
302
- * - branding: optional help header; when omitted, brand() uses "<alias> v<version>"
303
- *
304
- * Usage:
305
- * import \{ createCli \} from '\@karmaniverous/get-dotenv';
306
- * await createCli(\{ alias: 'getdotenv', branding: 'getdotenv vX.Y.Z' \})
307
- * .run(process.argv.slice(2));
308
- */
309
- type CreateCliOptions = {
310
- alias?: string;
311
- branding?: string;
312
- };
313
- declare function createCli(opts?: CreateCliOptions): {
314
- run: (argv: string[]) => Promise<void>;
315
- };
316
-
317
- export { buildSpawnEnv, createCli, defineDynamic, dotenvExpand, dotenvExpandAll, dotenvExpandFromProcessEnv, getDotenv, getDotenvCliOptions2Options, interpolateDeep };
318
- export type { CreateCliOptions, GetDotenvDynamic, GetDotenvOptions, ProcessEnv };
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 };