git ssb

3+

cel / ssb-npm-registry



Commit 79ea45d491788d5a33f86650468cb355a92d4aa7

Link dependencyBranch only for matching versions

Don't link to messages for versions of a package that do not match the
dependency spec
cel committed on 5/21/2018, 1:09:30 PM
Parent: b56b524effbc57d4b88d620b76205ae8e4208705

Files changed

index.jschanged
index.jsView
@@ -186,28 +186,47 @@
186186 })
187187 }
188188
189189 function addPkgBySpec(name, spec, cb) {
190- var done = multicb()
190 + var versions = {}
191 + var distTags = {}
191192 pull(
192193 getMentions(sbot.links2, {$prefix: 'npm:' + name + ':'}),
194 + pull.filter(mentionMatches(null, name, spec)),
193195 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 + })
196203 }),
197204 pull.flatten(),
198205 pull.drain(function (msg) {
199206 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
202222 if (Array.isArray(c.dependencyBranch)) {
203223 for (var k = 0; k < c.dependencyBranch.length; k++) {
204224 branched[c.dependencyBranch[k]] = true
205225 }
206226 }
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)
210229 })
211230 )
212231 }
213232
@@ -221,17 +240,9 @@
221240 })
222241 }
223242
224243 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)
234245 return pull(
235246 sbot.links({
236247 source: feed,
237248 dest: id,
@@ -416,8 +427,20 @@
416427 ]
417428 })
418429 }
419430
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 +
420443 SsbNpmRegistryServer.prototype.getMentions = function (name) {
421444 if (!this.sbot.links2) return pull.empty()
422445 return getMentions(this.sbot.links2, name)
423446 }

Built with git-ssb-web