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

[BUG] trap 'exit 0' SIGINT doesn't work in npm scripts #1947

Closed
rafgraph opened this issue Oct 12, 2020 · 5 comments
Closed

[BUG] trap 'exit 0' SIGINT doesn't work in npm scripts #1947

rafgraph opened this issue Oct 12, 2020 · 5 comments
Assignees
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release

Comments

@rafgraph
Copy link

Current Behavior:

trap 'exit 0' SIGINT in an npm script doesn't seem work. I use this to preform clean up after exiting running watch scripts with ctrl c (maybe there's a better way to do this?).

  "scripts": {
    "dev": "npm link && npm run watch && npm unlink -g react-router-hash-link",
    "watch": "trap 'exit 0' SIGINT; babel src -d lib --watch --presets=@babel/preset-env,@babel/preset-react"
  },

In npm v6, npm run dev links the package to global node_modules, then runs the watch script which watches for changes and re-compiles, when I'm done I ctrl c, the watch script stops and npm unlink ... is run to preform cleanup.

In npm v7, after I ctrl c, that's it, nothing runs. I ran it with --loglevel silly but nothing is printed to the terminal after I ctrl c.

Expected Behavior:

For the watch script to exit with 0 after I press ctrl c and npm unlink ... to run.

Steps To Reproduce:

You can reproduce it using my react-router-hash-link repo (the dev setup is pretty simple).

git clone [email protected]:rafgraph/react-router-hash-link.git
cd react-router-hash-link
npm install
npm run dev
# the watch script should be running...
# press ctrl c

Environment:

  • OS: MacOS 10.15.7
  • Node: 12.8.3
  • npm: 7.0.0-rc.4
@rafgraph rafgraph added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Oct 12, 2020
@nlf
Copy link
Contributor

nlf commented Oct 12, 2020

This is interesting.. I'll do a little research and see if I can figure out what might've broken this.

In the mean time, a workaround that should do what you want would be to make your watch script look like:

"watch": "babel src -d lib --watch --presets=@babel/preset-env,@babel/preset-react || true"

Leaving the suggestion, but after some manual testing the proposed workaround does not work. I'll keep looking!

@nlf nlf removed the Needs Triage needs review for next steps label Oct 12, 2020
@nlf nlf self-assigned this Oct 12, 2020
@rafgraph
Copy link
Author

@nlf any update on this? I'm still having this issue in v7.0.3 (it's preventing me from using npm v7 regularly). Thanks.

@nlf
Copy link
Contributor

nlf commented Oct 26, 2020

i've identified the issue and am working on a fix, hopefully we'll have something for you soon!

@nlf
Copy link
Contributor

nlf commented Oct 27, 2020

hi @rafgraph! we published 7.0.6 of npm today that should resolve this for you, can you update with npm install -g npm@7 and let me know how it goes?

@rafgraph
Copy link
Author

Yup, works great, thanks @nlf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

2 participants