Skip to content

Instantly share code, notes, and snippets.

@sotayamashita
Last active May 26, 2016 08:41
Show Gist options
  • Save sotayamashita/9819e71e7f0c54546d81526d993f2da8 to your computer and use it in GitHub Desktop.
Save sotayamashita/9819e71e7f0c54546d81526d993f2da8 to your computer and use it in GitHub Desktop.
Uninstall globally installed packages
# For fish shell
# it helps you win at npm
function clean -d "Clean npm global modules"
# ~/.config/fnm 下は例外
end
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;
});
});
});
{
"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