@karmaniverous/get-dotenv 5.2.2 → 5.2.4
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 +1 -1
- package/dist/cliHost.cjs +7 -0
- package/dist/cliHost.d.cts +33 -8
- package/dist/cliHost.d.mts +33 -8
- package/dist/cliHost.d.ts +33 -8
- package/dist/cliHost.mjs +7 -0
- package/dist/getdotenv.cli.mjs +9 -35
- package/dist/index.cjs +10 -35
- package/dist/index.d.cts +19 -1
- package/dist/index.d.mts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.mjs +10 -36
- package/dist/plugins-aws.cjs +7 -0
- package/dist/plugins-aws.d.cts +29 -162
- package/dist/plugins-aws.d.mts +29 -162
- package/dist/plugins-aws.d.ts +29 -162
- package/dist/plugins-aws.mjs +7 -0
- package/dist/plugins-batch.cjs +7 -0
- package/dist/plugins-batch.d.cts +29 -162
- package/dist/plugins-batch.d.mts +29 -162
- package/dist/plugins-batch.d.ts +29 -162
- package/dist/plugins-batch.mjs +7 -0
- package/dist/plugins-cmd.cjs +9 -5
- package/dist/plugins-cmd.d.cts +29 -162
- package/dist/plugins-cmd.d.mts +29 -162
- package/dist/plugins-cmd.d.ts +29 -162
- package/dist/plugins-cmd.mjs +9 -5
- package/dist/plugins-demo.cjs +7 -30
- package/dist/plugins-demo.d.cts +29 -162
- package/dist/plugins-demo.d.mts +29 -162
- package/dist/plugins-demo.d.ts +29 -162
- package/dist/plugins-demo.mjs +7 -30
- package/dist/plugins-init.cjs +7 -0
- package/dist/plugins-init.d.cts +29 -162
- package/dist/plugins-init.d.mts +29 -162
- package/dist/plugins-init.d.ts +29 -162
- package/dist/plugins-init.mjs +7 -0
- package/dist/plugins.cjs +3674 -0
- package/dist/plugins.d.cts +210 -0
- package/dist/plugins.d.mts +210 -0
- package/dist/plugins.d.ts +210 -0
- package/dist/plugins.mjs +3667 -0
- package/package.json +13 -1
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { ZodType } from 'zod';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A minimal representation of an environment key/value mapping.
|
|
6
|
+
* Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
* Dynamic variable function signature. Receives the current expanded variables
|
|
9
|
+
* and the selected environment (if any), and returns either a string to set
|
|
10
|
+
* or `undefined` to unset/skip the variable.
|
|
11
|
+
*/
|
|
12
|
+
type GetDotenvDynamicFunction = (vars: ProcessEnv, env: string | undefined) => string | undefined;
|
|
13
|
+
type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
|
|
14
|
+
type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
|
|
15
|
+
/**
|
|
16
|
+
* Options passed programmatically to `getDotenv`.
|
|
17
|
+
*/
|
|
18
|
+
interface GetDotenvOptions {
|
|
19
|
+
/**
|
|
20
|
+
* default target environment (used if `env` is not provided)
|
|
21
|
+
*/
|
|
22
|
+
defaultEnv?: string;
|
|
23
|
+
/**
|
|
24
|
+
* token indicating a dotenv file
|
|
25
|
+
*/
|
|
26
|
+
dotenvToken: string;
|
|
27
|
+
/**
|
|
28
|
+
* path to JS/TS module default-exporting an object keyed to dynamic variable functions
|
|
29
|
+
*/
|
|
30
|
+
dynamicPath?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Programmatic dynamic variables map. When provided, this takes precedence
|
|
33
|
+
* over {@link GetDotenvOptions.dynamicPath}.
|
|
34
|
+
*/
|
|
35
|
+
dynamic?: GetDotenvDynamic;
|
|
36
|
+
/**
|
|
37
|
+
* target environment
|
|
38
|
+
*/
|
|
39
|
+
env?: string;
|
|
40
|
+
/**
|
|
41
|
+
* exclude dynamic variables from loading
|
|
42
|
+
*/
|
|
43
|
+
excludeDynamic?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* exclude environment-specific variables from loading
|
|
46
|
+
*/
|
|
47
|
+
excludeEnv?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* exclude global variables from loading
|
|
50
|
+
*/
|
|
51
|
+
excludeGlobal?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* exclude private variables from loading
|
|
54
|
+
*/
|
|
55
|
+
excludePrivate?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* exclude public variables from loading
|
|
58
|
+
*/
|
|
59
|
+
excludePublic?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* load dotenv variables to `process.env`
|
|
62
|
+
*/
|
|
63
|
+
loadProcess?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* log loaded dotenv variables to `logger`
|
|
66
|
+
*/
|
|
67
|
+
log?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* logger object (defaults to console)
|
|
70
|
+
*/
|
|
71
|
+
logger?: Logger;
|
|
72
|
+
/**
|
|
73
|
+
* if populated, writes consolidated dotenv file to this path (follows dotenvExpand rules)
|
|
74
|
+
*/
|
|
75
|
+
outputPath?: string;
|
|
76
|
+
/**
|
|
77
|
+
* array of input directory paths
|
|
78
|
+
*/
|
|
79
|
+
paths?: string[];
|
|
80
|
+
/**
|
|
81
|
+
* filename token indicating private variables
|
|
82
|
+
*/
|
|
83
|
+
privateToken?: string;
|
|
84
|
+
/**
|
|
85
|
+
* explicit variables to include
|
|
86
|
+
*/
|
|
87
|
+
vars?: ProcessEnv;
|
|
88
|
+
/**
|
|
89
|
+
* Reserved: config loader flag (no-op).
|
|
90
|
+
* The plugin-first host and generator paths already use the config
|
|
91
|
+
* loader/overlay pipeline unconditionally (no-op when no config files
|
|
92
|
+
* are present). This flag is accepted for forward compatibility but
|
|
93
|
+
* currently has no effect.
|
|
94
|
+
*/
|
|
95
|
+
useConfigLoader?: boolean;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** * 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
|
+
/** src/cliHost/definePlugin.ts
|
|
107
|
+
* Plugin contracts for the GetDotenv CLI host.
|
|
108
|
+
*
|
|
109
|
+
* This module exposes a structural public interface for the host that plugins
|
|
110
|
+
* should use (GetDotenvCliPublic). Using a structural type at the seam avoids
|
|
111
|
+
* nominal class identity issues (private fields) in downstream consumers.
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Structural public interface for the host exposed to plugins.
|
|
116
|
+
* - Extends Commander.Command so plugins can attach options/commands/hooks.
|
|
117
|
+
* - Adds host-specific helpers used by built-in plugins.
|
|
118
|
+
*
|
|
119
|
+
* Purpose: remove nominal class identity (private fields) from the plugin seam
|
|
120
|
+
* to avoid TS2379 under exactOptionalPropertyTypes in downstream consumers.
|
|
121
|
+
*/
|
|
122
|
+
type GetDotenvCliPublic<TOptions extends GetDotenvOptions = GetDotenvOptions> = Command & {
|
|
123
|
+
ns: (name: string) => Command;
|
|
124
|
+
getCtx: () => GetDotenvCliCtx<TOptions> | undefined;
|
|
125
|
+
resolveAndLoad: (customOptions?: Partial<TOptions>) => Promise<GetDotenvCliCtx<TOptions>>;
|
|
126
|
+
};
|
|
127
|
+
/** Public plugin contract used by the GetDotenv CLI host. */
|
|
128
|
+
interface GetDotenvCliPlugin {
|
|
129
|
+
id?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Setup phase: register commands and wiring on the provided CLI instance.
|
|
132
|
+
* Runs parent → children (pre-order).
|
|
133
|
+
*/
|
|
134
|
+
setup: (cli: GetDotenvCliPublic) => void | Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* After the dotenv context is resolved, initialize any clients/secrets
|
|
137
|
+
* or attach per-plugin state under ctx.plugins (by convention).
|
|
138
|
+
* Runs parent → children (pre-order).
|
|
139
|
+
*/
|
|
140
|
+
afterResolve?: (cli: GetDotenvCliPublic, ctx: GetDotenvCliCtx) => void | Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Optional Zod schema for this plugin's config slice (from config.plugins[id]).
|
|
143
|
+
* When provided, the host validates the merged config under the guarded loader path.
|
|
144
|
+
*/
|
|
145
|
+
configSchema?: ZodType;
|
|
146
|
+
/**
|
|
147
|
+
* Compositional children. Installed after the parent per pre-order.
|
|
148
|
+
*/
|
|
149
|
+
children: GetDotenvCliPlugin[];
|
|
150
|
+
/**
|
|
151
|
+
* Compose a child plugin. Returns the parent to enable chaining.
|
|
152
|
+
*/
|
|
153
|
+
use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
declare const awsPlugin: () => GetDotenvCliPlugin;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Batch services (neutral): resolve command and shell settings.
|
|
160
|
+
* Shared by the generator path and the batch plugin to avoid circular deps.
|
|
161
|
+
*/
|
|
162
|
+
type Scripts = Record<string, string | {
|
|
163
|
+
cmd: string;
|
|
164
|
+
shell?: string | boolean | undefined;
|
|
165
|
+
}>;
|
|
166
|
+
|
|
167
|
+
type BatchPluginOptions = {
|
|
168
|
+
scripts?: Scripts;
|
|
169
|
+
shell?: string | boolean;
|
|
170
|
+
logger?: Logger;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Batch plugin for the GetDotenv CLI host.
|
|
175
|
+
*
|
|
176
|
+
* Mirrors the legacy batch subcommand behavior without altering the shipped CLI. * Options:
|
|
177
|
+
* - scripts/shell: used to resolve command and shell behavior per script or global default.
|
|
178
|
+
* - logger: defaults to console.
|
|
179
|
+
*/
|
|
180
|
+
declare const batchPlugin: (opts?: BatchPluginOptions) => GetDotenvCliPlugin;
|
|
181
|
+
|
|
182
|
+
type CmdPluginOptions = {
|
|
183
|
+
/**
|
|
184
|
+
* When true, register as the default subcommand at the root. */
|
|
185
|
+
asDefault?: boolean;
|
|
186
|
+
/**
|
|
187
|
+
* Optional alias option attached to the parent command to invoke the cmd * behavior without specifying the subcommand explicitly.
|
|
188
|
+
*/
|
|
189
|
+
optionAlias?: string | {
|
|
190
|
+
flags: string;
|
|
191
|
+
description?: string;
|
|
192
|
+
expand?: boolean;
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
/**+ Cmd plugin: executes a command using the current getdotenv CLI context.
|
|
196
|
+
*
|
|
197
|
+
* - Joins positional args into a single command string.
|
|
198
|
+
* - Resolves scripts and shell settings using shared helpers.
|
|
199
|
+
* - Forwards merged CLI options to subprocesses via
|
|
200
|
+
* process.env.getDotenvCliOptions for nested CLI behavior. */
|
|
201
|
+
declare const cmdPlugin: (options?: CmdPluginOptions) => GetDotenvCliPlugin;
|
|
202
|
+
|
|
203
|
+
declare const demoPlugin: () => GetDotenvCliPlugin;
|
|
204
|
+
|
|
205
|
+
type InitPluginOptions = {
|
|
206
|
+
logger?: Logger;
|
|
207
|
+
};
|
|
208
|
+
declare const initPlugin: (opts?: InitPluginOptions) => GetDotenvCliPlugin;
|
|
209
|
+
|
|
210
|
+
export { awsPlugin, batchPlugin, cmdPlugin, demoPlugin, initPlugin };
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { ZodType } from 'zod';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A minimal representation of an environment key/value mapping.
|
|
6
|
+
* Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
* Dynamic variable function signature. Receives the current expanded variables
|
|
9
|
+
* and the selected environment (if any), and returns either a string to set
|
|
10
|
+
* or `undefined` to unset/skip the variable.
|
|
11
|
+
*/
|
|
12
|
+
type GetDotenvDynamicFunction = (vars: ProcessEnv, env: string | undefined) => string | undefined;
|
|
13
|
+
type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
|
|
14
|
+
type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
|
|
15
|
+
/**
|
|
16
|
+
* Options passed programmatically to `getDotenv`.
|
|
17
|
+
*/
|
|
18
|
+
interface GetDotenvOptions {
|
|
19
|
+
/**
|
|
20
|
+
* default target environment (used if `env` is not provided)
|
|
21
|
+
*/
|
|
22
|
+
defaultEnv?: string;
|
|
23
|
+
/**
|
|
24
|
+
* token indicating a dotenv file
|
|
25
|
+
*/
|
|
26
|
+
dotenvToken: string;
|
|
27
|
+
/**
|
|
28
|
+
* path to JS/TS module default-exporting an object keyed to dynamic variable functions
|
|
29
|
+
*/
|
|
30
|
+
dynamicPath?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Programmatic dynamic variables map. When provided, this takes precedence
|
|
33
|
+
* over {@link GetDotenvOptions.dynamicPath}.
|
|
34
|
+
*/
|
|
35
|
+
dynamic?: GetDotenvDynamic;
|
|
36
|
+
/**
|
|
37
|
+
* target environment
|
|
38
|
+
*/
|
|
39
|
+
env?: string;
|
|
40
|
+
/**
|
|
41
|
+
* exclude dynamic variables from loading
|
|
42
|
+
*/
|
|
43
|
+
excludeDynamic?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* exclude environment-specific variables from loading
|
|
46
|
+
*/
|
|
47
|
+
excludeEnv?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* exclude global variables from loading
|
|
50
|
+
*/
|
|
51
|
+
excludeGlobal?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* exclude private variables from loading
|
|
54
|
+
*/
|
|
55
|
+
excludePrivate?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* exclude public variables from loading
|
|
58
|
+
*/
|
|
59
|
+
excludePublic?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* load dotenv variables to `process.env`
|
|
62
|
+
*/
|
|
63
|
+
loadProcess?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* log loaded dotenv variables to `logger`
|
|
66
|
+
*/
|
|
67
|
+
log?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* logger object (defaults to console)
|
|
70
|
+
*/
|
|
71
|
+
logger?: Logger;
|
|
72
|
+
/**
|
|
73
|
+
* if populated, writes consolidated dotenv file to this path (follows dotenvExpand rules)
|
|
74
|
+
*/
|
|
75
|
+
outputPath?: string;
|
|
76
|
+
/**
|
|
77
|
+
* array of input directory paths
|
|
78
|
+
*/
|
|
79
|
+
paths?: string[];
|
|
80
|
+
/**
|
|
81
|
+
* filename token indicating private variables
|
|
82
|
+
*/
|
|
83
|
+
privateToken?: string;
|
|
84
|
+
/**
|
|
85
|
+
* explicit variables to include
|
|
86
|
+
*/
|
|
87
|
+
vars?: ProcessEnv;
|
|
88
|
+
/**
|
|
89
|
+
* Reserved: config loader flag (no-op).
|
|
90
|
+
* The plugin-first host and generator paths already use the config
|
|
91
|
+
* loader/overlay pipeline unconditionally (no-op when no config files
|
|
92
|
+
* are present). This flag is accepted for forward compatibility but
|
|
93
|
+
* currently has no effect.
|
|
94
|
+
*/
|
|
95
|
+
useConfigLoader?: boolean;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** * 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
|
+
/** src/cliHost/definePlugin.ts
|
|
107
|
+
* Plugin contracts for the GetDotenv CLI host.
|
|
108
|
+
*
|
|
109
|
+
* This module exposes a structural public interface for the host that plugins
|
|
110
|
+
* should use (GetDotenvCliPublic). Using a structural type at the seam avoids
|
|
111
|
+
* nominal class identity issues (private fields) in downstream consumers.
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Structural public interface for the host exposed to plugins.
|
|
116
|
+
* - Extends Commander.Command so plugins can attach options/commands/hooks.
|
|
117
|
+
* - Adds host-specific helpers used by built-in plugins.
|
|
118
|
+
*
|
|
119
|
+
* Purpose: remove nominal class identity (private fields) from the plugin seam
|
|
120
|
+
* to avoid TS2379 under exactOptionalPropertyTypes in downstream consumers.
|
|
121
|
+
*/
|
|
122
|
+
type GetDotenvCliPublic<TOptions extends GetDotenvOptions = GetDotenvOptions> = Command & {
|
|
123
|
+
ns: (name: string) => Command;
|
|
124
|
+
getCtx: () => GetDotenvCliCtx<TOptions> | undefined;
|
|
125
|
+
resolveAndLoad: (customOptions?: Partial<TOptions>) => Promise<GetDotenvCliCtx<TOptions>>;
|
|
126
|
+
};
|
|
127
|
+
/** Public plugin contract used by the GetDotenv CLI host. */
|
|
128
|
+
interface GetDotenvCliPlugin {
|
|
129
|
+
id?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Setup phase: register commands and wiring on the provided CLI instance.
|
|
132
|
+
* Runs parent → children (pre-order).
|
|
133
|
+
*/
|
|
134
|
+
setup: (cli: GetDotenvCliPublic) => void | Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* After the dotenv context is resolved, initialize any clients/secrets
|
|
137
|
+
* or attach per-plugin state under ctx.plugins (by convention).
|
|
138
|
+
* Runs parent → children (pre-order).
|
|
139
|
+
*/
|
|
140
|
+
afterResolve?: (cli: GetDotenvCliPublic, ctx: GetDotenvCliCtx) => void | Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Optional Zod schema for this plugin's config slice (from config.plugins[id]).
|
|
143
|
+
* When provided, the host validates the merged config under the guarded loader path.
|
|
144
|
+
*/
|
|
145
|
+
configSchema?: ZodType;
|
|
146
|
+
/**
|
|
147
|
+
* Compositional children. Installed after the parent per pre-order.
|
|
148
|
+
*/
|
|
149
|
+
children: GetDotenvCliPlugin[];
|
|
150
|
+
/**
|
|
151
|
+
* Compose a child plugin. Returns the parent to enable chaining.
|
|
152
|
+
*/
|
|
153
|
+
use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
declare const awsPlugin: () => GetDotenvCliPlugin;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Batch services (neutral): resolve command and shell settings.
|
|
160
|
+
* Shared by the generator path and the batch plugin to avoid circular deps.
|
|
161
|
+
*/
|
|
162
|
+
type Scripts = Record<string, string | {
|
|
163
|
+
cmd: string;
|
|
164
|
+
shell?: string | boolean | undefined;
|
|
165
|
+
}>;
|
|
166
|
+
|
|
167
|
+
type BatchPluginOptions = {
|
|
168
|
+
scripts?: Scripts;
|
|
169
|
+
shell?: string | boolean;
|
|
170
|
+
logger?: Logger;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Batch plugin for the GetDotenv CLI host.
|
|
175
|
+
*
|
|
176
|
+
* Mirrors the legacy batch subcommand behavior without altering the shipped CLI. * Options:
|
|
177
|
+
* - scripts/shell: used to resolve command and shell behavior per script or global default.
|
|
178
|
+
* - logger: defaults to console.
|
|
179
|
+
*/
|
|
180
|
+
declare const batchPlugin: (opts?: BatchPluginOptions) => GetDotenvCliPlugin;
|
|
181
|
+
|
|
182
|
+
type CmdPluginOptions = {
|
|
183
|
+
/**
|
|
184
|
+
* When true, register as the default subcommand at the root. */
|
|
185
|
+
asDefault?: boolean;
|
|
186
|
+
/**
|
|
187
|
+
* Optional alias option attached to the parent command to invoke the cmd * behavior without specifying the subcommand explicitly.
|
|
188
|
+
*/
|
|
189
|
+
optionAlias?: string | {
|
|
190
|
+
flags: string;
|
|
191
|
+
description?: string;
|
|
192
|
+
expand?: boolean;
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
/**+ Cmd plugin: executes a command using the current getdotenv CLI context.
|
|
196
|
+
*
|
|
197
|
+
* - Joins positional args into a single command string.
|
|
198
|
+
* - Resolves scripts and shell settings using shared helpers.
|
|
199
|
+
* - Forwards merged CLI options to subprocesses via
|
|
200
|
+
* process.env.getDotenvCliOptions for nested CLI behavior. */
|
|
201
|
+
declare const cmdPlugin: (options?: CmdPluginOptions) => GetDotenvCliPlugin;
|
|
202
|
+
|
|
203
|
+
declare const demoPlugin: () => GetDotenvCliPlugin;
|
|
204
|
+
|
|
205
|
+
type InitPluginOptions = {
|
|
206
|
+
logger?: Logger;
|
|
207
|
+
};
|
|
208
|
+
declare const initPlugin: (opts?: InitPluginOptions) => GetDotenvCliPlugin;
|
|
209
|
+
|
|
210
|
+
export { awsPlugin, batchPlugin, cmdPlugin, demoPlugin, initPlugin };
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { ZodType } from 'zod';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A minimal representation of an environment key/value mapping.
|
|
6
|
+
* Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
|
|
7
|
+
/**
|
|
8
|
+
* Dynamic variable function signature. Receives the current expanded variables
|
|
9
|
+
* and the selected environment (if any), and returns either a string to set
|
|
10
|
+
* or `undefined` to unset/skip the variable.
|
|
11
|
+
*/
|
|
12
|
+
type GetDotenvDynamicFunction = (vars: ProcessEnv, env: string | undefined) => string | undefined;
|
|
13
|
+
type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
|
|
14
|
+
type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
|
|
15
|
+
/**
|
|
16
|
+
* Options passed programmatically to `getDotenv`.
|
|
17
|
+
*/
|
|
18
|
+
interface GetDotenvOptions {
|
|
19
|
+
/**
|
|
20
|
+
* default target environment (used if `env` is not provided)
|
|
21
|
+
*/
|
|
22
|
+
defaultEnv?: string;
|
|
23
|
+
/**
|
|
24
|
+
* token indicating a dotenv file
|
|
25
|
+
*/
|
|
26
|
+
dotenvToken: string;
|
|
27
|
+
/**
|
|
28
|
+
* path to JS/TS module default-exporting an object keyed to dynamic variable functions
|
|
29
|
+
*/
|
|
30
|
+
dynamicPath?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Programmatic dynamic variables map. When provided, this takes precedence
|
|
33
|
+
* over {@link GetDotenvOptions.dynamicPath}.
|
|
34
|
+
*/
|
|
35
|
+
dynamic?: GetDotenvDynamic;
|
|
36
|
+
/**
|
|
37
|
+
* target environment
|
|
38
|
+
*/
|
|
39
|
+
env?: string;
|
|
40
|
+
/**
|
|
41
|
+
* exclude dynamic variables from loading
|
|
42
|
+
*/
|
|
43
|
+
excludeDynamic?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* exclude environment-specific variables from loading
|
|
46
|
+
*/
|
|
47
|
+
excludeEnv?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* exclude global variables from loading
|
|
50
|
+
*/
|
|
51
|
+
excludeGlobal?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* exclude private variables from loading
|
|
54
|
+
*/
|
|
55
|
+
excludePrivate?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* exclude public variables from loading
|
|
58
|
+
*/
|
|
59
|
+
excludePublic?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* load dotenv variables to `process.env`
|
|
62
|
+
*/
|
|
63
|
+
loadProcess?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* log loaded dotenv variables to `logger`
|
|
66
|
+
*/
|
|
67
|
+
log?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* logger object (defaults to console)
|
|
70
|
+
*/
|
|
71
|
+
logger?: Logger;
|
|
72
|
+
/**
|
|
73
|
+
* if populated, writes consolidated dotenv file to this path (follows dotenvExpand rules)
|
|
74
|
+
*/
|
|
75
|
+
outputPath?: string;
|
|
76
|
+
/**
|
|
77
|
+
* array of input directory paths
|
|
78
|
+
*/
|
|
79
|
+
paths?: string[];
|
|
80
|
+
/**
|
|
81
|
+
* filename token indicating private variables
|
|
82
|
+
*/
|
|
83
|
+
privateToken?: string;
|
|
84
|
+
/**
|
|
85
|
+
* explicit variables to include
|
|
86
|
+
*/
|
|
87
|
+
vars?: ProcessEnv;
|
|
88
|
+
/**
|
|
89
|
+
* Reserved: config loader flag (no-op).
|
|
90
|
+
* The plugin-first host and generator paths already use the config
|
|
91
|
+
* loader/overlay pipeline unconditionally (no-op when no config files
|
|
92
|
+
* are present). This flag is accepted for forward compatibility but
|
|
93
|
+
* currently has no effect.
|
|
94
|
+
*/
|
|
95
|
+
useConfigLoader?: boolean;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** * 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
|
+
/** src/cliHost/definePlugin.ts
|
|
107
|
+
* Plugin contracts for the GetDotenv CLI host.
|
|
108
|
+
*
|
|
109
|
+
* This module exposes a structural public interface for the host that plugins
|
|
110
|
+
* should use (GetDotenvCliPublic). Using a structural type at the seam avoids
|
|
111
|
+
* nominal class identity issues (private fields) in downstream consumers.
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Structural public interface for the host exposed to plugins.
|
|
116
|
+
* - Extends Commander.Command so plugins can attach options/commands/hooks.
|
|
117
|
+
* - Adds host-specific helpers used by built-in plugins.
|
|
118
|
+
*
|
|
119
|
+
* Purpose: remove nominal class identity (private fields) from the plugin seam
|
|
120
|
+
* to avoid TS2379 under exactOptionalPropertyTypes in downstream consumers.
|
|
121
|
+
*/
|
|
122
|
+
type GetDotenvCliPublic<TOptions extends GetDotenvOptions = GetDotenvOptions> = Command & {
|
|
123
|
+
ns: (name: string) => Command;
|
|
124
|
+
getCtx: () => GetDotenvCliCtx<TOptions> | undefined;
|
|
125
|
+
resolveAndLoad: (customOptions?: Partial<TOptions>) => Promise<GetDotenvCliCtx<TOptions>>;
|
|
126
|
+
};
|
|
127
|
+
/** Public plugin contract used by the GetDotenv CLI host. */
|
|
128
|
+
interface GetDotenvCliPlugin {
|
|
129
|
+
id?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Setup phase: register commands and wiring on the provided CLI instance.
|
|
132
|
+
* Runs parent → children (pre-order).
|
|
133
|
+
*/
|
|
134
|
+
setup: (cli: GetDotenvCliPublic) => void | Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* After the dotenv context is resolved, initialize any clients/secrets
|
|
137
|
+
* or attach per-plugin state under ctx.plugins (by convention).
|
|
138
|
+
* Runs parent → children (pre-order).
|
|
139
|
+
*/
|
|
140
|
+
afterResolve?: (cli: GetDotenvCliPublic, ctx: GetDotenvCliCtx) => void | Promise<void>;
|
|
141
|
+
/**
|
|
142
|
+
* Optional Zod schema for this plugin's config slice (from config.plugins[id]).
|
|
143
|
+
* When provided, the host validates the merged config under the guarded loader path.
|
|
144
|
+
*/
|
|
145
|
+
configSchema?: ZodType;
|
|
146
|
+
/**
|
|
147
|
+
* Compositional children. Installed after the parent per pre-order.
|
|
148
|
+
*/
|
|
149
|
+
children: GetDotenvCliPlugin[];
|
|
150
|
+
/**
|
|
151
|
+
* Compose a child plugin. Returns the parent to enable chaining.
|
|
152
|
+
*/
|
|
153
|
+
use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
declare const awsPlugin: () => GetDotenvCliPlugin;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Batch services (neutral): resolve command and shell settings.
|
|
160
|
+
* Shared by the generator path and the batch plugin to avoid circular deps.
|
|
161
|
+
*/
|
|
162
|
+
type Scripts = Record<string, string | {
|
|
163
|
+
cmd: string;
|
|
164
|
+
shell?: string | boolean | undefined;
|
|
165
|
+
}>;
|
|
166
|
+
|
|
167
|
+
type BatchPluginOptions = {
|
|
168
|
+
scripts?: Scripts;
|
|
169
|
+
shell?: string | boolean;
|
|
170
|
+
logger?: Logger;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Batch plugin for the GetDotenv CLI host.
|
|
175
|
+
*
|
|
176
|
+
* Mirrors the legacy batch subcommand behavior without altering the shipped CLI. * Options:
|
|
177
|
+
* - scripts/shell: used to resolve command and shell behavior per script or global default.
|
|
178
|
+
* - logger: defaults to console.
|
|
179
|
+
*/
|
|
180
|
+
declare const batchPlugin: (opts?: BatchPluginOptions) => GetDotenvCliPlugin;
|
|
181
|
+
|
|
182
|
+
type CmdPluginOptions = {
|
|
183
|
+
/**
|
|
184
|
+
* When true, register as the default subcommand at the root. */
|
|
185
|
+
asDefault?: boolean;
|
|
186
|
+
/**
|
|
187
|
+
* Optional alias option attached to the parent command to invoke the cmd * behavior without specifying the subcommand explicitly.
|
|
188
|
+
*/
|
|
189
|
+
optionAlias?: string | {
|
|
190
|
+
flags: string;
|
|
191
|
+
description?: string;
|
|
192
|
+
expand?: boolean;
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
/**+ Cmd plugin: executes a command using the current getdotenv CLI context.
|
|
196
|
+
*
|
|
197
|
+
* - Joins positional args into a single command string.
|
|
198
|
+
* - Resolves scripts and shell settings using shared helpers.
|
|
199
|
+
* - Forwards merged CLI options to subprocesses via
|
|
200
|
+
* process.env.getDotenvCliOptions for nested CLI behavior. */
|
|
201
|
+
declare const cmdPlugin: (options?: CmdPluginOptions) => GetDotenvCliPlugin;
|
|
202
|
+
|
|
203
|
+
declare const demoPlugin: () => GetDotenvCliPlugin;
|
|
204
|
+
|
|
205
|
+
type InitPluginOptions = {
|
|
206
|
+
logger?: Logger;
|
|
207
|
+
};
|
|
208
|
+
declare const initPlugin: (opts?: InitPluginOptions) => GetDotenvCliPlugin;
|
|
209
|
+
|
|
210
|
+
export { awsPlugin, batchPlugin, cmdPlugin, demoPlugin, initPlugin };
|