npm / cli

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

[BUG] Ctrl+Cing npm update uninstalls everything #5006

Open BalaM314 opened 2 years ago

BalaM314 commented 2 years ago

Is there an existing issue for this?

This issue exists in the latest npm version

Current Behavior

(I was using npm 8.3.1 at first, updated to 8.12.1 and issue persisted) image I wanted to update a package I am using called mlogx. I mistyped the command as npm up -g mlog I did not want to install a random package, so I pressed Ctrl+C and told windows not to terminate the batch job. Several seconds after I pressed Ctrl+C npm outputs "Removed 1426 packages." Everything's gone.

I'm pretty sure you're not supposed to ctrl+c npm, but uninstalling all packages is the worst thing that can happen short of a vulnerability.

Expected Behavior

Either terminate/abort the command or install/update the mlog package.

Steps To Reproduce

Run npm up -g (some package that you don't have installed) Quickly press Ctrl+C and then type n

It removes all your globally installed packages. Reproduced twice.

Environment

prefix = "C:\Users\[username]\AppData\Roaming\npm"

; "user" config from C:\Users[username].npmrc

//registry.npmjs.org/:_authToken = (protected)

; node bin location = C:\Program Files\nodejs\node.exe ; cwd = C:\Bala\Mindustry\logic ; HOME = C:\Users[username] ; Run npm config ls -l to show all defaults.

BalaM314 commented 2 years ago

Also, is there any way to get my packages back? I don't remember everything I had installed.

BalaM314 commented 2 years ago

Anyone? This is kinda severe...

BalaM314 commented 2 years ago

anyone...