fix: 5 critical bugs from Codex review

1. Windows: change "node npm.cmd" to "call npm.cmd" (npm.cmd is a
   batch wrapper, not a JS file — can't run with node.exe)
2. Build: use pnpm instead of npm (upstream build script calls pnpm
   subcommands that fail without it); add set -eo pipefail
3. Build: fail explicitly when dist/ not generated instead of || true
4. Run scripts: separate first-time onboard from normal startup
   (was running onboard every time, blocking normal launch)
5. Windows .bat: fix findstr patterns for .env dedup with /r flag
This commit is contained in:
dongsheng123132
2026-03-09 11:02:14 +08:00
parent 1b4bfb38d9
commit c556f36d92
5 changed files with 74 additions and 35 deletions

View File

@@ -5,7 +5,7 @@
# 用法: ./build-uclaw.sh
# ============================================================
set -e
set -eo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
UCLAW_DIR="$SCRIPT_DIR/U-Claw"
@@ -104,21 +104,26 @@ cd "$UCLAW_DIR/openclaw"
# 设置淘宝镜像
"$NODE_BIN" "$NPM_BIN" config set registry https://registry.npmmirror.com --location=project 2>/dev/null || true
# 安装依赖
info "npm install 中...(可能需要几分钟)"
"$NODE_BIN" "$NPM_BIN" install --registry=https://registry.npmmirror.com --prefer-offline 2>&1 | tail -5
# 安装 pnpmOpenClaw build 脚本依赖 pnpm
info "安装 pnpm..."
"$NODE_BIN" "$NPM_BIN" install -g pnpm --registry=https://registry.npmmirror.com 2>&1 | tail -3
PNPM_BIN="$NODE_DIR/bin/pnpm"
ok "npm 依赖安装完成"
# 安装依赖(使用 pnpm与上游一致
info "pnpm install 中...(可能需要几分钟)"
cd "$UCLAW_DIR/openclaw"
"$NODE_BIN" "$PNPM_BIN" install --registry=https://registry.npmmirror.com 2>&1 | tail -5
ok "依赖安装完成"
# ---- 5. 构建 OpenClaw ----
info "构建 OpenClaw..."
# 检查是否有 pnpm 可用OpenClaw 使用 pnpm build
if [ -f "$UCLAW_DIR/openclaw/node_modules/.bin/tsdown" ]; then
# 尝试简单构建
cd "$UCLAW_DIR/openclaw"
"$NODE_BIN" "$NPM_BIN" run build 2>&1 | tail -10 || warn "build 可能有错误,继续..."
cd "$UCLAW_DIR/openclaw"
"$NODE_BIN" "$PNPM_BIN" run build 2>&1 | tail -10
if [ -d "$UCLAW_DIR/openclaw/dist" ]; then
ok "构建成功dist/ 已生成"
else
error "构建失败dist/ 目录未生成,请检查错误信息"
fi
ok "构建步骤完成"
cd "$SCRIPT_DIR"