Skip to content

Commit

Permalink
Sort outdated packages by name, fixes #2513 (#2759)
Browse files Browse the repository at this point in the history
This is the same npm does when calling `npm outdated`.
  • Loading branch information
hpurmann authored and bestander committed Feb 23, 2017
1 parent 4e4075f commit d853a96
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
12 changes: 6 additions & 6 deletions __tests__/commands/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ test.concurrent('displays correct dependency types', (): Promise<void> => {

// peerDependencies aren't included in the output
expect(json.data.body.length).toBe(3);
expect(body[0][0]).toBe('left-pad');
expect(body[0][4]).toBe('dependencies');
expect(body[1][0]).toBe('max-safe-integer');
expect(body[1][4]).toBe('devDependencies');
expect(body[2][0]).toBe('is-online');
expect(body[2][4]).toBe('optionalDependencies');
expect(body[0][0]).toBe('is-online');
expect(body[0][4]).toBe('optionalDependencies');
expect(body[1][0]).toBe('left-pad');
expect(body[1][4]).toBe('dependencies');
expect(body[2][0]).toBe('max-safe-integer');
expect(body[2][4]).toBe('devDependencies');
},
);
});
5 changes: 2 additions & 3 deletions src/package-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,8 @@ export default class PackageRequest {
const isDepOld = ({current, latest, wanted}) => latest === 'exotic' || (
latest !== 'exotic' && (semver.lt(current, wanted) || semver.lt(current, latest))
);
const isDepExpected = ({current, wanted}) => current === wanted;
const orderByExpected = (depA, depB) => isDepExpected(depA) && !isDepExpected(depB) ? 1 : -1;
const orderByName = (depA, depB) => depA.name.localeCompare(depB.name);

return deps.filter(isDepOld).sort(orderByExpected);
return deps.filter(isDepOld).sort(orderByName);
}
}

0 comments on commit d853a96

Please sign in to comment.