Skip to content

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

@rafgraph

Description

@rafgraph

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 git@github.com: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

Metadata

Metadata

Assignees

Labels

Bugthing that needs fixingRelease 7.xwork is associated with a specific npm 7 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions