@karmaniverous/get-dotenv 6.0.0-0 → 6.0.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 (93) hide show
  1. package/README.md +86 -334
  2. package/dist/cli.d.ts +569 -0
  3. package/dist/cli.mjs +18788 -0
  4. package/dist/cliHost.d.ts +548 -253
  5. package/dist/cliHost.mjs +1990 -1458
  6. package/dist/config.d.ts +192 -14
  7. package/dist/config.mjs +256 -81
  8. package/dist/env-overlay.d.ts +226 -18
  9. package/dist/env-overlay.mjs +181 -22
  10. package/dist/getdotenv.cli.mjs +18166 -3437
  11. package/dist/index.d.ts +729 -136
  12. package/dist/index.mjs +18207 -3457
  13. package/dist/plugins-aws.d.ts +289 -104
  14. package/dist/plugins-aws.mjs +2462 -350
  15. package/dist/plugins-batch.d.ts +355 -105
  16. package/dist/plugins-batch.mjs +2595 -420
  17. package/dist/plugins-cmd.d.ts +287 -118
  18. package/dist/plugins-cmd.mjs +2661 -839
  19. package/dist/plugins-init.d.ts +272 -100
  20. package/dist/plugins-init.mjs +2152 -37
  21. package/dist/plugins.d.ts +323 -140
  22. package/dist/plugins.mjs +18006 -2025
  23. package/dist/templates/cli/index.ts +26 -0
  24. package/dist/templates/cli/plugins/hello.ts +43 -0
  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 +43 -0
  39. package/dist/templates/index.ts +26 -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 +43 -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 +52 -89
  53. package/templates/cli/index.ts +26 -0
  54. package/templates/cli/plugins/hello.ts +43 -0
  55. package/templates/config/js/getdotenv.config.js +9 -4
  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 +17 -5
  59. package/templates/config/yaml/public/getdotenv.config.yaml +0 -3
  60. package/dist/cliHost.cjs +0 -2078
  61. package/dist/cliHost.d.cts +0 -451
  62. package/dist/cliHost.d.mts +0 -451
  63. package/dist/config.cjs +0 -252
  64. package/dist/config.d.cts +0 -55
  65. package/dist/config.d.mts +0 -55
  66. package/dist/env-overlay.cjs +0 -163
  67. package/dist/env-overlay.d.cts +0 -50
  68. package/dist/env-overlay.d.mts +0 -50
  69. package/dist/index.cjs +0 -4077
  70. package/dist/index.d.cts +0 -318
  71. package/dist/index.d.mts +0 -318
  72. package/dist/plugins-aws.cjs +0 -666
  73. package/dist/plugins-aws.d.cts +0 -158
  74. package/dist/plugins-aws.d.mts +0 -158
  75. package/dist/plugins-batch.cjs +0 -658
  76. package/dist/plugins-batch.d.cts +0 -181
  77. package/dist/plugins-batch.d.mts +0 -181
  78. package/dist/plugins-cmd.cjs +0 -1112
  79. package/dist/plugins-cmd.d.cts +0 -178
  80. package/dist/plugins-cmd.d.mts +0 -178
  81. package/dist/plugins-demo.cjs +0 -352
  82. package/dist/plugins-demo.d.cts +0 -158
  83. package/dist/plugins-demo.d.mts +0 -158
  84. package/dist/plugins-demo.d.ts +0 -158
  85. package/dist/plugins-demo.mjs +0 -350
  86. package/dist/plugins-init.cjs +0 -289
  87. package/dist/plugins-init.d.cts +0 -162
  88. package/dist/plugins-init.d.mts +0 -162
  89. package/dist/plugins.cjs +0 -2327
  90. package/dist/plugins.d.cts +0 -211
  91. package/dist/plugins.d.mts +0 -211
  92. package/templates/cli/ts/index.ts +0 -9
  93. package/templates/cli/ts/plugins/hello.ts +0 -17
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 };