@dotenvx/dotenvx 1.14.2 → 1.16.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,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.14.2...main)
5
+ ## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.16.0...main)
6
+
7
+ ## 1.16.0
8
+
9
+ ### Changed
10
+
11
+ * for `dotenvx keypair` call out to `dotenvx pro keypair` if [pro](https://github.com/dotenvx/dotenvx/issues/259) installed ([#390](https://github.com/dotenvx/dotenvx/pull/390))
12
+
13
+ ## 1.15.0
14
+
15
+ ### Added
16
+
17
+ * add `--format=shell` option for `keypair` ([#389](https://github.com/dotenvx/dotenvx/pull/389))
6
18
 
7
19
  ## 1.14.2
8
20
 
package/README.md CHANGED
@@ -1057,13 +1057,18 @@ More examples
1057
1057
  This can be useful when combined with `env` on the command line.
1058
1058
 
1059
1059
  ```
1060
- $ env $(dotenvx get format --shell) your-command
1060
+ $ echo "console.log('Hello ' + process.env.KEY + ' ' + process.env.HELLO)" > index.js
1061
+ $ env $(dotenvx get --format=shell) node index.js
1062
+ Hello value World
1061
1063
  ```
1062
1064
 
1063
1065
  or with `export`.
1064
1066
 
1065
1067
  ```
1066
- $ export $(dotenvx get format --shell) your-command
1068
+ $ echo "console.log('Hello ' + process.env.KEY + ' ' + process.env.HELLO)" > index.js
1069
+ $ export $(dotenvx get --format=shell)
1070
+ $ node index.js
1071
+ Hello value World
1067
1072
  ```
1068
1073
 
1069
1074
  </details>
@@ -1302,7 +1307,7 @@ More examples
1302
1307
  </details>
1303
1308
  * <details><summary>`keypair DOTENV_PRIVATE_KEY`</summary><br>
1304
1309
 
1305
- Print specific key for `.env` file.
1310
+ Print specific keypair for `.env` file.
1306
1311
 
1307
1312
  ```sh
1308
1313
  $ echo "HELLO=World" > .env
@@ -1312,6 +1317,19 @@ More examples
1312
1317
  <privateKey>
1313
1318
  ```
1314
1319
 
1320
+ </details>
1321
+ * <details><summary>`keypair --format shell`</summary><br>
1322
+
1323
+ Print a shell formatted reponse of public/private keys.
1324
+
1325
+ ```sh
1326
+ $ echo "HELLO=World" > .env
1327
+ $ dotenx encrypt
1328
+
1329
+ $ dotenvx keypair --format shell
1330
+ DOTENV_PUBLIC_KEY=<publicKey> DOTENV_PRIVATE_KEY=<privateKey>
1331
+ ```
1332
+
1315
1333
  </details>
1316
1334
  * <details><summary>`ls`</summary><br>
1317
1335
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.14.2",
2
+ "version": "1.16.0",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -13,12 +13,24 @@ function keypair (key) {
13
13
  const results = main.keypair(options.envFile, key)
14
14
 
15
15
  if (typeof results === 'object' && results !== null) {
16
- let space = 0
17
- if (options.prettyPrint) {
18
- space = 2
19
- }
16
+ // inline shell format - env $(dotenvx keypair --format=shell) your-command
17
+ if (options.format === 'shell') {
18
+ let inline = ''
19
+ for (const [key, value] of Object.entries(results)) {
20
+ inline += `${key}=${value || ''} `
21
+ }
22
+ inline = inline.trim()
23
+
24
+ console.log(inline)
25
+ // json format
26
+ } else {
27
+ let space = 0
28
+ if (options.prettyPrint) {
29
+ space = 2
30
+ }
20
31
 
21
- console.log(JSON.stringify(results, null, space))
32
+ console.log(JSON.stringify(results, null, space))
33
+ }
22
34
  } else {
23
35
  if (results === undefined) {
24
36
  console.log('')
@@ -122,6 +122,7 @@ program.command('keypair')
122
122
  .argument('[key]', 'environment variable key name')
123
123
  .option('-f, --env-file <paths...>', 'path(s) to your env file(s)')
124
124
  .option('-pp, --pretty-print', 'pretty print output')
125
+ .option('--format <type>', 'format of the output (json, shell)', 'json')
125
126
  .action(keypairAction)
126
127
 
127
128
  // dotenvx ls
@@ -1,6 +1,7 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
3
  const dotenv = require('dotenv')
4
+ const childProcess = require('child_process')
4
5
 
5
6
  const ENCODING = 'utf8'
6
7
  const TYPE_ENV = 'env'
@@ -13,10 +14,12 @@ const inject = require('./../helpers/inject')
13
14
  const decrypt = require('./../helpers/decrypt')
14
15
  const parseDecryptEvalExpand = require('./../helpers/parseDecryptEvalExpand')
15
16
  const parseEnvironmentFromDotenvKey = require('./../helpers/parseEnvironmentFromDotenvKey')
16
- const smartDotenvPrivateKey = require('./../helpers/smartDotenvPrivateKey')
17
17
  const guessPrivateKeyFilename = require('./../helpers/guessPrivateKeyFilename')
18
+ const guessPrivateKeyName = require('./../helpers/guessPrivateKeyName')
18
19
  const detectEncoding = require('./../helpers/detectEncoding')
19
20
 
21
+ const Keypair = require('./../services/keypair')
22
+
20
23
  class Run {
21
24
  constructor (envs = [], overload = false, DOTENV_KEY = '', processEnv = process.env) {
22
25
  this.dotenvPrivateKeyNames = Object.keys(processEnv).filter(key => key.startsWith('DOTENV_PRIVATE_KEY')) // important, must be first. used by determineEnvs
@@ -94,8 +97,7 @@ class Run {
94
97
  const src = fs.readFileSync(filepath, { encoding })
95
98
  this.readableFilepaths.add(envFilepath)
96
99
 
97
- // if DOTENV_PRIVATE_KEY_* already set in process.env then use it
98
- const privateKey = smartDotenvPrivateKey(envFilepath)
100
+ const privateKey = this._determinePrivateKey(envFilepath)
99
101
  const { parsed, processEnv, warnings } = parseDecryptEvalExpand(src, privateKey, this.processEnv)
100
102
  row.parsed = parsed
101
103
  row.warnings = warnings
@@ -270,6 +272,29 @@ class Run {
270
272
 
271
273
  return decrypt(ciphertext, dotenvKey)
272
274
  }
275
+
276
+ _determinePrivateKey (envFilepath) {
277
+ const privateKeyName = guessPrivateKeyName(envFilepath)
278
+
279
+ let privateKey
280
+ try {
281
+ // if installed as sibling module
282
+ const projectRoot = path.resolve(process.cwd())
283
+ const dotenvxProPath = require.resolve('@dotenvx/dotenvx-pro', { paths: [projectRoot] })
284
+ const { keypair } = require(dotenvxProPath)
285
+ privateKey = keypair(envFilepath, privateKeyName)
286
+ } catch (_e) {
287
+ try {
288
+ // if installed as binary cli
289
+ privateKey = childProcess.execSync(`dotenvx-pro keypair ${privateKeyName} -f ${envFilepath} 2>/dev/null`).toString().trim()
290
+ } catch (_e) {
291
+ // fallback to local KeyPair - smart enough to handle process.env, .env.keys, etc
292
+ privateKey = new Keypair(envFilepath, privateKeyName).run()
293
+ }
294
+ }
295
+
296
+ return privateKey
297
+ }
273
298
  }
274
299
 
275
300
  module.exports = Run