@dotenvx/dotenvx 1.10.4 → 1.11.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 CHANGED
@@ -2,7 +2,23 @@
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.1...main)
6
+
7
+ ## 1.11.1
8
+
9
+ ### Changed
10
+
11
+ * support encryption of `export KEY` variables and preserve `#!shebangs` ([#357](https://github.com/dotenvx/dotenvx/pull/357))
12
+
13
+ ## 1.11.0
14
+
15
+ ### Added
16
+
17
+ * add `--exclude-env-file (-ef)` to `ext ls` ([#356](https://github.com/dotenvx/dotenvx/pull/356))
18
+
19
+ ### Changed
20
+
21
+ * `ext precommit` ignores `tests/` directory (and similar) ([#356](https://github.com/dotenvx/dotenvx/pull/356))
6
22
 
7
23
  ## 1.10.4
8
24
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.10.4",
2
+ "version": "1.11.1",
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
@@ -39,6 +39,14 @@ function findOrCreatePublicKey (envFilepath, envKeysFilepath) {
39
39
  }
40
40
  }
41
41
 
42
+ // preserve shebang
43
+ const [firstLine, ...remainingLines] = envSrc.split('\n')
44
+ let firstLinePreserved = ''
45
+ if (firstLine.startsWith('#!')) {
46
+ firstLinePreserved = firstLine + '\n'
47
+ envSrc = remainingLines.join('\n')
48
+ }
49
+
42
50
  // generate key pair
43
51
  const { publicKey, privateKey } = keyPair(existingPrivateKey)
44
52
 
@@ -66,7 +74,7 @@ function findOrCreatePublicKey (envFilepath, envKeysFilepath) {
66
74
  ''
67
75
  ].join('\n')
68
76
 
69
- envSrc = `${prependPublicKey}\n${envSrc}`
77
+ envSrc = `${firstLinePreserved}${prependPublicKey}\n${envSrc}`
70
78
  keysSrc = keysSrc.length > 1 ? keysSrc : `${firstTimeKeysSrc}\n`
71
79
 
72
80
  let privateKeyAdded = false
@@ -7,13 +7,15 @@ function replace (src, key, value) {
7
7
  const parsed = dotenv.parse(src)
8
8
  if (Object.prototype.hasOwnProperty.call(parsed, key)) {
9
9
  const regex = new RegExp(
10
- // Match the key at the start of a line or following a newline
11
- `(^|\\n)${key}\\s*=\\s*` +
10
+ // Match the key at the start of a line, following a newline, or prefaced by export
11
+ `(^|\\n)\\s*(export\\s+)?${key}\\s*=\\s*` +
12
+ // `(^|\\n)${key}\\s*=\\s*` +
12
13
  // Non-capturing group to handle different types of quotations and unquoted values
13
14
  '(?:' +
14
15
  '(["\'`])' + // Match an opening quote
15
16
  '.*?' + // Non-greedy match for any characters within quotes
16
- '\\2' + // Match the corresponding closing quote
17
+ // '\\2' + // Match the corresponding closing quote
18
+ '\\3' + // Match the corresponding closing quote
17
19
  '|' +
18
20
  // Match unquoted values; account for escaped newlines
19
21
  '(?:[^#\\n\\\\]|\\\\.)*' + // Use non-capturing group for any character except #, newline, or backslash, or any escaped character
@@ -21,7 +23,7 @@ function replace (src, key, value) {
21
23
  'gs' // Global and dotAll mode to treat string as single line
22
24
  )
23
25
 
24
- output = src.replace(regex, `$1${formatted}`)
26
+ output = src.replace(regex, `$1$2${formatted}`)
25
27
  } else {
26
28
  // append
27
29
  if (src.endsWith('\n')) {
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