@dotenvx/dotenvx 1.65.0 → 1.65.2

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.65.0",
2
+ "version": "1.65.2",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "secrets for agents–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -53,7 +53,14 @@ async function run () {
53
53
  readableStrings,
54
54
  readableFilepaths,
55
55
  uniqueInjectedKeys
56
- } = await new Run(envs, options.overload, process.env, options.envKeysFile, noOps).run()
56
+ } = await new Run(envs, options.overload, process.env, options.envKeysFile, noOps, {
57
+ beforeOpsKeypair: () => {
58
+ if (spinner) spinner.stop()
59
+ },
60
+ afterOpsKeypair: () => {
61
+ if (spinner) spinner.start('injecting')
62
+ }
63
+ }).run()
57
64
 
58
65
  for (const processedEnv of processedEnvs) {
59
66
  if (processedEnv.type === 'envFile') {
@@ -42,7 +42,7 @@ class Ops {
42
42
  if (publicKey) args.push(publicKey)
43
43
 
44
44
  try {
45
- return JSON.parse(await this._exec(binary, args))
45
+ return JSON.parse(await this._execInteractive(binary, args))
46
46
  } catch (_e) {
47
47
  return {}
48
48
  }
@@ -58,7 +58,7 @@ class Ops {
58
58
  if (publicKey) args.push(publicKey)
59
59
 
60
60
  try {
61
- return JSON.parse(this._execSync(binary, args))
61
+ return JSON.parse(this._execInteractiveSync(binary, args))
62
62
  } catch (_e) {
63
63
  return {}
64
64
  }
@@ -104,6 +104,36 @@ class Ops {
104
104
  return childProcess.execFileSync(binary, args).toString().trim()
105
105
  }
106
106
 
107
+ _execInteractive (binary, args) {
108
+ return new Promise((resolve, reject) => {
109
+ const subprocess = childProcess.spawn(binary, args, {
110
+ stdio: ['inherit', 'pipe', 'inherit']
111
+ })
112
+ let stdout = ''
113
+
114
+ subprocess.stdout.on('data', (data) => {
115
+ stdout += data.toString()
116
+ })
117
+ subprocess.on('error', reject)
118
+ subprocess.on('close', (code) => {
119
+ if (code !== 0) {
120
+ reject(new Error(`${binary} ${args.join(' ')} exited with code ${code}`))
121
+ return
122
+ }
123
+
124
+ resolve(stdout.trim())
125
+ })
126
+ })
127
+ }
128
+
129
+ _execInteractiveSync (binary, args) {
130
+ logger.debug(binary)
131
+ logger.debug(args)
132
+ return childProcess.execFileSync(binary, args, {
133
+ stdio: ['inherit', 'pipe', 'inherit']
134
+ }).toString().trim()
135
+ }
136
+
107
137
  async _resolveBinary () {
108
138
  if (this._binaryPromise) return this._binaryPromise
109
139
 
@@ -1,7 +1,15 @@
1
1
  const Ops = require('../../extensions/ops')
2
2
 
3
- async function opsKeypair (existingPublicKey) {
4
- const kp = await new Ops().keypair(existingPublicKey)
3
+ async function opsKeypair (existingPublicKey, options = {}) {
4
+ if (options.beforeOpsKeypair) await options.beforeOpsKeypair()
5
+
6
+ let kp
7
+ try {
8
+ kp = await new Ops().keypair(existingPublicKey)
9
+ } finally {
10
+ if (options.afterOpsKeypair) await options.afterOpsKeypair()
11
+ }
12
+
5
13
  const publicKey = kp.public_key
6
14
  const privateKey = kp.private_key
7
15
 
@@ -72,7 +72,10 @@ async function keyValues (filepath, opts = {}) {
72
72
 
73
73
  // ops
74
74
  if (!noOps && !privateKey && publicKey && publicKey.length > 0) {
75
- const kp = await opsKeypair(publicKey)
75
+ const kp = await opsKeypair(publicKey, {
76
+ beforeOpsKeypair: opts.beforeOpsKeypair,
77
+ afterOpsKeypair: opts.afterOpsKeypair
78
+ })
76
79
  privateKey = kp.privateKey
77
80
  }
78
81
 
@@ -17,12 +17,14 @@ const {
17
17
  } = require('./../helpers/keyResolution')
18
18
 
19
19
  class Run {
20
- constructor (envs = [], overload = false, processEnv = process.env, envKeysFilepath = null, noOps = false) {
20
+ constructor (envs = [], overload = false, processEnv = process.env, envKeysFilepath = null, noOps = false, options = {}) {
21
21
  this.envs = envs
22
22
  this.overload = overload
23
23
  this.processEnv = processEnv
24
24
  this.envKeysFilepath = envKeysFilepath
25
25
  this.noOps = noOps
26
+ this.beforeOpsKeypair = options.beforeOpsKeypair
27
+ this.afterOpsKeypair = options.afterOpsKeypair
26
28
 
27
29
  this.processedEnvs = []
28
30
  this.readableFilepaths = new Set()
@@ -179,7 +181,12 @@ class Run {
179
181
  this.readableFilepaths.add(envFilepath)
180
182
 
181
183
  const { privateKeyName } = keyNames(filepath)
182
- const { privateKeyValue } = await keyValues(filepath, { keysFilepath: this.envKeysFilepath, noOps: this.noOps })
184
+ const { privateKeyValue } = await keyValues(filepath, {
185
+ keysFilepath: this.envKeysFilepath,
186
+ noOps: this.noOps,
187
+ beforeOpsKeypair: this.beforeOpsKeypair,
188
+ afterOpsKeypair: this.afterOpsKeypair
189
+ })
183
190
 
184
191
  const {
185
192
  parsed,