@dotenvx/dotenvx 1.6.1 → 1.6.3

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,21 +2,33 @@
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.6.1...main)
5
+ ## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.6.3...main)
6
+
7
+ ## 1.6.3
8
+
9
+ ### Changed
10
+
11
+ * adjust `dotenvx pro` to be dynamic if [dotenvx-pro](https://github.com/dotenvx/dotenvx-pro) is installed user's machine
12
+
13
+ ## 1.6.2
14
+
15
+ ### Added
16
+
17
+ * add more detailed type definitions ([#313](https://github.com/dotenvx/dotenvx/pull/313))
6
18
 
7
19
  ## 1.6.1
8
20
 
9
21
  ### Added
10
22
 
11
- * added support for `.env1` (`.env*`) file format. (private key expands to `DOTENV_PRIVATE_KEY_DEVELOPMENT1`) ([#312](https://github.com/dotenvx/dotenvx/pull/312))
23
+ * add support for `.env1` (`.env*`) file format. (private key expands to `DOTENV_PRIVATE_KEY_DEVELOPMENT1`) ([#312](https://github.com/dotenvx/dotenvx/pull/312))
12
24
 
13
25
  ## 1.6.0
14
26
 
15
27
  ### Added
16
28
 
17
29
  * add `dotenvx decrypt` command. works inversely to `dotenvx encrypt`. same flags. ([#294](https://github.com/dotenvx/dotenvx/pull/294))
18
- * add `--stdout` option to `dotenvx decrypt`. example: `dotenvx decrypt -f .env.production > somefile.txt` ([#298](https://github.com/dotenvx/dotenvx/pull/298))
19
- * add `--stdout` option to `dotenvx encrypt`. example: `dotenvx encrypt -f .env.production > somefile.txt` ([#298](https://github.com/dotenvx/dotenvx/pull/298))
30
+ * add `--stdout` option to `dotenvx decrypt`. example: `dotenvx decrypt -f .env.production --stdout > somefile.txt` ([#298](https://github.com/dotenvx/dotenvx/pull/298))
31
+ * add `--stdout` option to `dotenvx encrypt`. example: `dotenvx encrypt -f .env.production --stdout > somefile.txt` ([#298](https://github.com/dotenvx/dotenvx/pull/298))
20
32
 
21
33
  ### Changed
22
34
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.6.1",
2
+ "version": "1.6.3",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -1,15 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /* c8 ignore start */
4
- const fs = require('fs')
5
- const path = require('path')
6
- const { execSync } = require('child_process')
7
4
  const { Command } = require('commander')
8
5
  const program = new Command()
9
6
 
10
7
  const { setLogLevel, logger } = require('../shared/logger')
11
8
  const examples = require('./examples')
12
9
  const packageJson = require('./../lib/helpers/packageJson')
10
+ const executeDynamic = require('./../lib/helpers/executeDynamic')
13
11
 
14
12
  // for use with run
15
13
  const envs = []
@@ -32,11 +30,22 @@ program
32
30
  setLogLevel(options)
33
31
  })
34
32
 
33
+ program.addHelpText('after', ' pro 🏆 pro')
34
+
35
+ program
36
+ .argument('[command]', 'dynamic command')
37
+ .argument('[args...]', 'dynamic command arguments')
38
+ .action((command, args, cmdObj) => {
39
+ const rawArgs = process.argv.slice(3) // adjust the index based on where actual args start
40
+ executeDynamic(program, command, rawArgs)
41
+ })
42
+
35
43
  // cli
36
44
  program
37
45
  .name(packageJson.name)
38
46
  .description(packageJson.description)
39
47
  .version(packageJson.version)
48
+ .allowUnknownOption()
40
49
 
41
50
  // dotenvx run -- node index.js
42
51
  const runAction = require('./actions/run')
@@ -103,27 +112,6 @@ program.command('decrypt')
103
112
  .option('--stdout', 'send to stdout')
104
113
  .action(decryptAction)
105
114
 
106
- // dotenvx pro
107
- program.command('pro')
108
- .description('🏆 pro')
109
- .action(function (...args) {
110
- try {
111
- // execute `dotenvx-pro` if available
112
- execSync('dotenvx-pro', { stdio: ['inherit', 'inherit', 'ignore'] })
113
- } catch (_error) {
114
- const pro = fs.readFileSync(path.join(__dirname, './pro.txt'), 'utf8')
115
-
116
- console.log(pro)
117
- }
118
- })
119
-
120
- // // dotenvx ent
121
- // program.command('ent')
122
- // .description('🏢 enterprise')
123
- // .action(function (...args) {
124
- // console.log('coming soon (med-large companies)')
125
- // })
126
-
127
115
  // dotenvx ext
128
116
  program.addCommand(require('./commands/ext'))
129
117
 
@@ -0,0 +1,42 @@
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+ const childProcess = require('child_process')
4
+ const { logger } = require('../../shared/logger')
5
+
6
+ function executeDynamic (program, command, rawArgs) {
7
+ if (!command) {
8
+ program.outputHelp()
9
+ process.exit(1)
10
+ return
11
+ }
12
+
13
+ // construct the full command line manually including flags
14
+ const commandIndex = rawArgs.indexOf(command)
15
+ const forwardedArgs = rawArgs.slice(commandIndex + 1)
16
+
17
+ logger.debug(`command: ${command}`)
18
+ logger.debug(`args: ${JSON.stringify(forwardedArgs)}`)
19
+
20
+ const binPath = path.join(process.cwd(), 'node_modules', '.bin')
21
+ const newPath = `${binPath}:${process.env.PATH}`
22
+ const env = { ...process.env, PATH: newPath }
23
+
24
+ const result = childProcess.spawnSync(`dotenvx-${command}`, forwardedArgs, { stdio: 'inherit', env })
25
+ if (result.error) {
26
+ if (command === 'pro') {
27
+ // logger.warn(`[INSTALLATION_NEEDED] install dotenvx-${command} to use [dotenvx ${command}] commands 🏆`)
28
+ // logger.help('? see installation instructions [https://github.com/dotenvx/dotenvx-pro]')
29
+
30
+ const pro = fs.readFileSync(path.join(__dirname, './../../cli/pro.txt'), 'utf8')
31
+ console.log(pro)
32
+ } else {
33
+ logger.info(`error: unknown command '${command}'`)
34
+ }
35
+ }
36
+
37
+ if (result.status !== 0) {
38
+ process.exit(result.status)
39
+ }
40
+ }
41
+
42
+ module.exports = executeDynamic
package/src/lib/main.d.ts CHANGED
@@ -35,14 +35,6 @@ export interface DotenvConfigOptions {
35
35
  */
36
36
  encoding?: string;
37
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
38
  /**
47
39
  * Override any environment variables that have already been set on your machine with values from your .env file.
48
40
  * @default false
@@ -77,6 +69,40 @@ export interface DotenvConfigOptions {
77
69
  * Do not warn for missing .env files
78
70
  */
79
71
  convention?: string;
72
+
73
+ /**
74
+ * Turn on logging to help debug why certain keys or values are not being set as you expect.
75
+ *
76
+ * @default false
77
+ * @example require('@dotenvx/dotenvx').config({ debug: process.env.DEBUG })
78
+ */
79
+ debug?: boolean;
80
+
81
+ verbose?: boolean;
82
+
83
+ quiet?: boolean;
84
+
85
+ logLevel?:
86
+ | 'error'
87
+ | 'errorv'
88
+ | 'errorvp'
89
+ | 'errorvpb'
90
+ | 'errornocolor'
91
+ | 'warn'
92
+ | 'warnv'
93
+ | 'warnvp'
94
+ | 'warnvpb'
95
+ | 'success'
96
+ | 'successv'
97
+ | 'successvp'
98
+ | 'successvpb'
99
+ | 'info'
100
+ | 'help'
101
+ | 'help2'
102
+ | 'http'
103
+ | 'verbose'
104
+ | 'debug'
105
+ | 'blank';
80
106
  }
81
107
 
82
108
  export interface DotenvConfigOutput {
@@ -115,10 +141,13 @@ export function configDotenv(options?: DotenvConfigOptions): DotenvConfigOutput;
115
141
  *
116
142
  * @see https://dotenvx.com/docs
117
143
  *
118
- * @param encrypted - the encrypted ciphertext string
119
- * @param keyStr - the decryption key string
144
+ * @param envFile - the encrypted ciphertext string
145
+ * @param key - the decryption key(s)
120
146
  */
121
- export function decrypt(encrypted: string, keyStr: string): string;
147
+ export function decrypt(
148
+ envFile?: string | string[],
149
+ key?: string | string[]
150
+ ): string;
122
151
 
123
152
  export type EncryptRowOutput = {
124
153
  keys: string[];
@@ -143,10 +172,13 @@ export type EncryptOutput = {
143
172
  * Encrypt plaintext
144
173
  *
145
174
  * @see https://dotenvx.com/docs
146
- * @param envFile - path to the .env file
147
- * @param key - keys(s) to encrypt (default: all keys in .env file)
175
+ * @param envFile - path to the .env file(s)
176
+ * @param key - keys(s) to encrypt env file(s) (default: all keys in .env file)
148
177
  */
149
- export function encrypt(envFile: string, key: string): EncryptOutput;
178
+ export function encrypt(
179
+ envFile?: string | string[],
180
+ key?: string | string[]
181
+ ): EncryptOutput;
150
182
 
151
183
  export type VaultEncryptOutput = {
152
184
  dotenvKeys: Record<string, string>;
@@ -158,21 +190,8 @@ export type VaultEncryptOutput = {
158
190
  existingVaults: string[];
159
191
  addedDotenvFilenames: string[];
160
192
  envFile: string | string[];
161
- key: string | string[];
162
193
  };
163
194
 
164
- /**
165
- * Encrypt plaintext
166
- *
167
- * @see https://dotenvx.com/docs
168
- * @param directory - current working directory
169
- * @param envFile - path to the .env file(s)
170
- */
171
- export function vaultEncrypt(
172
- directory: string,
173
- envFile: string | string[]
174
- ): VaultEncryptOutput;
175
-
176
195
  /**
177
196
  * List all env files in the current working directory
178
197
  *
@@ -284,3 +303,22 @@ type KeyOfSettings = Extract<keyof Settings, string>;
284
303
  export function settings(
285
304
  key: KeyOfSettings | undefined | null = null
286
305
  ): Settings;
306
+
307
+ /**
308
+ * Decrypt ciphertext
309
+ * @param encrypted - the encrypted ciphertext string
310
+ * @param keyStr - the decryption key string
311
+ */
312
+ export function vaultDecrypt(encrypted: string, keyStr: string): string;
313
+
314
+ /**
315
+ * Encrypt plaintext
316
+ *
317
+ * @see https://dotenvx.com/docs
318
+ * @param directory - current working directory
319
+ * @param envFile - path to the .env file(s)
320
+ */
321
+ export function vaultEncrypt(
322
+ directory?: string,
323
+ envFile?: string | string[]
324
+ ): VaultEncryptOutput;
@@ -11,6 +11,10 @@ const replace = require('./../helpers/replace')
11
11
  const ENCODING = 'utf8'
12
12
 
13
13
  class Decrypt {
14
+ /**
15
+ * @param {string|string[]} [envFile]
16
+ * @param {string|string[]} [key]
17
+ **/
14
18
  constructor (envFile = '.env', key = []) {
15
19
  this.envFile = envFile
16
20
  this.key = key
@@ -12,6 +12,10 @@ const replace = require('./../helpers/replace')
12
12
  const ENCODING = 'utf8'
13
13
 
14
14
  class Encrypt {
15
+ /**
16
+ * @param {string|string[]} [envFile]
17
+ * @param {string|string[]} [key]
18
+ **/
15
19
  constructor (envFile = '.env', key = []) {
16
20
  this.envFile = envFile
17
21
  this.key = key
@@ -59,8 +63,10 @@ class Encrypt {
59
63
  // iterate over all non-encrypted values and encrypt them
60
64
  const parsed = dotenv.parse(src)
61
65
  for (const [key, value] of Object.entries(parsed)) {
62
- if (keys.length < 1 || keys.includes(key)) { // optionally control which key to encrypt
63
- const encrypted = isEncrypted(key, value) || isPublicKey(key, value)
66
+ if (keys.length < 1 || keys.includes(key)) {
67
+ // optionally control which key to encrypt
68
+ const encrypted =
69
+ isEncrypted(key, value) || isPublicKey(key, value)
64
70
  if (!encrypted) {
65
71
  row.keys.push(key) // track key(s)
66
72