@dotenvx/dotenvx 1.32.1 → 1.34.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 +13 -1
- package/README.md +2 -1
- package/package.json +11 -1
- package/src/lib/config.js +1 -0
- package/src/lib/main.js +61 -5
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.
|
|
5
|
+
[Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.34.0...main)
|
|
6
|
+
|
|
7
|
+
## [1.34.0](https://github.com/dotenvx/dotenvx/compare/v1.33.0...v1.34.0)
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* `main.set` method now writes to files ([#517](https://github.com/dotenvx/dotenvx/pull/517))
|
|
12
|
+
|
|
13
|
+
## [1.33.0](https://github.com/dotenvx/dotenvx/compare/v1.32.1...v1.33.0)
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
* support ESM import convenience `import '@dotenvx/dotenvx/config'` ([#508](https://github.com/dotenvx/dotenvx/pull/508))
|
|
6
18
|
|
|
7
19
|
## [1.32.1](https://github.com/dotenvx/dotenvx/compare/v1.32.0...v1.32.1)
|
|
8
20
|
|
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ npm install @dotenvx/dotenvx --save
|
|
|
19
19
|
```js
|
|
20
20
|
// index.js
|
|
21
21
|
require('@dotenvx/dotenvx').config()
|
|
22
|
+
// or import('@dotenvx/dotenvx/config') if you're using esm
|
|
22
23
|
|
|
23
24
|
console.log(`Hello ${process.env.HELLO}`)
|
|
24
25
|
```
|
|
@@ -2024,7 +2025,7 @@ More examples
|
|
|
2024
2025
|
|
|
2025
2026
|
```js
|
|
2026
2027
|
// index.js
|
|
2027
|
-
require('@dotenvx/dotenvx').config({envKeysFile: '../../.env.keys'})
|
|
2028
|
+
require('@dotenvx/dotenvx').config({path: ['.env'], envKeysFile: '../../.env.keys'})
|
|
2028
2029
|
```
|
|
2029
2030
|
|
|
2030
2031
|
</details>
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.34.0",
|
|
3
3
|
"name": "@dotenvx/dotenvx",
|
|
4
4
|
"description": "a better dotenv–from the creator of `dotenv`",
|
|
5
5
|
"author": "@motdotla",
|
|
@@ -19,6 +19,16 @@
|
|
|
19
19
|
],
|
|
20
20
|
"main": "src/lib/main.js",
|
|
21
21
|
"types": "src/lib/main.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./src/lib/main.d.ts",
|
|
25
|
+
"require": "./src/lib/main.js",
|
|
26
|
+
"default": "./src/lib/main.js"
|
|
27
|
+
},
|
|
28
|
+
"./config": "./src/lib/config.js",
|
|
29
|
+
"./config.js": "./src/lib/config.js",
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
22
32
|
"bin": {
|
|
23
33
|
"dotenvx": "./src/cli/dotenvx.js",
|
|
24
34
|
"git-dotenvx": "./src/cli/dotenvx.js"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require('./main.js').config()
|
package/src/lib/main.js
CHANGED
|
@@ -15,6 +15,8 @@ const Genexample = require('./services/genexample')
|
|
|
15
15
|
// helpers
|
|
16
16
|
const buildEnvs = require('./helpers/buildEnvs')
|
|
17
17
|
const Parse = require('./helpers/parse')
|
|
18
|
+
const fsx = require('./helpers/fsx')
|
|
19
|
+
const isIgnoringDotenvKeys = require('./helpers/isIgnoringDotenvKeys')
|
|
18
20
|
|
|
19
21
|
/** @type {import('./main').config} */
|
|
20
22
|
const config = function (options = {}) {
|
|
@@ -169,13 +171,67 @@ const set = function (key, value, options = {}) {
|
|
|
169
171
|
encrypt = false
|
|
170
172
|
}
|
|
171
173
|
|
|
172
|
-
// envKeysFile
|
|
173
|
-
const envKeysFile = options.envKeysFile
|
|
174
|
-
|
|
175
|
-
// envs
|
|
176
174
|
const envs = buildEnvs(options)
|
|
175
|
+
const envKeysFilepath = options.envKeysFile
|
|
176
|
+
|
|
177
|
+
const {
|
|
178
|
+
processedEnvs,
|
|
179
|
+
changedFilepaths,
|
|
180
|
+
unchangedFilepaths
|
|
181
|
+
} = new Sets(key, value, envs, encrypt, envKeysFilepath).run()
|
|
182
|
+
|
|
183
|
+
let withEncryption = ''
|
|
184
|
+
|
|
185
|
+
if (encrypt) {
|
|
186
|
+
withEncryption = ' with encryption'
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
for (const processedEnv of processedEnvs) {
|
|
190
|
+
logger.verbose(`setting for ${processedEnv.envFilepath}`)
|
|
191
|
+
|
|
192
|
+
if (processedEnv.error) {
|
|
193
|
+
if (processedEnv.error.code === 'MISSING_ENV_FILE') {
|
|
194
|
+
logger.warn(processedEnv.error.message)
|
|
195
|
+
logger.help(`? add one with [echo "HELLO=World" > ${processedEnv.envFilepath}] and re-run [dotenvx set]`)
|
|
196
|
+
} else {
|
|
197
|
+
logger.warn(processedEnv.error.message)
|
|
198
|
+
if (processedEnv.error.help) {
|
|
199
|
+
logger.help(processedEnv.error.help)
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
fsx.writeFileX(processedEnv.filepath, processedEnv.envSrc)
|
|
204
|
+
|
|
205
|
+
logger.verbose(`${processedEnv.key} set${withEncryption} (${processedEnv.envFilepath})`)
|
|
206
|
+
logger.debug(`${processedEnv.key} set${withEncryption} to ${processedEnv.value} (${processedEnv.envFilepath})`)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (changedFilepaths.length > 0) {
|
|
211
|
+
logger.success(`✔ set ${key}${withEncryption} (${changedFilepaths.join(',')})`)
|
|
212
|
+
} else if (unchangedFilepaths.length > 0) {
|
|
213
|
+
logger.info(`no changes (${unchangedFilepaths})`)
|
|
214
|
+
} else {
|
|
215
|
+
// do nothing
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
for (const processedEnv of processedEnvs) {
|
|
219
|
+
if (processedEnv.privateKeyAdded) {
|
|
220
|
+
logger.success(`✔ key added to ${processedEnv.envKeysFilepath} (${processedEnv.privateKeyName})`)
|
|
177
221
|
|
|
178
|
-
|
|
222
|
+
if (!isIgnoringDotenvKeys()) {
|
|
223
|
+
logger.help('⮕ next run [dotenvx ext gitignore --pattern .env.keys] to gitignore .env.keys')
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
logger.help(`⮕ next run [${processedEnv.privateKeyName}='${processedEnv.privateKey}' dotenvx get ${key}] to test decryption locally`)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return {
|
|
231
|
+
processedEnvs,
|
|
232
|
+
changedFilepaths,
|
|
233
|
+
unchangedFilepaths
|
|
234
|
+
}
|
|
179
235
|
}
|
|
180
236
|
|
|
181
237
|
/** @type {import('./main').ls} */
|