@dotenvx/dotenvx 1.19.0 → 1.19.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/CHANGELOG.md +7 -1
- package/package.json +1 -1
- package/src/cli/actions/decrypt.js +2 -4
- package/src/cli/actions/encrypt.js +2 -4
- package/src/cli/actions/ext/genexample.js +2 -4
- package/src/cli/actions/ext/gitignore.js +5 -5
- package/src/cli/actions/ext/prebuild.js +4 -4
- package/src/cli/actions/set.js +2 -4
- package/src/lib/helpers/executeCommand.js +9 -11
- package/src/lib/helpers/executeDynamic.js +2 -2
- package/src/lib/helpers/findEnvFiles.js +2 -2
- package/src/lib/helpers/findOrCreatePublicKey.js +4 -6
- package/src/lib/helpers/fsx.js +30 -0
- package/src/lib/helpers/installPrecommitHook.js +6 -6
- package/src/lib/helpers/isIgnoringDotenvKeys.js +3 -3
- package/src/lib/helpers/smartDotenvPrivateKey.js +5 -6
- package/src/lib/helpers/smartDotenvPublicKey.js +3 -5
- package/src/lib/main.js +2 -2
- package/src/lib/services/decrypt.js +2 -4
- package/src/lib/services/encrypt.js +3 -5
- package/src/lib/services/genexample.js +5 -7
- package/src/lib/services/precommit.js +4 -4
- package/src/lib/services/run.js +4 -5
- package/src/lib/services/sets.js +3 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
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.
|
|
5
|
+
## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.19.1...main)
|
|
6
|
+
|
|
7
|
+
## 1.19.1
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
* if `SIGTERM` or `SIGINT` sent, don't bubble wrapped process error ([#402](https://github.com/dotenvx/dotenvx/pull/402))
|
|
6
12
|
|
|
7
13
|
## 1.19.0
|
|
8
14
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
const
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
14
|
+
fsx.appendFileSync(this.filename, `\n${str}`)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
run () {
|
|
18
|
-
if (!
|
|
18
|
+
if (!fsx.existsSync(this.filename)) {
|
|
19
19
|
if (this.touchFile === true) {
|
|
20
20
|
logger.info(`creating ${this.filename}`)
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
fsx.writeFileX(this.filename, '')
|
|
23
23
|
} else {
|
|
24
24
|
return
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
const lines =
|
|
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
|
|
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 (!
|
|
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(
|
|
23
|
-
const files =
|
|
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
|
package/src/cli/actions/set.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
const
|
|
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
|
-
|
|
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,8 +11,10 @@ async function executeCommand (commandArgs, env) {
|
|
|
11
11
|
|
|
12
12
|
logger.debug(`executing process command [${commandArgs.join(' ')}]`)
|
|
13
13
|
|
|
14
|
-
// handler for SIGINT
|
|
15
14
|
let commandProcess
|
|
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')
|
|
@@ -20,16 +22,13 @@ async function executeCommand (commandArgs, env) {
|
|
|
20
22
|
|
|
21
23
|
if (commandProcess) {
|
|
22
24
|
logger.debug('sending SIGINT to command process')
|
|
25
|
+
signalSent = 'SIGINT'
|
|
23
26
|
commandProcess.kill('SIGINT') // Send SIGINT to the command process
|
|
24
|
-
/* c8 ignore start */
|
|
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')
|
|
@@ -37,7 +36,8 @@ async function executeCommand (commandArgs, env) {
|
|
|
37
36
|
|
|
38
37
|
if (commandProcess) {
|
|
39
38
|
logger.debug('sending SIGTERM to command process')
|
|
40
|
-
|
|
39
|
+
signalSent = 'SIGTERM'
|
|
40
|
+
commandProcess.kill('SIGTERM') // Send SIGTERM to the command process
|
|
41
41
|
} else {
|
|
42
42
|
logger.debug('no command process to send SIGTERM to')
|
|
43
43
|
}
|
|
@@ -94,13 +94,11 @@ async function executeCommand (commandArgs, env) {
|
|
|
94
94
|
}
|
|
95
95
|
} catch (error) {
|
|
96
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.
|
|
97
|
-
if (
|
|
97
|
+
if (!['SIGINT', 'SIGTERM'].includes(signalSent || error.signal)) {
|
|
98
98
|
if (error.code === 'ENOENT') {
|
|
99
|
-
|
|
100
|
-
} else if (error.message.includes('Command failed with exit code 1')) {
|
|
101
|
-
logger.errornocolor(`Command exited with exit code 1: ${error.command}`)
|
|
99
|
+
console.error(`Unknown command: ${error.command}`)
|
|
102
100
|
} else {
|
|
103
|
-
|
|
101
|
+
console.error(error.message)
|
|
104
102
|
}
|
|
105
103
|
}
|
|
106
104
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
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 =
|
|
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
|
|
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 =
|
|
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
|
|
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 =
|
|
16
|
+
let envSrc = fsx.readFileX(envFilepath)
|
|
19
17
|
let keysSrc = ''
|
|
20
|
-
if (
|
|
21
|
-
keysSrc =
|
|
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
|
|
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
|
|
50
|
+
return fsx.existsSync(this.hookPath)
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
_currentHook () {
|
|
54
|
-
return
|
|
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
|
-
|
|
60
|
-
|
|
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
|
-
|
|
65
|
+
fsx.appendFileSync(this.hookPath, '\n' + HOOK_SCRIPT)
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
const
|
|
1
|
+
const fsx = require('./fsx')
|
|
2
2
|
const ignore = require('ignore')
|
|
3
3
|
|
|
4
4
|
function isIgnoringDotenvKeys () {
|
|
5
|
-
if (!
|
|
5
|
+
if (!fsx.existsSync('.gitignore')) {
|
|
6
6
|
return false
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
const gitignore =
|
|
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
|
|
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 (
|
|
22
|
-
const keysSrc =
|
|
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 (!
|
|
31
|
+
if (!fsx.existsSync(envFilepath)) {
|
|
33
32
|
return null
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
const envSrc =
|
|
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
|
|
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 (
|
|
16
|
-
const keysSrc =
|
|
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
|
|
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 =
|
|
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
|
|
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 =
|
|
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
|
-
|
|
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
|
|
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 (!
|
|
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 =
|
|
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 (!
|
|
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 =
|
|
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
|
|
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 (!
|
|
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 =
|
|
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 =
|
|
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
|
package/src/lib/services/run.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
const
|
|
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 =
|
|
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 (!
|
|
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 =
|
|
255
|
+
const src = fsx.readFileX(filepath)
|
|
257
256
|
return dotenv.parse(src)
|
|
258
257
|
}
|
|
259
258
|
|
package/src/lib/services/sets.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
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 =
|
|
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
|
-
|
|
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
|
|