From 2b91ed1fe96fafe5aa73f78914203dd149cfb149 Mon Sep 17 00:00:00 2001 From: elrrrrrrr Date: Fri, 23 Feb 2024 19:07:32 +0800 Subject: [PATCH] fix: sort npe (#73) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit > 修复 #72 导致的部分页面 npe --- src/components/NPMVersionSelect.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/NPMVersionSelect.tsx b/src/components/NPMVersionSelect.tsx index 07c646d..d673807 100644 --- a/src/components/NPMVersionSelect.tsx +++ b/src/components/NPMVersionSelect.tsx @@ -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);