@dotenvx/dotenvx 0.6.13 → 0.7.2

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.13",
2
+ "version": "0.7.2",
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,52 @@ 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
+ const signals = [
23
+ 'SIGHUP', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT',
24
+ 'SIGBUS', 'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2', 'SIGTERM'
25
+ ]
27
26
 
28
- subprocess.on('close', (code) => {
29
- if (code > 0) {
30
- logger.error(`command [${subCommand.join(' ')}] failed (code: ${code})`)
27
+ logger.debug(`executing subcommand ${subCommand}`)
28
+
29
+ // handler for SIGINT
30
+ let subprocess
31
+ const sigintHandler = () => {
32
+ logger.debug('received SIGINT')
33
+
34
+ if (subprocess) {
35
+ logger.debug('sending SIGINT to subprocess')
36
+ subprocess.kill('SIGINT') // Send SIGINT to the subprocess
37
+ }
38
+ }
39
+
40
+ const handleOtherSignal = (signal) => {
41
+ logger.debug(`received ${signal}`)
42
+ }
43
+
44
+ try {
45
+ const subprocess = execa(subCommand[0], subCommand.slice(1), {
46
+ stdio: 'inherit',
47
+ env: { ...process.env, ...env }
48
+ })
49
+
50
+ process.on('SIGINT', sigintHandler)
51
+
52
+ signals.forEach(signal => {
53
+ process.on(signal, () => handleOtherSignal(signal))
54
+ })
55
+
56
+ // Wait for the subprocess to finish
57
+ const { exitCode } = await subprocess
58
+
59
+ if (exitCode !== 0) {
60
+ logger.debug(`received exitCode ${exitCode}`)
61
+ throw new Error(`Command failed with exit code ${exitCode}`)
62
+ }
63
+ } catch (error) {
64
+ if (error.signal !== 'SIGINT') {
65
+ logger.error(error.message)
66
+ logger.error(`command [${subCommand.join(' ')}] failed`)
31
67
  logger.error('')
32
68
  logger.error(` try without dotenvx: [${subCommand.join(' ')}]`)
33
69
  logger.error('')
@@ -35,20 +71,12 @@ const executeCommand = function (subCommand, env) {
35
71
  logger.error(`<${REPORT_ISSUE_LINK}>`)
36
72
  }
37
73
 
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
- })
74
+ // Exit with the error code from the subprocess, or 1 if unavailable
75
+ process.exit(error.exitCode || 1)
76
+ } finally {
77
+ // Clean up: Remove the SIGINT handler
78
+ process.removeListener('SIGINT', sigintHandler)
79
+ }
52
80
  }
53
81
 
54
82
  const pluralize = function (word, count) {