@karmaniverous/get-dotenv 5.2.1 → 5.2.3
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 +1 -1
- package/dist/getdotenv.cli.mjs +0 -30
- package/dist/index.cjs +0 -30
- package/dist/index.mjs +0 -30
- package/dist/plugins-cmd.cjs +2501 -0
- package/dist/plugins-cmd.d.cts +311 -0
- package/dist/plugins-cmd.d.mts +311 -0
- package/dist/plugins-cmd.d.ts +311 -0
- package/dist/plugins-cmd.mjs +2498 -0
- package/dist/plugins-demo.cjs +300 -0
- package/dist/plugins-demo.d.cts +291 -0
- package/dist/plugins-demo.d.mts +291 -0
- package/dist/plugins-demo.d.ts +291 -0
- package/dist/plugins-demo.mjs +298 -0
- package/dist/plugins.cjs +3670 -0
- package/dist/plugins.d.cts +343 -0
- package/dist/plugins.d.mts +343 -0
- package/dist/plugins.d.ts +343 -0
- package/dist/plugins.mjs +3663 -0
- package/package.json +33 -1
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A minimal representation of an environment key/value mapping.
|
|
6
|
+
* Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
* Dynamic variable function signature. Receives the current expanded variables
|
|
9
|
+
* and the selected environment (if any), and returns either a string to set
|
|
10
|
+
* or `undefined` to unset/skip the variable.
|
|
11
|
+
*/
|
|
12
|
+
type GetDotenvDynamicFunction = (vars: ProcessEnv, env: string | undefined) => string | undefined;
|
|
13
|
+
type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
|
|
14
|
+
type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
|
|
15
|
+
/**
|
|
16
|
+
* Options passed programmatically to `getDotenv`.
|
|
17
|
+
*/
|
|
18
|
+
interface GetDotenvOptions {
|
|
19
|
+
/**
|
|
20
|
+
* default target environment (used if `env` is not provided)
|
|
21
|
+
*/
|
|
22
|
+
defaultEnv?: string;
|
|
23
|
+
/**
|
|
24
|
+
* token indicating a dotenv file
|
|
25
|
+
*/
|
|
26
|
+
dotenvToken: string;
|
|
27
|
+
/**
|
|
28
|
+
* path to JS/TS module default-exporting an object keyed to dynamic variable functions
|
|
29
|
+
*/
|
|
30
|
+
dynamicPath?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Programmatic dynamic variables map. When provided, this takes precedence
|
|
33
|
+
* over {@link GetDotenvOptions.dynamicPath}.
|
|
34
|
+
*/
|
|
35
|
+
dynamic?: GetDotenvDynamic;
|
|
36
|
+
/**
|
|
37
|
+
* target environment
|
|
38
|
+
*/
|
|
39
|
+
env?: string;
|
|
40
|
+
/**
|
|
41
|
+
* exclude dynamic variables from loading
|
|
42
|
+
*/
|
|
43
|
+
excludeDynamic?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* exclude environment-specific variables from loading
|
|
46
|
+
*/
|
|
47
|
+
excludeEnv?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* exclude global variables from loading
|
|
50
|
+
*/
|
|
51
|
+
excludeGlobal?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* exclude private variables from loading
|
|
54
|
+
*/
|
|
55
|
+
excludePrivate?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* exclude public variables from loading
|
|
58
|
+
*/
|
|
59
|
+
excludePublic?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* load dotenv variables to `process.env`
|
|
62
|
+
*/
|
|
63
|
+
loadProcess?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* log loaded dotenv variables to `logger`
|
|
66
|
+
*/
|
|
67
|
+
log?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* logger object (defaults to console)
|
|
70
|
+
*/
|
|
71
|
+
logger?: Logger;
|
|
72
|
+
/**
|
|
73
|
+
* if populated, writes consolidated dotenv file to this path (follows dotenvExpand rules)
|
|
74
|
+
*/
|
|
75
|
+
outputPath?: string;
|
|
76
|
+
/**
|
|
77
|
+
* array of input directory paths
|
|
78
|
+
*/
|
|
79
|
+
paths?: string[];
|
|
80
|
+
/**
|
|
81
|
+
* filename token indicating private variables
|
|
82
|
+
*/
|
|
83
|
+
privateToken?: string;
|
|
84
|
+
/**
|
|
85
|
+
* explicit variables to include
|
|
86
|
+
*/
|
|
87
|
+
vars?: ProcessEnv;
|
|
88
|
+
/**
|
|
89
|
+
* Reserved: config loader flag (no-op).
|
|
90
|
+
* The plugin-first host and generator paths already use the config
|
|
91
|
+
* loader/overlay pipeline unconditionally (no-op when no config files
|
|
92
|
+
* are present). This flag is accepted for forward compatibility but
|
|
93
|
+
* currently has no effect.
|
|
94
|
+
*/
|
|
95
|
+
useConfigLoader?: boolean;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type Scripts$1 = Record<string, string | {
|
|
99
|
+
cmd: string;
|
|
100
|
+
shell?: string | boolean;
|
|
101
|
+
}>;
|
|
102
|
+
/**
|
|
103
|
+
* Options passed programmatically to `getDotenvCli`.
|
|
104
|
+
*/
|
|
105
|
+
interface GetDotenvCliOptions extends Omit<GetDotenvOptions, 'paths' | 'vars'> {
|
|
106
|
+
/**
|
|
107
|
+
* Logs CLI internals when true.
|
|
108
|
+
*/
|
|
109
|
+
debug?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Strict mode: fail the run when env validation issues are detected
|
|
112
|
+
* (schema or requiredKeys). Warns by default when false or unset.
|
|
113
|
+
*/
|
|
114
|
+
strict?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Redaction (presentation): mask secret-like values in logs/trace.
|
|
117
|
+
*/
|
|
118
|
+
redact?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Entropy warnings (presentation): emit once-per-key warnings for high-entropy values.
|
|
121
|
+
*/
|
|
122
|
+
warnEntropy?: boolean;
|
|
123
|
+
entropyThreshold?: number;
|
|
124
|
+
entropyMinLength?: number;
|
|
125
|
+
entropyWhitelist?: string[];
|
|
126
|
+
redactPatterns?: string[];
|
|
127
|
+
/**
|
|
128
|
+
* When true, capture child stdout/stderr and re-emit after completion.
|
|
129
|
+
* Useful for tests/CI. Default behavior is streaming via stdio: 'inherit'.
|
|
130
|
+
*/
|
|
131
|
+
capture?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* A delimited string of paths to dotenv files.
|
|
134
|
+
*/
|
|
135
|
+
paths?: string;
|
|
136
|
+
/**
|
|
137
|
+
* A delimiter string with which to split `paths`. Only used if
|
|
138
|
+
* `pathsDelimiterPattern` is not provided.
|
|
139
|
+
*/
|
|
140
|
+
pathsDelimiter?: string;
|
|
141
|
+
/**
|
|
142
|
+
* A regular expression pattern with which to split `paths`. Supersedes
|
|
143
|
+
* `pathsDelimiter`.
|
|
144
|
+
*/
|
|
145
|
+
pathsDelimiterPattern?: string;
|
|
146
|
+
/**
|
|
147
|
+
* Scripts that can be executed from the CLI, either individually or via the batch subcommand.
|
|
148
|
+
*/
|
|
149
|
+
scripts?: Scripts$1;
|
|
150
|
+
/**
|
|
151
|
+
* Determines how commands and scripts are executed. If `false` or
|
|
152
|
+
* `undefined`, commands are executed as plain Javascript using the default
|
|
153
|
+
* execa parser. If `true`, commands are executed using the default OS shell
|
|
154
|
+
* parser. Otherwise the user may provide a specific shell string (e.g.
|
|
155
|
+
* `/bin/bash`)
|
|
156
|
+
*/
|
|
157
|
+
shell?: string | boolean;
|
|
158
|
+
/**
|
|
159
|
+
* A delimited string of key-value pairs declaratively specifying variables &
|
|
160
|
+
* values to be loaded in addition to any dotenv files.
|
|
161
|
+
*/
|
|
162
|
+
vars?: string;
|
|
163
|
+
/**
|
|
164
|
+
* A string with which to split keys from values in `vars`. Only used if
|
|
165
|
+
* `varsDelimiterPattern` is not provided.
|
|
166
|
+
*/
|
|
167
|
+
varsAssignor?: string;
|
|
168
|
+
/**
|
|
169
|
+
* A regular expression pattern with which to split variable names from values
|
|
170
|
+
* in `vars`. Supersedes `varsAssignor`.
|
|
171
|
+
*/
|
|
172
|
+
varsAssignorPattern?: string;
|
|
173
|
+
/**
|
|
174
|
+
* A string with which to split `vars` into key-value pairs. Only used if
|
|
175
|
+
* `varsDelimiterPattern` is not provided.
|
|
176
|
+
*/
|
|
177
|
+
varsDelimiter?: string;
|
|
178
|
+
/**
|
|
179
|
+
* A regular expression pattern with which to split `vars` into key-value
|
|
180
|
+
* pairs. Supersedes `varsDelimiter`.
|
|
181
|
+
*/
|
|
182
|
+
varsDelimiterPattern?: string;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** * Per-invocation context shared with plugins and actions. */
|
|
186
|
+
type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
|
|
187
|
+
optionsResolved: TOptions;
|
|
188
|
+
dotenv: ProcessEnv;
|
|
189
|
+
plugins?: Record<string, unknown>;
|
|
190
|
+
pluginConfigs?: Record<string, unknown>;
|
|
191
|
+
};
|
|
192
|
+
declare const HELP_HEADER_SYMBOL: unique symbol;
|
|
193
|
+
/**
|
|
194
|
+
* Plugin-first CLI host for get-dotenv. Extends Commander.Command.
|
|
195
|
+
*
|
|
196
|
+
* Responsibilities:
|
|
197
|
+
* - Resolve options strictly and compute dotenv context (resolveAndLoad).
|
|
198
|
+
* - Expose a stable accessor for the current context (getCtx).
|
|
199
|
+
* - Provide a namespacing helper (ns).
|
|
200
|
+
* - Support composable plugins with parent → children install and afterResolve.
|
|
201
|
+
*
|
|
202
|
+
* NOTE: This host is additive and does not alter the legacy CLI.
|
|
203
|
+
*/
|
|
204
|
+
declare class GetDotenvCli<TOptions extends GetDotenvOptions = GetDotenvOptions> extends Command {
|
|
205
|
+
#private;
|
|
206
|
+
/** Registered top-level plugins (composition happens via .use()) */
|
|
207
|
+
private _plugins;
|
|
208
|
+
/** One-time installation guard */
|
|
209
|
+
private _installed;
|
|
210
|
+
/** Optional header line to prepend in help output */
|
|
211
|
+
private [HELP_HEADER_SYMBOL];
|
|
212
|
+
constructor(alias?: string);
|
|
213
|
+
/**
|
|
214
|
+
* Resolve options (strict) and compute dotenv context. * Stores the context on the instance under a symbol.
|
|
215
|
+
*/
|
|
216
|
+
resolveAndLoad(customOptions?: Partial<TOptions>): Promise<GetDotenvCliCtx<TOptions>>;
|
|
217
|
+
/**
|
|
218
|
+
* Retrieve the current invocation context (if any).
|
|
219
|
+
*/
|
|
220
|
+
getCtx(): GetDotenvCliCtx<TOptions> | undefined;
|
|
221
|
+
/**
|
|
222
|
+
* Retrieve the merged root CLI options bag (if set by passOptions()).
|
|
223
|
+
* Downstream-safe: no generics required.
|
|
224
|
+
*/
|
|
225
|
+
getOptions(): GetDotenvCliOptions | undefined;
|
|
226
|
+
/** Internal: set the merged root options bag for this run. */
|
|
227
|
+
_setOptionsBag(bag: GetDotenvCliOptions): void;
|
|
228
|
+
/** * Convenience helper to create a namespaced subcommand.
|
|
229
|
+
*/
|
|
230
|
+
ns(name: string): Command;
|
|
231
|
+
/**
|
|
232
|
+
* Tag options added during the provided callback as 'app' for grouped help.
|
|
233
|
+
* Allows downstream apps to demarcate their root-level options.
|
|
234
|
+
*/
|
|
235
|
+
tagAppOptions<T>(fn: (root: Command) => T): T;
|
|
236
|
+
/**
|
|
237
|
+
* Branding helper: set CLI name/description/version and optional help header.
|
|
238
|
+
* If version is omitted and importMetaUrl is provided, attempts to read the
|
|
239
|
+
* nearest package.json version (best-effort; non-fatal on failure).
|
|
240
|
+
*/
|
|
241
|
+
brand(args: {
|
|
242
|
+
name?: string;
|
|
243
|
+
description?: string;
|
|
244
|
+
version?: string;
|
|
245
|
+
importMetaUrl?: string;
|
|
246
|
+
helpHeader?: string;
|
|
247
|
+
}): Promise<this>;
|
|
248
|
+
/**
|
|
249
|
+
* Register a plugin for installation (parent level).
|
|
250
|
+
* Installation occurs on first resolveAndLoad() (or explicit install()).
|
|
251
|
+
*/
|
|
252
|
+
use(plugin: GetDotenvCliPlugin): this;
|
|
253
|
+
/**
|
|
254
|
+
* Install all registered plugins in parent → children (pre-order).
|
|
255
|
+
* Runs only once per CLI instance.
|
|
256
|
+
*/
|
|
257
|
+
install(): Promise<void>;
|
|
258
|
+
/**
|
|
259
|
+
* Run afterResolve hooks for all plugins (parent → children).
|
|
260
|
+
*/
|
|
261
|
+
private _runAfterResolve;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Public plugin contract used by the GetDotenv CLI host. */ interface GetDotenvCliPlugin {
|
|
265
|
+
id?: string /**
|
|
266
|
+
* Setup phase: register commands and wiring on the provided CLI instance. * Runs parent → children (pre-order).
|
|
267
|
+
*/;
|
|
268
|
+
setup: (cli: GetDotenvCli) => void | Promise<void>;
|
|
269
|
+
/**
|
|
270
|
+
* After the dotenv context is resolved, initialize any clients/secrets
|
|
271
|
+
* or attach per-plugin state under ctx.plugins (by convention).
|
|
272
|
+
* Runs parent → children (pre-order).
|
|
273
|
+
*/
|
|
274
|
+
afterResolve?: (cli: GetDotenvCli, ctx: GetDotenvCliCtx) => void | Promise<void>;
|
|
275
|
+
/**
|
|
276
|
+
* Optional Zod schema for this plugin's config slice (from config.plugins[id]).
|
|
277
|
+
* When provided, the host validates the merged config under the guarded loader path.
|
|
278
|
+
*/
|
|
279
|
+
configSchema?: ZodType;
|
|
280
|
+
/**
|
|
281
|
+
* Compositional children. Installed after the parent per pre-order.
|
|
282
|
+
*/ children: GetDotenvCliPlugin[];
|
|
283
|
+
/**
|
|
284
|
+
* Compose a child plugin. Returns the parent to enable chaining.
|
|
285
|
+
*/
|
|
286
|
+
use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
declare const awsPlugin: () => GetDotenvCliPlugin;
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Batch services (neutral): resolve command and shell settings.
|
|
293
|
+
* Shared by the generator path and the batch plugin to avoid circular deps.
|
|
294
|
+
*/
|
|
295
|
+
type Scripts = Record<string, string | {
|
|
296
|
+
cmd: string;
|
|
297
|
+
shell?: string | boolean | undefined;
|
|
298
|
+
}>;
|
|
299
|
+
|
|
300
|
+
type BatchPluginOptions = {
|
|
301
|
+
scripts?: Scripts;
|
|
302
|
+
shell?: string | boolean;
|
|
303
|
+
logger?: Logger;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Batch plugin for the GetDotenv CLI host.
|
|
308
|
+
*
|
|
309
|
+
* Mirrors the legacy batch subcommand behavior without altering the shipped CLI. * Options:
|
|
310
|
+
* - scripts/shell: used to resolve command and shell behavior per script or global default.
|
|
311
|
+
* - logger: defaults to console.
|
|
312
|
+
*/
|
|
313
|
+
declare const batchPlugin: (opts?: BatchPluginOptions) => GetDotenvCliPlugin;
|
|
314
|
+
|
|
315
|
+
type CmdPluginOptions = {
|
|
316
|
+
/**
|
|
317
|
+
* When true, register as the default subcommand at the root. */
|
|
318
|
+
asDefault?: boolean;
|
|
319
|
+
/**
|
|
320
|
+
* Optional alias option attached to the parent command to invoke the cmd * behavior without specifying the subcommand explicitly.
|
|
321
|
+
*/
|
|
322
|
+
optionAlias?: string | {
|
|
323
|
+
flags: string;
|
|
324
|
+
description?: string;
|
|
325
|
+
expand?: boolean;
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
/**+ Cmd plugin: executes a command using the current getdotenv CLI context.
|
|
329
|
+
*
|
|
330
|
+
* - Joins positional args into a single command string.
|
|
331
|
+
* - Resolves scripts and shell settings using shared helpers.
|
|
332
|
+
* - Forwards merged CLI options to subprocesses via
|
|
333
|
+
* process.env.getDotenvCliOptions for nested CLI behavior. */
|
|
334
|
+
declare const cmdPlugin: (options?: CmdPluginOptions) => GetDotenvCliPlugin;
|
|
335
|
+
|
|
336
|
+
declare const demoPlugin: () => GetDotenvCliPlugin;
|
|
337
|
+
|
|
338
|
+
type InitPluginOptions = {
|
|
339
|
+
logger?: Logger;
|
|
340
|
+
};
|
|
341
|
+
declare const initPlugin: (opts?: InitPluginOptions) => GetDotenvCliPlugin;
|
|
342
|
+
|
|
343
|
+
export { awsPlugin, batchPlugin, cmdPlugin, demoPlugin, initPlugin };
|