@xiaozhi-client/cli 1.9.7 → 1.9.8-beta.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiaozhi-client/cli",
3
- "version": "1.9.7",
3
+ "version": "1.9.8-beta.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "consola": "^3.4.2",
21
- "@xiaozhi-client/config": "1.9.7"
21
+ "@xiaozhi-client/config": "1.9.8-beta.0"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/node": "^24.3.0",
package/src/Container.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  */
4
4
 
5
5
  import { configManager } from "@xiaozhi-client/config";
6
+ import { VersionUtils } from "@xiaozhi-client/version";
6
7
  import { ErrorHandler } from "./errors/ErrorHandlers";
7
8
  import type { IDIContainer } from "./interfaces/Config";
8
9
  import { FileUtils } from "./utils/FileUtils";
@@ -10,7 +11,6 @@ import { FormatUtils } from "./utils/FormatUtils";
10
11
  import { PathUtils } from "./utils/PathUtils";
11
12
  import { PlatformUtils } from "./utils/PlatformUtils";
12
13
  import { Validation } from "./utils/Validation";
13
- import { VersionUtils } from "./utils/VersionUtils";
14
14
 
15
15
  /**
16
16
  * 依赖注入容器实现
package/tsup.config.ts CHANGED
@@ -62,6 +62,9 @@ export default defineConfig({
62
62
  // @xiaozhi-client/config 包(运行时从 dist/config 读取)
63
63
  "@xiaozhi-client/config",
64
64
  "@xiaozhi-client/config.js",
65
+ // @xiaozhi-client/version 包(运行时从 dist/version 读取)
66
+ "@xiaozhi-client/version",
67
+ "@xiaozhi-client/version.js",
65
68
  // Backend 模块(运行时从 dist/backend 读取)
66
69
  "@root/WebServer",
67
70
  "@root/WebServer.js",
@@ -1,64 +0,0 @@
1
- /**
2
- * 版本管理工具
3
- */
4
-
5
- import { APP_NAME, VERSION } from "../version";
6
-
7
- /**
8
- * 版本信息接口
9
- */
10
- export interface VersionInfo {
11
- version: string;
12
- name?: string;
13
- description?: string;
14
- author?: string;
15
- }
16
-
17
- /**
18
- * 版本工具类
19
- */
20
- export class VersionUtils {
21
- /**
22
- * 获取版本号(构建时注入)
23
- */
24
- static getVersion(): string {
25
- return VERSION;
26
- }
27
-
28
- /**
29
- * 获取完整版本信息(构建时注入)
30
- */
31
- static getVersionInfo(): VersionInfo {
32
- return {
33
- version: VERSION,
34
- name: APP_NAME,
35
- };
36
- }
37
-
38
- /**
39
- * 比较版本号
40
- */
41
- static compareVersions(version1: string, version2: string): number {
42
- const v1Parts = version1.split(".").map(Number);
43
- const v2Parts = version2.split(".").map(Number);
44
- const maxLength = Math.max(v1Parts.length, v2Parts.length);
45
-
46
- for (let i = 0; i < maxLength; i++) {
47
- const v1Part = v1Parts[i] || 0;
48
- const v2Part = v2Parts[i] || 0;
49
-
50
- if (v1Part > v2Part) return 1;
51
- if (v1Part < v2Part) return -1;
52
- }
53
-
54
- return 0;
55
- }
56
-
57
- /**
58
- * 检查版本是否有效
59
- */
60
- static isValidVersion(version: string): boolean {
61
- const versionRegex = /^\d+\.\d+\.\d+(-[a-zA-Z0-9.-]+)?$/;
62
- return versionRegex.test(version);
63
- }
64
- }
@@ -1,116 +0,0 @@
1
- /**
2
- * 版本管理工具单元测试
3
- */
4
-
5
- import { describe, expect, it } from "vitest";
6
- import { VersionUtils } from "../VersionUtils";
7
-
8
- describe("VersionUtils", () => {
9
- // 不再需要 beforeEach 和 afterEach,因为不再使用缓存
10
- // 也不再需要 mock fs、path、url 模块,因为不再读取文件
11
-
12
- describe("获取版本号", () => {
13
- it("应返回编译时注入的版本号", () => {
14
- const result = VersionUtils.getVersion();
15
- // 在测试环境中,版本号被定义为 "1.0.0-test"
16
- expect(result).toBe("1.0.0-test");
17
- });
18
-
19
- it("多次调用应返回相同的版本号", () => {
20
- const result1 = VersionUtils.getVersion();
21
- const result2 = VersionUtils.getVersion();
22
- expect(result1).toBe(result2);
23
- expect(result1).toBe("1.0.0-test");
24
- });
25
- });
26
-
27
- describe("获取版本信息", () => {
28
- it("应返回完整的版本信息", () => {
29
- const result = VersionUtils.getVersionInfo();
30
- expect(result).toEqual({
31
- version: "1.0.0-test",
32
- name: "xiaozhi-client",
33
- });
34
- });
35
-
36
- it("应包含版本号和名称", () => {
37
- const result = VersionUtils.getVersionInfo();
38
- expect(result.version).toBeDefined();
39
- expect(result.name).toBeDefined();
40
- expect(typeof result.version).toBe("string");
41
- expect(typeof result.name).toBe("string");
42
- });
43
- });
44
-
45
- describe("比较版本号", () => {
46
- it("当version1大于version2时应返回1", () => {
47
- expect(VersionUtils.compareVersions("2.0.0", "1.0.0")).toBe(1);
48
- expect(VersionUtils.compareVersions("1.1.0", "1.0.0")).toBe(1);
49
- expect(VersionUtils.compareVersions("1.0.1", "1.0.0")).toBe(1);
50
- });
51
-
52
- it("当version1小于version2时应返回-1", () => {
53
- expect(VersionUtils.compareVersions("1.0.0", "2.0.0")).toBe(-1);
54
- expect(VersionUtils.compareVersions("1.0.0", "1.1.0")).toBe(-1);
55
- expect(VersionUtils.compareVersions("1.0.0", "1.0.1")).toBe(-1);
56
- });
57
-
58
- it("版本号相等时应返回0", () => {
59
- expect(VersionUtils.compareVersions("1.0.0", "1.0.0")).toBe(0);
60
- expect(VersionUtils.compareVersions("2.1.3", "2.1.3")).toBe(0);
61
- });
62
-
63
- it("应处理不同部分数量的版本号", () => {
64
- expect(VersionUtils.compareVersions("1.0", "1.0.0")).toBe(0);
65
- expect(VersionUtils.compareVersions("1.0.0", "1.0")).toBe(0);
66
- expect(VersionUtils.compareVersions("1.0.0.1", "1.0.0")).toBe(1);
67
- expect(VersionUtils.compareVersions("1.0.0", "1.0.0.1")).toBe(-1);
68
- });
69
-
70
- it("应处理带预发布标识符的版本号", () => {
71
- // The current implementation ignores pre-release identifiers and just compares numeric parts
72
- expect(VersionUtils.compareVersions("1.0.0-alpha", "1.0.0")).toBe(0);
73
- expect(VersionUtils.compareVersions("1.0.0", "1.0.0-alpha")).toBe(0);
74
- });
75
-
76
- it("应处理带构建元数据的版本号", () => {
77
- // The current implementation doesn't properly handle build metadata
78
- // "1.0.0+build.1" becomes ["1", "0", "0+build", "1"] and "0+build" becomes NaN
79
- expect(VersionUtils.compareVersions("1.0.0+build.1", "1.0.0")).toBe(1);
80
- expect(VersionUtils.compareVersions("1.0.0", "1.0.0+build.1")).toBe(-1);
81
- });
82
- });
83
-
84
- describe("验证版本号有效性", () => {
85
- it("应接受有效的语义化版本号", () => {
86
- expect(VersionUtils.isValidVersion("1.0.0")).toBe(true);
87
- expect(VersionUtils.isValidVersion("0.0.1")).toBe(true);
88
- expect(VersionUtils.isValidVersion("10.20.30")).toBe(true);
89
- expect(VersionUtils.isValidVersion("1.0.0-alpha")).toBe(true);
90
- expect(VersionUtils.isValidVersion("1.0.0-alpha.1")).toBe(true);
91
- expect(VersionUtils.isValidVersion("1.0.0-0.3.7")).toBe(true);
92
- expect(VersionUtils.isValidVersion("1.0.0-x.7.z.92")).toBe(true);
93
- // Note: Build metadata is not supported by current regex
94
- expect(VersionUtils.isValidVersion("1.0.0-alpha+001")).toBe(false);
95
- expect(VersionUtils.isValidVersion("1.0.0+20130313144700")).toBe(false);
96
- expect(VersionUtils.isValidVersion("1.0.0-beta+exp.sha.5114f85")).toBe(
97
- false
98
- );
99
- });
100
-
101
- it("应拒绝无效的语义化版本号", () => {
102
- expect(VersionUtils.isValidVersion("1")).toBe(false);
103
- expect(VersionUtils.isValidVersion("1.0")).toBe(false);
104
- expect(VersionUtils.isValidVersion("1.0.0.0")).toBe(false);
105
- expect(VersionUtils.isValidVersion("v1.0.0")).toBe(false);
106
- expect(VersionUtils.isValidVersion("1.0.0-")).toBe(false);
107
- // The current regex actually accepts "1.0.0-.." because it matches the pattern
108
- expect(VersionUtils.isValidVersion("1.0.0-..")).toBe(true);
109
- expect(VersionUtils.isValidVersion("1.0.0-alpha..")).toBe(true);
110
- expect(VersionUtils.isValidVersion("1.0.0-alpha-beta")).toBe(true);
111
- expect(VersionUtils.isValidVersion("")).toBe(false);
112
- expect(VersionUtils.isValidVersion("not.a.version")).toBe(false);
113
- expect(VersionUtils.isValidVersion("1.0.0.1")).toBe(false);
114
- });
115
- });
116
- });
package/src/version.ts DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * 版本号常量(构建时注入)
3
- */
4
- export const VERSION = __VERSION__;
5
- export const APP_NAME = __APP_NAME__;