@dotenvx/dotenvx 1.40.0 → 1.41.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.
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.40.0...main)
5
+ [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.41.0...main)
6
+
7
+ ## [1.41.0](https://github.com/dotenvx/dotenvx/compare/v1.40.1...v1.41.0)
8
+
9
+ ### Added
10
+
11
+ * Add [directory] argument to precommit and prebuild ([#572](https://github.com/dotenvx/dotenvx/pull/572))
12
+
13
+ ## [1.40.1](https://github.com/dotenvx/dotenvx/compare/v1.40.0...v1.40.1)
14
+
15
+ ### Changed
16
+
17
+ * Patch `ext scan` command ([#570](https://github.com/dotenvx/dotenvx/pull/570))
6
18
 
7
19
  ## [1.40.0](https://github.com/dotenvx/dotenvx/compare/v1.39.1...v1.40.0)
8
20
 
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  BSD 3-Clause License
2
2
 
3
- Copyright (c) 2024, Scott Motte
3
+ Copyright (c) 2024, Dotenvx LLC
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
6
6
  modification, are permitted provided that the following conditions are met:
@@ -26,3 +26,11 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
26
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
27
  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
28
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+
30
+ ---
31
+
32
+ Dotenvx is an Open Source project licensed under the BSD 3-Clause above.
33
+
34
+ Dotenvx Pro is source-available with a commercial-friendly license. You can find
35
+ the full commercial license in `COMMERCIAL-LICENSE.txt`. See https://dotenvx.com
36
+ for features and purchasing options.
package/README.md CHANGED
@@ -796,6 +796,59 @@ Advanced CLI commands.
796
796
  Hello World
797
797
  ```
798
798
 
799
+ </details>
800
+ * <details><summary>`run` - Multiline</summary><br>
801
+
802
+ Dotenvx supports multiline values. This is particularly useful in conjunction with Docker - which [does not support multiline values](https://stackoverflow.com/questions/50299617/set-multiline-environment-variable-with-dockerfile/79578348#79578348).
803
+
804
+ ```ini
805
+ # .env
806
+ MULTILINE_PEM="-----BEGIN PUBLIC KEY-----
807
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnNl1tL3QjKp3DZWM0T3u
808
+ LgGJQwu9WqyzHKZ6WIA5T+7zPjO1L8l3S8k8YzBrfH4mqWOD1GBI8Yjq2L1ac3Y/
809
+ bTdfHN8CmQr2iDJC0C6zY8YV93oZB3x0zC/LPbRYpF8f6OqX1lZj5vo2zJZy4fI/
810
+ kKcI5jHYc8VJq+KCuRZrvn+3V+KuL9tF9v8ZgjF2PZbU+LsCy5Yqg1M8f5Jp5f6V
811
+ u4QuUoobAgMBAAE=
812
+ -----END PUBLIC KEY-----"
813
+ ```
814
+
815
+ ```js
816
+ // index.js
817
+ console.log('MULTILINE_PEM', process.env.MULTILINE_PEM)
818
+ ```
819
+
820
+ ```sh
821
+ $ dotenvx run -- node index.js
822
+ MULTILINE_PEM -----BEGIN PUBLIC KEY-----
823
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnNl1tL3QjKp3DZWM0T3u
824
+ LgGJQwu9WqyzHKZ6WIA5T+7zPjO1L8l3S8k8YzBrfH4mqWOD1GBI8Yjq2L1ac3Y/
825
+ bTdfHN8CmQr2iDJC0C6zY8YV93oZB3x0zC/LPbRYpF8f6OqX1lZj5vo2zJZy4fI/
826
+ kKcI5jHYc8VJq+KCuRZrvn+3V+KuL9tF9v8ZgjF2PZbU+LsCy5Yqg1M8f5Jp5f6V
827
+ u4QuUoobAgMBAAE=
828
+ -----END PUBLIC KEY-----
829
+ ```
830
+
831
+ </details>
832
+ * <details><summary>`run` - Contextual Help</summary><br>
833
+
834
+ Unlike other dotenv libraries, dotenvx attempts to unblock you with contextual help.
835
+
836
+ For example, when missing a custom .env file:
837
+
838
+ ```sh
839
+ $ dotenvx run -f .env.missing -- echo $HELLO
840
+ [MISSING_ENV_FILE] missing .env.missing file (/Users/scottmotte/Code/dotenvx/playground/apr-16/.env.missing)
841
+ [MISSING_ENV_FILE] https://github.com/dotenvx/dotenvx/issues/484 and re-run [dotenvx run -- echo]
842
+ ```
843
+
844
+ or when missing a KEY:
845
+
846
+ ```sh
847
+ $ echo "HELLO=World" > .env
848
+ $ dotenvx get GOODBYE
849
+ [MISSING_KEY] missing GOODBYE key
850
+ ```
851
+
799
852
  </details>
800
853
  * <details><summary>`run` - multiple `-f` flags</summary><br>
801
854
 
@@ -2026,6 +2079,16 @@ CLI extensions.
2026
2079
  [dotenvx][precommit] dotenvx ext precommit installed [.git/hooks/pre-commit]
2027
2080
  ```
2028
2081
 
2082
+ </details>
2083
+ * <details><summary>`ext precommit directory`</summary><br>
2084
+
2085
+ Prevent `.env` files from being committed to code inside a specified path to a directory.
2086
+
2087
+ ```sh
2088
+ $ dotenvx ext precommit apps/backend
2089
+ [dotenvx][precommit] .env files (1) protected (encrypted or gitignored)
2090
+ ```
2091
+
2029
2092
  </details>
2030
2093
  * <details><summary>`ext prebuild`</summary><br>
2031
2094
 
@@ -2044,23 +2107,35 @@ CLI extensions.
2044
2107
  ```
2045
2108
 
2046
2109
  </details>
2047
- * <details><summary>`ext scan`</summary><br>
2110
+ * <details><summary>`ext prebuild directory`</summary><br>
2111
+
2112
+ Prevent `.env` files from being built into your docker containers inside a specified path to a directory.
2048
2113
 
2049
- Use [gitleaks](https://gitleaks.io) under the hood to scan for possible secrets in your code.
2114
+ Add it to your `Dockerfile`.
2050
2115
 
2051
2116
  ```sh
2052
- $ dotenvx ext scan
2117
+ # Dockerfile
2118
+ RUN curl -fsS https://dotenvx.sh | sh
2053
2119
 
2054
-
2055
- │╲
2056
- │ ○
2057
- ○ ░
2058
- ░ gitleaks
2120
+ ...
2059
2121
 
2122
+ RUN dotenvx ext prebuild apps/backend
2123
+ CMD ["dotenvx", "run", "--", "node", "index.js"]
2124
+ ```
2125
+
2126
+ </details>
2127
+ * <details><summary>`ext scan`</summary><br>
2128
+
2129
+ Scan for leaked secrets.
2130
+
2131
+ ```sh
2132
+ $ dotenvx ext scan
2060
2133
  100 commits scanned.
2061
2134
  no leaks found
2062
2135
  ```
2063
2136
 
2137
+ Uses [gitleaks](https://gitleaks.io) under the hood.
2138
+
2064
2139
  </details>
2065
2140
 
2066
2141
  ### Library 📦
@@ -2289,6 +2364,8 @@ Use dotenvx directly in code.
2289
2364
 
2290
2365
  ### Pro 🏆
2291
2366
 
2367
+ > Dotenvx Pro is a commercial extension for [dotenvx](https://github.com/dotenvx/dotenvx).
2368
+
2292
2369
  *Secrets Management – Done Right. Encrypted, Cloaked, Secrets as Code.*
2293
2370
 
2294
2371
  * <details><summary>`pro keypair`</summary><br>
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.40.0",
2
+ "version": "1.41.0",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -2,7 +2,10 @@ const { logger } = require('./../../../shared/logger')
2
2
 
3
3
  const Prebuild = require('./../../../lib/services/prebuild')
4
4
 
5
- function prebuild () {
5
+ function prebuild (directory) {
6
+ // debug args
7
+ logger.debug(`directory: ${directory}`)
8
+
6
9
  const options = this.opts()
7
10
  logger.debug(`options: ${JSON.stringify(options)}`)
8
11
 
@@ -10,7 +13,7 @@ function prebuild () {
10
13
  const {
11
14
  successMessage,
12
15
  warnings
13
- } = new Prebuild(options).run()
16
+ } = new Prebuild(directory, options).run()
14
17
 
15
18
  for (const warning of warnings) {
16
19
  logger.warn(warning.message)
@@ -2,7 +2,10 @@ const { logger } = require('./../../../shared/logger')
2
2
 
3
3
  const Precommit = require('./../../../lib/services/precommit')
4
4
 
5
- function precommit () {
5
+ function precommit (directory) {
6
+ // debug args
7
+ logger.debug(`directory: ${directory}`)
8
+
6
9
  const options = this.opts()
7
10
  logger.debug(`options: ${JSON.stringify(options)}`)
8
11
 
@@ -10,7 +13,7 @@ function precommit () {
10
13
  const {
11
14
  successMessage,
12
15
  warnings
13
- } = new Precommit(options).run()
16
+ } = new Precommit(directory, options).run()
14
17
 
15
18
  for (const warning of warnings) {
16
19
  logger.warn(warning.message)
@@ -1,6 +1,7 @@
1
1
  const childProcess = require('child_process')
2
2
 
3
3
  const { logger } = require('./../../../shared/logger')
4
+ const chomp = require('./../../../lib/helpers/chomp')
4
5
 
5
6
  function scan () {
6
7
  const options = this.opts()
@@ -17,11 +18,14 @@ function scan () {
17
18
  return
18
19
  }
19
20
 
21
+ let output = ''
20
22
  try {
21
- const output = childProcess.execSync('gitleaks detect -v 2>&1', { stdio: 'pipe' }).toString() // gitleaks sends output as stderr for strange reason
22
- logger.blank(output)
23
+ output = childProcess.execSync('gitleaks detect --no-banner --verbose 2>&1').toString() // gitleaks sends exit code 1 but puts data on stdout for failures, so we catch later and resurface the stdout
24
+ logger.blank(chomp(output))
23
25
  } catch (error) {
24
- console.error(error.message)
26
+ if (error.stdout) {
27
+ console.error(chomp(error.stdout.toString()))
28
+ }
25
29
 
26
30
  process.exit(1)
27
31
  }
@@ -47,12 +47,14 @@ ext.command('gitignore')
47
47
  ext.command('prebuild')
48
48
  .description('prevent including .env files in docker builds')
49
49
  .addHelpText('after', examples.prebuild)
50
+ .argument('[directory]', 'directory to prevent including .env files from', '.')
50
51
  .action(require('./../actions/ext/prebuild'))
51
52
 
52
53
  // dotenvx ext precommit
53
54
  ext.command('precommit')
54
55
  .description('prevent committing .env files to code')
55
56
  .addHelpText('after', examples.precommit)
57
+ .argument('[directory]', 'directory to prevent committing .env files from', '.')
56
58
  .option('-i, --install', 'install to .git/hooks/pre-commit')
57
59
  .action(require('./../actions/ext/precommit'))
58
60
 
@@ -1,5 +1,6 @@
1
1
  /* istanbul ignore file */
2
2
  const fsx = require('./../helpers/fsx')
3
+ const path = require('path')
3
4
  const ignore = require('ignore')
4
5
 
5
6
  const Ls = require('../services/ls')
@@ -9,7 +10,10 @@ const packageJson = require('./../helpers/packageJson')
9
10
  const MISSING_DOCKERIGNORE = '.env.keys' // by default only ignore .env.keys. all other .env* files COULD be included - as long as they are encrypted
10
11
 
11
12
  class Prebuild {
12
- constructor () {
13
+ constructor (directory = './') {
14
+ // args
15
+ this.directory = directory
16
+
13
17
  this.excludeEnvFile = ['test/**', 'tests/**', 'spec/**', 'specs/**', 'pytest/**', 'test_suite/**']
14
18
  }
15
19
 
@@ -28,11 +32,13 @@ class Prebuild {
28
32
 
29
33
  // 2. check .env* files against .dockerignore file
30
34
  const ig = ignore().add(dockerignore)
31
- const lsService = new Ls(process.cwd(), undefined, this.excludeEnvFile)
35
+ const lsService = new Ls(this.directory, undefined, this.excludeEnvFile)
32
36
  const dotenvFiles = lsService.run()
33
- dotenvFiles.forEach(file => {
37
+ dotenvFiles.forEach(_file => {
34
38
  count += 1
35
39
 
40
+ const file = path.join(this.directory, _file) // to handle when directory argument passed
41
+
36
42
  // check if that file is being ignored
37
43
  if (ig.ignores(file)) {
38
44
  if (file === '.env.example' || file === '.env.vault') {
@@ -1,5 +1,6 @@
1
1
  /* istanbul ignore file */
2
2
  const fsx = require('./../helpers/fsx')
3
+ const path = require('path')
3
4
  const ignore = require('ignore')
4
5
 
5
6
  const Ls = require('../services/ls')
@@ -11,7 +12,10 @@ const childProcess = require('child_process')
11
12
  const MISSING_GITIGNORE = '.env.keys' // by default only ignore .env.keys. all other .env* files COULD be included - as long as they are encrypted
12
13
 
13
14
  class Precommit {
14
- constructor (options = {}) {
15
+ constructor (directory = './', options = {}) {
16
+ // args
17
+ this.directory = directory
18
+ // options
15
19
  this.install = options.install
16
20
  this.excludeEnvFile = ['test/**', 'tests/**', 'spec/**', 'specs/**', 'pytest/**', 'test_suite/**']
17
21
  }
@@ -41,11 +45,14 @@ class Precommit {
41
45
 
42
46
  // 2. check .env* files against .gitignore file
43
47
  const ig = ignore().add(gitignore)
44
- const lsService = new Ls(process.cwd(), undefined, this.excludeEnvFile)
48
+
49
+ const lsService = new Ls(this.directory, undefined, this.excludeEnvFile)
45
50
  const dotenvFiles = lsService.run()
46
- dotenvFiles.forEach(file => {
51
+ dotenvFiles.forEach(_file => {
47
52
  count += 1
48
53
 
54
+ const file = path.join(this.directory, _file) // to handle when directory argument passed
55
+
49
56
  // check if file is going to be committed
50
57
  if (this._isFileToBeCommitted(file)) {
51
58
  // check if that file is being ignored