@karmaniverous/get-dotenv 6.0.0-1 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +91 -379
  2. package/dist/cli.d.ts +569 -0
  3. package/dist/cli.mjs +18877 -0
  4. package/dist/cliHost.d.ts +528 -184
  5. package/dist/cliHost.mjs +1977 -1428
  6. package/dist/config.d.ts +191 -14
  7. package/dist/config.mjs +266 -81
  8. package/dist/env-overlay.d.ts +223 -16
  9. package/dist/env-overlay.mjs +185 -4
  10. package/dist/getdotenv.cli.mjs +18025 -3196
  11. package/dist/index.d.ts +623 -256
  12. package/dist/index.mjs +18045 -3206
  13. package/dist/plugins-aws.d.ts +221 -91
  14. package/dist/plugins-aws.mjs +2411 -369
  15. package/dist/plugins-batch.d.ts +300 -103
  16. package/dist/plugins-batch.mjs +2560 -484
  17. package/dist/plugins-cmd.d.ts +229 -106
  18. package/dist/plugins-cmd.mjs +2518 -790
  19. package/dist/plugins-init.d.ts +221 -95
  20. package/dist/plugins-init.mjs +2170 -105
  21. package/dist/plugins.d.ts +246 -125
  22. package/dist/plugins.mjs +17941 -1968
  23. package/dist/templates/cli/index.ts +25 -0
  24. package/{templates/cli/ts → dist/templates/cli}/plugins/hello.ts +13 -9
  25. package/dist/templates/config/js/getdotenv.config.js +20 -0
  26. package/dist/templates/config/json/local/getdotenv.config.local.json +7 -0
  27. package/dist/templates/config/json/public/getdotenv.config.json +9 -0
  28. package/dist/templates/config/public/getdotenv.config.json +8 -0
  29. package/dist/templates/config/ts/getdotenv.config.ts +28 -0
  30. package/dist/templates/config/yaml/local/getdotenv.config.local.yaml +7 -0
  31. package/dist/templates/config/yaml/public/getdotenv.config.yaml +7 -0
  32. package/dist/templates/getdotenv.config.js +20 -0
  33. package/dist/templates/getdotenv.config.json +9 -0
  34. package/dist/templates/getdotenv.config.local.json +7 -0
  35. package/dist/templates/getdotenv.config.local.yaml +7 -0
  36. package/dist/templates/getdotenv.config.ts +28 -0
  37. package/dist/templates/getdotenv.config.yaml +7 -0
  38. package/dist/templates/hello.ts +42 -0
  39. package/dist/templates/index.ts +25 -0
  40. package/dist/templates/js/getdotenv.config.js +20 -0
  41. package/dist/templates/json/local/getdotenv.config.local.json +7 -0
  42. package/dist/templates/json/public/getdotenv.config.json +9 -0
  43. package/dist/templates/local/getdotenv.config.local.json +7 -0
  44. package/dist/templates/local/getdotenv.config.local.yaml +7 -0
  45. package/dist/templates/plugins/hello.ts +42 -0
  46. package/dist/templates/public/getdotenv.config.json +9 -0
  47. package/dist/templates/public/getdotenv.config.yaml +7 -0
  48. package/dist/templates/ts/getdotenv.config.ts +28 -0
  49. package/dist/templates/yaml/local/getdotenv.config.local.yaml +7 -0
  50. package/dist/templates/yaml/public/getdotenv.config.yaml +7 -0
  51. package/getdotenv.config.json +1 -19
  52. package/package.json +42 -39
  53. package/templates/cli/index.ts +25 -0
  54. package/templates/cli/plugins/hello.ts +42 -0
  55. package/templates/config/js/getdotenv.config.js +8 -3
  56. package/templates/config/json/public/getdotenv.config.json +0 -3
  57. package/templates/config/public/getdotenv.config.json +0 -5
  58. package/templates/config/ts/getdotenv.config.ts +8 -3
  59. package/templates/config/yaml/public/getdotenv.config.yaml +0 -3
  60. package/dist/plugins-demo.d.ts +0 -204
  61. package/dist/plugins-demo.mjs +0 -496
  62. package/templates/cli/ts/index.ts +0 -9
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { createCli } from '@karmaniverous/get-dotenv/cli';
4
+ import {
5
+ awsPlugin,
6
+ awsWhoamiPlugin,
7
+ batchPlugin,
8
+ cmdPlugin,
9
+ initPlugin,
10
+ } from '@karmaniverous/get-dotenv/plugins';
11
+
12
+ import { helloPlugin } from './plugins/hello';
13
+
14
+ await createCli({
15
+ alias: 'mycli',
16
+ compose: (program) =>
17
+ program
18
+ .use(
19
+ cmdPlugin({ asDefault: true, optionAlias: '-c, --cmd <command...>' }),
20
+ )
21
+ .use(batchPlugin())
22
+ .use(awsPlugin().use(awsWhoamiPlugin()))
23
+ .use(initPlugin())
24
+ .use(helloPlugin()),
25
+ })();
@@ -0,0 +1,42 @@
1
+ import {
2
+ definePlugin,
3
+ getRootCommand,
4
+ } from '@karmaniverous/get-dotenv/cliHost';
5
+ import { z } from 'zod';
6
+
7
+ const HelloConfigSchema = z.object({
8
+ loud: z.boolean().optional().default(false),
9
+ color: z.string().optional(),
10
+ });
11
+
12
+ export const helloPlugin = () => {
13
+ const plugin = definePlugin({
14
+ ns: 'hello',
15
+ configSchema: HelloConfigSchema,
16
+ setup(cli) {
17
+ cli
18
+ .description('Say hello with current dotenv context')
19
+ .addOption(
20
+ plugin.createPluginDynamicOption(
21
+ cli,
22
+ '--loud',
23
+ (_bag, pluginCfg) =>
24
+ `print greeting in ALL CAPS${pluginCfg.loud ? ' (default)' : ''}`,
25
+ ),
26
+ )
27
+ .action(() => {
28
+ const ctx = cli.getCtx();
29
+ // Derive CLI name from the true root command using a typed helper.
30
+ const rootName = getRootCommand(cli).name();
31
+
32
+ const cfg = plugin.readConfig(cli);
33
+ const keys = Object.keys(ctx.dotenv);
34
+ const label = cfg.loud
35
+ ? `[${rootName}] DOTENV KEYS (${String(keys.length)}):`
36
+ : `[${rootName}] dotenv keys (${String(keys.length)}):`;
37
+ console.log(label, keys.join(', '));
38
+ });
39
+ },
40
+ });
41
+ return plugin;
42
+ };
@@ -1,7 +1,12 @@
1
1
  export default {
2
- dotenvToken: '.env',
3
- privateToken: 'local',
4
- paths: './',
2
+ // Help-time root defaults (example):
3
+ // rootOptionDefaults: {
4
+ // redact: true,
5
+ // // redactPatterns: ['API_KEY', 'SECRET'],
6
+ // },
7
+ // Help-time visibility (example): hide selected root flags in -h
8
+ // rootOptionVisibility: { capture: false },
9
+
5
10
  vars: { APP_SETTING: 'app_value' },
6
11
  envVars: { dev: { ENV_SETTING: 'dev_value' } },
7
12
  dynamic: {
@@ -1,7 +1,4 @@
1
1
  {
2
- "dotenvToken": ".env",
3
- "privateToken": "local",
4
- "paths": "./",
5
2
  "vars": {
6
3
  "APP_SETTING": "app_value"
7
4
  },
@@ -1,9 +1,4 @@
1
1
  {
2
- "dotenvToken": ".env",
3
- "privateToken": "local",
4
- "paths": "./",
5
- "loadProcess": true,
6
- "log": false,
7
2
  "vars": {
8
3
  "APP_NAME": "my-app"
9
4
  },
@@ -6,9 +6,14 @@ type Vars = {
6
6
  };
7
7
 
8
8
  export default defineGetDotenvConfig<Vars>({
9
- dotenvToken: '.env',
10
- privateToken: 'local',
11
- paths: './',
9
+ // Help-time root defaults (example):
10
+ // rootOptionDefaults: {
11
+ // redact: true,
12
+ // // redactPatterns: ['API_KEY', 'SECRET'],
13
+ // },
14
+ // Help-time visibility (example): hide selected root flags in -h
15
+ // rootOptionVisibility: { capture: false },
16
+
12
17
  vars: { APP_SETTING: 'app_value' },
13
18
  envVars: { dev: { ENV_SETTING: 'dev_value' } },
14
19
  dynamic: {
@@ -1,6 +1,3 @@
1
- dotenvToken: ".env"
2
- privateToken: "local"
3
- paths: "./"
4
1
  vars:
5
2
  APP_SETTING: "app_value"
6
3
  envVars:
@@ -1,204 +0,0 @@
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>;
31
-
32
- /**
33
- * A minimal representation of an environment key/value mapping.
34
- * Values may be `undefined` to represent "unset".
35
- */
36
- type ProcessEnv = Record<string, string | undefined>;
37
- /**
38
- * Dynamic variable function signature. Receives the current expanded variables
39
- * and the selected environment (if any), and returns either a string to set
40
- * or `undefined` to unset/skip the variable.
41
- */
42
- type GetDotenvDynamicFunction = (vars: ProcessEnv, env: string | undefined) => string | undefined;
43
- type GetDotenvDynamic = Record<string, GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>>;
44
- type Logger = Record<string, (...args: unknown[]) => void> | typeof console;
45
- /**
46
- * Canonical programmatic options type (schema-derived).
47
- * This type is the single source of truth for programmatic options.
48
- */
49
- type GetDotenvOptions = z.output<typeof getDotenvOptionsSchemaResolved> & {
50
- /**
51
- * Compile-time overlay: narrowed logger for DX (schema stores unknown).
52
- */
53
- logger?: Logger;
54
- /**
55
- * Compile-time overlay: narrowed dynamic map for DX (schema stores unknown).
56
- */
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 = 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> & {
106
- /**
107
- * Compile-only overlay for DX: logger narrowed from unknown.
108
- */
109
- logger?: Logger;
110
- /**
111
- * Compile-only overlay for DX: scripts narrowed from Record\<string, unknown\>.
112
- */
113
- scripts?: Scripts;
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
- };
126
-
127
- /** src/cliHost/definePlugin.ts
128
- * Plugin contracts for the GetDotenv CLI host.
129
- *
130
- * This module exposes a structural public interface for the host that plugins
131
- * should use (GetDotenvCliPublic). Using a structural type at the seam avoids
132
- * nominal class identity issues (private fields) in downstream consumers.
133
- */
134
-
135
- /**
136
- * Structural public interface for the host exposed to plugins.
137
- * - Extends Commander.Command so plugins can attach options/commands/hooks.
138
- * - Adds host-specific helpers used by built-in plugins.
139
- *
140
- * Purpose: remove nominal class identity (private fields) from the plugin seam
141
- * to avoid TS2379 under exactOptionalPropertyTypes in downstream consumers.
142
- */
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
- }
161
- /** Public plugin contract used by the GetDotenv CLI host. */
162
- interface GetDotenvCliPlugin<TOptions extends GetDotenvOptions = GetDotenvOptions> {
163
- id?: string;
164
- /**
165
- * Setup phase: register commands and wiring on the provided CLI instance.
166
- * Runs parent → children (pre-order).
167
- */
168
- setup: (cli: GetDotenvCliPublic<TOptions>) => void | Promise<void>;
169
- /**
170
- * After the dotenv context is resolved, initialize any clients/secrets
171
- * or attach per-plugin state under ctx.plugins (by convention).
172
- * Runs parent → children (pre-order).
173
- */
174
- afterResolve?: (cli: GetDotenvCliPublic<TOptions>, ctx: GetDotenvCliCtx<TOptions>) => void | Promise<void>;
175
- /**
176
- * Zod schema for this plugin's config slice (from config.plugins[id]).
177
- * Enforced object-like (ZodObject) to simplify code paths and inference.
178
- */
179
- configSchema?: ZodObject;
180
- /**
181
- * Compositional children. Installed after the parent per pre-order.
182
- */
183
- children: GetDotenvCliPlugin<TOptions>[];
184
- /**
185
- * Compose a child plugin. Returns the parent to enable chaining.
186
- */
187
- use: (child: GetDotenvCliPlugin<TOptions>) => GetDotenvCliPlugin<TOptions>;
188
- }
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;
200
- };
201
-
202
- declare const demoPlugin: () => PluginWithInstanceHelpers<GetDotenvOptions, {}>;
203
-
204
- export { demoPlugin };