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>2012-03-13 01:27:34 +0400
committerisaacs <i@izs.me>2012-03-13 01:27:34 +0400
commit28044f3a775e7ab1d66274731ad38496f5c6073d (patch)
treed9c8f92f07330a08bf9fa5873b0c6bbbf612d9e3
parent4a312bec1d77944212f16372fd1af82d30b49c55 (diff)
Fix cases where an optionalDependency fails to build
-rw-r--r--lib/install.js28
-rw-r--r--test/packages/npm-test-optional-deps/package.json4
-rw-r--r--test/packages/npm-test-optional-deps/test.js8
3 files changed, 30 insertions, 10 deletions
diff --git a/lib/install.js b/lib/install.js
index 593999147..e879775a1 100644
--- a/lib/install.js
+++ b/lib/install.js
@@ -542,7 +542,18 @@ function installOne (target, where, context, cb) {
&& !npm.config.get("global")) {
return localLink(target, where, context, cb)
}
- installOne_(target, where, context, cb)
+ installOne_(target, where, context, function (er, installedWhat) {
+
+ // check if this one is optional to its parent.
+ if (context.parent && context.parent.optionalDependencies &&
+ context.parent.optionalDependencies.hasOwnProperty(target.name)) {
+ log.warn(target._id, "optional dependency failed, continuing")
+ er = null
+ }
+
+ cb(er, installedWhat)
+ })
+
}
function localLink (target, where, context, cb) {
@@ -610,7 +621,6 @@ function installOne_ (target, where, context, cb) {
, [checkGit, targetFolder]
, [write, target, targetFolder, context] ]
, function (er, d) {
- log.verbose(target._id, "installOne cb")
if (er) return cb(er)
d.push(resultList(target, where, parent && parent._id))
cb(er, d)
@@ -702,7 +712,7 @@ function write (target, targetFolder, context, cb_) {
// cache.unpack returns the data object, and all we care about
// is the list of installed packages from that last thing.
if (!er) return cb_(er, data)
- log.error(target._id,"error installing")
+
if (false === npm.config.get("rollback")) return cb_(er)
npm.commands.unbuild([targetFolder], function (er2) {
if (er2) log.error(er2, "error rolling back "+target._id)
@@ -750,12 +760,12 @@ function write (target, targetFolder, context, cb_) {
t = d + "@" + t
return t
}), targetFolder, newcontext, function (er, d) {
- log.verbose(targetFolder, "about to build")
- if (er) return cb(er)
- npm.commands.build( [targetFolder]
- , npm.config.get("global")
- , true
- , function (er) { return cb(er, d) })
+ log.verbose(targetFolder, "about to build")
+ if (er) return cb(er)
+ npm.commands.build( [targetFolder]
+ , npm.config.get("global")
+ , true
+ , function (er) { return cb(er, d) })
})
})
})
diff --git a/test/packages/npm-test-optional-deps/package.json b/test/packages/npm-test-optional-deps/package.json
index ebcd56832..56c6f09ed 100644
--- a/test/packages/npm-test-optional-deps/package.json
+++ b/test/packages/npm-test-optional-deps/package.json
@@ -1,10 +1,12 @@
{ "name": "npm-test-optional-deps"
, "version": "1.2.5"
+, "scripts": { "test": "node test.js" }
, "optionalDependencies":
{ "npm-test-foobarzaaakakaka": "http://example.com/"
, "dnode": "10.999.14234"
- , "sax": "*"
+ , "sax": "0.3.5"
, "999 invalid name": "1.2.3"
, "glob": "some invalid version 99 #! $$ x y z"
+ , "npm-test-failer":"*"
}
}
diff --git a/test/packages/npm-test-optional-deps/test.js b/test/packages/npm-test-optional-deps/test.js
new file mode 100644
index 000000000..a6f4698b7
--- /dev/null
+++ b/test/packages/npm-test-optional-deps/test.js
@@ -0,0 +1,8 @@
+var fs = require("fs")
+var assert = require("assert")
+var path = require("path")
+
+// sax should be the only dep that ends up installed
+assert.deepEquals(fs.readdirSync(path.resolve(__dirname, "node_modules")
+ ,["sax"]))
+assert.equals(require("sax/package.json").version, "0.3.5")