@karmaniverous/get-dotenv 5.2.6 → 6.0.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.
- package/README.md +63 -67
- package/dist/cliHost.cjs +474 -271
- package/dist/cliHost.d.cts +45 -3
- package/dist/cliHost.d.mts +45 -3
- package/dist/cliHost.d.ts +45 -3
- package/dist/cliHost.mjs +474 -271
- package/dist/getdotenv.cli.mjs +713 -499
- package/dist/index.cjs +629 -692
- package/dist/index.d.cts +1 -140
- package/dist/index.d.mts +1 -140
- package/dist/index.d.ts +1 -140
- package/dist/index.mjs +630 -692
- package/dist/plugins-aws.cjs +0 -1
- package/dist/plugins-aws.mjs +0 -1
- package/dist/plugins-batch.cjs +53 -11
- package/dist/plugins-batch.d.cts +2 -1
- package/dist/plugins-batch.d.mts +2 -1
- package/dist/plugins-batch.d.ts +2 -1
- package/dist/plugins-batch.mjs +53 -11
- package/dist/plugins-cmd.cjs +3 -4
- package/dist/plugins-cmd.mjs +3 -4
- package/dist/plugins-demo.cjs +52 -7
- package/dist/plugins-demo.mjs +52 -7
- package/dist/plugins.cjs +66 -22
- package/dist/plugins.d.cts +2 -1
- package/dist/plugins.d.mts +2 -1
- package/dist/plugins.d.ts +2 -1
- package/dist/plugins.mjs +66 -22
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ Load environment variables with a cascade of environment-aware dotenv files. You
|
|
|
48
48
|
|
|
49
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
50
|
|
|
51
|
-
✅
|
|
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
52
|
|
|
53
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
54
|
|
|
@@ -60,6 +60,13 @@ When you plug your own [`commander`](https://www.npmjs.com/package/commander) CL
|
|
|
60
60
|
|
|
61
61
|
- Node.js >= 20 (this repository pins 22.19.0 for CI/reproducibility)
|
|
62
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
|
+
|
|
63
70
|
## API Reference
|
|
64
71
|
|
|
65
72
|
Generated API documentation is hosted at:
|
|
@@ -130,7 +137,7 @@ const dotenv = await getDotenv(options);
|
|
|
130
137
|
|
|
131
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.
|
|
132
139
|
|
|
133
|
-
See
|
|
140
|
+
See [Config files and overlays](./guides/config.md) for how to author defaults, overlays, validation, and diagnostics in JSON/YAML/JS/TS.
|
|
134
141
|
|
|
135
142
|
## CLI embedding (createCli)
|
|
136
143
|
|
|
@@ -168,6 +175,47 @@ Notes:
|
|
|
168
175
|
createCli({ alias: 'mycli' }).run(['-h']);
|
|
169
176
|
```
|
|
170
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:
|
|
181
|
+
|
|
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();
|
|
212
|
+
```
|
|
213
|
+
|
|
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.
|
|
218
|
+
|
|
171
219
|
## Dynamic Processing
|
|
172
220
|
|
|
173
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.
|
|
@@ -199,7 +247,7 @@ export default {
|
|
|
199
247
|
};
|
|
200
248
|
```
|
|
201
249
|
|
|
202
|
-
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`.
|
|
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`.
|
|
203
251
|
|
|
204
252
|
Programmatic users can skip files entirely and pass dynamic variables directly:
|
|
205
253
|
|
|
@@ -230,57 +278,7 @@ Notes:
|
|
|
230
278
|
|
|
231
279
|
## Command Line Interface
|
|
232
280
|
|
|
233
|
-
You can also use `getdotenv` from the command line:
|
|
234
|
-
|
|
235
|
-
```bash
|
|
236
|
-
> npx getdotenv -h
|
|
237
|
-
|
|
238
|
-
# Usage: getdotenv [options] [command]
|
|
239
|
-
#
|
|
240
|
-
# Base CLI.
|
|
241
|
-
#
|
|
242
|
-
# Options:
|
|
243
|
-
# -e, --env <string> target environment (dotenv-expanded)
|
|
244
|
-
# -v, --vars <string> extra variables expressed as delimited key-value pairs (dotenv-expanded): KEY1=VAL1 KEY2=VAL2
|
|
245
|
-
# -o, --output-path <string> consolidated output file (dotenv-expanded)
|
|
246
|
-
# -s, --shell [string] command execution shell, no argument for default OS shell or provide shell string (default OS shell)
|
|
247
|
-
# -S, --shell-off command execution shell OFF
|
|
248
|
-
# -p, --load-process load variables to process.env ON (default)
|
|
249
|
-
# -P, --load-process-off load variables to process.env OFF
|
|
250
|
-
# -a, --exclude-all exclude all dotenv variables from loading ON
|
|
251
|
-
# -A, --exclude-all-off exclude all dotenv variables from loading OFF (default)
|
|
252
|
-
# -z, --exclude-dynamic exclude dynamic dotenv variables from loading ON
|
|
253
|
-
# -Z, --exclude-dynamic-off exclude dynamic dotenv variables from loading OFF (default)
|
|
254
|
-
# -n, --exclude-env exclude environment-specific dotenv variables from loading
|
|
255
|
-
# -N, --exclude-env-off exclude environment-specific dotenv variables from loading OFF (default)
|
|
256
|
-
# -g, --exclude-global exclude global dotenv variables from loading ON
|
|
257
|
-
# -G, --exclude-global-off exclude global dotenv variables from loading OFF (default)
|
|
258
|
-
# -r, --exclude-private exclude private dotenv variables from loading ON
|
|
259
|
-
# -R, --exclude-private-off exclude private dotenv variables from loading OFF (default)
|
|
260
|
-
# -u, --exclude-public exclude public dotenv variables from loading ON
|
|
261
|
-
# -U, --exclude-public-off exclude public dotenv variables from loading OFF (default)
|
|
262
|
-
# -l, --log console log loaded variables ON
|
|
263
|
-
# -L, --log-off console log loaded variables OFF (default)
|
|
264
|
-
# -d, --debug debug mode ON
|
|
265
|
-
# -D, --debug-off debug mode OFF (default)
|
|
266
|
-
# --default-env <string> default target environment
|
|
267
|
-
# --dotenv-token <string> dotenv-expanded token indicating a dotenv file (default: ".env")
|
|
268
|
-
# --dynamic-path <string> dynamic variables path (.js or .ts; .ts is auto-compiled when esbuild is available, otherwise precompile)
|
|
269
|
-
# --paths <string> dotenv-expanded delimited list of paths to dotenv directory (default: "./")
|
|
270
|
-
# --paths-delimiter <string> paths delimiter string (default: " ")
|
|
271
|
-
# --paths-delimiter-pattern <string> paths delimiter regex pattern
|
|
272
|
-
# --private-token <string> dotenv-expanded token indicating private variables (default: "local")
|
|
273
|
-
# --vars-delimiter <string> vars delimiter string (default: " ")
|
|
274
|
-
# --vars-delimiter-pattern <string> vars delimiter regex pattern
|
|
275
|
-
# --vars-assignor <string> vars assignment operator string (default: "=")
|
|
276
|
-
# --vars-assignor-pattern <string> vars assignment operator regex pattern
|
|
277
|
-
# -h, --help display help for command
|
|
278
|
-
#
|
|
279
|
-
# Commands:
|
|
280
|
-
# batch [options] Batch shell commands across multiple working directories.
|
|
281
|
-
# cmd Execute command according to the --shell option, conflicts with --command option (default command)
|
|
282
|
-
# help [command] display help for command
|
|
283
|
-
```
|
|
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).
|
|
284
282
|
|
|
285
283
|
### Default shell behavior
|
|
286
284
|
|
|
@@ -387,19 +385,17 @@ Diagnostics and CI capture:
|
|
|
387
385
|
|
|
388
386
|
## Guides
|
|
389
387
|
|
|
390
|
-
- [Cascade and precedence](./guides/cascade.md)
|
|
391
|
-
|
|
392
|
-
- [
|
|
393
|
-
|
|
394
|
-
|
|
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.
|
|
396
|
+
|
|
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
|
+
|
|
395
399
|
The guides are also included in the [hosted API docs](https://docs.karmanivero.us/get-dotenv).
|
|
396
400
|
|
|
397
|
-
## Generated CLI
|
|
398
|
-
|
|
399
|
-
This package still supports generating a standalone CLI for your projects. For most use cases we recommend the new plugin-first host because it resolves dotenv context once per invocation, supports composable plugins, and provides better subprocess control and diagnostics. If you prefer a thin, fixed command surface with defaults baked into config, the generated CLI can be a good fit.
|
|
400
|
-
|
|
401
|
-
See the [Generated CLI guide](https://docs.karmanivero.us/get-dotenv/guides/generated-cli) for details
|
|
402
|
-
|
|
403
|
-
---
|
|
404
|
-
|
|
405
401
|
See more great templates & tools on [my GitHub Profile](https://github.com/karmaniverous)!
|