@karmaniverous/get-dotenv 5.2.5 → 6.0.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -67
- package/dist/cliHost.cjs +765 -549
- package/dist/cliHost.d.cts +128 -84
- package/dist/cliHost.d.mts +128 -84
- package/dist/cliHost.d.ts +128 -84
- package/dist/cliHost.mjs +765 -549
- package/dist/getdotenv.cli.mjs +915 -685
- package/dist/index.cjs +959 -1006
- package/dist/index.d.cts +18 -178
- package/dist/index.d.mts +18 -178
- package/dist/index.d.ts +18 -178
- package/dist/index.mjs +960 -1006
- package/dist/plugins-aws.cjs +0 -1
- package/dist/plugins-aws.d.cts +8 -78
- package/dist/plugins-aws.d.mts +8 -78
- package/dist/plugins-aws.d.ts +8 -78
- package/dist/plugins-aws.mjs +0 -1
- package/dist/plugins-batch.cjs +53 -11
- package/dist/plugins-batch.d.cts +10 -79
- package/dist/plugins-batch.d.mts +10 -79
- package/dist/plugins-batch.d.ts +10 -79
- package/dist/plugins-batch.mjs +53 -11
- package/dist/plugins-cmd.cjs +162 -1555
- package/dist/plugins-cmd.d.cts +8 -78
- package/dist/plugins-cmd.d.mts +8 -78
- package/dist/plugins-cmd.d.ts +8 -78
- package/dist/plugins-cmd.mjs +162 -1554
- package/dist/plugins-demo.cjs +52 -7
- package/dist/plugins-demo.d.cts +8 -78
- package/dist/plugins-demo.d.mts +8 -78
- package/dist/plugins-demo.d.ts +8 -78
- package/dist/plugins-demo.mjs +52 -7
- package/dist/plugins-init.d.cts +8 -78
- package/dist/plugins-init.d.mts +8 -78
- package/dist/plugins-init.d.ts +8 -78
- package/dist/plugins.cjs +283 -1630
- package/dist/plugins.d.cts +10 -79
- package/dist/plugins.d.mts +10 -79
- package/dist/plugins.d.ts +10 -79
- package/dist/plugins.mjs +285 -1631
- package/package.json +4 -2
package/dist/plugins-demo.cjs
CHANGED
|
@@ -139,6 +139,48 @@ const runCommand = async (command, shell, opts) => {
|
|
|
139
139
|
}
|
|
140
140
|
};
|
|
141
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
|
+
|
|
142
184
|
/** src/cliHost/definePlugin.ts
|
|
143
185
|
* Plugin contracts for the GetDotenv CLI host.
|
|
144
186
|
*
|
|
@@ -249,7 +291,7 @@ const demoPlugin = () => definePlugin({
|
|
|
249
291
|
const dotenv = (ctx?.dotenv ?? {});
|
|
250
292
|
// Inherit stdio for an interactive demo. Use --capture for CI.
|
|
251
293
|
await runCommand(['node', '-e', code], false, {
|
|
252
|
-
env:
|
|
294
|
+
env: buildSpawnEnv(process.env, dotenv),
|
|
253
295
|
stdio: 'inherit',
|
|
254
296
|
});
|
|
255
297
|
});
|
|
@@ -286,20 +328,23 @@ const demoPlugin = () => definePlugin({
|
|
|
286
328
|
const ctx = cli.getCtx();
|
|
287
329
|
const dotenv = (ctx?.dotenv ?? {});
|
|
288
330
|
await runCommand(resolved, shell, {
|
|
289
|
-
env:
|
|
331
|
+
env: buildSpawnEnv(process.env, dotenv),
|
|
290
332
|
stdio: 'inherit',
|
|
291
333
|
});
|
|
292
334
|
});
|
|
293
335
|
},
|
|
294
336
|
/**
|
|
295
337
|
* Optional: afterResolve can initialize per-plugin state using ctx.dotenv.
|
|
296
|
-
* For the demo we
|
|
338
|
+
* For the demo we emit a single breadcrumb only when GETDOTENV_DEBUG is set,
|
|
339
|
+
* keeping default runs (tests/CI/smoke) quiet.
|
|
297
340
|
*/
|
|
298
341
|
afterResolve(_cli, ctx) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
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
|
+
}
|
|
303
348
|
}
|
|
304
349
|
},
|
|
305
350
|
});
|
package/dist/plugins-demo.d.cts
CHANGED
|
@@ -1,76 +1,6 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { ZodType } from 'zod';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Minimal root options shape shared by CLI and generator layers.
|
|
6
|
-
* Keep keys optional to respect exactOptionalPropertyTypes semantics.
|
|
7
|
-
*/
|
|
8
|
-
type RootOptionsShape = {
|
|
9
|
-
env?: string;
|
|
10
|
-
vars?: string;
|
|
11
|
-
command?: string;
|
|
12
|
-
outputPath?: string;
|
|
13
|
-
shell?: string | boolean;
|
|
14
|
-
loadProcess?: boolean;
|
|
15
|
-
excludeAll?: boolean;
|
|
16
|
-
excludeDynamic?: boolean;
|
|
17
|
-
excludeEnv?: boolean;
|
|
18
|
-
excludeGlobal?: boolean;
|
|
19
|
-
excludePrivate?: boolean;
|
|
20
|
-
excludePublic?: boolean;
|
|
21
|
-
log?: boolean;
|
|
22
|
-
debug?: boolean;
|
|
23
|
-
capture?: boolean;
|
|
24
|
-
strict?: boolean;
|
|
25
|
-
redact?: boolean;
|
|
26
|
-
warnEntropy?: boolean;
|
|
27
|
-
entropyThreshold?: number;
|
|
28
|
-
entropyMinLength?: number;
|
|
29
|
-
entropyWhitelist?: string[];
|
|
30
|
-
redactPatterns?: string[];
|
|
31
|
-
defaultEnv?: string;
|
|
32
|
-
dotenvToken?: string;
|
|
33
|
-
dynamicPath?: string;
|
|
34
|
-
trace?: boolean | string[];
|
|
35
|
-
paths?: string;
|
|
36
|
-
pathsDelimiter?: string;
|
|
37
|
-
pathsDelimiterPattern?: string;
|
|
38
|
-
privateToken?: string;
|
|
39
|
-
varsDelimiter?: string;
|
|
40
|
-
varsDelimiterPattern?: string;
|
|
41
|
-
varsAssignor?: string;
|
|
42
|
-
varsAssignorPattern?: string;
|
|
43
|
-
scripts?: ScriptsTable;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Scripts table shape (configurable shell type).
|
|
47
|
-
*/
|
|
48
|
-
type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<string, string | {
|
|
49
|
-
cmd: string;
|
|
50
|
-
shell?: TShell;
|
|
51
|
-
}>;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Adapter-layer augmentation: add chainable helpers to GetDotenvCli without
|
|
55
|
-
* coupling the core host to cliCore. Importing this module has side effects:
|
|
56
|
-
* it extends the prototype and merges types for consumers.
|
|
57
|
-
*/
|
|
58
|
-
declare module '../cliHost/GetDotenvCli' {
|
|
59
|
-
interface GetDotenvCli {
|
|
60
|
-
/**
|
|
61
|
-
* Attach legacy root flags to this CLI instance. Defaults come from
|
|
62
|
-
* baseRootOptionDefaults when none are provided. */
|
|
63
|
-
attachRootOptions(defaults?: Partial<RootOptionsShape>, opts?: {
|
|
64
|
-
includeCommandOption?: boolean;
|
|
65
|
-
}): this;
|
|
66
|
-
/**
|
|
67
|
-
* Install a preSubcommand hook that merges CLI flags (including parent
|
|
68
|
-
* round-trip) and resolves the dotenv context before executing actions.
|
|
69
|
-
* Defaults come from baseRootOptionDefaults when none are provided.
|
|
70
|
-
*/ passOptions(defaults?: Partial<RootOptionsShape>): this;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
4
|
/**
|
|
75
5
|
* A minimal representation of an environment key/value mapping.
|
|
76
6
|
* Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
|
|
@@ -165,14 +95,6 @@ interface GetDotenvOptions {
|
|
|
165
95
|
useConfigLoader?: boolean;
|
|
166
96
|
}
|
|
167
97
|
|
|
168
|
-
/** * Per-invocation context shared with plugins and actions. */
|
|
169
|
-
type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
|
|
170
|
-
optionsResolved: TOptions;
|
|
171
|
-
dotenv: ProcessEnv;
|
|
172
|
-
plugins?: Record<string, unknown>;
|
|
173
|
-
pluginConfigs?: Record<string, unknown>;
|
|
174
|
-
};
|
|
175
|
-
|
|
176
98
|
/** src/cliHost/definePlugin.ts
|
|
177
99
|
* Plugin contracts for the GetDotenv CLI host.
|
|
178
100
|
*
|
|
@@ -223,6 +145,14 @@ interface GetDotenvCliPlugin {
|
|
|
223
145
|
use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
|
|
224
146
|
}
|
|
225
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
|
+
|
|
226
156
|
declare const demoPlugin: () => GetDotenvCliPlugin;
|
|
227
157
|
|
|
228
158
|
export { demoPlugin };
|
package/dist/plugins-demo.d.mts
CHANGED
|
@@ -1,76 +1,6 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { ZodType } from 'zod';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Minimal root options shape shared by CLI and generator layers.
|
|
6
|
-
* Keep keys optional to respect exactOptionalPropertyTypes semantics.
|
|
7
|
-
*/
|
|
8
|
-
type RootOptionsShape = {
|
|
9
|
-
env?: string;
|
|
10
|
-
vars?: string;
|
|
11
|
-
command?: string;
|
|
12
|
-
outputPath?: string;
|
|
13
|
-
shell?: string | boolean;
|
|
14
|
-
loadProcess?: boolean;
|
|
15
|
-
excludeAll?: boolean;
|
|
16
|
-
excludeDynamic?: boolean;
|
|
17
|
-
excludeEnv?: boolean;
|
|
18
|
-
excludeGlobal?: boolean;
|
|
19
|
-
excludePrivate?: boolean;
|
|
20
|
-
excludePublic?: boolean;
|
|
21
|
-
log?: boolean;
|
|
22
|
-
debug?: boolean;
|
|
23
|
-
capture?: boolean;
|
|
24
|
-
strict?: boolean;
|
|
25
|
-
redact?: boolean;
|
|
26
|
-
warnEntropy?: boolean;
|
|
27
|
-
entropyThreshold?: number;
|
|
28
|
-
entropyMinLength?: number;
|
|
29
|
-
entropyWhitelist?: string[];
|
|
30
|
-
redactPatterns?: string[];
|
|
31
|
-
defaultEnv?: string;
|
|
32
|
-
dotenvToken?: string;
|
|
33
|
-
dynamicPath?: string;
|
|
34
|
-
trace?: boolean | string[];
|
|
35
|
-
paths?: string;
|
|
36
|
-
pathsDelimiter?: string;
|
|
37
|
-
pathsDelimiterPattern?: string;
|
|
38
|
-
privateToken?: string;
|
|
39
|
-
varsDelimiter?: string;
|
|
40
|
-
varsDelimiterPattern?: string;
|
|
41
|
-
varsAssignor?: string;
|
|
42
|
-
varsAssignorPattern?: string;
|
|
43
|
-
scripts?: ScriptsTable;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Scripts table shape (configurable shell type).
|
|
47
|
-
*/
|
|
48
|
-
type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<string, string | {
|
|
49
|
-
cmd: string;
|
|
50
|
-
shell?: TShell;
|
|
51
|
-
}>;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Adapter-layer augmentation: add chainable helpers to GetDotenvCli without
|
|
55
|
-
* coupling the core host to cliCore. Importing this module has side effects:
|
|
56
|
-
* it extends the prototype and merges types for consumers.
|
|
57
|
-
*/
|
|
58
|
-
declare module '../cliHost/GetDotenvCli' {
|
|
59
|
-
interface GetDotenvCli {
|
|
60
|
-
/**
|
|
61
|
-
* Attach legacy root flags to this CLI instance. Defaults come from
|
|
62
|
-
* baseRootOptionDefaults when none are provided. */
|
|
63
|
-
attachRootOptions(defaults?: Partial<RootOptionsShape>, opts?: {
|
|
64
|
-
includeCommandOption?: boolean;
|
|
65
|
-
}): this;
|
|
66
|
-
/**
|
|
67
|
-
* Install a preSubcommand hook that merges CLI flags (including parent
|
|
68
|
-
* round-trip) and resolves the dotenv context before executing actions.
|
|
69
|
-
* Defaults come from baseRootOptionDefaults when none are provided.
|
|
70
|
-
*/ passOptions(defaults?: Partial<RootOptionsShape>): this;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
4
|
/**
|
|
75
5
|
* A minimal representation of an environment key/value mapping.
|
|
76
6
|
* Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
|
|
@@ -165,14 +95,6 @@ interface GetDotenvOptions {
|
|
|
165
95
|
useConfigLoader?: boolean;
|
|
166
96
|
}
|
|
167
97
|
|
|
168
|
-
/** * Per-invocation context shared with plugins and actions. */
|
|
169
|
-
type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
|
|
170
|
-
optionsResolved: TOptions;
|
|
171
|
-
dotenv: ProcessEnv;
|
|
172
|
-
plugins?: Record<string, unknown>;
|
|
173
|
-
pluginConfigs?: Record<string, unknown>;
|
|
174
|
-
};
|
|
175
|
-
|
|
176
98
|
/** src/cliHost/definePlugin.ts
|
|
177
99
|
* Plugin contracts for the GetDotenv CLI host.
|
|
178
100
|
*
|
|
@@ -223,6 +145,14 @@ interface GetDotenvCliPlugin {
|
|
|
223
145
|
use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
|
|
224
146
|
}
|
|
225
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
|
+
|
|
226
156
|
declare const demoPlugin: () => GetDotenvCliPlugin;
|
|
227
157
|
|
|
228
158
|
export { demoPlugin };
|
package/dist/plugins-demo.d.ts
CHANGED
|
@@ -1,76 +1,6 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { ZodType } from 'zod';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Minimal root options shape shared by CLI and generator layers.
|
|
6
|
-
* Keep keys optional to respect exactOptionalPropertyTypes semantics.
|
|
7
|
-
*/
|
|
8
|
-
type RootOptionsShape = {
|
|
9
|
-
env?: string;
|
|
10
|
-
vars?: string;
|
|
11
|
-
command?: string;
|
|
12
|
-
outputPath?: string;
|
|
13
|
-
shell?: string | boolean;
|
|
14
|
-
loadProcess?: boolean;
|
|
15
|
-
excludeAll?: boolean;
|
|
16
|
-
excludeDynamic?: boolean;
|
|
17
|
-
excludeEnv?: boolean;
|
|
18
|
-
excludeGlobal?: boolean;
|
|
19
|
-
excludePrivate?: boolean;
|
|
20
|
-
excludePublic?: boolean;
|
|
21
|
-
log?: boolean;
|
|
22
|
-
debug?: boolean;
|
|
23
|
-
capture?: boolean;
|
|
24
|
-
strict?: boolean;
|
|
25
|
-
redact?: boolean;
|
|
26
|
-
warnEntropy?: boolean;
|
|
27
|
-
entropyThreshold?: number;
|
|
28
|
-
entropyMinLength?: number;
|
|
29
|
-
entropyWhitelist?: string[];
|
|
30
|
-
redactPatterns?: string[];
|
|
31
|
-
defaultEnv?: string;
|
|
32
|
-
dotenvToken?: string;
|
|
33
|
-
dynamicPath?: string;
|
|
34
|
-
trace?: boolean | string[];
|
|
35
|
-
paths?: string;
|
|
36
|
-
pathsDelimiter?: string;
|
|
37
|
-
pathsDelimiterPattern?: string;
|
|
38
|
-
privateToken?: string;
|
|
39
|
-
varsDelimiter?: string;
|
|
40
|
-
varsDelimiterPattern?: string;
|
|
41
|
-
varsAssignor?: string;
|
|
42
|
-
varsAssignorPattern?: string;
|
|
43
|
-
scripts?: ScriptsTable;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Scripts table shape (configurable shell type).
|
|
47
|
-
*/
|
|
48
|
-
type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<string, string | {
|
|
49
|
-
cmd: string;
|
|
50
|
-
shell?: TShell;
|
|
51
|
-
}>;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Adapter-layer augmentation: add chainable helpers to GetDotenvCli without
|
|
55
|
-
* coupling the core host to cliCore. Importing this module has side effects:
|
|
56
|
-
* it extends the prototype and merges types for consumers.
|
|
57
|
-
*/
|
|
58
|
-
declare module '../cliHost/GetDotenvCli' {
|
|
59
|
-
interface GetDotenvCli {
|
|
60
|
-
/**
|
|
61
|
-
* Attach legacy root flags to this CLI instance. Defaults come from
|
|
62
|
-
* baseRootOptionDefaults when none are provided. */
|
|
63
|
-
attachRootOptions(defaults?: Partial<RootOptionsShape>, opts?: {
|
|
64
|
-
includeCommandOption?: boolean;
|
|
65
|
-
}): this;
|
|
66
|
-
/**
|
|
67
|
-
* Install a preSubcommand hook that merges CLI flags (including parent
|
|
68
|
-
* round-trip) and resolves the dotenv context before executing actions.
|
|
69
|
-
* Defaults come from baseRootOptionDefaults when none are provided.
|
|
70
|
-
*/ passOptions(defaults?: Partial<RootOptionsShape>): this;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
4
|
/**
|
|
75
5
|
* A minimal representation of an environment key/value mapping.
|
|
76
6
|
* Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
|
|
@@ -165,14 +95,6 @@ interface GetDotenvOptions {
|
|
|
165
95
|
useConfigLoader?: boolean;
|
|
166
96
|
}
|
|
167
97
|
|
|
168
|
-
/** * Per-invocation context shared with plugins and actions. */
|
|
169
|
-
type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
|
|
170
|
-
optionsResolved: TOptions;
|
|
171
|
-
dotenv: ProcessEnv;
|
|
172
|
-
plugins?: Record<string, unknown>;
|
|
173
|
-
pluginConfigs?: Record<string, unknown>;
|
|
174
|
-
};
|
|
175
|
-
|
|
176
98
|
/** src/cliHost/definePlugin.ts
|
|
177
99
|
* Plugin contracts for the GetDotenv CLI host.
|
|
178
100
|
*
|
|
@@ -223,6 +145,14 @@ interface GetDotenvCliPlugin {
|
|
|
223
145
|
use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
|
|
224
146
|
}
|
|
225
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
|
+
|
|
226
156
|
declare const demoPlugin: () => GetDotenvCliPlugin;
|
|
227
157
|
|
|
228
158
|
export { demoPlugin };
|
package/dist/plugins-demo.mjs
CHANGED
|
@@ -137,6 +137,48 @@ const runCommand = async (command, shell, opts) => {
|
|
|
137
137
|
}
|
|
138
138
|
};
|
|
139
139
|
|
|
140
|
+
const dropUndefined = (bag) => Object.fromEntries(Object.entries(bag).filter((e) => typeof e[1] === 'string'));
|
|
141
|
+
/** Build a sanitized env for child processes from base + overlay. */
|
|
142
|
+
const buildSpawnEnv = (base, overlay) => {
|
|
143
|
+
const raw = {
|
|
144
|
+
...(base ?? {}),
|
|
145
|
+
...(overlay ?? {}),
|
|
146
|
+
};
|
|
147
|
+
// Drop undefined first
|
|
148
|
+
const entries = Object.entries(dropUndefined(raw));
|
|
149
|
+
if (process.platform === 'win32') {
|
|
150
|
+
// Windows: keys are case-insensitive; collapse duplicates
|
|
151
|
+
const byLower = new Map();
|
|
152
|
+
for (const [k, v] of entries) {
|
|
153
|
+
byLower.set(k.toLowerCase(), [k, v]); // last wins; preserve latest casing
|
|
154
|
+
}
|
|
155
|
+
const out = {};
|
|
156
|
+
for (const [, [k, v]] of byLower)
|
|
157
|
+
out[k] = v;
|
|
158
|
+
// HOME fallback from USERPROFILE (common expectation)
|
|
159
|
+
if (!Object.prototype.hasOwnProperty.call(out, 'HOME')) {
|
|
160
|
+
const up = out['USERPROFILE'];
|
|
161
|
+
if (typeof up === 'string' && up.length > 0)
|
|
162
|
+
out['HOME'] = up;
|
|
163
|
+
}
|
|
164
|
+
// Normalize TMP/TEMP coherence (pick any present; reflect to both)
|
|
165
|
+
const tmp = out['TMP'] ?? out['TEMP'];
|
|
166
|
+
if (typeof tmp === 'string' && tmp.length > 0) {
|
|
167
|
+
out['TMP'] = tmp;
|
|
168
|
+
out['TEMP'] = tmp;
|
|
169
|
+
}
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
// POSIX: keep keys as-is
|
|
173
|
+
const out = Object.fromEntries(entries);
|
|
174
|
+
// Ensure TMPDIR exists when any temp key is present (best-effort)
|
|
175
|
+
const tmpdir = out['TMPDIR'] ?? out['TMP'] ?? out['TEMP'];
|
|
176
|
+
if (typeof tmpdir === 'string' && tmpdir.length > 0) {
|
|
177
|
+
out['TMPDIR'] = tmpdir;
|
|
178
|
+
}
|
|
179
|
+
return out;
|
|
180
|
+
};
|
|
181
|
+
|
|
140
182
|
/** src/cliHost/definePlugin.ts
|
|
141
183
|
* Plugin contracts for the GetDotenv CLI host.
|
|
142
184
|
*
|
|
@@ -247,7 +289,7 @@ const demoPlugin = () => definePlugin({
|
|
|
247
289
|
const dotenv = (ctx?.dotenv ?? {});
|
|
248
290
|
// Inherit stdio for an interactive demo. Use --capture for CI.
|
|
249
291
|
await runCommand(['node', '-e', code], false, {
|
|
250
|
-
env:
|
|
292
|
+
env: buildSpawnEnv(process.env, dotenv),
|
|
251
293
|
stdio: 'inherit',
|
|
252
294
|
});
|
|
253
295
|
});
|
|
@@ -284,20 +326,23 @@ const demoPlugin = () => definePlugin({
|
|
|
284
326
|
const ctx = cli.getCtx();
|
|
285
327
|
const dotenv = (ctx?.dotenv ?? {});
|
|
286
328
|
await runCommand(resolved, shell, {
|
|
287
|
-
env:
|
|
329
|
+
env: buildSpawnEnv(process.env, dotenv),
|
|
288
330
|
stdio: 'inherit',
|
|
289
331
|
});
|
|
290
332
|
});
|
|
291
333
|
},
|
|
292
334
|
/**
|
|
293
335
|
* Optional: afterResolve can initialize per-plugin state using ctx.dotenv.
|
|
294
|
-
* For the demo we
|
|
336
|
+
* For the demo we emit a single breadcrumb only when GETDOTENV_DEBUG is set,
|
|
337
|
+
* keeping default runs (tests/CI/smoke) quiet.
|
|
295
338
|
*/
|
|
296
339
|
afterResolve(_cli, ctx) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
340
|
+
if (process.env.GETDOTENV_DEBUG) {
|
|
341
|
+
const keys = Object.keys(ctx.dotenv);
|
|
342
|
+
if (keys.length > 0) {
|
|
343
|
+
// Keep noise low; a single-line breadcrumb is sufficient for the demo.
|
|
344
|
+
console.error('[demo] afterResolve: dotenv keys loaded:', keys.length);
|
|
345
|
+
}
|
|
301
346
|
}
|
|
302
347
|
},
|
|
303
348
|
});
|
package/dist/plugins-init.d.cts
CHANGED
|
@@ -1,76 +1,6 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { ZodType } from 'zod';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Minimal root options shape shared by CLI and generator layers.
|
|
6
|
-
* Keep keys optional to respect exactOptionalPropertyTypes semantics.
|
|
7
|
-
*/
|
|
8
|
-
type RootOptionsShape = {
|
|
9
|
-
env?: string;
|
|
10
|
-
vars?: string;
|
|
11
|
-
command?: string;
|
|
12
|
-
outputPath?: string;
|
|
13
|
-
shell?: string | boolean;
|
|
14
|
-
loadProcess?: boolean;
|
|
15
|
-
excludeAll?: boolean;
|
|
16
|
-
excludeDynamic?: boolean;
|
|
17
|
-
excludeEnv?: boolean;
|
|
18
|
-
excludeGlobal?: boolean;
|
|
19
|
-
excludePrivate?: boolean;
|
|
20
|
-
excludePublic?: boolean;
|
|
21
|
-
log?: boolean;
|
|
22
|
-
debug?: boolean;
|
|
23
|
-
capture?: boolean;
|
|
24
|
-
strict?: boolean;
|
|
25
|
-
redact?: boolean;
|
|
26
|
-
warnEntropy?: boolean;
|
|
27
|
-
entropyThreshold?: number;
|
|
28
|
-
entropyMinLength?: number;
|
|
29
|
-
entropyWhitelist?: string[];
|
|
30
|
-
redactPatterns?: string[];
|
|
31
|
-
defaultEnv?: string;
|
|
32
|
-
dotenvToken?: string;
|
|
33
|
-
dynamicPath?: string;
|
|
34
|
-
trace?: boolean | string[];
|
|
35
|
-
paths?: string;
|
|
36
|
-
pathsDelimiter?: string;
|
|
37
|
-
pathsDelimiterPattern?: string;
|
|
38
|
-
privateToken?: string;
|
|
39
|
-
varsDelimiter?: string;
|
|
40
|
-
varsDelimiterPattern?: string;
|
|
41
|
-
varsAssignor?: string;
|
|
42
|
-
varsAssignorPattern?: string;
|
|
43
|
-
scripts?: ScriptsTable;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Scripts table shape (configurable shell type).
|
|
47
|
-
*/
|
|
48
|
-
type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<string, string | {
|
|
49
|
-
cmd: string;
|
|
50
|
-
shell?: TShell;
|
|
51
|
-
}>;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Adapter-layer augmentation: add chainable helpers to GetDotenvCli without
|
|
55
|
-
* coupling the core host to cliCore. Importing this module has side effects:
|
|
56
|
-
* it extends the prototype and merges types for consumers.
|
|
57
|
-
*/
|
|
58
|
-
declare module '../cliHost/GetDotenvCli' {
|
|
59
|
-
interface GetDotenvCli {
|
|
60
|
-
/**
|
|
61
|
-
* Attach legacy root flags to this CLI instance. Defaults come from
|
|
62
|
-
* baseRootOptionDefaults when none are provided. */
|
|
63
|
-
attachRootOptions(defaults?: Partial<RootOptionsShape>, opts?: {
|
|
64
|
-
includeCommandOption?: boolean;
|
|
65
|
-
}): this;
|
|
66
|
-
/**
|
|
67
|
-
* Install a preSubcommand hook that merges CLI flags (including parent
|
|
68
|
-
* round-trip) and resolves the dotenv context before executing actions.
|
|
69
|
-
* Defaults come from baseRootOptionDefaults when none are provided.
|
|
70
|
-
*/ passOptions(defaults?: Partial<RootOptionsShape>): this;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
4
|
/**
|
|
75
5
|
* A minimal representation of an environment key/value mapping.
|
|
76
6
|
* Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
|
|
@@ -165,14 +95,6 @@ interface GetDotenvOptions {
|
|
|
165
95
|
useConfigLoader?: boolean;
|
|
166
96
|
}
|
|
167
97
|
|
|
168
|
-
/** * Per-invocation context shared with plugins and actions. */
|
|
169
|
-
type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
|
|
170
|
-
optionsResolved: TOptions;
|
|
171
|
-
dotenv: ProcessEnv;
|
|
172
|
-
plugins?: Record<string, unknown>;
|
|
173
|
-
pluginConfigs?: Record<string, unknown>;
|
|
174
|
-
};
|
|
175
|
-
|
|
176
98
|
/** src/cliHost/definePlugin.ts
|
|
177
99
|
* Plugin contracts for the GetDotenv CLI host.
|
|
178
100
|
*
|
|
@@ -223,6 +145,14 @@ interface GetDotenvCliPlugin {
|
|
|
223
145
|
use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
|
|
224
146
|
}
|
|
225
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
|
+
|
|
226
156
|
type InitPluginOptions = {
|
|
227
157
|
logger?: Logger;
|
|
228
158
|
};
|