nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.92k stars 29.75k forks source link

`--watch-path` also watches `--env` file directory tree in >=22.7 #55913

Open gorankarlic opened 3 days ago

gorankarlic commented 3 days ago

Version

22.7.0

Platform

Darwin Users-MacBook-Air-2.local 24.0.0 Darwin Kernel Version 24.0.0: Tue Sep 24 23:37:13 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T8112 arm64

Subsystem

No response

What steps will reproduce the bug?

When running node --watch-path lib test.js with 22.6.0 it behaves as expected (restarts only when a file changes in the lib directory).

When running node --watch-path lib test.js with 22.7.0 it keeps restarting indefinitely.

How often does it reproduce? Is there a required condition?

Always reproducible.

What is the expected behavior? Why is that the expected behavior?

Should only restart when a file changes in the watched directory.

What do you see instead?

Restarting indefinitely in a loop.

Additional information

No response

targos commented 3 days ago

I'm not able to reproduce.

gorankarlic commented 2 days ago

I have discovered that the issue is a bit more convoluted and indeed can not be reproduced as stated above.

In order to reproduce the issue two conditions must be met:

  1. --env argument must be present
  2. --watch-path argument must be present

    --watch-preserve-output is used here only for easier observation but is not required to reproduce the issue

node --env-file sub/dev.env --watch-path /usr/local/bin --watch-preserve-output index.js

In this case Node 22.7 and above erroneously starts watching the directory tree where the environment file (in this casedev.env) is located. That means that executing touch sub/test.txt triggers a restart.

Please find attached a complete example 55913.zip that can be used with the above description to reliably reproduce the issue.

pmarchini commented 2 days ago

Hey @gorankarlic, could you please provide the repro as a public repository? 😊

gorankarlic commented 1 day ago

Hey @gorankarlic, could you please provide the repro as a public repository? 😊

Please find the public repository with the reproducible at https://github.com/gorankarlic/55913.

pmarchini commented 1 day ago

Hey @gorankarlic, could you please provide the repro as a public repository? 😊

Please find the public repository with the reproducible at https://github.com/gorankarlic/55913.

Thanks @gorankarlic 😊