@dotenvx/dotenvx 1.10.4 → 1.11.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,17 @@
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.10.4...main)
5
+ ## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.11.0...main)
6
+
7
+ ## 1.11.0
8
+
9
+ ### Added
10
+
11
+ * add `--exclude-env-file (-ef)` to `ext ls` ([#356](https://github.com/dotenvx/dotenvx/pull/356))
12
+
13
+ ### Changed
14
+
15
+ * `ext precommit` ignores `tests/` directory (and similar) ([#356](https://github.com/dotenvx/dotenvx/pull/356))
6
16
 
7
17
  ## 1.10.4
8
18
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.10.4",
2
+ "version": "1.11.0",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -12,7 +12,7 @@ function ls (directory) {
12
12
  const options = this.opts()
13
13
  logger.debug(`options: ${JSON.stringify(options)}`)
14
14
 
15
- const filepaths = main.ls(directory, options.envFile)
15
+ const filepaths = main.ls(directory, options.envFile, options.excludeEnvFile)
16
16
  logger.debug(`filepaths: ${JSON.stringify(filepaths)}`)
17
17
 
18
18
  const tree = new ArrayToTree(filepaths).run()
@@ -25,6 +25,7 @@ ext.command('ls')
25
25
  .description('print all .env files in a tree structure')
26
26
  .argument('[directory]', 'directory to list .env files from', '.')
27
27
  .option('-f, --env-file <filenames...>', 'path(s) to your env file(s)', '.env*')
28
+ .option('-ef, --exclude-env-file <excludeFilenames...>', 'path(s) to exclude from your env file(s) (default: none)')
28
29
  .action(require('./../actions/ext/ls'))
29
30
 
30
31
  // dotenvx ext genexample
package/src/lib/main.d.ts CHANGED
@@ -184,8 +184,13 @@ export function encrypt(
184
184
  *
185
185
  * @param directory - current working directory
186
186
  * @param envFile - glob pattern to match env files
187
+ * @param excludeEnvFile - glob pattern to exclude env files
187
188
  */
188
- export function ls(directory: string, envFile: string): string[];
189
+ export function ls(
190
+ directory: string,
191
+ envFile: string | string[],
192
+ excludeEnvFile: string | string[]
193
+ ): string[];
189
194
 
190
195
  /**
191
196
  * Get the value of a key from the .env file
package/src/lib/main.js CHANGED
@@ -173,8 +173,8 @@ const parse = function (src) {
173
173
  }
174
174
 
175
175
  /** @type {import('./main').ls} */
176
- const ls = function (directory, envFile) {
177
- return new Ls(directory, envFile).run()
176
+ const ls = function (directory, envFile, excludeEnvFile) {
177
+ return new Ls(directory, envFile, excludeEnvFile).run()
178
178
  }
179
179
 
180
180
  /** @type {import('./main').genexample} */
@@ -3,11 +3,12 @@ const path = require('path')
3
3
  const picomatch = require('picomatch')
4
4
 
5
5
  class Ls {
6
- constructor (directory = './', envFile = '.env*') {
6
+ constructor (directory = './', envFile = ['.env*'], excludeEnvFile = []) {
7
7
  this.ignore = ['node_modules/**', '.git/**']
8
8
 
9
9
  this.cwd = path.resolve(directory)
10
10
  this.envFile = envFile
11
+ this.excludeEnvFile = excludeEnvFile
11
12
  }
12
13
 
13
14
  run () {
@@ -15,9 +16,9 @@ class Ls {
15
16
  }
16
17
 
17
18
  _filepaths () {
18
- const exclude = picomatch(this.ignore)
19
+ const exclude = picomatch(this._exclude())
19
20
  const include = picomatch(this._patterns(), {
20
- ignore: this.ignore
21
+ ignore: this._exclude()
21
22
  })
22
23
 
23
24
  return new Fdir()
@@ -35,6 +36,22 @@ class Ls {
35
36
 
36
37
  return this.envFile.map(part => `**/${part}`)
37
38
  }
39
+
40
+ _excludePatterns () {
41
+ if (!Array.isArray(this.excludeEnvFile)) {
42
+ return [`**/${this.excludeEnvFile}`]
43
+ }
44
+
45
+ return this.excludeEnvFile.map(part => `**/${part}`)
46
+ }
47
+
48
+ _exclude () {
49
+ if (this._excludePatterns().length > 0) {
50
+ return this.ignore.concat(this._excludePatterns())
51
+ } else {
52
+ return this.ignore
53
+ }
54
+ }
38
55
  }
39
56
 
40
57
  module.exports = Ls
@@ -12,6 +12,7 @@ const MISSING_GITIGNORE = '.env.keys' // by default only ignore .env.keys. all o
12
12
  class Precommit {
13
13
  constructor (options = {}) {
14
14
  this.install = options.install
15
+ this.excludeEnvFile = ['test/**', 'tests/**', 'spec/**', 'specs/**', 'pytest/**', 'test_suite/**']
15
16
  }
16
17
 
17
18
  run () {
@@ -40,7 +41,7 @@ class Precommit {
40
41
 
41
42
  // 2. check .env* files against .gitignore file
42
43
  const ig = ignore().add(gitignore)
43
- const lsService = new Ls(process.cwd())
44
+ const lsService = new Ls(process.cwd(), undefined, this.excludeEnvFile)
44
45
  const dotenvFiles = lsService.run()
45
46
  dotenvFiles.forEach(file => {
46
47
  // check if that file is being ignored