Commit 7cccee1ede4fd988f72a911b9fb2ef7be34a0754
Serve package dependencies from mentions
cel committed on 10/16/2017, 10:48:59 PMParent: 3caa0d6a8eb3842c70b3b9bdc2a5c55e4a80df5d
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -675,17 +675,53 @@ | ||
675 | 675 | } |
676 | 676 | |
677 | 677 | function populatePackageJson(sbot, obj, cb) { |
678 | 678 | var blobId = obj.dist.tarball.replace(/.*\/blobs\/get\//, '') |
679 | - getPackageJsonFromTarballBlob(sbot, blobId, function (err, pkg) { | |
680 | - if (err) return cb(err) | |
681 | - pkg.dist = obj.dist | |
682 | - pkg.dist.shasum = pkg._shasum | |
683 | - pkg.author = pkg.author || obj.author | |
684 | - pkg.version = pkg.version || obj.version | |
685 | - pkg.name = pkg.name || obj.name | |
686 | - cb(null, pkg) | |
687 | - }) | |
679 | + var deps | |
680 | + | |
681 | + // look for dependencies in links. | |
682 | + // then fallback to getting it from the tarball blob | |
683 | + | |
684 | + pull( | |
685 | + sbot.links({ | |
686 | + dest: blobId, | |
687 | + rel: 'mentions', | |
688 | + values: true, | |
689 | + }), | |
690 | + // decryption could be done here | |
691 | + pull.map(function (msg) { | |
692 | + var c = msg.value && msg.value.content | |
693 | + var mentions = c && c.mentions | |
694 | + return Array.isArray(mentions) ? mentions : [] | |
695 | + }), | |
696 | + pull.flatten(), | |
697 | + pull.filter(function (link) { | |
698 | + return link && link.link === blobId | |
699 | + }), | |
700 | + pull.drain(function (link) { | |
701 | + if (link.dependencies) deps = link.dependencies | |
702 | + // how to handle multiple assignments of dependencies to a package? | |
703 | + }, function (err) { | |
704 | + if (err) return cb(new Error(err.stack || err)) | |
705 | + if (deps) { | |
706 | + // assume that the dependencies in the links to the blob are | |
707 | + // correct. | |
708 | + obj.dependencies = deps | |
709 | + cb(null, obj) | |
710 | + } else { | |
711 | + // get dependencies from the tarball | |
712 | + getPackageJsonFromTarballBlob(sbot, blobId, function (err, pkg) { | |
713 | + if (err) return cb(err) | |
714 | + pkg.dist = obj.dist | |
715 | + pkg.dist.shasum = pkg._shasum | |
716 | + pkg.author = pkg.author || obj.author | |
717 | + pkg.version = pkg.version || obj.version | |
718 | + pkg.name = pkg.name || obj.name | |
719 | + cb(null, pkg) | |
720 | + }) | |
721 | + } | |
722 | + }) | |
723 | + ) | |
688 | 724 | } |
689 | 725 | |
690 | 726 | function getPackageJsonFromTarballBlob(sbot, id, cb) { |
691 | 727 | var self = this |
Built with git-ssb-web