Last active
May 26, 2016 08:41
-
-
Save sotayamashita/9819e71e7f0c54546d81526d993f2da8 to your computer and use it in GitHub Desktop.
Uninstall globally installed packages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For fish shell | |
# it helps you win at npm | |
function clean -d "Clean npm global modules" | |
# ~/.config/fnm 下は例外 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var npm = require('npm'); | |
npm.load({global: true}, function() { | |
npm.commands.ls([], true, function(e, data) { | |
if(e) throw e; | |
var deps = Object.keys(data.dependencies); | |
var protecteds = ['npm']; | |
deps = deps.filter(function(dep) { | |
return !~protecteds.indexOf(dep); | |
}); | |
npm.commands.uninstall(deps, function(e) { | |
if (e) throw e; | |
}); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "clean", | |
"version": "0.0.0", | |
"script": { | |
"start": "sudo node index.js", | |
}, | |
"dependencies": { | |
"npm": "*" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment