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: handle null values for dependency objects #6

Merged
merged 1 commit into from
Mar 26, 2021
Merged
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
6 changes: 3 additions & 3 deletions lib/get-dep-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module.exports = (mani, name) => {
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
}
34 changes: 29 additions & 5 deletions test/get-dep-spec.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
const t = require('tap')
const getDepSpec = require('../lib/get-dep-spec.js')

t.equal(getDepSpec({ dependencies: { dep: '1' } }, 'dep'), '1')
t.equal(getDepSpec({ optionalDependencies: { dep: '1' } }, 'dep'), '1')
t.equal(getDepSpec({ peerDependencies: { dep: '1' } }, 'dep'), '1')
t.equal(getDepSpec({
dependencies: { dep: '1' }
}, 'dep'), '1')

t.equal(getDepSpec({
optionalDependencies: { dep: '1' }
}, 'dep'), '1')

t.equal(getDepSpec({
dependencies: null,
optionalDependencies: { dep: '1' }
}, 'dep'), '1', 'allows dependencies to be null')

t.equal(getDepSpec({
peerDependencies: { dep: '1' }
}, 'dep'), '1')

t.equal(getDepSpec({
dependencies: null,
optioanlDependencies: null,
peerDependencies: { dep: '1' }
}, 'dep'), '1', 'allows optionalDependencies to be null')

t.equal(getDepSpec({
dependencies: { dep: '1' },
optionalDependencies: { dep: '2' },
}, 'dep'), '1', 'prefer prod deps over optional')

t.equal(getDepSpec({
dependencies: { dep: '1' },
peerDependencies: { dep: '2' },
}, 'dep'), '1', 'prefer prod deps over peer')

t.equal(getDepSpec({
optionalDependencies: { dep: '1' },
peerDependencies: { dep: '2' },
}, 'dep'), '1', 'prefer optional deps over peer')
t.equal(getDepSpec({ devDependencies: { dep: '1' } }, 'dep'), null,
'ignore dev')

t.equal(getDepSpec({
devDependencies: { dep: '1' }
}, 'dep'), null, 'ignore dev')