Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
fix: filter functions and undefined out of makeEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Sep 18, 2019
1 parent 188414a commit 10c0c08
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion index.js
Expand Up @@ -458,12 +458,17 @@ function makeEnv (data, opts, prefix, env) {
return
}
var value = opts.config[i]
if (value instanceof Stream || Array.isArray(value)) return
if (value instanceof Stream || Array.isArray(value) || typeof value === 'function') return
if (i.match(/umask/)) value = umask.toString(value)

if (!value) value = ''
else if (typeof value === 'number') value = '' + value
else if (typeof value !== 'string') value = JSON.stringify(value)

if (typeof value !== 'string') {
return
}

value = value.indexOf('\n') !== -1
? JSON.stringify(value)
: value
Expand Down
9 changes: 8 additions & 1 deletion test/index.js
Expand Up @@ -20,7 +20,10 @@ test('makeEnv', function (t) {
'myPackage:bar': 2,
'myPackage:foo': 3,
'myPackage@1.0.0:baz': 4,
'myPackage@1.0.0:foo': 5
'myPackage@1.0.0:foo': 5,
ignoreThisFunction: () => {},
jsonsAsUndefined: { toJSON: () => undefined },
jsonsAsFunction: { toJSON: () => () => {} }
}

const env = lifecycle.makeEnv(pkg, {
Expand All @@ -44,6 +47,10 @@ test('makeEnv', function (t) {
t.equal('4', env.npm_package_config_baz, 'package@version config is included')
t.equal('5', env.npm_package_config_foo, 'package@version config overrides package config')

t.equal(env.npm_package_config_ignoreThisFunction, undefined)
t.equal(env.npm_package_config_jsonsAsUndefined, undefined)
t.equal(env.npm_package_config_jsonsAsFunction, undefined)

t.equal('--inspect-brk --abort-on-uncaught-exception', env.NODE_OPTIONS, 'nodeOptions sets NODE_OPTIONS')
t.end()
})
Expand Down

0 comments on commit 10c0c08

Please sign in to comment.