Skip to content

Commit

Permalink
fix: correct expandEnv bug when passing in a new object in the data o…
Browse files Browse the repository at this point in the history
…ption
  • Loading branch information
serdnam authored and jsumners committed Oct 24, 2023
1 parent 089c90e commit b355984
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,16 @@ function envSchema (_opts) {

/* istanbul ignore else */
if (env) {
if (expandEnv) {
require('dotenv-expand').expand({ parsed: process.env })
}
data.unshift(process.env)
}

const merge = {}
data.forEach(d => Object.assign(merge, d))

if (expandEnv) {
require('dotenv-expand').expand({ ignoreProcessEnv: true, parsed: merge })
}

const ajv = chooseAjvInstance(sharedAjvInstance, opts.ajv)

const valid = ajv.validate(schema, merge)
Expand Down
24 changes: 24 additions & 0 deletions test/expand.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ const tests = [
confExpected: {
EXPANDED_VALUE_FROM_DOTENV: 'the password is password!'
}
},
{
name: 'simple object - ok - expandEnv works when passed an arbitrary new object based on process.env as data',
schema: {
type: 'object',
properties: {
URL: {
type: 'string'
},
K8S_NAMESPACE: {
type: 'string'
}
}
},
expandEnv: true,
isOk: true,
data: {
...process.env,
K8S_NAMESPACE: 'hello'
},
confExpected: {
URL: 'https://prefix.hello.pluto.my.domain.com',
K8S_NAMESPACE: 'hello'
}
}
]

Expand Down

0 comments on commit b355984

Please sign in to comment.