Skip to content

Commit d60a2f2

Browse files
committed
fix(install): repair set-npm-prefix rc line and surface silent finalization failures
- install-cli.sh --set-npm-prefix wrote an over-escaped PATH line: the backslash-escaping expanded PATH at install time, appending a literal \"-quoted, frozen PATH snapshot to .bashrc/.zshrc that never resolves the npm-global bin dir. Use the same correct form as install.sh. - install.sh finalization helpers (retire_npm_owner_after_git_install, retire_git_wrapper_after_npm_install) could abort the install with exit 1 and no output; each fatal path now prints an actionable error. - prepare_git_wrapper_backup_for_npm no longer hard-fails when npm is missing (Arch splits node/npm): there is nothing to back up, and the npm install step already reports the missing npm with remediation. - install-cli.sh --compatible-with with an unresolvable --version died silently through set -e before its error message; the failed npm view now reaches the explicit fail path (and the JSON error event).
1 parent f6d7fe4 commit d60a2f2

2 files changed

Lines changed: 29 additions & 9 deletions

File tree

‎scripts/install-cli.sh‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ fix_npm_prefix_if_needed() {
12251225
mkdir -p "$target"
12261226
"$(npm_bin)" config set prefix "$target"
12271227

1228-
local path_line="export PATH=\\\"${target}/bin:\\$PATH\\\""
1228+
local path_line="export PATH=\"${target}/bin:\$PATH\""
12291229
for rc in "${HOME}/.bashrc" "${HOME}/.zshrc"; do
12301230
if [[ -f "$rc" ]] && ! grep -q ".npm-global" "$rc"; then
12311231
echo "$path_line" >> "$rc"
@@ -1400,7 +1400,9 @@ install_openclaw() {
14001400
)
14011401
local resolved_requested="$requested"
14021402
if [[ -n "${REQUIRED_COMPATIBLE_VERSION:-}" ]]; then
1403-
resolved_requested="$(resolve_npm_openclaw_version "$requested")"
1403+
# || true: a failed npm view must reach the explicit fail below instead
1404+
# of dying silently through set -e with no error event.
1405+
resolved_requested="$(resolve_npm_openclaw_version "$requested" || true)"
14041406
if [[ -z "$resolved_requested" ]]; then
14051407
fail "Could not resolve OpenClaw ${requested} before compatibility checking."
14061408
fi

‎scripts/install.sh‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3654,17 +3654,29 @@ verify_installation() {
36543654

36553655
retire_npm_owner_after_git_install() {
36563656
local wrapper="$HOME/.local/bin/openclaw" npm_cmd="" npm_root="" npm_bin="" package_root="" package_name=""
3657-
npm_cmd="$(npm_command_path npm)" || return 1
3657+
if ! npm_cmd="$(npm_command_path npm)"; then
3658+
ui_error "Could not retire the previous npm install: npm not found on PATH"
3659+
return 1
3660+
fi
36583661
npm_root="$("$npm_cmd" root -g 2>/dev/null | awk 'NF { value = $0 } END { print value }')" || true
36593662
package_root="${npm_root%/}/openclaw"
36603663
[[ -n "$npm_root" && -f "$package_root/package.json" ]] || return 0
36613664
package_name="$(node -e 'const p=require(process.argv[1]); process.stdout.write(String(p.name || ""))' "$package_root/package.json" 2>/dev/null || true)"
3662-
[[ "$package_name" == "openclaw" ]] || return 1
3665+
if [[ "$package_name" != "openclaw" ]]; then
3666+
ui_error "Could not retire the previous npm install: ${package_root} contains package '${package_name:-unknown}', not openclaw"
3667+
return 1
3668+
fi
36633669
npm_bin="$(npm_global_bin_dir "$npm_cmd" || true)"
36643670
if [[ "${npm_bin%/}/openclaw" == "$wrapper" ]]; then
3665-
rm -rf "$package_root" || return 1
3671+
if ! rm -rf "$package_root"; then
3672+
ui_error "Could not retire the previous npm install: failed to remove ${package_root}"
3673+
return 1
3674+
fi
36663675
else
3667-
"$npm_cmd" uninstall -g openclaw >/dev/null 2>&1 || return 1
3676+
if ! "$npm_cmd" uninstall -g openclaw >/dev/null 2>&1; then
3677+
ui_error "Could not retire the previous npm install: npm uninstall -g openclaw failed"
3678+
return 1
3679+
fi
36683680
fi
36693681
ui_success "Previous npm install retired"
36703682
}
@@ -3680,10 +3692,13 @@ is_installer_git_wrapper() {
36803692

36813693
prepare_git_wrapper_backup_for_npm() {
36823694
local npm_cmd="" npm_root="" npm_bin="" target="" launcher=""
3683-
npm_cmd="$(npm_command_path npm)" || return 1
3695+
# Without a resolvable npm there is nothing to back up; let the npm
3696+
# install step report the missing npm with its own remediation text
3697+
# instead of silently exiting here (Arch splits node and npm packages).
3698+
npm_cmd="$(npm_command_path npm)" || return 0
36843699
npm_root="$("$npm_cmd" root -g 2>/dev/null || true)"
36853700
npm_bin="$(npm_global_bin_dir "$npm_cmd" || true)"
3686-
[[ -n "$npm_root" && -n "$npm_bin" ]] || return 1
3701+
[[ -n "$npm_root" && -n "$npm_bin" ]] || return 0
36873702
target="${npm_bin%/}/openclaw"
36883703
is_installer_git_wrapper "$target" || return 0
36893704
launcher="${npm_root%/}/openclaw/openclaw.mjs"
@@ -3693,7 +3708,10 @@ prepare_git_wrapper_backup_for_npm() {
36933708
retire_git_wrapper_after_npm_install() {
36943709
local wrapper="$HOME/.local/bin/openclaw"
36953710
is_installer_git_wrapper "$wrapper" || return 0
3696-
rm -f "$wrapper" || return 1
3711+
if ! rm -f "$wrapper"; then
3712+
ui_error "Could not retire the previous git wrapper: failed to remove ${wrapper}"
3713+
return 1
3714+
fi
36973715
ui_success "Previous git wrapper retired"
36983716
}
36993717

0 commit comments

Comments
 (0)