@ryantest/openclaw-qqbot 1.6.7-beta.21 → 1.6.7-beta.22

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": "@ryantest/openclaw-qqbot",
3
- "version": "1.6.7-beta.21",
3
+ "version": "1.6.7-beta.22",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -291,7 +291,25 @@ fi
291
291
  # 由于 CJS/ESM 混用问题(Node 22 ERR_INTERNAL_ASSERTION),验证阶段可能失败
292
292
  # 但文件已成功拷贝。因此不依赖退出码,而是检查安装目录中关键文件是否存在。
293
293
  _INSTALL_DIR="$HOME/.openclaw/extensions/openclaw-qqbot"
294
+
295
+ # ── 优化:安装前临时移走 node_modules ──
296
+ # openclaw plugins install . 会把整个项目目录(含 node_modules/)复制到 extensions,
297
+ # 但运行时只需要 bundledDependencies 中的 3 个包 + openclaw symlink。
298
+ # 移走 node_modules 可避免复制数百个不必要的包,大幅加速安装。
299
+ _NM_BACKUP=""
300
+ if [ -d "$PROJ_DIR/node_modules" ]; then
301
+ echo " 临时移走 node_modules(避免整体复制到 extensions)..."
302
+ _NM_BACKUP="$PROJ_DIR/.node_modules_install_bak"
303
+ mv "$PROJ_DIR/node_modules" "$_NM_BACKUP"
304
+ fi
305
+
294
306
  openclaw plugins install . 2>&1 | tee "$INSTALL_LOG" || true
307
+
308
+ # ── 恢复 node_modules ──
309
+ if [ -n "$_NM_BACKUP" ] && [ -d "$_NM_BACKUP" ]; then
310
+ mv "$_NM_BACKUP" "$PROJ_DIR/node_modules"
311
+ echo " 已恢复源码目录 node_modules"
312
+ fi
295
313
  if [ ! -f "$_INSTALL_DIR/dist/index.js" ] || [ ! -f "$_INSTALL_DIR/preload.cjs" ]; then
296
314
  echo ""
297
315
  echo "❌ 插件安装失败!"
@@ -400,6 +418,12 @@ else
400
418
  echo " 尝试自动修复: 清理残留并重试安装..."
401
419
  find "$HOME/.openclaw/extensions/" -maxdepth 1 -name ".openclaw-install-stage-*" -exec rm -rf {} + 2>/dev/null || true
402
420
  find "${TMPDIR:-/tmp}" -maxdepth 1 -name ".openclaw-install-stage-*" -exec rm -rf {} + 2>/dev/null || true
421
+ # 重试时同样移走 node_modules 避免整体复制
422
+ _NM_BACKUP=""
423
+ if [ -d "$PROJ_DIR/node_modules" ]; then
424
+ _NM_BACKUP="$PROJ_DIR/.node_modules_install_bak"
425
+ mv "$PROJ_DIR/node_modules" "$_NM_BACKUP"
426
+ fi
403
427
  if openclaw plugins install . 2>&1 | tee -a "$INSTALL_LOG"; then
404
428
  for _candidate_name in openclaw-qqbot qqbot openclaw-qq; do
405
429
  if [ -d "$HOME/.openclaw/extensions/$_candidate_name" ]; then
@@ -409,6 +433,10 @@ else
409
433
  fi
410
434
  done
411
435
  fi
436
+ # 恢复 node_modules
437
+ if [ -n "$_NM_BACKUP" ] && [ -d "$_NM_BACKUP" ]; then
438
+ mv "$_NM_BACKUP" "$PROJ_DIR/node_modules"
439
+ fi
412
440
  if [ "$_plugin_dir_ok" -eq 0 ]; then
413
441
  echo " ❌ 重试安装仍失败,插件目录不存在"
414
442
  echo " 请手动排查: ls -la ~/.openclaw/extensions/"
@@ -442,18 +470,70 @@ else
442
470
  fi
443
471
  fi
444
472
 
445
- # 清理多余的 peerDependencies 传递依赖(兼容旧版 openclaw):
446
- # openclaw v2026.3.4 之前的 plugins install 缺少 --omit=peer,会把 peerDeps
447
- # (openclaw 平台及其 400+ 传递依赖)也安装到插件 node_modules 中。
448
- # 新版已修复,此处通过阈值判断:包数量 > 50 才触发清理,避免对新版做无用操作。
473
+ # ── 复制 bundledDependencies 到插件 node_modules ──
474
+ # 由于安装前移走了源码的 node_modules,extensions 中的插件目录没有依赖。
475
+ # 只需复制 bundledDependenciesws, silk-wasm, mpg123-decoder)及其传递依赖即可。
449
476
  PLUGIN_NM=""
450
477
  for _candidate in openclaw-qqbot qqbot openclaw-qq; do
451
478
  _nm="$HOME/.openclaw/extensions/$_candidate/node_modules"
452
- [ -d "$_nm" ] && PLUGIN_NM="$_nm" && break
479
+ _ext_dir="$HOME/.openclaw/extensions/$_candidate"
480
+ [ -d "$_ext_dir" ] && PLUGIN_NM="$_nm" && break
453
481
  done
454
- if [ -n "$PLUGIN_NM" ]; then
482
+ if [ -n "$PLUGIN_NM" ] && [ -d "$PROJ_DIR/node_modules" ]; then
483
+ # 如果 extensions 中已有大量包(旧版 openclaw 安装的 peerDeps),先清理
484
+ if [ -d "$PLUGIN_NM" ]; then
485
+ _before=$(ls -d "$PLUGIN_NM"/*/ "$PLUGIN_NM"/@*/*/ 2>/dev/null | wc -l | tr -d ' ')
486
+ if [ "$_before" -gt 50 ]; then
487
+ echo ""
488
+ echo "检测到 ${_before} 个包(超过阈值 50),清理多余的 peerDep 传递依赖..."
489
+ rm -rf "$PLUGIN_NM"
490
+ fi
491
+ fi
492
+
493
+ # 读取 bundledDependencies 及其传递依赖列表,只复制这些包
494
+ _deps_to_copy=$(node -e "
495
+ const fs = require('fs');
496
+ const path = require('path');
497
+ const pkgPath = path.join('$PROJ_DIR', 'package.json');
498
+ if (!fs.existsSync(pkgPath)) process.exit(0);
499
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
500
+ const bundled = pkg.bundledDependencies || pkg.bundleDependencies || [];
501
+ const keep = new Set();
502
+ const resolve = (name) => {
503
+ if (keep.has(name)) return;
504
+ keep.add(name);
505
+ const depPkg = path.join('$PROJ_DIR', 'node_modules', name, 'package.json');
506
+ if (!fs.existsSync(depPkg)) return;
507
+ const dep = JSON.parse(fs.readFileSync(depPkg, 'utf8'));
508
+ for (const d of Object.keys(dep.dependencies || {})) resolve(d);
509
+ };
510
+ bundled.forEach(resolve);
511
+ process.stdout.write([...keep].join('\\n'));
512
+ " 2>/dev/null || true)
513
+
514
+ if [ -n "$_deps_to_copy" ]; then
515
+ mkdir -p "$PLUGIN_NM"
516
+ _copied=0
517
+ echo "$_deps_to_copy" | while IFS= read -r _dep; do
518
+ _src="$PROJ_DIR/node_modules/$_dep"
519
+ _dst="$PLUGIN_NM/$_dep"
520
+ if [ -d "$_src" ] && [ ! -d "$_dst" ]; then
521
+ # 处理 scoped 包(如 @scope/pkg)
522
+ mkdir -p "$(dirname "$_dst")"
523
+ cp -r "$_src" "$_dst"
524
+ fi
525
+ done
526
+ _after=$(ls -d "$PLUGIN_NM"/*/ "$PLUGIN_NM"/@*/*/ 2>/dev/null | wc -l | tr -d ' ')
527
+ echo " ✅ 已复制 bundled 依赖到插件目录(${_after} 个包)"
528
+ else
529
+ echo " ⚠️ 未读取到 bundledDependencies,跳过依赖复制"
530
+ fi
531
+ elif [ -n "$PLUGIN_NM" ] && [ -d "$PLUGIN_NM" ]; then
532
+ # node_modules 已存在(可能是旧版 openclaw 安装的),检查是否需要清理
455
533
  _before=$(ls -d "$PLUGIN_NM"/*/ "$PLUGIN_NM"/@*/*/ 2>/dev/null | wc -l | tr -d ' ')
456
534
  if [ "$_before" -gt 50 ]; then
535
+ echo ""
536
+ echo "检测到 ${_before} 个包(超过阈值 50),清理多余的 peerDep 传递依赖..."
457
537
  # 读取 bundledDependencies 列表,只保留这些包及其子依赖
458
538
  _bundled_deps=$(node -e "
459
539
  const fs = require('fs');
@@ -492,8 +572,6 @@ else
492
572
  process.stdout.write(toRemove.join('\n'));
493
573
  " 2>/dev/null || true)
494
574
  if [ -n "$_bundled_deps" ]; then
495
- echo ""
496
- echo "检测到 ${_before} 个包(超过阈值 50),清理多余的 peerDep 传递依赖..."
497
575
  echo "$_bundled_deps" | while IFS= read -r _pkg; do
498
576
  rm -rf "$PLUGIN_NM/$_pkg"
499
577
  done