Skip to content

Commit b355984

Browse files
serdnamjsumners
authored andcommitted
fix: correct expandEnv bug when passing in a new object in the data option
1 parent 089c90e commit b355984

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,16 @@ function envSchema (_opts) {
6868

6969
/* istanbul ignore else */
7070
if (env) {
71-
if (expandEnv) {
72-
require('dotenv-expand').expand({ parsed: process.env })
73-
}
7471
data.unshift(process.env)
7572
}
7673

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

77+
if (expandEnv) {
78+
require('dotenv-expand').expand({ ignoreProcessEnv: true, parsed: merge })
79+
}
80+
8081
const ajv = chooseAjvInstance(sharedAjvInstance, opts.ajv)
8182

8283
const valid = ajv.validate(schema, merge)

test/expand.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,30 @@ const tests = [
4646
confExpected: {
4747
EXPANDED_VALUE_FROM_DOTENV: 'the password is password!'
4848
}
49+
},
50+
{
51+
name: 'simple object - ok - expandEnv works when passed an arbitrary new object based on process.env as data',
52+
schema: {
53+
type: 'object',
54+
properties: {
55+
URL: {
56+
type: 'string'
57+
},
58+
K8S_NAMESPACE: {
59+
type: 'string'
60+
}
61+
}
62+
},
63+
expandEnv: true,
64+
isOk: true,
65+
data: {
66+
...process.env,
67+
K8S_NAMESPACE: 'hello'
68+
},
69+
confExpected: {
70+
URL: 'https://prefix.hello.pluto.my.domain.com',
71+
K8S_NAMESPACE: 'hello'
72+
}
4973
}
5074
]
5175

0 commit comments

Comments
 (0)