Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
Treat env value of '' as a missing value
Browse files Browse the repository at this point in the history
Fix: #2
  • Loading branch information
isaacs committed Aug 27, 2020
1 parent 217daf8 commit 3b63000
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class Config {
const prefix = 'npm_config_'
const conf = Object.create(null)
for (const [envKey, envVal] of Object.entries(this.env)) {
if (!/^npm_config_/i.test(envKey))
if (!/^npm_config_/i.test(envKey) || envVal === '')
continue
const key = envKey.substr('npm_config_'.length)
.replace(/(?!^)_/g, '-') // don't replace _ at the start of the key
Expand Down
6 changes: 5 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ loglevel = yolo

t.test('load configs from all files, cli, and env', async t => {
const env = {
npm_config_foo: 'from-env'
npm_config_foo: 'from-env',
npm_config_global: '',
}
const config = new Config({
npmPath: `${path}/npm`,
Expand All @@ -207,6 +208,9 @@ loglevel = yolo
})
await config.load()

t.equal(config.get('global', 'env'), undefined, 'empty env is missing')
t.equal(config.get('global'), false, 'empty env is missing')

config.set('asdf', 'quux', 'global')
await config.save('global')
const gres = readFileSync(`${path}/global/etc/npmrc`, 'utf8')
Expand Down

0 comments on commit 3b63000

Please sign in to comment.