Permalink
Browse files

dedupe: respect dependency versions

Fixes issue #4675
  • Loading branch information...
1 parent 09223de commit 86028e9fd8524d5e520ce01ba2ebab5a030103fc @rafeca rafeca committed with isaacs Feb 14, 2014
Showing with 16 additions and 9 deletions.
  1. +11 −7 lib/dedupe.js
  2. +2 −1 test/tap/dedupe.js
  3. +3 −1 test/tap/dedupe/package.json
View
@@ -249,10 +249,10 @@ function findVersions (npm, summary, cb) {
var regVersions = er ? [] : Object.keys(data.versions)
var locMatch = bestMatch(versions, ranges)
var regMatch;
- var tag = npm.config.get("tag");
- var distTags = data["dist-tags"];
- if (distTags && distTags[tag] && data.versions[distTags[tag]]) {
- regMatch = distTags[tag]
+ var tag = npm.config.get("tag")
+ var distTag = data["dist-tags"] && data["dist-tags"][tag]
+ if (distTag && data.versions[distTag] && matches(distTag, ranges)) {
+ regMatch = distTag
} else {
regMatch = bestMatch(regVersions, ranges)
}
@@ -262,11 +262,15 @@ function findVersions (npm, summary, cb) {
}, cb)
}
+function matches (version, ranges) {
+ return !ranges.some(function (r) {
+ return !semver.satisfies(version, r, true)
+ })
+}
+
function bestMatch (versions, ranges) {
return versions.filter(function (v) {
- return !ranges.some(function (r) {
- return !semver.satisfies(v, r, true)
- })
+ return matches(v, ranges)
}).sort(semver.compareLoose).pop()
}
View
@@ -6,14 +6,15 @@ var test = require("tap").test
, rimraf = require("rimraf")
test("dedupe finds the common module and moves it up one level", function (t) {
- t.plan(1)
+ t.plan(2)
setup(function () {
npm.install(".", function (err) {
if (err) return t.fail(err)
npm.dedupe(function(err) {
if (err) return t.fail(err)
t.ok(existsSync(path.join(__dirname, "dedupe", "node_modules", "minimist")))
+ t.ok(!existsSync(path.join(__dirname, "dedupe", "node_modules", "prime")))
})
})
})
@@ -4,6 +4,8 @@
"version": "0.0.0",
"dependencies": {
"optimist": "0.6.0",
- "clean": "2.1.6"
+ "clean": "2.1.6",
+ "informal": "0.0.1",
+ "pathogen": "0.1.5"
}
}

0 comments on commit 86028e9

Please sign in to comment.