@@ -3,7 +3,6 @@ const path = require('path')
3
3
const os = require ( 'os' )
4
4
const crypto = require ( 'crypto' )
5
5
const packageJson = require ( '../package.json' )
6
- const envOptions = require ( './env-options' )
7
6
8
7
const version = packageJson . version
9
8
@@ -26,6 +25,13 @@ function _getRandomTip () {
26
25
return TIPS [ Math . floor ( Math . random ( ) * TIPS . length ) ]
27
26
}
28
27
28
+ function parseBoolean ( value ) {
29
+ if ( typeof value === 'string' ) {
30
+ return ! [ 'false' , '0' , 'no' , 'off' , '' ] . includes ( value . toLowerCase ( ) )
31
+ }
32
+ return Boolean ( value )
33
+ }
34
+
29
35
function supportsAnsi ( ) {
30
36
return process . stdout . isTTY // && process.env.TERM !== 'dumb'
31
37
}
@@ -217,8 +223,8 @@ function _resolveHome (envPath) {
217
223
}
218
224
219
225
function _configVault ( options ) {
220
- const debug = Boolean ( options && options . debug )
221
- const quiet = Boolean ( options && options . quiet )
226
+ const debug = parseBoolean ( process . env . DOTENV_CONFIG_DEBUG || ( options && options . debug ) )
227
+ const quiet = parseBoolean ( process . env . DOTENV_CONFIG_QUIET || ( options && options . quiet ) )
222
228
223
229
if ( debug || ! quiet ) {
224
230
_log ( 'Loading env from encrypted .env.vault' )
@@ -239,8 +245,8 @@ function _configVault (options) {
239
245
function configDotenv ( options ) {
240
246
const dotenvPath = path . resolve ( process . cwd ( ) , '.env' )
241
247
let encoding = 'utf8'
242
- const debug = Boolean ( options && options . debug )
243
- const quiet = Boolean ( options && options . quiet )
248
+ let debug = parseBoolean ( process . env . DOTENV_CONFIG_DEBUG || ( options && options . debug ) )
249
+ let quiet = parseBoolean ( process . env . DOTENV_CONFIG_QUIET || ( options && options . quiet ) )
244
250
245
251
if ( options && options . encoding ) {
246
252
encoding = options . encoding
@@ -287,6 +293,10 @@ function configDotenv (options) {
287
293
288
294
const populated = DotenvModule . populate ( processEnv , parsedAll , options )
289
295
296
+ // handle user settings DOTENV_CONFIG_ options inside .env file(s)
297
+ debug = parseBoolean ( processEnv . DOTENV_CONFIG_DEBUG || debug )
298
+ quiet = parseBoolean ( process . env . DOTENV_CONFIG_QUIET || quiet )
299
+
290
300
if ( debug || ! quiet ) {
291
301
const keysCount = Object . keys ( populated ) . length
292
302
const shortPaths = [ ]
@@ -314,23 +324,21 @@ function configDotenv (options) {
314
324
315
325
// Populates process.env from .env file
316
326
function config ( options ) {
317
- const mergedOptions = Object . assign ( { } , envOptions , options )
318
-
319
327
// fallback to original dotenv if DOTENV_KEY is not set
320
- if ( _dotenvKey ( mergedOptions ) . length === 0 ) {
321
- return DotenvModule . configDotenv ( mergedOptions )
328
+ if ( _dotenvKey ( options ) . length === 0 ) {
329
+ return DotenvModule . configDotenv ( options )
322
330
}
323
331
324
- const vaultPath = _vaultPath ( mergedOptions )
332
+ const vaultPath = _vaultPath ( options )
325
333
326
334
// dotenvKey exists but .env.vault file does not exist
327
335
if ( ! vaultPath ) {
328
336
_warn ( `You set DOTENV_KEY but you are missing a .env.vault file at ${ vaultPath } . Did you forget to build it?` )
329
337
330
- return DotenvModule . configDotenv ( mergedOptions )
338
+ return DotenvModule . configDotenv ( options )
331
339
}
332
340
333
- return DotenvModule . _configVault ( mergedOptions )
341
+ return DotenvModule . _configVault ( options )
334
342
}
335
343
336
344
function decrypt ( encrypted , keyStr ) {
0 commit comments