diff options
author | isaacs <i@izs.me> | 2012-02-29 05:16:27 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2012-02-29 05:16:27 +0400 |
commit | 8cf5f3445ba2944a48e5b9821932c18092d13450 (patch) | |
tree | f17e9625edf7ca0b79a4ee44e7620e0da9c935e1 | |
parent | 2f4c5be5454cec6355017eebeb10306a9af682d9 (diff) |
install: Support --save with url install targets
-rw-r--r-- | lib/install.js | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/install.js b/lib/install.js index 55c86bace..0a773b7ab 100644 --- a/lib/install.js +++ b/lib/install.js @@ -225,14 +225,22 @@ function save (where, installed, tree, pretty, cb) { if (!npm.config.get("save") || npm.config.get("global")) { return cb(null, installed, tree, pretty) } + // each item in the tree is a top-level thing that should be saved // to the package.json file. // The relevant tree shape is { <folder>: {what:<pkg>} } var saveTarget = path.resolve(where, "package.json") , things = Object.keys(tree).map(function (k) { - return tree[k].what.split("@") + // if "what" was a url, then save that instead. + var t = tree[k] + , u = url.parse(t.from) + , w = t.what.split("@") + if (u && u.protocol) w[1] = t.from + return w }).reduce(function (set, k) { - var rangeDescriptor = semver.gte(k[1], "0.1.0") ? "~" : "" + var rangeDescriptor = semver.valid(k[1]) && + semver.gte(k[1], "0.1.0") + ? "~" : "" set[k[0]] = rangeDescriptor + k[1] return set }, {}) @@ -309,11 +317,13 @@ function treeify (installed) { , parent = r[2] , where = r[1] , what = r[0] + , from = r[4] l[where] = { parentDir: parentDir , parent: parent , children: [] , where: where - , what: what } + , what: what + , from: from } return l }, {}) @@ -517,6 +527,9 @@ function targetResolver (where, context, deps) { log.info(data.name + "@" + data.version, "already installed") return cb(null, []) } + + if (data) data._from = what + return cb(er, data) }) } @@ -581,7 +594,8 @@ function resultList (target, where, parentId) { return [ target._id , targetFolder , prettyWhere && parentId - , parentId && prettyWhere ] + , parentId && prettyWhere + , target._from ] } function installOne_ (target, where, context, cb) { |