Skip to content
This repository has been archived by the owner on Jan 31, 2019. It is now read-only.

Commit

Permalink
check for unused packages after install command
Browse files Browse the repository at this point in the history
  • Loading branch information
Caolan McMahon committed Mar 5, 2012
1 parent 95ee791 commit 46c441b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
40 changes: 39 additions & 1 deletion lib/commands/install.js
Expand Up @@ -13,6 +13,7 @@ var semver = require('semver'),
argParse = require('../args').parse, argParse = require('../args').parse,
tar = require('../tar'), tar = require('../tar'),
tree = require('../tree'), tree = require('../tree'),
clean = require('./clean'),
async = require('async'), async = require('async'),
path = require('path'), path = require('path'),
fs = require('fs'); fs = require('fs');
Expand Down Expand Up @@ -239,7 +240,13 @@ exports.installTree = function (packages, opt, callback) {
else { else {
process.nextTick(cb); process.nextTick(cb);
} }
}, callback); }, function (err) {
if (err) {
return callback(err);
}
// report packages that are no-longer used
exports.checkUnused(packages, opt, callback);
});
}; };




Expand Down Expand Up @@ -534,3 +541,34 @@ exports.installURL = function (url, opt, callback) {
exports.installFile(filename, opt, callback); exports.installFile(filename, opt, callback);
}); });
}; };


/**
* Checks the packages directory for packages not in the provided version
* tree.
*
* @param {Object} packages - the version tree to compare against
* @param {Object} opt - the options object
* @param {Function} callback
*/

exports.checkUnused = function (packages, opt, callback) {
clean.unusedDirsTree(packages, opt, function (err, dirs) {
if (err) {
return callback(err);
}
if (dirs.length) {
var names = dirs.map(function (d) {
return path.relative('.', d);
});
console.log(
'\n' +
'The following packages are no longer required, ' +
'and can be removed\nby running "kanso clean":\n' +
' ' + names.join('\n ') +
'\n'
);
}
return callback();
});
};
34 changes: 1 addition & 33 deletions lib/commands/update.js
Expand Up @@ -4,7 +4,6 @@


var path = require('path'), var path = require('path'),
semver = require('semver'), semver = require('semver'),
clean = require('./clean'),
install = require('./install'), install = require('./install'),
tree = require('../tree'); tree = require('../tree');
utils = require('../utils'), utils = require('../utils'),
Expand Down Expand Up @@ -85,45 +84,14 @@ exports.update = function (deps, opt, callback) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
exports.checkUnused(updated, opt, callback); install.checkUnused(updated, opt, callback);
}); });
} }
); );
}); });
}; };




/**
* Checks the packages directory for packages not in the provided version
* tree.
*
* @param {Object} packages - the version tree to compare against
* @param {Object} opt - the options object
* @param {Function} callback
*/

exports.checkUnused = function (packages, opt, callback) {
clean.unusedDirsTree(packages, opt, function (err, dirs) {
if (err) {
return callback(err);
}
if (dirs.length) {
var names = dirs.map(function (d) {
return path.relative('.', d);
});
console.log(
'\n' +
'The following packages are no longer required, ' +
'and can be removed\nby running "kanso clean":\n' +
' ' + names.join('\n ') +
'\n'
);
}
return callback();
});
};


/** /**
* Builds a remote and a local copy of the version tree. This is used to compare * Builds a remote and a local copy of the version tree. This is used to compare
* the installed packages against those that are available in the repositories. * the installed packages against those that are available in the repositories.
Expand Down

0 comments on commit 46c441b

Please sign in to comment.