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

Commit 10c0c08

Browse files
committedSep 18, 2019
fix: filter functions and undefined out of makeEnv
1 parent 188414a commit 10c0c08

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed
 

‎index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,17 @@ function makeEnv (data, opts, prefix, env) {
458458
return
459459
}
460460
var value = opts.config[i]
461-
if (value instanceof Stream || Array.isArray(value)) return
461+
if (value instanceof Stream || Array.isArray(value) || typeof value === 'function') return
462462
if (i.match(/umask/)) value = umask.toString(value)
463+
463464
if (!value) value = ''
464465
else if (typeof value === 'number') value = '' + value
465466
else if (typeof value !== 'string') value = JSON.stringify(value)
466467

468+
if (typeof value !== 'string') {
469+
return
470+
}
471+
467472
value = value.indexOf('\n') !== -1
468473
? JSON.stringify(value)
469474
: value

‎test/index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ test('makeEnv', function (t) {
2020
'myPackage:bar': 2,
2121
'myPackage:foo': 3,
2222
'myPackage@1.0.0:baz': 4,
23-
'myPackage@1.0.0:foo': 5
23+
'myPackage@1.0.0:foo': 5,
24+
ignoreThisFunction: () => {},
25+
jsonsAsUndefined: { toJSON: () => undefined },
26+
jsonsAsFunction: { toJSON: () => () => {} }
2427
}
2528

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

50+
t.equal(env.npm_package_config_ignoreThisFunction, undefined)
51+
t.equal(env.npm_package_config_jsonsAsUndefined, undefined)
52+
t.equal(env.npm_package_config_jsonsAsFunction, undefined)
53+
4754
t.equal('--inspect-brk --abort-on-uncaught-exception', env.NODE_OPTIONS, 'nodeOptions sets NODE_OPTIONS')
4855
t.end()
4956
})

0 commit comments

Comments
 (0)
This repository has been archived.