@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/config.d.cts DELETED
@@ -1,55 +0,0 @@
1
- type Scripts = Record<string, string | {
2
- cmd: string;
3
- shell?: string | boolean;
4
- }>;
5
-
6
- type GetDotenvConfigResolved = {
7
- dotenvToken?: string;
8
- privateToken?: string;
9
- paths?: string[];
10
- loadProcess?: boolean;
11
- log?: boolean;
12
- shell?: string | boolean;
13
- scripts?: Scripts;
14
- requiredKeys?: string[];
15
- schema?: unknown;
16
- vars?: Record<string, string>;
17
- envVars?: Record<string, Record<string, string>>;
18
- dynamic?: unknown;
19
- plugins?: Record<string, unknown>;
20
- };
21
-
22
- type ConfigPrivacy = 'public' | 'local';
23
- type ConfigScope = 'packaged' | 'project';
24
- type ConfigFile = {
25
- path: string;
26
- privacy: ConfigPrivacy;
27
- scope: ConfigScope;
28
- };
29
- /**
30
- * Discover JSON/YAML config files in the packaged root and project root.
31
- * Order: packaged public → project public → project local. */
32
- declare const discoverConfigFiles: (importMetaUrl?: string) => Promise<ConfigFile[]>;
33
- /**
34
- * Load a single config file (JSON/YAML). JS/TS is not supported in this step.
35
- * Validates with Zod RAW schema, then normalizes to RESOLVED.
36
- *
37
- * For JSON/YAML: if a "dynamic" property is present, throws with guidance.
38
- * For JS/TS: default export is loaded; "dynamic" is allowed.
39
- */
40
- declare const loadConfigFile: (filePath: string) => Promise<GetDotenvConfigResolved>;
41
- type ResolvedConfigSources = {
42
- packaged?: GetDotenvConfigResolved;
43
- project?: {
44
- public?: GetDotenvConfigResolved;
45
- local?: GetDotenvConfigResolved;
46
- };
47
- };
48
- /**
49
- * Discover and load configs into resolved shapes, ordered by scope/privacy.
50
- * JSON/YAML/JS/TS supported; first match per scope/privacy applies.
51
- */
52
- declare const resolveGetDotenvConfigSources: (importMetaUrl?: string) => Promise<ResolvedConfigSources>;
53
- declare const toFileUrl: (p: string) => string;
54
-
55
- export { discoverConfigFiles, loadConfigFile, resolveGetDotenvConfigSources, toFileUrl };
package/dist/config.d.mts DELETED
@@ -1,55 +0,0 @@
1
- type Scripts = Record<string, string | {
2
- cmd: string;
3
- shell?: string | boolean;
4
- }>;
5
-
6
- type GetDotenvConfigResolved = {
7
- dotenvToken?: string;
8
- privateToken?: string;
9
- paths?: string[];
10
- loadProcess?: boolean;
11
- log?: boolean;
12
- shell?: string | boolean;
13
- scripts?: Scripts;
14
- requiredKeys?: string[];
15
- schema?: unknown;
16
- vars?: Record<string, string>;
17
- envVars?: Record<string, Record<string, string>>;
18
- dynamic?: unknown;
19
- plugins?: Record<string, unknown>;
20
- };
21
-
22
- type ConfigPrivacy = 'public' | 'local';
23
- type ConfigScope = 'packaged' | 'project';
24
- type ConfigFile = {
25
- path: string;
26
- privacy: ConfigPrivacy;
27
- scope: ConfigScope;
28
- };
29
- /**
30
- * Discover JSON/YAML config files in the packaged root and project root.
31
- * Order: packaged public → project public → project local. */
32
- declare const discoverConfigFiles: (importMetaUrl?: string) => Promise<ConfigFile[]>;
33
- /**
34
- * Load a single config file (JSON/YAML). JS/TS is not supported in this step.
35
- * Validates with Zod RAW schema, then normalizes to RESOLVED.
36
- *
37
- * For JSON/YAML: if a "dynamic" property is present, throws with guidance.
38
- * For JS/TS: default export is loaded; "dynamic" is allowed.
39
- */
40
- declare const loadConfigFile: (filePath: string) => Promise<GetDotenvConfigResolved>;
41
- type ResolvedConfigSources = {
42
- packaged?: GetDotenvConfigResolved;
43
- project?: {
44
- public?: GetDotenvConfigResolved;
45
- local?: GetDotenvConfigResolved;
46
- };
47
- };
48
- /**
49
- * Discover and load configs into resolved shapes, ordered by scope/privacy.
50
- * JSON/YAML/JS/TS supported; first match per scope/privacy applies.
51
- */
52
- declare const resolveGetDotenvConfigSources: (importMetaUrl?: string) => Promise<ResolvedConfigSources>;
53
- declare const toFileUrl: (p: string) => string;
54
-
55
- export { discoverConfigFiles, loadConfigFile, resolveGetDotenvConfigSources, toFileUrl };
@@ -1,163 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Dotenv expansion utilities.
5
- *
6
- * This module implements recursive expansion of environment-variable
7
- * references in strings and records. It supports both whitespace and
8
- * bracket syntaxes with optional defaults:
9
- *
10
- * - Whitespace: `$VAR[:default]`
11
- * - Bracketed: `${VAR[:default]}`
12
- *
13
- * Escaped dollar signs (`\$`) are preserved.
14
- * Unknown variables resolve to empty string unless a default is provided.
15
- */
16
- /**
17
- * Like String.prototype.search but returns the last index.
18
- * @internal
19
- */
20
- const searchLast = (str, rgx) => {
21
- const matches = Array.from(str.matchAll(rgx));
22
- return matches.length > 0 ? (matches.slice(-1)[0]?.index ?? -1) : -1;
23
- };
24
- const replaceMatch = (value, match, ref) => {
25
- /**
26
- * @internal
27
- */
28
- const group = match[0];
29
- const key = match[1];
30
- const defaultValue = match[2];
31
- if (!key)
32
- return value;
33
- const replacement = value.replace(group, ref[key] ?? defaultValue ?? '');
34
- return interpolate(replacement, ref);
35
- };
36
- const interpolate = (value = '', ref = {}) => {
37
- /**
38
- * @internal
39
- */
40
- // if value is falsy, return it as is
41
- if (!value)
42
- return value;
43
- // get position of last unescaped dollar sign
44
- const lastUnescapedDollarSignIndex = searchLast(value, /(?!(?<=\\))\$/g);
45
- // return value if none found
46
- if (lastUnescapedDollarSignIndex === -1)
47
- return value;
48
- // evaluate the value tail
49
- const tail = value.slice(lastUnescapedDollarSignIndex);
50
- // find whitespace pattern: $KEY:DEFAULT
51
- const whitespacePattern = /^\$([\w]+)(?::([^\s]*))?/;
52
- const whitespaceMatch = whitespacePattern.exec(tail);
53
- if (whitespaceMatch != null)
54
- return replaceMatch(value, whitespaceMatch, ref);
55
- else {
56
- // find bracket pattern: ${KEY:DEFAULT}
57
- const bracketPattern = /^\${([\w]+)(?::([^}]*))?}/;
58
- const bracketMatch = bracketPattern.exec(tail);
59
- if (bracketMatch != null)
60
- return replaceMatch(value, bracketMatch, ref);
61
- }
62
- return value;
63
- };
64
- /**
65
- * Recursively expands environment variables in a string. Variables may be
66
- * presented with optional default as `$VAR[:default]` or `${VAR[:default]}`.
67
- * Unknown variables will expand to an empty string.
68
- *
69
- * @param value - The string to expand.
70
- * @param ref - The reference object to use for variable expansion.
71
- * @returns The expanded string.
72
- *
73
- * @example
74
- * ```ts
75
- * process.env.FOO = 'bar';
76
- * dotenvExpand('Hello $FOO'); // "Hello bar"
77
- * dotenvExpand('Hello $BAZ:world'); // "Hello world"
78
- * ```
79
- *
80
- * @remarks
81
- * The expansion is recursive. If a referenced variable itself contains
82
- * references, those will also be expanded until a stable value is reached.
83
- * Escaped references (e.g. `\$FOO`) are preserved as literals.
84
- */
85
- const dotenvExpand = (value, ref = process.env) => {
86
- const result = interpolate(value, ref);
87
- return result ? result.replace(/\\\$/g, '$') : undefined;
88
- };
89
- /**
90
- * Recursively expands environment variables in the values of a JSON object.
91
- * Variables may be presented with optional default as `$VAR[:default]` or
92
- * `${VAR[:default]}`. Unknown variables will expand to an empty string.
93
- *
94
- * @param values - The values object to expand.
95
- * @param options - Expansion options.
96
- * @returns The value object with expanded string values.
97
- *
98
- * @example
99
- * ```ts
100
- * process.env.FOO = 'bar';
101
- * dotenvExpandAll({ A: '$FOO', B: 'x${FOO}y' });
102
- * // => { A: "bar", B: "xbary" }
103
- * ```
104
- *
105
- * @remarks
106
- * Options:
107
- * - ref: The reference object to use for expansion (defaults to process.env).
108
- * - progressive: Whether to progressively add expanded values to the set of
109
- * reference keys.
110
- *
111
- * When `progressive` is true, each expanded key becomes available for
112
- * subsequent expansions in the same object (left-to-right by object key order).
113
- */
114
- const dotenvExpandAll = (values = {}, options = {}) => Object.keys(values).reduce((acc, key) => {
115
- const { ref = process.env, progressive = false } = options;
116
- acc[key] = dotenvExpand(values[key], {
117
- ...ref,
118
- ...(progressive ? acc : {}),
119
- });
120
- return acc;
121
- }, {});
122
-
123
- const applyKv = (current, kv) => {
124
- if (!kv || Object.keys(kv).length === 0)
125
- return current;
126
- const expanded = dotenvExpandAll(kv, { ref: current, progressive: true });
127
- return { ...current, ...expanded };
128
- };
129
- const applyConfigSlice = (current, cfg, env) => {
130
- if (!cfg)
131
- return current;
132
- // kind axis: global then env (env overrides global)
133
- const afterGlobal = applyKv(current, cfg.vars);
134
- const envKv = env && cfg.envVars ? cfg.envVars[env] : undefined;
135
- return applyKv(afterGlobal, envKv);
136
- };
137
- /**
138
- * Overlay config-provided values onto a base ProcessEnv using precedence axes:
139
- * - kind: env \> global
140
- * - privacy: local \> public
141
- * - source: project \> packaged \> base
142
- *
143
- * Programmatic explicit vars (if provided) override all config slices.
144
- * Progressive expansion is applied within each slice.
145
- */
146
- const overlayEnv = ({ base, env, configs, programmaticVars, }) => {
147
- let current = { ...base };
148
- // Source: packaged (public -> local)
149
- current = applyConfigSlice(current, configs.packaged, env);
150
- // Packaged "local" is not expected by policy; if present, honor it.
151
- // We do not have a separate object for packaged.local in sources, keep as-is.
152
- // Source: project (public -> local)
153
- current = applyConfigSlice(current, configs.project?.public, env);
154
- current = applyConfigSlice(current, configs.project?.local, env);
155
- // Programmatic explicit vars (top of static tier)
156
- if (programmaticVars) {
157
- const toApply = Object.fromEntries(Object.entries(programmaticVars).filter(([_k, v]) => typeof v === 'string'));
158
- current = applyKv(current, toApply);
159
- }
160
- return current;
161
- };
162
-
163
- exports.overlayEnv = overlayEnv;
@@ -1,50 +0,0 @@
1
- /**
2
- * A minimal representation of an environment key/value mapping.
3
- * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
4
-
5
- type Scripts = Record<string, string | {
6
- cmd: string;
7
- shell?: string | boolean;
8
- }>;
9
-
10
- type GetDotenvConfigResolved = {
11
- dotenvToken?: string;
12
- privateToken?: string;
13
- paths?: string[];
14
- loadProcess?: boolean;
15
- log?: boolean;
16
- shell?: string | boolean;
17
- scripts?: Scripts;
18
- requiredKeys?: string[];
19
- schema?: unknown;
20
- vars?: Record<string, string>;
21
- envVars?: Record<string, Record<string, string>>;
22
- dynamic?: unknown;
23
- plugins?: Record<string, unknown>;
24
- };
25
-
26
- type OverlayConfigSources = {
27
- packaged?: GetDotenvConfigResolved;
28
- project?: {
29
- public?: GetDotenvConfigResolved;
30
- local?: GetDotenvConfigResolved;
31
- };
32
- };
33
- /**
34
- * Overlay config-provided values onto a base ProcessEnv using precedence axes:
35
- * - kind: env \> global
36
- * - privacy: local \> public
37
- * - source: project \> packaged \> base
38
- *
39
- * Programmatic explicit vars (if provided) override all config slices.
40
- * Progressive expansion is applied within each slice.
41
- */
42
- declare const overlayEnv: ({ base, env, configs, programmaticVars, }: {
43
- base: ProcessEnv;
44
- env: string | undefined;
45
- configs: OverlayConfigSources;
46
- programmaticVars?: ProcessEnv;
47
- }) => ProcessEnv;
48
-
49
- export { overlayEnv };
50
- export type { OverlayConfigSources };
@@ -1,50 +0,0 @@
1
- /**
2
- * A minimal representation of an environment key/value mapping.
3
- * Values may be `undefined` to represent "unset". */ type ProcessEnv = Record<string, string | undefined>;
4
-
5
- type Scripts = Record<string, string | {
6
- cmd: string;
7
- shell?: string | boolean;
8
- }>;
9
-
10
- type GetDotenvConfigResolved = {
11
- dotenvToken?: string;
12
- privateToken?: string;
13
- paths?: string[];
14
- loadProcess?: boolean;
15
- log?: boolean;
16
- shell?: string | boolean;
17
- scripts?: Scripts;
18
- requiredKeys?: string[];
19
- schema?: unknown;
20
- vars?: Record<string, string>;
21
- envVars?: Record<string, Record<string, string>>;
22
- dynamic?: unknown;
23
- plugins?: Record<string, unknown>;
24
- };
25
-
26
- type OverlayConfigSources = {
27
- packaged?: GetDotenvConfigResolved;
28
- project?: {
29
- public?: GetDotenvConfigResolved;
30
- local?: GetDotenvConfigResolved;
31
- };
32
- };
33
- /**
34
- * Overlay config-provided values onto a base ProcessEnv using precedence axes:
35
- * - kind: env \> global
36
- * - privacy: local \> public
37
- * - source: project \> packaged \> base
38
- *
39
- * Programmatic explicit vars (if provided) override all config slices.
40
- * Progressive expansion is applied within each slice.
41
- */
42
- declare const overlayEnv: ({ base, env, configs, programmaticVars, }: {
43
- base: ProcessEnv;
44
- env: string | undefined;
45
- configs: OverlayConfigSources;
46
- programmaticVars?: ProcessEnv;
47
- }) => ProcessEnv;
48
-
49
- export { overlayEnv };
50
- export type { OverlayConfigSources };