diff --git a/lib/package-envs.js b/lib/package-envs.js index 72185f2..44005cb 100644 --- a/lib/package-envs.js +++ b/lib/package-envs.js @@ -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) }