Skip to content

Instantly share code, notes, and snippets.

@mklabs
Created October 21, 2011 13:07
Show Gist options
  • Save mklabs/1303805 to your computer and use it in GitHub Desktop.
Save mklabs/1303805 to your computer and use it in GitHub Desktop.
npm script to automatically uninstall globally installed packages
var npm = require('npm');
// simple npm script to automatically uninstall globally installed package
//
// Usage: [sudo] node npm-clean.js
// Or, maybe: npm start
//
// edit protecteds array below to disable uninstall on these packages
var protecteds = ['npm'];
npm.load({global: true}, function() {
npm.commands.ls([], true, function(e, data) {
if(e) throw e;
var deps = Object.keys(data.dependencies),
protecteds = ['npm'];
deps = deps.filter(function(dep) {
return !~protecteds.indexOf(dep);
});
npm.commands.uninstall(deps, function(e) {
if(e) throw e;
});
});
});
{
"author": "mklabs",
"name": "npm-clean",
"description": "npm script to clean out globally installed package",
"version": "0.0.0",
"engines": {
"node": "~v0.4.12"
},
"dependencies": {
"npm": "~1.0.99"
},
"scripts": {
"start": "node npm-clean.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment