@dotenvx/dotenvx 1.16.0 → 1.17.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/CHANGELOG.md CHANGED
@@ -2,7 +2,19 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
- ## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.16.0...main)
5
+ ## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.17.0...main)
6
+
7
+ ## 1.17.0
8
+
9
+ ### Added
10
+
11
+ * add `--format=eval` option for `get` ([#393](https://github.com/dotenvx/dotenvx/pull/393))
12
+
13
+ ## 1.16.1
14
+
15
+ ### Changed
16
+
17
+ * suppress stderr using `options.stdio` ([#391](https://github.com/dotenvx/dotenvx/pull/391))
6
18
 
7
19
  ## 1.16.0
8
20
 
package/README.md CHANGED
@@ -1072,6 +1072,33 @@ More examples
1072
1072
  ```
1073
1073
 
1074
1074
  </details>
1075
+ * <details><summary>`get --format eval`</summary><br>
1076
+
1077
+ Return an `eval`-ready shell formatted response of all key/value pairs in a `.env` file.
1078
+
1079
+ ```sh
1080
+ $ echo "HELLO=World" > .env
1081
+ $ echo "KEY=value" >> .env
1082
+
1083
+ $ dotenvx get --format eval
1084
+ HELLO="World"
1085
+ KEY="value"
1086
+ ```
1087
+
1088
+ Note that this exports newlines and quoted strings.
1089
+
1090
+ This can be useful for more complex .env values (spaces, escaped characters, quotes, etc) combined with `eval` on the command line.
1091
+
1092
+ ```
1093
+ $ echo "console.log('Hello ' + process.env.KEY + ' ' + process.env.HELLO)" > index.js
1094
+ $ eval $(dotenvx get --format=eval) node index.js
1095
+ Hello value World
1096
+ ```
1097
+
1098
+ Be careful with `eval` as it allows for arbitrary execution of commands. Prefer `dotenvx run --` but in some cases `eval` is a sharp knife that is useful to have.
1099
+
1100
+ </details>
1101
+
1075
1102
  * <details><summary>`get --all`</summary><br>
1076
1103
 
1077
1104
  Return preset machine envs as well.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.16.0",
2
+ "version": "1.17.0",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -1,6 +1,7 @@
1
1
  const { logger } = require('./../../shared/logger')
2
2
 
3
3
  const conventions = require('./../../lib/helpers/conventions')
4
+ const escape = require('./../../lib/helpers/escape')
4
5
 
5
6
  const main = require('./../../lib/main')
6
7
 
@@ -23,8 +24,15 @@ function get (key) {
23
24
  const results = main.get(key, envs, options.overload, process.env.DOTENV_KEY, options.all)
24
25
 
25
26
  if (typeof results === 'object' && results !== null) {
26
- // inline shell format - env $(dotenvx get --format shell) your-command
27
- if (options.format === 'shell') {
27
+ if (options.format === 'eval') {
28
+ let inline = ''
29
+ for (const [key, value] of Object.entries(results)) {
30
+ inline += `${key}=${escape(value)}\n`
31
+ }
32
+ inline = inline.trim()
33
+
34
+ console.log(inline)
35
+ } else if (options.format === 'shell') {
28
36
  let inline = ''
29
37
  for (const [key, value] of Object.entries(results)) {
30
38
  inline += `${key}=${value} `
@@ -32,7 +40,6 @@ function get (key) {
32
40
  inline = inline.trim()
33
41
 
34
42
  console.log(inline)
35
- // json format
36
43
  } else {
37
44
  let space = 0
38
45
  if (options.prettyPrint) {
@@ -75,7 +75,7 @@ program.command('get')
75
75
  .option('--convention <name>', 'load a .env convention (available conventions: [\'nextjs\'])')
76
76
  .option('-a, --all', 'include all machine envs as well')
77
77
  .option('-pp, --pretty-print', 'pretty print output')
78
- .option('--format <type>', 'format of the output (json, shell)', 'json')
78
+ .option('--format <type>', 'format of the output (json, shell, eval)', 'json')
79
79
  .action(function (...args) {
80
80
  this.envs = envs
81
81
 
@@ -0,0 +1,5 @@
1
+ function escape (value) {
2
+ return JSON.stringify(value)
3
+ }
4
+
5
+ module.exports = escape
@@ -286,7 +286,7 @@ class Run {
286
286
  } catch (_e) {
287
287
  try {
288
288
  // if installed as binary cli
289
- privateKey = childProcess.execSync(`dotenvx-pro keypair ${privateKeyName} -f ${envFilepath} 2>/dev/null`).toString().trim()
289
+ privateKey = childProcess.execSync(`dotenvx-pro keypair ${privateKeyName} -f ${envFilepath}`, { stdio: ['pipe', 'pipe', 'ignore'] }).toString().trim()
290
290
  } catch (_e) {
291
291
  // fallback to local KeyPair - smart enough to handle process.env, .env.keys, etc
292
292
  privateKey = new Keypair(envFilepath, privateKeyName).run()