Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix NPE if dependencies fields are explicitly null in get-dep-spec #5

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/get-dep-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ module.exports = (mani, name) => {
// where we aren't fetching a manifest from the registry
// with multiple versions anyway.
const {
dependencies: deps = {},
optionalDependencies: optDeps = {},
peerDependencies: peerDeps = {},
dependencies: deps,
optionalDependencies: optDeps,
peerDependencies: peerDeps,
} = mani

return typeof deps[name] === 'string' ? deps[name]
: typeof optDeps[name] === 'string' ? optDeps[name]
: typeof peerDeps[name] === 'string' ? peerDeps[name]
return (deps && typeof deps[name] === 'string') ? deps[name]
: (optDeps && typeof optDeps[name] === 'string') ? optDeps[name]
: (peerDeps && typeof peerDeps[name] === 'string') ? peerDeps[name]
: null
}
5 changes: 5 additions & 0 deletions test/get-dep-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ t.equal(getDepSpec({
}, 'dep'), '1', 'prefer optional deps over peer')
t.equal(getDepSpec({ devDependencies: { dep: '1' } }, 'dep'), null,
'ignore dev')
t.equal(getDepSpec({
dependencies: null,
optionalDependencies: null,
peerDependencies: null
}, 'dep'), null, 'ignore null fields')