@karmaniverous/get-dotenv 5.2.6 → 6.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.
Files changed (55) hide show
  1. package/README.md +106 -70
  2. package/dist/cliHost.d.ts +232 -226
  3. package/dist/cliHost.mjs +777 -545
  4. package/dist/config.d.ts +7 -2
  5. package/dist/env-overlay.d.ts +21 -9
  6. package/dist/env-overlay.mjs +14 -19
  7. package/dist/getdotenv.cli.mjs +1366 -1163
  8. package/dist/index.d.ts +415 -242
  9. package/dist/index.mjs +1364 -1414
  10. package/dist/plugins-aws.d.ts +149 -94
  11. package/dist/plugins-aws.mjs +307 -195
  12. package/dist/plugins-batch.d.ts +153 -99
  13. package/dist/plugins-batch.mjs +277 -95
  14. package/dist/plugins-cmd.d.ts +140 -94
  15. package/dist/plugins-cmd.mjs +636 -502
  16. package/dist/plugins-demo.d.ts +140 -94
  17. package/dist/plugins-demo.mjs +237 -46
  18. package/dist/plugins-init.d.ts +140 -94
  19. package/dist/plugins-init.mjs +129 -12
  20. package/dist/plugins.d.ts +166 -103
  21. package/dist/plugins.mjs +977 -840
  22. package/package.json +15 -53
  23. package/templates/cli/ts/plugins/hello.ts +27 -6
  24. package/templates/config/js/getdotenv.config.js +1 -1
  25. package/templates/config/ts/getdotenv.config.ts +9 -2
  26. package/dist/cliHost.cjs +0 -1875
  27. package/dist/cliHost.d.cts +0 -409
  28. package/dist/cliHost.d.mts +0 -409
  29. package/dist/config.cjs +0 -252
  30. package/dist/config.d.cts +0 -55
  31. package/dist/config.d.mts +0 -55
  32. package/dist/env-overlay.cjs +0 -163
  33. package/dist/env-overlay.d.cts +0 -50
  34. package/dist/env-overlay.d.mts +0 -50
  35. package/dist/index.cjs +0 -4140
  36. package/dist/index.d.cts +0 -457
  37. package/dist/index.d.mts +0 -457
  38. package/dist/plugins-aws.cjs +0 -667
  39. package/dist/plugins-aws.d.cts +0 -158
  40. package/dist/plugins-aws.d.mts +0 -158
  41. package/dist/plugins-batch.cjs +0 -616
  42. package/dist/plugins-batch.d.cts +0 -180
  43. package/dist/plugins-batch.d.mts +0 -180
  44. package/dist/plugins-cmd.cjs +0 -1113
  45. package/dist/plugins-cmd.d.cts +0 -178
  46. package/dist/plugins-cmd.d.mts +0 -178
  47. package/dist/plugins-demo.cjs +0 -307
  48. package/dist/plugins-demo.d.cts +0 -158
  49. package/dist/plugins-demo.d.mts +0 -158
  50. package/dist/plugins-init.cjs +0 -289
  51. package/dist/plugins-init.d.cts +0 -162
  52. package/dist/plugins-init.d.mts +0 -162
  53. package/dist/plugins.cjs +0 -2283
  54. package/dist/plugins.d.cts +0 -210
  55. package/dist/plugins.d.mts +0 -210
package/dist/plugins.d.ts CHANGED
@@ -1,9 +1,39 @@
1
- import { Command } from 'commander';
2
- import { ZodType } from 'zod';
1
+ import { z, ZodObject } from 'zod';
2
+ import { Command, Option } from 'commander';
3
+
4
+ /**
5
+ * Scripts table shape (configurable shell type).
6
+ */
7
+ type ScriptsTable<TShell extends string | boolean = string | boolean> = Record<string, string | {
8
+ cmd: string;
9
+ shell?: TShell | undefined;
10
+ }>;
11
+
12
+ declare const getDotenvOptionsSchemaResolved: z.ZodObject<{
13
+ defaultEnv: z.ZodOptional<z.ZodString>;
14
+ dotenvToken: z.ZodOptional<z.ZodString>;
15
+ dynamicPath: z.ZodOptional<z.ZodString>;
16
+ dynamic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
17
+ env: z.ZodOptional<z.ZodString>;
18
+ excludeDynamic: z.ZodOptional<z.ZodBoolean>;
19
+ excludeEnv: z.ZodOptional<z.ZodBoolean>;
20
+ excludeGlobal: z.ZodOptional<z.ZodBoolean>;
21
+ excludePrivate: z.ZodOptional<z.ZodBoolean>;
22
+ excludePublic: z.ZodOptional<z.ZodBoolean>;
23
+ loadProcess: z.ZodOptional<z.ZodBoolean>;
24
+ log: z.ZodOptional<z.ZodBoolean>;
25
+ logger: z.ZodOptional<z.ZodUnknown>;
26
+ outputPath: z.ZodOptional<z.ZodString>;
27
+ paths: z.ZodOptional<z.ZodArray<z.ZodString>>;
28
+ privateToken: z.ZodOptional<z.ZodString>;
29
+ vars: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodString>>>;
30
+ }, z.core.$strip>;
3
31
 
4
32
  /**
5
33
  * A minimal representation of an environment key/value mapping.
6
- * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
34
+ * Values may be `undefined` to represent "unset".
35
+ */
36
+ type ProcessEnv = Record<string, string | undefined>;
7
37
  /**
8
38
  * Dynamic variable function signature. Receives the current expanded variables
9
39
  * and the selected environment (if any), and returns either a string to set
@@ -13,87 +43,86 @@ type GetDotenvDynamicFunction = (vars: ProcessEnv, env: string | undefined) => s
13
43
  type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
14
44
  type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
15
45
  /**
16
- * Options passed programmatically to `getDotenv`.
46
+ * Canonical programmatic options type (schema-derived).
47
+ * This type is the single source of truth for programmatic options.
17
48
  */
18
- interface GetDotenvOptions {
19
- /**
20
- * default target environment (used if `env` is not provided)
21
- */
22
- defaultEnv?: string;
49
+ type GetDotenvOptions = z.output<typeof getDotenvOptionsSchemaResolved> & {
23
50
  /**
24
- * token indicating a dotenv file
51
+ * Compile-time overlay: narrowed logger for DX (schema stores unknown).
25
52
  */
26
- dotenvToken: string;
27
- /**
28
- * path to JS/TS module default-exporting an object keyed to dynamic variable functions
29
- */
30
- dynamicPath?: string;
53
+ logger?: Logger;
31
54
  /**
32
- * Programmatic dynamic variables map. When provided, this takes precedence
33
- * over {@link GetDotenvOptions.dynamicPath}.
55
+ * Compile-time overlay: narrowed dynamic map for DX (schema stores unknown).
34
56
  */
35
57
  dynamic?: GetDotenvDynamic;
58
+ };
59
+
60
+ declare const getDotenvCliOptionsSchemaResolved: z.ZodObject<{
61
+ defaultEnv: z.ZodOptional<z.ZodString>;
62
+ dotenvToken: z.ZodOptional<z.ZodString>;
63
+ dynamicPath: z.ZodOptional<z.ZodString>;
64
+ dynamic: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
65
+ env: z.ZodOptional<z.ZodString>;
66
+ excludeDynamic: z.ZodOptional<z.ZodBoolean>;
67
+ excludeEnv: z.ZodOptional<z.ZodBoolean>;
68
+ excludeGlobal: z.ZodOptional<z.ZodBoolean>;
69
+ excludePrivate: z.ZodOptional<z.ZodBoolean>;
70
+ excludePublic: z.ZodOptional<z.ZodBoolean>;
71
+ loadProcess: z.ZodOptional<z.ZodBoolean>;
72
+ log: z.ZodOptional<z.ZodBoolean>;
73
+ logger: z.ZodOptional<z.ZodUnknown>;
74
+ outputPath: z.ZodOptional<z.ZodString>;
75
+ privateToken: z.ZodOptional<z.ZodString>;
76
+ debug: z.ZodOptional<z.ZodBoolean>;
77
+ strict: z.ZodOptional<z.ZodBoolean>;
78
+ capture: z.ZodOptional<z.ZodBoolean>;
79
+ trace: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
80
+ redact: z.ZodOptional<z.ZodBoolean>;
81
+ warnEntropy: z.ZodOptional<z.ZodBoolean>;
82
+ entropyThreshold: z.ZodOptional<z.ZodNumber>;
83
+ entropyMinLength: z.ZodOptional<z.ZodNumber>;
84
+ entropyWhitelist: z.ZodOptional<z.ZodArray<z.ZodString>>;
85
+ redactPatterns: z.ZodOptional<z.ZodArray<z.ZodString>>;
86
+ paths: z.ZodOptional<z.ZodString>;
87
+ pathsDelimiter: z.ZodOptional<z.ZodString>;
88
+ pathsDelimiterPattern: z.ZodOptional<z.ZodString>;
89
+ scripts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
90
+ shell: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodString]>>;
91
+ vars: z.ZodOptional<z.ZodString>;
92
+ varsAssignor: z.ZodOptional<z.ZodString>;
93
+ varsAssignorPattern: z.ZodOptional<z.ZodString>;
94
+ varsDelimiter: z.ZodOptional<z.ZodString>;
95
+ varsDelimiterPattern: z.ZodOptional<z.ZodString>;
96
+ }, z.core.$strip>;
97
+
98
+ type Scripts$1 = ScriptsTable;
99
+ /**
100
+ * Canonical CLI options type derived from the Zod schema output.
101
+ * Includes CLI-only flags (debug/strict/capture/trace/redaction/entropy),
102
+ * stringly paths/vars, and inherited programmatic fields (minus normalized
103
+ * shapes that are handled by resolution).
104
+ */
105
+ type GetDotenvCliOptions = z.output<typeof getDotenvCliOptionsSchemaResolved> & {
36
106
  /**
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)
107
+ * Compile-only overlay for DX: logger narrowed from unknown.
70
108
  */
71
109
  logger?: Logger;
72
110
  /**
73
- * if populated, writes consolidated dotenv file to this path (follows dotenvExpand rules)
74
- */
75
- outputPath?: string;
76
- /**
77
- * array of input directory paths
111
+ * Compile-only overlay for DX: scripts narrowed from Record\<string, unknown\>.
78
112
  */
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
- }
113
+ scripts?: Scripts$1;
114
+ };
115
+
116
+ type ResolvedHelpConfig = Partial<GetDotenvCliOptions> & {
117
+ plugins: Record<string, unknown>;
118
+ };
119
+ /** Per-invocation context shared with plugins and actions. */
120
+ type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
121
+ optionsResolved: TOptions;
122
+ dotenv: ProcessEnv;
123
+ plugins?: Record<string, unknown>;
124
+ pluginConfigs?: Record<string, unknown>;
125
+ };
97
126
 
98
127
  /** src/cliHost/definePlugin.ts
99
128
  * Plugin contracts for the GetDotenv CLI host.
@@ -111,58 +140,82 @@ interface GetDotenvOptions {
111
140
  * Purpose: remove nominal class identity (private fields) from the plugin seam
112
141
  * to avoid TS2379 under exactOptionalPropertyTypes in downstream consumers.
113
142
  */
114
- type GetDotenvCliPublic<TOptions extends GetDotenvOptions = GetDotenvOptions> = Command & {
115
- ns: (name: string) => Command;
116
- getCtx: () => GetDotenvCliCtx<TOptions> | undefined;
117
- resolveAndLoad: (customOptions?: Partial<TOptions>) => Promise<GetDotenvCliCtx<TOptions>>;
118
- };
143
+ interface GetDotenvCliPublic<TOptions extends GetDotenvOptions = GetDotenvOptions> extends Command {
144
+ ns(name: string): Command;
145
+ getCtx(): GetDotenvCliCtx<TOptions> | undefined;
146
+ resolveAndLoad(customOptions?: Partial<TOptions>, opts?: {
147
+ runAfterResolve?: boolean;
148
+ }): Promise<GetDotenvCliCtx<TOptions>>;
149
+ setOptionGroup(opt: Option, group: string): void;
150
+ /**
151
+ * Create a dynamic option whose description is computed at help time
152
+ * from the resolved configuration.
153
+ */
154
+ createDynamicOption(flags: string, desc: (cfg: ResolvedHelpConfig & {
155
+ plugins: Record<string, unknown>;
156
+ }) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option;
157
+ createDynamicOption<TValue = unknown>(flags: string, desc: (cfg: ResolvedHelpConfig & {
158
+ plugins: Record<string, unknown>;
159
+ }) => string, parser: (value: string, previous?: TValue) => TValue, defaultValue?: TValue): Option;
160
+ }
119
161
  /** Public plugin contract used by the GetDotenv CLI host. */
120
- interface GetDotenvCliPlugin {
162
+ interface GetDotenvCliPlugin<TOptions extends GetDotenvOptions = GetDotenvOptions> {
121
163
  id?: string;
122
164
  /**
123
165
  * Setup phase: register commands and wiring on the provided CLI instance.
124
166
  * Runs parent → children (pre-order).
125
167
  */
126
- setup: (cli: GetDotenvCliPublic) => void | Promise<void>;
168
+ setup: (cli: GetDotenvCliPublic<TOptions>) => void | Promise<void>;
127
169
  /**
128
170
  * After the dotenv context is resolved, initialize any clients/secrets
129
171
  * or attach per-plugin state under ctx.plugins (by convention).
130
172
  * Runs parent → children (pre-order).
131
173
  */
132
- afterResolve?: (cli: GetDotenvCliPublic, ctx: GetDotenvCliCtx) => void | Promise<void>;
174
+ afterResolve?: (cli: GetDotenvCliPublic<TOptions>, ctx: GetDotenvCliCtx<TOptions>) => void | Promise<void>;
133
175
  /**
134
- * Optional Zod schema for this plugin's config slice (from config.plugins[id]).
135
- * When provided, the host validates the merged config under the guarded loader path.
176
+ * Zod schema for this plugin's config slice (from config.plugins[id]).
177
+ * Enforced object-like (ZodObject) to simplify code paths and inference.
136
178
  */
137
- configSchema?: ZodType;
179
+ configSchema?: ZodObject;
138
180
  /**
139
181
  * Compositional children. Installed after the parent per pre-order.
140
182
  */
141
- children: GetDotenvCliPlugin[];
183
+ children: GetDotenvCliPlugin<TOptions>[];
142
184
  /**
143
185
  * Compose a child plugin. Returns the parent to enable chaining.
144
186
  */
145
- use: (child: GetDotenvCliPlugin) => GetDotenvCliPlugin;
187
+ use: (child: GetDotenvCliPlugin<TOptions>) => GetDotenvCliPlugin<TOptions>;
146
188
  }
147
-
148
- /** * Per-invocation context shared with plugins and actions. */
149
- type GetDotenvCliCtx<TOptions extends GetDotenvOptions = GetDotenvOptions> = {
150
- optionsResolved: TOptions;
151
- dotenv: ProcessEnv;
152
- plugins?: Record<string, unknown>;
153
- pluginConfigs?: Record<string, unknown>;
189
+ /**
190
+ * Compile-time helper type: the plugin object returned by definePlugin always
191
+ * includes the instance-bound helpers as required members. Keeping the public
192
+ * interface optional preserves compatibility for ad-hoc/test plugins, while
193
+ * return types from definePlugin provide stronger DX for shipped/typed plugins.
194
+ */
195
+ type PluginWithInstanceHelpers<TOptions extends GetDotenvOptions = GetDotenvOptions, TConfig = unknown> = GetDotenvCliPlugin<TOptions> & {
196
+ readConfig<TCfg = TConfig>(cli: GetDotenvCliPublic<TOptions>): Readonly<TCfg>;
197
+ createPluginDynamicOption<TCfg = TConfig>(cli: GetDotenvCliPublic<TOptions>, flags: string, desc: (cfg: ResolvedHelpConfig & {
198
+ plugins: Record<string, unknown>;
199
+ }, pluginCfg: Readonly<TCfg>) => string, parser?: (value: string, previous?: unknown) => unknown, defaultValue?: unknown): Option;
154
200
  };
155
201
 
156
- declare const awsPlugin: () => GetDotenvCliPlugin;
202
+ declare const awsPlugin: () => PluginWithInstanceHelpers<GetDotenvOptions, {
203
+ profile?: string | undefined;
204
+ region?: string | undefined;
205
+ defaultRegion?: string | undefined;
206
+ profileKey?: string | undefined;
207
+ profileFallbackKey?: string | undefined;
208
+ regionKey?: string | undefined;
209
+ strategy?: "cli-export" | "none" | undefined;
210
+ loginOnDemand?: boolean | undefined;
211
+ }>;
157
212
 
158
213
  /**
159
214
  * Batch services (neutral): resolve command and shell settings.
160
215
  * Shared by the generator path and the batch plugin to avoid circular deps.
161
216
  */
162
- type Scripts = Record<string, string | {
163
- cmd: string;
164
- shell?: string | boolean | undefined;
165
- }>;
217
+
218
+ type Scripts = ScriptsTable;
166
219
 
167
220
  type BatchPluginOptions = {
168
221
  scripts?: Scripts;
@@ -173,11 +226,21 @@ type BatchPluginOptions = {
173
226
  /**
174
227
  * Batch plugin for the GetDotenv CLI host.
175
228
  *
176
- * Mirrors the legacy batch subcommand behavior without altering the shipped CLI. * Options:
229
+ * Mirrors the legacy batch subcommand behavior without altering the shipped CLI.
230
+ * Options:
177
231
  * - scripts/shell: used to resolve command and shell behavior per script or global default.
178
232
  * - logger: defaults to console.
179
233
  */
180
- declare const batchPlugin: (opts?: BatchPluginOptions) => GetDotenvCliPlugin;
234
+ declare const batchPlugin: (opts?: BatchPluginOptions) => PluginWithInstanceHelpers<GetDotenvOptions, {
235
+ scripts?: Record<string, string | {
236
+ cmd: string;
237
+ shell?: string | boolean | undefined;
238
+ }> | undefined;
239
+ shell?: string | boolean | undefined;
240
+ rootPath?: string | undefined;
241
+ globs?: string | undefined;
242
+ pkgCwd?: boolean | undefined;
243
+ }>;
181
244
 
182
245
  type CmdPluginOptions = {
183
246
  /**
@@ -198,13 +261,13 @@ type CmdPluginOptions = {
198
261
  * - Resolves scripts and shell settings using shared helpers.
199
262
  * - Forwards merged CLI options to subprocesses via
200
263
  * process.env.getDotenvCliOptions for nested CLI behavior. */
201
- declare const cmdPlugin: (options?: CmdPluginOptions) => GetDotenvCliPlugin;
264
+ declare const cmdPlugin: (options?: CmdPluginOptions) => PluginWithInstanceHelpers<GetDotenvOptions, {}>;
202
265
 
203
- declare const demoPlugin: () => GetDotenvCliPlugin;
266
+ declare const demoPlugin: () => PluginWithInstanceHelpers<GetDotenvOptions, {}>;
204
267
 
205
268
  type InitPluginOptions = {
206
269
  logger?: Logger;
207
270
  };
208
- declare const initPlugin: (opts?: InitPluginOptions) => GetDotenvCliPlugin;
271
+ declare const initPlugin: (opts?: InitPluginOptions) => PluginWithInstanceHelpers<GetDotenvOptions, {}>;
209
272
 
210
273
  export { awsPlugin, batchPlugin, cmdPlugin, demoPlugin, initPlugin };