@dotenvx/dotenvx 1.0.1 → 1.2.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,13 +2,29 @@
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.0.1...main)
5
+ ## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.2.0...main)
6
+
7
+ ## 1.2.0
8
+
9
+ ### Added
10
+
11
+ * handle nested `dotenvx` invocations - `dotenvx run -- dotenvx run -- env` ([#279](https://github.com/dotenvx/dotenvx/pull/279))
12
+
13
+ ### Changed
14
+
15
+ * replace `glob` with faster approach ([#278](https://github.com/dotenvx/dotenvx/pull/278))
16
+
17
+ ## 1.1.0
18
+
19
+ ### Added
20
+
21
+ * add TypeScript type definitions ([#272](https://github.com/dotenvx/dotenvx/pull/272))
6
22
 
7
23
  ## 1.0.1
8
24
 
9
25
  ### Changed
10
26
 
11
- * 🐞 Fix expansion when preset on `process.env` and/or with `--overload` ([#271](https://github.com/dotenvx/dotenvx/pull/271))
27
+ * 🐞 fix expansion when preset on `process.env` and/or with `--overload` ([#271](https://github.com/dotenvx/dotenvx/pull/271))
12
28
 
13
29
  ## 1.0.0
14
30
 
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
   
10
10
 
11
11
 
12
- ### Quickstart [![npm version](https://img.shields.io/npm/v/@dotenvx/dotenvx.svg)](https://www.npmjs.com/package/@dotenvx/dotenvx) [![npm installs](https://img.shields.io/npm/dm/@dotenvx/dotenvx)](https://www.npmjs.com/package/@dotenvx/dotenvx)
12
+ ### Quickstart [![npm version](https://img.shields.io/npm/v/@dotenvx/dotenvx.svg)](https://www.npmjs.com/package/@dotenvx/dotenvx) [![test count](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/motdotenv/bb76445765a9731e7d824a6efdf53524/raw/dotenvxTestCount.json)](https://github.com/dotenvx/dotenvx/tree/main/tests) [![npm installs](https://img.shields.io/npm/dm/@dotenvx/dotenvx)](https://www.npmjs.com/package/@dotenvx/dotenvx)
13
13
 
14
14
  Install and use it in code just like `dotenv`.
15
15
 
@@ -233,6 +233,17 @@ More examples
233
233
  Hello World
234
234
  ```
235
235
 
236
+ </details>
237
+ * <details><summary>Clojure 🌿</summary><br>
238
+
239
+ ```sh
240
+ $ echo "HELLO=World" > .env
241
+ $ echo '(println "Hello" (System/getenv "HELLO"))' > index.clj
242
+
243
+ $ dotenvx run -- clojure -M index.clj
244
+ Hello World
245
+ ```
246
+
236
247
  </details>
237
248
  * <details><summary>.NET 🔵</summary><br>
238
249
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.1",
2
+ "version": "1.2.0",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -15,6 +15,7 @@
15
15
  "CHANGELOG.md"
16
16
  ],
17
17
  "main": "src/lib/main.js",
18
+ "types": "src/lib/main.d.ts",
18
19
  "bin": {
19
20
  "dotenvx": "./src/cli/dotenvx.js",
20
21
  "git-dotenvx": "./src/cli/dotenvx.js"
@@ -25,7 +26,8 @@
25
26
  "test": "tap run --show-full-coverage",
26
27
  "testshell": "bash shellspec",
27
28
  "prerelease": "npm test && npm run testshell",
28
- "release": "standard-version"
29
+ "release": "standard-version",
30
+ "postinstall": "patch-package"
29
31
  },
30
32
  "funding": "https://dotenvx.com",
31
33
  "dependencies": {
@@ -38,12 +40,13 @@
38
40
  "dotenv": "^16.4.5",
39
41
  "eciesjs": "^0.4.6",
40
42
  "execa": "^5.1.1",
41
- "glob": "^10.3.10",
43
+ "fdir": "^6.1.1",
42
44
  "ignore": "^5.3.0",
43
45
  "is-wsl": "^2.1.1",
44
46
  "object-treeify": "1.1.33",
45
47
  "open": "^8.4.2",
46
48
  "ora": "^5.4.1",
49
+ "picomatch": "^3.0.1",
47
50
  "semver": "^7.3.4",
48
51
  "undici": "^5.28.3",
49
52
  "which": "^4.0.0",
@@ -52,6 +55,7 @@
52
55
  },
53
56
  "devDependencies": {
54
57
  "capture-console": "^1.0.2",
58
+ "patch-package": "^8.0.0",
55
59
  "pkg": "^5.8.1",
56
60
  "proxyquire": "^2.1.3",
57
61
  "sinon": "^14.0.1",
@@ -48,15 +48,31 @@ const executeCommand = async function (commandArgs, env) {
48
48
  }
49
49
 
50
50
  try {
51
- let systemCommandPath = commandArgs[0]
51
+ // ensure the first command is expanded
52
52
  try {
53
- systemCommandPath = which.sync(`${commandArgs[0]}`)
54
- logger.debug(`expanding process command to [${systemCommandPath} ${commandArgs.slice(1).join(' ')}]`)
53
+ commandArgs[0] = path.resolve(which.sync(`${commandArgs[0]}`))
54
+ logger.debug(`expanding process command to [${commandArgs.join(' ')}]`)
55
55
  } catch (e) {
56
- logger.debug(`could not expand process command. using [${systemCommandPath} ${commandArgs.slice(1).join(' ')}]`)
56
+ logger.debug(`could not expand process command. using [${commandArgs.join(' ')}]`)
57
57
  }
58
58
 
59
- commandProcess = execa(systemCommandPath, commandArgs.slice(1), {
59
+ // expand any other commands that follow a --
60
+ let expandNext = false
61
+ for (let i = 0; i < commandArgs.length; i++) {
62
+ if (commandArgs[i] === '--') {
63
+ expandNext = true
64
+ } else if (expandNext) {
65
+ try {
66
+ commandArgs[i] = path.resolve(which.sync(`${commandArgs[i]}`))
67
+ logger.debug(`expanding process command to [${commandArgs.join(' ')}]`)
68
+ } catch (e) {
69
+ logger.debug(`could not expand process command. using [${commandArgs.join(' ')}]`)
70
+ }
71
+ expandNext = false
72
+ }
73
+ }
74
+
75
+ commandProcess = execa(commandArgs[0], commandArgs.slice(1), {
60
76
  stdio: 'inherit',
61
77
  env: { ...process.env, ...env }
62
78
  })
@@ -197,7 +213,6 @@ async function run () {
197
213
  logger.error(' or try: [dotenvx run -- npm run dev]')
198
214
  process.exit(1)
199
215
  } else {
200
- // const commandArgs = process.argv.slice(commandIndex + 1)
201
216
  await executeCommand(commandArgs, process.env)
202
217
  }
203
218
  }
@@ -2,6 +2,7 @@
2
2
 
3
3
  const fs = require('fs')
4
4
  const path = require('path')
5
+ const { execSync } = require('child_process')
5
6
  const UpdateNotice = require('./../lib/helpers/updateNotice')
6
7
  const { Command } = require('commander')
7
8
  const program = new Command()
@@ -99,9 +100,14 @@ program.command('encrypt')
99
100
  program.command('pro')
100
101
  .description('🏆 pro')
101
102
  .action(function (...args) {
102
- const pro = fs.readFileSync(path.join(__dirname, './pro.txt'), 'utf8')
103
-
104
- console.log(pro)
103
+ try {
104
+ // execute `dotenvx-pro` if available
105
+ execSync('dotenvx-pro', { stdio: ['inherit', 'inherit', 'ignore'] })
106
+ } catch (_error) {
107
+ const pro = fs.readFileSync(path.join(__dirname, './pro.txt'), 'utf8')
108
+
109
+ console.log(pro)
110
+ }
105
111
  })
106
112
 
107
113
  // // dotenvx ent
@@ -0,0 +1,284 @@
1
+ import type { URL } from 'url';
2
+ import type { Change } from 'diff';
3
+
4
+ export interface DotenvParseOutput {
5
+ [name: string]: string;
6
+ }
7
+
8
+ /**
9
+ * Parses a string or buffer in the .env file format into an object.
10
+ *
11
+ * @see https://dotenvx.com/docs
12
+ * @param src - contents to be parsed. example: `'DB_HOST=localhost'`
13
+ * @returns an object with keys and values based on `src`. example: `{ DB_HOST : 'localhost' }`
14
+ */
15
+ export function parse<T extends DotenvParseOutput = DotenvParseOutput>(
16
+ src: string | Buffer
17
+ ): T;
18
+
19
+ export interface DotenvConfigOptions {
20
+ /** *
21
+ * Specify a custom path if your file containing environment variables is located elsewhere.
22
+ * Can also be an array of strings, specifying multiple paths.
23
+ *
24
+ * @default require('path').resolve(process.cwd(), '.env')
25
+ * @example require('@dotenvx/dotenvx').config({ path: '/custom/path/to/.env' })
26
+ * @example require('@dotenvx/dotenvx').config({ path: ['/path/to/first.env', '/path/to/second.env'] })
27
+ */
28
+ path?: string | string[] | URL;
29
+
30
+ /**
31
+ * Specify the encoding of your file containing environment variables.
32
+ *
33
+ * @default 'utf8'
34
+ * @example require('@dotenvx/dotenvx').config({ encoding: 'latin1' })
35
+ */
36
+ encoding?: string;
37
+
38
+ /**
39
+ * Turn on logging to help debug why certain keys or values are not being set as you expect.
40
+ *
41
+ * @default false
42
+ * @example require('@dotenvx/dotenvx').config({ debug: process.env.DEBUG })
43
+ */
44
+ debug?: boolean;
45
+
46
+ /**
47
+ * Override any environment variables that have already been set on your machine with values from your .env file.
48
+ * @default false
49
+ * @example require('@dotenvx/dotenvx').config({ override: true })
50
+ * @alias overload
51
+ */
52
+ override?: boolean;
53
+
54
+ /**
55
+ * @default false
56
+ * @alias override
57
+ */
58
+ overload?: boolean;
59
+
60
+ /**
61
+ * Specify an object to write your secrets to. Defaults to process.env environment variables.
62
+ *
63
+ * @default process.env
64
+ * @example const processEnv = {}; require('@dotenvx/dotenvx').config({ processEnv: processEnv })
65
+ */
66
+ processEnv?: DotenvPopulateInput;
67
+
68
+ /**
69
+ * Pass the DOTENV_KEY directly to config options. Defaults to looking for process.env.DOTENV_KEY environment variable. Note this only applies to decrypting .env.vault files. If passed as null or undefined, or not passed at all, dotenv falls back to its traditional job of parsing a .env file.
70
+ *
71
+ * @default undefined
72
+ * @example require('@dotenvx/dotenvx').config({ DOTENV_KEY: 'dotenv://:key_1234…@dotenvx.com/vault/.env.vault?environment=production' })
73
+ */
74
+ DOTENV_KEY?: string;
75
+
76
+ /**
77
+ * Do not warn for missing .env files
78
+ */
79
+ convention?: string;
80
+ }
81
+
82
+ export interface DotenvConfigOutput {
83
+ error?: Error;
84
+ parsed?: DotenvParseOutput;
85
+ }
86
+
87
+ export interface DotenvPopulateInput {
88
+ [name: string]: string;
89
+ }
90
+
91
+ /**
92
+ * Loads `.env` file contents into process.env by default. If `DOTENV_KEY` is present, it smartly attempts to load encrypted `.env.vault` file contents into process.env.
93
+ *
94
+ * @see https://dotenvx.com/docs
95
+ *
96
+ * @param options - additional options. example: `{ path: './custom/path', encoding: 'latin1', debug: true, override: false }`
97
+ * @returns an object with a `parsed` key if successful or `error` key if an error occurred. example: { parsed: { KEY: 'value' } }
98
+ *
99
+ */
100
+ export function config(options?: DotenvConfigOptions): DotenvConfigOutput;
101
+
102
+ /**
103
+ * Loads `.env` file contents into process.env.
104
+ *
105
+ * @see https://dotenvx.com/docs
106
+ *
107
+ * @param options - additional options. example: `{ path: './custom/path', encoding: 'latin1', debug: true, override: false }`
108
+ * @returns an object with a `parsed` key if successful or `error` key if an error occurred. example: { parsed: { KEY: 'value' } }
109
+ *
110
+ */
111
+ export function configDotenv(options?: DotenvConfigOptions): DotenvConfigOutput;
112
+
113
+ /**
114
+ * Decrypt ciphertext
115
+ *
116
+ * @see https://dotenvx.com/docs
117
+ *
118
+ * @param encrypted - the encrypted ciphertext string
119
+ * @param keyStr - the decryption key string
120
+ */
121
+ export function decrypt(encrypted: string, keyStr: string): string;
122
+
123
+ export type EncryptRowOutput = {
124
+ keys: string[];
125
+ filepath: string;
126
+ envFilepath: string;
127
+ publicKey: string;
128
+ privateKey: string;
129
+ privateKeyName: string;
130
+ privateKeyAdded: boolean;
131
+ envSrc: string;
132
+ changed: boolean;
133
+ error?: Error;
134
+ };
135
+
136
+ export type EncryptOutput = {
137
+ processedEnvFiles: EncryptRowOutput[];
138
+ changedFilepaths: string[];
139
+ unchangedFilepaths: string[];
140
+ };
141
+
142
+ /**
143
+ * Encrypt plaintext
144
+ *
145
+ * @see https://dotenvx.com/docs
146
+ * @param envFile - path to the .env file
147
+ */
148
+ export function encrypt(envFile: string): EncryptOutput;
149
+
150
+ export type VaultEncryptOutput = {
151
+ dotenvKeys: Record<string, string>;
152
+ dotenvKeysFile: string;
153
+ addedKeys: string[];
154
+ existingKeys: string[];
155
+ dotenvVaultFile: string;
156
+ addedVaults: string[];
157
+ existingVaults: string[];
158
+ addedDotenvFilenames: string[];
159
+ envFile: string | string[];
160
+ };
161
+
162
+ /**
163
+ * Encrypt plaintext
164
+ *
165
+ * @see https://dotenvx.com/docs
166
+ * @param directory - current working directory
167
+ * @param envFile - path to the .env file(s)
168
+ */
169
+ export function vaultEncrypt(
170
+ directory: string,
171
+ envFile: string | string[]
172
+ ): VaultEncryptOutput;
173
+
174
+ /**
175
+ * List all env files in the current working directory
176
+ *
177
+ * @param directory - current working directory
178
+ * @param envFile - glob pattern to match env files
179
+ */
180
+ export function ls(directory: string, envFile: string): string[];
181
+
182
+ /**
183
+ * Get the value of a key from the .env file
184
+ *
185
+ * @param [key] - the key to get the value of
186
+ * @param [envs] - the environment(s) to get the value from
187
+ * @param [overload] - whether to overload the value from the .env file
188
+ * @param [DOTENV_KEY] - the decryption key string
189
+ * @param [all] - whether to return all values
190
+ */
191
+ export function get(
192
+ key?: string,
193
+ envs: string[] = [],
194
+ overload = false,
195
+ DOTENV_KEY = '',
196
+ all = false
197
+ ): Record<string, string | undefined> | string | undefined;
198
+
199
+ export type SetOutput = {
200
+ key: string;
201
+ value: string;
202
+ filepath: string;
203
+ envFilepath: string;
204
+ envSrc: string;
205
+ changed: boolean;
206
+ encryptedValue?: string;
207
+ publicKey?: string;
208
+ privateKey?: string;
209
+ privateKeyAdded?: boolean;
210
+ privateKeyName?: string;
211
+ error?: Error;
212
+ };
213
+
214
+ /**
215
+ * Set the value of a key in the .env file
216
+ *
217
+ * @param key - the key to set the value of
218
+ * @param value - the value to set
219
+ * @param envFile - the path to the .env file
220
+ * @param [encrypt] - whether to encrypt the value
221
+ */
222
+ export function set(
223
+ key: string,
224
+ value: string,
225
+ envFile: string | string,
226
+ encrypt?: boolean
227
+ ): EncryptOutput;
228
+
229
+ type StatusRow = {
230
+ filename: string;
231
+ filepath: string;
232
+ environment: string;
233
+ raw: string;
234
+ decrypted: any;
235
+ differences: Change[];
236
+ };
237
+
238
+ export type StatusOutput = {
239
+ changes: StatusRow[];
240
+ nochanges: StatusRow[];
241
+ untracked: StatusRow[];
242
+ };
243
+
244
+ /**
245
+ * Check the differences between the .env file and the decrypted values
246
+ *
247
+ * @param directory - current working directory
248
+ */
249
+ export function status(directory: string): StatusOutput;
250
+
251
+ export type GenExampleOutput = {
252
+ envExampleFile: string;
253
+ envFile: string | string[];
254
+ exampleFilepath: string;
255
+ addedKeys: string[];
256
+ injected: Record<string, string>;
257
+ preExisted: Record<string, string>;
258
+ };
259
+
260
+ /**
261
+ * Generate an example .env file
262
+ *
263
+ * @param directory - current working directory
264
+ * @param envFile - path to the .env file(s)
265
+ */
266
+ export function genexample(
267
+ directory: string,
268
+ envFile: string
269
+ ): GenExampleOutput;
270
+
271
+ export type Settings = {
272
+ DOTENVX_SETTINGS_FILEPATH: string;
273
+ };
274
+
275
+ type KeyOfSettings = Extract<keyof Settings, string>;
276
+
277
+ /**
278
+ * Get the dotenvx settings
279
+ *
280
+ * @param [key] - the key to get the value of
281
+ */
282
+ export function settings(
283
+ key: KeyOfSettings | undefined | null = null
284
+ ): Settings;
package/src/lib/main.js CHANGED
@@ -1,3 +1,4 @@
1
+ // @ts-check
1
2
  const path = require('path')
2
3
  const { logger } = require('./../shared/logger')
3
4
  const dotenv = require('dotenv')
@@ -18,6 +19,8 @@ const dotenvOptionPaths = require('./helpers/dotenvOptionPaths')
18
19
  const { setLogLevel } = require('../shared/logger')
19
20
 
20
21
  // proxies to dotenv
22
+
23
+ /** @type {import('./main').config} */
21
24
  const config = function (options = {}) {
22
25
  // allow user to set processEnv to write to
23
26
  let processEnv = process.env
@@ -44,29 +47,46 @@ const config = function (options = {}) {
44
47
  for (const optionPath of optionPaths) {
45
48
  // if DOTENV_KEY is set then assume we are checking envVaultFile
46
49
  if (DOTENV_KEY) {
47
- envs.push({ type: 'envVaultFile', value: path.join(path.dirname(optionPath), '.env.vault') })
50
+ envs.push({
51
+ type: 'envVaultFile',
52
+ value: path.join(path.dirname(optionPath), '.env.vault')
53
+ })
48
54
  } else {
49
55
  envs.push({ type: 'envFile', value: optionPath })
50
56
  }
51
57
  }
52
58
 
53
- const {
54
- processedEnvs,
55
- readableFilepaths,
56
- uniqueInjectedKeys
57
- } = new Run(envs, overload, DOTENV_KEY, processEnv).run()
59
+ const { processedEnvs, readableFilepaths, uniqueInjectedKeys } = new Run(
60
+ envs,
61
+ overload,
62
+ DOTENV_KEY,
63
+ processEnv
64
+ ).run()
58
65
 
59
66
  let lastError
67
+ /** @type {Record<string, string>} */
60
68
  const parsedAll = {}
61
69
 
62
70
  for (const processedEnv of processedEnvs) {
63
71
  if (processedEnv.type === 'envVaultFile') {
64
- logger.verbose(`loading env from encrypted ${processedEnv.filepath} (${path.resolve(processedEnv.filepath)})`)
65
- logger.debug(`decrypting encrypted env from ${processedEnv.filepath} (${path.resolve(processedEnv.filepath)})`)
72
+ logger.verbose(
73
+ `loading env from encrypted ${processedEnv.filepath} (${path.resolve(
74
+ processedEnv.filepath
75
+ )})`
76
+ )
77
+ logger.debug(
78
+ `decrypting encrypted env from ${
79
+ processedEnv.filepath
80
+ } (${path.resolve(processedEnv.filepath)})`
81
+ )
66
82
  }
67
83
 
68
84
  if (processedEnv.type === 'envFile') {
69
- logger.verbose(`loading env from ${processedEnv.filepath} (${path.resolve(processedEnv.filepath)})`)
85
+ logger.verbose(
86
+ `loading env from ${processedEnv.filepath} (${path.resolve(
87
+ processedEnv.filepath
88
+ )})`
89
+ )
70
90
  }
71
91
 
72
92
  if (processedEnv.error) {
@@ -76,7 +96,9 @@ const config = function (options = {}) {
76
96
  // do not warn for conventions (too noisy)
77
97
  if (!options.convention) {
78
98
  logger.warnv(processedEnv.error)
79
- logger.help(`? add one with [echo "HELLO=World" > ${processedEnv.filepath}] and re-run [dotenvx run -- yourcommand]`)
99
+ logger.help(
100
+ `? add one with [echo "HELLO=World" > ${processedEnv.filepath}] and re-run [dotenvx run -- yourcommand]`
101
+ )
80
102
  }
81
103
  } else {
82
104
  logger.warnv(processedEnv.error)
@@ -99,8 +121,12 @@ const config = function (options = {}) {
99
121
  // verbose/debug preExisted key/value
100
122
  const preExisted = processedEnv.preExisted
101
123
  for (const [key, value] of Object.entries(preExisted)) {
102
- logger.verbose(`${key} pre-exists (protip: use --overload to override)`)
103
- logger.debug(`${key} pre-exists as ${value} (protip: use --overload to override)`)
124
+ logger.verbose(
125
+ `${key} pre-exists (protip: use --overload to override)`
126
+ )
127
+ logger.debug(
128
+ `${key} pre-exists as ${value} (protip: use --overload to override)`
129
+ )
104
130
  }
105
131
  }
106
132
  }
@@ -126,47 +152,66 @@ const config = function (options = {}) {
126
152
  }
127
153
  }
128
154
 
155
+ /** @type {import('./main').configDotenv} */
129
156
  const configDotenv = function (options) {
130
157
  return dotenv.configDotenv(options)
131
158
  }
132
159
 
160
+ /** @type {import('./main').parse} */
133
161
  const parse = function (src) {
134
162
  return dotenv.parse(src)
135
163
  }
136
164
 
165
+ /** @type {import('./main').vaultEncrypt} */
137
166
  const vaultEncrypt = function (directory, envFile) {
138
167
  return new VaultEncrypt(directory, envFile).run()
139
168
  }
140
169
 
170
+ /** @type {import('./main').ls} */
141
171
  const ls = function (directory, envFile) {
142
172
  return new Ls(directory, envFile).run()
143
173
  }
144
174
 
175
+ /** @type {import('./main').genexample} */
145
176
  const genexample = function (directory, envFile) {
146
177
  return new Genexample(directory, envFile).run()
147
178
  }
148
179
 
149
- const get = function (key, envs = [], overload = false, DOTENV_KEY = '', all = false) {
180
+ /** @type {import('./main').get} */
181
+ const get = function (
182
+ key,
183
+ envs = [],
184
+ overload = false,
185
+ DOTENV_KEY = '',
186
+ all = false
187
+ ) {
150
188
  return new Get(key, envs, overload, DOTENV_KEY, all).run()
151
189
  }
152
190
 
191
+ /** @type {import('./main').set} */
153
192
  const set = function (key, value, envFile, encrypt) {
154
193
  return new Sets(key, value, envFile, encrypt).run()
155
194
  }
156
195
 
196
+ /** @type {import('./main').encrypt} */
157
197
  const encrypt = function (envFile) {
158
198
  return new Encrypt(envFile).run()
159
199
  }
160
200
 
201
+ /** @type {import('./main').status} */
161
202
  const status = function (directory) {
162
203
  return new Status(directory).run()
163
204
  }
164
205
 
206
+ /** @type {import('./main').settings} */
165
207
  const settings = function (key = null) {
208
+ // @ts-ignore
166
209
  return new Settings(key).run()
167
210
  }
168
211
 
169
212
  // misc/cleanup
213
+
214
+ /** @type {import('./main').decrypt} */
170
215
  const decrypt = function (encrypted, keyStr) {
171
216
  try {
172
217
  return dotenv.decrypt(encrypted, keyStr)
@@ -174,9 +219,15 @@ const decrypt = function (encrypted, keyStr) {
174
219
  switch (e.code) {
175
220
  case 'DECRYPTION_FAILED':
176
221
  // more helpful error when decryption fails
177
- logger.error('[DECRYPTION_FAILED] Unable to decrypt .env.vault with DOTENV_KEY.')
178
- logger.help('[DECRYPTION_FAILED] Run with debug flag [dotenvx run --debug -- yourcommand] or manually run [echo $DOTENV_KEY] to compare it to the one in .env.keys.')
179
- logger.debug(`[DECRYPTION_FAILED] DOTENV_KEY is ${process.env.DOTENV_KEY}`)
222
+ logger.error(
223
+ '[DECRYPTION_FAILED] Unable to decrypt .env.vault with DOTENV_KEY.'
224
+ )
225
+ logger.help(
226
+ '[DECRYPTION_FAILED] Run with debug flag [dotenvx run --debug -- yourcommand] or manually run [echo $DOTENV_KEY] to compare it to the one in .env.keys.'
227
+ )
228
+ logger.debug(
229
+ `[DECRYPTION_FAILED] DOTENV_KEY is ${process.env.DOTENV_KEY}`
230
+ )
180
231
  process.exit(1)
181
232
  break
182
233
  default:
@@ -57,7 +57,9 @@ class Genexample {
57
57
  }
58
58
 
59
59
  const currentEnvExample = dotenv.configDotenv({ path: exampleFilepath }).parsed
60
+ /** @type {Record<string, string>} */
60
61
  const injected = {}
62
+ /** @type {Record<string, string>} */
61
63
  const preExisted = {}
62
64
 
63
65
  for (const key of [...keys]) {
@@ -21,6 +21,7 @@ class Get {
21
21
 
22
22
  // typical scenario - return only envs that were identified in the .env file
23
23
  // iterate over all processedEnvs.parsed and grab from processEnv
24
+ /** @type {Record<string, string>} */
24
25
  const result = {}
25
26
  for (const processedEnv of processedEnvs) {
26
27
  // parsed means we saw the key in a file or --env flag. this effectively filters out any preset machine envs - while still respecting complex evaluating, expansion, and overload. in other words, the value might be the machine value because the key was displayed in a .env file
@@ -1,5 +1,6 @@
1
+ const { fdir: Fdir } = require('fdir')
1
2
  const path = require('path')
2
- const globSync = require('glob').globSync
3
+ const picomatch = require('picomatch')
3
4
 
4
5
  class Ls {
5
6
  constructor (directory = './', envFile = '.env*') {
@@ -14,27 +15,23 @@ class Ls {
14
15
  }
15
16
 
16
17
  _filepaths () {
17
- const options = {
18
- ignore: this.ignore,
19
- cwd: this.cwd // context dirctory for globSync
20
- }
18
+ const ignoreMatchers = this.ignore.map(pattern => picomatch(pattern))
19
+ const pathMatchers = this._patterns().map(pattern => picomatch(pattern))
20
+
21
+ const api = new Fdir()
22
+ .withRelativePaths()
23
+ .exclude((dir, path) => ignoreMatchers.some(matcher => matcher(path)))
24
+ .filter((path) => pathMatchers.some(matcher => matcher(path)))
21
25
 
22
- const patterns = this._patterns()
23
- return globSync(patterns, options)
26
+ return api.crawl(this.cwd).sync()
24
27
  }
25
28
 
26
29
  _patterns () {
27
30
  if (!Array.isArray(this.envFile)) {
28
- return `**/${this.envFile}`
31
+ return [`**/${this.envFile}`]
29
32
  }
30
33
 
31
- const out = []
32
-
33
- for (let i = 0; i < this.envFile.length; i++) {
34
- const part = this.envFile[i]
35
- out.push(`**/${part}`)
36
- }
37
- return out
34
+ return this.envFile.map(part => `**/${part}`)
38
35
  }
39
36
  }
40
37