Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: support --watch use with --watch-path #46000

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ydeshayes
Copy link

@ydeshayes ydeshayes commented Dec 29, 2022

This patch is adding support for --watch-path when using --watch by adding the path passed to --watch-path in the filtered files instead of calling watchPath directly.
So now the app will reload if the entry point or one of the dependency change, but also if one of the --watch-path change.
The aim was to keep the current behavior of --watch-path when used alone.

It is also fixing the child arguments, now removing the --watch-path=xxx from it.
It is also fixing a hardcoded clear that did not account for --watch-preserve-output.

Fixes: #45467

This patch is removing --watch-path=xxx from the child command line
argument. The code seemed to only remove --watch-path xxx args.
This patch is removing the hardcoded clear command in the log and
check for --watch-preserve-output before clearing.
This patch is adding support for --watch-path when using --watch to
watch extra files/paths. When used together, the path(s) passed to --watch-path
will be added to the filteredFiles in the file watcher.

Fixes: nodejs#45467
This patch is adding test for the new feature.
@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Dec 29, 2022
lib/internal/main/watch_mode.js Outdated Show resolved Hide resolved
const kCommand = ArrayPrototypeSlice(process.argv, 1);
const kCommandStr = inspect(ArrayPrototypeJoin(kCommand, ' '));
const args = ArrayPrototypeFilter(process.execArgv, (arg, i, arr) =>
arg !== '--watch-path' && arr[i - 1] !== '--watch-path' && arg !== '--watch' && arg !== '--watch-preserve-output');
!arg.startsWith('--watch-path') &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use startsWith instead of !==? How is it related to this change?

Suggested change
!arg.startsWith('--watch-path') &&
!StringPrototypeStartsWith(arg, '--watch-path') &&

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I saw, in the test it is passing the arg like --watch-path xxx but in the doc I see --watch-path=xxx and in this case --watch-path=xxx was not removed from the args passed to the child process. When that happend that caused an infite loop because the child was called like node --watch-path=xxx entry.js

Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
@ydeshayes
Copy link
Author

@aduh95 Hello, any chance I can get a review on this one? thanks!

@ydeshayes ydeshayes requested a review from aduh95 May 7, 2023 02:51
@aduh95
Copy link
Contributor

aduh95 commented Sep 20, 2023

@ydeshayes sorry I missed the ping, my GitHub notifications are all over the place 😵‍💫 Any chance you could rebase to solve the git conflict?

@aduh95 aduh95 requested a review from MoLow September 20, 2023 10:30
@MoLow
Copy link
Member

MoLow commented Sep 20, 2023

LGTM, please rebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Watch mode: Allow adding files to watch when using the --watch flag
4 participants