@karmaniverous/get-dotenv 6.3.0 → 6.4.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 (45) hide show
  1. package/dist/chunks/{AwsRestJsonProtocol-Dv5q8CFK.mjs → AwsRestJsonProtocol-fYZqn-kW.mjs} +2 -2
  2. package/dist/chunks/{createCli-BSn6Be40.mjs → createCli-BnRdfRRL.mjs} +5 -5
  3. package/dist/chunks/{externalDataInterceptor-pqHO-Qmn.mjs → externalDataInterceptor-CILOLqbB.mjs} +2 -2
  4. package/dist/chunks/{getSSOTokenFromFile-otmZHSRV.mjs → getSSOTokenFromFile-BwMkZ_yT.mjs} +1 -1
  5. package/dist/chunks/{index-CGg5wWCm.mjs → index-0-nP97ri.mjs} +5 -5
  6. package/dist/chunks/{index-BNcKuiBy.mjs → index-70Dm0f1N.mjs} +9 -9
  7. package/dist/chunks/{index-DLQEHTw4.mjs → index-BhVOypA1.mjs} +7 -7
  8. package/dist/chunks/{index-C6uLiKpC.mjs → index-CcwT4HJK.mjs} +4 -4
  9. package/dist/chunks/{index-B18W-ELX.mjs → index-D8UL3w94.mjs} +4 -4
  10. package/dist/chunks/{index-CYoFYXZv.mjs → index-DLNhHC15.mjs} +7 -7
  11. package/dist/chunks/{index-C4Ac6feq.mjs → index-DWqbxY8Y.mjs} +9 -9
  12. package/dist/chunks/{index-CXpZ0pei.mjs → index-Du51s-Z0.mjs} +6 -6
  13. package/dist/chunks/{index-DFNcs3pR.mjs → index-DuSz0ul6.mjs} +6 -6
  14. package/dist/chunks/{index-DtRaL61T.mjs → index-OeNCYa8T.mjs} +4 -4
  15. package/dist/chunks/{index-Bi0RIILn.mjs → index-_FP0whjC.mjs} +4 -4
  16. package/dist/chunks/{index-eZMlmESW.mjs → index-o5zJ9PWL.mjs} +14 -14
  17. package/dist/chunks/{index-BqZ3PB6c.mjs → index-r0Me7-sT.mjs} +109 -4
  18. package/dist/chunks/{loadSso-CJ_XUhEj.mjs → loadSso-CLR1fKci.mjs} +6 -6
  19. package/dist/chunks/{parseKnownFiles-B6x1cUmR.mjs → parseKnownFiles-BQvmJ0HK.mjs} +1 -1
  20. package/dist/chunks/readDotenvCascade-DfFkWMjs.mjs +546 -0
  21. package/dist/chunks/{readMergedOptions-DLBDzpXX.mjs → readMergedOptions-B7VdLROn.mjs} +60 -271
  22. package/dist/chunks/{resolveCliOptions-_qtsVxda.mjs → resolveCliOptions-pgUXHJtj.mjs} +1 -1
  23. package/dist/chunks/{sdk-stream-mixin-DCdC70Up.mjs → sdk-stream-mixin-ecbbBR0l.mjs} +1 -1
  24. package/dist/chunks/{types-DdqcXCV1.mjs → types-CVDR-Sjk.mjs} +1 -1
  25. package/dist/cli.d.ts +218 -84
  26. package/dist/cli.mjs +7 -7
  27. package/dist/cliHost.d.ts +218 -84
  28. package/dist/cliHost.mjs +5 -5
  29. package/dist/env-overlay.d.ts +304 -2
  30. package/dist/env-overlay.mjs +37 -1
  31. package/dist/getdotenv.cli.mjs +7 -7
  32. package/dist/index.d.ts +218 -84
  33. package/dist/index.mjs +199 -42
  34. package/dist/plugins-aws.d.ts +153 -19
  35. package/dist/plugins-aws.mjs +2 -2
  36. package/dist/plugins-batch.d.ts +153 -19
  37. package/dist/plugins-batch.mjs +2 -2
  38. package/dist/plugins-cmd.d.ts +153 -19
  39. package/dist/plugins-cmd.mjs +4 -4
  40. package/dist/plugins-init.d.ts +153 -19
  41. package/dist/plugins-init.mjs +2 -2
  42. package/dist/plugins.d.ts +153 -19
  43. package/dist/plugins.mjs +6 -6
  44. package/package.json +1 -1
  45. package/dist/chunks/overlayEnv-Bqh_kPGA.mjs +0 -235
@@ -1,235 +0,0 @@
1
- import fs from 'fs-extra';
2
- import 'node:path';
3
- import { l as loadModuleDefault } from './loadModuleDefault-Dj8B3Stt.mjs';
4
-
5
- /**
6
- * Dotenv expansion utilities.
7
- *
8
- * This module implements recursive expansion of environment-variable
9
- * references in strings and records. It supports both whitespace and
10
- * bracket syntaxes with optional defaults:
11
- *
12
- * - Whitespace: `$VAR[:default]`
13
- * - Bracketed: `${VAR[:default]}`
14
- *
15
- * Escaped dollar signs (`\$`) are preserved.
16
- * Unknown variables resolve to empty string unless a default is provided.
17
- */
18
- /**
19
- * Like String.prototype.search but returns the last index.
20
- * @internal
21
- */
22
- const searchLast = (str, rgx) => {
23
- const matches = Array.from(str.matchAll(rgx));
24
- return matches.length > 0 ? (matches.slice(-1)[0]?.index ?? -1) : -1;
25
- };
26
- const replaceMatch = (value, match, ref) => {
27
- /**
28
- * @internal
29
- */
30
- const group = match[0];
31
- const key = match[1];
32
- const defaultValue = match[2];
33
- if (!key)
34
- return value;
35
- const replacement = value.replace(group, ref[key] ?? defaultValue ?? '');
36
- return interpolate(replacement, ref);
37
- };
38
- const interpolate = (value = '', ref = {}) => {
39
- /**
40
- * @internal
41
- */
42
- // if value is falsy, return it as is
43
- if (!value)
44
- return value;
45
- // get position of last unescaped dollar sign
46
- const lastUnescapedDollarSignIndex = searchLast(value, /(?!(?<=\\))\$/g);
47
- // return value if none found
48
- if (lastUnescapedDollarSignIndex === -1)
49
- return value;
50
- // evaluate the value tail
51
- const tail = value.slice(lastUnescapedDollarSignIndex);
52
- // find whitespace pattern: $KEY:DEFAULT
53
- const whitespacePattern = /^\$([\w]+)(?::([^\s]*))?/;
54
- const whitespaceMatch = whitespacePattern.exec(tail);
55
- if (whitespaceMatch != null)
56
- return replaceMatch(value, whitespaceMatch, ref);
57
- else {
58
- // find bracket pattern: ${KEY:DEFAULT}
59
- const bracketPattern = /^\${([\w]+)(?::([^}]*))?}/;
60
- const bracketMatch = bracketPattern.exec(tail);
61
- if (bracketMatch != null)
62
- return replaceMatch(value, bracketMatch, ref);
63
- }
64
- return value;
65
- };
66
- /**
67
- * Recursively expands environment variables in a string. Variables may be
68
- * presented with optional default as `$VAR[:default]` or `${VAR[:default]}`.
69
- * Unknown variables will expand to an empty string.
70
- *
71
- * @param value - The string to expand.
72
- * @param ref - The reference object to use for variable expansion.
73
- * @returns The expanded string.
74
- *
75
- * @example
76
- * ```ts
77
- * process.env.FOO = 'bar';
78
- * dotenvExpand('Hello $FOO'); // "Hello bar"
79
- * dotenvExpand('Hello $BAZ:world'); // "Hello world"
80
- * ```
81
- *
82
- * @remarks
83
- * The expansion is recursive. If a referenced variable itself contains
84
- * references, those will also be expanded until a stable value is reached.
85
- * Escaped references (e.g. `\$FOO`) are preserved as literals.
86
- */
87
- const dotenvExpand = (value, ref = process.env) => {
88
- const result = interpolate(value, ref);
89
- return result ? result.replace(/\\\$/g, '$') : undefined;
90
- };
91
- /**
92
- * Recursively expands environment variables in the values of a JSON object.
93
- * Variables may be presented with optional default as `$VAR[:default]` or
94
- * `${VAR[:default]}`. Unknown variables will expand to an empty string.
95
- *
96
- * @param values - The values object to expand.
97
- * @param options - Expansion options.
98
- * @returns The value object with expanded string values.
99
- *
100
- * @example
101
- * ```ts
102
- * process.env.FOO = 'bar';
103
- * dotenvExpandAll({ A: '$FOO', B: 'x${FOO}y' });
104
- * // => { A: "bar", B: "xbary" }
105
- * ```
106
- *
107
- * @remarks
108
- * Options:
109
- * - ref: The reference object to use for expansion (defaults to process.env).
110
- * - progressive: Whether to progressively add expanded values to the set of
111
- * reference keys.
112
- *
113
- * When `progressive` is true, each expanded key becomes available for
114
- * subsequent expansions in the same object (left-to-right by object key order).
115
- */
116
- function dotenvExpandAll(values, options = {}) {
117
- const { ref = process.env, progressive = false, } = options;
118
- const out = Object.keys(values).reduce((acc, key) => {
119
- acc[key] = dotenvExpand(values[key], {
120
- ...ref,
121
- ...(progressive ? acc : {}),
122
- });
123
- return acc;
124
- }, {});
125
- // Key-preserving return with a permissive index signature to allow later additions.
126
- return out;
127
- }
128
- /**
129
- * Recursively expands environment variables in a string using `process.env` as
130
- * the expansion reference. Variables may be presented with optional default as
131
- * `$VAR[:default]` or `${VAR[:default]}`. Unknown variables will expand to an
132
- * empty string.
133
- *
134
- * @param value - The string to expand.
135
- * @returns The expanded string.
136
- *
137
- * @example
138
- * ```ts
139
- * process.env.FOO = 'bar';
140
- * dotenvExpandFromProcessEnv('Hello $FOO'); // "Hello bar"
141
- * ```
142
- */
143
- const dotenvExpandFromProcessEnv = (value) => dotenvExpand(value, process.env);
144
-
145
- /** src/env/dynamic.ts
146
- * Helpers for applying and loading dynamic variables (JS/TS).
147
- *
148
- * Requirements addressed:
149
- * - Single service to apply a dynamic map progressively.
150
- * - Single service to load a JS/TS dynamic module with robust fallbacks (util/loadModuleDefault).
151
- * - Unify error messaging so callers show consistent guidance.
152
- */
153
- /**
154
- * Apply a dynamic map to the target progressively.
155
- * - Functions receive (target, env) and may return string | undefined.
156
- * - Literals are assigned directly (including undefined).
157
- *
158
- * @param target - Mutable target environment to assign into.
159
- * @param map - Dynamic map to apply (functions and/or literal values).
160
- * @param env - Selected environment name (if any) passed through to dynamic functions.
161
- * @returns Nothing.
162
- */
163
- function applyDynamicMap(target, map, env) {
164
- if (!map)
165
- return;
166
- for (const key of Object.keys(map)) {
167
- const val = typeof map[key] === 'function'
168
- ? map[key](target, env)
169
- : map[key];
170
- Object.assign(target, { [key]: val });
171
- }
172
- }
173
- /**
174
- * Load a default-export dynamic map from a JS/TS file and apply it.
175
- * Uses util/loadModuleDefault for robust TS handling (direct import, esbuild,
176
- * typescript.transpile fallback).
177
- *
178
- * Error behavior:
179
- * - On failure to load/compile/evaluate the module, throws a unified message:
180
- * "Unable to load dynamic TypeScript file: <absPath>. Install 'esbuild'..."
181
- *
182
- * @param target - Mutable target environment to assign into.
183
- * @param absPath - Absolute path to the dynamic module file.
184
- * @param env - Selected environment name (if any).
185
- * @param cacheDirName - Cache subdirectory under `.tsbuild/` for compiled artifacts.
186
- * @returns A `Promise\<void\>` which resolves after the module (if present) has been applied.
187
- */
188
- async function loadAndApplyDynamic(target, absPath, env, cacheDirName) {
189
- if (!(await fs.exists(absPath)))
190
- return;
191
- let dyn;
192
- try {
193
- dyn = await loadModuleDefault(absPath, cacheDirName);
194
- }
195
- catch {
196
- // Preserve legacy/clear guidance used by tests and docs.
197
- throw new Error(`Unable to load dynamic TypeScript file: ${absPath}. ` +
198
- `Install 'esbuild' (devDependency) to enable TypeScript dynamic modules.`);
199
- }
200
- applyDynamicMap(target, dyn, env);
201
- }
202
-
203
- const applyKv = (current, kv) => {
204
- if (!kv || Object.keys(kv).length === 0)
205
- return current;
206
- const expanded = dotenvExpandAll(kv, { ref: current, progressive: true });
207
- return { ...current, ...expanded };
208
- };
209
- const applyConfigSlice = (current, cfg, env) => {
210
- if (!cfg)
211
- return current;
212
- // kind axis: global then env (env overrides global)
213
- const afterGlobal = applyKv(current, cfg.vars);
214
- const envKv = env && cfg.envVars ? cfg.envVars[env] : undefined;
215
- return applyKv(afterGlobal, envKv);
216
- };
217
- function overlayEnv(args) {
218
- const { base, env, configs } = args;
219
- let current = { ...base };
220
- // Source: packaged (public -> local)
221
- current = applyConfigSlice(current, configs.packaged, env);
222
- // Packaged "local" is not expected by policy; if present, honor it.
223
- // We do not have a separate object for packaged.local in sources, keep as-is.
224
- // Source: project (public -> local)
225
- current = applyConfigSlice(current, configs.project?.public, env);
226
- current = applyConfigSlice(current, configs.project?.local, env);
227
- // Programmatic explicit vars (top of static tier)
228
- if ('programmaticVars' in args) {
229
- const toApply = Object.fromEntries(Object.entries(args.programmaticVars).filter(([_k, v]) => typeof v === 'string'));
230
- current = applyKv(current, toApply);
231
- }
232
- return current;
233
- }
234
-
235
- export { applyDynamicMap as a, dotenvExpandAll as b, dotenvExpandFromProcessEnv as c, dotenvExpand as d, loadAndApplyDynamic as l, overlayEnv as o };