-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(envs): revert behavior of array in npm config (#194)
Reverts environment parsing of config arrays to use indexed names instead of joining them with double newlines. That change appears to have been introduced when the enviromnent values were added back into npm, but not in the same way they were done before. Fixes: npm/cli#3775 --------- Co-authored-by: siemhesda <[email protected]>
- Loading branch information
Showing
3 changed files
with
23 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,29 @@ | ||
// https://github.com/npm/rfcs/pull/183 | ||
|
||
const envVal = val => { | ||
if (Array.isArray(val)) { | ||
return val.map(v => envVal(v)).join('\n\n') | ||
} | ||
if (val === null || val === false) { | ||
return '' | ||
} | ||
return String(val) | ||
} | ||
|
||
const packageEnvs = (env, vals, prefix) => { | ||
const packageEnvs = (vals, prefix, env = {}) => { | ||
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 (val === null || val === false) { | ||
env[`${prefix}${key}`] = '' | ||
} else if (Array.isArray(val)) { | ||
val.forEach((item, index) => { | ||
packageEnvs({ [`${key}_${index}`]: item }, `${prefix}`, env) | ||
}) | ||
} else if (typeof val === 'object') { | ||
packageEnvs(val, `${prefix}${key}_`, env) | ||
} else { | ||
env[`${prefix}${key}`] = envVal(val) | ||
env[`${prefix}${key}`] = String(val) | ||
} | ||
} | ||
return env | ||
} | ||
|
||
module.exports = (env, pkg) => packageEnvs({ ...env }, { | ||
name: pkg.name, | ||
version: pkg.version, | ||
config: pkg.config, | ||
engines: pkg.engines, | ||
bin: pkg.bin, | ||
}, 'npm_package_') | ||
// https://github.com/npm/rfcs/pull/183 defines which fields we put into the environment | ||
module.exports = pkg => { | ||
return packageEnvs({ | ||
name: pkg.name, | ||
version: pkg.version, | ||
config: pkg.config, | ||
engines: pkg.engines, | ||
bin: pkg.bin, | ||
}, 'npm_package_') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters