Skip to content
Browse files

check for unused packages after install command

  • Loading branch information...
1 parent 95ee791 commit 46c441b2d03e089d8f427b680cacb688ca40d224 @caolan caolan committed Mar 5, 2012
Showing with 40 additions and 34 deletions.
  1. +39 −1 lib/commands/install.js
  2. +1 −33 lib/commands/update.js
View
40 lib/commands/install.js
@@ -13,6 +13,7 @@ var semver = require('semver'),
argParse = require('../args').parse,
tar = require('../tar'),
tree = require('../tree'),
+ clean = require('./clean'),
async = require('async'),
path = require('path'),
fs = require('fs');
@@ -239,7 +240,13 @@ exports.installTree = function (packages, opt, callback) {
else {
process.nextTick(cb);
}
- }, callback);
+ }, function (err) {
+ if (err) {
+ return callback(err);
+ }
+ // report packages that are no-longer used
+ exports.checkUnused(packages, opt, callback);
+ });
};
@@ -534,3 +541,34 @@ exports.installURL = function (url, 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();
+ });
+};
View
34 lib/commands/update.js
@@ -4,7 +4,6 @@
var path = require('path'),
semver = require('semver'),
- clean = require('./clean'),
install = require('./install'),
tree = require('../tree');
utils = require('../utils'),
@@ -85,7 +84,7 @@ exports.update = function (deps, opt, callback) {
if (err) {
return callback(err);
}
- exports.checkUnused(updated, opt, callback);
+ install.checkUnused(updated, opt, callback);
});
}
);
@@ -94,37 +93,6 @@ exports.update = function (deps, 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
* the installed packages against those that are available in the repositories.
*

0 comments on commit 46c441b

Please sign in to comment.
Something went wrong with that request. Please try again.