Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2011-12-13 03:07:03 +0400
committerisaacs <i@izs.me>2011-12-13 03:07:03 +0400
commit13956300a65465a7b0593d11fda29527a9f4bc1c (patch)
tree64d2e62feb88070358e7322f456fcd5041511a57 /lib/rebuild.js
parent8f26ac441a5b514ad9ffdde0c130df3164e43e6e (diff)
Fix #1872 Clean on rebuild
Diffstat (limited to 'lib/rebuild.js')
-rw-r--r--lib/rebuild.js30
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) {