Skip to content

Commit

Permalink
fix: sort npe (#73)
Browse files Browse the repository at this point in the history
> 修复 #72 导致的部分页面 npe
  • Loading branch information
elrrrrrrr authored Feb 23, 2024
1 parent f6b5394 commit 2b91ed1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/components/NPMVersionSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ interface VersionNode {

function sortNodes(nodes: VersionNode[]): void {
nodes.sort((a, b) => {
if ([a.value, b.value].every(v => semver.clean(v) === v)) {
return semver.rcompare(a.value, b.value);
}
const aVersion = semver.coerce(a.value);
const bVersion = semver.coerce(b.value);
if (!aVersion || !bVersion) {
return 0;
}
return semver.rcompare(a.value, b.value);
return semver.rcompare(aVersion, bVersion);
});
for (const node of nodes) {
sortNodes(node.children);
Expand Down

0 comments on commit 2b91ed1

Please sign in to comment.