@dotenvx/dotenvx 1.11.4 → 1.12.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,15 @@
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.11.4...main)
5
+ ## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.12.0...main)
6
+
7
+ ## 1.12.0
8
+
9
+ * add `dotenvx get --format shell` option ([#363](https://github.com/dotenvx/dotenvx/pull/363))
10
+
11
+ ## 1.11.5
12
+
13
+ * revert `tinyexec` for `execa` - to support usage in bun
6
14
 
7
15
  ## 1.11.4
8
16
 
package/README.md CHANGED
@@ -1041,6 +1041,31 @@ More examples
1041
1041
  {"HELLO":"World"}
1042
1042
  ```
1043
1043
 
1044
+ </details>
1045
+ * <details><summary>`get --format shell`</summary><br>
1046
+
1047
+ Return a shell formatted response of all key/value pairs in a `.env` file.
1048
+
1049
+ ```sh
1050
+ $ echo "HELLO=World\n" > .env
1051
+ $ echo "KEY=value\n" >> .env
1052
+
1053
+ $ dotenvx get --format shell
1054
+ HELLO="World" KEY="value"
1055
+ ```
1056
+
1057
+ This can be useful when combined with `env` on the command line.
1058
+
1059
+ ```
1060
+ $ env $(dotenvx get format --shell) your-command
1061
+ ```
1062
+
1063
+ or with `export`.
1064
+
1065
+ ```
1066
+ $ export $(dotenvx get format --shell) your-command
1067
+ ```
1068
+
1044
1069
  </details>
1045
1070
  * <details><summary>`get --all`</summary><br>
1046
1071
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.11.4",
2
+ "version": "1.12.0",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -39,11 +39,11 @@
39
39
  "commander": "^11.1.0",
40
40
  "dotenv": "^16.4.5",
41
41
  "eciesjs": "^0.4.6",
42
+ "execa": "^5.1.1",
42
43
  "fdir": "^6.2.0",
43
44
  "ignore": "^5.3.0",
44
45
  "object-treeify": "1.1.33",
45
46
  "picomatch": "^4.0.2",
46
- "tinyexec": "^0.3.0",
47
47
  "which": "^4.0.0"
48
48
  },
49
49
  "devDependencies": {
@@ -20,21 +20,33 @@ function get (key) {
20
20
  envs = this.envs
21
21
  }
22
22
 
23
- const value = main.get(key, envs, options.overload, process.env.DOTENV_KEY, options.all)
23
+ const results = main.get(key, envs, options.overload, process.env.DOTENV_KEY, options.all)
24
+
25
+ if (typeof results === 'object' && results !== null) {
26
+ // inline shell format - env $(dotenvx get --format shell) your-command
27
+ if (options.format === 'shell') {
28
+ let inline = ''
29
+ for (const [key, value] of Object.entries(results)) {
30
+ inline += `${key}="${value}" `
31
+ }
32
+ inline = inline.trim()
33
+
34
+ process.stdout.write(inline)
35
+ // json format
36
+ } else {
37
+ let space = 0
38
+ if (options.prettyPrint) {
39
+ space = 2
40
+ }
24
41
 
25
- if (typeof value === 'object' && value !== null) {
26
- let space = 0
27
- if (options.prettyPrint) {
28
- space = 2
42
+ process.stdout.write(JSON.stringify(results, null, space))
29
43
  }
30
-
31
- process.stdout.write(JSON.stringify(value, null, space))
32
44
  } else {
33
- if (value === undefined) {
45
+ if (results === undefined) {
34
46
  process.stdout.write('')
35
47
  process.exit(1)
36
48
  } else {
37
- process.stdout.write(value)
49
+ process.stdout.write(results)
38
50
  }
39
51
  }
40
52
  }
@@ -75,6 +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
79
  .action(function (...args) {
79
80
  this.envs = envs
80
81
 
@@ -14,12 +14,6 @@ function detectEncoding (filepath) {
14
14
  return 'utf8'
15
15
  }
16
16
 
17
- // Check if the file is entirely US-ASCII (0x00 - 0x7F), which is valid UTF-8
18
- for (let i = 0; i < buffer.length; i++) {
19
- if (buffer[i] > 0x7F) {
20
- break
21
- }
22
- }
23
17
  /* c8 ignore stop */
24
18
 
25
19
  return 'utf8'
@@ -1,3 +1,9 @@
1
- const { exec } = require('tinyexec')
1
+ const execa = require('execa')
2
2
 
3
- module.exports = { exec }
3
+ const execute = {
4
+ execa (command, args, options) {
5
+ return execa(command, args, options)
6
+ }
7
+ }
8
+
9
+ module.exports = execute
@@ -13,8 +13,6 @@ async function executeCommand (commandArgs, env) {
13
13
 
14
14
  // handler for SIGINT
15
15
  let commandProcess
16
- // workaround until error.signal gets added https://github.com/tinylibs/tinyexec/issues/28
17
- let signal
18
16
  const sigintHandler = () => {
19
17
  logger.debug('received SIGINT')
20
18
  logger.debug('checking command process')
@@ -22,7 +20,6 @@ async function executeCommand (commandArgs, env) {
22
20
 
23
21
  if (commandProcess) {
24
22
  logger.debug('sending SIGINT to command process')
25
- signal = 'SIGINT'
26
23
  commandProcess.kill('SIGINT') // Send SIGINT to the command process
27
24
  /* c8 ignore start */
28
25
  } else {
@@ -40,7 +37,6 @@ async function executeCommand (commandArgs, env) {
40
37
 
41
38
  if (commandProcess) {
42
39
  logger.debug('sending SIGTERM to command process')
43
- signal = 'SIGTERM'
44
40
  commandProcess.kill('SIGTERM') // Send SIGTEM to the command process
45
41
  } else {
46
42
  logger.debug('no command process to send SIGTERM to')
@@ -77,11 +73,9 @@ async function executeCommand (commandArgs, env) {
77
73
  }
78
74
  }
79
75
 
80
- commandProcess = execute.exec(commandArgs[0], commandArgs.slice(1), {
81
- nodeOptions: {
82
- stdio: 'inherit',
83
- env: { ...process.env, ...env }
84
- }
76
+ commandProcess = execute.execa(commandArgs[0], commandArgs.slice(1), {
77
+ stdio: 'inherit',
78
+ env: { ...process.env, ...env }
85
79
  })
86
80
 
87
81
  process.on('SIGINT', sigintHandler)
@@ -92,9 +86,7 @@ async function executeCommand (commandArgs, env) {
92
86
  })
93
87
 
94
88
  // Wait for the command process to finish
95
- // exitCode is not in the awaited result, see https://github.com/tinylibs/tinyexec/issues/27
96
- await commandProcess
97
- const { exitCode } = commandProcess
89
+ const { exitCode } = await commandProcess
98
90
 
99
91
  if (exitCode !== 0) {
100
92
  logger.debug(`received exitCode ${exitCode}`)
@@ -102,11 +94,11 @@ async function executeCommand (commandArgs, env) {
102
94
  }
103
95
  } catch (error) {
104
96
  // no color on these errors as they can be standard errors for things like jest exiting with exitCode 1 for a single failed test.
105
- if (signal !== 'SIGINT' && signal !== 'SIGTERM') {
97
+ if (error.signal !== 'SIGINT' && error.signal !== 'SIGTERM') {
106
98
  if (error.code === 'ENOENT') {
107
- logger.errornocolor(`Unknown command: ${error.path}${error.spawnargs ? ' ' + error.spawnargs.join(' ') : ''}`)
99
+ logger.errornocolor(`Unknown command: ${error.command}`)
108
100
  } else if (error.message.includes('Command failed with exit code 1')) {
109
- logger.errornocolor(`Command exited with exit code 1: ${error.path}${error.spawnargs ? ' ' + error.spawnargs.join(' ') : ''}`)
101
+ logger.errornocolor(`Command exited with exit code 1: ${error.command}`)
110
102
  } else {
111
103
  logger.errornocolor(error.message)
112
104
  }