Skip to content

Commit

Permalink
Add options.loadDotEnv as a way to opt out of .env parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
af committed Feb 16, 2017
1 parent af3f319 commit 7500638
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ function formatSpecDescription(spec) {
return `${spec.desc}${egText}${docsText}` || ''
}

function extendWithDotEnv(inputEnv) {
return extend(dotenv.config({ silent: true }), inputEnv)
}

function cleanEnv(inputEnv, specs = {}, options = {}) {
let output = {}
let defaultNodeEnv = ''
const errors = {}
const env = extend(dotenv.config({ silent: true }), inputEnv)
const shouldLoadDotEnv = (options.loadDotEnv !== false)
const env = shouldLoadDotEnv ? extendWithDotEnv(inputEnv) : inputEnv
const varKeys = Object.keys(specs)

// If validation for NODE_ENV isn't specified, use the default validation:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_dotenv.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ test('.env test in strict mode', () => {
}, opts)
assert.deepEqual(env, { MYNUM: 4 })
})

test('can opt out of dotenv with loadDotEnv=false', () => {
const env = cleanEnv({ FOO: 'bar' }, {}, { loadDotEnv: false })
assert.deepEqual(env, { FOO: 'bar' })
})

0 comments on commit 7500638

Please sign in to comment.