Skip to content

Commit

Permalink
fix(registry-change): prioritize dependencies over all other depend…
Browse files Browse the repository at this point in the history
…ency types

see #409
  • Loading branch information
Realtin authored and christophwitzko committed Jul 7, 2017
1 parent db2270a commit 3f163a9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
18 changes: 17 additions & 1 deletion jobs/registry-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,24 @@ module.exports = async function (
'_id'
)

return packages
// Prioritize `dependencies` over all other dependency types
// https://github.com/greenkeeperio/greenkeeper/issues/409

const order = {
'dependencies': 1,
'devDependencies': 2,
'optionalDependencies': 3
}

const sortByDependency = (packageA, packageB) => {
return order[packageA.value.type] - order[packageB.value.type]
}

const filteredSortedPackages = packages
.filter(pkg => pkg.value.type !== 'peerDependencies')
.sort(sortByDependency)

return _.sortedUniqBy(filteredSortedPackages, pkg => pkg.value.fullName)
.map(pkg => {
const account = accounts[pkg.value.accountId]
const plan = account.plan
Expand Down
40 changes: 40 additions & 0 deletions test/jobs/registry-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,45 @@ test('registry change create jobs', async t => {
tt.is(newJobs.length, 0, 'no new jobs')
tt.end()
})

t.test('registry change updates dependencies if duplicated as devDependencies', async tt => {
tt.plan(2)
await repositories.put({
_id: '775',
enabled: true,
type: 'repository',
fullName: 'owner/repo3',
accountId: '999',
packages: {
'package.json': {
dependencies: {
eslint: '1.0.0'
},
devDependencies: {
eslint: '1.0.0'
}
}
}
})

const newJobs = await worker({
name: 'registry-change',
dependency: 'eslint',
distTags: {
latest: '10.0.0'
},
versions: {
'10.0.0': {
gitHead: 'b75aeb3'
}
},
registry: 'https://skimdb.npmjs.com/registry'
})

tt.is(newJobs.length, 1, 'one new jobs')
tt.is(newJobs[0].data.type, 'dependencies')
tt.end()
})
t.end()
})

Expand All @@ -156,6 +195,7 @@ tearDown(async () => {
await repositories.remove(await repositories.get('888'))
await repositories.remove(await repositories.get('777'))
await repositories.remove(await repositories.get('776'))
await repositories.remove(await repositories.get('775'))
await npm.remove(await npm.get('standard'))
await npm.remove(await npm.get('eslint'))
})

0 comments on commit 3f163a9

Please sign in to comment.