--watch-path restarts on unrelated directory touch when --env-file is set
未关闭
还没有人认领这个 Issue。
watch-mode
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 272
描述
Version
- Node.js: v24.13.0
- OS: macOS
Reproduction
Setup:
mkdir -p /tmp/node-watch-envfile-repro/watched /tmp/node-watch-envfile-repro/unrelated
cd /tmp/node-watch-envfile-repro
echo "FOO=bar" > .env
echo "console.log('START', JSON.stringify({ pid: process.pid, ts: Date.now(), foo: process.env.FOO ?? null }));" > watched/server.js
echo "setInterval(() => {}, 1000);" >> watched/server.js
Run with --env-file and touch an unrelated path:
cd /tmp/node-watch-envfile-repro
node --watch-path=watched --env-file=.env watched/server.js > out-env.log 2>&1 &
PID=$!
sleep 2
touch unrelated
sleep 2
kill $PID
cat out-env.log
Observed output:
START {"pid":58939,"ts":1771621917212,"foo":"bar"}
Restarting 'watched/server.js'
START {"pid":58948,"ts":1771621919442,"foo":"bar"}
Now run without --env-file:
cd /tmp/node-watch-envfile-repro
node --watch-path=watched watched/server.js > out-no-env.log 2>&1 &
PID=$!
sleep 2
touch unrelated
sleep 2
kill $PID
cat out-no-env.log
Observed output:
START {"pid":59279,"ts":1771621950778,"foo":null}
Expected behavior
When --watch-path=watched is set, touching unrelated should not trigger a restart, regardless of whether --env-file is used.
Actual behavior
With --env-file=.env, touching unrelated triggers a restart.
Without --env-file, touching unrelated does not restart.
Notes
This was first noticed in a larger workspace where:
node --watch-path=apps/server/dist-dev --env-file=.env apps/server/dist-dev/server.js
restarts when running:
touch apps/client/dist/
The reduced test case above reproduces the same behavior.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先分别使用和不使用 --env-file 运行提供的 macOS 复现,重点关注 Node.js 的 watch-path 处理以及与 --env-file 入口点的交互。跟踪用于监视的文件系统路径在哪里被选定,并添加或更新回归测试,以确保触碰无关内容不会重启进程;重新运行复现和相关的 watch 测试,以确认该行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, node.js
- 领域
- cli, tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 64/100