@dotenvx/dotenvx 1.14.0 → 1.14.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/lib/services/precommit.js +32 -16
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.14.
|
|
5
|
+
## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.14.1...main)
|
|
6
|
+
|
|
7
|
+
## 1.14.1
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
* run precommit hook only on staged files ([#380](https://github.com/dotenvx/dotenvx/pull/380))
|
|
6
12
|
|
|
7
13
|
## 1.14.0
|
|
8
14
|
|
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@ const Ls = require('../services/ls')
|
|
|
7
7
|
const pluralize = require('./../helpers/pluralize')
|
|
8
8
|
const isFullyEncrypted = require('./../helpers/isFullyEncrypted')
|
|
9
9
|
const InstallPrecommitHook = require('./../helpers/installPrecommitHook')
|
|
10
|
+
const childProcess = require('child_process')
|
|
10
11
|
const MISSING_GITIGNORE = '.env.keys' // by default only ignore .env.keys. all other .env* files COULD be included - as long as they are encrypted
|
|
11
12
|
|
|
12
13
|
class Precommit {
|
|
@@ -44,23 +45,26 @@ class Precommit {
|
|
|
44
45
|
const lsService = new Ls(process.cwd(), undefined, this.excludeEnvFile)
|
|
45
46
|
const dotenvFiles = lsService.run()
|
|
46
47
|
dotenvFiles.forEach(file => {
|
|
47
|
-
// check if
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
// check if file is going to be commited
|
|
49
|
+
if (this._isFileToBeCommitted(file)) {
|
|
50
|
+
// check if that file is being ignored
|
|
51
|
+
if (ig.ignores(file)) {
|
|
52
|
+
if (file === '.env.example' || file === '.env.vault') {
|
|
53
|
+
const warning = new Error(`${file} (currently ignored but should not be)`)
|
|
54
|
+
warning.help = `? add !${file} to .gitignore with [echo "!${file}" >> .gitignore]`
|
|
55
|
+
warnings.push(warning)
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
if (file !== '.env.example' && file !== '.env.vault') {
|
|
59
|
+
const src = fs.readFileSync(file).toString()
|
|
60
|
+
const encrypted = isFullyEncrypted(src)
|
|
58
61
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
// if contents are encrypted don't raise an error
|
|
63
|
+
if (!encrypted) {
|
|
64
|
+
const error = new Error(`${file} not encrypted (or not gitignored)`)
|
|
65
|
+
error.help = `? encrypt it with [dotenvx encrypt -f ${file}] or add ${file} to .gitignore with [echo ".env*" >> .gitignore]`
|
|
66
|
+
throw error
|
|
67
|
+
}
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
}
|
|
@@ -77,6 +81,18 @@ class Precommit {
|
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
83
|
|
|
84
|
+
_isFileToBeCommitted (filePath) {
|
|
85
|
+
try {
|
|
86
|
+
const output = childProcess.execSync('git diff --cached --name-only').toString()
|
|
87
|
+
const files = output.split('\n')
|
|
88
|
+
|
|
89
|
+
return files.includes(filePath)
|
|
90
|
+
} catch (error) {
|
|
91
|
+
// consider file to be committed if there is an error (not using git)
|
|
92
|
+
return true
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
80
96
|
_installPrecommitHook () {
|
|
81
97
|
return new InstallPrecommitHook().run()
|
|
82
98
|
}
|