Skip to content

Commit

Permalink
fix: update envVal function
Browse files Browse the repository at this point in the history
  • Loading branch information
siemhesda authored Jan 16, 2024
1 parent 354d50e commit 6ba9f30
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/package-envs.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// https://github.com/npm/rfcs/pull/183

const envVal = val => Array.isArray(val) ? val.map(v => envVal(v)).join('\n\n')
: val === null || val === false ? ''
: String(val)
const envVal = val => val === null || val === false ? '' : String(val)

const packageEnvs = (env, vals, prefix) => {
for (const [key, val] of Object.entries(vals)) {
if (val === undefined) {
continue
} else if (val && !Array.isArray(val) && typeof val === 'object') {
packageEnvs(env, val, `${prefix}${key}_`)
} else if (Array.isArray(val)) {
val.forEach((item, index) => {
env[`${prefix}${key}_${index}`] = envVal(item)
})
} else if (val && typeof val === 'object') {
if (Array.isArray(val)) {
val.forEach((item, index) => {
packageEnvs(env, { [`${key}_${index}`]: item }, `${prefix}`)
})
} else {
packageEnvs(env, val, `${prefix}${key}_`)
}
} else {
env[`${prefix}${key}`] = envVal(val)
}
Expand Down

0 comments on commit 6ba9f30

Please sign in to comment.