Commit 79ea45d491788d5a33f86650468cb355a92d4aa7
Link dependencyBranch only for matching versions
Don't link to messages for versions of a package that do not match the dependency speccel committed on 5/21/2018, 1:09:30 PM
Parent: b56b524effbc57d4b88d620b76205ae8e4208705
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -186,28 +186,47 @@ | ||
186 | 186 … | }) |
187 | 187 … | } |
188 | 188 … | |
189 | 189 … | function addPkgBySpec(name, spec, cb) { |
190 | - var done = multicb() | |
190 … | + var versions = {} | |
191 … | + var distTags = {} | |
191 | 192 … | pull( |
192 | 193 … | getMentions(sbot.links2, {$prefix: 'npm:' + name + ':'}), |
194 … | + pull.filter(mentionMatches(null, name, spec)), | |
193 | 195 … | pull.map(function (mention) { |
194 | - addPkgById(mention.link, done()) | |
195 | - return packageLinks(sbot, mention.author, mention.link, name, spec) | |
196 … | + // query to get the messages since links2 does not include the msg id | |
197 … | + return sbot.links({ | |
198 … | + source: mention.author, | |
199 … | + dest: mention.link, | |
200 … | + rel: 'mentions', | |
201 … | + values: true, | |
202 … | + }) | |
196 | 203 … | }), |
197 | 204 … | pull.flatten(), |
198 | 205 … | pull.drain(function (msg) { |
199 | 206 … | var c = msg && msg.value && msg.value.content |
200 | - if (!c) return | |
201 | - msgs[msg.key] = msg.value | |
207 … | + if (!c || !Array.isArray(c.mentions)) return | |
208 … | + c.mentions.forEach(function (link) { | |
209 … | + var data = link && link.name && decodeName(link.name) | |
210 … | + if (!data || data.name !== name) return | |
211 … | + versions[data.version] = {msg: msg, mention: link, mentionData: data} | |
212 … | + if (data.distTag) distTags[data.distTag] = data.version | |
213 … | + }) | |
214 … | + }, function (err) { | |
215 … | + if (err) return cb(err) | |
216 … | + var version = distTags[spec] | |
217 … | + || semver.maxSatisfying(Object.keys(versions), spec) | |
218 … | + var item = versions[version] | |
219 … | + if (!item) return console.error('version not found: ' + name + '@' + spec) | |
220 … | + msgs[item.msg.key] = item.msg.value | |
221 … | + var c = item.msg.value.content | |
202 | 222 … | if (Array.isArray(c.dependencyBranch)) { |
203 | 223 … | for (var k = 0; k < c.dependencyBranch.length; k++) { |
204 | 224 … | branched[c.dependencyBranch[k]] = true |
205 | 225 … | } |
206 | 226 … | } |
207 | - }, function (err) { | |
208 | - if (err) return cb(err) | |
209 | - done(cb) | |
227 … | + // console.log('add', item.msg.key, item.mentionData.name, item.mentionData.version) | |
228 … | + addPkgById(item.mention.link, cb) | |
210 | 229 … | }) |
211 | 230 … | ) |
212 | 231 … | } |
213 | 232 … | |
@@ -221,17 +240,9 @@ | ||
221 | 240 … | }) |
222 | 241 … | } |
223 | 242 … | |
224 | 243 … | function packageLinks(sbot, feed, id, name, spec) { |
225 | - function matches(mention) { | |
226 | - var data = mention | |
227 | - && mention.link === id | |
228 | - && mention.name | |
229 | - && decodeName(mention.name) | |
230 | - return data | |
231 | - && data.name === name | |
232 | - && (spec ? semver.satisfies(data.version, spec) : true) | |
233 | - } | |
244 … | + var matches = mentionMatches(id, name, spec) | |
234 | 245 … | return pull( |
235 | 246 … | sbot.links({ |
236 | 247 … | source: feed, |
237 | 248 … | dest: id, |
@@ -416,8 +427,20 @@ | ||
416 | 427 … | ] |
417 | 428 … | }) |
418 | 429 … | } |
419 | 430 … | |
431 … | +function mentionMatches(id, name, spec) { | |
432 … | + return function (mention) { | |
433 … | + var data = mention | |
434 … | + && (!id || id === mention.link) | |
435 … | + && mention.name | |
436 … | + && decodeName(mention.name) | |
437 … | + return data | |
438 … | + && data.name === name | |
439 … | + && (spec ? semver.satisfies(data.version, spec) : true) | |
440 … | + } | |
441 … | +} | |
442 … | + | |
420 | 443 … | SsbNpmRegistryServer.prototype.getMentions = function (name) { |
421 | 444 … | if (!this.sbot.links2) return pull.empty() |
422 | 445 … | return getMentions(this.sbot.links2, name) |
423 | 446 … | } |
Built with git-ssb-web