@karmaniverous/get-dotenv 4.6.0-0 → 5.0.0-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 +130 -23
- package/dist/cliHost.cjs +1089 -0
- package/dist/cliHost.d.cts +191 -0
- package/dist/cliHost.d.mts +191 -0
- package/dist/cliHost.d.ts +191 -0
- package/dist/cliHost.mjs +1085 -0
- package/dist/config.cjs +247 -0
- package/dist/config.d.cts +53 -0
- package/dist/config.d.mts +53 -0
- package/dist/config.d.ts +53 -0
- package/dist/config.mjs +242 -0
- package/dist/env-overlay.cjs +163 -0
- package/dist/env-overlay.d.cts +48 -0
- package/dist/env-overlay.d.mts +48 -0
- package/dist/env-overlay.d.ts +48 -0
- package/dist/env-overlay.mjs +161 -0
- package/dist/getdotenv.cli.mjs +2788 -734
- package/dist/index.cjs +902 -280
- package/dist/index.d.cts +122 -64
- package/dist/index.d.mts +122 -64
- package/dist/index.d.ts +122 -64
- package/dist/index.mjs +904 -283
- package/dist/plugins-aws.cjs +618 -0
- package/dist/plugins-aws.d.cts +176 -0
- package/dist/plugins-aws.d.mts +176 -0
- package/dist/plugins-aws.d.ts +176 -0
- package/dist/plugins-aws.mjs +616 -0
- package/dist/plugins-batch.cjs +569 -0
- package/dist/plugins-batch.d.cts +198 -0
- package/dist/plugins-batch.d.mts +198 -0
- package/dist/plugins-batch.d.ts +198 -0
- package/dist/plugins-batch.mjs +567 -0
- package/dist/plugins-init.cjs +282 -0
- package/dist/plugins-init.d.cts +180 -0
- package/dist/plugins-init.d.mts +180 -0
- package/dist/plugins-init.d.ts +180 -0
- package/dist/plugins-init.mjs +280 -0
- package/getdotenv.config.json +19 -0
- package/package.json +88 -17
- package/templates/cli/ts/index.ts +9 -0
- package/templates/cli/ts/plugins/hello.ts +17 -0
- package/templates/config/js/getdotenv.config.js +15 -0
- package/templates/config/json/local/getdotenv.config.local.json +7 -0
- package/templates/config/json/public/getdotenv.config.json +12 -0
- package/templates/config/public/getdotenv.config.json +13 -0
- package/templates/config/ts/getdotenv.config.ts +16 -0
- package/templates/config/yaml/local/getdotenv.config.local.yaml +7 -0
- package/templates/config/yaml/public/getdotenv.config.yaml +10 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A minimal representation of an environment key/value mapping.
|
|
6
|
+
* Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
* Dynamic variable function signature. Receives the current expanded variables
|
|
9
|
+
* and the selected environment (if any), and returns either a string to set
|
|
10
|
+
* or `undefined` to unset/skip the variable.
|
|
11
|
+
*/
|
|
12
|
+
type GetDotenvDynamicFunction = (vars: ProcessEnv, env: string | undefined) => string | undefined;
|
|
13
|
+
type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
|
|
14
|
+
type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
|
|
15
|
+
/**
|
|
16
|
+
* Options passed programmatically to `getDotenv`.
|
|
17
|
+
*/
|
|
18
|
+
interface GetDotenvOptions {
|
|
19
|
+
/**
|
|
20
|
+
* default target environment (used if `env` is not provided)
|
|
21
|
+
*/
|
|
22
|
+
defaultEnv?: string;
|
|
23
|
+
/**
|
|
24
|
+
* token indicating a dotenv file
|
|
25
|
+
*/
|
|
26
|
+
dotenvToken: string;
|
|
27
|
+
/**
|
|
28
|
+
* path to JS/TS module default-exporting an object keyed to dynamic variable functions
|
|
29
|
+
*/
|
|
30
|
+
dynamicPath?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Programmatic dynamic variables map. When provided, this takes precedence
|
|
33
|
+
* over {@link GetDotenvOptions.dynamicPath}.
|
|
34
|
+
*/
|
|
35
|
+
dynamic?: GetDotenvDynamic;
|
|
36
|
+
/**
|
|
37
|
+
* target environment
|
|
38
|
+
*/
|
|
39
|
+
env?: string;
|
|
40
|
+
/**
|
|
41
|
+
* exclude dynamic variables from loading
|
|
42
|
+
*/
|
|
43
|
+
excludeDynamic?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* exclude environment-specific variables from loading
|
|
46
|
+
*/
|
|
47
|
+
excludeEnv?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* exclude global variables from loading
|
|
50
|
+
*/
|
|
51
|
+
excludeGlobal?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* exclude private variables from loading
|
|
54
|
+
*/
|
|
55
|
+
excludePrivate?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* exclude public variables from loading
|
|
58
|
+
*/
|
|
59
|
+
excludePublic?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* load dotenv variables to `process.env`
|
|
62
|
+
*/
|
|
63
|
+
loadProcess?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* log loaded dotenv variables to `logger`
|
|
66
|
+
*/
|
|
67
|
+
log?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* logger object (defaults to console)
|
|
70
|
+
*/
|
|
71
|
+
logger?: Logger;
|
|
72
|
+
/**
|
|
73
|
+
* if populated, writes consolidated dotenv file to this path (follows dotenvExpand rules)
|
|
74
|
+
*/
|
|
75
|
+
outputPath?: string;
|
|
76
|
+
/**
|
|
77
|
+
* array of input directory paths
|
|
78
|
+
*/
|
|
79
|
+
paths?: string[];
|
|
80
|
+
/**
|
|
81
|
+
* filename token indicating private variables
|
|
82
|
+
*/
|
|
83
|
+
privateToken?: string;
|
|
84
|
+
/**
|
|
85
|
+
* explicit variables to include
|
|
86
|
+
*/
|
|
87
|
+
vars?: ProcessEnv;
|
|
88
|
+
/**
|
|
89
|
+
* Reserved: config loader flag (no-op).
|
|
90
|
+
* The plugin-first host and generator paths already use the config
|
|
91
|
+
* loader/overlay pipeline unconditionally (no-op when no config files
|
|
92
|
+
* are present). This flag is accepted for forward compatibility but
|
|
93
|
+
* currently has no effect.
|
|
94
|
+
*/
|
|
95
|
+
useConfigLoader?: boolean;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** * Per-invocation context shared with plugins and actions. */
|
|
99
|
+
type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
|
|
100
|
+
optionsResolved: TOptions;
|
|
101
|
+
dotenv: ProcessEnv;
|
|
102
|
+
plugins?: Record<string, unknown>;
|
|
103
|
+
pluginConfigs?: Record<string, unknown>;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Plugin-first CLI host for get-dotenv. Extends Commander.Command.
|
|
107
|
+
*
|
|
108
|
+
* Responsibilities:
|
|
109
|
+
* - Resolve options strictly and compute dotenv context (resolveAndLoad).
|
|
110
|
+
* - Expose a stable accessor for the current context (getCtx).
|
|
111
|
+
* - Provide a namespacing helper (ns).
|
|
112
|
+
* - Support composable plugins with parent → children install and afterResolve.
|
|
113
|
+
*
|
|
114
|
+
* NOTE: This host is additive and does not alter the legacy CLI.
|
|
115
|
+
*/
|
|
116
|
+
declare class GetDotenvCli<TOptions extends GetDotenvOptions = GetDotenvOptions> extends Command {
|
|
117
|
+
/** Registered top-level plugins (composition happens via .use()) */
|
|
118
|
+
private _plugins;
|
|
119
|
+
/** One-time installation guard */
|
|
120
|
+
private _installed;
|
|
121
|
+
constructor(alias?: string);
|
|
122
|
+
/**
|
|
123
|
+
* Resolve options (strict) and compute dotenv context. * Stores the context on the instance under a symbol.
|
|
124
|
+
*/
|
|
125
|
+
resolveAndLoad(customOptions?: Partial<TOptions>): Promise<GetDotenvCliCtx<TOptions>>;
|
|
126
|
+
/**
|
|
127
|
+
* Retrieve the current invocation context (if any).
|
|
128
|
+
*/
|
|
129
|
+
getCtx(): GetDotenvCliCtx<TOptions> | undefined;
|
|
130
|
+
/** * Convenience helper to create a namespaced subcommand.
|
|
131
|
+
*/
|
|
132
|
+
ns(name: string): Command;
|
|
133
|
+
/**
|
|
134
|
+
* Register a plugin for installation (parent level).
|
|
135
|
+
* Installation occurs on first resolveAndLoad() (or explicit install()).
|
|
136
|
+
*/
|
|
137
|
+
use(plugin: GetDotenvCliPlugin): this;
|
|
138
|
+
/**
|
|
139
|
+
* Install all registered plugins in parent → children (pre-order).
|
|
140
|
+
* Runs only once per CLI instance.
|
|
141
|
+
*/
|
|
142
|
+
install(): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Run afterResolve hooks for all plugins (parent → children).
|
|
145
|
+
*/
|
|
146
|
+
private _runAfterResolve;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Public plugin contract used by the GetDotenv CLI host. */ interface GetDotenvCliPlugin {
|
|
150
|
+
id?: string /**
|
|
151
|
+
* Setup phase: register commands and wiring on the provided CLI instance. * Runs parent → children (pre-order).
|
|
152
|
+
*/;
|
|
153
|
+
setup: (cli: GetDotenvCli) => void | Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* After the dotenv context is resolved, initialize any clients/secrets
|
|
156
|
+
* or attach per-plugin state under ctx.plugins (by convention).
|
|
157
|
+
* Runs parent → children (pre-order).
|
|
158
|
+
*/
|
|
159
|
+
afterResolve?: (cli: GetDotenvCli, ctx: GetDotenvCliCtx) => void | Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Optional Zod schema for this plugin's config slice (from config.plugins[id]).
|
|
162
|
+
* When provided, the host validates the merged config under the guarded loader path.
|
|
163
|
+
*/
|
|
164
|
+
configSchema?: ZodType;
|
|
165
|
+
/**
|
|
166
|
+
* Compositional children. Installed after the parent per pre-order.
|
|
167
|
+
*/ children: GetDotenvCliPlugin[];
|
|
168
|
+
/**
|
|
169
|
+
* Compose a child plugin. Returns the parent to enable chaining.
|
|
170
|
+
*/
|
|
171
|
+
use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Public spec type for defining a plugin with optional children.
|
|
175
|
+
* Exported to ensure TypeDoc links and navigation resolve correctly.
|
|
176
|
+
*/
|
|
177
|
+
type DefineSpec = Omit<GetDotenvCliPlugin, 'children' | 'use'> & {
|
|
178
|
+
children?: GetDotenvCliPlugin[];
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Define a GetDotenv CLI plugin with compositional helpers.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* const parent = definePlugin(\{ id: 'p', setup(cli) \{ /* ... *\/ \} \})
|
|
185
|
+
* .use(childA)
|
|
186
|
+
* .use(childB);
|
|
187
|
+
*/
|
|
188
|
+
declare const definePlugin: (spec: DefineSpec) => GetDotenvCliPlugin;
|
|
189
|
+
|
|
190
|
+
export { GetDotenvCli, definePlugin };
|
|
191
|
+
export type { DefineSpec, GetDotenvCliPlugin };
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A minimal representation of an environment key/value mapping.
|
|
6
|
+
* Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
* Dynamic variable function signature. Receives the current expanded variables
|
|
9
|
+
* and the selected environment (if any), and returns either a string to set
|
|
10
|
+
* or `undefined` to unset/skip the variable.
|
|
11
|
+
*/
|
|
12
|
+
type GetDotenvDynamicFunction = (vars: ProcessEnv, env: string | undefined) => string | undefined;
|
|
13
|
+
type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
|
|
14
|
+
type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
|
|
15
|
+
/**
|
|
16
|
+
* Options passed programmatically to `getDotenv`.
|
|
17
|
+
*/
|
|
18
|
+
interface GetDotenvOptions {
|
|
19
|
+
/**
|
|
20
|
+
* default target environment (used if `env` is not provided)
|
|
21
|
+
*/
|
|
22
|
+
defaultEnv?: string;
|
|
23
|
+
/**
|
|
24
|
+
* token indicating a dotenv file
|
|
25
|
+
*/
|
|
26
|
+
dotenvToken: string;
|
|
27
|
+
/**
|
|
28
|
+
* path to JS/TS module default-exporting an object keyed to dynamic variable functions
|
|
29
|
+
*/
|
|
30
|
+
dynamicPath?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Programmatic dynamic variables map. When provided, this takes precedence
|
|
33
|
+
* over {@link GetDotenvOptions.dynamicPath}.
|
|
34
|
+
*/
|
|
35
|
+
dynamic?: GetDotenvDynamic;
|
|
36
|
+
/**
|
|
37
|
+
* target environment
|
|
38
|
+
*/
|
|
39
|
+
env?: string;
|
|
40
|
+
/**
|
|
41
|
+
* exclude dynamic variables from loading
|
|
42
|
+
*/
|
|
43
|
+
excludeDynamic?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* exclude environment-specific variables from loading
|
|
46
|
+
*/
|
|
47
|
+
excludeEnv?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* exclude global variables from loading
|
|
50
|
+
*/
|
|
51
|
+
excludeGlobal?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* exclude private variables from loading
|
|
54
|
+
*/
|
|
55
|
+
excludePrivate?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* exclude public variables from loading
|
|
58
|
+
*/
|
|
59
|
+
excludePublic?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* load dotenv variables to `process.env`
|
|
62
|
+
*/
|
|
63
|
+
loadProcess?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* log loaded dotenv variables to `logger`
|
|
66
|
+
*/
|
|
67
|
+
log?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* logger object (defaults to console)
|
|
70
|
+
*/
|
|
71
|
+
logger?: Logger;
|
|
72
|
+
/**
|
|
73
|
+
* if populated, writes consolidated dotenv file to this path (follows dotenvExpand rules)
|
|
74
|
+
*/
|
|
75
|
+
outputPath?: string;
|
|
76
|
+
/**
|
|
77
|
+
* array of input directory paths
|
|
78
|
+
*/
|
|
79
|
+
paths?: string[];
|
|
80
|
+
/**
|
|
81
|
+
* filename token indicating private variables
|
|
82
|
+
*/
|
|
83
|
+
privateToken?: string;
|
|
84
|
+
/**
|
|
85
|
+
* explicit variables to include
|
|
86
|
+
*/
|
|
87
|
+
vars?: ProcessEnv;
|
|
88
|
+
/**
|
|
89
|
+
* Reserved: config loader flag (no-op).
|
|
90
|
+
* The plugin-first host and generator paths already use the config
|
|
91
|
+
* loader/overlay pipeline unconditionally (no-op when no config files
|
|
92
|
+
* are present). This flag is accepted for forward compatibility but
|
|
93
|
+
* currently has no effect.
|
|
94
|
+
*/
|
|
95
|
+
useConfigLoader?: boolean;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** * Per-invocation context shared with plugins and actions. */
|
|
99
|
+
type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
|
|
100
|
+
optionsResolved: TOptions;
|
|
101
|
+
dotenv: ProcessEnv;
|
|
102
|
+
plugins?: Record<string, unknown>;
|
|
103
|
+
pluginConfigs?: Record<string, unknown>;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Plugin-first CLI host for get-dotenv. Extends Commander.Command.
|
|
107
|
+
*
|
|
108
|
+
* Responsibilities:
|
|
109
|
+
* - Resolve options strictly and compute dotenv context (resolveAndLoad).
|
|
110
|
+
* - Expose a stable accessor for the current context (getCtx).
|
|
111
|
+
* - Provide a namespacing helper (ns).
|
|
112
|
+
* - Support composable plugins with parent → children install and afterResolve.
|
|
113
|
+
*
|
|
114
|
+
* NOTE: This host is additive and does not alter the legacy CLI.
|
|
115
|
+
*/
|
|
116
|
+
declare class GetDotenvCli<TOptions extends GetDotenvOptions = GetDotenvOptions> extends Command {
|
|
117
|
+
/** Registered top-level plugins (composition happens via .use()) */
|
|
118
|
+
private _plugins;
|
|
119
|
+
/** One-time installation guard */
|
|
120
|
+
private _installed;
|
|
121
|
+
constructor(alias?: string);
|
|
122
|
+
/**
|
|
123
|
+
* Resolve options (strict) and compute dotenv context. * Stores the context on the instance under a symbol.
|
|
124
|
+
*/
|
|
125
|
+
resolveAndLoad(customOptions?: Partial<TOptions>): Promise<GetDotenvCliCtx<TOptions>>;
|
|
126
|
+
/**
|
|
127
|
+
* Retrieve the current invocation context (if any).
|
|
128
|
+
*/
|
|
129
|
+
getCtx(): GetDotenvCliCtx<TOptions> | undefined;
|
|
130
|
+
/** * Convenience helper to create a namespaced subcommand.
|
|
131
|
+
*/
|
|
132
|
+
ns(name: string): Command;
|
|
133
|
+
/**
|
|
134
|
+
* Register a plugin for installation (parent level).
|
|
135
|
+
* Installation occurs on first resolveAndLoad() (or explicit install()).
|
|
136
|
+
*/
|
|
137
|
+
use(plugin: GetDotenvCliPlugin): this;
|
|
138
|
+
/**
|
|
139
|
+
* Install all registered plugins in parent → children (pre-order).
|
|
140
|
+
* Runs only once per CLI instance.
|
|
141
|
+
*/
|
|
142
|
+
install(): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Run afterResolve hooks for all plugins (parent → children).
|
|
145
|
+
*/
|
|
146
|
+
private _runAfterResolve;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Public plugin contract used by the GetDotenv CLI host. */ interface GetDotenvCliPlugin {
|
|
150
|
+
id?: string /**
|
|
151
|
+
* Setup phase: register commands and wiring on the provided CLI instance. * Runs parent → children (pre-order).
|
|
152
|
+
*/;
|
|
153
|
+
setup: (cli: GetDotenvCli) => void | Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* After the dotenv context is resolved, initialize any clients/secrets
|
|
156
|
+
* or attach per-plugin state under ctx.plugins (by convention).
|
|
157
|
+
* Runs parent → children (pre-order).
|
|
158
|
+
*/
|
|
159
|
+
afterResolve?: (cli: GetDotenvCli, ctx: GetDotenvCliCtx) => void | Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Optional Zod schema for this plugin's config slice (from config.plugins[id]).
|
|
162
|
+
* When provided, the host validates the merged config under the guarded loader path.
|
|
163
|
+
*/
|
|
164
|
+
configSchema?: ZodType;
|
|
165
|
+
/**
|
|
166
|
+
* Compositional children. Installed after the parent per pre-order.
|
|
167
|
+
*/ children: GetDotenvCliPlugin[];
|
|
168
|
+
/**
|
|
169
|
+
* Compose a child plugin. Returns the parent to enable chaining.
|
|
170
|
+
*/
|
|
171
|
+
use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Public spec type for defining a plugin with optional children.
|
|
175
|
+
* Exported to ensure TypeDoc links and navigation resolve correctly.
|
|
176
|
+
*/
|
|
177
|
+
type DefineSpec = Omit<GetDotenvCliPlugin, 'children' | 'use'> & {
|
|
178
|
+
children?: GetDotenvCliPlugin[];
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Define a GetDotenv CLI plugin with compositional helpers.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* const parent = definePlugin(\{ id: 'p', setup(cli) \{ /* ... *\/ \} \})
|
|
185
|
+
* .use(childA)
|
|
186
|
+
* .use(childB);
|
|
187
|
+
*/
|
|
188
|
+
declare const definePlugin: (spec: DefineSpec) => GetDotenvCliPlugin;
|
|
189
|
+
|
|
190
|
+
export { GetDotenvCli, definePlugin };
|
|
191
|
+
export type { DefineSpec, GetDotenvCliPlugin };
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A minimal representation of an environment key/value mapping.
|
|
6
|
+
* Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
* Dynamic variable function signature. Receives the current expanded variables
|
|
9
|
+
* and the selected environment (if any), and returns either a string to set
|
|
10
|
+
* or `undefined` to unset/skip the variable.
|
|
11
|
+
*/
|
|
12
|
+
type GetDotenvDynamicFunction = (vars: ProcessEnv, env: string | undefined) => string | undefined;
|
|
13
|
+
type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
|
|
14
|
+
type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
|
|
15
|
+
/**
|
|
16
|
+
* Options passed programmatically to `getDotenv`.
|
|
17
|
+
*/
|
|
18
|
+
interface GetDotenvOptions {
|
|
19
|
+
/**
|
|
20
|
+
* default target environment (used if `env` is not provided)
|
|
21
|
+
*/
|
|
22
|
+
defaultEnv?: string;
|
|
23
|
+
/**
|
|
24
|
+
* token indicating a dotenv file
|
|
25
|
+
*/
|
|
26
|
+
dotenvToken: string;
|
|
27
|
+
/**
|
|
28
|
+
* path to JS/TS module default-exporting an object keyed to dynamic variable functions
|
|
29
|
+
*/
|
|
30
|
+
dynamicPath?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Programmatic dynamic variables map. When provided, this takes precedence
|
|
33
|
+
* over {@link GetDotenvOptions.dynamicPath}.
|
|
34
|
+
*/
|
|
35
|
+
dynamic?: GetDotenvDynamic;
|
|
36
|
+
/**
|
|
37
|
+
* target environment
|
|
38
|
+
*/
|
|
39
|
+
env?: string;
|
|
40
|
+
/**
|
|
41
|
+
* exclude dynamic variables from loading
|
|
42
|
+
*/
|
|
43
|
+
excludeDynamic?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* exclude environment-specific variables from loading
|
|
46
|
+
*/
|
|
47
|
+
excludeEnv?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* exclude global variables from loading
|
|
50
|
+
*/
|
|
51
|
+
excludeGlobal?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* exclude private variables from loading
|
|
54
|
+
*/
|
|
55
|
+
excludePrivate?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* exclude public variables from loading
|
|
58
|
+
*/
|
|
59
|
+
excludePublic?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* load dotenv variables to `process.env`
|
|
62
|
+
*/
|
|
63
|
+
loadProcess?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* log loaded dotenv variables to `logger`
|
|
66
|
+
*/
|
|
67
|
+
log?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* logger object (defaults to console)
|
|
70
|
+
*/
|
|
71
|
+
logger?: Logger;
|
|
72
|
+
/**
|
|
73
|
+
* if populated, writes consolidated dotenv file to this path (follows dotenvExpand rules)
|
|
74
|
+
*/
|
|
75
|
+
outputPath?: string;
|
|
76
|
+
/**
|
|
77
|
+
* array of input directory paths
|
|
78
|
+
*/
|
|
79
|
+
paths?: string[];
|
|
80
|
+
/**
|
|
81
|
+
* filename token indicating private variables
|
|
82
|
+
*/
|
|
83
|
+
privateToken?: string;
|
|
84
|
+
/**
|
|
85
|
+
* explicit variables to include
|
|
86
|
+
*/
|
|
87
|
+
vars?: ProcessEnv;
|
|
88
|
+
/**
|
|
89
|
+
* Reserved: config loader flag (no-op).
|
|
90
|
+
* The plugin-first host and generator paths already use the config
|
|
91
|
+
* loader/overlay pipeline unconditionally (no-op when no config files
|
|
92
|
+
* are present). This flag is accepted for forward compatibility but
|
|
93
|
+
* currently has no effect.
|
|
94
|
+
*/
|
|
95
|
+
useConfigLoader?: boolean;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** * Per-invocation context shared with plugins and actions. */
|
|
99
|
+
type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
|
|
100
|
+
optionsResolved: TOptions;
|
|
101
|
+
dotenv: ProcessEnv;
|
|
102
|
+
plugins?: Record<string, unknown>;
|
|
103
|
+
pluginConfigs?: Record<string, unknown>;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Plugin-first CLI host for get-dotenv. Extends Commander.Command.
|
|
107
|
+
*
|
|
108
|
+
* Responsibilities:
|
|
109
|
+
* - Resolve options strictly and compute dotenv context (resolveAndLoad).
|
|
110
|
+
* - Expose a stable accessor for the current context (getCtx).
|
|
111
|
+
* - Provide a namespacing helper (ns).
|
|
112
|
+
* - Support composable plugins with parent → children install and afterResolve.
|
|
113
|
+
*
|
|
114
|
+
* NOTE: This host is additive and does not alter the legacy CLI.
|
|
115
|
+
*/
|
|
116
|
+
declare class GetDotenvCli<TOptions extends GetDotenvOptions = GetDotenvOptions> extends Command {
|
|
117
|
+
/** Registered top-level plugins (composition happens via .use()) */
|
|
118
|
+
private _plugins;
|
|
119
|
+
/** One-time installation guard */
|
|
120
|
+
private _installed;
|
|
121
|
+
constructor(alias?: string);
|
|
122
|
+
/**
|
|
123
|
+
* Resolve options (strict) and compute dotenv context. * Stores the context on the instance under a symbol.
|
|
124
|
+
*/
|
|
125
|
+
resolveAndLoad(customOptions?: Partial<TOptions>): Promise<GetDotenvCliCtx<TOptions>>;
|
|
126
|
+
/**
|
|
127
|
+
* Retrieve the current invocation context (if any).
|
|
128
|
+
*/
|
|
129
|
+
getCtx(): GetDotenvCliCtx<TOptions> | undefined;
|
|
130
|
+
/** * Convenience helper to create a namespaced subcommand.
|
|
131
|
+
*/
|
|
132
|
+
ns(name: string): Command;
|
|
133
|
+
/**
|
|
134
|
+
* Register a plugin for installation (parent level).
|
|
135
|
+
* Installation occurs on first resolveAndLoad() (or explicit install()).
|
|
136
|
+
*/
|
|
137
|
+
use(plugin: GetDotenvCliPlugin): this;
|
|
138
|
+
/**
|
|
139
|
+
* Install all registered plugins in parent → children (pre-order).
|
|
140
|
+
* Runs only once per CLI instance.
|
|
141
|
+
*/
|
|
142
|
+
install(): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Run afterResolve hooks for all plugins (parent → children).
|
|
145
|
+
*/
|
|
146
|
+
private _runAfterResolve;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Public plugin contract used by the GetDotenv CLI host. */ interface GetDotenvCliPlugin {
|
|
150
|
+
id?: string /**
|
|
151
|
+
* Setup phase: register commands and wiring on the provided CLI instance. * Runs parent → children (pre-order).
|
|
152
|
+
*/;
|
|
153
|
+
setup: (cli: GetDotenvCli) => void | Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* After the dotenv context is resolved, initialize any clients/secrets
|
|
156
|
+
* or attach per-plugin state under ctx.plugins (by convention).
|
|
157
|
+
* Runs parent → children (pre-order).
|
|
158
|
+
*/
|
|
159
|
+
afterResolve?: (cli: GetDotenvCli, ctx: GetDotenvCliCtx) => void | Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Optional Zod schema for this plugin's config slice (from config.plugins[id]).
|
|
162
|
+
* When provided, the host validates the merged config under the guarded loader path.
|
|
163
|
+
*/
|
|
164
|
+
configSchema?: ZodType;
|
|
165
|
+
/**
|
|
166
|
+
* Compositional children. Installed after the parent per pre-order.
|
|
167
|
+
*/ children: GetDotenvCliPlugin[];
|
|
168
|
+
/**
|
|
169
|
+
* Compose a child plugin. Returns the parent to enable chaining.
|
|
170
|
+
*/
|
|
171
|
+
use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Public spec type for defining a plugin with optional children.
|
|
175
|
+
* Exported to ensure TypeDoc links and navigation resolve correctly.
|
|
176
|
+
*/
|
|
177
|
+
type DefineSpec = Omit<GetDotenvCliPlugin, 'children' | 'use'> & {
|
|
178
|
+
children?: GetDotenvCliPlugin[];
|
|
179
|
+
};
|
|
180
|
+
/**
|
|
181
|
+
* Define a GetDotenv CLI plugin with compositional helpers.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* const parent = definePlugin(\{ id: 'p', setup(cli) \{ /* ... *\/ \} \})
|
|
185
|
+
* .use(childA)
|
|
186
|
+
* .use(childB);
|
|
187
|
+
*/
|
|
188
|
+
declare const definePlugin: (spec: DefineSpec) => GetDotenvCliPlugin;
|
|
189
|
+
|
|
190
|
+
export { GetDotenvCli, definePlugin };
|
|
191
|
+
export type { DefineSpec, GetDotenvCliPlugin };
|