@karmaniverous/get-dotenv 4.6.0-0 → 5.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 +130 -23
- package/dist/cliHost.cjs +1078 -0
- package/dist/cliHost.d.cts +193 -0
- package/dist/cliHost.d.mts +193 -0
- package/dist/cliHost.d.ts +193 -0
- package/dist/cliHost.mjs +1074 -0
- package/dist/config.cjs +247 -0
- package/dist/config.d.cts +53 -0
- package/dist/config.d.mts +53 -0
- package/dist/config.d.ts +53 -0
- package/dist/config.mjs +242 -0
- package/dist/env-overlay.cjs +163 -0
- package/dist/env-overlay.d.cts +50 -0
- package/dist/env-overlay.d.mts +50 -0
- package/dist/env-overlay.d.ts +50 -0
- package/dist/env-overlay.mjs +161 -0
- package/dist/getdotenv.cli.mjs +2776 -733
- package/dist/index.cjs +886 -275
- package/dist/index.d.cts +117 -61
- package/dist/index.d.mts +117 -61
- package/dist/index.d.ts +117 -61
- package/dist/index.mjs +888 -278
- package/dist/plugins-aws.cjs +618 -0
- package/dist/plugins-aws.d.cts +178 -0
- package/dist/plugins-aws.d.mts +178 -0
- package/dist/plugins-aws.d.ts +178 -0
- package/dist/plugins-aws.mjs +616 -0
- package/dist/plugins-batch.cjs +569 -0
- package/dist/plugins-batch.d.cts +200 -0
- package/dist/plugins-batch.d.mts +200 -0
- package/dist/plugins-batch.d.ts +200 -0
- package/dist/plugins-batch.mjs +567 -0
- package/dist/plugins-init.cjs +282 -0
- package/dist/plugins-init.d.cts +182 -0
- package/dist/plugins-init.d.mts +182 -0
- package/dist/plugins-init.d.ts +182 -0
- package/dist/plugins-init.mjs +280 -0
- package/getdotenv.config.json +19 -0
- package/package.json +88 -17
- package/templates/cli/ts/index.ts +9 -0
- package/templates/cli/ts/plugins/hello.ts +17 -0
- package/templates/config/js/getdotenv.config.js +15 -0
- package/templates/config/json/local/getdotenv.config.local.json +7 -0
- package/templates/config/json/public/getdotenv.config.json +12 -0
- package/templates/config/public/getdotenv.config.json +13 -0
- package/templates/config/ts/getdotenv.config.ts +16 -0
- package/templates/config/yaml/local/getdotenv.config.local.yaml +7 -0
- package/templates/config/yaml/public/getdotenv.config.yaml +10 -0
package/README.md
CHANGED
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
## Requirements
|
|
4
4
|
|
|
5
|
-
- Node.js >=
|
|
5
|
+
- Node.js >= 20 (this repository pins 22.19.0 for CI/reproducibility)
|
|
6
6
|
|
|
7
7
|
## API Reference
|
|
8
|
-
|
|
9
8
|
Generated API documentation is hosted at:
|
|
10
|
-
|
|
11
9
|
- https://docs.karmanivero.us/get-dotenv
|
|
12
10
|
|
|
13
11
|
The site is built with TypeDoc from the source code in this repository.
|
|
@@ -46,14 +44,6 @@ You can always use `getdotenv` directly on the command line, but its REAL power
|
|
|
46
44
|
|
|
47
45
|
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!
|
|
48
46
|
|
|
49
|
-
## Breaking Changes
|
|
50
|
-
|
|
51
|
-
In version 4.0.0, in addition to a full TypeScript refactor, I replaced the use of the unsafe `Function` constructor for dynamic variable processing with a MUCH safer dynamic module import.
|
|
52
|
-
|
|
53
|
-
Dynamic importing is intrinsically asynchronous, and so far I haven't been able to figure out how to cram that into the synchronous `getDotenvSync` function. There really aren't THAT many users of this library, so rather than have async & sync versions that do different things, I just eliminated the sync version entirely.
|
|
54
|
-
|
|
55
|
-
If you have a use case for sync dotenv processing and DON'T need dynamic variables, let me know and I'll put the restricted version back in. If you have an idea of how to make dynamic imports synchronous, I'm all ears!
|
|
56
|
-
|
|
57
47
|
## Testing
|
|
58
48
|
|
|
59
49
|
This project uses Vitest with the V8 coverage provider. Run:
|
|
@@ -68,13 +58,58 @@ npm run test
|
|
|
68
58
|
npm install @karmaniverous/get-dotenv
|
|
69
59
|
```
|
|
70
60
|
|
|
61
|
+
## Scaffold
|
|
62
|
+
|
|
63
|
+
You can scaffold config files and a host-based CLI skeleton using the built-in
|
|
64
|
+
init command. Templates are shipped with the package and copied verbatim.
|
|
65
|
+
|
|
66
|
+
Examples:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# JSON config + .local variant, and a CLI skeleton named "acme"
|
|
70
|
+
npx getdotenv init . \
|
|
71
|
+
--config-format json \
|
|
72
|
+
--with-local \
|
|
73
|
+
--cli-name acme \
|
|
74
|
+
--force
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# TypeScript config with a dynamic example; CLI named "toolbox"
|
|
79
|
+
npx getdotenv init ./apps/toolbox \
|
|
80
|
+
--config-format ts \
|
|
81
|
+
--cli-name toolbox
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Collision flow (when a destination file exists):
|
|
85
|
+
|
|
86
|
+
- Interactive prompt: [o]verwrite, [e]xample, [s]kip, or their “all” variants
|
|
87
|
+
[O]/[E]/[S].
|
|
88
|
+
- Non-interactive detection:
|
|
89
|
+
- Treated as `--yes` (Skip All) unless `--force` is provided (Overwrite All).
|
|
90
|
+
- Considered non-interactive when stdin or stdout is not a TTY OR when a
|
|
91
|
+
CI-like environment variable is present (`CI`, `GITHUB_ACTIONS`,
|
|
92
|
+
`BUILDKITE`, `TEAMCITY_VERSION`, `TF_BUILD`).
|
|
93
|
+
- Precedence:
|
|
94
|
+
- `--force` > `--yes` > auto-detect (non-interactive => Skip All).
|
|
95
|
+
- Options overview:
|
|
96
|
+
- `--config-format <json|yaml|js|ts>`
|
|
97
|
+
- `--with-local` to generate `.local` alongside public config (JSON/YAML)
|
|
98
|
+
- `--cli-name <string>` for token substitution (`__CLI_NAME__`) in the CLI
|
|
99
|
+
skeleton
|
|
100
|
+
- `--force` to overwrite all; `--yes` to skip all
|
|
101
|
+
|
|
102
|
+
Notes:
|
|
103
|
+
|
|
104
|
+
- Templates are shipped with the package and copied verbatim.
|
|
105
|
+
- The CLI skeleton replaces `__CLI_NAME__` tokens with your chosen name.
|
|
106
|
+
|
|
71
107
|
## Usage
|
|
72
108
|
|
|
73
|
-
|
|
109
|
+
````js
|
|
74
110
|
import { getDotenv } from '@karmaniverous/get-dotenv';
|
|
75
111
|
|
|
76
|
-
const dotenv = await getDotenv(options)
|
|
77
|
-
```
|
|
112
|
+
const dotenv = await getDotenv(options);```
|
|
78
113
|
|
|
79
114
|
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.
|
|
80
115
|
|
|
@@ -94,7 +129,7 @@ export default {
|
|
|
94
129
|
ONE_MORE_TIME: ({ DESTRUCTRED_VARIABLE, ANOTHER_DYNAMIC_VARIABLE }) =>
|
|
95
130
|
DESTRUCTRED_VARIABLE + ANOTHER_DYNAMIC_VARIABLE,
|
|
96
131
|
};
|
|
97
|
-
|
|
132
|
+
````
|
|
98
133
|
|
|
99
134
|
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.)
|
|
100
135
|
|
|
@@ -157,7 +192,6 @@ You can also use `getdotenv` from the command line:
|
|
|
157
192
|
# Options:
|
|
158
193
|
# -e, --env <string> target environment (dotenv-expanded)
|
|
159
194
|
# -v, --vars <string> extra variables expressed as delimited key-value pairs (dotenv-expanded): KEY1=VAL1 KEY2=VAL2
|
|
160
|
-
# -c, --command <string> command executed according to the --shell option, conflicts with cmd subcommand (dotenv-expanded)
|
|
161
195
|
# -o, --output-path <string> consolidated output file (dotenv-expanded)
|
|
162
196
|
# -s, --shell [string] command execution shell, no argument for default OS shell or provide shell string (default OS shell)
|
|
163
197
|
# -S, --shell-off command execution shell OFF
|
|
@@ -184,8 +218,7 @@ You can also use `getdotenv` from the command line:
|
|
|
184
218
|
# --dynamic-path <string> dynamic variables path (.js or .ts; .ts is auto-compiled when esbuild is available, otherwise precompile)
|
|
185
219
|
# --paths <string> dotenv-expanded delimited list of paths to dotenv directory (default: "./")
|
|
186
220
|
# --paths-delimiter <string> paths delimiter string (default: " ")
|
|
187
|
-
# --paths-delimiter-pattern <string> paths delimiter regex pattern
|
|
188
|
-
# --private-token <string> dotenv-expanded token indicating private variables (default: "local")
|
|
221
|
+
# --paths-delimiter-pattern <string> paths delimiter regex pattern# --private-token <string> dotenv-expanded token indicating private variables (default: "local")
|
|
189
222
|
# --vars-delimiter <string> vars delimiter string (default: " ")
|
|
190
223
|
# --vars-delimiter-pattern <string> vars delimiter regex pattern
|
|
191
224
|
# --vars-assignor <string> vars assignment operator string (default: "=")
|
|
@@ -250,13 +283,87 @@ Meanwhile, [this issue](https://github.com/karmaniverous/get-dotenv/issues/7) do
|
|
|
250
283
|
|
|
251
284
|
---
|
|
252
285
|
|
|
286
|
+
### Authoring npm scripts and the `-c`/`--cmd` alias
|
|
287
|
+
|
|
288
|
+
When you run commands via `npm run`, flags after `--` are forwarded to your script
|
|
289
|
+
and may be applied to the inner shell command instead of `getdotenv` unless you
|
|
290
|
+
structure your script carefully.
|
|
291
|
+
|
|
292
|
+
- Anti-pattern:
|
|
293
|
+
|
|
294
|
+
```json
|
|
295
|
+
{ "scripts": { "script": "getdotenv echo $APP_SETTING" } }
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Then `npm run script -- -e dev` applies `-e` to `echo`, not to `getdotenv`.
|
|
299
|
+
|
|
300
|
+
- Recommended:
|
|
301
|
+
```json
|
|
302
|
+
{ "scripts": { "script": "getdotenv -c 'echo $APP_SETTING'" } }
|
|
303
|
+
```
|
|
304
|
+
Now `npm run script -- -e dev` applies `-e` to `getdotenv`, which loads and expands
|
|
305
|
+
variables before executing the inner command.
|
|
306
|
+
|
|
307
|
+
Notes:
|
|
308
|
+
|
|
309
|
+
- `-c`/`--cmd` is an alias of the `cmd` subcommand; do not use both in a single invocation.
|
|
310
|
+
- On POSIX shells, prefer single quotes to prevent the outer shell from expanding `$VAR`
|
|
311
|
+
before Node sees it. On PowerShell, single quotes are also literal.
|
|
312
|
+
- Script-level shell overrides (`scripts[name].shell`) still take precedence over the global
|
|
313
|
+
`--shell`.
|
|
314
|
+
|
|
315
|
+
Important:
|
|
316
|
+
|
|
317
|
+
- When using the parent alias `--cmd` with a Node eval payload, quote the entire
|
|
318
|
+
payload as a single token so Commander does not treat `-e/--eval` as
|
|
319
|
+
getdotenv’s `-e, --env` flag.
|
|
320
|
+
- POSIX example:
|
|
321
|
+
```
|
|
322
|
+
getdotenv --cmd 'node -e "console.log(process.env.APP_SETTING ?? \"\")"'
|
|
323
|
+
```
|
|
324
|
+
- PowerShell example (single quotes are literal in PowerShell):
|
|
325
|
+
```
|
|
326
|
+
getdotenv --cmd 'node -e "console.log(process.env.APP_SETTING ?? \"\")"'
|
|
327
|
+
```
|
|
328
|
+
- If you do not need to pass additional parent flags after the command, you can
|
|
329
|
+
prefer the subcommand form instead:
|
|
330
|
+
```
|
|
331
|
+
getdotenv --shell-off cmd node -e "console.log(process.env.APP_SETTING ?? '')"
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Diagnostics and CI capture:
|
|
335
|
+
|
|
336
|
+
- To capture child stdout/stderr deterministically (e.g., in CI), either set
|
|
337
|
+
the environment variable `GETDOTENV_STDIO=pipe` or pass `--capture`. Outputs
|
|
338
|
+
are buffered and re-emitted after completion.
|
|
339
|
+
- For debugging environment composition, use:
|
|
340
|
+
```
|
|
341
|
+
getdotenv --trace [keys...] cmd node -e "0"
|
|
342
|
+
```
|
|
343
|
+
When provided without keys, `--trace` emits a concise origin line for every
|
|
344
|
+
key (parent | dotenv | unset) to stderr before the child process launches.
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
253
348
|
## Guides
|
|
254
349
|
|
|
255
|
-
- Cascade and precedence
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
350
|
+
- [Cascade and precedence](./guides/cascade.md)
|
|
351
|
+
- [Shell execution behavior and quoting](./guides/shell.md)
|
|
352
|
+
|
|
353
|
+
The guides are also included in the [hosted API docs](https://docs.karmanivero.us/get-dotenv).
|
|
354
|
+
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
## Generated CLI
|
|
358
|
+
|
|
359
|
+
This package still supports generating a standalone CLI for your projects.
|
|
360
|
+
For most use cases we recommend the new plugin-first host because it resolves
|
|
361
|
+
dotenv context once per invocation, supports composable plugins, and provides
|
|
362
|
+
better subprocess control and diagnostics. If you prefer a thin, fixed
|
|
363
|
+
command surface with defaults baked into config, the generated CLI can be a
|
|
364
|
+
good fit.
|
|
259
365
|
|
|
260
|
-
|
|
366
|
+
See the Generated CLI guide for details:
|
|
367
|
+
https://docs.karmanivero.us/get-dotenv/guides/generated-cli
|
|
261
368
|
|
|
262
369
|
See more great templates & tools on [my GitHub Profile](https://github.com/karmaniverous)!
|