diff options
Diffstat (limited to 'lib/rebuild.js')
-rw-r--r-- | lib/rebuild.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/rebuild.js b/lib/rebuild.js index f3f759620..fc5f96825 100644 --- a/lib/rebuild.js +++ b/lib/rebuild.js @@ -7,6 +7,9 @@ var readInstalled = require("./utils/read-installed.js") , path = require("path") , npm = require("./npm.js") , output = require("./utils/output.js") + , asyncMap = require("slide").asyncMap + , fs = require("graceful-fs") + , exec = require("./utils/exec.js") rebuild.usage = "npm rebuild [<name>[@<version>] [name[@<version>] ...]]" @@ -22,6 +25,33 @@ function rebuild (args, cb) { }) if (!folders.length) return cb() log.silly(folders, "rebuild set") + cleanBuild(folders, set, cb) + }) +} + +function cleanBuild (folders, set, cb) { + // https://github.com/isaacs/npm/issues/1872 + // If there's a makefile, try 'make clean' + // If there's a wscript, try 'node-waf clean' + // But don't die on either of those if they fail. + // Just a best-effort kind of deal. + asyncMap(folders, function (f, cb) { + fs.readdir(f, function (er, files) { + // everything should be a dir. + if (er) return cb(er) + if (files.indexOf("wscript") !== -1) { + exec("node-waf", ["clean"], null, false, f, thenBuild) + } else if (files.indexOf("Makefile") !== -1) { + exec("make", ["clean"], null, false, f, thenBuild) + } else thenBuild() + }) + function thenBuild (er) { + // ignore error, just continue + // it could be that it's not configured yet or whatever. + cb() + } + }, function (er) { + if (er) return cb(er) npm.commands.build(folders, function (er) { if (er) return cb(er) output.write(folders.map(function (f) { |