@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.
- package/README.md +106 -70
- package/dist/cliHost.d.ts +232 -226
- package/dist/cliHost.mjs +777 -545
- package/dist/config.d.ts +7 -2
- package/dist/env-overlay.d.ts +21 -9
- package/dist/env-overlay.mjs +14 -19
- package/dist/getdotenv.cli.mjs +1366 -1163
- package/dist/index.d.ts +415 -242
- package/dist/index.mjs +1364 -1414
- package/dist/plugins-aws.d.ts +149 -94
- package/dist/plugins-aws.mjs +307 -195
- package/dist/plugins-batch.d.ts +153 -99
- package/dist/plugins-batch.mjs +277 -95
- package/dist/plugins-cmd.d.ts +140 -94
- package/dist/plugins-cmd.mjs +636 -502
- package/dist/plugins-demo.d.ts +140 -94
- package/dist/plugins-demo.mjs +237 -46
- package/dist/plugins-init.d.ts +140 -94
- package/dist/plugins-init.mjs +129 -12
- package/dist/plugins.d.ts +166 -103
- package/dist/plugins.mjs +977 -840
- package/package.json +15 -53
- package/templates/cli/ts/plugins/hello.ts +27 -6
- package/templates/config/js/getdotenv.config.js +1 -1
- package/templates/config/ts/getdotenv.config.ts +9 -2
- package/dist/cliHost.cjs +0 -1875
- package/dist/cliHost.d.cts +0 -409
- package/dist/cliHost.d.mts +0 -409
- package/dist/config.cjs +0 -252
- package/dist/config.d.cts +0 -55
- package/dist/config.d.mts +0 -55
- package/dist/env-overlay.cjs +0 -163
- package/dist/env-overlay.d.cts +0 -50
- package/dist/env-overlay.d.mts +0 -50
- package/dist/index.cjs +0 -4140
- package/dist/index.d.cts +0 -457
- package/dist/index.d.mts +0 -457
- package/dist/plugins-aws.cjs +0 -667
- package/dist/plugins-aws.d.cts +0 -158
- package/dist/plugins-aws.d.mts +0 -158
- package/dist/plugins-batch.cjs +0 -616
- package/dist/plugins-batch.d.cts +0 -180
- package/dist/plugins-batch.d.mts +0 -180
- package/dist/plugins-cmd.cjs +0 -1113
- package/dist/plugins-cmd.d.cts +0 -178
- package/dist/plugins-cmd.d.mts +0 -178
- package/dist/plugins-demo.cjs +0 -307
- package/dist/plugins-demo.d.cts +0 -158
- package/dist/plugins-demo.d.mts +0 -158
- package/dist/plugins-init.cjs +0 -289
- package/dist/plugins-init.d.cts +0 -162
- package/dist/plugins-init.d.mts +0 -162
- package/dist/plugins.cjs +0 -2283
- package/dist/plugins.d.cts +0 -210
- package/dist/plugins.d.mts +0 -210
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,13 +60,45 @@ 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
|
-
##
|
|
63
|
+
## Quick Start
|
|
64
|
+
|
|
65
|
+
- Zero‑install one‑off command with your env (POSIX):
|
|
64
66
|
|
|
65
|
-
|
|
67
|
+
```
|
|
68
|
+
npx @karmaniverous/get-dotenv -c 'node -e "console.log(process.env.APP_SETTING ?? \"\")"'
|
|
69
|
+
```
|
|
66
70
|
|
|
67
|
-
|
|
71
|
+
Windows/PowerShell:
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
npx @karmaniverous/get-dotenv -c 'node -e "console.log(process.env.APP_SETTING ?? \"\")"'
|
|
75
|
+
```
|
|
68
76
|
|
|
69
|
-
|
|
77
|
+
- Scaffold config and a CLI skeleton (JSON config + .local + CLI “acme”):
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
npx @karmaniverous/get-dotenv init . \
|
|
81
|
+
--config-format json \
|
|
82
|
+
--with-local \
|
|
83
|
+
--cli-name acme \
|
|
84
|
+
--force
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
- Install (for programmatic use and local scripts):
|
|
88
|
+
```
|
|
89
|
+
npm install @karmaniverous/get-dotenv
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Getting Started
|
|
93
|
+
|
|
94
|
+
- One‑off CLI with your env: `npx @karmaniverous/get-dotenv -c 'node -e "console.log(process.env.APP_SETTING ?? \"\")"'` — see [Shell execution behavior](./guides/shell.md) and [cmd plugin](./guides/shipped/cmd.md).
|
|
95
|
+
- Programmatic load: `const vars = await getDotenv({ env: 'dev', paths: ['./'] });` — see [Config files and overlays](./guides/config.md).
|
|
96
|
+
- Embed a CLI quickly: use [createCli](#cli-embedding-createcli), or wire a [custom host](#custom-host-wire-plugins) to choose plugins.
|
|
97
|
+
- Scaffold config and a CLI skeleton: `npx @karmaniverous/get-dotenv init . --config-format json --with-local --cli-name acme` — see [init plugin](./guides/shipped/init.md).
|
|
98
|
+
|
|
99
|
+
## API Reference
|
|
100
|
+
|
|
101
|
+
[API documentation](https://docs.karmanivero.us/get-dotenv) is built with TypeDoc from the source code in this repository.
|
|
70
102
|
|
|
71
103
|
## Testing
|
|
72
104
|
|
|
@@ -90,7 +122,7 @@ Examples:
|
|
|
90
122
|
|
|
91
123
|
```bash
|
|
92
124
|
# JSON config + .local variant, and a CLI skeleton named "acme"
|
|
93
|
-
npx
|
|
125
|
+
npx @karmaniverous/get-dotenv init . \
|
|
94
126
|
--config-format json \
|
|
95
127
|
--with-local \
|
|
96
128
|
--cli-name acme \
|
|
@@ -99,7 +131,7 @@ npx getdotenv init . \
|
|
|
99
131
|
|
|
100
132
|
```bash
|
|
101
133
|
# TypeScript config with a dynamic example; CLI named "toolbox"
|
|
102
|
-
npx
|
|
134
|
+
npx @karmaniverous/get-dotenv init ./apps/toolbox \
|
|
103
135
|
--config-format ts \
|
|
104
136
|
--cli-name toolbox
|
|
105
137
|
```
|
|
@@ -130,7 +162,7 @@ const dotenv = await getDotenv(options);
|
|
|
130
162
|
|
|
131
163
|
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
164
|
|
|
133
|
-
See
|
|
165
|
+
See [Config files and overlays](./guides/config.md) for how to author defaults, overlays, validation, and diagnostics in JSON/YAML/JS/TS.
|
|
134
166
|
|
|
135
167
|
## CLI embedding (createCli)
|
|
136
168
|
|
|
@@ -168,6 +200,47 @@ Notes:
|
|
|
168
200
|
createCli({ alias: 'mycli' }).run(['-h']);
|
|
169
201
|
```
|
|
170
202
|
|
|
203
|
+
### Custom host (wire plugins)
|
|
204
|
+
|
|
205
|
+
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:
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
#!/usr/bin/env node
|
|
209
|
+
import type { Command } from 'commander';
|
|
210
|
+
import { GetDotenvCli } from '@karmaniverous/get-dotenv/cliHost';
|
|
211
|
+
import {
|
|
212
|
+
cmdPlugin,
|
|
213
|
+
batchPlugin,
|
|
214
|
+
awsPlugin,
|
|
215
|
+
initPlugin,
|
|
216
|
+
} from '@karmaniverous/get-dotenv/plugins';
|
|
217
|
+
// import { demoPlugin } from '@karmaniverous/get-dotenv/plugins/demo'; // optional
|
|
218
|
+
// import { helloPlugin } from './plugins/hello'; // your plugin
|
|
219
|
+
|
|
220
|
+
const program: Command = new GetDotenvCli('mycli');
|
|
221
|
+
await (program as unknown as GetDotenvCli).brand({
|
|
222
|
+
importMetaUrl: import.meta.url,
|
|
223
|
+
description: 'mycli',
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
program
|
|
227
|
+
.attachRootOptions({ loadProcess: false })
|
|
228
|
+
.use(cmdPlugin({ asDefault: true, optionAlias: '-c, --cmd <command...>' }))
|
|
229
|
+
.use(batchPlugin())
|
|
230
|
+
.use(awsPlugin())
|
|
231
|
+
.use(initPlugin())
|
|
232
|
+
// .use(demoPlugin()) // omit demo by default
|
|
233
|
+
// .use(helloPlugin()) // add your own plugin(s)
|
|
234
|
+
.passOptions({ loadProcess: false });
|
|
235
|
+
|
|
236
|
+
await program.parseAsync();
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Notes:
|
|
240
|
+
|
|
241
|
+
- Root flags come from `attachRootOptions()`. `passOptions()` merges flags (parent < current), resolves dotenv context once, validates, and persists the merged options bag for nested flows.
|
|
242
|
+
- See [Authoring Plugins → Lifecycle & Wiring](./guides/authoring/lifecycle.md) for a deeper walk‑through and best practices.
|
|
243
|
+
|
|
171
244
|
## Dynamic Processing
|
|
172
245
|
|
|
173
246
|
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 +272,21 @@ export default {
|
|
|
199
272
|
};
|
|
200
273
|
```
|
|
201
274
|
|
|
202
|
-
|
|
275
|
+
### TypeScript-first Vars-aware dynamic typing
|
|
276
|
+
|
|
277
|
+
You can bind the expected variable shape to get strong inference inside your dynamic map.
|
|
278
|
+
|
|
279
|
+
```ts
|
|
280
|
+
import { defineDynamic } from '@karmaniverous/get-dotenv';
|
|
281
|
+
|
|
282
|
+
type Vars = { APP_SETTING?: string; ENV_TAG?: string };
|
|
283
|
+
|
|
284
|
+
export const dynamic = defineDynamic<Vars>({
|
|
285
|
+
GREETING: ({ APP_SETTING = '' }) => `Hello ${APP_SETTING}`,
|
|
286
|
+
});
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
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
290
|
|
|
204
291
|
Programmatic users can skip files entirely and pass dynamic variables directly:
|
|
205
292
|
|
|
@@ -230,57 +317,7 @@ Notes:
|
|
|
230
317
|
|
|
231
318
|
## Command Line Interface
|
|
232
319
|
|
|
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
|
-
```
|
|
320
|
+
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
321
|
|
|
285
322
|
### Default shell behavior
|
|
286
323
|
|
|
@@ -387,19 +424,18 @@ Diagnostics and CI capture:
|
|
|
387
424
|
|
|
388
425
|
## Guides
|
|
389
426
|
|
|
390
|
-
- [Cascade and precedence](./guides/cascade.md)
|
|
391
|
-
|
|
392
|
-
- [
|
|
393
|
-
|
|
427
|
+
- [Cascade and precedence](./guides/cascade.md) - How variables load and merge across
|
|
428
|
+
paths and public/private/env axes.
|
|
429
|
+
- [Shell execution behavior](./guides/shell.md) - How commands run cross‑platform;
|
|
430
|
+
quoting rules, default shells, and capture tips.
|
|
431
|
+
- [Config files and overlays](./guides/config.md) - Author JSON/YAML/JS/TS config and
|
|
432
|
+
apply privacy/source overlays (always‑on).
|
|
433
|
+
- [Authoring Plugins](./guides/authoring/index.md) - Compose CLIs with once‑per‑invoke dotenv context and plugin lifecycles.
|
|
434
|
+
- [Shipped Plugins](./guides/shipped/index.md) - The get‑dotenv host ships a small set of plugins that cover needs.
|
|
394
435
|
|
|
436
|
+
Note: Dynamic option descriptions and help‑time default labels are documented under [Authoring Plugins → Lifecycle](./guides/authoring/lifecycle.md) (plugin‑bound createPluginDynamicOption), [Config files and overlays](./guides/config.md) (plugin config), and [Shell execution behavior](./guides/shell.md) (dynamic defaults).
|
|
395
437
|
The guides are also included in the [hosted API docs](https://docs.karmanivero.us/get-dotenv).
|
|
396
438
|
|
|
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
439
|
---
|
|
404
440
|
|
|
405
441
|
See more great templates & tools on [my GitHub Profile](https://github.com/karmaniverous)!
|