fix(macos): use user login shell in restart-mac.sh for nvm/fnm compat#33523
fix(macos): use user login shell in restart-mac.sh for nvm/fnm compat#33523Nachx639 wants to merge 1 commit intoopenclaw:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ba16678ac6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
scripts/restart-mac.sh
Outdated
|
|
||
| # 3) Package app (no embedded gateway). | ||
| run_step "package app" bash -lc "cd '${ROOT_DIR}' && SKIP_TSC=${SKIP_TSC:-1} '${ROOT_DIR}/scripts/package-mac-app.sh'" | ||
| run_step "package app" "$USER_SHELL" -lc "cd '${ROOT_DIR}' && SKIP_TSC=${SKIP_TSC:-1} '${ROOT_DIR}/scripts/package-mac-app.sh'" |
There was a problem hiding this comment.
Keep restart commands on a POSIX-compatible shell
Switching run_step invocations from bash -lc to "$USER_SHELL" -lc makes the script depend on whatever shell the user has configured, but several command strings here use POSIX/Bash syntax (for example inline env assignment in SKIP_TSC=${SKIP_TSC:-1} ...). If a developer’s default shell is non-POSIX (e.g. fish), these steps fail to parse and restart-mac.sh aborts during rebuild/package, whereas the previous hardcoded bash -lc path worked regardless of user shell.
Useful? React with 👍 / 👎.
Greptile SummaryThis PR replaces hardcoded
Confidence Score: 3/5
Last reviewed commit: ba16678 |
|
|
||
| # Use the user's login shell (typically zsh on macOS) for subshells so that | ||
| # version managers like nvm/fnm load correctly. | ||
| USER_SHELL="${SHELL:-/bin/bash}" |
There was a problem hiding this comment.
zsh -lc does not source ~/.zshrc — fix may silently fail for most nvm/zsh users
The -l (login) flag in zsh -lc "..." spawns a non-interactive login shell, which sources /etc/zprofile, ~/.zprofile, /etc/zlogin, and ~/.zlogin — but explicitly skips ~/.zshrc. The vast majority of nvm/fnm users on zsh (including nvm's own installer) write their initialization into ~/.zshrc, not ~/.zprofile. As a result, "$USER_SHELL" -lc "..." where $SHELL=/bin/zsh will still not find the nvm-managed node, meaning the Cannot find native binding error this PR aims to fix will persist for the most common configuration.
To also load ~/.zshrc, the shell needs to be launched as an interactive login shell via -ilc:
| USER_SHELL="${SHELL:-/bin/bash}" | |
| USER_SHELL="${SHELL:-/bin/bash}" | |
| # For zsh, -l alone spawns a non-interactive login shell that skips ~/.zshrc. | |
| # Use -i to force interactive mode so ~/.zshrc (where nvm/fnm init typically lives) is sourced. | |
| USER_SHELL_FLAGS="-lc" | |
| if [[ "$(basename "$USER_SHELL")" == "zsh" ]]; then | |
| USER_SHELL_FLAGS="-ilc" | |
| fi |
Then replace each "$USER_SHELL" -lc "..." with "$USER_SHELL" $USER_SHELL_FLAGS "...". Alternatively, add a single helper function:
run_in_user_shell() {
local cmd="$1"
if [[ "$(basename "$USER_SHELL")" == "zsh" ]]; then
"$USER_SHELL" -ilc "$cmd"
else
"$USER_SHELL" -lc "$cmd"
fi
}Note that -i can produce extra output from prompts/plugins (Oh My Zsh, Powerlevel10k, etc.) if they aren't guarded by [[ $- == *i* ]] / [[ -o interactive ]] checks. An equally clean alternative is to explicitly source the nvm/fnm init inside the command string:
run_step "bundle canvas a2ui" "$USER_SHELL" -lc \
'[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"; command -v fnm >/dev/null && eval "$(fnm env)"; '"cd '${ROOT_DIR}' && pnpm canvas:a2ui:bundle"This guarantees the version manager is loaded regardless of which shell startup file the user chose.
Prompt To Fix With AI
This is a comment left during a code review.
Path: scripts/restart-mac.sh
Line: 33
Comment:
**`zsh -lc` does not source `~/.zshrc`** — fix may silently fail for most nvm/zsh users
The `-l` (login) flag in `zsh -lc "..."` spawns a **non-interactive** login shell, which sources `/etc/zprofile`, `~/.zprofile`, `/etc/zlogin`, and `~/.zlogin` — but explicitly **skips** `~/.zshrc`. The vast majority of nvm/fnm users on zsh (including nvm's own installer) write their initialization into `~/.zshrc`, not `~/.zprofile`. As a result, `"$USER_SHELL" -lc "..."` where `$SHELL=/bin/zsh` will still not find the nvm-managed node, meaning the `Cannot find native binding` error this PR aims to fix will persist for the most common configuration.
To also load `~/.zshrc`, the shell needs to be launched as an **interactive** login shell via `-ilc`:
```suggestion
USER_SHELL="${SHELL:-/bin/bash}"
# For zsh, -l alone spawns a non-interactive login shell that skips ~/.zshrc.
# Use -i to force interactive mode so ~/.zshrc (where nvm/fnm init typically lives) is sourced.
USER_SHELL_FLAGS="-lc"
if [[ "$(basename "$USER_SHELL")" == "zsh" ]]; then
USER_SHELL_FLAGS="-ilc"
fi
```
Then replace each `"$USER_SHELL" -lc "..."` with `"$USER_SHELL" $USER_SHELL_FLAGS "..."`. Alternatively, add a single helper function:
```bash
run_in_user_shell() {
local cmd="$1"
if [[ "$(basename "$USER_SHELL")" == "zsh" ]]; then
"$USER_SHELL" -ilc "$cmd"
else
"$USER_SHELL" -lc "$cmd"
fi
}
```
Note that `-i` can produce extra output from prompts/plugins (Oh My Zsh, Powerlevel10k, etc.) if they aren't guarded by `[[ $- == *i* ]]` / `[[ -o interactive ]]` checks. An equally clean alternative is to explicitly source the nvm/fnm init inside the command string:
```bash
run_step "bundle canvas a2ui" "$USER_SHELL" -lc \
'[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"; command -v fnm >/dev/null && eval "$(fnm env)"; '"cd '${ROOT_DIR}' && pnpm canvas:a2ui:bundle"
```
This guarantees the version manager is loaded regardless of which shell startup file the user chose.
How can I resolve this? If you propose a fix, please make it concise.Use $SHELL (user's login shell) instead of hardcoded bash for subshells. For zsh, use -ilc (interactive login) to also source ~/.zshrc where nvm/fnm init typically lives — zsh -lc alone only sources ~/.zprofile. Co-Authored-By: Claude Opus 4.6 <[email protected]>
ba16678 to
59b1e23
Compare
|
Updated in 59b1e23 — addressed both review comments: @greptile-apps — Good catch on @chatgpt-codex-connector — The command strings use POSIX/bash syntax intentionally. If |
|
To use Codex here, create a Codex account and connect to github. |
|
Perfect! The fix looks good. The The implementation matches what I suggested and should now properly load nvm/fnm on modern macOS systems. Nice work! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 59b1e23d9b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
|
||
| # 3) Package app (no embedded gateway). | ||
| run_step "package app" bash -lc "cd '${ROOT_DIR}' && SKIP_TSC=${SKIP_TSC:-1} '${ROOT_DIR}/scripts/package-mac-app.sh'" | ||
| run_step "package app" run_in_user_shell "cd '${ROOT_DIR}' && SKIP_TSC=${SKIP_TSC:-1} '${ROOT_DIR}/scripts/package-mac-app.sh'" |
There was a problem hiding this comment.
Keep package command on a POSIX shell
Routing this step through run_in_user_shell makes it execute under whatever $SHELL is configured, but the command uses POSIX inline env assignment (SKIP_TSC=... cmd), which non-POSIX shells like fish do not parse; in those environments restart-mac.sh now aborts at packaging instead of rebuilding. Fresh evidence: this line newly passes that inline assignment through run_in_user_shell.
Useful? React with 👍 / 👎.
Summary
run_in_user_shellhelper that uses$SHELL(user's login shell, defaults to/bin/bash)-ilc(interactive login) to source~/.zshrcwhere nvm/fnm init typically lives —zsh -lcalone only sources~/.zprofile-lcas beforebash -lcdidn't load nvm/fnm, causing native bindings (e.g. rolldown) to fail with the wrong Node versionAddresses bot review feedback:
zsh -lcskips~/.zshrc→ fixed with-ilcfor zsh via helper function$SHELLdefaults to/bin/bashif unsetTest plan
restart-mac.shcompletes full rebuild cycle (bundle, swift build, package, sign, launch) on macOS with nvm in zshzsh -ilcloads nvm and produces no extra output noise🤖 Generated with Claude Code