nodejs / node

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

Support file globs with `--watch-path` #45182

Open ghost opened 1 year ago

ghost commented 1 year ago

What is the problem this feature will solve?

The new experimental watch feature is awesome, but sometimes apps depend on non-imported files or data. For example, if your app has a set of templates that are read/cached at server start, updating an HTML file won't restart the process.

What is the feature you are proposing to solve the problem?

It would be extremely useful to provide an optional list of file globs that would also trigger a process restart. For example:

# current
$ node --watch app.mjs

# proposed
$ node --watch app.mjs views/*.html

Note: this syntax is just to illustrate the idea.

What alternatives have you considered?

Some template engines/libraries have caching logic built in so it's disabled during local development, but supporting this in a more generic way would open up a lot of additional use cases without having to explicitly code against NODE_ENV or enabling/disabling caching. Since the watch feature already seems to do exactly what would be needed to make this work, it would simply have to accept an optional glob or list of globs to also watch along with any imports.

MoLow commented 1 year ago

I would say there are two separate issues raised here:

  1. watching paths/files that are not required, which is currently supported with --watch-path
  2. using globs as an input for this flag - there have been a few discussions about adding glob support to node and I hope that will eventually happen allowing this to work, but it is currently out of the scope of watch mode.
ghost commented 1 year ago

Ah, wow, I don't know how I missed --watch-path when it's literally right below --watch in the docs, haha. The globs would definitely be a nice to have, but --watch-path does pretty much what I needed, so appreciate the reply!

EDIT: On a side note, the docs state This option is only supported on macOS and Windows., but it appears to work just fine on linux (Ubuntu).

karlhorky commented 1 year ago

@mmarti @MoLow what do you think about reopening this for support for globs in --watch-path?

Would be great to only target certain file extensions, for example.

karlhorky commented 1 year ago

Thanks for reopening! Maybe the title can be changed to Support path globs with `--watch-path`? And I suppose the issue description text will also need to be adapted a bit...

MoLow commented 1 year ago

Refs: https://github.com/nodejs/node/issues/40731

github-actions[bot] commented 1 year ago

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

karlhorky commented 1 year ago

I guess this one is still validly open, and just because it hasn't had activity, doesn't seem like that is a reason that it won't be implemented... 🤔

Probably will be a pretty common request as more people use the watch mode in the Node.js CLI.

github-actions[bot] commented 11 months ago

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

karlhorky commented 11 months ago

not stale

github-actions[bot] commented 5 months ago

There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the https://github.com/nodejs/node/labels/never-stale label or close this issue if it should be closed. If not, the issue will be automatically closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document.

RedYetiDev commented 3 months ago

Given the repeated stale/unstale-ing of this issue, I've marked it as never-stale to save time and energy. Feel free to undo.

(Note the author is @ghost, so if more information is needed, that could be hard to obtain)

waynesbrain commented 1 day ago

One related problem that I'm having is that using --watch-path causes node to turn off watching of required or imported modules even when used in combination with --watch.

IMO it should watch required/imported modules of any watch-path that I provide. (I am here trying to fix my watch script which was node --watch-path=./src ./scripts/build.mjs until I found out it wasn't rebuilding when dependencies changed).

I ended up having to add all the node_modules I cared about as a watch-path, e.g. node --watch-path=./src --watch-path=../../node_modules/@mine/p1/lib --watch-path=../../node_modules/@mine/p2/lib ./scripts/build.mjs