@karmaniverous/get-dotenv 2.2.2 → 2.3.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 CHANGED
@@ -78,17 +78,10 @@ dotenv files. You can:
78
78
  * Specify a default environment, override the default with an existing
79
79
  environment variable, and override both with a direct setting.
80
80
  * Exclude public, private, global, environment-specific, or dynamic variables.
81
- * Execute a &&-delimited series of shell commands after loading variables.
81
+ * Execute a &&-delimited series of shell commands after loading variables,
82
+ optionally ignoring errors.
82
83
  * Place the shell commands inside the invocation to support npm script
83
84
  arguments for other options.
84
- * Specify the token that identifies dotenv files (e.g. '.env').
85
- * Specify the token that identifies private vatiables (e.g. '.local').
86
-
87
- Options:
88
- -p, --paths <strings...> space-delimited paths to dotenv directory (default './')
89
- -y, --dynamic-path <string> dynamic variables path
90
- -o, --output-path <string> consolidated output file (follows dotenv-expand rules using loaded env vars)
91
- -d, --defaultEnvironment <string> default environment (prefix with $ to use environment variable)
92
85
  -e, --environment <string> designated environment (prefix with $ to use environment variable)
93
86
  -n, --exclude-env exclude environment-specific variables (default: false)
94
87
  -g, --exclude-global exclude global & dynamic variables (default: false)
@@ -99,6 +92,7 @@ Options:
99
92
  -l, --log log extracted variables (default: false)
100
93
  -t, --dotenv-token <string> token indicating a dotenv file (default: '.env')
101
94
  -i, --private-token <string> token indicating private variables (default: 'local')
95
+ -q, --throw-error throw error to shell & terminate sequential process (default: false)
102
96
  -h, --help display help for command
103
97
  ```
104
98
 
@@ -33,7 +33,8 @@ program
33
33
  `* Specify a default environment, override the default with an existing`,
34
34
  ` environment variable, and override both with a direct setting.`,
35
35
  `* Exclude public, private, global, environment-specific, or dynamic variables.`,
36
- `* Execute a &&-delimited series of shell commands after loading variables.`,
36
+ `* Execute a &&-delimited series of shell commands after loading variables,`,
37
+ ` optionally ignoring errors.`,
37
38
  `* Place the shell commands inside the invocation to support npm script`,
38
39
  ` arguments for other options.`,
39
40
  `* Specify the token that identifies dotenv files (e.g. '.env').`,
@@ -82,6 +83,10 @@ program
82
83
  .option(
83
84
  '-i, --private-token <string>',
84
85
  "token indicating private variables (default: 'local')"
86
+ )
87
+ .option(
88
+ '-q, --throw-error',
89
+ 'throw error to shell & terminate sequential process (default: false)'
85
90
  );
86
91
 
87
92
  // Parse CLI options from command line.
@@ -100,6 +105,7 @@ const {
100
105
  outputPath,
101
106
  paths,
102
107
  privateToken,
108
+ throwError,
103
109
  } = program.opts();
104
110
 
105
111
  if (command && program.args.length) program.error('command specified twice');
@@ -129,6 +135,8 @@ if (command || program.args.length) {
129
135
  .split('&&')
130
136
  .map((c) => parseArgsStringToArgv(c));
131
137
 
132
- for (const argv of argvs)
133
- spawn.sync(argv[0], argv.slice(1), { stdio: 'inherit' });
138
+ for (const argv of argvs) {
139
+ const { error } = spawn.sync(argv[0], argv.slice(1), { stdio: 'inherit' });
140
+ if (error && throwError) throw error;
141
+ }
134
142
  }
@@ -89,17 +89,9 @@ const getDotenv = async function () {
89
89
  if (dynamicPath && !excludeDynamic) {
90
90
  const dynamic = new Function(`return ${(await _fsExtra.default.readFile(dynamicPath)).toString()}`)()(dotenv);
91
91
  Object.keys(dynamic).forEach(key => {
92
- try {
93
- Object.assign(dotenv, {
94
- [key]: dynamic[key](dotenv)
95
- });
96
- } catch ({
97
- message
98
- }) {
99
- Object.assign(dotenv, {
100
- [key]: `ERROR: ${message}`
101
- });
102
- }
92
+ Object.assign(dotenv, {
93
+ [key]: typeof dynamic[key] === 'function' ? dynamic[key](dotenv) : dynamic[key]
94
+ });
103
95
  });
104
96
  }
105
97
 
@@ -119,7 +111,23 @@ const getDotenv = async function () {
119
111
  if (log) console.log(dotenv);
120
112
 
121
113
  // Load process.env.
122
- if (loadProcess) Object.assign(process.env, dotenv);
114
+ if (loadProcess) Object.assign(process.env, dotenv, {
115
+ getdotenvOptions: JSON.stringify({
116
+ dotenvToken,
117
+ dynamicPath,
118
+ env,
119
+ excludeDynamic,
120
+ excludeEnv,
121
+ excludeGlobal,
122
+ excludePrivate,
123
+ excludePublic,
124
+ loadProcess,
125
+ log,
126
+ outputPath,
127
+ paths,
128
+ privateToken
129
+ })
130
+ });
123
131
  return dotenv;
124
132
  };
125
133
 
@@ -201,7 +209,7 @@ const getDotenvSync = function () {
201
209
 
202
210
  // Load process.env.
203
211
  if (loadProcess) Object.assign(process.env, dotenv, {
204
- __getdotenvOptions: JSON.stringify({
212
+ getdotenvOptions: JSON.stringify({
205
213
  dotenvToken,
206
214
  dynamicPath,
207
215
  env,
@@ -99,11 +99,12 @@ export const getDotenv = async ({
99
99
  `return ${(await fs.readFile(dynamicPath)).toString()}`
100
100
  )()(dotenv);
101
101
  Object.keys(dynamic).forEach((key) => {
102
- try {
103
- Object.assign(dotenv, { [key]: dynamic[key](dotenv) });
104
- } catch ({ message }) {
105
- Object.assign(dotenv, { [key]: `ERROR: ${message}` });
106
- }
102
+ Object.assign(dotenv, {
103
+ [key]:
104
+ typeof dynamic[key] === 'function'
105
+ ? dynamic[key](dotenv)
106
+ : dynamic[key],
107
+ });
107
108
  });
108
109
  }
109
110
 
@@ -128,7 +129,24 @@ export const getDotenv = async ({
128
129
  if (log) console.log(dotenv);
129
130
 
130
131
  // Load process.env.
131
- if (loadProcess) Object.assign(process.env, dotenv);
132
+ if (loadProcess)
133
+ Object.assign(process.env, dotenv, {
134
+ getdotenvOptions: JSON.stringify({
135
+ dotenvToken,
136
+ dynamicPath,
137
+ env,
138
+ excludeDynamic,
139
+ excludeEnv,
140
+ excludeGlobal,
141
+ excludePrivate,
142
+ excludePublic,
143
+ loadProcess,
144
+ log,
145
+ outputPath,
146
+ paths,
147
+ privateToken,
148
+ }),
149
+ });
132
150
 
133
151
  return dotenv;
134
152
  };
@@ -236,7 +254,7 @@ export const getDotenvSync = ({
236
254
  // Load process.env.
237
255
  if (loadProcess)
238
256
  Object.assign(process.env, dotenv, {
239
- __getdotenvOptions: JSON.stringify({
257
+ getdotenvOptions: JSON.stringify({
240
258
  dotenvToken,
241
259
  dynamicPath,
242
260
  env,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "bin": {
4
4
  "getdotenv": "bin/getdotenv/index.js"
5
5
  },
6
- "version": "2.2.2",
6
+ "version": "2.3.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -31,31 +31,31 @@
31
31
  ],
32
32
  "license": "BSD-3-Clause",
33
33
  "dependencies": {
34
- "commander": "^10.0.0",
34
+ "commander": "^10.0.1",
35
35
  "cross-spawn": "^7.0.3",
36
36
  "dotenv": "^16.0.3",
37
37
  "dotenv-expand": "^10.0.0",
38
- "fs-extra": "^11.1.0",
39
- "string-argv": "^0.3.1",
38
+ "fs-extra": "^11.1.1",
39
+ "string-argv": "^0.3.2",
40
40
  "uuid": "^9.0.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@babel/cli": "^7.21.0",
44
- "@babel/core": "^7.21.0",
45
- "@babel/eslint-parser": "^7.19.1",
43
+ "@babel/cli": "^7.21.5",
44
+ "@babel/core": "^7.21.8",
45
+ "@babel/eslint-parser": "^7.21.8",
46
46
  "@babel/plugin-syntax-import-assertions": "^7.20.0",
47
- "@babel/preset-env": "^7.20.2",
47
+ "@babel/preset-env": "^7.21.5",
48
48
  "@babel/register": "^7.21.0",
49
- "@types/node": "^18.15.3",
49
+ "@types/node": "^20.1.1",
50
50
  "chai": "^4.3.7",
51
51
  "concat-md": "^0.5.1",
52
- "eslint": "^8.36.0",
52
+ "eslint": "^8.40.0",
53
53
  "eslint-config-standard": "^17.0.0",
54
54
  "eslint-plugin-mocha": "^10.1.0",
55
55
  "jsdoc-to-markdown": "^8.0.0",
56
56
  "mocha": "^10.2.0",
57
- "prettier": "^2.8.4",
58
- "release-it": "^15.8.0"
57
+ "prettier": "^2.8.8",
58
+ "release-it": "^15.10.3"
59
59
  },
60
60
  "exports": {
61
61
  ".": {