@ryantest/openclaw-qqbot 1.6.7-beta.23 → 1.6.7-beta.24

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.
@@ -21,11 +21,8 @@ import { fileURLToPath } from "node:url";
21
21
  import { getPackageVersion } from "./utils/pkg-version.js";
22
22
  const require = createRequire(import.meta.url);
23
23
  let PLUGIN_VERSION = getPackageVersion(import.meta.url);
24
- // 获取 openclaw 框架版本(缓存结果,只执行一次)
25
- let _frameworkVersion = null;
24
+ // 获取 openclaw 框架版本(不缓存,每次实时获取)
26
25
  export function getFrameworkVersion() {
27
- if (_frameworkVersion !== null)
28
- return _frameworkVersion;
29
26
  try {
30
27
  // 先尝试 PATH 中的 CLI
31
28
  // Windows 上 npm 安装的 CLI 通常是 .cmd wrapper,execFileSync 需要 shell:true 才能执行
@@ -37,8 +34,7 @@ export function getFrameworkVersion() {
37
34
  }).trim();
38
35
  // 输出格式: "OpenClaw 2026.3.13 (61d171a)"
39
36
  if (out) {
40
- _frameworkVersion = out;
41
- return _frameworkVersion;
37
+ return out;
42
38
  }
43
39
  }
44
40
  catch {
@@ -50,16 +46,14 @@ export function getFrameworkVersion() {
50
46
  if (cliPath) {
51
47
  const out = execCliSync(cliPath, ["--version"]);
52
48
  if (out) {
53
- _frameworkVersion = out;
54
- return _frameworkVersion;
49
+ return out;
55
50
  }
56
51
  }
57
52
  }
58
53
  catch {
59
54
  // fallback
60
55
  }
61
- _frameworkVersion = "unknown";
62
- return _frameworkVersion;
56
+ return "unknown";
63
57
  }
64
58
  // ============ 热更新兼容性检查 ============
65
59
  /**
@@ -6,10 +6,22 @@ import { fileURLToPath } from "node:url";
6
6
  import { createRequire } from "node:module";
7
7
  import path from "node:path";
8
8
  import fs from "node:fs";
9
- let _cached = null;
9
+ /** 已定位到的 package.json 路径,避免重复遍历目录树 */
10
+ let _resolvedPkgPath = null;
10
11
  export function getPackageVersion(metaUrl) {
11
- if (_cached !== null)
12
- return _cached;
12
+ // 如果之前已定位到 package.json 路径,直接重新读取(快速路径)
13
+ if (_resolvedPkgPath) {
14
+ try {
15
+ const pkg = JSON.parse(fs.readFileSync(_resolvedPkgPath, "utf8"));
16
+ if (pkg.name === "@tencent-connect/openclaw-qqbot" && pkg.version) {
17
+ return pkg.version;
18
+ }
19
+ }
20
+ catch {
21
+ // 文件可能已被删除(升级过程中),清除路径缓存,走完整查找
22
+ _resolvedPkgPath = null;
23
+ }
24
+ }
13
25
  // Strategy 1: 从调用者的 import.meta.url(或本模块)向上遍历找 package.json
14
26
  const startFile = metaUrl ? fileURLToPath(metaUrl) : fileURLToPath(import.meta.url);
15
27
  let dir = path.dirname(startFile);
@@ -21,8 +33,8 @@ export function getPackageVersion(metaUrl) {
21
33
  const pkg = JSON.parse(fs.readFileSync(candidate, "utf8"));
22
34
  // 确认是我们自己的包(避免找到其他 package.json)
23
35
  if (pkg.name === "@tencent-connect/openclaw-qqbot" && pkg.version) {
24
- _cached = pkg.version;
25
- return _cached;
36
+ _resolvedPkgPath = candidate;
37
+ return pkg.version;
26
38
  }
27
39
  }
28
40
  }
@@ -38,14 +50,12 @@ export function getPackageVersion(metaUrl) {
38
50
  try {
39
51
  const pkg = require(rel);
40
52
  if (pkg?.version) {
41
- _cached = pkg.version;
42
- return _cached;
53
+ return pkg.version;
43
54
  }
44
55
  }
45
56
  catch { /* next */ }
46
57
  }
47
58
  }
48
59
  catch { /* fallback */ }
49
- _cached = "unknown";
50
- return _cached;
60
+ return "unknown";
51
61
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryantest/openclaw-qqbot",
3
- "version": "1.6.7-beta.23",
3
+ "version": "1.6.7-beta.24",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,6 +18,10 @@
18
18
 
19
19
  set -eo pipefail
20
20
 
21
+ # ⚠️ 必须在 cd 之前解析脚本路径,否则相对路径的 $0 在 cd 后无法正确解析
22
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
23
+ PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
24
+
21
25
  # 确保 cwd 是一个存在的目录。
22
26
  # 当从 gateway 进程 fork 时,继承的 cwd 可能已被删除(如旧插件目录被 mv/rm),
23
27
  # 导致 openclaw CLI 启动时 process.cwd() 报 ENOENT: uv_cwd 错误。
@@ -83,8 +87,6 @@ TARGET_VERSION=""
83
87
  APPID=""
84
88
  SECRET=""
85
89
  NO_RESTART=false
86
- SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
87
- PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
88
90
 
89
91
  LOCAL_VERSION="$(node -e "
90
92
  try {
@@ -25,10 +25,8 @@ const require = createRequire(import.meta.url);
25
25
 
26
26
  let PLUGIN_VERSION = getPackageVersion(import.meta.url);
27
27
 
28
- // 获取 openclaw 框架版本(缓存结果,只执行一次)
29
- let _frameworkVersion: string | null = null;
28
+ // 获取 openclaw 框架版本(不缓存,每次实时获取)
30
29
  export function getFrameworkVersion(): string {
31
- if (_frameworkVersion !== null) return _frameworkVersion;
32
30
  try {
33
31
  // 先尝试 PATH 中的 CLI
34
32
  // Windows 上 npm 安装的 CLI 通常是 .cmd wrapper,execFileSync 需要 shell:true 才能执行
@@ -40,8 +38,7 @@ export function getFrameworkVersion(): string {
40
38
  }).trim();
41
39
  // 输出格式: "OpenClaw 2026.3.13 (61d171a)"
42
40
  if (out) {
43
- _frameworkVersion = out;
44
- return _frameworkVersion;
41
+ return out;
45
42
  }
46
43
  } catch {
47
44
  continue;
@@ -52,15 +49,13 @@ export function getFrameworkVersion(): string {
52
49
  if (cliPath) {
53
50
  const out = execCliSync(cliPath, ["--version"]);
54
51
  if (out) {
55
- _frameworkVersion = out;
56
- return _frameworkVersion;
52
+ return out;
57
53
  }
58
54
  }
59
55
  } catch {
60
56
  // fallback
61
57
  }
62
- _frameworkVersion = "unknown";
63
- return _frameworkVersion;
58
+ return "unknown";
64
59
  }
65
60
 
66
61
  // ============ 热更新兼容性检查 ============
@@ -8,10 +8,22 @@ import { createRequire } from "node:module";
8
8
  import path from "node:path";
9
9
  import fs from "node:fs";
10
10
 
11
- let _cached: string | null = null;
11
+ /** 已定位到的 package.json 路径,避免重复遍历目录树 */
12
+ let _resolvedPkgPath: string | null = null;
12
13
 
13
14
  export function getPackageVersion(metaUrl?: string): string {
14
- if (_cached !== null) return _cached;
15
+ // 如果之前已定位到 package.json 路径,直接重新读取(快速路径)
16
+ if (_resolvedPkgPath) {
17
+ try {
18
+ const pkg = JSON.parse(fs.readFileSync(_resolvedPkgPath, "utf8"));
19
+ if (pkg.name === "@tencent-connect/openclaw-qqbot" && pkg.version) {
20
+ return pkg.version as string;
21
+ }
22
+ } catch {
23
+ // 文件可能已被删除(升级过程中),清除路径缓存,走完整查找
24
+ _resolvedPkgPath = null;
25
+ }
26
+ }
15
27
 
16
28
  // Strategy 1: 从调用者的 import.meta.url(或本模块)向上遍历找 package.json
17
29
  const startFile = metaUrl ? fileURLToPath(metaUrl) : fileURLToPath(import.meta.url);
@@ -25,8 +37,8 @@ export function getPackageVersion(metaUrl?: string): string {
25
37
  const pkg = JSON.parse(fs.readFileSync(candidate, "utf8"));
26
38
  // 确认是我们自己的包(避免找到其他 package.json)
27
39
  if (pkg.name === "@tencent-connect/openclaw-qqbot" && pkg.version) {
28
- _cached = pkg.version as string;
29
- return _cached;
40
+ _resolvedPkgPath = candidate;
41
+ return pkg.version as string;
30
42
  }
31
43
  }
32
44
  } catch {
@@ -42,13 +54,11 @@ export function getPackageVersion(metaUrl?: string): string {
42
54
  try {
43
55
  const pkg = require(rel);
44
56
  if (pkg?.version) {
45
- _cached = pkg.version as string;
46
- return _cached;
57
+ return pkg.version as string;
47
58
  }
48
59
  } catch { /* next */ }
49
60
  }
50
61
  } catch { /* fallback */ }
51
62
 
52
- _cached = "unknown";
53
- return _cached;
63
+ return "unknown";
54
64
  }