@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/plugins-demo.cjs
DELETED
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var execa = require('execa');
|
|
4
|
-
|
|
5
|
-
// Minimal tokenizer for shell-off execution:
|
|
6
|
-
// Splits by whitespace while preserving quoted segments (single or double quotes).
|
|
7
|
-
const tokenize = (command) => {
|
|
8
|
-
const out = [];
|
|
9
|
-
let cur = '';
|
|
10
|
-
let quote = null;
|
|
11
|
-
for (let i = 0; i < command.length; i++) {
|
|
12
|
-
const c = command.charAt(i);
|
|
13
|
-
if (quote) {
|
|
14
|
-
if (c === quote) {
|
|
15
|
-
// Support doubled quotes inside a quoted segment (Windows/PowerShell style):
|
|
16
|
-
// "" -> " and '' -> '
|
|
17
|
-
const next = command.charAt(i + 1);
|
|
18
|
-
if (next === quote) {
|
|
19
|
-
cur += quote;
|
|
20
|
-
i += 1; // skip the second quote
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
// end of quoted segment
|
|
24
|
-
quote = null;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
cur += c;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
if (c === '"' || c === "'") {
|
|
33
|
-
quote = c;
|
|
34
|
-
}
|
|
35
|
-
else if (/\s/.test(c)) {
|
|
36
|
-
if (cur) {
|
|
37
|
-
out.push(cur);
|
|
38
|
-
cur = '';
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
cur += c;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (cur)
|
|
47
|
-
out.push(cur);
|
|
48
|
-
return out;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const dbg = (...args) => {
|
|
52
|
-
if (process.env.GETDOTENV_DEBUG) {
|
|
53
|
-
// Use stderr to avoid interfering with stdout assertions
|
|
54
|
-
console.error('[getdotenv:run]', ...args);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
// Strip repeated symmetric outer quotes (single or double) until stable.
|
|
58
|
-
// This is safe for argv arrays passed to execa (no quoting needed) and avoids
|
|
59
|
-
// passing quote characters through to Node (e.g., for `node -e "<code>"`).
|
|
60
|
-
// Handles stacked quotes from shells like PowerShell: """code""" -> code.
|
|
61
|
-
const stripOuterQuotes = (s) => {
|
|
62
|
-
let out = s;
|
|
63
|
-
// Repeatedly trim only when the entire string is wrapped in matching quotes.
|
|
64
|
-
// Stop as soon as the ends are asymmetric or no quotes remain.
|
|
65
|
-
while (out.length >= 2) {
|
|
66
|
-
const a = out.charAt(0);
|
|
67
|
-
const b = out.charAt(out.length - 1);
|
|
68
|
-
const symmetric = (a === '"' && b === '"') || (a === "'" && b === "'");
|
|
69
|
-
if (!symmetric)
|
|
70
|
-
break;
|
|
71
|
-
out = out.slice(1, -1);
|
|
72
|
-
}
|
|
73
|
-
return out;
|
|
74
|
-
};
|
|
75
|
-
// Convert NodeJS.ProcessEnv (string | undefined values) to the shape execa
|
|
76
|
-
// expects (Readonly<Partial<Record<string, string>>>), dropping undefineds.
|
|
77
|
-
const sanitizeEnv = (env) => {
|
|
78
|
-
if (!env)
|
|
79
|
-
return undefined;
|
|
80
|
-
const entries = Object.entries(env).filter((e) => typeof e[1] === 'string');
|
|
81
|
-
return entries.length > 0 ? Object.fromEntries(entries) : undefined;
|
|
82
|
-
};
|
|
83
|
-
const runCommand = async (command, shell, opts) => {
|
|
84
|
-
if (shell === false) {
|
|
85
|
-
let file;
|
|
86
|
-
let args = [];
|
|
87
|
-
if (Array.isArray(command)) {
|
|
88
|
-
file = command[0];
|
|
89
|
-
args = command.slice(1).map(stripOuterQuotes);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
const tokens = tokenize(command);
|
|
93
|
-
file = tokens[0];
|
|
94
|
-
args = tokens.slice(1);
|
|
95
|
-
}
|
|
96
|
-
if (!file)
|
|
97
|
-
return 0;
|
|
98
|
-
dbg('exec (plain)', { file, args, stdio: opts.stdio });
|
|
99
|
-
// Build options without injecting undefined properties (exactOptionalPropertyTypes).
|
|
100
|
-
const envSan = sanitizeEnv(opts.env);
|
|
101
|
-
const plainOpts = {};
|
|
102
|
-
if (opts.cwd !== undefined)
|
|
103
|
-
plainOpts.cwd = opts.cwd;
|
|
104
|
-
if (envSan !== undefined)
|
|
105
|
-
plainOpts.env = envSan;
|
|
106
|
-
if (opts.stdio !== undefined)
|
|
107
|
-
plainOpts.stdio = opts.stdio;
|
|
108
|
-
const result = await execa.execa(file, args, plainOpts);
|
|
109
|
-
if (opts.stdio === 'pipe' && result.stdout) {
|
|
110
|
-
process.stdout.write(result.stdout + (result.stdout.endsWith('\n') ? '' : '\n'));
|
|
111
|
-
}
|
|
112
|
-
const exit = result?.exitCode;
|
|
113
|
-
dbg('exit (plain)', { exitCode: exit });
|
|
114
|
-
return typeof exit === 'number' ? exit : Number.NaN;
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
const commandStr = Array.isArray(command) ? command.join(' ') : command;
|
|
118
|
-
dbg('exec (shell)', {
|
|
119
|
-
shell: typeof shell === 'string' ? shell : 'custom',
|
|
120
|
-
stdio: opts.stdio,
|
|
121
|
-
command: commandStr,
|
|
122
|
-
});
|
|
123
|
-
const envSan = sanitizeEnv(opts.env);
|
|
124
|
-
const shellOpts = { shell };
|
|
125
|
-
if (opts.cwd !== undefined)
|
|
126
|
-
shellOpts.cwd = opts.cwd;
|
|
127
|
-
if (envSan !== undefined)
|
|
128
|
-
shellOpts.env = envSan;
|
|
129
|
-
if (opts.stdio !== undefined)
|
|
130
|
-
shellOpts.stdio = opts.stdio;
|
|
131
|
-
const result = await execa.execaCommand(commandStr, shellOpts);
|
|
132
|
-
const out = result?.stdout;
|
|
133
|
-
if (opts.stdio === 'pipe' && out) {
|
|
134
|
-
process.stdout.write(out + (out.endsWith('\n') ? '' : '\n'));
|
|
135
|
-
}
|
|
136
|
-
const exit = result?.exitCode;
|
|
137
|
-
dbg('exit (shell)', { exitCode: exit });
|
|
138
|
-
return typeof exit === 'number' ? exit : Number.NaN;
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const dropUndefined = (bag) => Object.fromEntries(Object.entries(bag).filter((e) => typeof e[1] === 'string'));
|
|
143
|
-
/** Build a sanitized env for child processes from base + overlay. */
|
|
144
|
-
const buildSpawnEnv = (base, overlay) => {
|
|
145
|
-
const raw = {
|
|
146
|
-
...(base ?? {}),
|
|
147
|
-
...(overlay ?? {}),
|
|
148
|
-
};
|
|
149
|
-
// Drop undefined first
|
|
150
|
-
const entries = Object.entries(dropUndefined(raw));
|
|
151
|
-
if (process.platform === 'win32') {
|
|
152
|
-
// Windows: keys are case-insensitive; collapse duplicates
|
|
153
|
-
const byLower = new Map();
|
|
154
|
-
for (const [k, v] of entries) {
|
|
155
|
-
byLower.set(k.toLowerCase(), [k, v]); // last wins; preserve latest casing
|
|
156
|
-
}
|
|
157
|
-
const out = {};
|
|
158
|
-
for (const [, [k, v]] of byLower)
|
|
159
|
-
out[k] = v;
|
|
160
|
-
// HOME fallback from USERPROFILE (common expectation)
|
|
161
|
-
if (!Object.prototype.hasOwnProperty.call(out, 'HOME')) {
|
|
162
|
-
const up = out['USERPROFILE'];
|
|
163
|
-
if (typeof up === 'string' && up.length > 0)
|
|
164
|
-
out['HOME'] = up;
|
|
165
|
-
}
|
|
166
|
-
// Normalize TMP/TEMP coherence (pick any present; reflect to both)
|
|
167
|
-
const tmp = out['TMP'] ?? out['TEMP'];
|
|
168
|
-
if (typeof tmp === 'string' && tmp.length > 0) {
|
|
169
|
-
out['TMP'] = tmp;
|
|
170
|
-
out['TEMP'] = tmp;
|
|
171
|
-
}
|
|
172
|
-
return out;
|
|
173
|
-
}
|
|
174
|
-
// POSIX: keep keys as-is
|
|
175
|
-
const out = Object.fromEntries(entries);
|
|
176
|
-
// Ensure TMPDIR exists when any temp key is present (best-effort)
|
|
177
|
-
const tmpdir = out['TMPDIR'] ?? out['TMP'] ?? out['TEMP'];
|
|
178
|
-
if (typeof tmpdir === 'string' && tmpdir.length > 0) {
|
|
179
|
-
out['TMPDIR'] = tmpdir;
|
|
180
|
-
}
|
|
181
|
-
return out;
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
/** src/cliHost/definePlugin.ts
|
|
185
|
-
* Plugin contracts for the GetDotenv CLI host.
|
|
186
|
-
*
|
|
187
|
-
* This module exposes a structural public interface for the host that plugins
|
|
188
|
-
* should use (GetDotenvCliPublic). Using a structural type at the seam avoids
|
|
189
|
-
* nominal class identity issues (private fields) in downstream consumers.
|
|
190
|
-
*/
|
|
191
|
-
/**
|
|
192
|
-
* Define a GetDotenv CLI plugin with compositional helpers.
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
* const parent = definePlugin(\{ id: 'p', setup(cli) \{ /* ... *\/ \} \})
|
|
196
|
-
* .use(childA)
|
|
197
|
-
* .use(childB);
|
|
198
|
-
*/
|
|
199
|
-
const definePlugin = (spec) => {
|
|
200
|
-
const { children = [], ...rest } = spec;
|
|
201
|
-
const plugin = {
|
|
202
|
-
...rest,
|
|
203
|
-
children: [...children],
|
|
204
|
-
use(child) {
|
|
205
|
-
this.children.push(child);
|
|
206
|
-
return this;
|
|
207
|
-
},
|
|
208
|
-
};
|
|
209
|
-
return plugin;
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Batch services (neutral): resolve command and shell settings.
|
|
214
|
-
* Shared by the generator path and the batch plugin to avoid circular deps.
|
|
215
|
-
*/
|
|
216
|
-
/**
|
|
217
|
-
* Resolve a command string from the {@link Scripts} table.
|
|
218
|
-
* A script may be expressed as a string or an object with a `cmd` property.
|
|
219
|
-
*
|
|
220
|
-
* @param scripts - Optional scripts table.
|
|
221
|
-
* @param command - User-provided command name or string.
|
|
222
|
-
* @returns Resolved command string (falls back to the provided command).
|
|
223
|
-
*/
|
|
224
|
-
const resolveCommand = (scripts, command) => scripts && typeof scripts[command] === 'object'
|
|
225
|
-
? scripts[command].cmd
|
|
226
|
-
: (scripts?.[command] ?? command);
|
|
227
|
-
/**
|
|
228
|
-
* Resolve the shell setting for a given command:
|
|
229
|
-
* - If the script entry is an object, prefer its `shell` override.
|
|
230
|
-
* - Otherwise use the provided `shell` (string | boolean).
|
|
231
|
-
*
|
|
232
|
-
* @param scripts - Optional scripts table.
|
|
233
|
-
* @param command - User-provided command name or string.
|
|
234
|
-
* @param shell - Global shell preference (string | boolean).
|
|
235
|
-
*/
|
|
236
|
-
const resolveShell = (scripts, command, shell) => scripts && typeof scripts[command] === 'object'
|
|
237
|
-
? (scripts[command].shell ?? false)
|
|
238
|
-
: (shell ?? false);
|
|
239
|
-
|
|
240
|
-
const demoPlugin = () => definePlugin({
|
|
241
|
-
id: 'demo',
|
|
242
|
-
setup(cli) {
|
|
243
|
-
const logger = console;
|
|
244
|
-
const ns = cli
|
|
245
|
-
.ns('demo')
|
|
246
|
-
.description('Educational demo of host/plugin features (context, child exec, scripts/shell)');
|
|
247
|
-
/**
|
|
248
|
-
* demo ctx
|
|
249
|
-
* Print a summary of the current dotenv context.
|
|
250
|
-
*
|
|
251
|
-
* Notes:
|
|
252
|
-
* - The host resolves context once per invocation in a preSubcommand hook
|
|
253
|
-
* (added by enhanceGetDotenvCli.passOptions() in the shipped CLI).
|
|
254
|
-
* - ctx.dotenv contains the final merged values after overlays/dynamics.
|
|
255
|
-
*/
|
|
256
|
-
ns.command('ctx')
|
|
257
|
-
.description('Print a summary of the current dotenv context')
|
|
258
|
-
.action(() => {
|
|
259
|
-
const ctx = cli.getCtx();
|
|
260
|
-
const dotenv = ctx?.dotenv ?? {};
|
|
261
|
-
const keys = Object.keys(dotenv).sort();
|
|
262
|
-
const sample = keys.slice(0, 5);
|
|
263
|
-
logger.log('[demo] Context summary:');
|
|
264
|
-
logger.log(`- keys: ${keys.length.toString()}`);
|
|
265
|
-
logger.log(`- sample keys: ${sample.join(', ') || '(none)'}`);
|
|
266
|
-
logger.log('- tip: use "--trace [keys...]" for per-key diagnostics');
|
|
267
|
-
});
|
|
268
|
-
/**
|
|
269
|
-
* demo run [--print KEY]
|
|
270
|
-
* Execute a small child process that prints a dotenv value.
|
|
271
|
-
*
|
|
272
|
-
* Design:
|
|
273
|
-
* - Use shell-off + argv array to avoid cross-platform quoting pitfalls.
|
|
274
|
-
* - Inject ctx.dotenv explicitly into the child env.
|
|
275
|
-
* - Inherit stdio so output streams live (works well outside CI).
|
|
276
|
-
*
|
|
277
|
-
* Tip:
|
|
278
|
-
* - For deterministic capture in CI, run with "--capture" (or set
|
|
279
|
-
* GETDOTENV_STDIO=pipe). The shipped CLI honors both.
|
|
280
|
-
*/
|
|
281
|
-
ns.command('run')
|
|
282
|
-
.description('Run a small child process under the current dotenv (shell-off)')
|
|
283
|
-
.option('--print <key>', 'dotenv key to print', 'APP_SETTING')
|
|
284
|
-
.action(async (opts) => {
|
|
285
|
-
const key = typeof opts.print === 'string' && opts.print.length > 0
|
|
286
|
-
? opts.print
|
|
287
|
-
: 'APP_SETTING';
|
|
288
|
-
// Build a minimal node -e payload via argv array (avoid quoting issues).
|
|
289
|
-
const code = `console.log(process.env.${key} ?? "")`;
|
|
290
|
-
const ctx = cli.getCtx();
|
|
291
|
-
const dotenv = (ctx?.dotenv ?? {});
|
|
292
|
-
// Inherit stdio for an interactive demo. Use --capture for CI.
|
|
293
|
-
await runCommand(['node', '-e', code], false, {
|
|
294
|
-
env: buildSpawnEnv(process.env, dotenv),
|
|
295
|
-
stdio: 'inherit',
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
/**
|
|
299
|
-
* demo script [command...]
|
|
300
|
-
* Resolve and execute a command using the current scripts table and
|
|
301
|
-
* shell preference (with per-script overrides).
|
|
302
|
-
*
|
|
303
|
-
* How it works:
|
|
304
|
-
* - We read the merged CLI options persisted by the shipped CLI’s
|
|
305
|
-
* passOptions() hook on the current command instance’s parent.
|
|
306
|
-
* - resolveCommand resolves a script name → cmd or passes through a raw
|
|
307
|
-
* command string.
|
|
308
|
-
* - resolveShell chooses the appropriate shell:
|
|
309
|
-
* scripts[name].shell ?? global shell (string|boolean).
|
|
310
|
-
*/
|
|
311
|
-
ns.command('script')
|
|
312
|
-
.description('Resolve a command via scripts and execute it with the proper shell')
|
|
313
|
-
.argument('[command...]')
|
|
314
|
-
.action(async (commandParts, _opts, thisCommand) => {
|
|
315
|
-
// Safely access the parent’s merged options (installed by passOptions()).
|
|
316
|
-
const parent = thisCommand.parent;
|
|
317
|
-
const bag = (parent?.getDotenvCliOptions ?? {});
|
|
318
|
-
const input = Array.isArray(commandParts)
|
|
319
|
-
? commandParts.map(String).join(' ')
|
|
320
|
-
: '';
|
|
321
|
-
if (!input) {
|
|
322
|
-
logger.log('[demo] Please provide a command or script name, e.g. "echo OK" or "git-status".');
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
const resolved = resolveCommand(bag?.scripts, input);
|
|
326
|
-
const shell = resolveShell(bag?.scripts, input, bag?.shell);
|
|
327
|
-
// Compose child env (parent + ctx.dotenv). This mirrors cmd/batch behavior.
|
|
328
|
-
const ctx = cli.getCtx();
|
|
329
|
-
const dotenv = (ctx?.dotenv ?? {});
|
|
330
|
-
await runCommand(resolved, shell, {
|
|
331
|
-
env: buildSpawnEnv(process.env, dotenv),
|
|
332
|
-
stdio: 'inherit',
|
|
333
|
-
});
|
|
334
|
-
});
|
|
335
|
-
},
|
|
336
|
-
/**
|
|
337
|
-
* Optional: afterResolve can initialize per-plugin state using ctx.dotenv.
|
|
338
|
-
* For the demo we emit a single breadcrumb only when GETDOTENV_DEBUG is set,
|
|
339
|
-
* keeping default runs (tests/CI/smoke) quiet.
|
|
340
|
-
*/
|
|
341
|
-
afterResolve(_cli, ctx) {
|
|
342
|
-
if (process.env.GETDOTENV_DEBUG) {
|
|
343
|
-
const keys = Object.keys(ctx.dotenv);
|
|
344
|
-
if (keys.length > 0) {
|
|
345
|
-
// Keep noise low; a single-line breadcrumb is sufficient for the demo.
|
|
346
|
-
console.error('[demo] afterResolve: dotenv keys loaded:', keys.length);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
},
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
exports.demoPlugin = demoPlugin;
|
package/dist/plugins-demo.d.cts
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { ZodType } from 'zod';
|
|
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
|
-
/** src/cliHost/definePlugin.ts
|
|
99
|
-
* Plugin contracts for the GetDotenv CLI host.
|
|
100
|
-
*
|
|
101
|
-
* This module exposes a structural public interface for the host that plugins
|
|
102
|
-
* should use (GetDotenvCliPublic). Using a structural type at the seam avoids
|
|
103
|
-
* nominal class identity issues (private fields) in downstream consumers.
|
|
104
|
-
*/
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Structural public interface for the host exposed to plugins.
|
|
108
|
-
* - Extends Commander.Command so plugins can attach options/commands/hooks.
|
|
109
|
-
* - Adds host-specific helpers used by built-in plugins.
|
|
110
|
-
*
|
|
111
|
-
* Purpose: remove nominal class identity (private fields) from the plugin seam
|
|
112
|
-
* to avoid TS2379 under exactOptionalPropertyTypes in downstream consumers.
|
|
113
|
-
*/
|
|
114
|
-
type GetDotenvCliPublic<TOptions extends GetDotenvOptions = GetDotenvOptions> = Command & {
|
|
115
|
-
ns: (name: string) => Command;
|
|
116
|
-
getCtx: () => GetDotenvCliCtx<TOptions> | undefined;
|
|
117
|
-
resolveAndLoad: (customOptions?: Partial<TOptions>) => Promise<GetDotenvCliCtx<TOptions>>;
|
|
118
|
-
};
|
|
119
|
-
/** Public plugin contract used by the GetDotenv CLI host. */
|
|
120
|
-
interface GetDotenvCliPlugin {
|
|
121
|
-
id?: string;
|
|
122
|
-
/**
|
|
123
|
-
* Setup phase: register commands and wiring on the provided CLI instance.
|
|
124
|
-
* Runs parent → children (pre-order).
|
|
125
|
-
*/
|
|
126
|
-
setup: (cli: GetDotenvCliPublic) => void | Promise<void>;
|
|
127
|
-
/**
|
|
128
|
-
* After the dotenv context is resolved, initialize any clients/secrets
|
|
129
|
-
* or attach per-plugin state under ctx.plugins (by convention).
|
|
130
|
-
* Runs parent → children (pre-order).
|
|
131
|
-
*/
|
|
132
|
-
afterResolve?: (cli: GetDotenvCliPublic, ctx: GetDotenvCliCtx) => void | Promise<void>;
|
|
133
|
-
/**
|
|
134
|
-
* Optional Zod schema for this plugin's config slice (from config.plugins[id]).
|
|
135
|
-
* When provided, the host validates the merged config under the guarded loader path.
|
|
136
|
-
*/
|
|
137
|
-
configSchema?: ZodType;
|
|
138
|
-
/**
|
|
139
|
-
* Compositional children. Installed after the parent per pre-order.
|
|
140
|
-
*/
|
|
141
|
-
children: GetDotenvCliPlugin[];
|
|
142
|
-
/**
|
|
143
|
-
* Compose a child plugin. Returns the parent to enable chaining.
|
|
144
|
-
*/
|
|
145
|
-
use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/** * Per-invocation context shared with plugins and actions. */
|
|
149
|
-
type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
|
|
150
|
-
optionsResolved: TOptions;
|
|
151
|
-
dotenv: ProcessEnv;
|
|
152
|
-
plugins?: Record<string, unknown>;
|
|
153
|
-
pluginConfigs?: Record<string, unknown>;
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
declare const demoPlugin: () => GetDotenvCliPlugin;
|
|
157
|
-
|
|
158
|
-
export { demoPlugin };
|
package/dist/plugins-demo.d.mts
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
2
|
-
import { ZodType } from 'zod';
|
|
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
|
-
/** src/cliHost/definePlugin.ts
|
|
99
|
-
* Plugin contracts for the GetDotenv CLI host.
|
|
100
|
-
*
|
|
101
|
-
* This module exposes a structural public interface for the host that plugins
|
|
102
|
-
* should use (GetDotenvCliPublic). Using a structural type at the seam avoids
|
|
103
|
-
* nominal class identity issues (private fields) in downstream consumers.
|
|
104
|
-
*/
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Structural public interface for the host exposed to plugins.
|
|
108
|
-
* - Extends Commander.Command so plugins can attach options/commands/hooks.
|
|
109
|
-
* - Adds host-specific helpers used by built-in plugins.
|
|
110
|
-
*
|
|
111
|
-
* Purpose: remove nominal class identity (private fields) from the plugin seam
|
|
112
|
-
* to avoid TS2379 under exactOptionalPropertyTypes in downstream consumers.
|
|
113
|
-
*/
|
|
114
|
-
type GetDotenvCliPublic<TOptions extends GetDotenvOptions = GetDotenvOptions> = Command & {
|
|
115
|
-
ns: (name: string) => Command;
|
|
116
|
-
getCtx: () => GetDotenvCliCtx<TOptions> | undefined;
|
|
117
|
-
resolveAndLoad: (customOptions?: Partial<TOptions>) => Promise<GetDotenvCliCtx<TOptions>>;
|
|
118
|
-
};
|
|
119
|
-
/** Public plugin contract used by the GetDotenv CLI host. */
|
|
120
|
-
interface GetDotenvCliPlugin {
|
|
121
|
-
id?: string;
|
|
122
|
-
/**
|
|
123
|
-
* Setup phase: register commands and wiring on the provided CLI instance.
|
|
124
|
-
* Runs parent → children (pre-order).
|
|
125
|
-
*/
|
|
126
|
-
setup: (cli: GetDotenvCliPublic) => void | Promise<void>;
|
|
127
|
-
/**
|
|
128
|
-
* After the dotenv context is resolved, initialize any clients/secrets
|
|
129
|
-
* or attach per-plugin state under ctx.plugins (by convention).
|
|
130
|
-
* Runs parent → children (pre-order).
|
|
131
|
-
*/
|
|
132
|
-
afterResolve?: (cli: GetDotenvCliPublic, ctx: GetDotenvCliCtx) => void | Promise<void>;
|
|
133
|
-
/**
|
|
134
|
-
* Optional Zod schema for this plugin's config slice (from config.plugins[id]).
|
|
135
|
-
* When provided, the host validates the merged config under the guarded loader path.
|
|
136
|
-
*/
|
|
137
|
-
configSchema?: ZodType;
|
|
138
|
-
/**
|
|
139
|
-
* Compositional children. Installed after the parent per pre-order.
|
|
140
|
-
*/
|
|
141
|
-
children: GetDotenvCliPlugin[];
|
|
142
|
-
/**
|
|
143
|
-
* Compose a child plugin. Returns the parent to enable chaining.
|
|
144
|
-
*/
|
|
145
|
-
use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/** * Per-invocation context shared with plugins and actions. */
|
|
149
|
-
type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
|
|
150
|
-
optionsResolved: TOptions;
|
|
151
|
-
dotenv: ProcessEnv;
|
|
152
|
-
plugins?: Record<string, unknown>;
|
|
153
|
-
pluginConfigs?: Record<string, unknown>;
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
declare const demoPlugin: () => GetDotenvCliPlugin;
|
|
157
|
-
|
|
158
|
-
export { demoPlugin };
|