@dotenvx/dotenvx 1.14.0 → 1.14.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.14.0...main)
5
+ ## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.14.2...main)
6
+
7
+ ## 1.14.2
8
+
9
+ ### Changed
10
+
11
+ * swap `process.stdout.write` for `console.log` to patch up npx edge case ([#387](https://github.com/dotenvx/dotenvx/pull/387))
12
+
13
+ ## 1.14.1
14
+
15
+ ### Changed
16
+
17
+ * run precommit hook only on staged files ([#380](https://github.com/dotenvx/dotenvx/pull/380))
6
18
 
7
19
  ## 1.14.0
8
20
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.14.0",
2
+ "version": "1.14.2",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -22,7 +22,7 @@ function decrypt () {
22
22
  errorCount += 1
23
23
  console.error(processedEnvFile.error.message)
24
24
  } else {
25
- process.stdout.write(processedEnvFile.envSrc)
25
+ console.log(processedEnvFile.envSrc)
26
26
  }
27
27
  }
28
28
 
@@ -18,7 +18,7 @@ function encrypt () {
18
18
  } = main.encrypt(options.envFile, options.key, options.excludeKey)
19
19
 
20
20
  for (const processedEnvFile of processedEnvFiles) {
21
- process.stdout.write(processedEnvFile.envSrc)
21
+ console.log(processedEnvFile.envSrc)
22
22
  }
23
23
  process.exit(0) // exit early
24
24
  } else {
@@ -31,7 +31,7 @@ function get (key) {
31
31
  }
32
32
  inline = inline.trim()
33
33
 
34
- process.stdout.write(inline)
34
+ console.log(inline)
35
35
  // json format
36
36
  } else {
37
37
  let space = 0
@@ -39,14 +39,14 @@ function get (key) {
39
39
  space = 2
40
40
  }
41
41
 
42
- process.stdout.write(JSON.stringify(results, null, space))
42
+ console.log(JSON.stringify(results, null, space))
43
43
  }
44
44
  } else {
45
45
  if (results === undefined) {
46
- process.stdout.write('')
46
+ console.log('')
47
47
  process.exit(1)
48
48
  } else {
49
- process.stdout.write(results)
49
+ console.log(results)
50
50
  }
51
51
  }
52
52
  }
@@ -18,13 +18,13 @@ function keypair (key) {
18
18
  space = 2
19
19
  }
20
20
 
21
- process.stdout.write(JSON.stringify(results, null, space))
21
+ console.log(JSON.stringify(results, null, space))
22
22
  } else {
23
23
  if (results === undefined) {
24
- process.stdout.write('')
24
+ console.log('')
25
25
  process.exit(1)
26
26
  } else {
27
- process.stdout.write(results)
27
+ console.log(results)
28
28
  }
29
29
  }
30
30
  }
@@ -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 that file is being ignored
48
- if (ig.ignores(file)) {
49
- if (file === '.env.example' || file === '.env.vault') {
50
- const warning = new Error(`${file} (currently ignored but should not be)`)
51
- warning.help = `? add !${file} to .gitignore with [echo "!${file}" >> .gitignore]`
52
- warnings.push(warning)
53
- }
54
- } else {
55
- if (file !== '.env.example' && file !== '.env.vault') {
56
- const src = fs.readFileSync(file).toString()
57
- const encrypted = isFullyEncrypted(src)
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
- // if contents are encrypted don't raise an error
60
- if (!encrypted) {
61
- const error = new Error(`${file} not encrypted (or not gitignored)`)
62
- error.help = `? encrypt it with [dotenvx encrypt -f ${file}] or add ${file} to .gitignore with [echo ".env*" >> .gitignore]`
63
- throw error
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
  }