@dotenvx/dotenvx 0.3.8 → 0.3.9
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 +3 -5
- package/package.json +1 -1
- package/src/cli/dotenvx.js +9 -2
- package/src/lib/main.js +36 -6
package/README.md
CHANGED
|
@@ -94,7 +94,7 @@ More examples
|
|
|
94
94
|
```sh
|
|
95
95
|
FROM node:latest
|
|
96
96
|
RUN echo "HELLO=World" > .env && echo "console.log('Hello ' + process.env.HELLO)" > index.js
|
|
97
|
-
RUN curl -
|
|
97
|
+
RUN curl -fsS https://dotenvx.sh/ | sh
|
|
98
98
|
CMD ["dotenvx", "run", "--", "echo", "Hello $HELLO"]
|
|
99
99
|
```
|
|
100
100
|
|
|
@@ -273,14 +273,12 @@ npm i @dotenvx/dotenvx --save
|
|
|
273
273
|
3. Or download it directly as a standalone binary:
|
|
274
274
|
|
|
275
275
|
```sh
|
|
276
|
-
curl -
|
|
276
|
+
curl -fsS https://dotenvx.sh/ | sh
|
|
277
277
|
```
|
|
278
278
|
|
|
279
|
-
Remove the `!` to install where you prefer. (the `!` downloads directly into `/usr/local/bin/`)
|
|
280
|
-
|
|
281
279
|
```sh
|
|
282
280
|
# download it to `./dotenvx`
|
|
283
|
-
curl -
|
|
281
|
+
curl -fsS https://dotenvx.sh/ | sh
|
|
284
282
|
|
|
285
283
|
# check it works
|
|
286
284
|
./dotenvx help
|
package/package.json
CHANGED
package/src/cli/dotenvx.js
CHANGED
|
@@ -65,6 +65,8 @@ program.command('run')
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
const env = {}
|
|
68
|
+
const readableFilepaths = new Set()
|
|
69
|
+
const populated = new Set()
|
|
68
70
|
|
|
69
71
|
for (const envFilepath of optionEnvFile) {
|
|
70
72
|
const filepath = helpers.resolvePath(envFilepath)
|
|
@@ -79,13 +81,18 @@ program.command('run')
|
|
|
79
81
|
const parsed = main.parse(src)
|
|
80
82
|
|
|
81
83
|
logger.debug(`Populating env from ${filepath}`)
|
|
82
|
-
main.populate(process.env, parsed,
|
|
84
|
+
const result = main.populate(process.env, parsed, options.overload)
|
|
85
|
+
|
|
86
|
+
readableFilepaths.add(envFilepath)
|
|
87
|
+
result.populated.forEach(key => populated.add(key))
|
|
83
88
|
} catch (e) {
|
|
84
89
|
logger.warn(e)
|
|
85
90
|
}
|
|
86
91
|
}
|
|
87
92
|
|
|
88
|
-
|
|
93
|
+
if (readableFilepaths.size > 0) {
|
|
94
|
+
logger.info(`Injecting ${populated.size} environment variables from ${[...readableFilepaths]}`)
|
|
95
|
+
}
|
|
89
96
|
|
|
90
97
|
// Extract command and arguments after '--'
|
|
91
98
|
const commandIndex = process.argv.indexOf('--')
|
package/src/lib/main.js
CHANGED
|
@@ -13,12 +13,42 @@ const parse = function (src) {
|
|
|
13
13
|
return result
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
const populate = function (processEnv, parsed,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
const populate = function (processEnv = {}, parsed = {}, overload = false) {
|
|
17
|
+
if (typeof parsed !== 'object') {
|
|
18
|
+
throw new Error('OBJECT_REQUIRED: Please check the parsed argument being passed to populate')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const populated = new Set()
|
|
22
|
+
const preExisting = new Set()
|
|
23
|
+
|
|
24
|
+
// set processEnv
|
|
25
|
+
for (const key of Object.keys(parsed)) {
|
|
26
|
+
if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
|
|
27
|
+
if (overload === true) {
|
|
28
|
+
processEnv[key] = parsed[key]
|
|
29
|
+
populated.add(key)
|
|
30
|
+
|
|
31
|
+
logger.verbose(`${key} set`)
|
|
32
|
+
logger.debug(`${key} set to ${parsed[key]}`)
|
|
33
|
+
} else {
|
|
34
|
+
preExisting.add(key)
|
|
35
|
+
|
|
36
|
+
logger.verbose(`${key} pre-exists`)
|
|
37
|
+
logger.debug(`${key} pre-exists as ${processEnv[key]}`)
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
processEnv[key] = parsed[key]
|
|
41
|
+
populated.add(key)
|
|
42
|
+
|
|
43
|
+
logger.verbose(`${key} set`)
|
|
44
|
+
logger.debug(`${key} set to ${parsed[key]}`)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
populated,
|
|
50
|
+
preExisting
|
|
51
|
+
}
|
|
22
52
|
}
|
|
23
53
|
|
|
24
54
|
module.exports = {
|