@dotenvx/dotenvx 2.29.0 → 2.31.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.
Files changed (85) hide show
  1. package/CHANGELOG.md +24 -1
  2. package/README.md +81 -749
  3. package/package.json +5 -5
  4. package/src/cli/actions/armor/down.js +1 -1
  5. package/src/cli/actions/armor/move.js +1 -1
  6. package/src/cli/actions/armor/open.js +1 -1
  7. package/src/cli/actions/armor/pull.js +1 -1
  8. package/src/cli/actions/armor/push.js +1 -1
  9. package/src/cli/actions/armor/up.js +1 -1
  10. package/src/cli/actions/{validate.js → check.js} +5 -5
  11. package/src/cli/actions/curl.js +2 -2
  12. package/src/cli/actions/decrypt.js +4 -10
  13. package/src/cli/actions/del.js +3 -5
  14. package/src/cli/actions/encrypt.js +4 -10
  15. package/src/cli/actions/ext/genexample.js +1 -1
  16. package/src/cli/actions/ext/prebuild.js +1 -1
  17. package/src/cli/actions/ext/scan.js +2 -3
  18. package/src/cli/actions/feedback.js +42 -0
  19. package/src/cli/actions/get.js +4 -7
  20. package/src/cli/actions/init.js +56 -2
  21. package/src/cli/actions/keychain/down.js +1 -1
  22. package/src/cli/actions/keychain/pull.js +1 -1
  23. package/src/cli/actions/keychain/push.js +1 -1
  24. package/src/cli/actions/keychain/up.js +1 -1
  25. package/src/cli/actions/keypair.js +3 -3
  26. package/src/cli/actions/lock/down.js +2 -3
  27. package/src/cli/actions/lock/up.js +2 -3
  28. package/src/cli/actions/login.js +2 -2
  29. package/src/cli/actions/logout.js +1 -1
  30. package/src/cli/actions/ls.js +1 -1
  31. package/src/cli/actions/protect.js +4 -1
  32. package/src/cli/actions/protectDocker.js +2 -2
  33. package/src/cli/actions/protectProcess.js +4 -1
  34. package/src/cli/actions/protectStdin.js +1 -0
  35. package/src/cli/actions/run.js +5 -6
  36. package/src/cli/actions/set.js +5 -9
  37. package/src/cli/actions/settings/device.js +2 -2
  38. package/src/cli/actions/settings/hostname.js +2 -2
  39. package/src/cli/actions/settings/off.js +1 -1
  40. package/src/cli/actions/settings/on.js +1 -1
  41. package/src/cli/actions/settings/path.js +2 -2
  42. package/src/cli/actions/settings/token.js +2 -2
  43. package/src/cli/actions/settings/username.js +2 -2
  44. package/src/cli/commandAction.js +16 -0
  45. package/src/cli/commands/armor.js +10 -9
  46. package/src/cli/commands/custody.js +6 -4
  47. package/src/cli/commands/ext.js +4 -3
  48. package/src/cli/commands/lock.js +3 -2
  49. package/src/cli/commands/native.js +5 -4
  50. package/src/cli/commands/primitives.js +46 -0
  51. package/src/cli/commands/settings.js +8 -7
  52. package/src/cli/dotenvx.js +45 -24
  53. package/src/lib/api/postFeedback.js +31 -0
  54. package/src/lib/envfile/discovery/discoverEnvFiles.js +29 -0
  55. package/src/lib/envfile/discovery/extractEnvKeys.js +173 -0
  56. package/src/lib/envfile/discovery/scanSource.js +79 -0
  57. package/src/lib/{helpers → envfile/parsing}/readEnvfile.js +3 -3
  58. package/src/lib/envfile/rendering/normalizeEnvfile.js +56 -0
  59. package/src/lib/envfile/rendering/renderEnvfile.js +26 -0
  60. package/src/lib/{helpers → envfile/validation}/validate.js +2 -2
  61. package/src/lib/{helpers → envfile/validation}/validateEnvfile.js +1 -1
  62. package/src/lib/events/backends/armor.js +31 -0
  63. package/src/lib/events/background.js +59 -0
  64. package/src/lib/events/catalog.js +14 -0
  65. package/src/lib/events/cli.js +40 -0
  66. package/src/lib/events/delivery.js +89 -0
  67. package/src/lib/events/index.js +73 -0
  68. package/src/lib/events/metadata.js +25 -0
  69. package/src/lib/events/sdk.js +44 -0
  70. package/src/lib/events/worker.js +29 -0
  71. package/src/lib/events/workerEnvironment.js +14 -0
  72. package/src/lib/helpers/checklist.js +9 -4
  73. package/src/lib/helpers/errors.js +1 -1
  74. package/src/lib/helpers/executeCommand.js +12 -1
  75. package/src/lib/helpers/hasPlaintextSecrets.js +2 -6
  76. package/src/lib/helpers/prompts.js +17 -0
  77. package/src/lib/main.d.ts +14 -0
  78. package/src/lib/main.js +15 -3
  79. package/src/lib/services/init.js +34 -12
  80. package/src/lib/services/validate.js +2 -2
  81. package/src/cli/actions/define.js +0 -17
  82. /package/src/lib/{grammars → envfile/parsing}/envfile.peggy +0 -0
  83. /package/src/lib/{helpers → envfile/parsing}/envfileParser.js +0 -0
  84. /package/src/lib/{helpers → envfile/parsing}/formatEnvfileSyntaxError.js +0 -0
  85. /package/src/lib/{helpers → envfile/validation}/encryptedSources.js +0 -0
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.29.0",
2
+ "version": "2.31.0",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a secure dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -45,16 +45,16 @@
45
45
  "scripts": {
46
46
  "standard": "standard",
47
47
  "standard:fix": "standard --fix",
48
- "test": "tap run --test-env=DOTENVX_NO_ARMOR=true --allow-empty-coverage --disable-coverage --timeout=60000",
48
+ "test": "tap run --test-env=DOTENVX_NO_ARMOR=true --allow-empty-coverage --allow-incomplete-coverage --disable-coverage --timeout=60000",
49
49
  "testshell": "shellspec --shell /bin/bash",
50
50
  "release:check": "npm test && npm run testshell",
51
51
  "prerelease": "npm run release:check",
52
52
  "release": "npm run release:check && standard-version",
53
- "build:envfile": "peggy --format commonjs -o src/lib/helpers/envfileParser.js src/lib/grammars/envfile.peggy"
53
+ "build:envfile": "peggy --format commonjs -o src/lib/envfile/parsing/envfileParser.js src/lib/envfile/parsing/envfile.peggy"
54
54
  },
55
55
  "funding": "https://dotenvx.com",
56
56
  "dependencies": {
57
- "@dotenvx/primitives": "^3.0.2",
57
+ "@dotenvx/primitives": "^3.0.3",
58
58
  "@dotenvx/tooling": "^1.0.3",
59
59
  "global-agent": "^3.0.0",
60
60
  "node-forge": "^1.4.0",
@@ -82,7 +82,7 @@
82
82
  },
83
83
  "standard": {
84
84
  "ignore": [
85
- "src/lib/helpers/envfileParser.js"
85
+ "src/lib/envfile/parsing/envfileParser.js"
86
86
  ]
87
87
  }
88
88
  }
@@ -31,7 +31,7 @@ async function down () {
31
31
  } catch (error) {
32
32
  if (spinner) spinner.stop()
33
33
  logger.error(error.message)
34
- process.exit(1)
34
+ return { exitCode: 1, error }
35
35
  }
36
36
  }
37
37
 
@@ -36,7 +36,7 @@ async function move () {
36
36
  } catch (error) {
37
37
  if (spinner) spinner.stop()
38
38
  logger.error(error.message)
39
- process.exit(1)
39
+ return { exitCode: 1, error }
40
40
  }
41
41
  }
42
42
 
@@ -21,7 +21,7 @@ async function open () {
21
21
  logger.success(`◌ opened (${keyDisplay})`)
22
22
  } catch (error) {
23
23
  logger.error(error.message)
24
- process.exit(1)
24
+ return { exitCode: 1, error }
25
25
  }
26
26
  }
27
27
 
@@ -31,7 +31,7 @@ async function pull () {
31
31
  } catch (error) {
32
32
  if (spinner) spinner.stop()
33
33
  logger.error(error.message)
34
- process.exit(1)
34
+ return { exitCode: 1, error }
35
35
  }
36
36
  }
37
37
 
@@ -31,7 +31,7 @@ async function push () {
31
31
  } catch (error) {
32
32
  if (spinner) spinner.stop()
33
33
  logger.error(error.message)
34
- process.exit(1)
34
+ return { exitCode: 1, error }
35
35
  }
36
36
  }
37
37
 
@@ -31,7 +31,7 @@ async function up () {
31
31
  } catch (error) {
32
32
  if (spinner) spinner.stop()
33
33
  logger.error(error.message)
34
- process.exit(1)
34
+ return { exitCode: 1, error }
35
35
  }
36
36
  }
37
37
 
@@ -7,10 +7,10 @@ const normalizeDotenvConfigQuiet = require('../../lib/helpers/normalizeDotenvCon
7
7
  const normalizeDotenvConfigConvention = require('../../lib/helpers/normalizeDotenvConfigConvention')
8
8
  const normalizeDotenvConfigIgnore = require('../../lib/helpers/normalizeDotenvConfigIgnore')
9
9
 
10
- async function validate () {
10
+ async function check () {
11
11
  const options = normalizeDotenvConfigIgnore(normalizeDotenvConfigConvention(normalizeDotenvConfigQuiet(this.opts())))
12
12
  const spinnerOptions = typeof this.optsWithGlobals === 'function' ? this.optsWithGlobals() : options
13
- const spinner = await createSpinner({ ...spinnerOptions, ...options, text: 'validating' })
13
+ const spinner = await createSpinner({ ...spinnerOptions, ...options, text: 'checking' })
14
14
  const ignore = options.ignore || []
15
15
  let errorCount = 0
16
16
 
@@ -61,15 +61,15 @@ async function validate () {
61
61
  if (spinner) spinner.stop()
62
62
 
63
63
  if (errorCount > 0) {
64
- process.exit(1)
64
+ return { exitCode: 1 }
65
65
  } else {
66
66
  logger.success(`▣ valid ${sourceSummary}`)
67
67
  }
68
68
  } catch (error) {
69
69
  if (spinner) spinner.stop()
70
70
  catchAndLog(error)
71
- process.exit(1)
71
+ return { exitCode: 1, error }
72
72
  }
73
73
  }
74
74
 
75
- module.exports = validate
75
+ module.exports = check
@@ -58,10 +58,10 @@ async function curl () {
58
58
  const text = await response.body.text()
59
59
  console.log(outputBody(text))
60
60
 
61
- if (response.statusCode >= 400) process.exitCode = 1
61
+ if (response.statusCode >= 400) return { exitCode: 1 }
62
62
  } catch (error) {
63
63
  catchAndLog(error)
64
- process.exit(1)
64
+ return { exitCode: 1, error }
65
65
  }
66
66
  }
67
67
 
@@ -59,11 +59,7 @@ async function decrypt () {
59
59
  }
60
60
  }
61
61
 
62
- if (errorCount > 0) {
63
- process.exit(1)
64
- } else {
65
- process.exit(0) // exit early
66
- }
62
+ return { exitCode: errorCount > 0 ? 1 : 0, errorCount }
67
63
  } else {
68
64
  try {
69
65
  const {
@@ -110,15 +106,13 @@ async function decrypt () {
110
106
  // do nothing - scenario when no .env files found
111
107
  }
112
108
 
113
- if (errorCount > 0) {
114
- process.exit(1)
115
- }
109
+ return { exitCode: errorCount > 0 ? 1 : 0, errorCount }
116
110
  } catch (error) {
117
111
  if (spinner) spinner.stop()
118
112
  catchAndLog(error)
119
- process.exit(1)
113
+ return { exitCode: 1, error }
120
114
  }
121
115
  }
122
116
  }
123
117
 
124
- module.exports = decrypt
118
+ module.exports = require('../../lib/events/cli')('decrypt', decrypt)
@@ -43,14 +43,12 @@ async function del (key) {
43
43
  // do nothing - scenario when no .env files found
44
44
  }
45
45
 
46
- if (errorCount > 0) {
47
- process.exit(1)
48
- }
46
+ return { exitCode: errorCount > 0 ? 1 : 0, errorCount }
49
47
  } catch (error) {
50
48
  if (spinner) spinner.stop()
51
49
  catchAndLog(error)
52
- process.exit(1)
50
+ return { exitCode: 1, error }
53
51
  }
54
52
  }
55
53
 
56
- module.exports = del
54
+ module.exports = require('../../lib/events/cli')('del', del)
@@ -43,11 +43,7 @@ async function encryptAction () {
43
43
  }
44
44
  }
45
45
 
46
- if (errorCount > 0) {
47
- process.exit(1)
48
- } else {
49
- process.exit(0) // exit early
50
- }
46
+ return { exitCode: errorCount > 0 ? 1 : 0, errorCount }
51
47
  }
52
48
 
53
49
  try {
@@ -84,14 +80,12 @@ async function encryptAction () {
84
80
  // do nothing - scenario when no .env files found
85
81
  }
86
82
 
87
- if (errorCount > 0) {
88
- process.exit(1)
89
- }
83
+ return { exitCode: errorCount > 0 ? 1 : 0, errorCount }
90
84
  } catch (error) {
91
85
  if (spinner) spinner.stop()
92
86
  catchAndLog(error)
93
- process.exit(1)
87
+ return { exitCode: 1, error }
94
88
  }
95
89
  }
96
90
 
97
- module.exports = encryptAction
91
+ module.exports = require('../../lib/events/cli')('encrypt', encryptAction)
@@ -29,7 +29,7 @@ function genexample (directory) {
29
29
  }
30
30
  } catch (error) {
31
31
  catchAndLog(error)
32
- process.exit(1)
32
+ return { exitCode: 1, error }
33
33
  }
34
34
  }
35
35
 
@@ -1,5 +1,5 @@
1
1
  const { logger } = require('../../../shared/logger')
2
- const protectDocker = require('../protectDocker')
2
+ const protectDocker = require('../../../lib/events/cli')('protect', require('../protectDocker'))
3
3
 
4
4
  module.exports = function prebuild (directory) {
5
5
  logger.warn('[DEPRECATED] dotenvx prebuild. fix: run [dotenvx protect --docker]')
@@ -14,8 +14,7 @@ function scan () {
14
14
  logger.error('gitleaks: command not found')
15
15
  logger.help('fix: install gitleaks: [brew install gitleaks]')
16
16
  logger.help('fix: other install options: [https://github.com/gitleaks/gitleaks]')
17
- process.exit(1)
18
- return
17
+ return { exitCode: 1, error }
19
18
  }
20
19
 
21
20
  let output = ''
@@ -27,7 +26,7 @@ function scan () {
27
26
  logger.error(chomp(error.stdout.toString()))
28
27
  }
29
28
 
30
- process.exit(1)
29
+ return { exitCode: 1, error }
31
30
  }
32
31
  }
33
32
 
@@ -0,0 +1,42 @@
1
+ const { logger } = require('../../shared/logger')
2
+ const Session = require('../../db/session')
3
+ const PostFeedback = require('../../lib/api/postFeedback')
4
+ const prompts = require('../../lib/helpers/prompts')
5
+ const createSpinner = require('../../lib/helpers/createSpinner')
6
+
7
+ async function feedback (body) {
8
+ let spinner
9
+ try {
10
+ if (body === undefined) {
11
+ if (!process.stdin.isTTY) {
12
+ throw new Error('provide a message: dotenvx feedback "Your feedback"')
13
+ }
14
+
15
+ body = await prompts.input({
16
+ message: 'Send feedback'
17
+ }, { input: process.stdin, output: process.stderr })
18
+ }
19
+
20
+ if (!body.trim()) {
21
+ throw new Error('feedback cannot be empty')
22
+ }
23
+
24
+ const options = this.opts()
25
+ const spinnerOptions = typeof this.optsWithGlobals === 'function' ? this.optsWithGlobals() : options
26
+ const hostname = options.hostname || new Session().hostname()
27
+ spinner = await createSpinner({ ...spinnerOptions, ...options, text: 'sending' })
28
+ await new PostFeedback(hostname, body).run()
29
+ if (spinner) spinner.stop()
30
+ logger.success('✔ Feedback sent, thanks!')
31
+ } catch (error) {
32
+ if (spinner) spinner.stop()
33
+ if (error.code === 'PROMPT_CANCELLED') {
34
+ return { exitCode: 130, error }
35
+ }
36
+
37
+ logger.error(error.message || error)
38
+ return { exitCode: 1, error }
39
+ }
40
+ }
41
+
42
+ module.exports = feedback
@@ -118,18 +118,15 @@ async function get (key) {
118
118
  }
119
119
  }
120
120
 
121
- if (errorCount > 0) {
122
- process.exit(1)
123
- }
121
+ return { exitCode: errorCount > 0 ? 1 : 0, errorCount }
124
122
  } catch (error) {
125
123
  if (spinner) spinner.stop()
126
124
  if (error.code === 'PROMPT_CANCELLED') {
127
- process.exit(130)
128
- return
125
+ return { exitCode: 130, error }
129
126
  }
130
127
  catchAndLog(error)
131
- process.exit(1)
128
+ return { exitCode: 1, error }
132
129
  }
133
130
  }
134
131
 
135
- module.exports = get
132
+ module.exports = require('../../lib/events/cli')('get', get)
@@ -1,3 +1,57 @@
1
- module.exports = function init () {
2
- return require('./define').apply(this, arguments)
1
+ const fs = require('node:fs')
2
+ const process = require('node:process')
3
+ const prompts = require('../../lib/helpers/prompts')
4
+ const initEnvfile = require('../../lib/services/init')
5
+ const scanSource = require('../../lib/envfile/discovery/scanSource')
6
+ const discoverEnvFiles = require('../../lib/envfile/discovery/discoverEnvFiles')
7
+ const createSpinner = require('../../lib/helpers/createSpinner')
8
+ const { logger } = require('../../shared/logger')
9
+ const catchAndLog = require('../../lib/helpers/catchAndLog')
10
+
11
+ module.exports = async function init () {
12
+ const envFile = this.opts().envFile
13
+ const interactive = !process.env.CI && process.stdin.isTTY && process.stderr.isTTY
14
+ let spinner
15
+
16
+ try {
17
+ if (fs.lstatSync('Envfile', { throwIfNoEntry: false })) {
18
+ logger.info('○ Envfile already exists (unchanged)')
19
+ return
20
+ }
21
+
22
+ let envFiles
23
+ let sourceKeys = []
24
+ let scanCode = false
25
+ const onFile = filename => {
26
+ if (spinner) spinner.text = `scanning ${filename}`
27
+ }
28
+ if (interactive && !envFile) {
29
+ const candidates = discoverEnvFiles()
30
+ const selected = await prompts.multiselect({
31
+ message: 'Create Envfile from .env files and code',
32
+ submitLabel: 'Create Envfile',
33
+ choices: [...candidates, { name: 'code ./**/* (env references)', value: '__scan_source' }],
34
+ initial: [...candidates, '__scan_source']
35
+ })
36
+ envFiles = selected.filter(value => value !== '__scan_source')
37
+ scanCode = selected.includes('__scan_source')
38
+ }
39
+
40
+ const options = this.opts()
41
+ const spinnerOptions = typeof this.optsWithGlobals === 'function' ? this.optsWithGlobals() : options
42
+ spinner = await createSpinner({ ...spinnerOptions, ...options, text: 'scanning' })
43
+ if (scanCode) {
44
+ const { keys } = await scanSource({ onFile })
45
+ sourceKeys = keys
46
+ }
47
+
48
+ const { created } = initEnvfile({ envFile, envFiles, sourceKeys, onFile })
49
+ if (spinner) spinner.stop()
50
+ if (created) logger.success('◈ created (Envfile)')
51
+ else logger.info('○ Envfile already exists (unchanged)')
52
+ } catch (error) {
53
+ if (spinner) spinner.stop()
54
+ catchAndLog(error)
55
+ return { exitCode: 1, error }
56
+ }
3
57
  }
@@ -23,7 +23,7 @@ async function down () {
23
23
  } catch (error) {
24
24
  if (spinner) spinner.stop()
25
25
  logger.error(error.message)
26
- process.exit(1)
26
+ return { exitCode: 1, error }
27
27
  }
28
28
  }
29
29
 
@@ -23,7 +23,7 @@ async function pull () {
23
23
  } catch (error) {
24
24
  if (spinner) spinner.stop()
25
25
  logger.error(error.message)
26
- process.exit(1)
26
+ return { exitCode: 1, error }
27
27
  }
28
28
  }
29
29
 
@@ -23,7 +23,7 @@ async function push () {
23
23
  } catch (error) {
24
24
  if (spinner) spinner.stop()
25
25
  logger.error(error.message)
26
- process.exit(1)
26
+ return { exitCode: 1, error }
27
27
  }
28
28
  }
29
29
 
@@ -23,7 +23,7 @@ async function up () {
23
23
  } catch (error) {
24
24
  if (spinner) spinner.stop()
25
25
  logger.error(error.message)
26
- process.exit(1)
26
+ return { exitCode: 1, error }
27
27
  }
28
28
  }
29
29
 
@@ -65,7 +65,7 @@ async function keypair (key) {
65
65
  } else {
66
66
  if (results === undefined) {
67
67
  console.log('')
68
- process.exit(1)
68
+ return { exitCode: 1 }
69
69
  } else if (options.format === 'colon' && key) {
70
70
  console.log(`${key}:${results}`)
71
71
  } else {
@@ -75,8 +75,8 @@ async function keypair (key) {
75
75
  } catch (error) {
76
76
  if (spinner) spinner.stop()
77
77
  catchAndLog(error)
78
- process.exit(1)
78
+ return { exitCode: 1, error }
79
79
  }
80
80
  }
81
81
 
82
- module.exports = keypair
82
+ module.exports = require('../../lib/events/cli')('keypair', keypair)
@@ -42,12 +42,11 @@ async function down () {
42
42
  }
43
43
  } catch (error) {
44
44
  if (error.code === 'PROMPT_CANCELLED') {
45
- process.exit(130)
46
- return
45
+ return { exitCode: 130, error }
47
46
  }
48
47
 
49
48
  logger.error(error.message)
50
- process.exit(1)
49
+ return { exitCode: 1, error }
51
50
  }
52
51
  }
53
52
 
@@ -50,12 +50,11 @@ async function up () {
50
50
  }
51
51
  } catch (error) {
52
52
  if (error.code === 'PROMPT_CANCELLED') {
53
- process.exit(130)
54
- return
53
+ return { exitCode: 130, error }
55
54
  }
56
55
 
57
56
  logger.error(error.message)
58
- process.exit(1)
57
+ return { exitCode: 1, error }
59
58
  }
60
59
  }
61
60
 
@@ -45,7 +45,7 @@ async function login () {
45
45
  cleanupOpenKeyListener()
46
46
  if (spinner) spinner.stop()
47
47
  logger.success(`◉ logged in (${data.username})`)
48
- process.exit(0)
48
+ return { exitCode: 0 }
49
49
  } catch (error) {
50
50
  cleanupOpenKeyListener()
51
51
  if (spinner) spinner.stop()
@@ -57,7 +57,7 @@ async function login () {
57
57
  if (error.stack) {
58
58
  logger.debug(error.stack)
59
59
  }
60
- process.exit(1)
60
+ return { exitCode: 1, error }
61
61
  }
62
62
  }
63
63
 
@@ -30,7 +30,7 @@ async function logout () {
30
30
  if (error.stack) {
31
31
  logger.debug(error.stack)
32
32
  }
33
- process.exit(1)
33
+ return { exitCode: 1, error }
34
34
  }
35
35
  }
36
36
 
@@ -69,7 +69,7 @@ async function ls (directory) {
69
69
  } catch (error) {
70
70
  if (spinner) spinner.stop()
71
71
  catchAndLog(error)
72
- process.exit(1)
72
+ return { exitCode: 1, error }
73
73
  }
74
74
  }
75
75
 
@@ -6,7 +6,7 @@ const catchAndLog = require('../../lib/helpers/catchAndLog')
6
6
  const settings = require('../../lib/helpers/protectSettings')
7
7
  const createSpinner = require('../../lib/helpers/createSpinner')
8
8
 
9
- module.exports = async function protect (directory) {
9
+ async function protect (directory) {
10
10
  if (this.opts().docker) return require('./protectDocker').call(this, directory)
11
11
  const filterOptions = typeof this.optsWithGlobals === 'function' ? this.optsWithGlobals() : this.opts()
12
12
  if (this.opts().gitProcess) return require('./protectProcess')(filterOptions)
@@ -68,5 +68,8 @@ module.exports = async function protect (directory) {
68
68
  if (spinner) spinner.stop()
69
69
  catchAndLog(error)
70
70
  process.exitCode = 1
71
+ return { error }
71
72
  }
72
73
  }
74
+
75
+ module.exports = require('../../lib/events/cli')('protect', protect)
@@ -3,7 +3,7 @@ const { logger } = require('../../shared/logger')
3
3
  const Prebuild = require('../../lib/services/prebuild')
4
4
  const catchAndLog = require('../../lib/helpers/catchAndLog')
5
5
 
6
- function protectDocker (directory) {
6
+ async function protectDocker (directory) {
7
7
  // debug args
8
8
  logger.debug(`directory: ${directory}`)
9
9
 
@@ -23,7 +23,7 @@ function protectDocker (directory) {
23
23
  logger.success(successMessage)
24
24
  } catch (error) {
25
25
  catchAndLog(error)
26
- process.exit(1)
26
+ return { exitCode: 1, error }
27
27
  }
28
28
  }
29
29
 
@@ -27,6 +27,7 @@ module.exports = async function protectProcess (options = {}) {
27
27
  let spinner
28
28
  let started = false
29
29
  let failed = false
30
+ let errorCount = 0
30
31
  let activeRequest = false
31
32
  let reported = false
32
33
  const checkedFiles = new Set()
@@ -78,7 +79,7 @@ module.exports = async function protectProcess (options = {}) {
78
79
  await packet(null)
79
80
  while (true) {
80
81
  const headers = await list(true)
81
- if (headers === null) return
82
+ if (headers === null) return { errorCount }
82
83
  activeRequest = true
83
84
  const fields = new Map(lines(headers).map(line => {
84
85
  const index = line.indexOf('=')
@@ -94,6 +95,7 @@ module.exports = async function protectProcess (options = {}) {
94
95
  // Checkout must remain a byte-for-byte passthrough, even for existing plaintext history.
95
96
  if (command === 'clean' && !check(fields.get('pathname'), content, stop)) {
96
97
  failed = true
98
+ errorCount++
97
99
  await packet('status=error\n')
98
100
  await packet(null)
99
101
  activeRequest = false
@@ -116,6 +118,7 @@ module.exports = async function protectProcess (options = {}) {
116
118
  logger.error('Git protection filter protocol failed')
117
119
  process.exitCode = 1
118
120
  process.stdin.destroy()
121
+ return { error: { code: 'GIT_FILTER_PROTOCOL_FAILED' } }
119
122
  } finally {
120
123
  finish()
121
124
  process.removeListener('exit', onExit)
@@ -53,6 +53,7 @@ async function protectStdin (filepath, options = {}) {
53
53
  stop()
54
54
  logger.error(error.message)
55
55
  process.exitCode = 1
56
+ return { error }
56
57
  } finally {
57
58
  stop()
58
59
  }
@@ -95,7 +95,7 @@ async function run () {
95
95
  logger.error(`ambiguous command due to missing '--' separator. try [dotenvx run -f ${realExample} -- yourcommand]`)
96
96
  }
97
97
 
98
- process.exit(1)
98
+ return { exitCode: 1 }
99
99
  }
100
100
 
101
101
  try {
@@ -214,18 +214,17 @@ async function run () {
214
214
  if (closeProxy) await closeProxy()
215
215
  if (spinner) spinner.stop()
216
216
  if (error.code === 'PROMPT_CANCELLED') {
217
- process.exit(130)
218
- return
217
+ return { exitCode: 130, error }
219
218
  }
220
219
  catchAndLog(error)
221
- process.exit(1)
220
+ return { exitCode: 1, error }
222
221
  }
223
222
 
224
223
  try {
225
- await executeCommand(commandArgs, commandEnv, sensitiveValues, closeProxy)
224
+ return await executeCommand(commandArgs, commandEnv, sensitiveValues, closeProxy)
226
225
  } finally {
227
226
  if (closeProxy) await closeProxy()
228
227
  }
229
228
  }
230
229
 
231
- module.exports = run
230
+ module.exports = require('../../lib/events/cli')('run', run)