dsh-version-check 0.0.0-stage → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +113 -2
- package/cordis.patch.yml +23 -0
- package/icon.svg +13 -0
- package/lib/client.js +977 -0
- package/lib/deployment.d.ts +36 -0
- package/lib/deployment.js +154 -0
- package/lib/gate.d.ts +22 -0
- package/lib/gate.js +92 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +833 -0
- package/lib/install.d.ts +29 -0
- package/lib/install.js +109 -0
- package/lib/preferences.d.ts +41 -0
- package/lib/preferences.js +132 -0
- package/lib/registry.d.ts +53 -0
- package/lib/registry.js +124 -0
- package/lib/styles/client.css +80 -0
- package/lib/versions.d.ts +32 -0
- package/lib/versions.js +100 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +64 -4
package/lib/versions.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// src/versions.ts
|
|
2
|
+
const NUMERIC_IDENTIFIER = /^(?:0|[1-9]\d*)$/;
|
|
3
|
+
const IDENTIFIER = /^[0-9A-Za-z-]+$/;
|
|
4
|
+
const VERSION = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
5
|
+
/**
|
|
6
|
+
* 解析一个版本字符串。
|
|
7
|
+
* @param text 版本字符串,允许 v 前缀与 build metadata。
|
|
8
|
+
* @returns 非法输入返回 null。
|
|
9
|
+
*/
|
|
10
|
+
function parseVersion(text) {
|
|
11
|
+
if (typeof text !== "string") return null;
|
|
12
|
+
const match = VERSION.exec(text);
|
|
13
|
+
if (match === null) return null;
|
|
14
|
+
if (![
|
|
15
|
+
match[1],
|
|
16
|
+
match[2],
|
|
17
|
+
match[3]
|
|
18
|
+
].every((part) => NUMERIC_IDENTIFIER.test(part))) return null;
|
|
19
|
+
const prerelease = match[4] === void 0 ? [] : match[4].split(".");
|
|
20
|
+
for (const identifier of prerelease) {
|
|
21
|
+
if (!IDENTIFIER.test(identifier)) return null;
|
|
22
|
+
if (/^\d+$/.test(identifier) && !NUMERIC_IDENTIFIER.test(identifier)) return null;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
major: Number(match[1]),
|
|
26
|
+
minor: Number(match[2]),
|
|
27
|
+
patch: Number(match[3]),
|
|
28
|
+
prerelease
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 取一个可比较的版本对象;非法版本就地抛出。
|
|
33
|
+
* @param text 版本字符串。
|
|
34
|
+
* @param label 参数名称,仅用于错误信息。
|
|
35
|
+
*/
|
|
36
|
+
function requireVersion(text, label) {
|
|
37
|
+
const parsed = parseVersion(text);
|
|
38
|
+
if (parsed === null) throw new TypeError(`${label} 不是合法的版本号: ${String(text)}`);
|
|
39
|
+
return parsed;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 比较两个 prerelease 标识符。
|
|
43
|
+
* 两个数字按数值比较;数字小于非数字;非数字按 ASCII 字典序比较。
|
|
44
|
+
*/
|
|
45
|
+
function compareIdentifiers(left, right) {
|
|
46
|
+
const leftNumeric = /^\d+$/.test(left);
|
|
47
|
+
const rightNumeric = /^\d+$/.test(right);
|
|
48
|
+
if (leftNumeric && rightNumeric) {
|
|
49
|
+
const leftValue = Number(left);
|
|
50
|
+
const rightValue = Number(right);
|
|
51
|
+
if (leftValue === rightValue) return 0;
|
|
52
|
+
return leftValue < rightValue ? -1 : 1;
|
|
53
|
+
}
|
|
54
|
+
if (leftNumeric !== rightNumeric) return leftNumeric ? -1 : 1;
|
|
55
|
+
if (left === right) return 0;
|
|
56
|
+
return left < right ? -1 : 1;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 按 semver 优先级比较两个版本号。
|
|
60
|
+
* 有 prerelease 的版本小于同号正式版;prerelease 标识符逐个比较,
|
|
61
|
+
* 前缀相同时更长的标识符列表更大。
|
|
62
|
+
*/
|
|
63
|
+
function compareVersions(a, b) {
|
|
64
|
+
const left = requireVersion(a, "a");
|
|
65
|
+
const right = requireVersion(b, "b");
|
|
66
|
+
for (const field of [
|
|
67
|
+
"major",
|
|
68
|
+
"minor",
|
|
69
|
+
"patch"
|
|
70
|
+
]) if (left[field] !== right[field]) return left[field] < right[field] ? -1 : 1;
|
|
71
|
+
const leftPrerelease = left.prerelease;
|
|
72
|
+
const rightPrerelease = right.prerelease;
|
|
73
|
+
if (leftPrerelease.length === 0 && rightPrerelease.length === 0) return 0;
|
|
74
|
+
if (leftPrerelease.length === 0) return 1;
|
|
75
|
+
if (rightPrerelease.length === 0) return -1;
|
|
76
|
+
const length = Math.min(leftPrerelease.length, rightPrerelease.length);
|
|
77
|
+
for (let index = 0; index < length; index += 1) {
|
|
78
|
+
const result = compareIdentifiers(leftPrerelease[index], rightPrerelease[index]);
|
|
79
|
+
if (result !== 0) return result;
|
|
80
|
+
}
|
|
81
|
+
if (leftPrerelease.length === rightPrerelease.length) return 0;
|
|
82
|
+
return leftPrerelease.length < rightPrerelease.length ? -1 : 1;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 取版本号 prerelease 渠道,即第一个 prerelease 标识符。
|
|
86
|
+
* @param version 版本字符串。
|
|
87
|
+
* @returns 无 prerelease 或版本非法时返回 null。
|
|
88
|
+
*/
|
|
89
|
+
function prereleaseChannel(version) {
|
|
90
|
+
const parsed = parseVersion(version);
|
|
91
|
+
if (parsed === null || parsed.prerelease.length === 0) return null;
|
|
92
|
+
return parsed.prerelease[0];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* 判断字符串是否是一个合法版本号。
|
|
96
|
+
*/
|
|
97
|
+
function isValidVersion(text) {
|
|
98
|
+
return parseVersion(text) !== null;
|
|
99
|
+
}
|
|
100
|
+
export { compareVersions, isValidVersion, parseVersion, prereleaseChannel };
|
package/locale/en.json
ADDED
package/locale/zh.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-version-check",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "在 DSH Web 侧边栏底部显示 DSH 版本,从 npm 检查新版本,支持一键更新、把主程序回滚到更早的已发布版本,并在更新与回滚后自动重启服务;更新检查可在设置页里开关与调整。",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/kerolt/dsh-version-check.git"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "./lib/index.js",
|
|
11
|
+
"types": "./lib/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./lib/index.d.ts",
|
|
15
|
+
"default": "./lib/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./client": "./lib/client.js",
|
|
18
|
+
"./locale/*.json": "./locale/*.json",
|
|
19
|
+
"./icon": "./icon.svg",
|
|
20
|
+
"./package.json": "./package.json"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"lib",
|
|
24
|
+
"cordis.patch.yml",
|
|
25
|
+
"locale/*.json",
|
|
26
|
+
"icon.svg",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"dsh",
|
|
34
|
+
"dsh-plugin",
|
|
35
|
+
"version-check"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsdown",
|
|
39
|
+
"check": "tsc -p tsconfig.json",
|
|
40
|
+
"prepack": "npm run build",
|
|
41
|
+
"pretest": "npm run build",
|
|
42
|
+
"test": "node --test test/*.test.ts",
|
|
43
|
+
"verify": "npm run build && npm run check && node --test test/*.test.ts"
|
|
44
|
+
},
|
|
45
|
+
"dsh": {
|
|
46
|
+
"bundle": {
|
|
47
|
+
"patch": "./cordis.patch.yml"
|
|
48
|
+
},
|
|
49
|
+
"client": {
|
|
50
|
+
"platform": "web",
|
|
51
|
+
"immediately": true,
|
|
52
|
+
"inject": [
|
|
53
|
+
"@deepseek-ai/dsh-client-locale",
|
|
54
|
+
"@deepseek-ai/dsh-client-ui-sidebar",
|
|
55
|
+
"@deepseek-ai/dsh-client-ui-settings"
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@deepseek-ai/cordis": "~4.0.5",
|
|
61
|
+
"@deepseek-ai/dsh-host-webserver": "^0.2.1-rc.3",
|
|
62
|
+
"@types/node": "^24.19.2",
|
|
63
|
+
"tsdown": "^0.23.4",
|
|
64
|
+
"typescript": "^5.9.3"
|
|
65
|
+
}
|
|
66
|
+
}
|