-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Closed
Labels
Bugthing that needs fixingthing that needs fixingPriority 2secondary priority issuesecondary priority issueRelease 9.xwork is associated with a specific npm 9 releasework is associated with a specific npm 9 release
Description
Is there an existing issue for this?
- I have searched the existing issues
This issue exists in the latest npm version
- I am using the latest npm
Current Behavior
Scripts run via npm run
have their trap hooks terminated prematurely. This is undesirable because the script does not get a chance to clean up after itself. Worse, it might clean up only some of its mess.
Expected Behavior
Any Bash "trap" hooks to run to completion.
Steps To Reproduce
Create a file demo.sh containing
#!/bin/bash
trap "echo start; sleep 1; echo end" EXIT
cat
and make it executable with chmod +x demo.sh
. Notice that it has a trap hook that runs on exit. The hook echoes "start", does some work, then echoes "end". Declare it as the script "demo" in a package.json file:
{
"scripts":{
"demo":"./demo.sh"
}
}
Run the "demo" script, then interrupt it by typing ctrl-c. Notice that the trap hook does not run to completion:
$ npm run demo
> demo
> ./demo.sh
^Cstart
On the other hand, running the script directly runs the trap hook to completion:
$ ./demo.sh
^Cstart
end
Environment
- npm: 9.4.0
- Node.js: v19.6.0
- OS Name: MacOS 13.1
- System Model Name: MacBook Pro
- npm config:
; "user" config from /Users/me/.npmrc
//registry.npmjs.org/:_authToken = (protected)
; node bin location = /nix/store/fnhfi19p4wlj38wjrxipnb355jxf3zzn-nodejs-19.6.0/bin/node
; node version = v19.6.0
; npm local prefix = /private/tmp
; npm version = 9.4.0
; cwd = /private/tmp
; HOME = /Users/me
; Run `npm config ls -l` to show all defaults.
Metadata
Metadata
Assignees
Labels
Bugthing that needs fixingthing that needs fixingPriority 2secondary priority issuesecondary priority issueRelease 9.xwork is associated with a specific npm 9 releasework is associated with a specific npm 9 release