@dotenvx/dotenvx 0.14.0 → 0.15.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
@@ -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;
@@ -614,10 +631,10 @@ $ dotenvx hub push
614
631
 
615
632
  > Keep your `.env` files safe
616
633
 
634
+ * [`dotenvx genexample`](https://dotenvx.com/docs/features/genexample) – generate `.env.example` file
617
635
  * [`dotenvx gitignore`](https://dotenvx.com/docs/features/gitignore) – gitignore your `.env` files
618
- * [`dotenvx precommit`](https://dotenvx.com/docs/features/precommit) – prevent `.env` files from being committed to code
619
636
  * [`dotenvx prebuild`](https://dotenvx.com/docs/features/prebuild) – prevent `.env` files from being built into your docker container
620
- * `dotenvx genexample` – generate `.env.example` file (coming soon)
637
+ * [`dotenvx precommit`](https://dotenvx.com/docs/features/precommit)prevent `.env` files from being committed to code
621
638
 
622
639
  &nbsp;
623
640
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.14.0",
2
+ "version": "0.15.0",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -31,12 +31,12 @@
31
31
  "commander": "^11.1.0",
32
32
  "conf": "^10.2.0",
33
33
  "dotenv": "^16.4.0",
34
+ "dotenv-expand": "^10.0.0",
34
35
  "execa": "^5.1.1",
35
36
  "ignore": "^5.3.0",
36
37
  "open": "^8.4.2",
37
38
  "ora": "^5.4.1",
38
- "qrcode-terminal": "^0.12.0",
39
- "update-notifier": "^7.0.0",
39
+ "update-notifier": "^5.1.0",
40
40
  "winston": "^3.11.0",
41
41
  "xxhashjs": "^0.2.2"
42
42
  },
@@ -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
+ ignoreProcessEnv: true, // https://github.com/motdotla/dotenv-expand?tab=readme-ov-file#ignoreprocessenv
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
  }