@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/README.md CHANGED
@@ -1,87 +1,45 @@
1
- > Load, expand, and compose environment variables from a deterministic dotenv cascade, then execute commands under that context. Use `get-dotenv` as a library, a CLI, or a plugin-first host to build dotenv-aware tooling with cross‑platform shell control, CI‑friendly capture, and clear diagnostics.
1
+ > Load, expand, and compose environment variables from a deterministic dotenv cascade, then execute commands under that context. Use getdotenv as a library, a CLI, or a pluginfirst host to build dotenvaware tooling with cross‑platform shell control, CI‑friendly capture, and clear diagnostics.
2
2
 
3
3
  # get-dotenv
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@karmaniverous/get-dotenv.svg)](https://www.npmjs.com/package/@karmaniverous/get-dotenv)
6
- ![Node Current](https://img.shields.io/node/v/@karmaniverous/get-dotenv) <!-- TYPEDOC_EXCLUDE -->
6
+ ![Node Current](https://img.shields.io/node/v/@karmaniverous/get-dotenv)
7
7
  [![docs](https://img.shields.io/badge/docs-website-blue)](https://docs.karmanivero.us/get-dotenv)
8
- [![changelog](https://img.shields.io/badge/changelog-latest-blue.svg)](https://github.com/karmaniverous/get-dotenv/tree/main/CHANGELOG.md)<!-- /TYPEDOC_EXCLUDE -->
9
- [![license](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](https://github.com/karmaniverous/get-dotenv/tree/main/LICENSE.md)
8
+ [![changelog](https://img.shields.io/badge/changelog-latest-blue.svg)](./CHANGELOG.md)
9
+ [![license](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](./LICENSE)
10
10
 
11
- Load environment variables with a cascade of environment-aware dotenv files. You can:
11
+ get‑dotenv helps you:
12
12
 
13
- Asynchronously load environment variables from multiple dotenv files.
13
+ - Load and merge env vars from a deterministic cascade (global/env × public/private) across multiple paths.
14
+ - Expand values recursively with defaults.
15
+ - Add dynamic variables (JS/TS) that compute from the composed env.
16
+ - Run commands with normalized shell behavior and a consistent child environment.
17
+ - Compose your own CLI from shipped plugins or your own.
14
18
 
15
- Segregate variables into distinct files:
19
+ See full guides:
16
20
 
17
- - Public files (e.g. `.env`, `.env.dev`, `.env.test`) are synced with your git repository.
18
- - Private files (e.g. `.env.local`, `.env.dev.local`, `.env.test.local`) are protected by `.gitignore`.
19
- - Global files (e.g. `.env`, `.env.local`) apply to all environments.
20
- - Env files (e.g. `.env.dev`, `.env.dev.local`, `.env.test`, `.env.test.local`) apply to a specific environment.
21
- - [Dynamic files](#dynamic-processing) (`.env.js`) export logic that dynamically & progressively generates new variables or overrides current ones.
22
-
23
- ✅ Dynamically specify which variables to load by type.
24
-
25
- ✅ Explicitly add variables to the loaded set.
26
-
27
- ✅ Extract the resulting variables to an object, `process.env`, a dotenv file, or a logger object, in any combination.
28
-
29
- ✅ Customize your dotenv file directories & naming patterns.
30
-
31
- ✅ Perform all of the above either programmatically or [from the command line](#command-line-interface), where you can also execute additional commands within the resulting context... including nested `getdotenv` commands that inherit the parent command's settings & context!
32
-
33
- ✅ [Execute batched CLI commands](#batch-command) across multiple working directories, with each command inheriting the `getdotenv` context.
34
-
35
- ✅ Set defaults for all options in a `getdotenv.config.json` file in your project root directory.
36
-
37
- ✅ Validate your final composed environment via config: JSON/YAML `requiredKeys` or a JS/TS Zod `schema`. Validation runs once after Phase C (interpolation). Use `--strict` to fail on issues; otherwise warnings are printed. See the [Config files and overlays](./guides/config.md) guide.
38
-
39
- ✅ Diagnostics for safer visibility without altering runtime values:
40
-
41
- - Redaction at presentation time for secret-like keys (`--redact`, `--redact-pattern`).
42
- - Entropy warnings (on by default) for high-entropy strings; gated by length/printability and tunable via `--entropy-*` flags. See [Config files and overlays](./guides/config.md).
43
-
44
- ✅ Clear tracing and CI-friendly capture:
45
-
46
- - `--trace [keys...]` shows per-key origin (parent | dotenv | unset) before spawning.
47
- - Set `GETDOTENV_STDIO=pipe` or use `--capture` to buffer child stdout/stderr deterministically. See [Shell execution behavior](./guides/shell.md).
48
-
49
- ✅ Cross-platform shells and normalized child environments: defaults to `/bin/bash` on POSIX and `powershell.exe` on Windows; subprocess env is composed once via a unified helper that drops undefineds and normalizes temp/home variables. See [Shell execution behavior](./guides/shell.md).
50
-
51
- ✅ Embed the plugin‑first get‑dotenv host and wire shipped or custom plugins to build your own CLI. See [Authoring Plugins](./guides/authoring/index.md).
52
-
53
- `getdotenv` relies on the excellent [`dotenv`](https://www.npmjs.com/package/dotenv) parser and somewhat improves on [`dotenv-expand`](https://www.npmjs.com/package/dotenv-expand) for recursive variable expansion.
54
-
55
- You can always use `getdotenv` directly on the command line, but its REAL power comes into play when you use it as the foundation of your own CLI. This lets you set defaults globally and configure pre- and post-hooks that mutate your `getdotenv` context and do useful things like grab an AWS session from your dev environment and add it to the command execution context.
56
-
57
- When you plug your own [`commander`](https://www.npmjs.com/package/commander) CLI commands into the `getdotenv` base, they will execute within all of the environmental context created above!
21
+ - [Getting started](./guides/getting-started.md)
22
+ - [Config and overlays](./guides/config.md) (dynamic, validation, defaults):
23
+ - [Shell execution behavior, quoting, capture](./guides/shell.md)
24
+ - [Shipped plugins](./guides/shipped/index.md)
25
+ - [Authoring plugins](./guides/authoring/index.md) (host, lifecycle, exec, diagnostics)
58
26
 
27
+ ## Use Cases
28
+
29
+ - Execute deployment steps across many repositories from one command sequence. See [batch plugin guide](./guides/shipped/batch.md)
30
+ - Run config‑driven, environment‑aware operations with simple CLI commands. See [config guide](./guides/config.md)
31
+ - Compose a rich CLI from shipped and third‑party plugins and share it across projects. See [shipped plugins overview](./guides/shipped/index.md)
32
+ - Drive complex AWS workflows in an authenticated, environment‑aware context. See [aws plugin guide](./guides/shipped/aws.md)
33
+ - Scaffold a project config and a host‑based CLI skeleton in seconds. See [init plugin guide](./guides/shipped/init.md)
34
+ - Batch lint/build/test across a monorepo with deterministic output. See [batch plugin guide](./guides/shipped/batch.md)
35
+ - Run cross‑platform commands in CI with normalized shells and capture. See [shell guide](./guides/shell.md)
36
+ - Programmatically compose env and run tools inside Node scripts. See [Getting started](./guides/getting-started.md)
37
+ - Add observability without leaking secrets using trace, redaction, and entropy warnings. See [diagnostics guide](./guides/authoring/diagnostics.md)
38
+ - Author new plugins with maximum DX and minimal boilerplate. See [authoring plugins guide](./guides/authoring/index.md)
39
+
59
40
  ## Requirements
60
41
 
61
- - Node.js >= 20 (this repository pins 22.19.0 for CI/reproducibility)
62
-
63
- ## Getting Started
64
-
65
- - One‑off CLI with your env: `getdotenv -c 'node -e "console.log(process.env.APP_SETTING ?? \"\")"'` — see [Shell execution behavior](./guides/shell.md) and [cmd plugin](./guides/shipped/cmd.md).
66
- - Programmatic load: `const vars = await getDotenv({ env: 'dev', paths: ['./'] });` — see [Config files and overlays](./guides/config.md).
67
- - Embed a CLI quickly: use [createCli](#cli-embedding-createcli), or wire a [custom host](#custom-host-wire-plugins) to choose plugins.
68
- - Scaffold config and a CLI skeleton: `npx getdotenv init . --config-format json --with-local --cli-name acme` — see [init plugin](./guides/shipped/init.md).
69
-
70
- ## API Reference
71
-
72
- Generated API documentation is hosted at:
73
-
74
- - https://docs.karmanivero.us/get-dotenv
75
-
76
- The site is built with TypeDoc from the source code in this repository.
77
-
78
- ## Testing
79
-
80
- This project uses Vitest with the V8 coverage provider. Run:
81
-
82
- ```bash
83
- npm run test
84
- ```
42
+ - Node.js 20 (this repository pins 22.19.0 for CI/reproducibility)
85
43
 
86
44
  ## Installation
87
45
 
@@ -89,313 +47,107 @@ npm run test
89
47
  npm install @karmaniverous/get-dotenv
90
48
  ```
91
49
 
92
- ## Scaffold
93
-
94
- You can scaffold config files and a host-based CLI skeleton using the built-in init command. Templates are shipped with the package and copied verbatim.
50
+ ## Quick Start
95
51
 
96
- Examples:
52
+ Run a one‑off command with your env (parent alias so flags apply to getdotenv):
97
53
 
98
54
  ```bash
99
- # JSON config + .local variant, and a CLI skeleton named "acme"
100
- npx getdotenv init . \
101
- --config-format json \
102
- --with-local \
103
- --cli-name acme \
104
- --force
55
+ npx @karmaniverous/get-dotenv -c 'node -e "console.log(process.env.APP_SETTING ?? \"\")"'
105
56
  ```
106
57
 
107
- ```bash
108
- # TypeScript config with a dynamic example; CLI named "toolbox"
109
- npx getdotenv init ./apps/toolbox \
110
- --config-format ts \
111
- --cli-name toolbox
112
- ```
113
-
114
- Collision flow (when a destination file exists):
115
-
116
- - Interactive prompt: [o]verwrite, [e]xample, [s]kip, or their “all” variants [O]/[E]/[S].
117
- - Non-interactive detection: Treated as `--yes` (Skip All) unless `--force` is provided (Overwrite All). Considered non-interactive when stdin or stdout is not a TTY OR when a CI-like environment variable is present (`CI`, `GITHUB_ACTIONS`, `BUILDKITE`, `TEAMCITY_VERSION`, `TF_BUILD`).
118
- - Precedence: `--force` > `--yes` > auto-detect (non-interactive => Skip All).
119
- - Options overview:
120
- - `--config-format <json|yaml|js|ts>`
121
- - `--with-local` to generate `.local` alongside public config (JSON/YAML)
122
- - `--cli-name <string>` for token substitution (`__CLI_NAME__`) in the CLI skeleton
123
- - `--force` to overwrite all; `--yes` to skip all
124
-
125
- Notes:
58
+ Load programmatically:
126
59
 
127
- - Templates are shipped with the package and copied verbatim.
128
- - The CLI skeleton replaces `__CLI_NAME__` tokens with your chosen name.
129
-
130
- ## Usage
131
-
132
- ```js
60
+ ```ts
133
61
  import { getDotenv } from '@karmaniverous/get-dotenv';
134
62
 
135
- const dotenv = await getDotenv(options);
63
+ const vars = await getDotenv({ env: 'dev', paths: ['./'] });
64
+ console.log(vars.APP_SETTING);
136
65
  ```
137
66
 
138
- Options can be passed programmatically or set in a `getdotenv.config.json` file in your project root directory. The same file also sets default options for the `getdotenv` CLI or any child CLI you spawn from it.
139
-
140
- See [Config files and overlays](./guides/config.md) for how to author defaults, overlays, validation, and diagnostics in JSON/YAML/JS/TS.
141
-
142
- ## CLI embedding (createCli)
143
-
144
- Prefer the named factory when you want to embed the get‑dotenv CLI in your own tool. It wires the plugin‑first host with the included plugins and returns a small runner.
67
+ Embed a CLI quickly (shipped plugins wired for you):
145
68
 
146
69
  ```ts
147
70
  #!/usr/bin/env node
148
- import { createCli } from '@karmaniverous/get-dotenv';
149
-
150
- // Build a CLI and run with your argv; alias appears in help.
151
- await createCli({
152
- alias: 'mycli',
153
- // Optional: override the help header (otherwise “mycli v<version>” is used).
154
- branding: 'mycli v1.2.3',
155
- }).run(process.argv.slice(2));
156
- ```
157
-
158
- Notes:
159
-
160
- - The host resolves dotenv context once per invocation and exposes subcommands: cmd, batch, aws, and init (see Guides below).
161
- - Use `--trace [keys...]` and `--redact` for diagnostics without altering runtime values.
162
- - Default shells are normalized across platforms: `/bin/bash` on POSIX and `powershell.exe` on Windows (overridable per‑script or globally).
163
- - Help/exit behavior (important for embedding and tests):
164
- - To keep `-h/--help` deterministic across ESM/CJS and avoid Commander’s default `process.exit`, `createCli().run(['-h'])` prints help and returns without exiting the process.
165
- - Because help is printed before the internal `brand()` call runs, the optional branding header may be omitted when `-h/--help` is used at the top level. If you need a branded header, prefer `mycli help` (which runs through normal parsing) or construct and brand a host directly (see “Branding the host CLI” in Guides).
166
- - Interop matrix (embedding in different module systems):
167
- - ESM dynamic:
168
- ```ts
169
- const { createCli } = await import('@karmaniverous/get-dotenv');
170
- await createCli({ alias: 'mycli' }).run(['-h']);
171
- ```
172
- - CommonJS require (using built outputs for smoke checks):
173
- ```js
174
- const { createCli } = require('@karmaniverous/get-dotenv/dist/index.cjs');
175
- createCli({ alias: 'mycli' }).run(['-h']);
176
- ```
177
-
178
- ### Custom host (wire plugins)
179
-
180
- When you want full control over the command surface, construct a host directly and choose which plugins to install. This example omits the demo plugin by default and shows where to add your own:
71
+ import { createCli } from '@karmaniverous/get-dotenv/cli';
181
72
 
182
- ```ts
183
- #!/usr/bin/env node
184
- import type { Command } from 'commander';
185
- import { GetDotenvCli } from '@karmaniverous/get-dotenv/cliHost';
186
- import {
187
- cmdPlugin,
188
- batchPlugin,
189
- awsPlugin,
190
- initPlugin,
191
- } from '@karmaniverous/get-dotenv/plugins';
192
- // import { demoPlugin } from '@karmaniverous/get-dotenv/plugins/demo'; // optional
193
- // import { helloPlugin } from './plugins/hello'; // your plugin
194
-
195
- const program: Command = new GetDotenvCli('mycli');
196
- await (program as unknown as GetDotenvCli).brand({
197
- importMetaUrl: import.meta.url,
198
- description: 'mycli',
199
- });
200
-
201
- program
202
- .attachRootOptions({ loadProcess: false })
203
- .use(cmdPlugin({ asDefault: true, optionAlias: '-c, --cmd <command...>' }))
204
- .use(batchPlugin())
205
- .use(awsPlugin())
206
- .use(initPlugin())
207
- // .use(demoPlugin()) // omit demo by default
208
- // .use(helloPlugin()) // add your own plugin(s)
209
- .passOptions({ loadProcess: false });
210
-
211
- await program.parseAsync();
73
+ await createCli({ alias: 'toolbox' }).run(process.argv.slice(2));
212
74
  ```
213
75
 
214
- Notes:
215
-
216
- - Root flags come from `attachRootOptions()`. `passOptions()` merges flags (parent < current), resolves dotenv context once, validates, and persists the merged options bag for nested flows.
217
- - See [Authoring Plugins → Lifecycle & Wiring](./guides/authoring/lifecycle.md) for a deeper walk‑through and best practices.
76
+ More first steps and tips at [Getting Started](./guides/getting-started.md)
218
77
 
219
- ## Dynamic Processing
78
+ ## Configuration & overlays
220
79
 
221
- This package supports the full [`dotenv-expand`](https://www.npmjs.com/package/dotenv-expand) syntax, with some internal performance improvements. Dynamic variables can be authored in JS or TS.
222
-
223
- Use the `dynamicPath` option to add a relative path to a Javascript module with a default export like this:
224
-
225
- ```js
226
- export default {
227
- SOME_DYNAMIC_VARIABLE: (dotenv) => someLogic(dotenv),
228
- ANOTHER_DYNAMIC_VARIABLE: (dotenv) =>
229
- someOtherLogic(dotenv.SOME_DYNAMIC_VARIABLE),
230
- ONE_MORE_TIME: ({ DESTRUCTURED_VARIABLE, ANOTHER_DYNAMIC_VARIABLE }) =>
231
- DESTRUCTURED_VARIABLE + ANOTHER_DYNAMIC_VARIABLE,
232
- };
233
- ```
80
+ Author config in JSON/YAML/JS/TS at your project root. The loader is always on in the shipped host:
234
81
 
235
- If the value corresponding to a key is a function, it will be executed with the current state of `dotenv` as its single argument and the result applied back to the `dotenv` object. Otherwise, the value will just be applied back to `dotenv`. (Although if you're going to do that then you might as well just create a public global variable in the first place.)
82
+ - Data: `vars` (global), `envVars` (per‑env)
83
+ - Root defaults and visibility for CLI flags: `rootOptionDefaults`, `rootOptionVisibility`
84
+ - Optional scripts table: `scripts`
85
+ - Dynamic (JS/TS only): `dynamic`
86
+ - Validation (JS/TS schema or required keys): `schema`, `requiredKeys`
236
87
 
237
- Since keys will be evaluated progressively, each successive key function will have access to any previous ones. These keys can also override existing variables.
88
+ Overlays apply by kind/env/privacy/source with clear precedence. Details and examples in the [Config guide](./guides/config.md).
238
89
 
239
- ### TypeScript-first dynamic processing
90
+ ## Dynamic variables (JS/TS)
240
91
 
241
- You can write your dynamic module in TypeScript and point `dynamicPath` at a `.ts` file. Install [`esbuild`](https://esbuild.github.io/) as a dev dependency to enable automatic compilation:
92
+ Add dynamic keys that compute from the composed env. Programmatic or file‑based (JS/TS). For TypeScript, install `esbuild` for auto‑compile.
242
93
 
243
94
  ```ts
244
95
  // dynamic.ts
245
96
  export default {
246
- MY_DYNAMIC: ({ APP_SETTING = '' }) => `${APP_SETTING}-ts`,
97
+ GREETING: ({ APP_SETTING = '' }) => `Hello ${APP_SETTING}`,
247
98
  };
248
99
  ```
249
100
 
250
- If `esbuild` is not installed and a direct import fails, `get-dotenv` attempts a simple fallback for single-file `.ts` modules without imports; otherwise it will throw with clear guidance to install `esbuild`.
251
-
252
- Programmatic users can skip files entirely and pass dynamic variables directly:
253
-
254
- ```ts
255
- import { getDotenv, defineDynamic } from '@karmaniverous/get-dotenv';
256
-
257
- const dynamic = defineDynamic({
258
- MY_DYNAMIC(vars, env) {
259
- return `${vars.APP_SETTING}-${env ?? ''}`;
260
- },
261
- });
262
-
263
- const vars = await getDotenv({ dynamic, paths: ['./'], env: 'dev' });
264
- ```
265
-
266
- Notes:
267
-
268
- - Programmatic `dynamic` takes precedence over `dynamicPath` when both are provided.
269
- - Dynamic keys are evaluated progressively, so later keys can reference earlier results.
270
-
271
- #### Troubleshooting
272
-
273
- - “Unknown file extension '.ts'” when loading `dynamic.ts`:
274
- - Install `esbuild` (`npm i -D esbuild`).
275
-
276
- - “Unable to load dynamic TypeScript file …”:
277
- - Install `esbuild`. A simple transpile fallback exists only for trivial single-file modules; any imports in `dynamic.ts` require `esbuild` bundling.
278
-
279
- ## Command Line Interface
280
-
281
- You can also use `getdotenv` from the command line. For a concise overview run `getdotenv -h`, and see the shipped plugin pages for details: [cmd](./guides/shipped/cmd.md), [batch](./guides/shipped/batch.md), [aws](./guides/shipped/aws.md), and [init](./guides/shipped/init.md). For quoting and default shell behavior, see [Shell execution behavior](./guides/shell.md).
282
-
283
- ### Default shell behavior
284
-
285
- To normalize behavior across platforms, the CLI resolves a default shell when `--shell` is true or omitted:
286
-
287
- - POSIX: `/bin/bash`
288
- - Windows: `powershell.exe`
289
-
290
- ### Batch Command
291
-
292
- The `getdotenv` base CLI includes one very useful subcommand: `batch`.
293
-
294
- This command lets you execute a shell command across multiple working directories. Executions occur within the loaded `dotenv` context. Might not be relevant to your specific use case, but when you need it, it's a game-changer!
295
-
296
- My most common use case for this command is a microservice project where release day finds me updating dependencies & performing a release in well over a dozen very similar repositories. The sequence of steps in each case is exactly the same, but I need to respond individually as issues arise, so scripting the whole thing out would fail more often than it would work.
297
-
298
- I use the `batch` command to perform each step across all repositories at once. Once you get used to it, it feels like a superpower!
299
-
300
- Lest you doubt what that kind of leverage can do for you, consider this:
301
-
302
- [![batch superpower in action](./assets/contributions.png)](https://github.com/karmaniverous)
303
-
304
- ```bash
305
- > getdotenv batch -h
306
-
307
- # Usage: getdotenv batch [options] [command]
308
- #
309
- # Batch command execution across multiple working directories.
310
- #
311
- # Options:
312
- # -p, --pkg-cwd use nearest package directory as current working directory
313
- # -r, --root-path <string> path to batch root directory from current working directory (default: "./")
314
- # -g, --globs <string> space-delimited globs from root path (default: "*")
315
- # -c, --command <string> command executed according to the base --shell option, conflicts with cmd subcommand (dotenv-expanded)
316
- # -l, --list list working directories without executing command
317
- # -e, --ignore-errors ignore errors and continue with next path
318
- # -h, --help display help for command
319
- #
320
- # Commands:
321
- # cmd execute command, conflicts with --command option (default subcommand)
322
- # help [command] display help for command
323
- ```
324
-
325
- Note that `batch` executes its commands in sequence, rather than in parallel!
326
-
327
- To understand why, imagine running `npm install` in a dozen repos from the same command line. The visual feedback would be impossible to follow, and if something broke you'd have a really hard time figuring out why.
328
-
329
- Instead, everything runs in sequence, and you get a clear record of exactly what happened and where. Also worth noting that many complex processes are resource hogs: you would not _want_ to run a dozen Serverless deployments at once!
101
+ Learn more in the [Config guide formats section](./guides/config.md#formats).
330
102
 
331
- Meanwhile, [this issue](https://github.com/karmaniverous/get-dotenv/issues/7) documents the parallel-processing option requirement. Feel free to submit a PR!
103
+ ## CLI basics
332
104
 
333
- ---
105
+ The shipped CLI is plugin‑first:
334
106
 
335
- ### Authoring npm scripts and the `-c`/`--cmd` alias
107
+ - Execute commands within your dotenv context using the `cmd` subcommand or the parent alias:
108
+ - `getdotenv cmd ...` or `getdotenv -c 'echo $APP_SETTING'`
109
+ - Quoting, alias conflicts, expansion behavior. [More info...](./guides/shipped/cmd.md)
110
+ - Normalize shell behavior across platforms; use `--shell` (default OS shell) or `--shell-off`, and enable capture for CI:
111
+ - [Shell guide](./guides/shell.md)
112
+ - Execute across multiple working directories with the [`batch` plugin][guides/shipped/batch.md](./guides/shipped/batch.md)
336
113
 
337
- When you run commands via `npm run`, flags after `--` are forwarded to your script and may be applied to the inner shell command instead of `getdotenv` unless you structure your script carefully.
114
+ ## Diagnostics (trace, capture, redact, entropy)
338
115
 
339
- - Anti-pattern:
116
+ - `--trace [keys...]` prints per‑key origin (dotenv | parent | unset) before spawning.
117
+ - Deterministic output for CI: set `GETDOTENV_STDIO=pipe` or pass `--capture`.
118
+ - Presentation‑time redaction for secret‑like keys: `--redact` / `--redact-off` (+ `--redact-pattern` for additional key matches).
119
+ - Optional entropy warnings (length/printable/threshold gated) for likely secrets in logs/trace.
340
120
 
341
- ```json
342
- { "scripts": { "script": "getdotenv echo $APP_SETTING" } }
343
- ```
121
+ Learn more:
344
122
 
345
- Then `npm run script -- -e dev` applies `-e` to `echo`, not to `getdotenv`.
123
+ - [Shell & capture](./guides/shell.md)
124
+ - [Authoring diagnostics](./guides/authoring/diagnostics.md) (redaction & entropy)
346
125
 
347
- - Recommended:
348
- ```json
349
- { "scripts": { "script": "getdotenv -c 'echo $APP_SETTING'" } }
350
- ```
351
- Now `npm run script -- -e dev` applies `-e` to `getdotenv`, which loads and expands variables before executing the inner command.
126
+ ## Shipped plugins
352
127
 
353
- Notes:
128
+ - [cmd](./guides/shipped/cmd.md) — execute a command (with parent alias)
129
+ - [batch](./guides/shipped/batch.md) — run a command across multiple working directories
130
+ - [aws](./guides/shipped/aws.md) — establish a session and optionally forward to AWS CLI
131
+ - [init](./guides/shipped/init.md) — scaffold config files and a host‑based CLI skeleton
354
132
 
355
- - `-c`/`--cmd` is an alias of the `cmd` subcommand; do not use both in a single invocation.
356
- - On POSIX shells, prefer single quotes to prevent the outer shell from expanding `$VAR` before Node sees it. On PowerShell, single quotes are also literal.
357
- - Script-level shell overrides (`scripts[name].shell`) still take precedence over the global `--shell`.
133
+ Also see the [shipped plugins overview](./guides/shipped/index.md).
358
134
 
359
- Important:
135
+ ## Authoring your own CLI & plugins
360
136
 
361
- - When using the parent alias `--cmd` with a Node eval payload, quote the entire payload as a single token so Commander does not treat `-e/--eval` as getdotenv’s `-e, --env` flag.
362
- - POSIX example:
363
- ```
364
- getdotenv --cmd 'node -e "console.log(process.env.APP_SETTING ?? \"\")"'
365
- ```
366
- - PowerShell example (single quotes are literal in PowerShell):
367
- ```
368
- getdotenv --cmd 'node -e "console.log(process.env.APP_SETTING ?? \"\")"'
369
- ```
370
- - If you do not need to pass additional parent flags after the command, you can prefer the subcommand form instead:
371
- ```
372
- getdotenv --shell-off cmd node -e "console.log(process.env.APP_SETTING ?? '')"
373
- ```
137
+ The host resolves dotenv context once per invocation, overlays config, validates, and then runs plugins with a typed options bag.
374
138
 
375
- Diagnostics and CI capture:
139
+ - [Lifecycle & wiring](./guides/authoring/lifecycle.md)
140
+ - [Executing shell commands](./guides/authoring/exec.md) from plugins
141
+ - [Config & validation](./guides/authoring/config.md) for plugins
376
142
 
377
- - To capture child stdout/stderr deterministically (e.g., in CI), either set the environment variable `GETDOTENV_STDIO=pipe` or pass `--capture`. Outputs are buffered and re-emitted after completion.
378
- - For debugging environment composition, use:
379
- ```
380
- getdotenv --trace [keys...] cmd node -e "0"
381
- ```
382
- When provided without keys, `--trace` emits a concise origin line for every key (parent | dotenv | unset) to stderr before the child process launches.
143
+ ## API Reference
383
144
 
384
- ---
145
+ [Typed API docs](https://docs.karmanivero.us/get-dotenv) are built with TypeDoc.
385
146
 
386
- ## Guides
147
+ ## Changelog
387
148
 
388
- - [Cascade and precedence](./guides/cascade.md) - How variables load and merge across
389
- paths and public/private/env axes.
390
- - [Shell execution behavior](./guides/shell.md) - How commands run cross‑platform;
391
- quoting rules, default shells, and capture tips.
392
- - [Config files and overlays](./guides/config.md) - Author JSON/YAML/JS/TS config and
393
- apply privacy/source overlays (always‑on).
394
- - [Authoring Plugins](./guides/authoring/index.md) - Compose CLIs with once‑per‑invoke dotenv context and plugin lifecycles.
395
- - [Shipped Plugins](./guides/shipped/index.md) - The get‑dotenv host ships a small set of plugins that cover needs.
149
+ See [CHANGELOG.md](./CHANGELOG.md)
396
150
 
397
- Note: Dynamic option descriptions and help‑time default labels are documented under [Authoring Plugins → Lifecycle](./guides/authoring/lifecycle.md) (dynamicOption), [Config files and overlays](./guides/config.md) (plugin config), and [Shell execution behavior](./guides/shell.md) (dynamic defaults).
398
-
399
- The guides are also included in the [hosted API docs](https://docs.karmanivero.us/get-dotenv).
151
+ ## License
400
152
 
401
- See more great templates & tools on [my GitHub Profile](https://github.com/karmaniverous)!
153
+ BSD‑3‑Clause see [LICENSE](./LICENSE)