Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Bug]: herd isolate-node ignores --site and writes .nvmrc into the current folder

未关闭 适合新手
#1,774 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
76/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
php, shell
领域
backend, cli

调研方向

从 cli/app.php:1592 和 cli/Valet/Site.php:1303-1306 开始,追踪 --site 如何选择目标路径;并与 cli/app.php:1619 中对 unisolate-node 的处理进行比较。还要检查 bin/herd:148,这里的 shell hook 会检查 --site=。完成标准是:隔离操作将 .nvmrc 写入指定站点的文件夹;未知站点会返回错误;hook 能处理文档中说明的参数顺序,且不会更改当前文件夹的 Node 版本。

由索引模型根据 Issue 内容生成。

描述

macOS
Platform

macOS

Operating system version

macOS 27.0.1 (26A434)

System architecture

ARM64 (M1, M2, etc)

Herd Version

2.0.2 (Build: 71)

PHP Version

n/a (Node 26.12.0 through Herd's nvm; global PHP is 8.5.10)

Bug description

herd isolate-node 26 --site=example ignores --site. The docs show this form for sites whose name doesn't match their folder, but the .nvmrc lands in the current folder instead of the site's, overwriting any .nvmrc already there. It still says "The site is now using Node 26." and exits 0, even for a site that doesn't exist.

herd unisolate-node --site=example does look in the site's folder, so it says it worked and leaves the stray .nvmrc behind.

Because nvm and Herd's shell hook pick up .nvmrc from parent folders, running it from ~/Herd would switch Node for every site below it without its own .nvmrc (I saw the hook switch after a cd into a subfolder). From the hook's code it would also nvm install a missing version; I didn't test that.

Expected: the .nvmrc goes into the site's folder, and an unknown site name gives an error.

Cause (herd.phar 2.0.2): isolate-node always passes getcwd() to Site::isolateNode() (cli/app.php:1592), which uses that path whenever it's set (cli/Valet/Site.php:1303-1305), so the site lookup at :1306 never runs. unisolate-node passes no path (app.php:1619), so it finds the site.

Possible fix: pass null instead of getcwd() when --site is set (app.php:1592, and :1580 for the form without a version).

Also: bin/herd:148 only checks $2 for --site=, so with the docs' argument order (and for --help) it runs nvm use in the current folder as well.

Thanks for the quick fixes on #1770 and #1771.

Steps to reproduce
  1. Herd 2.0.2 with any installed Node version (26 here) and a linked or parked site example that has no .nvmrc.
  2. From a folder that isn't a site: mkdir ~/herd-test && cd ~/herd-test, then herd isolate-node 26 --site=example.
  3. ls -A ~/herd-test ~/Herd/example: the .nvmrc is in ~/herd-test, not in the site's folder, and herd isolated-node doesn't list the site.
  4. herd unisolate-node --site=example: it says it worked, but ~/herd-test/.nvmrc is still there.
  5. Clean up with rm ~/herd-test/.nvmrc.
Relevant log output
# Paths changed for privacy. For the linked-site part I ran herd.phar against a copy of my Herd config, so my real setup stayed untouched.
# Same behaviour with a stock .zshrc (only Herd's own lines) and with no shell config at all.

$ cd ~/herd-test
$ herd isolate-node --site=example 26
The site is now using Node 26.
$ ls -A ~/herd-test
.nvmrc
$ cat ~/herd-test/.nvmrc
26
$ ls -A ~/Herd/example
$ herd isolated-node
+------+--------------+
| Path | Node Version |
+------+--------------+
$ herd unisolate-node --site=example
The site is now using the default Node version.
$ ls -A ~/herd-test
.nvmrc

# The docs' argument order, with a site name that doesn't exist:
$ cd ~/herd-test2
$ herd isolate-node 26 --site=nosuchsite
The site is now using Node 26.
Found '~/herd-test2/.nvmrc' with version <26>
Now using node v26.12.0 (npm v11.20.0)
$ echo $?
0
主要语言
没有语言数据
星标
124
派生
1
PR 合并指标
30 天内没有已合并 PR

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

beyondcode/herd-community 的其他 Issue

查看 beyondcode/herd-community 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。