Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

refactor: replace hand-rolled compareVersions with semver package

coderstory4f0533faa778
diff --git a/package.json b/package.json
index c0ae51e3..ed94b0d3 100644
--- a/package.json
+++ b/package.json
@@ -59,6 +59,7 @@
"@types/node": "catalog:types",
"@types/react": "catalog:types",
"@types/react-dom": "catalog:types",
+ "@types/semver": "catalog:",
"@vitejs/plugin-react": "catalog:build",
"babel-plugin-react-compiler": "catalog:build",
"bumpp": "catalog:release",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 57c06747..d8c87a1f 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -37,6 +37,10 @@ catalogs:
typescript:
specifier: ~5.8.3
version: 5.8.3
+ default:
+ '@types/semver':
+ specifier: ^7.8.0
+ version: 7.8.0
dsh:
'@deepseek-ai/cordis':
specifier: ^4.0.2
@@ -312,6 +316,9 @@ importers:
'@types/react-dom':
specifier: catalog:types
version: 19.2.4(@types/[email protected])
+ '@types/semver':
+ specifier: 'catalog:'
+ version: 7.8.0
'@vitejs/plugin-react':
specifier: catalog:build
@@ -2843,6 +2850,9 @@ packages:
resolution: {integrity: sha512-AnzbBERsrLKtk2XSfTbYRLjQPdy116Sty4q+T+Bp3IC4l6jNBvreVPAHmpq9qhXQM7CXZPjLVmGMw9sy+hxQ3w==}
+ '@types/[email protected]':
+ resolution: {integrity: sha512-1mAINjtQCXXeLkJ9ehXkwOcBpqtLxiVtKhpUf83DdRNdQKV0iXZpaHYqRr7nj+wvxuJzoAmAwXI+sCNMv1CzLQ==}
+
resolution: {integrity: sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==}
@@ -7473,6 +7483,8 @@ snapshots:
dependencies:
csstype: 3.2.3
+ '@types/[email protected]': {}
+
optional: true
diff --git a/src/components/config-core.tsx b/src/components/config-core.tsx
index 5e4aba1d..54960ab8 100644
--- a/src/components/config-core.tsx
+++ b/src/components/config-core.tsx
@@ -4,6 +4,7 @@ import { Button, Checkbox, Chip, Description, Label, Spinner } from '@heroui/rea
import { useOverlay } from '@overlastic/react'
import { invoke } from '@tauri-apps/api/core'
import { Fragment, useState } from 'react'
+import semver from 'semver'
import { useTranslation } from 'react-i18next'
import { If } from 'react-if-lite'
import { store } from '@/store'
@@ -392,58 +393,15 @@ function displayVersion(version: HarnessCore): string {
}
/**
- * 简化 semver 比较(不引入额外依赖),可处理 `0.1.1-rc.2` / `0.1.1` 格式。
- * 返回值:负数 a < b,0 相等,正数 a > b。
+ * Semver comparison using the `semver` package.
+ * Handles `dsh-`/`src-` prefixes by stripping before comparison.
+ * Returns: negative if a < b, 0 if equal, positive if a > b.
*/
function compareVersions(a: string, b: string): number {
- const parse = (value: string) => {
- let v = value
- while (v.startsWith('dsh-') || v.startsWith('src-'))
- v = v.replace(/^(?:src|dsh)-/, '')
- if (v.includes('-')) {
- const candidate = v.slice(0, v.lastIndexOf('-'))
- if (/^\d+\.\d+\.\d+(?:-[0-9A-Z.-]+)?$/i.test(candidate))
- v = candidate
- }
- const [core, pre = ''] = v.split('-', 2)
- const nums = core.split('.').map(n => parseInt(n, 10) || 0)
- return { nums, pre }
- }
- const pa = parse(a)
- const pb = parse(b)
- for (let i = 0; i < 3; i++) {
- const x = pa.nums[i] ?? 0
- const y = pb.nums[i] ?? 0
- if (x !== y)
- return x < y ? -1 : 1
- }
- // 无预发布号 > 有预发布号
- if (!pa.pre && !pb.pre)
+ const clean = (v: string) => v.replace(/^(?:src|dsh)-/, '')
+ const pa = semver.parse(clean(a))
+ const pb = semver.parse(clean(b))
+ if (!pa || !pb)
return 0
- if (!pa.pre)
- return 1
- if (!pb.pre)
- return -1
- // 预发布号按点分段比较:数字按数值、非数字按字典序
- const paParts = pa.pre.split('.').map(p => (Number.isNaN(Number(p)) ? p : Number(p)))
- const pbParts = pb.pre.split('.').map(p => (Number.isNaN(Number(p)) ? p : Number(p)))
- const len = Math.max(paParts.length, pbParts.length)
- for (let i = 0; i < len; i++) {
- const x = paParts[i]
- const y = pbParts[i]
- if (x === undefined)
- return -1
- if (y === undefined)
- return 1
- if (x === y)
- continue
- if (typeof x === 'number' && typeof y === 'number')
- return x < y ? -1 : 1
- if (typeof x === 'number')
- return -1
- if (typeof y === 'number')
- return 1
- return x < y ? -1 : 1
- }
- return 0
+ return semver.compare(pa, pb)
}