@karmaniverous/get-dotenv 6.1.1 → 6.2.1
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 +2 -0
- package/dist/cli.d.ts +58 -2
- package/dist/cli.mjs +149 -14
- package/dist/cliHost.d.ts +216 -17
- package/dist/cliHost.mjs +178 -14
- package/dist/config.d.ts +12 -0
- package/dist/config.mjs +79 -2
- package/dist/env-overlay.d.ts +8 -0
- package/dist/getdotenv.cli.mjs +149 -14
- package/dist/index.d.ts +220 -35
- package/dist/index.mjs +200 -15
- package/dist/plugins-aws.d.ts +89 -3
- package/dist/plugins-aws.mjs +141 -14
- package/dist/plugins-batch.d.ts +83 -2
- package/dist/plugins-batch.mjs +126 -13
- package/dist/plugins-cmd.d.ts +83 -2
- package/dist/plugins-cmd.mjs +120 -13
- package/dist/plugins-init.d.ts +83 -2
- package/dist/plugins-init.mjs +111 -13
- package/dist/plugins.d.ts +78 -2
- package/dist/plugins.mjs +149 -14
- package/package.json +2 -3
package/dist/plugins-batch.mjs
CHANGED
|
@@ -21,26 +21,58 @@ import { globby } from 'globby';
|
|
|
21
21
|
* Minimal process env representation used by options and helpers.
|
|
22
22
|
* Values may be `undefined` to indicate "unset".
|
|
23
23
|
*/
|
|
24
|
+
/**
|
|
25
|
+
* Schema for an env-like record.
|
|
26
|
+
*
|
|
27
|
+
* Keys are environment variable names and values are either strings or `undefined`
|
|
28
|
+
* (to represent “unset”).
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
24
32
|
const processEnvSchema = z.record(z.string(), z.string().optional());
|
|
25
33
|
// RAW: all fields optional — undefined means "inherit" from lower layers.
|
|
34
|
+
/**
|
|
35
|
+
* Programmatic options schema (raw).
|
|
36
|
+
*
|
|
37
|
+
* This schema is the canonical runtime source of truth for the `getDotenv()` programmatic API.
|
|
38
|
+
* All fields are optional; `undefined` generally means “inherit default/lower layer”.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
26
42
|
const getDotenvOptionsSchemaRaw = z.object({
|
|
43
|
+
/** Default environment name when `env` is not provided. */
|
|
27
44
|
defaultEnv: z.string().optional(),
|
|
45
|
+
/** Base dotenv filename token (default `.env`). */
|
|
28
46
|
dotenvToken: z.string().optional(),
|
|
47
|
+
/** Path to a dynamic variables module (JS/TS) to load and apply. */
|
|
29
48
|
dynamicPath: z.string().optional(),
|
|
30
|
-
|
|
49
|
+
/** Dynamic map is intentionally wide for now; refine once sources are normalized. */
|
|
31
50
|
dynamic: z.record(z.string(), z.unknown()).optional(),
|
|
51
|
+
/** Selected environment name for this invocation (for env-scoped files and overlays). */
|
|
32
52
|
env: z.string().optional(),
|
|
53
|
+
/** When true, skip applying dynamic variables. */
|
|
33
54
|
excludeDynamic: z.boolean().optional(),
|
|
55
|
+
/** When true, skip environment-scoped dotenv files. */
|
|
34
56
|
excludeEnv: z.boolean().optional(),
|
|
57
|
+
/** When true, skip global dotenv files. */
|
|
35
58
|
excludeGlobal: z.boolean().optional(),
|
|
59
|
+
/** When true, skip private dotenv files. */
|
|
36
60
|
excludePrivate: z.boolean().optional(),
|
|
61
|
+
/** When true, skip public dotenv files. */
|
|
37
62
|
excludePublic: z.boolean().optional(),
|
|
63
|
+
/** When true, merge the final composed environment into `process.env`. */
|
|
38
64
|
loadProcess: z.boolean().optional(),
|
|
65
|
+
/** When true, log the final environment map via `logger`. */
|
|
39
66
|
log: z.boolean().optional(),
|
|
67
|
+
/** Logger used when `log` is enabled (console-compatible). */
|
|
40
68
|
logger: z.unknown().default(console),
|
|
69
|
+
/** Optional output dotenv file path to write after composition. */
|
|
41
70
|
outputPath: z.string().optional(),
|
|
71
|
+
/** Dotenv search paths (ordered). */
|
|
42
72
|
paths: z.array(z.string()).optional(),
|
|
73
|
+
/** Private token suffix for private dotenv files (default `local`). */
|
|
43
74
|
privateToken: z.string().optional(),
|
|
75
|
+
/** Explicit variables to overlay onto the composed dotenv map. */
|
|
44
76
|
vars: processEnvSchema.optional(),
|
|
45
77
|
});
|
|
46
78
|
/**
|
|
@@ -48,6 +80,14 @@ const getDotenvOptionsSchemaRaw = z.object({
|
|
|
48
80
|
* For now, this mirrors the RAW schema; future stages may materialize defaults
|
|
49
81
|
* and narrow shapes as resolution is wired into the host.
|
|
50
82
|
*/
|
|
83
|
+
/**
|
|
84
|
+
* Programmatic options schema (resolved).
|
|
85
|
+
*
|
|
86
|
+
* Today this mirrors {@link getDotenvOptionsSchemaRaw}, but is kept as a distinct export
|
|
87
|
+
* so future resolution steps can narrow or materialize defaults without breaking the API.
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
51
91
|
const getDotenvOptionsSchemaResolved = getDotenvOptionsSchemaRaw;
|
|
52
92
|
|
|
53
93
|
/**
|
|
@@ -57,27 +97,55 @@ const getDotenvOptionsSchemaResolved = getDotenvOptionsSchemaRaw;
|
|
|
57
97
|
* reflect normalized types (paths: string[], vars: ProcessEnv), applied in the
|
|
58
98
|
* CLI resolution pipeline.
|
|
59
99
|
*/
|
|
100
|
+
/**
|
|
101
|
+
* CLI options schema (raw).
|
|
102
|
+
*
|
|
103
|
+
* Extends the programmatic options schema with CLI-only flags and stringly inputs
|
|
104
|
+
* which are normalized later by the host resolution pipeline.
|
|
105
|
+
*
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
60
108
|
const getDotenvCliOptionsSchemaRaw = getDotenvOptionsSchemaRaw.extend({
|
|
61
109
|
// CLI-specific fields (stringly inputs before preprocessing)
|
|
110
|
+
/** Enable verbose debug output (host-specific). */
|
|
62
111
|
debug: z.boolean().optional(),
|
|
112
|
+
/** Fail on validation errors (schema/requiredKeys). */
|
|
63
113
|
strict: z.boolean().optional(),
|
|
114
|
+
/** Capture child process stdio (useful for CI/tests). */
|
|
64
115
|
capture: z.boolean().optional(),
|
|
116
|
+
/** Emit child env diagnostics (boolean or selected keys). */
|
|
65
117
|
trace: z.union([z.boolean(), z.array(z.string())]).optional(),
|
|
118
|
+
/** Enable presentation-time redaction in trace/log output. */
|
|
66
119
|
redact: z.boolean().optional(),
|
|
120
|
+
/** Enable entropy warnings in trace/log output. */
|
|
67
121
|
warnEntropy: z.boolean().optional(),
|
|
122
|
+
/** Entropy threshold (bits/char) for warnings. */
|
|
68
123
|
entropyThreshold: z.number().optional(),
|
|
124
|
+
/** Minimum value length to consider for entropy warnings. */
|
|
69
125
|
entropyMinLength: z.number().optional(),
|
|
126
|
+
/** Regex patterns (strings) to suppress entropy warnings by key. */
|
|
70
127
|
entropyWhitelist: z.array(z.string()).optional(),
|
|
128
|
+
/** Additional key-match patterns (strings) for redaction. */
|
|
71
129
|
redactPatterns: z.array(z.string()).optional(),
|
|
130
|
+
/** Dotenv search paths provided as a single delimited string. */
|
|
72
131
|
paths: z.string().optional(),
|
|
132
|
+
/** Delimiter string used to split `paths`. */
|
|
73
133
|
pathsDelimiter: z.string().optional(),
|
|
134
|
+
/** Regex pattern used to split `paths` (takes precedence over delimiter). */
|
|
74
135
|
pathsDelimiterPattern: z.string().optional(),
|
|
136
|
+
/** Scripts table in a permissive shape at parse time (validated elsewhere). */
|
|
75
137
|
scripts: z.record(z.string(), z.unknown()).optional(),
|
|
138
|
+
/** Shell selection (`false` for shell-off, string for explicit shell). */
|
|
76
139
|
shell: z.union([z.boolean(), z.string()]).optional(),
|
|
140
|
+
/** Extra variables expressed as a single delimited string of assignments. */
|
|
77
141
|
vars: z.string().optional(),
|
|
142
|
+
/** Assignment operator used when parsing `vars`. */
|
|
78
143
|
varsAssignor: z.string().optional(),
|
|
144
|
+
/** Regex pattern used as the assignment operator for `vars` parsing. */
|
|
79
145
|
varsAssignorPattern: z.string().optional(),
|
|
146
|
+
/** Delimiter string used to split `vars`. */
|
|
80
147
|
varsDelimiter: z.string().optional(),
|
|
148
|
+
/** Regex pattern used to split `vars` (takes precedence over delimiter). */
|
|
81
149
|
varsDelimiterPattern: z.string().optional(),
|
|
82
150
|
});
|
|
83
151
|
|
|
@@ -101,17 +169,34 @@ const envStringMap = z.record(z.string(), stringMap);
|
|
|
101
169
|
* Raw configuration schema for get‑dotenv config files (JSON/YAML/JS/TS).
|
|
102
170
|
* Validates allowed top‑level keys without performing path normalization.
|
|
103
171
|
*/
|
|
172
|
+
/**
|
|
173
|
+
* Config schema for discovered get-dotenv configuration documents (raw).
|
|
174
|
+
*
|
|
175
|
+
* This schema validates the allowed top-level keys for configuration files.
|
|
176
|
+
* It does not normalize paths or coerce types beyond Zod’s parsing.
|
|
177
|
+
*
|
|
178
|
+
* @public
|
|
179
|
+
*/
|
|
104
180
|
const getDotenvConfigSchemaRaw = z.object({
|
|
181
|
+
/** Root option defaults applied by the host (CLI-like, collapsed families). */
|
|
105
182
|
rootOptionDefaults: getDotenvCliOptionsSchemaRaw.optional(),
|
|
183
|
+
/** Help-time visibility map for root flags (false hides). */
|
|
106
184
|
rootOptionVisibility: visibilityMap.optional(),
|
|
107
|
-
|
|
185
|
+
/** Scripts table used by cmd/batch resolution (validation intentionally permissive here). */
|
|
186
|
+
scripts: z.record(z.string(), z.unknown()).optional(),
|
|
187
|
+
/** Keys required to be present in the final composed environment. */
|
|
108
188
|
requiredKeys: z.array(z.string()).optional(),
|
|
189
|
+
/** Validation schema (JS/TS only; JSON/YAML loader rejects). */
|
|
109
190
|
schema: z.unknown().optional(), // JS/TS-only; loader rejects in JSON/YAML
|
|
191
|
+
/** Public global variables (string-only). */
|
|
110
192
|
vars: stringMap.optional(), // public, global
|
|
193
|
+
/** Public per-environment variables (string-only). */
|
|
111
194
|
envVars: envStringMap.optional(), // public, per-env
|
|
112
195
|
// Dynamic in config (JS/TS only). JSON/YAML loader will reject if set.
|
|
196
|
+
/** Dynamic variable definitions (JS/TS only). */
|
|
113
197
|
dynamic: z.unknown().optional(),
|
|
114
198
|
// Per-plugin config bag; validated by plugins/host when used.
|
|
199
|
+
/** Per-plugin config slices keyed by realized mount path (for example, `aws/whoami`). */
|
|
115
200
|
plugins: z.record(z.string(), z.unknown()).optional(),
|
|
116
201
|
});
|
|
117
202
|
/**
|
|
@@ -863,13 +948,21 @@ const redactObject = (obj, opts) => {
|
|
|
863
948
|
* Base root CLI defaults (shared; kept untyped here to avoid cross-layer deps).
|
|
864
949
|
* Used as the bottom layer for CLI option resolution.
|
|
865
950
|
*/
|
|
951
|
+
const baseScripts = {
|
|
952
|
+
'git-status': {
|
|
953
|
+
cmd: 'git branch --show-current && git status -s -u',
|
|
954
|
+
shell: true,
|
|
955
|
+
},
|
|
956
|
+
};
|
|
866
957
|
/**
|
|
867
|
-
* Default values for root CLI options used by the host and helpers as the
|
|
868
|
-
*
|
|
958
|
+
* Default values for root CLI options used by the host and helpers as the baseline layer during option resolution.
|
|
959
|
+
*
|
|
960
|
+
* These defaults correspond to the “stringly” root surface (see `RootOptionsShape`) and are merged by precedence with:
|
|
961
|
+
* - create-time overrides
|
|
962
|
+
* - any discovered configuration `rootOptionDefaults`
|
|
963
|
+
* - and finally CLI flags at runtime
|
|
869
964
|
*
|
|
870
|
-
*
|
|
871
|
-
* and are merged by precedence with create-time overrides and any discovered
|
|
872
|
-
* configuration `rootOptionDefaults` before CLI flags are applied.
|
|
965
|
+
* @public
|
|
873
966
|
*/
|
|
874
967
|
const baseRootOptionDefaults = {
|
|
875
968
|
dotenvToken: '.env',
|
|
@@ -883,12 +976,7 @@ const baseRootOptionDefaults = {
|
|
|
883
976
|
paths: './',
|
|
884
977
|
pathsDelimiter: ' ',
|
|
885
978
|
privateToken: 'local',
|
|
886
|
-
scripts:
|
|
887
|
-
'git-status': {
|
|
888
|
-
cmd: 'git branch --show-current && git status -s -u',
|
|
889
|
-
shell: true,
|
|
890
|
-
},
|
|
891
|
-
},
|
|
979
|
+
scripts: baseScripts,
|
|
892
980
|
shell: true,
|
|
893
981
|
vars: '',
|
|
894
982
|
varsAssignor: '=',
|
|
@@ -1430,6 +1518,14 @@ async function _execNormalized(command, shell, opts = {}) {
|
|
|
1430
1518
|
return out;
|
|
1431
1519
|
}
|
|
1432
1520
|
}
|
|
1521
|
+
/**
|
|
1522
|
+
* Execute a command and return its exit code.
|
|
1523
|
+
*
|
|
1524
|
+
* @param command - Command string (shell) or argv array (shell-off supported).
|
|
1525
|
+
* @param shell - Shell setting (false for plain execution).
|
|
1526
|
+
* @param opts - Execution options (cwd/env/stdio).
|
|
1527
|
+
* @returns A promise resolving to the process exit code.
|
|
1528
|
+
*/
|
|
1433
1529
|
async function runCommand(command, shell, opts) {
|
|
1434
1530
|
// Build opts without injecting undefined (exactOptionalPropertyTypes-safe)
|
|
1435
1531
|
const callOpts = {};
|
|
@@ -1889,6 +1985,16 @@ function evaluateDynamicOptions(root, resolved) {
|
|
|
1889
1985
|
visit(root);
|
|
1890
1986
|
}
|
|
1891
1987
|
|
|
1988
|
+
/**
|
|
1989
|
+
* Initialize a {@link GetDotenvCli} instance with help configuration and safe defaults.
|
|
1990
|
+
*
|
|
1991
|
+
* @remarks
|
|
1992
|
+
* This is a low-level initializer used by the host constructor to keep `GetDotenvCli.ts`
|
|
1993
|
+
* small and to centralize help/output behavior.
|
|
1994
|
+
*
|
|
1995
|
+
* @param cli - The CLI instance to initialize.
|
|
1996
|
+
* @param headerGetter - Callback returning an optional help header string.
|
|
1997
|
+
*/
|
|
1892
1998
|
function initializeInstance(cli, headerGetter) {
|
|
1893
1999
|
// Configure grouped help: show only base options in default "Options";
|
|
1894
2000
|
// subcommands show all of their own options.
|
|
@@ -2856,7 +2962,9 @@ function attachBatchOptions(plugin, cli) {
|
|
|
2856
2962
|
const ScriptSchema = z.union([
|
|
2857
2963
|
z.string(),
|
|
2858
2964
|
z.object({
|
|
2965
|
+
/** Command string to execute. */
|
|
2859
2966
|
cmd: z.string(),
|
|
2967
|
+
/** Optional shell override for this script entry. */
|
|
2860
2968
|
shell: z.union([z.string(), z.boolean()]).optional(),
|
|
2861
2969
|
}),
|
|
2862
2970
|
]);
|
|
@@ -2864,10 +2972,15 @@ const ScriptSchema = z.union([
|
|
|
2864
2972
|
* Zod schema for batch plugin configuration.
|
|
2865
2973
|
*/
|
|
2866
2974
|
const batchPluginConfigSchema = z.object({
|
|
2975
|
+
/** Optional scripts table scoped to the batch plugin. */
|
|
2867
2976
|
scripts: z.record(z.string(), ScriptSchema).optional(),
|
|
2977
|
+
/** Optional default shell for batch execution (overridden by per-script shell when present). */
|
|
2868
2978
|
shell: z.union([z.string(), z.boolean()]).optional(),
|
|
2979
|
+
/** Root path for discovery, relative to CWD (or package root when pkgCwd is true). */
|
|
2869
2980
|
rootPath: z.string().optional(),
|
|
2981
|
+
/** Space-delimited glob patterns used to discover directories. */
|
|
2870
2982
|
globs: z.string().optional(),
|
|
2983
|
+
/** When true, resolve the batch root from the nearest package directory. */
|
|
2871
2984
|
pkgCwd: z.boolean().optional(),
|
|
2872
2985
|
});
|
|
2873
2986
|
|
package/dist/plugins-cmd.d.ts
CHANGED
|
@@ -20,9 +20,21 @@ type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<s
|
|
|
20
20
|
* @public
|
|
21
21
|
*/
|
|
22
22
|
interface GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> {
|
|
23
|
+
/**
|
|
24
|
+
* Fully resolved option bag used to compute this context.
|
|
25
|
+
*/
|
|
23
26
|
optionsResolved: TOptions;
|
|
27
|
+
/**
|
|
28
|
+
* Final composed dotenv environment for this invocation.
|
|
29
|
+
*/
|
|
24
30
|
dotenv: ProcessEnv;
|
|
31
|
+
/**
|
|
32
|
+
* Optional runtime plugin state bag. Plugins may publish non-sensitive metadata here.
|
|
33
|
+
*/
|
|
25
34
|
plugins?: Record<string, unknown>;
|
|
35
|
+
/**
|
|
36
|
+
* Per-plugin validated configuration slices keyed by realized mount path.
|
|
37
|
+
*/
|
|
26
38
|
pluginConfigs?: Record<string, unknown>;
|
|
27
39
|
}
|
|
28
40
|
|
|
@@ -31,6 +43,14 @@ interface GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions>
|
|
|
31
43
|
* For the current step this mirrors the RAW schema; later stages may further
|
|
32
44
|
* narrow types post-resolution in the host pipeline.
|
|
33
45
|
*/
|
|
46
|
+
/**
|
|
47
|
+
* CLI options schema (resolved).
|
|
48
|
+
*
|
|
49
|
+
* Today this mirrors {@link getDotenvCliOptionsSchemaRaw}, but is kept as a distinct export
|
|
50
|
+
* so future resolution steps can narrow or materialize defaults without breaking the API.
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
34
54
|
declare const getDotenvCliOptionsSchemaResolved: z.ZodObject<{
|
|
35
55
|
defaultEnv: z.ZodOptional<z.ZodString>;
|
|
36
56
|
dotenvToken: z.ZodOptional<z.ZodString>;
|
|
@@ -74,6 +94,14 @@ declare const getDotenvCliOptionsSchemaResolved: z.ZodObject<{
|
|
|
74
94
|
* For now, this mirrors the RAW schema; future stages may materialize defaults
|
|
75
95
|
* and narrow shapes as resolution is wired into the host.
|
|
76
96
|
*/
|
|
97
|
+
/**
|
|
98
|
+
* Programmatic options schema (resolved).
|
|
99
|
+
*
|
|
100
|
+
* Today this mirrors {@link getDotenvOptionsSchemaRaw}, but is kept as a distinct export
|
|
101
|
+
* so future resolution steps can narrow or materialize defaults without breaking the API.
|
|
102
|
+
*
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
77
105
|
declare const getDotenvOptionsSchemaResolved: z.ZodObject<{
|
|
78
106
|
defaultEnv: z.ZodOptional<z.ZodString>;
|
|
79
107
|
dotenvToken: z.ZodOptional<z.ZodString>;
|
|
@@ -128,7 +156,7 @@ type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
|
|
|
128
156
|
* Canonical programmatic options type (schema-derived).
|
|
129
157
|
* This type is the single source of truth for programmatic options.
|
|
130
158
|
*/
|
|
131
|
-
type GetDotenvOptions = z.output<typeof getDotenvOptionsSchemaResolved> & {
|
|
159
|
+
type GetDotenvOptions = Omit<z.output<typeof getDotenvOptionsSchemaResolved>, 'logger' | 'dynamic'> & {
|
|
132
160
|
/**
|
|
133
161
|
* Compile-time overlay: narrowed logger for DX (schema stores unknown).
|
|
134
162
|
*/
|
|
@@ -149,11 +177,15 @@ type Scripts = ScriptsTable;
|
|
|
149
177
|
* stringly paths/vars, and inherited programmatic fields (minus normalized
|
|
150
178
|
* shapes that are handled by resolution).
|
|
151
179
|
*/
|
|
152
|
-
type GetDotenvCliOptions = z.output<typeof getDotenvCliOptionsSchemaResolved> & {
|
|
180
|
+
type GetDotenvCliOptions = Omit<z.output<typeof getDotenvCliOptionsSchemaResolved>, 'logger' | 'dynamic' | 'scripts'> & {
|
|
153
181
|
/**
|
|
154
182
|
* Compile-only overlay for DX: logger narrowed from unknown.
|
|
155
183
|
*/
|
|
156
184
|
logger: Logger;
|
|
185
|
+
/**
|
|
186
|
+
* Compile-only overlay for DX: dynamic map narrowed from unknown.
|
|
187
|
+
*/
|
|
188
|
+
dynamic?: GetDotenvDynamic;
|
|
157
189
|
/**
|
|
158
190
|
* Compile-only overlay for DX: scripts narrowed from Record\<string, unknown\>.
|
|
159
191
|
*/
|
|
@@ -216,13 +248,37 @@ interface GetDotenvCliPublic<TOptions extends GetDotenvOptions = GetDotenvOption
|
|
|
216
248
|
getCtx(): GetDotenvCliCtx<TOptions>;
|
|
217
249
|
/** Check whether a context has been resolved (non-throwing). */
|
|
218
250
|
hasCtx(): boolean;
|
|
251
|
+
/**
|
|
252
|
+
* Resolve options and compute the dotenv context for this invocation.
|
|
253
|
+
*
|
|
254
|
+
* @param customOptions - Partial options to overlay for this invocation.
|
|
255
|
+
* @param opts - Optional resolver behavior switches (for example, whether to run `afterResolve`).
|
|
256
|
+
* @returns A promise resolving to the computed invocation context.
|
|
257
|
+
*/
|
|
219
258
|
resolveAndLoad(customOptions?: Partial<TOptions>, opts?: ResolveAndLoadOptions): Promise<GetDotenvCliCtx<TOptions>>;
|
|
259
|
+
/**
|
|
260
|
+
* Tag an option with a help group identifier for grouped root help rendering.
|
|
261
|
+
*
|
|
262
|
+
* @param opt - The Commander option to tag.
|
|
263
|
+
* @param group - Group identifier (for example, `base`, `app`, or `plugin:<name>`).
|
|
264
|
+
* @returns Nothing.
|
|
265
|
+
*/
|
|
220
266
|
setOptionGroup(opt: Option, group: string): void;
|
|
221
267
|
/**
|
|
222
268
|
* Create a dynamic option whose description is computed at help time
|
|
223
269
|
* from the resolved configuration.
|
|
224
270
|
*/
|
|
271
|
+
/**
|
|
272
|
+
* Create a dynamic option whose description is computed at help time from the resolved configuration.
|
|
273
|
+
*
|
|
274
|
+
* @param flags - Commander option flags usage string.
|
|
275
|
+
* @param desc - Description builder called during help rendering with the resolved help config.
|
|
276
|
+
* @param parser - Optional argument parser.
|
|
277
|
+
* @param defaultValue - Optional default value.
|
|
278
|
+
* @returns A Commander `Option` instance with a dynamic description.
|
|
279
|
+
*/
|
|
225
280
|
createDynamicOption<Usage extends string>(flags: Usage, desc: (cfg: ResolvedHelpConfig) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option<Usage>;
|
|
281
|
+
/** {@inheritDoc} */
|
|
226
282
|
createDynamicOption<Usage extends string, TValue = unknown>(flags: Usage, desc: (cfg: ResolvedHelpConfig) => string, parser: (value: string, previous?: TValue) => TValue, defaultValue?: TValue): Option<Usage>;
|
|
227
283
|
}
|
|
228
284
|
/**
|
|
@@ -285,7 +341,27 @@ interface GetDotenvCliPlugin<TOptions extends GetDotenvOptions = GetDotenvOption
|
|
|
285
341
|
* return types from definePlugin provide stronger DX for shipped/typed plugins.
|
|
286
342
|
*/
|
|
287
343
|
interface PluginWithInstanceHelpers<TOptions extends GetDotenvOptions = GetDotenvOptions, TConfig = unknown, TArgs extends unknown[] = [], TOpts extends OptionValues = {}, TGlobal extends OptionValues = {}> extends GetDotenvCliPlugin<TOptions, TArgs, TOpts, TGlobal> {
|
|
344
|
+
/**
|
|
345
|
+
* Read the validated (and interpolated) configuration slice for this plugin instance.
|
|
346
|
+
*
|
|
347
|
+
* @param cli - The plugin mount (or any command under this mount) used to resolve the invocation context.
|
|
348
|
+
* @returns The plugin configuration slice, typed as `TCfg`.
|
|
349
|
+
* @throws Error when called before the host has resolved the invocation context.
|
|
350
|
+
*/
|
|
288
351
|
readConfig<TCfg = TConfig>(cli: GetDotenvCliPublic<TOptions, unknown[], OptionValues, OptionValues>): Readonly<TCfg>;
|
|
352
|
+
/**
|
|
353
|
+
* Create a Commander option whose help-time description receives the resolved root help config
|
|
354
|
+
* and this plugin instance’s validated configuration slice.
|
|
355
|
+
*
|
|
356
|
+
* @typeParam TCfg - The plugin configuration slice type.
|
|
357
|
+
* @typeParam Usage - The Commander usage string for the option flags.
|
|
358
|
+
* @param cli - The plugin mount used to associate the option with a realized mount path.
|
|
359
|
+
* @param flags - Commander option flags usage string.
|
|
360
|
+
* @param desc - Description builder receiving the resolved help config and the plugin config slice.
|
|
361
|
+
* @param parser - Optional argument parser.
|
|
362
|
+
* @param defaultValue - Optional default value.
|
|
363
|
+
* @returns A Commander `Option` instance with a dynamic description.
|
|
364
|
+
*/
|
|
289
365
|
createPluginDynamicOption<TCfg = TConfig, Usage extends string = string>(cli: GetDotenvCliPublic<TOptions, unknown[], OptionValues, OptionValues>, flags: Usage, desc: (cfg: ResolvedHelpConfig, pluginCfg: Readonly<TCfg>) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option<Usage>;
|
|
290
366
|
}
|
|
291
367
|
|
|
@@ -342,6 +418,11 @@ interface RunCmdWithContextOptions {
|
|
|
342
418
|
declare const cmdPlugin: (options?: CmdPluginOptions) => PluginWithInstanceHelpers<GetDotenvOptions, {
|
|
343
419
|
expand?: boolean | undefined;
|
|
344
420
|
}, [], {}, {}>;
|
|
421
|
+
/**
|
|
422
|
+
* Cmd plugin instance type returned by {@link cmdPlugin}.
|
|
423
|
+
*
|
|
424
|
+
* @public
|
|
425
|
+
*/
|
|
345
426
|
type CmdPlugin = ReturnType<typeof cmdPlugin>;
|
|
346
427
|
|
|
347
428
|
export { cmdPlugin };
|
package/dist/plugins-cmd.mjs
CHANGED
|
@@ -20,26 +20,58 @@ import { Option, Command } from '@commander-js/extra-typings';
|
|
|
20
20
|
* Minimal process env representation used by options and helpers.
|
|
21
21
|
* Values may be `undefined` to indicate "unset".
|
|
22
22
|
*/
|
|
23
|
+
/**
|
|
24
|
+
* Schema for an env-like record.
|
|
25
|
+
*
|
|
26
|
+
* Keys are environment variable names and values are either strings or `undefined`
|
|
27
|
+
* (to represent “unset”).
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
23
31
|
const processEnvSchema = z.record(z.string(), z.string().optional());
|
|
24
32
|
// RAW: all fields optional — undefined means "inherit" from lower layers.
|
|
33
|
+
/**
|
|
34
|
+
* Programmatic options schema (raw).
|
|
35
|
+
*
|
|
36
|
+
* This schema is the canonical runtime source of truth for the `getDotenv()` programmatic API.
|
|
37
|
+
* All fields are optional; `undefined` generally means “inherit default/lower layer”.
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
25
41
|
const getDotenvOptionsSchemaRaw = z.object({
|
|
42
|
+
/** Default environment name when `env` is not provided. */
|
|
26
43
|
defaultEnv: z.string().optional(),
|
|
44
|
+
/** Base dotenv filename token (default `.env`). */
|
|
27
45
|
dotenvToken: z.string().optional(),
|
|
46
|
+
/** Path to a dynamic variables module (JS/TS) to load and apply. */
|
|
28
47
|
dynamicPath: z.string().optional(),
|
|
29
|
-
|
|
48
|
+
/** Dynamic map is intentionally wide for now; refine once sources are normalized. */
|
|
30
49
|
dynamic: z.record(z.string(), z.unknown()).optional(),
|
|
50
|
+
/** Selected environment name for this invocation (for env-scoped files and overlays). */
|
|
31
51
|
env: z.string().optional(),
|
|
52
|
+
/** When true, skip applying dynamic variables. */
|
|
32
53
|
excludeDynamic: z.boolean().optional(),
|
|
54
|
+
/** When true, skip environment-scoped dotenv files. */
|
|
33
55
|
excludeEnv: z.boolean().optional(),
|
|
56
|
+
/** When true, skip global dotenv files. */
|
|
34
57
|
excludeGlobal: z.boolean().optional(),
|
|
58
|
+
/** When true, skip private dotenv files. */
|
|
35
59
|
excludePrivate: z.boolean().optional(),
|
|
60
|
+
/** When true, skip public dotenv files. */
|
|
36
61
|
excludePublic: z.boolean().optional(),
|
|
62
|
+
/** When true, merge the final composed environment into `process.env`. */
|
|
37
63
|
loadProcess: z.boolean().optional(),
|
|
64
|
+
/** When true, log the final environment map via `logger`. */
|
|
38
65
|
log: z.boolean().optional(),
|
|
66
|
+
/** Logger used when `log` is enabled (console-compatible). */
|
|
39
67
|
logger: z.unknown().default(console),
|
|
68
|
+
/** Optional output dotenv file path to write after composition. */
|
|
40
69
|
outputPath: z.string().optional(),
|
|
70
|
+
/** Dotenv search paths (ordered). */
|
|
41
71
|
paths: z.array(z.string()).optional(),
|
|
72
|
+
/** Private token suffix for private dotenv files (default `local`). */
|
|
42
73
|
privateToken: z.string().optional(),
|
|
74
|
+
/** Explicit variables to overlay onto the composed dotenv map. */
|
|
43
75
|
vars: processEnvSchema.optional(),
|
|
44
76
|
});
|
|
45
77
|
/**
|
|
@@ -47,6 +79,14 @@ const getDotenvOptionsSchemaRaw = z.object({
|
|
|
47
79
|
* For now, this mirrors the RAW schema; future stages may materialize defaults
|
|
48
80
|
* and narrow shapes as resolution is wired into the host.
|
|
49
81
|
*/
|
|
82
|
+
/**
|
|
83
|
+
* Programmatic options schema (resolved).
|
|
84
|
+
*
|
|
85
|
+
* Today this mirrors {@link getDotenvOptionsSchemaRaw}, but is kept as a distinct export
|
|
86
|
+
* so future resolution steps can narrow or materialize defaults without breaking the API.
|
|
87
|
+
*
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
50
90
|
const getDotenvOptionsSchemaResolved = getDotenvOptionsSchemaRaw;
|
|
51
91
|
|
|
52
92
|
/**
|
|
@@ -56,27 +96,55 @@ const getDotenvOptionsSchemaResolved = getDotenvOptionsSchemaRaw;
|
|
|
56
96
|
* reflect normalized types (paths: string[], vars: ProcessEnv), applied in the
|
|
57
97
|
* CLI resolution pipeline.
|
|
58
98
|
*/
|
|
99
|
+
/**
|
|
100
|
+
* CLI options schema (raw).
|
|
101
|
+
*
|
|
102
|
+
* Extends the programmatic options schema with CLI-only flags and stringly inputs
|
|
103
|
+
* which are normalized later by the host resolution pipeline.
|
|
104
|
+
*
|
|
105
|
+
* @public
|
|
106
|
+
*/
|
|
59
107
|
const getDotenvCliOptionsSchemaRaw = getDotenvOptionsSchemaRaw.extend({
|
|
60
108
|
// CLI-specific fields (stringly inputs before preprocessing)
|
|
109
|
+
/** Enable verbose debug output (host-specific). */
|
|
61
110
|
debug: z.boolean().optional(),
|
|
111
|
+
/** Fail on validation errors (schema/requiredKeys). */
|
|
62
112
|
strict: z.boolean().optional(),
|
|
113
|
+
/** Capture child process stdio (useful for CI/tests). */
|
|
63
114
|
capture: z.boolean().optional(),
|
|
115
|
+
/** Emit child env diagnostics (boolean or selected keys). */
|
|
64
116
|
trace: z.union([z.boolean(), z.array(z.string())]).optional(),
|
|
117
|
+
/** Enable presentation-time redaction in trace/log output. */
|
|
65
118
|
redact: z.boolean().optional(),
|
|
119
|
+
/** Enable entropy warnings in trace/log output. */
|
|
66
120
|
warnEntropy: z.boolean().optional(),
|
|
121
|
+
/** Entropy threshold (bits/char) for warnings. */
|
|
67
122
|
entropyThreshold: z.number().optional(),
|
|
123
|
+
/** Minimum value length to consider for entropy warnings. */
|
|
68
124
|
entropyMinLength: z.number().optional(),
|
|
125
|
+
/** Regex patterns (strings) to suppress entropy warnings by key. */
|
|
69
126
|
entropyWhitelist: z.array(z.string()).optional(),
|
|
127
|
+
/** Additional key-match patterns (strings) for redaction. */
|
|
70
128
|
redactPatterns: z.array(z.string()).optional(),
|
|
129
|
+
/** Dotenv search paths provided as a single delimited string. */
|
|
71
130
|
paths: z.string().optional(),
|
|
131
|
+
/** Delimiter string used to split `paths`. */
|
|
72
132
|
pathsDelimiter: z.string().optional(),
|
|
133
|
+
/** Regex pattern used to split `paths` (takes precedence over delimiter). */
|
|
73
134
|
pathsDelimiterPattern: z.string().optional(),
|
|
135
|
+
/** Scripts table in a permissive shape at parse time (validated elsewhere). */
|
|
74
136
|
scripts: z.record(z.string(), z.unknown()).optional(),
|
|
137
|
+
/** Shell selection (`false` for shell-off, string for explicit shell). */
|
|
75
138
|
shell: z.union([z.boolean(), z.string()]).optional(),
|
|
139
|
+
/** Extra variables expressed as a single delimited string of assignments. */
|
|
76
140
|
vars: z.string().optional(),
|
|
141
|
+
/** Assignment operator used when parsing `vars`. */
|
|
77
142
|
varsAssignor: z.string().optional(),
|
|
143
|
+
/** Regex pattern used as the assignment operator for `vars` parsing. */
|
|
78
144
|
varsAssignorPattern: z.string().optional(),
|
|
145
|
+
/** Delimiter string used to split `vars`. */
|
|
79
146
|
varsDelimiter: z.string().optional(),
|
|
147
|
+
/** Regex pattern used to split `vars` (takes precedence over delimiter). */
|
|
80
148
|
varsDelimiterPattern: z.string().optional(),
|
|
81
149
|
});
|
|
82
150
|
|
|
@@ -100,17 +168,34 @@ const envStringMap = z.record(z.string(), stringMap);
|
|
|
100
168
|
* Raw configuration schema for get‑dotenv config files (JSON/YAML/JS/TS).
|
|
101
169
|
* Validates allowed top‑level keys without performing path normalization.
|
|
102
170
|
*/
|
|
171
|
+
/**
|
|
172
|
+
* Config schema for discovered get-dotenv configuration documents (raw).
|
|
173
|
+
*
|
|
174
|
+
* This schema validates the allowed top-level keys for configuration files.
|
|
175
|
+
* It does not normalize paths or coerce types beyond Zod’s parsing.
|
|
176
|
+
*
|
|
177
|
+
* @public
|
|
178
|
+
*/
|
|
103
179
|
const getDotenvConfigSchemaRaw = z.object({
|
|
180
|
+
/** Root option defaults applied by the host (CLI-like, collapsed families). */
|
|
104
181
|
rootOptionDefaults: getDotenvCliOptionsSchemaRaw.optional(),
|
|
182
|
+
/** Help-time visibility map for root flags (false hides). */
|
|
105
183
|
rootOptionVisibility: visibilityMap.optional(),
|
|
106
|
-
|
|
184
|
+
/** Scripts table used by cmd/batch resolution (validation intentionally permissive here). */
|
|
185
|
+
scripts: z.record(z.string(), z.unknown()).optional(),
|
|
186
|
+
/** Keys required to be present in the final composed environment. */
|
|
107
187
|
requiredKeys: z.array(z.string()).optional(),
|
|
188
|
+
/** Validation schema (JS/TS only; JSON/YAML loader rejects). */
|
|
108
189
|
schema: z.unknown().optional(), // JS/TS-only; loader rejects in JSON/YAML
|
|
190
|
+
/** Public global variables (string-only). */
|
|
109
191
|
vars: stringMap.optional(), // public, global
|
|
192
|
+
/** Public per-environment variables (string-only). */
|
|
110
193
|
envVars: envStringMap.optional(), // public, per-env
|
|
111
194
|
// Dynamic in config (JS/TS only). JSON/YAML loader will reject if set.
|
|
195
|
+
/** Dynamic variable definitions (JS/TS only). */
|
|
112
196
|
dynamic: z.unknown().optional(),
|
|
113
197
|
// Per-plugin config bag; validated by plugins/host when used.
|
|
198
|
+
/** Per-plugin config slices keyed by realized mount path (for example, `aws/whoami`). */
|
|
114
199
|
plugins: z.record(z.string(), z.unknown()).optional(),
|
|
115
200
|
});
|
|
116
201
|
/**
|
|
@@ -940,13 +1025,21 @@ function traceChildEnv(opts) {
|
|
|
940
1025
|
* Base root CLI defaults (shared; kept untyped here to avoid cross-layer deps).
|
|
941
1026
|
* Used as the bottom layer for CLI option resolution.
|
|
942
1027
|
*/
|
|
1028
|
+
const baseScripts = {
|
|
1029
|
+
'git-status': {
|
|
1030
|
+
cmd: 'git branch --show-current && git status -s -u',
|
|
1031
|
+
shell: true,
|
|
1032
|
+
},
|
|
1033
|
+
};
|
|
943
1034
|
/**
|
|
944
|
-
* Default values for root CLI options used by the host and helpers as the
|
|
945
|
-
*
|
|
1035
|
+
* Default values for root CLI options used by the host and helpers as the baseline layer during option resolution.
|
|
1036
|
+
*
|
|
1037
|
+
* These defaults correspond to the “stringly” root surface (see `RootOptionsShape`) and are merged by precedence with:
|
|
1038
|
+
* - create-time overrides
|
|
1039
|
+
* - any discovered configuration `rootOptionDefaults`
|
|
1040
|
+
* - and finally CLI flags at runtime
|
|
946
1041
|
*
|
|
947
|
-
*
|
|
948
|
-
* and are merged by precedence with create-time overrides and any discovered
|
|
949
|
-
* configuration `rootOptionDefaults` before CLI flags are applied.
|
|
1042
|
+
* @public
|
|
950
1043
|
*/
|
|
951
1044
|
const baseRootOptionDefaults = {
|
|
952
1045
|
dotenvToken: '.env',
|
|
@@ -960,12 +1053,7 @@ const baseRootOptionDefaults = {
|
|
|
960
1053
|
paths: './',
|
|
961
1054
|
pathsDelimiter: ' ',
|
|
962
1055
|
privateToken: 'local',
|
|
963
|
-
scripts:
|
|
964
|
-
'git-status': {
|
|
965
|
-
cmd: 'git branch --show-current && git status -s -u',
|
|
966
|
-
shell: true,
|
|
967
|
-
},
|
|
968
|
-
},
|
|
1056
|
+
scripts: baseScripts,
|
|
969
1057
|
shell: true,
|
|
970
1058
|
vars: '',
|
|
971
1059
|
varsAssignor: '=',
|
|
@@ -1512,6 +1600,14 @@ async function _execNormalized(command, shell, opts = {}) {
|
|
|
1512
1600
|
return out;
|
|
1513
1601
|
}
|
|
1514
1602
|
}
|
|
1603
|
+
/**
|
|
1604
|
+
* Execute a command and return its exit code.
|
|
1605
|
+
*
|
|
1606
|
+
* @param command - Command string (shell) or argv array (shell-off supported).
|
|
1607
|
+
* @param shell - Shell setting (false for plain execution).
|
|
1608
|
+
* @param opts - Execution options (cwd/env/stdio).
|
|
1609
|
+
* @returns A promise resolving to the process exit code.
|
|
1610
|
+
*/
|
|
1515
1611
|
async function runCommand(command, shell, opts) {
|
|
1516
1612
|
// Build opts without injecting undefined (exactOptionalPropertyTypes-safe)
|
|
1517
1613
|
const callOpts = {};
|
|
@@ -1971,6 +2067,16 @@ function evaluateDynamicOptions(root, resolved) {
|
|
|
1971
2067
|
visit(root);
|
|
1972
2068
|
}
|
|
1973
2069
|
|
|
2070
|
+
/**
|
|
2071
|
+
* Initialize a {@link GetDotenvCli} instance with help configuration and safe defaults.
|
|
2072
|
+
*
|
|
2073
|
+
* @remarks
|
|
2074
|
+
* This is a low-level initializer used by the host constructor to keep `GetDotenvCli.ts`
|
|
2075
|
+
* small and to centralize help/output behavior.
|
|
2076
|
+
*
|
|
2077
|
+
* @param cli - The CLI instance to initialize.
|
|
2078
|
+
* @param headerGetter - Callback returning an optional help header string.
|
|
2079
|
+
*/
|
|
1974
2080
|
function initializeInstance(cli, headerGetter) {
|
|
1975
2081
|
// Configure grouped help: show only base options in default "Options";
|
|
1976
2082
|
// subcommands show all of their own options.
|
|
@@ -2940,6 +3046,7 @@ const attachCmdParentInvoker = (cli, options, plugin) => {
|
|
|
2940
3046
|
*/
|
|
2941
3047
|
const cmdPluginConfigSchema = z
|
|
2942
3048
|
.object({
|
|
3049
|
+
/** When true, expand the alias value before execution (default behavior when omitted). */
|
|
2943
3050
|
expand: z.boolean().optional(),
|
|
2944
3051
|
})
|
|
2945
3052
|
.strict();
|