npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.38k stars 3.1k forks source link

[BUG] Pressing Ctrl+C exits running scripts anyways, Terminate batch job (Y/N)? prompt does not skip it on 'N' response. #4209

Closed Git-Harshit closed 2 years ago

Git-Harshit commented 2 years ago

Is there an existing issue for this?

This issue exists in the latest npm version

Current Behavior

I am using the latest npm LTS (Long Term Support) version v7.20.3 at the time of reporting this issue.

Normally, when we press Ctrl + C keyboard shortcut to terminate our running program, it prompts us with "Terminate batch job (Y/N)?", before actually stopping it. However, even when the response entered is a no (tried with entering 'n', 'no', 'N', 'No', 'NO' to this prompt), it still exits the running script. This is an undesired response for the case of denial to this prompt, as a non-termination should mean that the user has changed their mind on being prompted, and would like to keep the script running.

This behavior has been observed on Windows 10 Powershell. A snapshot of this has been attached: Non-Termination Error Highlighted

Expected Behavior

On pressing Ctrl + C keyboard shortcut, when "Terminate Batch Job (Y/N)?" prompt appears, it should ideally terminate the script only upon a positive confirmation (with case-insensitive responses like: 'y', 'yes'), and on a negation with responses like 'n'/'no', the termination of program must not be done, since it has prompted for the termination and the choice must still remain over to user.

i.e., Terminate batch job (Y/N)? should not terminate the script and continue running it in case of 'no' as a response.

Steps To Reproduce

  1. Run your npm project (with npm start)
  2. As the script gets successfully running, try to exit the running script with Ctrl + C keyboard shortcut.
  3. As a prompt appears, "Terminate batch job (Y/N)?", respond with typing 'n' or 'no' in terminal. Notice that the script still terminates, which is undesired and is exactly why this issue has been raised.

Environment

prefix = "C:\Users\Devil's Lair\AppData\Roaming\npm"

; node bin location = C:\Program Files\nodejs\node.exe ; cwd = C:\Users\Devil's Lair\Desktop\Temp\Swiggy IPP Backend Round 2 Case Study\food-app ; HOME = C:\Users\Devil's Lair ; Run npm config ls -l to show all defaults.

ljharb commented 2 years ago

npm start just runs your own script. Does that support control-c?

ljharb commented 2 years ago

Also, npm has no LTS and v7 is EOL. Try v8.

haneenmahd commented 2 years ago

I have also came across with that issue sometimes, but I didn't bother because I thought it was a typo 👀

Git-Harshit commented 2 years ago

npm start just runs your own script. Does that support control-c?

No, that Control+C isn't handled within the running script, but I guess npm does handle it since it captures the Control+C keyboard combination and prompts for "Terminate batch job (Y/N)?" following it, which gets exit on any input either beginning with a 'y' (which is desired) or 'n' (which isn't desired) or even a repeated Control+C key combination.

fritzy commented 2 years ago

"Terminate batch job" is a prompt that the windows command prompt gives. SIGINT is not something that npm handles when running scripts.