@karmaniverous/get-dotenv 4.5.1 → 4.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.
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2025, Jason Williscroft
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,215 +1,262 @@
1
- # get-dotenv
2
-
3
- Load environment variables with a cascade of environment-aware dotenv files. You can:
4
-
5
- Asynchronously load environment variables from multiple dotenv files.
6
-
7
- Segregate variables info distinct files:
8
-
9
- - Public files (e.g. `.env`, `env.dev`, `env.test`) are synced with your git repository.
10
- - Private files (e.g. `.env.local`, `env.dev.local`, `env.test.local`) are protected by `.gitignore`.
11
- - Global files (e.g. `.env`, `env.local`) apply to all environments.
12
- - Env files (e.g. `.env.dev`, `.env.dev.local`, `.env.test`, `.env.test.local`) apply to a specific environment.
13
- - [Dynamic files](#dynamic-processing) (`.env.js`) export logic that dynamically & progressively generates new variables or overrides current ones.
14
-
15
- Dynamically specify which variables to load by type.
16
-
17
- Explicitly add variables to the loaded set.
18
-
19
- Extract the resulting variables to an object, `process.env`, a dotenv file, or a logger object, in any combination.
20
-
21
- Customize your dotenv file directories & naming patterns.
22
-
23
- 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!
24
-
25
- [Execute batched CLI commands](#batch-command) across multiple working directories, with each command inheriting the `getdotenv` context.
26
-
27
- Set defaults for all options in a `getdotenv.config.json` file in your project root directory.
28
-
29
- [Generate an extensible `getdotenv`-based CLI](https://github.com/karmaniverous/get-dotenv-child) for use in your own projects.
30
-
31
- `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.
32
-
33
- 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.
34
-
35
- 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!
36
-
37
- ## Breaking Changes
38
-
39
- 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.
40
-
41
- 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.
42
-
43
- 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!
44
-
45
- ## Installation
46
-
47
- ```bash
48
- npm install @karmaniverous/get-dotenv
49
- ```
50
-
51
- ## Usage
52
-
53
- ```js
54
- import { getDotenv } from '@karmaniverous/get-dotenv';
55
-
56
- const dotenv = await getDotenv(options);
57
- ```
58
-
59
- 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.
60
-
61
- See the [child CLI example repo](https://github.com/karmaniverous/get-dotenv-child#configuration) for an extensiive discussion of the various config options and how & where to set them.
62
-
63
- ## Dynamic Processing
64
-
65
- This package supports the full [`dotenv-expand`](https://www.npmjs.com/package/dotenv-expand) syntax, with some internal performance improvements.
66
-
67
- Use the `dynamicPath` option to add a relative path to a Javascript module with a default export like this:
68
-
69
- ```js
70
- export default {
71
- SOME_DYNAMIC_VARIABLE: (dotenv) => someLogic(dotenv),
72
- ANOTHER_DYNAMIC_VARIABLE: (dotenv) =>
73
- someOtherLogic(dotenv.SOME_DYNAMIC_VARIABLE),
74
- ONE_MORE_TIME: ({ DESTRUCTRED_VARIABLE, ANOTHER_DYNAMIC_VARIABLE }) =>
75
- DESTRUCTRED_VARIABLE + ANOTHER_DYNAMIC_VARIABLE,
76
- };
77
- ```
78
-
79
- 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.)
80
-
81
- Since keys will be evaluated progressively, each successive key function will have access to any previous ones. These keys can also override existing variables.
82
-
83
- ### Dynamic Processing with TypeScript
84
-
85
- Even though the rest of your project is in TypeScript, the dynamic processing module SHOULD be in JavasScript.
86
-
87
- Think about it: the module is loaded via a dynamic import, with the file name determined at run time. If you write this module in TS, you'll have to jump through some hoops to get your bundler to compile this file, and you'll have to be careful to set `dynamicPath` to reference the compiled file. That's a lot of work to do for some very simple logic.
88
-
89
- BUT... if you must, then your dynamic module's default export should be of the `GetDotenvDynamic` type, which is defined [here](./src/GetDotenvOptions.ts) and looks like this:
90
-
91
- ```ts
92
- export type ProcessEnv = Record<string, string | undefined>;
93
-
94
- export type GetDotenvDynamicFunction = (
95
- vars: ProcessEnv,
96
- env: string | undefined,
97
- ) => string | undefined;
98
-
99
- export type GetDotenvDynamic = Record<
100
- string,
101
- GetDotenvDynamicFunction | ReturnType<GetDotenvDynamicFunction>
102
- >;
103
- ```
104
-
105
- The second argumnt `env` of the `GetDotenvDynamicFunction` type is the environment token (if any) specified in the controlling `getDotenv` call.
106
-
107
- ## Command Line Interface
108
-
109
- You can also use `getdotenv` from the command line:
110
-
111
- ```bash
112
- > npx getdotenv -h
113
-
114
- # Usage: getdotenv [options] [command]
115
- #
116
- # Base CLI.
117
- #
118
- # Options:
119
- # -e, --env <string> target environment (dotenv-expanded)
120
- # -v, --vars <string> extra variables expressed as delimited key-value pairs (dotenv-expanded): KEY1=VAL1 KEY2=VAL2
121
- # -c, --command <string> command executed according to the --shell option, conflicts with cmd subcommand (dotenv-expanded)
122
- # -o, --output-path <string> consolidated output file (dotenv-expanded)
123
- # -s, --shell [string] command execution shell, no argument for default OS shell or provide shell string (default OS shell)
124
- # -S, --shell-off command execution shell OFF
125
- # -p, --load-process load variables to process.env ON (default)
126
- # -P, --load-process-off load variables to process.env OFF
127
- # -a, --exclude-all exclude all dotenv variables from loading ON
128
- # -A, --exclude-all-off exclude all dotenv variables from loading OFF (default)
129
- # -z, --exclude-dynamic exclude dynamic dotenv variables from loading ON
130
- # -Z, --exclude-dynamic-off exclude dynamic dotenv variables from loading OFF (default)
131
- # -n, --exclude-env exclude environment-specific dotenv variables from loading
132
- # -N, --exclude-env-off exclude environment-specific dotenv variables from loading OFF (default)
133
- # -g, --exclude-global exclude global dotenv variables from loading ON
134
- # -G, --exclude-global-off exclude global dotenv variables from loading OFF (default)
135
- # -r, --exclude-private exclude private dotenv variables from loading ON
136
- # -R, --exclude-private-off exclude private dotenv variables from loading OFF (default)
137
- # -u, --exclude-public exclude public dotenv variables from loading ON
138
- # -U, --exclude-public-off exclude public dotenv variables from loading OFF (default)
139
- # -l, --log console log loaded variables ON
140
- # -L, --log-off console log loaded variables OFF (default)
141
- # -d, --debug debug mode ON
142
- # -D, --debug-off debug mode OFF (default)
143
- # --default-env <string> default target environment
144
- # --dotenv-token <string> dotenv-expanded token indicating a dotenv file (default: ".env")
145
- # --dynamic-path <string> dynamic variables path
146
- # --paths <string> dotenv-expanded delimited list of paths to dotenv directory (default: "./")
147
- # --paths-delimiter <string> paths delimiter string (default: " ")
148
- # --paths-delimiter-pattern <string> paths delimiter regex pattern
149
- # --private-token <string> dotenv-expanded token indicating private variables (default: "local")
150
- # --vars-delimiter <string> vars delimiter string (default: " ")
151
- # --vars-delimiter-pattern <string> vars delimiter regex pattern
152
- # --vars-assignor <string> vars assignment operator string (default: "=")
153
- # --vars-assignor-pattern <string> vars assignment operator regex pattern
154
- # -h, --help display help for command
155
- #
156
- # Commands:
157
- # batch [options] Batch shell commands across multiple working directories.
158
- # cmd Batch execute command according to the --shell option, conflicts with --command option (default command)
159
- # help [command] display help for command
160
- ```
161
-
162
- By default, commands (`-c` or `--command` or the `cmd` subcommand either in the base CLI or in the `batch` subcommand) execute in the default OS shell with the `dotenv` context applied. The `-S` or `--shell-off` options will turn this off, and Execa will [execute your command as Javascript](https://github.com/sindresorhus/execa/blob/main/docs/bash.md).
163
-
164
- Alternatively, you can use the `-s` or `--shell` option to specify a different shell [following the Execa spec](https://github.com/sindresorhus/execa/blob/main/docs/shell.md). This is useful if you're running a command that requires a specific shell, like `bash` or `zsh`.
165
-
166
- Finally, you can set the [`shell`](https://github.com/karmaniverous/get-dotenv-child?tab=readme-ov-file#options) default globally in your `getdotenv.config.json` file.
167
-
168
- See [this example repo](https://github.com/karmaniverous/get-dotenv-child) for a deep dive on using the `getDotenv` CLI and how to extend it for your own projects.
169
-
170
- ### Batch Command
171
-
172
- The `getdotenv` base CLI includes one very useful subcommand: `batch`.
173
-
174
- 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!
175
-
176
- 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.
177
-
178
- 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!
179
-
180
- Lest you doubt what that kind of leverage can do for you, consider this:
181
-
182
- [![batch superpower in action](./doc/contributions.png)](https://github.com/karmaniverous)
183
-
184
- ```bash
185
- > getdotenv batch -h
186
-
187
- # Usage: getdotenv batch [options] [command]
188
- #
189
- # Batch command execution across multiple working directories.
190
- #
191
- # Options:
192
- # -p, --pkg-cwd use nearest package directory as current working directory
193
- # -r, --root-path <string> path to batch root directory from current working directory (default: "./")
194
- # -g, --globs <string> space-delimited globs from root path (default: "*")
195
- # -c, --command <string> command executed according to the base --shell option, conflicts with cmd subcommand (dotenv-expanded)
196
- # -l, --list list working directories without executing command
197
- # -e, --ignore-errors ignore errors and continue with next path
198
- # -h, --help display help for command
199
- #
200
- # Commands:
201
- # cmd execute command, conflicts with --command option (default subcommand)
202
- # help [command] display help for command
203
- ```
204
-
205
- Note that `batch` executes its commands in sequence, rather than in parallel!
206
-
207
- 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.
208
-
209
- Instead, everything runs in sequence, and you get a clear record of exactly what heppened and where. Also worth noting that many complex processes are resource hogs: you would not _want_ to run a dozen Serverless deployments at once!
210
-
211
- Meanwhile, [this issue](https://github.com/karmaniverous/get-dotenv/issues/7) documents the parallel-processing option requirement. Feel free to submit a PR!
212
-
213
- ---
214
-
215
- See more great templates & tools on [my GitHub Profile](https://github.com/karmaniverous)!
1
+ # get-dotenv
2
+
3
+ ## Requirements
4
+
5
+ - Node.js >= 22.19 (this repository pins 22.19.0 for CI/reproducibility)
6
+
7
+ ## API Reference
8
+
9
+ Generated API documentation is hosted at:
10
+
11
+ - https://docs.karmanivero.us/get-dotenv
12
+
13
+ The site is built with TypeDoc from the source code in this repository.
14
+
15
+ Load environment variables with a cascade of environment-aware dotenv files. You can:
16
+
17
+ Asynchronously load environment variables from multiple dotenv files.
18
+
19
+ Segregate variables info distinct files:
20
+
21
+ - Public files (e.g. `.env`, `env.dev`, `env.test`) are synced with your git repository.
22
+ - Private files (e.g. `.env.local`, `env.dev.local`, `env.test.local`) are protected by `.gitignore`.
23
+ - Global files (e.g. `.env`, `env.local`) apply to all environments.
24
+ - Env files (e.g. `.env.dev`, `.env.dev.local`, `.env.test`, `.env.test.local`) apply to a specific environment.
25
+ - [Dynamic files](#dynamic-processing) (`.env.js`) export logic that dynamically & progressively generates new variables or overrides current ones.
26
+
27
+ Dynamically specify which variables to load by type.
28
+
29
+ Explicitly add variables to the loaded set.
30
+
31
+ Extract the resulting variables to an object, `process.env`, a dotenv file, or a logger object, in any combination.
32
+
33
+ Customize your dotenv file directories & naming patterns.
34
+
35
+ 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!
36
+
37
+ [Execute batched CLI commands](#batch-command) across multiple working directories, with each command inheriting the `getdotenv` context.
38
+
39
+ Set defaults for all options in a `getdotenv.config.json` file in your project root directory.
40
+
41
+ [Generate an extensible `getdotenv`-based CLI](https://github.com/karmaniverous/get-dotenv-child) for use in your own projects.
42
+
43
+ `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.
44
+
45
+ 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.
46
+
47
+ 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
+
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
+ ## Testing
58
+
59
+ This project uses Vitest with the V8 coverage provider. Run:
60
+
61
+ ```bash
62
+ npm run test
63
+ ```
64
+
65
+ ## Installation
66
+
67
+ ```bash
68
+ npm install @karmaniverous/get-dotenv
69
+ ```
70
+
71
+ ## Usage
72
+
73
+ ```js
74
+ import { getDotenv } from '@karmaniverous/get-dotenv';
75
+
76
+ const dotenv = await getDotenv(options);
77
+ ```
78
+
79
+ 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
+
81
+ See the [child CLI example repo](https://github.com/karmaniverous/get-dotenv-child#configuration) for an extensiive discussion of the various config options and how & where to set them.
82
+
83
+ ## Dynamic Processing
84
+
85
+ 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.
86
+
87
+ Use the `dynamicPath` option to add a relative path to a Javascript module with a default export like this:
88
+
89
+ ```js
90
+ export default {
91
+ SOME_DYNAMIC_VARIABLE: (dotenv) => someLogic(dotenv),
92
+ ANOTHER_DYNAMIC_VARIABLE: (dotenv) =>
93
+ someOtherLogic(dotenv.SOME_DYNAMIC_VARIABLE),
94
+ ONE_MORE_TIME: ({ DESTRUCTRED_VARIABLE, ANOTHER_DYNAMIC_VARIABLE }) =>
95
+ DESTRUCTRED_VARIABLE + ANOTHER_DYNAMIC_VARIABLE,
96
+ };
97
+ ```
98
+
99
+ 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
+
101
+ Since keys will be evaluated progressively, each successive key function will have access to any previous ones. These keys can also override existing variables.
102
+
103
+ ### TypeScript-first dynamic processing
104
+
105
+ 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:
106
+
107
+ ```ts
108
+ // dynamic.ts
109
+ export default {
110
+ MY_DYNAMIC: ({ APP_SETTING = '' }) => `${APP_SETTING}-ts`,
111
+ };
112
+ ```
113
+
114
+ If `esbuild` is not installed and a direct import fails, get-dotenv attempts a
115
+ simple fallback for single-file `.ts` modules without imports; otherwise it will
116
+ throw with clear guidance to install `esbuild`.
117
+
118
+ Programmatic users can skip files entirely and pass dynamic variables directly:
119
+
120
+ ```ts
121
+ import { getDotenv, defineDynamic } from '@karmaniverous/get-dotenv';
122
+
123
+ const dynamic = defineDynamic({
124
+ MY_DYNAMIC(vars, env) {
125
+ return `${vars.APP_SETTING}-${env ?? ''}`;
126
+ },
127
+ });
128
+
129
+ const vars = await getDotenv({ dynamic, paths: ['./'], env: 'dev' });
130
+ ```
131
+
132
+ Notes:
133
+
134
+ - Programmatic `dynamic` takes precedence over `dynamicPath` when both are provided.
135
+ - Dynamic keys are evaluated progressively, so later keys can reference earlier results.
136
+
137
+ #### Troubleshooting
138
+
139
+ - “Unknown file extension '.ts'” when loading `dynamic.ts`:
140
+ - Install `esbuild` (`npm i -D esbuild`).
141
+
142
+ - “Unable to load dynamic TypeScript file …”:
143
+ - Install `esbuild`. A simple transpile fallback exists only for trivial
144
+ single-file modules; any imports in `dynamic.ts` require `esbuild` bundling.
145
+
146
+ ## Command Line Interface
147
+
148
+ You can also use `getdotenv` from the command line:
149
+
150
+ ```bash
151
+ > npx getdotenv -h
152
+
153
+ # Usage: getdotenv [options] [command]
154
+ #
155
+ # Base CLI.
156
+ #
157
+ # Options:
158
+ # -e, --env <string> target environment (dotenv-expanded)
159
+ # -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
+ # -o, --output-path <string> consolidated output file (dotenv-expanded)
162
+ # -s, --shell [string] command execution shell, no argument for default OS shell or provide shell string (default OS shell)
163
+ # -S, --shell-off command execution shell OFF
164
+ # -p, --load-process load variables to process.env ON (default)
165
+ # -P, --load-process-off load variables to process.env OFF
166
+ # -a, --exclude-all exclude all dotenv variables from loading ON
167
+ # -A, --exclude-all-off exclude all dotenv variables from loading OFF (default)
168
+ # -z, --exclude-dynamic exclude dynamic dotenv variables from loading ON
169
+ # -Z, --exclude-dynamic-off exclude dynamic dotenv variables from loading OFF (default)
170
+ # -n, --exclude-env exclude environment-specific dotenv variables from loading
171
+ # -N, --exclude-env-off exclude environment-specific dotenv variables from loading OFF (default)
172
+ # -g, --exclude-global exclude global dotenv variables from loading ON
173
+ # -G, --exclude-global-off exclude global dotenv variables from loading OFF (default)
174
+ # -r, --exclude-private exclude private dotenv variables from loading ON
175
+ # -R, --exclude-private-off exclude private dotenv variables from loading OFF (default)
176
+ # -u, --exclude-public exclude public dotenv variables from loading ON
177
+ # -U, --exclude-public-off exclude public dotenv variables from loading OFF (default)
178
+ # -l, --log console log loaded variables ON
179
+ # -L, --log-off console log loaded variables OFF (default)
180
+ # -d, --debug debug mode ON
181
+ # -D, --debug-off debug mode OFF (default)
182
+ # --default-env <string> default target environment
183
+ # --dotenv-token <string> dotenv-expanded token indicating a dotenv file (default: ".env")
184
+ # --dynamic-path <string> dynamic variables path (.js or .ts; .ts is auto-compiled when esbuild is available, otherwise precompile)
185
+ # --paths <string> dotenv-expanded delimited list of paths to dotenv directory (default: "./")
186
+ # --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")
189
+ # --vars-delimiter <string> vars delimiter string (default: " ")
190
+ # --vars-delimiter-pattern <string> vars delimiter regex pattern
191
+ # --vars-assignor <string> vars assignment operator string (default: "=")
192
+ # --vars-assignor-pattern <string> vars assignment operator regex pattern
193
+ # -h, --help display help for command
194
+ #
195
+ # Commands:
196
+ # batch [options] Batch shell commands across multiple working directories.
197
+ # cmd Batch execute command according to the --shell option, conflicts with --command option (default command)
198
+ # help [command] display help for command
199
+ ```
200
+
201
+ ### Default shell behavior
202
+
203
+ To normalize behavior across platforms, the CLI resolves a default shell when `--shell` is true or omitted:
204
+
205
+ - POSIX: `/bin/bash`
206
+ - Windows: `powershell.exe`
207
+
208
+ ### Batch Command
209
+
210
+ The `getdotenv` base CLI includes one very useful subcommand: `batch`.
211
+
212
+ 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!
213
+
214
+ 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.
215
+
216
+ 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!
217
+
218
+ Lest you doubt what that kind of leverage can do for you, consider this:
219
+
220
+ [![batch superpower in action](./assets/contributions.png)](https://github.com/karmaniverous)
221
+
222
+ ```bash
223
+ > getdotenv batch -h
224
+
225
+ # Usage: getdotenv batch [options] [command]
226
+ #
227
+ # Batch command execution across multiple working directories.
228
+ #
229
+ # Options:
230
+ # -p, --pkg-cwd use nearest package directory as current working directory
231
+ # -r, --root-path <string> path to batch root directory from current working directory (default: "./")
232
+ # -g, --globs <string> space-delimited globs from root path (default: "*")
233
+ # -c, --command <string> command executed according to the base --shell option, conflicts with cmd subcommand (dotenv-expanded)
234
+ # -l, --list list working directories without executing command
235
+ # -e, --ignore-errors ignore errors and continue with next path
236
+ # -h, --help display help for command
237
+ #
238
+ # Commands:
239
+ # cmd execute command, conflicts with --command option (default subcommand)
240
+ # help [command] display help for command
241
+ ```
242
+
243
+ Note that `batch` executes its commands in sequence, rather than in parallel!
244
+
245
+ 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.
246
+
247
+ Instead, everything runs in sequence, and you get a clear record of exactly what heppened and where. Also worth noting that many complex processes are resource hogs: you would not _want_ to run a dozen Serverless deployments at once!
248
+
249
+ Meanwhile, [this issue](https://github.com/karmaniverous/get-dotenv/issues/7) documents the parallel-processing option requirement. Feel free to submit a PR!
250
+
251
+ ---
252
+
253
+ ## Guides
254
+
255
+ - Cascade and precedence:
256
+ - ./guides/cascade.md
257
+ - Shell execution behavior and quoting:
258
+ - ./guides/shell.md
259
+
260
+ The guides are also included in the hosted API docs.
261
+
262
+ See more great templates & tools on [my GitHub Profile](https://github.com/karmaniverous)!