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

Way to stop listening on changes #49

Open
hadrien-toma opened this issue Apr 7, 2017 · 3 comments
Open

Way to stop listening on changes #49

hadrien-toma opened this issue Apr 7, 2017 · 3 comments

Comments

@hadrien-toma
Copy link

hadrien-toma commented Apr 7, 2017

Hi there, I am wondering if there is a cross-platform way to stop listening on changes. For instance, do you have an idea of how to achieve this behavior:

  • In my package.json:
"scripts": {
    "onchange": "./node_modules/onchange/cli.js",
    "listen": "npm run listen:*",
    "listen:a": "npm run onchange -- \"./file_a\" -- npm run doonchange:a",
    "doonchange:a": "# do awesome things",
    "listen:b": "npm run onchange -- \"./file_b\" -- npm run doonchange:b",
    "doonchange:b": "# stop listening on file_a changes ",
}
  • In my terminal:
   npm run listen
# Listening on changes until I change my `index.js` file 

PS : Really usefull/powerfull package, thank you!

@blakeembrey
Copy link
Collaborator

I can't think of any way beyond writing the PID to disk and reading it again later to kill the process. Not sure if something similar to that works on Windows. If there is, I can look at building it into the package, but until then I'll leave the issue open for others to comment.

@hadrien-toma
Copy link
Author

hadrien-toma commented Aug 2, 2017

I finally use pm2 (cross-platform) in order to wrap the onchange command, this way the package.json's script section looks like:

		"callback": "echo 'foo'",
		"listener": "onchange ./listened -- npm run callback",
		"listener:ps:c": "pm2 start --name listener.ps npm -- run listener",
		"listener:ps:d": "pm2 delete listener.ps"

This allows to stop listening onchange in a cross-platform way!

@alecarg
Copy link

alecarg commented Oct 30, 2022

While the above didn't work for me, using nodemon did:

"main": "yarn run start",

and

"scripts": {
  "start": "nodemon --exec yarn run onchange-watch",
  "onchange-watch": "onchange -- yarn run callback"
  "callback": "<something> && nodemon --exec yarn run start"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants