@dotenvx/dotenvx 1.0.1 → 1.1.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 +7 -1
- package/README.md +12 -1
- package/package.json +2 -1
- package/src/lib/main.d.ts +284 -0
- package/src/lib/main.js +67 -16
- package/src/lib/services/genexample.js +2 -0
- package/src/lib/services/get.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
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
|
|
5
|
+
## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.1.0...main)
|
|
6
|
+
|
|
7
|
+
## 1.1.0
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* Add TypeScript type definitions ([#272](https://github.com/dotenvx/dotenvx/pull/272))
|
|
6
12
|
|
|
7
13
|
## 1.0.1
|
|
8
14
|
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
### Quickstart [](https://www.npmjs.com/package/@dotenvx/dotenvx) [](https://www.npmjs.com/package/@dotenvx/dotenvx)
|
|
12
|
+
### Quickstart [](https://www.npmjs.com/package/@dotenvx/dotenvx) [](https://github.com/dotenvx/dotenvx/tree/main/tests) [](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
|
|
2
|
+
"version": "1.1.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"
|
|
@@ -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({
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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(
|
|
65
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
103
|
-
|
|
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
|
-
|
|
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(
|
|
178
|
-
|
|
179
|
-
|
|
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]) {
|
package/src/lib/services/get.js
CHANGED
|
@@ -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
|