@dotenvx/dotenvx 0.6.12 → 0.7.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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.6.12",
2
+ "version": "0.7.1",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -26,6 +26,7 @@
26
26
  "dependencies": {
27
27
  "commander": "^11.1.0",
28
28
  "dotenv": "^16.3.1",
29
+ "execa": "^5.1.1",
29
30
  "winston": "^3.11.0",
30
31
  "xxhashjs": "^0.2.2"
31
32
  },
@@ -58,7 +58,7 @@ program.command('run')
58
58
  .addHelpText('after', examples.run)
59
59
  .option('-f, --env-file <paths...>', 'path(s) to your env file(s)', '.env')
60
60
  .option('-o, --overload', 'override existing env variables')
61
- .action(function () {
61
+ .action(async function () {
62
62
  const options = this.opts()
63
63
  logger.debug('configuring options')
64
64
  logger.debug(options)
@@ -167,7 +167,7 @@ program.command('run')
167
167
  } else {
168
168
  const subCommand = process.argv.slice(commandIndex + 1)
169
169
 
170
- helpers.executeCommand(subCommand, process.env)
170
+ await helpers.executeCommand(subCommand, process.env)
171
171
  }
172
172
  })
173
173
 
@@ -1,7 +1,7 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
+ const execa = require('execa')
3
4
  const crypto = require('crypto')
4
- const { spawn } = require('child_process')
5
5
  const xxhash = require('xxhashjs')
6
6
 
7
7
  const XXHASH_SEED = 0xABCD
@@ -18,16 +18,33 @@ const resolvePath = function (filepath) {
18
18
  return path.resolve(process.cwd(), filepath)
19
19
  }
20
20
 
21
- const executeCommand = function (subCommand, env) {
22
- const subprocess = spawn(subCommand[0], subCommand.slice(1), {
23
- stdio: 'inherit',
24
- shell: true,
25
- env: { ...process.env, ...env }
26
- })
21
+ const executeCommand = async function (subCommand, env) {
22
+ // handler for SIGINT
23
+ let subprocess
24
+ const sigintHandler = () => {
25
+ if (subprocess) {
26
+ subprocess.kill('SIGINT') // Send SIGINT to the subprocess
27
+ }
28
+ }
29
+
30
+ try {
31
+ const subprocess = execa(subCommand[0], subCommand.slice(1), {
32
+ stdio: 'inherit',
33
+ env: { ...process.env, ...env }
34
+ })
35
+
36
+ process.on('SIGINT', sigintHandler)
27
37
 
28
- subprocess.on('close', (code) => {
29
- if (code > 0) {
30
- logger.error(`command [${subCommand.join(' ')}] failed (code: ${code})`)
38
+ // Wait for the subprocess to finish
39
+ const { exitCode } = await subprocess
40
+
41
+ if (exitCode !== 0) {
42
+ throw new Error(`Command failed with exit code ${exitCode}`)
43
+ }
44
+ } catch (error) {
45
+ if (error.signal !== 'SIGINT') {
46
+ logger.error(error.message)
47
+ logger.error(`command [${subCommand.join(' ')}] failed`)
31
48
  logger.error('')
32
49
  logger.error(` try without dotenvx: [${subCommand.join(' ')}]`)
33
50
  logger.error('')
@@ -35,20 +52,12 @@ const executeCommand = function (subCommand, env) {
35
52
  logger.error(`<${REPORT_ISSUE_LINK}>`)
36
53
  }
37
54
 
38
- process.exit(code)
39
- })
40
-
41
- subprocess.on('error', (err) => {
42
- logger.error(err)
43
- logger.error(`command [${subCommand.join(' ')}] failed`)
44
- logger.error('')
45
- logger.error(` try without dotenvx: [${subCommand.join(' ')}]`)
46
- logger.error('')
47
- logger.error('if that succeeds, then dotenvx is the culprit. report issue:')
48
- logger.error(`<${REPORT_ISSUE_LINK}>`)
49
-
50
- process.exit(1)
51
- })
55
+ // Exit with the error code from the subprocess, or 1 if unavailable
56
+ process.exit(error.exitCode || 1)
57
+ } finally {
58
+ // Clean up: Remove the SIGINT handler
59
+ process.removeListener('SIGINT', sigintHandler)
60
+ }
52
61
  }
53
62
 
54
63
  const pluralize = function (word, count) {