git ssb

3+

cel / ssb-npm-registry



Commit 768670b4c7e5fe519e7fcd47c00f692fcfadaf21

Let newer dist-tag updates take precedence

re: %1kWUe02L1DP5+XWKFKlgSviEYXCuzx+xzaXIeVY6aYU=.sha256
cel committed on 12/11/2017, 6:36:24 AM
Parent: 9a4aec35b080e6a7dd68a561c6fe650319bc07e5

Files changed

index.jschanged
index.jsView
@@ -609,14 +609,22 @@
609609 name: pkgName,
610610 'dist-tags': {},
611611 versions: {}
612612 }
613+ var distTags = {/* <tag>: {version, ts}*/}
613614 pull(
614615 self.server.getMentions({$prefix: 'npm:' + pkgName + ':'}),
615616 pull.drain(function (mention) {
616617 var data = decodeName(mention.name)
617618 if (!data.version) return
618- if (data.distTag) obj['dist-tags'][data.distTag] = data.version
619+ if (data.distTag) {
620+ var tag = distTags[data.distTag]
621+ if (!tag || mention.ts > tag.ts) {
622+ /* TODO: sort by causal order (versionBranch links) instead of just
623+ * by timestamps */
624+ distTags[data.distTag] = {ts: mention.ts, version: data.version}
625+ }
626+ }
619627 obj.versions[data.version] = {
620628 author: {
621629 url: mention.author
622630 },
@@ -625,8 +633,11 @@
625633 dist: self.server.blobDist(mention.link)
626634 }
627635 }, function (err) {
628636 if (err) return self.respondError(500, err.stack || err)
637+ for (var tag in distTags) {
638+ obj['dist-tags'][tag] = distTags[tag].version
639+ }
629640 if (spec) resolveSpec()
630641 else if (self.fetchAll) resolveAll()
631642 else done()
632643 })

Built with git-ssb-web