@dotenvx/dotenvx 1.19.0 → 1.19.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/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.19.0...main)
5
+ ## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.19.2...main)
6
+
7
+ ## 1.19.2
8
+
9
+ ### Changed
10
+
11
+ * forward additional signals like `SIGUSR2` ([#403](https://github.com/dotenvx/dotenvx/pull/403))
12
+
13
+ ## 1.19.1
14
+
15
+ ### Changed
16
+
17
+ * if `SIGTERM` or `SIGINT` sent, don't bubble wrapped process error ([#402](https://github.com/dotenvx/dotenvx/pull/402))
6
18
 
7
19
  ## 1.19.0
8
20
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.19.0",
2
+ "version": "1.19.2",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -1,10 +1,8 @@
1
- const fs = require('fs')
1
+ const fsx = require('./../../lib/helpers/fsx')
2
2
  const { logger } = require('./../../shared/logger')
3
3
 
4
4
  const main = require('./../../lib/main')
5
5
 
6
- const ENCODING = 'utf8'
7
-
8
6
  function decrypt () {
9
7
  const options = this.opts()
10
8
  logger.debug(`options: ${JSON.stringify(options)}`)
@@ -52,7 +50,7 @@ function decrypt () {
52
50
  logger.error(processedEnvFile.error.message)
53
51
  }
54
52
  } else if (processedEnvFile.changed) {
55
- fs.writeFileSync(processedEnvFile.filepath, processedEnvFile.envSrc, ENCODING)
53
+ fsx.writeFileX(processedEnvFile.filepath, processedEnvFile.envSrc)
56
54
 
57
55
  logger.verbose(`decrypted ${processedEnvFile.envFilepath} (${processedEnvFile.filepath})`)
58
56
  } else {
@@ -1,12 +1,10 @@
1
- const fs = require('fs')
1
+ const fsx = require('./../../lib/helpers/fsx')
2
2
  const { logger } = require('./../../shared/logger')
3
3
 
4
4
  const main = require('./../../lib/main')
5
5
 
6
6
  const isIgnoringDotenvKeys = require('../../lib/helpers/isIgnoringDotenvKeys')
7
7
 
8
- const ENCODING = 'utf8'
9
-
10
8
  function encrypt () {
11
9
  const options = this.opts()
12
10
  logger.debug(`options: ${JSON.stringify(options)}`)
@@ -39,7 +37,7 @@ function encrypt () {
39
37
  logger.warn(processedEnvFile.error.message)
40
38
  }
41
39
  } else if (processedEnvFile.changed) {
42
- fs.writeFileSync(processedEnvFile.filepath, processedEnvFile.envSrc, ENCODING)
40
+ fsx.writeFileX(processedEnvFile.filepath, processedEnvFile.envSrc)
43
41
 
44
42
  logger.verbose(`encrypted ${processedEnvFile.envFilepath} (${processedEnvFile.filepath})`)
45
43
  } else {
@@ -1,9 +1,7 @@
1
- const fs = require('fs')
1
+ const fsx = require('./../../../lib/helpers/fsx')
2
2
  const main = require('./../../../lib/main')
3
3
  const { logger } = require('./../../../shared/logger')
4
4
 
5
- const ENCODING = 'utf8'
6
-
7
5
  function genexample (directory) {
8
6
  logger.debug(`directory: ${directory}`)
9
7
 
@@ -20,7 +18,7 @@ function genexample (directory) {
20
18
 
21
19
  logger.verbose(`loading env from ${envFile}`)
22
20
 
23
- fs.writeFileSync(exampleFilepath, envExampleFile, ENCODING)
21
+ fsx.writeFileX(exampleFilepath, envExampleFile)
24
22
 
25
23
  if (addedKeys.length > 0) {
26
24
  logger.success(`updated .env.example (${addedKeys.length})`)
@@ -1,4 +1,4 @@
1
- const fs = require('fs')
1
+ const fsx = require('./../../../lib/helpers/fsx')
2
2
 
3
3
  const FORMATS = ['.env*', '!.env.vault']
4
4
  const { logger } = require('./../../../shared/logger')
@@ -11,21 +11,21 @@ class Generic {
11
11
  }
12
12
 
13
13
  append (str) {
14
- fs.appendFileSync(this.filename, `\n${str}`)
14
+ fsx.appendFileSync(this.filename, `\n${str}`)
15
15
  }
16
16
 
17
17
  run () {
18
- if (!fs.existsSync(this.filename)) {
18
+ if (!fsx.existsSync(this.filename)) {
19
19
  if (this.touchFile === true) {
20
20
  logger.info(`creating ${this.filename}`)
21
21
 
22
- fs.writeFileSync(this.filename, '')
22
+ fsx.writeFileX(this.filename, '')
23
23
  } else {
24
24
  return
25
25
  }
26
26
  }
27
27
 
28
- const lines = fs.readFileSync(this.filename, 'utf8').split(/\r?\n/)
28
+ const lines = fsx.readFileX(this.filename).split(/\r?\n/)
29
29
  this.formats.forEach(format => {
30
30
  if (!lines.includes(format.trim())) {
31
31
  logger.info(`appending ${format} to ${this.filename}`)
@@ -1,4 +1,4 @@
1
- const fs = require('fs')
1
+ const fsx = require('./../../../lib/helpers/fsx')
2
2
 
3
3
  const ignore = require('ignore')
4
4
 
@@ -10,7 +10,7 @@ function prebuild () {
10
10
  logger.debug(`options: ${JSON.stringify(options)}`)
11
11
 
12
12
  // 1. check for .dockerignore file
13
- if (!fs.existsSync('.dockerignore')) {
13
+ if (!fsx.existsSync('.dockerignore')) {
14
14
  logger.errorvpb('.dockerignore missing')
15
15
  logger.help2('? add it with [touch .dockerignore]')
16
16
  process.exit(1)
@@ -19,8 +19,8 @@ function prebuild () {
19
19
 
20
20
  // 2. check .env* files against .dockerignore file
21
21
  let warningCount = 0
22
- const ig = ignore().add(fs.readFileSync('.dockerignore').toString())
23
- const files = fs.readdirSync(process.cwd())
22
+ const ig = ignore().add(fsx.readFileX('.dockerignore'))
23
+ const files = fsx.readdirSync(process.cwd())
24
24
  const dotenvFiles = files.filter(file => file.match(/^\.env(\..+)?$/))
25
25
  dotenvFiles.forEach(file => {
26
26
  // check if that file is being ignored
@@ -1,12 +1,10 @@
1
- const fs = require('fs')
1
+ const fsx = require('./../../lib/helpers/fsx')
2
2
  const { logger } = require('./../../shared/logger')
3
3
 
4
4
  const main = require('./../../lib/main')
5
5
 
6
6
  const isIgnoringDotenvKeys = require('../../lib/helpers/isIgnoringDotenvKeys')
7
7
 
8
- const ENCODING = 'utf8'
9
-
10
8
  function set (key, value) {
11
9
  logger.debug(`key: ${key}`)
12
10
  logger.debug(`value: ${value}`)
@@ -44,7 +42,7 @@ function set (key, value) {
44
42
  logger.warn(processedEnvFile.error.message)
45
43
  }
46
44
  } else {
47
- fs.writeFileSync(processedEnvFile.filepath, processedEnvFile.envSrc, ENCODING)
45
+ fsx.writeFileX(processedEnvFile.filepath, processedEnvFile.envSrc)
48
46
 
49
47
  logger.verbose(`${processedEnvFile.key} set${withEncryption} (${processedEnvFile.envFilepath})`)
50
48
  logger.debug(`${processedEnvFile.key} set${withEncryption} to ${processedEnvFile.value} (${processedEnvFile.envFilepath})`)
@@ -11,33 +11,33 @@ async function executeCommand (commandArgs, env) {
11
11
 
12
12
  logger.debug(`executing process command [${commandArgs.join(' ')}]`)
13
13
 
14
- // handler for SIGINT
15
- let commandProcess
14
+ let child
15
+ let signalSent
16
+
17
+ /* c8 ignore start */
16
18
  const sigintHandler = () => {
17
19
  logger.debug('received SIGINT')
18
20
  logger.debug('checking command process')
19
- logger.debug(commandProcess)
21
+ logger.debug(child)
20
22
 
21
- if (commandProcess) {
23
+ if (child) {
22
24
  logger.debug('sending SIGINT to command process')
23
- commandProcess.kill('SIGINT') // Send SIGINT to the command process
24
- /* c8 ignore start */
25
+ signalSent = 'SIGINT'
26
+ child.kill('SIGINT') // Send SIGINT to the command process
25
27
  } else {
26
28
  logger.debug('no command process to send SIGINT to')
27
29
  }
28
- /* c8 ignore stop */
29
30
  }
30
- // handler for SIGTERM
31
31
 
32
- /* c8 ignore start */
33
32
  const sigtermHandler = () => {
34
33
  logger.debug('received SIGTERM')
35
34
  logger.debug('checking command process')
36
- logger.debug(commandProcess)
35
+ logger.debug(child)
37
36
 
38
- if (commandProcess) {
37
+ if (child) {
39
38
  logger.debug('sending SIGTERM to command process')
40
- commandProcess.kill('SIGTERM') // Send SIGTEM to the command process
39
+ signalSent = 'SIGTERM'
40
+ child.kill('SIGTERM') // Send SIGTERM to the command process
41
41
  } else {
42
42
  logger.debug('no command process to send SIGTERM to')
43
43
  }
@@ -45,6 +45,7 @@ async function executeCommand (commandArgs, env) {
45
45
 
46
46
  const handleOtherSignal = (signal) => {
47
47
  logger.debug(`received ${signal}`)
48
+ child.kill(signal)
48
49
  }
49
50
  /* c8 ignore stop */
50
51
 
@@ -73,7 +74,7 @@ async function executeCommand (commandArgs, env) {
73
74
  }
74
75
  }
75
76
 
76
- commandProcess = execute.execa(commandArgs[0], commandArgs.slice(1), {
77
+ child = execute.execa(commandArgs[0], commandArgs.slice(1), {
77
78
  stdio: 'inherit',
78
79
  env: { ...process.env, ...env }
79
80
  })
@@ -86,7 +87,7 @@ async function executeCommand (commandArgs, env) {
86
87
  })
87
88
 
88
89
  // Wait for the command process to finish
89
- const { exitCode } = await commandProcess
90
+ const { exitCode } = await child
90
91
 
91
92
  if (exitCode !== 0) {
92
93
  logger.debug(`received exitCode ${exitCode}`)
@@ -94,13 +95,11 @@ async function executeCommand (commandArgs, env) {
94
95
  }
95
96
  } catch (error) {
96
97
  // no color on these errors as they can be standard errors for things like jest exiting with exitCode 1 for a single failed test.
97
- if (error.signal !== 'SIGINT' && error.signal !== 'SIGTERM') {
98
+ if (!['SIGINT', 'SIGTERM'].includes(signalSent || error.signal)) {
98
99
  if (error.code === 'ENOENT') {
99
- logger.errornocolor(`Unknown command: ${error.command}`)
100
- } else if (error.message.includes('Command failed with exit code 1')) {
101
- logger.errornocolor(`Command exited with exit code 1: ${error.command}`)
100
+ console.error(`Unknown command: ${error.command}`)
102
101
  } else {
103
- logger.errornocolor(error.message)
102
+ console.error(error.message)
104
103
  }
105
104
  }
106
105
 
@@ -1,4 +1,4 @@
1
- const fs = require('fs')
1
+ const fsx = require('./fsx')
2
2
  const path = require('path')
3
3
  const childProcess = require('child_process')
4
4
  const { logger } = require('../../shared/logger')
@@ -27,7 +27,7 @@ function executeDynamic (program, command, rawArgs) {
27
27
  // logger.warn(`[INSTALLATION_NEEDED] install dotenvx-${command} to use [dotenvx ${command}] commands 🏆`)
28
28
  // logger.help('? see installation instructions [https://github.com/dotenvx/dotenvx-pro]')
29
29
 
30
- const pro = fs.readFileSync(path.join(__dirname, './../../cli/pro.txt'), 'utf8')
30
+ const pro = fsx.readFileX(path.join(__dirname, './../../cli/pro.txt'))
31
31
  console.log(pro)
32
32
  } else {
33
33
  logger.info(`error: unknown command '${command}'`)
@@ -1,10 +1,10 @@
1
- const fs = require('fs')
1
+ const fsx = require('./fsx')
2
2
 
3
3
  const RESERVED_ENV_FILES = ['.env.vault', '.env.project', '.env.keys', '.env.me', '.env.x', '.env.example']
4
4
 
5
5
  function findEnvFiles (directory) {
6
6
  try {
7
- const files = fs.readdirSync(directory)
7
+ const files = fsx.readdirSync(directory)
8
8
  const envFiles = files.filter(file =>
9
9
  file.startsWith('.env') &&
10
10
  !file.endsWith('.previous') &&
@@ -1,4 +1,4 @@
1
- const fs = require('fs')
1
+ const fsx = require('./fsx')
2
2
  const path = require('path')
3
3
  const dotenv = require('dotenv')
4
4
 
@@ -6,8 +6,6 @@ const keyPair = require('./keyPair')
6
6
  const guessPublicKeyName = require('./guessPublicKeyName')
7
7
  const guessPrivateKeyName = require('./guessPrivateKeyName')
8
8
 
9
- const ENCODING = 'utf8'
10
-
11
9
  function findOrCreatePublicKey (envFilepath, envKeysFilepath) {
12
10
  // filename
13
11
  const filename = path.basename(envFilepath)
@@ -15,10 +13,10 @@ function findOrCreatePublicKey (envFilepath, envKeysFilepath) {
15
13
  const privateKeyName = guessPrivateKeyName(envFilepath)
16
14
 
17
15
  // src
18
- let envSrc = fs.readFileSync(envFilepath, { encoding: ENCODING })
16
+ let envSrc = fsx.readFileX(envFilepath)
19
17
  let keysSrc = ''
20
- if (fs.existsSync(envKeysFilepath)) {
21
- keysSrc = fs.readFileSync(envKeysFilepath, { encoding: ENCODING })
18
+ if (fsx.existsSync(envKeysFilepath)) {
19
+ keysSrc = fsx.readFileX(envKeysFilepath)
22
20
  }
23
21
 
24
22
  // parsed
@@ -0,0 +1,30 @@
1
+ const fs = require('fs')
2
+
3
+ const ENCODING = 'utf8'
4
+
5
+ function readFileX (filepath, encoding = null) {
6
+ if (!encoding) {
7
+ encoding = ENCODING
8
+ }
9
+
10
+ return fs.readFileSync(filepath, encoding) // utf8 default so it returns a string
11
+ }
12
+
13
+ function writeFileX (filepath, str) {
14
+ return fs.writeFileSync(filepath, str, ENCODING) // utf8 always
15
+ }
16
+
17
+ const fsx = {
18
+ chmodSync: fs.chmodSync,
19
+ existsSync: fs.existsSync,
20
+ readdirSync: fs.readdirSync,
21
+ readFileSync: fs.readFileSync,
22
+ writeFileSync: fs.writeFileSync,
23
+ appendFileSync: fs.appendFileSync,
24
+
25
+ // fsx special commands
26
+ readFileX,
27
+ writeFileX
28
+ }
29
+
30
+ module.exports = fsx
@@ -1,4 +1,4 @@
1
- const fs = require('fs')
1
+ const fsx = require('./fsx')
2
2
  const path = require('path')
3
3
 
4
4
  const HOOK_SCRIPT = `#!/bin/sh
@@ -47,22 +47,22 @@ class InstallPrecommitHook {
47
47
  }
48
48
 
49
49
  _exists () {
50
- return fs.existsSync(this.hookPath)
50
+ return fsx.existsSync(this.hookPath)
51
51
  }
52
52
 
53
53
  _currentHook () {
54
- return fs.readFileSync(this.hookPath, 'utf8')
54
+ return fsx.readFileX(this.hookPath)
55
55
  }
56
56
 
57
57
  _createHook () {
58
58
  // If the pre-commit file doesn't exist, create a new one with the hookScript
59
- fs.writeFileSync(this.hookPath, HOOK_SCRIPT)
60
- fs.chmodSync(this.hookPath, '755') // Make the file executable
59
+ fsx.writeFileX(this.hookPath, HOOK_SCRIPT)
60
+ fsx.chmodSync(this.hookPath, '755') // Make the file executable
61
61
  }
62
62
 
63
63
  _appendHook () {
64
64
  // Append 'dotenvx precommit' to the existing file
65
- fs.appendFileSync(this.hookPath, '\n' + HOOK_SCRIPT)
65
+ fsx.appendFileSync(this.hookPath, '\n' + HOOK_SCRIPT)
66
66
  }
67
67
  }
68
68
 
@@ -1,12 +1,12 @@
1
- const fs = require('fs')
1
+ const fsx = require('./fsx')
2
2
  const ignore = require('ignore')
3
3
 
4
4
  function isIgnoringDotenvKeys () {
5
- if (!fs.existsSync('.gitignore')) {
5
+ if (!fsx.existsSync('.gitignore')) {
6
6
  return false
7
7
  }
8
8
 
9
- const gitignore = fs.readFileSync('.gitignore').toString()
9
+ const gitignore = fsx.readFileX('.gitignore')
10
10
  const ig = ignore(gitignore).add(gitignore)
11
11
 
12
12
  if (!ig.ignores('.env.keys')) {
@@ -1,8 +1,7 @@
1
- const fs = require('fs')
1
+ const fsx = require('./fsx')
2
2
  const path = require('path')
3
3
  const dotenv = require('dotenv')
4
4
 
5
- const ENCODING = 'utf8'
6
5
  const PUBLIC_KEY_SCHEMA = 'DOTENV_PUBLIC_KEY'
7
6
  const PRIVATE_KEY_SCHEMA = 'DOTENV_PRIVATE_KEY'
8
7
 
@@ -18,8 +17,8 @@ function searchKeysFile (privateKeyName, envFilepath) {
18
17
  const directory = path.dirname(envFilepath)
19
18
  const envKeysFilepath = path.resolve(directory, '.env.keys')
20
19
 
21
- if (fs.existsSync(envKeysFilepath)) {
22
- const keysSrc = fs.readFileSync(envKeysFilepath, { encoding: ENCODING })
20
+ if (fsx.existsSync(envKeysFilepath)) {
21
+ const keysSrc = fsx.readFileX(envKeysFilepath)
23
22
  const keysParsed = dotenv.parse(keysSrc)
24
23
 
25
24
  if (keysParsed[privateKeyName] && keysParsed[privateKeyName].length > 0) {
@@ -29,11 +28,11 @@ function searchKeysFile (privateKeyName, envFilepath) {
29
28
  }
30
29
 
31
30
  function invertForPrivateKeyName (envFilepath) {
32
- if (!fs.existsSync(envFilepath)) {
31
+ if (!fsx.existsSync(envFilepath)) {
33
32
  return null
34
33
  }
35
34
 
36
- const envSrc = fs.readFileSync(envFilepath, { encoding: ENCODING })
35
+ const envSrc = fsx.readFileX(envFilepath)
37
36
  const envParsed = dotenv.parse(envSrc)
38
37
 
39
38
  let publicKeyName
@@ -1,8 +1,6 @@
1
- const fs = require('fs')
1
+ const fsx = require('./fsx')
2
2
  const dotenv = require('dotenv')
3
3
 
4
- const ENCODING = 'utf8'
5
-
6
4
  const guessPublicKeyName = require('./guessPublicKeyName')
7
5
 
8
6
  function searchProcessEnv (publicKeyName) {
@@ -12,8 +10,8 @@ function searchProcessEnv (publicKeyName) {
12
10
  }
13
11
 
14
12
  function searchEnvFile (publicKeyName, envFilepath) {
15
- if (fs.existsSync(envFilepath)) {
16
- const keysSrc = fs.readFileSync(envFilepath, { encoding: ENCODING })
13
+ if (fsx.existsSync(envFilepath)) {
14
+ const keysSrc = fsx.readFileX(envFilepath)
17
15
  const keysParsed = dotenv.parse(keysSrc)
18
16
 
19
17
  if (keysParsed[publicKeyName] && keysParsed[publicKeyName].length > 0) {
package/src/lib/main.js CHANGED
@@ -108,13 +108,13 @@ const config = function (options = {}) {
108
108
  if (processedEnv.error.code === 'MISSING_ENV_FILE') {
109
109
  // do not warn for conventions (too noisy)
110
110
  if (!options.convention) {
111
- logger.warnv(processedEnv.error)
111
+ logger.warnv(processedEnv.error.message)
112
112
  logger.help(
113
113
  `? add one with [echo "HELLO=World" > ${processedEnv.filepath}] and re-run [dotenvx run -- yourcommand]`
114
114
  )
115
115
  }
116
116
  } else {
117
- logger.warnv(processedEnv.error)
117
+ logger.warnv(processedEnv.error.message)
118
118
  }
119
119
  } else {
120
120
  Object.assign(parsedAll, processedEnv.injected)
@@ -1,4 +1,4 @@
1
- const fs = require('fs')
1
+ const fsx = require('./../helpers/fsx')
2
2
  const path = require('path')
3
3
  const dotenv = require('dotenv')
4
4
  const picomatch = require('picomatch')
@@ -9,8 +9,6 @@ const decryptValue = require('./../helpers/decryptValue')
9
9
  const isEncrypted = require('./../helpers/isEncrypted')
10
10
  const replace = require('./../helpers/replace')
11
11
 
12
- const ENCODING = 'utf8'
13
-
14
12
  class Decrypt {
15
13
  /**
16
14
  * @param {string|string[]} [envFile]
@@ -43,7 +41,7 @@ class Decrypt {
43
41
 
44
42
  try {
45
43
  // get the src
46
- let src = fs.readFileSync(filepath, { encoding: ENCODING })
44
+ let src = fsx.readFileX(filepath)
47
45
 
48
46
  // if DOTENV_PRIVATE_KEY_* already set in process.env then use it
49
47
  const privateKey = smartDotenvPrivateKey(envFilepath)
@@ -1,4 +1,4 @@
1
- const fs = require('fs')
1
+ const fsx = require('./../helpers/fsx')
2
2
  const path = require('path')
3
3
  const dotenv = require('dotenv')
4
4
  const picomatch = require('picomatch')
@@ -10,8 +10,6 @@ const isEncrypted = require('./../helpers/isEncrypted')
10
10
  const isPublicKey = require('./../helpers/isPublicKey')
11
11
  const replace = require('./../helpers/replace')
12
12
 
13
- const ENCODING = 'utf8'
14
-
15
13
  class Encrypt {
16
14
  /**
17
15
  * @param {string|string[]} [envFile]
@@ -44,7 +42,7 @@ class Encrypt {
44
42
 
45
43
  try {
46
44
  // get the original src
47
- let src = fs.readFileSync(filepath, { encoding: ENCODING })
45
+ let src = fsx.readFileX(filepath)
48
46
  // get/generate the public key
49
47
  const envKeysFilepath = path.join(path.dirname(filepath), '.env.keys')
50
48
  const {
@@ -57,7 +55,7 @@ class Encrypt {
57
55
  } = findOrCreatePublicKey(filepath, envKeysFilepath)
58
56
 
59
57
  // handle .env.keys write
60
- fs.writeFileSync(envKeysFilepath, keysSrc)
58
+ fsx.writeFileX(envKeysFilepath, keysSrc)
61
59
 
62
60
  src = envSrc // src was potentially modified by findOrCreatePublicKey so we set it again here
63
61
 
@@ -1,9 +1,7 @@
1
- const fs = require('fs')
1
+ const fsx = require('./../helpers/fsx')
2
2
  const path = require('path')
3
3
  const dotenv = require('dotenv')
4
4
 
5
- const ENCODING = 'utf8'
6
-
7
5
  const findEnvFiles = require('../helpers/findEnvFiles')
8
6
  const replace = require('../helpers/replace')
9
7
 
@@ -40,7 +38,7 @@ class Genexample {
40
38
 
41
39
  for (const envFilepath of envFilepaths) {
42
40
  const filepath = path.resolve(this.directory, envFilepath)
43
- if (!fs.existsSync(filepath)) {
41
+ if (!fsx.existsSync(filepath)) {
44
42
  const code = 'MISSING_ENV_FILE'
45
43
  const message = `file does not exist at [${filepath}]`
46
44
  const help = `? add it with [echo "HELLO=World" > ${envFilepath}] and then run [dotenvx genexample]`
@@ -52,7 +50,7 @@ class Genexample {
52
50
  }
53
51
 
54
52
  // get the original src
55
- let src = fs.readFileSync(filepath, { encoding: ENCODING })
53
+ let src = fsx.readFileX(filepath)
56
54
  const parsed = dotenv.parse(src)
57
55
  for (const key in parsed) {
58
56
  // used later
@@ -65,7 +63,7 @@ class Genexample {
65
63
  exampleSrc += `\n${src}`
66
64
  }
67
65
 
68
- if (!fs.existsSync(this.exampleFilepath)) {
66
+ if (!fsx.existsSync(this.exampleFilepath)) {
69
67
  // it doesn't exist so just write this first generated one
70
68
  // exampleSrc - already written to from the prior loop
71
69
  for (const key of [...keys]) {
@@ -76,7 +74,7 @@ class Genexample {
76
74
  }
77
75
  } else {
78
76
  // it already exists (which means the user might have it modified a way in which they prefer, so replace exampleSrc with their existing .env.example)
79
- exampleSrc = fs.readFileSync(this.exampleFilepath, ENCODING)
77
+ exampleSrc = fsx.readFileX(this.exampleFilepath)
80
78
 
81
79
  const parsed = dotenv.parse(exampleSrc)
82
80
  for (const key of [...keys]) {
@@ -1,5 +1,5 @@
1
1
  /* istanbul ignore file */
2
- const fs = require('fs')
2
+ const fsx = require('./../helpers/fsx')
3
3
  const ignore = require('ignore')
4
4
 
5
5
  const Ls = require('../services/ls')
@@ -32,12 +32,12 @@ class Precommit {
32
32
  let gitignore = MISSING_GITIGNORE
33
33
 
34
34
  // 1. check for .gitignore file
35
- if (!fs.existsSync('.gitignore')) {
35
+ if (!fsx.existsSync('.gitignore')) {
36
36
  const warning = new Error('.gitignore missing')
37
37
  warning.help = '? add it with [touch .gitignore]'
38
38
  warnings.push(warning)
39
39
  } else {
40
- gitignore = fs.readFileSync('.gitignore').toString()
40
+ gitignore = fsx.readFileX('.gitignore')
41
41
  }
42
42
 
43
43
  // 2. check .env* files against .gitignore file
@@ -56,7 +56,7 @@ class Precommit {
56
56
  }
57
57
  } else {
58
58
  if (file !== '.env.example' && file !== '.env.vault') {
59
- const src = fs.readFileSync(file).toString()
59
+ const src = fsx.readFileX(file)
60
60
  const encrypted = isFullyEncrypted(src)
61
61
 
62
62
  // if contents are encrypted don't raise an error
@@ -1,9 +1,8 @@
1
- const fs = require('fs')
1
+ const fsx = require('./../helpers/fsx')
2
2
  const path = require('path')
3
3
  const dotenv = require('dotenv')
4
4
  const childProcess = require('child_process')
5
5
 
6
- const ENCODING = 'utf8'
7
6
  const TYPE_ENV = 'env'
8
7
  const TYPE_ENV_FILE = 'envFile'
9
8
  const TYPE_ENV_VAULT_FILE = 'envVaultFile'
@@ -94,7 +93,7 @@ class Run {
94
93
  const filepath = path.resolve(envFilepath)
95
94
  try {
96
95
  const encoding = detectEncoding(filepath)
97
- const src = fs.readFileSync(filepath, { encoding })
96
+ const src = fsx.readFileX(filepath, { encoding })
98
97
  this.readableFilepaths.add(envFilepath)
99
98
 
100
99
  const privateKey = this._determinePrivateKey(envFilepath)
@@ -131,7 +130,7 @@ class Run {
131
130
  const filepath = path.resolve(envVaultFilepath)
132
131
  this.readableFilepaths.add(envVaultFilepath)
133
132
 
134
- if (!fs.existsSync(filepath)) {
133
+ if (!fsx.existsSync(filepath)) {
135
134
  const code = 'MISSING_ENV_VAULT_FILE'
136
135
  const message = `you set DOTENV_KEY but your .env.vault file is missing: ${filepath}`
137
136
  const error = new Error(message)
@@ -253,7 +252,7 @@ class Run {
253
252
 
254
253
  // { "DOTENV_VAULT_DEVELOPMENT": "<ciphertext>" }
255
254
  _parsedVault (filepath) {
256
- const src = fs.readFileSync(filepath, { encoding: ENCODING })
255
+ const src = fsx.readFileX(filepath)
257
256
  return dotenv.parse(src)
258
257
  }
259
258
 
@@ -1,4 +1,4 @@
1
- const fs = require('fs')
1
+ const fsx = require('./../helpers/fsx')
2
2
  const path = require('path')
3
3
 
4
4
  const dotenv = require('dotenv')
@@ -8,8 +8,6 @@ const guessPrivateKeyName = require('./../helpers/guessPrivateKeyName')
8
8
  const encryptValue = require('./../helpers/encryptValue')
9
9
  const replace = require('./../helpers/replace')
10
10
 
11
- const ENCODING = 'utf8'
12
-
13
11
  class Sets {
14
12
  constructor (key, value, envFile = '.env', encrypt = true) {
15
13
  this.key = key
@@ -36,7 +34,7 @@ class Sets {
36
34
 
37
35
  try {
38
36
  let value = this.value
39
- let src = fs.readFileSync(filepath, { encoding: ENCODING })
37
+ let src = fsx.readFileX(filepath)
40
38
  row.originalValue = dotenv.parse(src)[row.key] || null
41
39
 
42
40
  if (this.encrypt) {
@@ -51,7 +49,7 @@ class Sets {
51
49
  } = findOrCreatePublicKey(filepath, envKeysFilepath)
52
50
 
53
51
  // handle .env.keys write
54
- fs.writeFileSync(envKeysFilepath, keysSrc)
52
+ fsx.writeFileX(envKeysFilepath, keysSrc)
55
53
 
56
54
  src = envSrc // src was potentially modified by findOrCreatePublicKey so we set it again here
57
55