From 13956300a65465a7b0593d11fda29527a9f4bc1c Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 12 Dec 2011 15:07:03 -0800 Subject: Fix #1872 Clean on rebuild --- lib/rebuild.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'lib/rebuild.js') 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[@] ...]]" @@ -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) { -- cgit v1.2.3