@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.
- package/README.md +86 -334
- package/dist/cli.d.ts +569 -0
- package/dist/cli.mjs +18788 -0
- package/dist/cliHost.d.ts +548 -253
- package/dist/cliHost.mjs +1990 -1458
- package/dist/config.d.ts +192 -14
- package/dist/config.mjs +256 -81
- package/dist/env-overlay.d.ts +226 -18
- package/dist/env-overlay.mjs +181 -22
- package/dist/getdotenv.cli.mjs +18166 -3437
- package/dist/index.d.ts +729 -136
- package/dist/index.mjs +18207 -3457
- package/dist/plugins-aws.d.ts +289 -104
- package/dist/plugins-aws.mjs +2462 -350
- package/dist/plugins-batch.d.ts +355 -105
- package/dist/plugins-batch.mjs +2595 -420
- package/dist/plugins-cmd.d.ts +287 -118
- package/dist/plugins-cmd.mjs +2661 -839
- package/dist/plugins-init.d.ts +272 -100
- package/dist/plugins-init.mjs +2152 -37
- package/dist/plugins.d.ts +323 -140
- package/dist/plugins.mjs +18006 -2025
- package/dist/templates/cli/index.ts +26 -0
- package/dist/templates/cli/plugins/hello.ts +43 -0
- package/dist/templates/config/js/getdotenv.config.js +20 -0
- package/dist/templates/config/json/local/getdotenv.config.local.json +7 -0
- package/dist/templates/config/json/public/getdotenv.config.json +9 -0
- package/dist/templates/config/public/getdotenv.config.json +8 -0
- package/dist/templates/config/ts/getdotenv.config.ts +28 -0
- package/dist/templates/config/yaml/local/getdotenv.config.local.yaml +7 -0
- package/dist/templates/config/yaml/public/getdotenv.config.yaml +7 -0
- package/dist/templates/getdotenv.config.js +20 -0
- package/dist/templates/getdotenv.config.json +9 -0
- package/dist/templates/getdotenv.config.local.json +7 -0
- package/dist/templates/getdotenv.config.local.yaml +7 -0
- package/dist/templates/getdotenv.config.ts +28 -0
- package/dist/templates/getdotenv.config.yaml +7 -0
- package/dist/templates/hello.ts +43 -0
- package/dist/templates/index.ts +26 -0
- package/dist/templates/js/getdotenv.config.js +20 -0
- package/dist/templates/json/local/getdotenv.config.local.json +7 -0
- package/dist/templates/json/public/getdotenv.config.json +9 -0
- package/dist/templates/local/getdotenv.config.local.json +7 -0
- package/dist/templates/local/getdotenv.config.local.yaml +7 -0
- package/dist/templates/plugins/hello.ts +43 -0
- package/dist/templates/public/getdotenv.config.json +9 -0
- package/dist/templates/public/getdotenv.config.yaml +7 -0
- package/dist/templates/ts/getdotenv.config.ts +28 -0
- package/dist/templates/yaml/local/getdotenv.config.local.yaml +7 -0
- package/dist/templates/yaml/public/getdotenv.config.yaml +7 -0
- package/getdotenv.config.json +1 -19
- package/package.json +52 -89
- package/templates/cli/index.ts +26 -0
- package/templates/cli/plugins/hello.ts +43 -0
- package/templates/config/js/getdotenv.config.js +9 -4
- package/templates/config/json/public/getdotenv.config.json +0 -3
- package/templates/config/public/getdotenv.config.json +0 -5
- package/templates/config/ts/getdotenv.config.ts +17 -5
- package/templates/config/yaml/public/getdotenv.config.yaml +0 -3
- package/dist/cliHost.cjs +0 -2078
- package/dist/cliHost.d.cts +0 -451
- package/dist/cliHost.d.mts +0 -451
- package/dist/config.cjs +0 -252
- package/dist/config.d.cts +0 -55
- package/dist/config.d.mts +0 -55
- package/dist/env-overlay.cjs +0 -163
- package/dist/env-overlay.d.cts +0 -50
- package/dist/env-overlay.d.mts +0 -50
- package/dist/index.cjs +0 -4077
- package/dist/index.d.cts +0 -318
- package/dist/index.d.mts +0 -318
- package/dist/plugins-aws.cjs +0 -666
- package/dist/plugins-aws.d.cts +0 -158
- package/dist/plugins-aws.d.mts +0 -158
- package/dist/plugins-batch.cjs +0 -658
- package/dist/plugins-batch.d.cts +0 -181
- package/dist/plugins-batch.d.mts +0 -181
- package/dist/plugins-cmd.cjs +0 -1112
- package/dist/plugins-cmd.d.cts +0 -178
- package/dist/plugins-cmd.d.mts +0 -178
- package/dist/plugins-demo.cjs +0 -352
- package/dist/plugins-demo.d.cts +0 -158
- package/dist/plugins-demo.d.mts +0 -158
- package/dist/plugins-demo.d.ts +0 -158
- package/dist/plugins-demo.mjs +0 -350
- package/dist/plugins-init.cjs +0 -289
- package/dist/plugins-init.d.cts +0 -162
- package/dist/plugins-init.d.mts +0 -162
- package/dist/plugins.cjs +0 -2327
- package/dist/plugins.d.cts +0 -211
- package/dist/plugins.d.mts +0 -211
- package/templates/cli/ts/index.ts +0 -9
- package/templates/cli/ts/plugins/hello.ts +0 -17
package/dist/index.d.cts
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
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;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Minimal root options shape shared by CLI and generator layers.
|
|
21
|
-
* Keep keys optional to respect exactOptionalPropertyTypes semantics.
|
|
22
|
-
*/
|
|
23
|
-
type RootOptionsShape = {
|
|
24
|
-
env?: string;
|
|
25
|
-
vars?: string;
|
|
26
|
-
command?: string;
|
|
27
|
-
outputPath?: string;
|
|
28
|
-
shell?: string | boolean;
|
|
29
|
-
loadProcess?: boolean;
|
|
30
|
-
excludeAll?: boolean;
|
|
31
|
-
excludeDynamic?: boolean;
|
|
32
|
-
excludeEnv?: boolean;
|
|
33
|
-
excludeGlobal?: boolean;
|
|
34
|
-
excludePrivate?: boolean;
|
|
35
|
-
excludePublic?: boolean;
|
|
36
|
-
log?: boolean;
|
|
37
|
-
debug?: boolean;
|
|
38
|
-
capture?: boolean;
|
|
39
|
-
strict?: boolean;
|
|
40
|
-
redact?: boolean;
|
|
41
|
-
warnEntropy?: boolean;
|
|
42
|
-
entropyThreshold?: number;
|
|
43
|
-
entropyMinLength?: number;
|
|
44
|
-
entropyWhitelist?: string[];
|
|
45
|
-
redactPatterns?: string[];
|
|
46
|
-
defaultEnv?: string;
|
|
47
|
-
dotenvToken?: string;
|
|
48
|
-
dynamicPath?: string;
|
|
49
|
-
trace?: boolean | string[];
|
|
50
|
-
paths?: string;
|
|
51
|
-
pathsDelimiter?: string;
|
|
52
|
-
pathsDelimiterPattern?: string;
|
|
53
|
-
privateToken?: string;
|
|
54
|
-
varsDelimiter?: string;
|
|
55
|
-
varsDelimiterPattern?: string;
|
|
56
|
-
varsAssignor?: string;
|
|
57
|
-
varsAssignorPattern?: string;
|
|
58
|
-
scripts?: ScriptsTable;
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Scripts table shape (configurable shell type).
|
|
62
|
-
*/
|
|
63
|
-
type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<string, string | {
|
|
64
|
-
cmd: string;
|
|
65
|
-
shell?: TShell;
|
|
66
|
-
}>;
|
|
67
|
-
|
|
68
|
-
type RootOptionsShapeCompat = Omit<RootOptionsShape, 'vars' | 'paths'> & {
|
|
69
|
-
vars?: string | Record<string, string | undefined>;
|
|
70
|
-
paths?: string | string[];
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* A minimal representation of an environment key/value mapping.
|
|
74
|
-
* Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
|
|
75
|
-
/**
|
|
76
|
-
* Dynamic variable function signature. Receives the current expanded variables
|
|
77
|
-
* and the selected environment (if any), and returns either a string to set
|
|
78
|
-
* or `undefined` to unset/skip the variable.
|
|
79
|
-
*/
|
|
80
|
-
type GetDotenvDynamicFunction = (vars: ProcessEnv, env: string | undefined) => string | undefined;
|
|
81
|
-
type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
|
|
82
|
-
type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
|
|
83
|
-
/**
|
|
84
|
-
* Helper to define a dynamic map with strong inference.
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* const dynamic = defineDynamic(\{ KEY: (\{ FOO = '' \}) =\> FOO + '-x' \});
|
|
88
|
-
*/
|
|
89
|
-
declare const defineDynamic: <T extends GetDotenvDynamic>(d: T) => T;
|
|
90
|
-
/**
|
|
91
|
-
* Options passed programmatically to `getDotenv`.
|
|
92
|
-
*/
|
|
93
|
-
interface GetDotenvOptions {
|
|
94
|
-
/**
|
|
95
|
-
* default target environment (used if `env` is not provided)
|
|
96
|
-
*/
|
|
97
|
-
defaultEnv?: string;
|
|
98
|
-
/**
|
|
99
|
-
* token indicating a dotenv file
|
|
100
|
-
*/
|
|
101
|
-
dotenvToken: string;
|
|
102
|
-
/**
|
|
103
|
-
* path to JS/TS module default-exporting an object keyed to dynamic variable functions
|
|
104
|
-
*/
|
|
105
|
-
dynamicPath?: string;
|
|
106
|
-
/**
|
|
107
|
-
* Programmatic dynamic variables map. When provided, this takes precedence
|
|
108
|
-
* over {@link GetDotenvOptions.dynamicPath}.
|
|
109
|
-
*/
|
|
110
|
-
dynamic?: GetDotenvDynamic;
|
|
111
|
-
/**
|
|
112
|
-
* target environment
|
|
113
|
-
*/
|
|
114
|
-
env?: string;
|
|
115
|
-
/**
|
|
116
|
-
* exclude dynamic variables from loading
|
|
117
|
-
*/
|
|
118
|
-
excludeDynamic?: boolean;
|
|
119
|
-
/**
|
|
120
|
-
* exclude environment-specific variables from loading
|
|
121
|
-
*/
|
|
122
|
-
excludeEnv?: boolean;
|
|
123
|
-
/**
|
|
124
|
-
* exclude global variables from loading
|
|
125
|
-
*/
|
|
126
|
-
excludeGlobal?: boolean;
|
|
127
|
-
/**
|
|
128
|
-
* exclude private variables from loading
|
|
129
|
-
*/
|
|
130
|
-
excludePrivate?: boolean;
|
|
131
|
-
/**
|
|
132
|
-
* exclude public variables from loading
|
|
133
|
-
*/
|
|
134
|
-
excludePublic?: boolean;
|
|
135
|
-
/**
|
|
136
|
-
* load dotenv variables to `process.env`
|
|
137
|
-
*/
|
|
138
|
-
loadProcess?: boolean;
|
|
139
|
-
/**
|
|
140
|
-
* log loaded dotenv variables to `logger`
|
|
141
|
-
*/
|
|
142
|
-
log?: boolean;
|
|
143
|
-
/**
|
|
144
|
-
* logger object (defaults to console)
|
|
145
|
-
*/
|
|
146
|
-
logger?: Logger;
|
|
147
|
-
/**
|
|
148
|
-
* if populated, writes consolidated dotenv file to this path (follows dotenvExpand rules)
|
|
149
|
-
*/
|
|
150
|
-
outputPath?: string;
|
|
151
|
-
/**
|
|
152
|
-
* array of input directory paths
|
|
153
|
-
*/
|
|
154
|
-
paths?: string[];
|
|
155
|
-
/**
|
|
156
|
-
* filename token indicating private variables
|
|
157
|
-
*/
|
|
158
|
-
privateToken?: string;
|
|
159
|
-
/**
|
|
160
|
-
* explicit variables to include
|
|
161
|
-
*/
|
|
162
|
-
vars?: ProcessEnv;
|
|
163
|
-
/**
|
|
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.
|
|
169
|
-
*/
|
|
170
|
-
useConfigLoader?: boolean;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Converts programmatic CLI options to `getDotenv` options. *
|
|
174
|
-
* @param cliOptions - CLI options. Defaults to `{}`.
|
|
175
|
-
*
|
|
176
|
-
* @returns `getDotenv` options.
|
|
177
|
-
*/
|
|
178
|
-
declare const getDotenvCliOptions2Options: ({ paths, pathsDelimiter, pathsDelimiterPattern, vars, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, ...rest }: RootOptionsShapeCompat) => GetDotenvOptions;
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Recursively expands environment variables in a string. Variables may be
|
|
182
|
-
* presented with optional default as `$VAR[:default]` or `${VAR[:default]}`.
|
|
183
|
-
* Unknown variables will expand to an empty string.
|
|
184
|
-
*
|
|
185
|
-
* @param value - The string to expand.
|
|
186
|
-
* @param ref - The reference object to use for variable expansion.
|
|
187
|
-
* @returns The expanded string.
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* ```ts
|
|
191
|
-
* process.env.FOO = 'bar';
|
|
192
|
-
* dotenvExpand('Hello $FOO'); // "Hello bar"
|
|
193
|
-
* dotenvExpand('Hello $BAZ:world'); // "Hello world"
|
|
194
|
-
* ```
|
|
195
|
-
*
|
|
196
|
-
* @remarks
|
|
197
|
-
* The expansion is recursive. If a referenced variable itself contains
|
|
198
|
-
* references, those will also be expanded until a stable value is reached.
|
|
199
|
-
* Escaped references (e.g. `\$FOO`) are preserved as literals.
|
|
200
|
-
*/
|
|
201
|
-
declare const dotenvExpand: (value: string | undefined, ref?: ProcessEnv) => string | undefined;
|
|
202
|
-
/**
|
|
203
|
-
* Recursively expands environment variables in the values of a JSON object.
|
|
204
|
-
* Variables may be presented with optional default as `$VAR[:default]` or
|
|
205
|
-
* `${VAR[:default]}`. Unknown variables will expand to an empty string.
|
|
206
|
-
*
|
|
207
|
-
* @param values - The values object to expand.
|
|
208
|
-
* @param options - Expansion options.
|
|
209
|
-
* @returns The value object with expanded string values.
|
|
210
|
-
*
|
|
211
|
-
* @example
|
|
212
|
-
* ```ts
|
|
213
|
-
* process.env.FOO = 'bar';
|
|
214
|
-
* dotenvExpandAll({ A: '$FOO', B: 'x${FOO}y' });
|
|
215
|
-
* // => { A: "bar", B: "xbary" }
|
|
216
|
-
* ```
|
|
217
|
-
*
|
|
218
|
-
* @remarks
|
|
219
|
-
* Options:
|
|
220
|
-
* - ref: The reference object to use for expansion (defaults to process.env).
|
|
221
|
-
* - progressive: Whether to progressively add expanded values to the set of
|
|
222
|
-
* reference keys.
|
|
223
|
-
*
|
|
224
|
-
* When `progressive` is true, each expanded key becomes available for
|
|
225
|
-
* subsequent expansions in the same object (left-to-right by object key order).
|
|
226
|
-
*/
|
|
227
|
-
declare const dotenvExpandAll: (values?: ProcessEnv, options?: {
|
|
228
|
-
ref?: ProcessEnv;
|
|
229
|
-
progressive?: boolean;
|
|
230
|
-
}) => Record<string, string | undefined>;
|
|
231
|
-
/**
|
|
232
|
-
* Recursively expands environment variables in a string using `process.env` as
|
|
233
|
-
* the expansion reference. Variables may be presented with optional default as
|
|
234
|
-
* `$VAR[:default]` or `${VAR[:default]}`. Unknown variables will expand to an
|
|
235
|
-
* empty string.
|
|
236
|
-
*
|
|
237
|
-
* @param value - The string to expand.
|
|
238
|
-
* @returns The expanded string.
|
|
239
|
-
*
|
|
240
|
-
* @example
|
|
241
|
-
* ```ts
|
|
242
|
-
* process.env.FOO = 'bar';
|
|
243
|
-
* dotenvExpandFromProcessEnv('Hello $FOO'); // "Hello bar"
|
|
244
|
-
* ```
|
|
245
|
-
*/
|
|
246
|
-
declare const dotenvExpandFromProcessEnv: (value: string | undefined) => string | undefined;
|
|
247
|
-
|
|
248
|
-
/**
|
|
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
|
-
* ```
|
|
258
|
-
*
|
|
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.
|
|
283
|
-
*/
|
|
284
|
-
declare const getDotenv: (options?: Partial<GetDotenvOptions>) => Promise<ProcessEnv>;
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Deeply interpolate string leaves against envRef.
|
|
288
|
-
* Arrays are not recursed into; they are returned unchanged.
|
|
289
|
-
*
|
|
290
|
-
* @typeParam T - Shape of the input value.
|
|
291
|
-
* @param value - Input value (object/array/primitive).
|
|
292
|
-
* @param envRef - Reference environment for interpolation.
|
|
293
|
-
* @returns A new value with string leaves interpolated.
|
|
294
|
-
*/
|
|
295
|
-
declare const interpolateDeep: <T>(value: T, envRef: ProcessEnv) => T;
|
|
296
|
-
|
|
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 };
|
package/dist/index.d.mts
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
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;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Minimal root options shape shared by CLI and generator layers.
|
|
21
|
-
* Keep keys optional to respect exactOptionalPropertyTypes semantics.
|
|
22
|
-
*/
|
|
23
|
-
type RootOptionsShape = {
|
|
24
|
-
env?: string;
|
|
25
|
-
vars?: string;
|
|
26
|
-
command?: string;
|
|
27
|
-
outputPath?: string;
|
|
28
|
-
shell?: string | boolean;
|
|
29
|
-
loadProcess?: boolean;
|
|
30
|
-
excludeAll?: boolean;
|
|
31
|
-
excludeDynamic?: boolean;
|
|
32
|
-
excludeEnv?: boolean;
|
|
33
|
-
excludeGlobal?: boolean;
|
|
34
|
-
excludePrivate?: boolean;
|
|
35
|
-
excludePublic?: boolean;
|
|
36
|
-
log?: boolean;
|
|
37
|
-
debug?: boolean;
|
|
38
|
-
capture?: boolean;
|
|
39
|
-
strict?: boolean;
|
|
40
|
-
redact?: boolean;
|
|
41
|
-
warnEntropy?: boolean;
|
|
42
|
-
entropyThreshold?: number;
|
|
43
|
-
entropyMinLength?: number;
|
|
44
|
-
entropyWhitelist?: string[];
|
|
45
|
-
redactPatterns?: string[];
|
|
46
|
-
defaultEnv?: string;
|
|
47
|
-
dotenvToken?: string;
|
|
48
|
-
dynamicPath?: string;
|
|
49
|
-
trace?: boolean | string[];
|
|
50
|
-
paths?: string;
|
|
51
|
-
pathsDelimiter?: string;
|
|
52
|
-
pathsDelimiterPattern?: string;
|
|
53
|
-
privateToken?: string;
|
|
54
|
-
varsDelimiter?: string;
|
|
55
|
-
varsDelimiterPattern?: string;
|
|
56
|
-
varsAssignor?: string;
|
|
57
|
-
varsAssignorPattern?: string;
|
|
58
|
-
scripts?: ScriptsTable;
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Scripts table shape (configurable shell type).
|
|
62
|
-
*/
|
|
63
|
-
type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<string, string | {
|
|
64
|
-
cmd: string;
|
|
65
|
-
shell?: TShell;
|
|
66
|
-
}>;
|
|
67
|
-
|
|
68
|
-
type RootOptionsShapeCompat = Omit<RootOptionsShape, 'vars' | 'paths'> & {
|
|
69
|
-
vars?: string | Record<string, string | undefined>;
|
|
70
|
-
paths?: string | string[];
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* A minimal representation of an environment key/value mapping.
|
|
74
|
-
* Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
|
|
75
|
-
/**
|
|
76
|
-
* Dynamic variable function signature. Receives the current expanded variables
|
|
77
|
-
* and the selected environment (if any), and returns either a string to set
|
|
78
|
-
* or `undefined` to unset/skip the variable.
|
|
79
|
-
*/
|
|
80
|
-
type GetDotenvDynamicFunction = (vars: ProcessEnv, env: string | undefined) => string | undefined;
|
|
81
|
-
type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
|
|
82
|
-
type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
|
|
83
|
-
/**
|
|
84
|
-
* Helper to define a dynamic map with strong inference.
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* const dynamic = defineDynamic(\{ KEY: (\{ FOO = '' \}) =\> FOO + '-x' \});
|
|
88
|
-
*/
|
|
89
|
-
declare const defineDynamic: <T extends GetDotenvDynamic>(d: T) => T;
|
|
90
|
-
/**
|
|
91
|
-
* Options passed programmatically to `getDotenv`.
|
|
92
|
-
*/
|
|
93
|
-
interface GetDotenvOptions {
|
|
94
|
-
/**
|
|
95
|
-
* default target environment (used if `env` is not provided)
|
|
96
|
-
*/
|
|
97
|
-
defaultEnv?: string;
|
|
98
|
-
/**
|
|
99
|
-
* token indicating a dotenv file
|
|
100
|
-
*/
|
|
101
|
-
dotenvToken: string;
|
|
102
|
-
/**
|
|
103
|
-
* path to JS/TS module default-exporting an object keyed to dynamic variable functions
|
|
104
|
-
*/
|
|
105
|
-
dynamicPath?: string;
|
|
106
|
-
/**
|
|
107
|
-
* Programmatic dynamic variables map. When provided, this takes precedence
|
|
108
|
-
* over {@link GetDotenvOptions.dynamicPath}.
|
|
109
|
-
*/
|
|
110
|
-
dynamic?: GetDotenvDynamic;
|
|
111
|
-
/**
|
|
112
|
-
* target environment
|
|
113
|
-
*/
|
|
114
|
-
env?: string;
|
|
115
|
-
/**
|
|
116
|
-
* exclude dynamic variables from loading
|
|
117
|
-
*/
|
|
118
|
-
excludeDynamic?: boolean;
|
|
119
|
-
/**
|
|
120
|
-
* exclude environment-specific variables from loading
|
|
121
|
-
*/
|
|
122
|
-
excludeEnv?: boolean;
|
|
123
|
-
/**
|
|
124
|
-
* exclude global variables from loading
|
|
125
|
-
*/
|
|
126
|
-
excludeGlobal?: boolean;
|
|
127
|
-
/**
|
|
128
|
-
* exclude private variables from loading
|
|
129
|
-
*/
|
|
130
|
-
excludePrivate?: boolean;
|
|
131
|
-
/**
|
|
132
|
-
* exclude public variables from loading
|
|
133
|
-
*/
|
|
134
|
-
excludePublic?: boolean;
|
|
135
|
-
/**
|
|
136
|
-
* load dotenv variables to `process.env`
|
|
137
|
-
*/
|
|
138
|
-
loadProcess?: boolean;
|
|
139
|
-
/**
|
|
140
|
-
* log loaded dotenv variables to `logger`
|
|
141
|
-
*/
|
|
142
|
-
log?: boolean;
|
|
143
|
-
/**
|
|
144
|
-
* logger object (defaults to console)
|
|
145
|
-
*/
|
|
146
|
-
logger?: Logger;
|
|
147
|
-
/**
|
|
148
|
-
* if populated, writes consolidated dotenv file to this path (follows dotenvExpand rules)
|
|
149
|
-
*/
|
|
150
|
-
outputPath?: string;
|
|
151
|
-
/**
|
|
152
|
-
* array of input directory paths
|
|
153
|
-
*/
|
|
154
|
-
paths?: string[];
|
|
155
|
-
/**
|
|
156
|
-
* filename token indicating private variables
|
|
157
|
-
*/
|
|
158
|
-
privateToken?: string;
|
|
159
|
-
/**
|
|
160
|
-
* explicit variables to include
|
|
161
|
-
*/
|
|
162
|
-
vars?: ProcessEnv;
|
|
163
|
-
/**
|
|
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.
|
|
169
|
-
*/
|
|
170
|
-
useConfigLoader?: boolean;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Converts programmatic CLI options to `getDotenv` options. *
|
|
174
|
-
* @param cliOptions - CLI options. Defaults to `{}`.
|
|
175
|
-
*
|
|
176
|
-
* @returns `getDotenv` options.
|
|
177
|
-
*/
|
|
178
|
-
declare const getDotenvCliOptions2Options: ({ paths, pathsDelimiter, pathsDelimiterPattern, vars, varsAssignor, varsAssignorPattern, varsDelimiter, varsDelimiterPattern, ...rest }: RootOptionsShapeCompat) => GetDotenvOptions;
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Recursively expands environment variables in a string. Variables may be
|
|
182
|
-
* presented with optional default as `$VAR[:default]` or `${VAR[:default]}`.
|
|
183
|
-
* Unknown variables will expand to an empty string.
|
|
184
|
-
*
|
|
185
|
-
* @param value - The string to expand.
|
|
186
|
-
* @param ref - The reference object to use for variable expansion.
|
|
187
|
-
* @returns The expanded string.
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* ```ts
|
|
191
|
-
* process.env.FOO = 'bar';
|
|
192
|
-
* dotenvExpand('Hello $FOO'); // "Hello bar"
|
|
193
|
-
* dotenvExpand('Hello $BAZ:world'); // "Hello world"
|
|
194
|
-
* ```
|
|
195
|
-
*
|
|
196
|
-
* @remarks
|
|
197
|
-
* The expansion is recursive. If a referenced variable itself contains
|
|
198
|
-
* references, those will also be expanded until a stable value is reached.
|
|
199
|
-
* Escaped references (e.g. `\$FOO`) are preserved as literals.
|
|
200
|
-
*/
|
|
201
|
-
declare const dotenvExpand: (value: string | undefined, ref?: ProcessEnv) => string | undefined;
|
|
202
|
-
/**
|
|
203
|
-
* Recursively expands environment variables in the values of a JSON object.
|
|
204
|
-
* Variables may be presented with optional default as `$VAR[:default]` or
|
|
205
|
-
* `${VAR[:default]}`. Unknown variables will expand to an empty string.
|
|
206
|
-
*
|
|
207
|
-
* @param values - The values object to expand.
|
|
208
|
-
* @param options - Expansion options.
|
|
209
|
-
* @returns The value object with expanded string values.
|
|
210
|
-
*
|
|
211
|
-
* @example
|
|
212
|
-
* ```ts
|
|
213
|
-
* process.env.FOO = 'bar';
|
|
214
|
-
* dotenvExpandAll({ A: '$FOO', B: 'x${FOO}y' });
|
|
215
|
-
* // => { A: "bar", B: "xbary" }
|
|
216
|
-
* ```
|
|
217
|
-
*
|
|
218
|
-
* @remarks
|
|
219
|
-
* Options:
|
|
220
|
-
* - ref: The reference object to use for expansion (defaults to process.env).
|
|
221
|
-
* - progressive: Whether to progressively add expanded values to the set of
|
|
222
|
-
* reference keys.
|
|
223
|
-
*
|
|
224
|
-
* When `progressive` is true, each expanded key becomes available for
|
|
225
|
-
* subsequent expansions in the same object (left-to-right by object key order).
|
|
226
|
-
*/
|
|
227
|
-
declare const dotenvExpandAll: (values?: ProcessEnv, options?: {
|
|
228
|
-
ref?: ProcessEnv;
|
|
229
|
-
progressive?: boolean;
|
|
230
|
-
}) => Record<string, string | undefined>;
|
|
231
|
-
/**
|
|
232
|
-
* Recursively expands environment variables in a string using `process.env` as
|
|
233
|
-
* the expansion reference. Variables may be presented with optional default as
|
|
234
|
-
* `$VAR[:default]` or `${VAR[:default]}`. Unknown variables will expand to an
|
|
235
|
-
* empty string.
|
|
236
|
-
*
|
|
237
|
-
* @param value - The string to expand.
|
|
238
|
-
* @returns The expanded string.
|
|
239
|
-
*
|
|
240
|
-
* @example
|
|
241
|
-
* ```ts
|
|
242
|
-
* process.env.FOO = 'bar';
|
|
243
|
-
* dotenvExpandFromProcessEnv('Hello $FOO'); // "Hello bar"
|
|
244
|
-
* ```
|
|
245
|
-
*/
|
|
246
|
-
declare const dotenvExpandFromProcessEnv: (value: string | undefined) => string | undefined;
|
|
247
|
-
|
|
248
|
-
/**
|
|
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
|
-
* ```
|
|
258
|
-
*
|
|
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.
|
|
283
|
-
*/
|
|
284
|
-
declare const getDotenv: (options?: Partial<GetDotenvOptions>) => Promise<ProcessEnv>;
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Deeply interpolate string leaves against envRef.
|
|
288
|
-
* Arrays are not recursed into; they are returned unchanged.
|
|
289
|
-
*
|
|
290
|
-
* @typeParam T - Shape of the input value.
|
|
291
|
-
* @param value - Input value (object/array/primitive).
|
|
292
|
-
* @param envRef - Reference environment for interpolation.
|
|
293
|
-
* @returns A new value with string leaves interpolated.
|
|
294
|
-
*/
|
|
295
|
-
declare const interpolateDeep: <T>(value: T, envRef: ProcessEnv) => T;
|
|
296
|
-
|
|
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 };
|