fix(install): surface npm link failures and fall back to user-local shim#2520
fix(install): surface npm link failures and fall back to user-local shim#2520laitingsheng wants to merge 1 commit intomainfrom
Conversation
## Summary A fresh `git clone` + `npm install` on a Linux host without a writable global npm prefix (and without sudo) reported success, but the `nemoclaw` command never landed on PATH. Root cause: the package.json `prepare` script invoked `NEMOCLAW_INSTALLING=1 npm link 2>/dev/null || true`, which suppressed both stderr and the exit code, so any link failure was invisible to the user. They only discovered it when `nemoclaw onboard` returned "No such file or directory". Replace the silent npm-link step with a small helper that surfaces the real npm error and falls back to a user-local wrapper at `~/.local/bin/nemoclaw`. Wrapper preserves the Node directory that was on PATH at install time so it works in shells where Node is provisioned via nvm. uninstall.sh recognises the new shim shape so a later uninstall cleans it up alongside the installer wrapper. ## Related Issue Closes #2515 ## Changes - scripts/npm-link-or-shim.sh: new helper invoked by `npm install` via the package.json `prepare` script. `set -eu` so any unchecked failure halts. Runs `npm link` from the repo root; on failure, prints the captured npm error then writes a wrapper at `~/.local/bin/nemoclaw` that exports the captured Node directory and execs `bin/nemoclaw.js`. Refuses to overwrite a foreign file (only refreshes a NemoClaw-managed shim, identified by a marker line). Atomic write via tempfile + rename so a mid-write failure cannot leave a partial unrecognisable file. Honours an already-set `NEMOCLAW_INSTALLING` to short-circuit prepare-script recursion. - package.json: replace the inline `NEMOCLAW_INSTALLING=1 npm link 2>/dev/null || true` with `bash scripts/npm-link-or-shim.sh`. Lenient chaining preserved (the helper warns loudly on stderr but does not fail `npm install`). - uninstall.sh: extend `is_installer_managed_nemoclaw_shim` to also recognise the dev-shim shape (marker line + same wrapper structure) so a later `uninstall.sh` removes it cleanly instead of leaving a stale `nemoclaw` command behind after the source checkout is gone. - test/npm-link-or-shim.test.ts: regression tests covering six cases — shim is created on link failure (wrapper structure, marker line, Node-directory PATH export), no shim on success, no-op when `NEMOCLAW_INSTALLING` is preset, refusal to overwrite a foreign file, idempotent refresh of an existing dev-shim, and the original high-severity reproduction (`~/.local` exists as a regular file). - test/uninstall.test.ts: regression test that a dev-shim file in `~/.local/bin/nemoclaw` is removed by `remove_nemoclaw_cli`. Signed-off-by: Tinson Lai <tinsonl@nvidia.com>
📝 WalkthroughWalkthroughUpdates the dev install process to handle Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
✨ Thanks for submitting this pull request that proposes a way to fix a bug where npm link failures were not surfaced and fell back to a user-local shim. This identifies a bug and proposes a change to surface the real npm error and fall back to a user-local wrapper at ~/.local/bin/nemoclaw, with matching recognition in uninstall.sh to clean up the shim later. The addition of a hardened set -eu helper script and updates to package.json and uninstall.sh will help ensure the issue does not recur. Related open issues: |
Summary
A fresh
git clone+npm installon a Linux host without a writable global npm prefix reported success but left nonemoclawcommand on PATH — thepreparescript'snpm link 2>/dev/null || trueswallowed both stderr and the exit code. This surfaces the real npm error and falls back to a user-local wrapper at~/.local/bin/nemoclaw.uninstall.shrecognises the new shim shape so it cleans up later.Related Issue
Closes #2515
Changes
scripts/npm-link-or-shim.sh: hardenedset -euhelper that runsnpm linkand on failure writes a wrapper at~/.local/bin/nemoclaw. Atomic write via tempfile + rename, marker-based refusal to overwrite foreign files, idempotent refresh of NemoClaw-managed shims.package.json:preparenow invokes the helper instead of swallowing errors inline.uninstall.sh:is_installer_managed_nemoclaw_shimrecognises the dev-shim shape soremove_nemoclaw_clicleans it up.test/npm-link-or-shim.test.ts(new) +test/uninstall.test.ts: regression coverage for six failure/success paths plus the uninstaller cleanup.Type of Change
Verification
npx prek run --all-filespassesnpm testpassesmake docsbuilds without warnings (doc changes only)AI Disclosure
Signed-off-by: Tinson Lai tinsonl@nvidia.com
Summary by CodeRabbit
New Features
Tests