@dotenvx/dotenvx 0.14.1 → 0.15.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 CHANGED
@@ -280,6 +280,23 @@ More examples
280
280
  $ git dotenvx run -- npm start
281
281
  ```
282
282
 
283
+ </details>
284
+ * <details><summary>Variable Expansion</summary><br>
285
+
286
+ Reference and expand variables already on your machine for use in your .env file.
287
+
288
+ ```ini
289
+ DATABASE_URL="postgres://${USER}@localhost/my_database"
290
+ ```
291
+ ```js
292
+ console.log('DATABASE_URL', process.env.DATABASE_URL)
293
+ ```
294
+ ```sh
295
+ $ USER=username dotenvx run --debug -- node index.js
296
+ [dotenvx@0.14.1] injecting env (1) from .env
297
+ DATABASE_URL postgres://username@localhost/my_database
298
+ ```
299
+
283
300
  </details>
284
301
 
285
302
  &nbsp;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.14.1",
2
+ "version": "0.15.1",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -23,6 +23,7 @@
23
23
  "standard:fix": "standard --fix",
24
24
  "test": "jest --verbose"
25
25
  },
26
+ "funding": "Have you seen dotenvx.com? run anywhere, cross-platform, and encrypted envs.",
26
27
  "dependencies": {
27
28
  "@inquirer/prompts": "^3.3.0",
28
29
  "axios": "^1.6.2",
@@ -30,12 +31,12 @@
30
31
  "clipboardy": "^2.3.0",
31
32
  "commander": "^11.1.0",
32
33
  "conf": "^10.2.0",
33
- "dotenv": "^16.4.0",
34
+ "dotenv": "^16.4.2",
35
+ "dotenv-expand": "^11.0.2",
34
36
  "execa": "^5.1.1",
35
37
  "ignore": "^5.3.0",
36
38
  "open": "^8.4.2",
37
39
  "ora": "^5.4.1",
38
- "qrcode-terminal": "^0.12.0",
39
40
  "update-notifier": "^5.1.0",
40
41
  "winston": "^3.11.0",
41
42
  "xxhashjs": "^0.2.2"
@@ -68,7 +68,7 @@ async function encrypt () {
68
68
 
69
69
  let keysData = `#/!!!!!!!!!!!!!!!!!!!.env.keys!!!!!!!!!!!!!!!!!!!!!!/
70
70
  #/ DOTENV_KEYs. DO NOT commit to source control /
71
- #/ [how it works](https://dotenv.org/env-keys) /
71
+ #/ [how it works](https://dotenvx.com/env-keys) /
72
72
  #/--------------------------------------------------/\n`
73
73
 
74
74
  for (const key in dotenvKeys) {
@@ -115,7 +115,7 @@ async function encrypt () {
115
115
 
116
116
  let vaultData = `#/-------------------.env.vault---------------------/
117
117
  #/ cloud-agnostic vaulting standard /
118
- #/ [how it works](https://dotenv.org/env-vault) /
118
+ #/ [how it works](https://dotenvx.com/env-vault) /
119
119
  #/--------------------------------------------------/\n\n`
120
120
 
121
121
  for (const vault in dotenvVaults) {
@@ -27,7 +27,7 @@ async function run () {
27
27
 
28
28
  logger.debug(`decrypting encrypted env from ${filepath}`)
29
29
  // handle scenario for comma separated keys - for use with key rotation
30
- // example: DOTENV_KEY="dotenv://:key_1234@dotenv.org/vault/.env.vault?environment=prod,dotenv://:key_7890@dotenv.org/vault/.env.vault?environment=prod"
30
+ // example: DOTENV_KEY="dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=prod,dotenv://:key_7890@dotenvx.com/vault/.env.vault?environment=prod"
31
31
  const dotenvKeys = process.env.DOTENV_KEY.split(',')
32
32
  const length = dotenvKeys.length
33
33
 
@@ -53,7 +53,7 @@ async function run () {
53
53
  }
54
54
  }
55
55
  logger.debug(decrypted)
56
- const parsed = main.parse(decrypted)
56
+ const parsed = main.parseExpand(decrypted)
57
57
  const result = main.inject(process.env, parsed, options.overload)
58
58
 
59
59
  logger.successv(`injecting env (${result.injected.size}) from encrypted .env.vault`)
@@ -78,7 +78,7 @@ async function run () {
78
78
 
79
79
  try {
80
80
  const src = fs.readFileSync(filepath, { encoding: ENCODING })
81
- const parsed = main.parse(src)
81
+ const parsed = main.parseExpand(src)
82
82
  const result = main.inject(process.env, parsed, options.overload)
83
83
 
84
84
  readableFilepaths.add(envFilepath)
package/src/lib/main.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const logger = require('./../shared/logger')
2
2
  const dotenv = require('dotenv')
3
+ const dotenvExpand = require('dotenv-expand')
3
4
 
4
5
  const config = function (options) {
5
6
  return dotenv.config(options)
@@ -35,6 +36,27 @@ const parse = function (src) {
35
36
  return result
36
37
  }
37
38
 
39
+ const parseExpand = function (src) {
40
+ const parsed = dotenv.parse(src)
41
+ const expandPlease = {
42
+ processEnv: {}, // https://github.com/motdotla/dotenv-expand?tab=readme-ov-file#processenv
43
+ parsed: { ...parsed, ...process.env } // must merge process.env in order to use pre-existing envs for expansion of parsed object
44
+ }
45
+ const expanded = dotenvExpand.expand(expandPlease).parsed
46
+
47
+ // but then for logging only log the original keys existing in parsed. this feels unnecessarily complex - like dotenv-expand should support the ability to inject additional `process.env` or objects as it sees fit to the object it wants to expand
48
+ const result = {}
49
+ for (const key in parsed) {
50
+ if (Object.prototype.hasOwnProperty.call(expanded, key)) {
51
+ result[key] = expanded[key]
52
+ }
53
+ }
54
+
55
+ logger.debug(result)
56
+
57
+ return result
58
+ }
59
+
38
60
  const inject = function (processEnv = {}, parsed = {}, overload = false) {
39
61
  if (typeof parsed !== 'object') {
40
62
  throw new Error('OBJECT_REQUIRED: Please check the parsed argument being passed to inject')
@@ -78,5 +100,6 @@ module.exports = {
78
100
  configDotenv,
79
101
  decrypt,
80
102
  parse,
103
+ parseExpand,
81
104
  inject
82
105
  }