@karmaniverous/get-dotenv 4.5.2 → 5.0.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 (49) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +369 -215
  3. package/dist/cliHost.cjs +1078 -0
  4. package/dist/cliHost.d.cts +193 -0
  5. package/dist/cliHost.d.mts +193 -0
  6. package/dist/cliHost.d.ts +193 -0
  7. package/dist/cliHost.mjs +1074 -0
  8. package/dist/config.cjs +247 -0
  9. package/dist/config.d.cts +53 -0
  10. package/dist/config.d.mts +53 -0
  11. package/dist/config.d.ts +53 -0
  12. package/dist/config.mjs +242 -0
  13. package/dist/env-overlay.cjs +163 -0
  14. package/dist/env-overlay.d.cts +50 -0
  15. package/dist/env-overlay.d.mts +50 -0
  16. package/dist/env-overlay.d.ts +50 -0
  17. package/dist/env-overlay.mjs +161 -0
  18. package/dist/getdotenv.cli.mjs +2817 -40874
  19. package/dist/index.cjs +1482 -40965
  20. package/dist/index.d.cts +206 -67
  21. package/dist/index.d.mts +206 -67
  22. package/dist/index.d.ts +206 -67
  23. package/dist/index.mjs +1454 -40939
  24. package/dist/plugins-aws.cjs +618 -0
  25. package/dist/plugins-aws.d.cts +178 -0
  26. package/dist/plugins-aws.d.mts +178 -0
  27. package/dist/plugins-aws.d.ts +178 -0
  28. package/dist/plugins-aws.mjs +616 -0
  29. package/dist/plugins-batch.cjs +569 -0
  30. package/dist/plugins-batch.d.cts +200 -0
  31. package/dist/plugins-batch.d.mts +200 -0
  32. package/dist/plugins-batch.d.ts +200 -0
  33. package/dist/plugins-batch.mjs +567 -0
  34. package/dist/plugins-init.cjs +282 -0
  35. package/dist/plugins-init.d.cts +182 -0
  36. package/dist/plugins-init.d.mts +182 -0
  37. package/dist/plugins-init.d.ts +182 -0
  38. package/dist/plugins-init.mjs +280 -0
  39. package/getdotenv.config.json +19 -0
  40. package/package.json +228 -139
  41. package/templates/cli/ts/index.ts +9 -0
  42. package/templates/cli/ts/plugins/hello.ts +17 -0
  43. package/templates/config/js/getdotenv.config.js +15 -0
  44. package/templates/config/json/local/getdotenv.config.local.json +7 -0
  45. package/templates/config/json/public/getdotenv.config.json +12 -0
  46. package/templates/config/public/getdotenv.config.json +13 -0
  47. package/templates/config/ts/getdotenv.config.ts +16 -0
  48. package/templates/config/yaml/local/getdotenv.config.local.yaml +7 -0
  49. package/templates/config/yaml/public/getdotenv.config.yaml +10 -0
package/dist/index.d.ts CHANGED
@@ -1,74 +1,67 @@
1
- import { Command } from '@commander-js/extra-typings';
1
+ import { Command } from 'commander';
2
2
 
3
- type Scripts = Record<string, string | {
4
- cmd: string;
5
- shell?: string | boolean;
6
- }>;
7
3
  /**
8
- * Options passed programmatically to `getDotenvCli`.
4
+ * Minimal root options shape shared by CLI and generator layers.
5
+ * Keep keys optional to respect exactOptionalPropertyTypes semantics.
9
6
  */
10
- interface GetDotenvCliOptions extends Omit<GetDotenvOptions, 'paths' | 'vars'> {
11
- /**
12
- * Logs CLI internals when true.
13
- */
7
+ type RootOptionsShape = {
8
+ env?: string;
9
+ vars?: string;
10
+ command?: string;
11
+ outputPath?: string;
12
+ shell?: string | boolean;
13
+ loadProcess?: boolean;
14
+ excludeAll?: boolean;
15
+ excludeDynamic?: boolean;
16
+ excludeEnv?: boolean;
17
+ excludeGlobal?: boolean;
18
+ excludePrivate?: boolean;
19
+ excludePublic?: boolean;
20
+ log?: boolean;
14
21
  debug?: boolean;
15
- /**
16
- * A delimited string of paths to dotenv files.
17
- */
22
+ capture?: boolean;
23
+ defaultEnv?: string;
24
+ dotenvToken?: string;
25
+ dynamicPath?: string;
26
+ trace?: boolean | string[];
18
27
  paths?: string;
19
- /**
20
- * A delimiter string with which to split `paths`. Only used if
21
- * `pathsDelimiterPattern` is not provided.
22
- */
23
28
  pathsDelimiter?: string;
24
- /**
25
- * A regular expression pattern with which to split `paths`. Supersedes
26
- * `pathsDelimiter`.
27
- */
28
29
  pathsDelimiterPattern?: string;
29
- /**
30
- * Scripts that can be executed from the CLI, either individually or via the batch subcommand.
31
- */
32
- scripts?: Scripts;
33
- /**
34
- * Determines how commands and scripts are executed. If `false` or
35
- * `undefined`, commands are executed as plain Javascript using the default
36
- * execa parser. If `true`, commands are executed using the default OS shell
37
- * parser. Otherwise the user may provide a specific shell string (e.g.
38
- * `/bin/bash`)
39
- */
40
- shell?: string | boolean;
41
- /**
42
- * A delimited string of key-value pairs declaratively specifying variables &
43
- * values to be loaded in addition to any dotenv files.
44
- */
45
- vars?: string;
46
- /**
47
- * A string with which to split keys from values in `vars`. Only used if
48
- * `varsDelimiterPattern` is not provided.
49
- */
50
- varsAssignor?: string;
51
- /**
52
- * A regular expression pattern with which to split variable names from values
53
- * in `vars`. Supersedes `varsAssignor`.
54
- */
55
- varsAssignorPattern?: string;
56
- /**
57
- * A string with which to split `vars` into key-value pairs. Only used if
58
- * `varsDelimiterPattern` is not provided.
59
- */
30
+ privateToken?: string;
60
31
  varsDelimiter?: string;
61
- /**
62
- * A regular expression pattern with which to split `vars` into key-value
63
- * pairs. Supersedes `varsDelimiter`.
64
- */
65
32
  varsDelimiterPattern?: string;
66
- }
33
+ varsAssignor?: string;
34
+ varsAssignorPattern?: string;
35
+ scripts?: ScriptsTable;
36
+ };
37
+ /**
38
+ * Scripts table shape (configurable shell type).
39
+ */
40
+ type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<string, string | {
41
+ cmd: string;
42
+ shell?: TShell;
43
+ }>;
67
44
 
45
+ /**
46
+ * A minimal representation of an environment key/value mapping.
47
+ * Values may be `undefined` to represent "unset".
48
+ */
68
49
  type ProcessEnv = Record<string, string | undefined>;
50
+ /**
51
+ * Dynamic variable function signature. Receives the current expanded variables
52
+ * and the selected environment (if any), and returns either a string to set
53
+ * or `undefined` to unset/skip the variable.
54
+ */
69
55
  type GetDotenvDynamicFunction = (vars: ProcessEnv, env: string | undefined) => string | undefined;
70
56
  type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
71
57
  type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
58
+ /**
59
+ * Helper to define a dynamic map with strong inference.
60
+ *
61
+ * @example
62
+ * const dynamic = defineDynamic(\{ KEY: (\{ FOO = '' \}) =\> FOO + '-x' \});
63
+ */
64
+ declare const defineDynamic: <T extends GetDotenvDynamic>(d: T) => T;
72
65
  /**
73
66
  * Options passed programmatically to `getDotenv`.
74
67
  */
@@ -82,9 +75,14 @@ interface GetDotenvOptions {
82
75
  */
83
76
  dotenvToken: string;
84
77
  /**
85
- * path to JS module default-exporting an object keyed to dynamic variable functions
78
+ * path to JS/TS module default-exporting an object keyed to dynamic variable functions
86
79
  */
87
80
  dynamicPath?: string;
81
+ /**
82
+ * Programmatic dynamic variables map. When provided, this takes precedence
83
+ * over {@link GetDotenvOptions.dynamicPath}.
84
+ */
85
+ dynamic?: GetDotenvDynamic;
88
86
  /**
89
87
  * target environment
90
88
  */
@@ -137,15 +135,22 @@ interface GetDotenvOptions {
137
135
  * explicit variables to include
138
136
  */
139
137
  vars?: ProcessEnv;
138
+ /**
139
+ * Reserved: config loader flag (no-op).
140
+ * The plugin-first host and generator paths already use the config
141
+ * loader/overlay pipeline unconditionally (no-op when no config files
142
+ * are present). This flag is accepted for forward compatibility but
143
+ * currently has no effect.
144
+ */
145
+ useConfigLoader?: boolean;
140
146
  }
141
147
  /**
142
- * Converts programmatic CLI options to `getDotenv` options.
143
- *
148
+ * Converts programmatic CLI options to `getDotenv` options. *
144
149
  * @param cliOptions - CLI options. Defaults to `{}`.
145
150
  *
146
151
  * @returns `getDotenv` options.
147
152
  */
148
- declare const getDotenvCliOptions2Options: ({ paths, pathsDelimiter, pathsDelimiterPattern, vars, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, ...rest }: GetDotenvCliOptions) => GetDotenvOptions;
153
+ declare const getDotenvCliOptions2Options: ({ paths, pathsDelimiter, pathsDelimiterPattern, vars, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, ...rest }: RootOptionsShape) => GetDotenvOptions;
149
154
 
150
155
  /**
151
156
  * Recursively expands environment variables in a string. Variables may be
@@ -155,6 +160,18 @@ declare const getDotenvCliOptions2Options: ({ paths, pathsDelimiter, pathsDelimi
155
160
  * @param value - The string to expand.
156
161
  * @param ref - The reference object to use for variable expansion.
157
162
  * @returns The expanded string.
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * process.env.FOO = 'bar';
167
+ * dotenvExpand('Hello $FOO'); // "Hello bar"
168
+ * dotenvExpand('Hello $BAZ:world'); // "Hello world"
169
+ * ```
170
+ *
171
+ * @remarks
172
+ * The expansion is recursive. If a referenced variable itself contains
173
+ * references, those will also be expanded until a stable value is reached.
174
+ * Escaped references (e.g. `\$FOO`) are preserved as literals.
158
175
  */
159
176
  declare const dotenvExpand: (value: string | undefined, ref?: ProcessEnv) => string | undefined;
160
177
  /**
@@ -162,13 +179,27 @@ declare const dotenvExpand: (value: string | undefined, ref?: ProcessEnv) => str
162
179
  * Variables may be presented with optional default as `$VAR[:default]` or
163
180
  * `${VAR[:default]}`. Unknown variables will expand to an empty string.
164
181
  *
165
- * @param value - The string to expand.
166
- * @param ref - The reference object to use for variable expansion.
167
- * @param progressive - Whether to progressively add expanded values to the
168
- * set of reference keys.
182
+ * @param values - The values object to expand.
183
+ * @param options - Expansion options.
169
184
  * @returns The value object with expanded string values.
185
+ *
186
+ * @example
187
+ * ```ts
188
+ * process.env.FOO = 'bar';
189
+ * dotenvExpandAll({ A: '$FOO', B: 'x${FOO}y' });
190
+ * // => { A: "bar", B: "xbary" }
191
+ * ```
192
+ *
193
+ * @remarks
194
+ * Options:
195
+ * - ref: The reference object to use for expansion (defaults to process.env).
196
+ * - progressive: Whether to progressively add expanded values to the set of
197
+ * reference keys.
198
+ *
199
+ * When `progressive` is true, each expanded key becomes available for
200
+ * subsequent expansions in the same object (left-to-right by object key order).
170
201
  */
171
- declare const dotenvExpandAll: (values?: ProcessEnv, { ref, progressive, }?: {
202
+ declare const dotenvExpandAll: (values?: ProcessEnv, options?: {
172
203
  ref?: ProcessEnv;
173
204
  progressive?: boolean;
174
205
  }) => Record<string, string | undefined>;
@@ -180,9 +211,85 @@ declare const dotenvExpandAll: (values?: ProcessEnv, { ref, progressive, }?: {
180
211
  *
181
212
  * @param value - The string to expand.
182
213
  * @returns The expanded string.
214
+ *
215
+ * @example
216
+ * ```ts
217
+ * process.env.FOO = 'bar';
218
+ * dotenvExpandFromProcessEnv('Hello $FOO'); // "Hello bar"
219
+ * ```
183
220
  */
184
221
  declare const dotenvExpandFromProcessEnv: (value: string | undefined) => string | undefined;
185
222
 
223
+ type Scripts = Record<string, string | {
224
+ cmd: string;
225
+ shell?: string | boolean;
226
+ }>;
227
+ /**
228
+ * Options passed programmatically to `getDotenvCli`.
229
+ */
230
+ interface GetDotenvCliOptions extends Omit<GetDotenvOptions, 'paths' | 'vars'> {
231
+ /**
232
+ * Logs CLI internals when true.
233
+ */
234
+ debug?: boolean;
235
+ /**
236
+ * When true, capture child stdout/stderr and re-emit after completion.
237
+ * Useful for tests/CI. Default behavior is streaming via stdio: 'inherit'.
238
+ */
239
+ capture?: boolean;
240
+ /**
241
+ * A delimited string of paths to dotenv files.
242
+ */
243
+ paths?: string;
244
+ /**
245
+ * A delimiter string with which to split `paths`. Only used if
246
+ * `pathsDelimiterPattern` is not provided.
247
+ */
248
+ pathsDelimiter?: string;
249
+ /**
250
+ * A regular expression pattern with which to split `paths`. Supersedes
251
+ * `pathsDelimiter`.
252
+ */
253
+ pathsDelimiterPattern?: string;
254
+ /**
255
+ * Scripts that can be executed from the CLI, either individually or via the batch subcommand.
256
+ */
257
+ scripts?: Scripts;
258
+ /**
259
+ * Determines how commands and scripts are executed. If `false` or
260
+ * `undefined`, commands are executed as plain Javascript using the default
261
+ * execa parser. If `true`, commands are executed using the default OS shell
262
+ * parser. Otherwise the user may provide a specific shell string (e.g.
263
+ * `/bin/bash`)
264
+ */
265
+ shell?: string | boolean;
266
+ /**
267
+ * A delimited string of key-value pairs declaratively specifying variables &
268
+ * values to be loaded in addition to any dotenv files.
269
+ */
270
+ vars?: string;
271
+ /**
272
+ * A string with which to split keys from values in `vars`. Only used if
273
+ * `varsDelimiterPattern` is not provided.
274
+ */
275
+ varsAssignor?: string;
276
+ /**
277
+ * A regular expression pattern with which to split variable names from values
278
+ * in `vars`. Supersedes `varsAssignor`.
279
+ */
280
+ varsAssignorPattern?: string;
281
+ /**
282
+ * A string with which to split `vars` into key-value pairs. Only used if
283
+ * `varsDelimiterPattern` is not provided.
284
+ */
285
+ varsDelimiter?: string;
286
+ /**
287
+ * A regular expression pattern with which to split `vars` into key-value
288
+ * pairs. Supersedes `varsDelimiter`.
289
+ */
290
+ varsDelimiterPattern?: string;
291
+ }
292
+
186
293
  /**
187
294
  * GetDotenv CLI Pre-hook Callback function type. Mutates inbound options &
188
295
  * executes side effects within the `getDotenv` context.
@@ -229,6 +336,7 @@ interface GetDotenvCliGenerateOptions extends GetDotenvCliOptions {
229
336
 
230
337
  /**
231
338
  * Generate a Commander CLI Command for get-dotenv.
339
+ * Orchestration only: delegates building and lifecycle hooks.
232
340
  */
233
341
  declare const generateGetDotenvCli: (customOptions: Pick<GetDotenvCliGenerateOptions, "importMetaUrl"> & Partial<Omit<GetDotenvCliGenerateOptions, "importMetaUrl">>) => Promise<Command>;
234
342
 
@@ -237,7 +345,38 @@ declare const generateGetDotenvCli: (customOptions: Pick<GetDotenvCliGenerateOpt
237
345
  *
238
346
  * @param options - `GetDotenvOptions` object
239
347
  * @returns The combined parsed dotenv object.
348
+ * * @example Load from the project root with default tokens
349
+ * ```ts
350
+ * const vars = await getDotenv();
351
+ * console.log(vars.MY_SETTING);
352
+ * ```
353
+ *
354
+ * @example Load from multiple paths and a specific environment
355
+ * ```ts
356
+ * const vars = await getDotenv({
357
+ * env: 'dev',
358
+ * dotenvToken: '.testenv',
359
+ * privateToken: 'secret',
360
+ * paths: ['./', './packages/app'],
361
+ * });
362
+ * ```
363
+ *
364
+ * @example Use dynamic variables
365
+ * ```ts
366
+ * // .env.js default-exports: { DYNAMIC: ({ PREV }) => `${PREV}-suffix` }
367
+ * const vars = await getDotenv({ dynamicPath: '.env.js' });
368
+ * ```
369
+ *
370
+ * @remarks
371
+ * - When {@link GetDotenvOptions.loadProcess} is true, the resulting variables are merged
372
+ * into `process.env` as a side effect.
373
+ * - When {@link GetDotenvOptions.outputPath} is provided, a consolidated dotenv file is written.
374
+ * The path is resolved after expansion, so it may reference previously loaded vars.
375
+ *
376
+ * @throws Error when a dynamic module is present but cannot be imported.
377
+ * @throws Error when an output path was requested but could not be resolved.
240
378
  */
241
379
  declare const getDotenv: (options?: Partial<GetDotenvOptions>) => Promise<ProcessEnv>;
242
380
 
243
- export { type GetDotenvDynamic, type GetDotenvOptions, type ProcessEnv, dotenvExpand, dotenvExpandAll, dotenvExpandFromProcessEnv, generateGetDotenvCli, getDotenv, getDotenvCliOptions2Options };
381
+ export { defineDynamic, dotenvExpand, dotenvExpandAll, dotenvExpandFromProcessEnv, generateGetDotenvCli, getDotenv, getDotenvCliOptions2Options };
382
+ export type { GetDotenvDynamic, GetDotenvOptions, ProcessEnv };