git ssb

3+

cel / ssb-npm-registry



Commit 95a2fd6cf1a985c8b6464b1cd942976514dd2a8a

Merge remote-tracking branch 'origin/versionbranch'

cel committed on 9/15/2018, 4:36:22 AM
Parent: 5ee0a01a69c91c5160041d83a15cff5fedbd9868
Parent: bf1c5c86632296f2a3cd1dd494c169143d5a2d7c

Files changed

index.jschanged
index.jsView
@@ -147,11 +147,9 @@
147147 cb(err, msg)
148148 })
149149 }
150150
151-function getDependencyBranches(sbot, link, cb) {
152- var id = link.link
153-
151 +function getDependencyBranches(sbot, id, cb) {
154152 // get ids of heads of tree of dependencyBranch message links to include all
155153 // the dependencies of the given tarball id.
156154 var getPackageJsonCached = memo(getPackageJsonFromTarballBlob, sbot)
157155 var msgs = {}
@@ -204,48 +202,22 @@
204202 var version = distTags[spec]
205203 || semver.maxSatisfying(Object.keys(versions), spec)
206204 var item = versions[version]
207205 if (!item) return cb(new Error('Dependency version not found: ' + name + '@' + spec))
208- addDepBranchMsg(item.msg)
206 + msgs[item.msg.key] = item.msg.value
207 + var c = item.msg.value.content
208 + if (Array.isArray(c.dependencyBranch)) {
209 + for (var k = 0; k < c.dependencyBranch.length; k++) {
210 + branched[c.dependencyBranch[k]] = true
211 + }
212 + }
209213 // console.log('add', item.msg.key, item.mentionData.name, item.mentionData.version)
210214 addPkgById(item.mention.link, cb)
211215 })
212216 )
213217 }
214218
215- function addDepBranchMsg(msg) {
216- var c = msg && msg.value && msg.value.content
217- if (!c) return
218- if (msgs[msg.key]) return
219- msgs[msg.key] = msg.value
220- if (Array.isArray(c.dependencyBranch)) {
221- for (var k = 0; k < c.dependencyBranch.length; k++) {
222- branched[c.dependencyBranch[k]] = true
223- }
224- }
225- if (Array.isArray(c.versionBranch)) {
226- for (var k = 0; k < c.versionBranch.length; k++) {
227- branched[c.versionBranch[k]] = true
228- }
229- }
230- }
231-
232- function addPkgsByName(name, cb) {
233- var data = decodeName(name)
234- pull(
235- getMentions(sbot.links2, {$prefix: 'npm:' + data.name + ':'}),
236- pull.map(function (mention) {
237- return packageLinks(sbot, mention.author, mention.link, data.name)
238- }),
239- pull.flatten(),
240- pull.drain(addDepBranchMsg, cb)
241- )
242- }
243-
244- var done = multicb()
245- addPkgsByName(link.name, done())
246- addPkgById(id, done())
247- done(function (err) {
219 + addPkgById(id, function (err) {
248220 if (err) return cb(err)
249221 var ids = []
250222 for (var key in msgs) {
251223 if (!branched[key]) ids.push(key)
@@ -269,21 +241,53 @@
269241 })
270242 )
271243 }
272244
245 +function getVersionBranches(sbot, link, cb) {
246 + var data = decodeName(link.name)
247 + var msgs = {}, branched = {}
248 + pull(
249 + getMentions(sbot.links2, {$prefix: 'npm:' + data.name + ':'}),
250 + pull.map(function (mention) {
251 + return packageLinks(sbot, mention.author, mention.link, data.name)
252 + }),
253 + pull.flatten(),
254 + pull.drain(function (msg) {
255 + var c = msg && msg.value && msg.value.content
256 + if (!c) return
257 + msgs[msg.key] = msg.value
258 + if (Array.isArray(c.versionBranch)) {
259 + for (var k = 0; k < c.versionBranch.length; k++) {
260 + branched[c.versionBranch[k]] = true
261 + }
262 + }
263 + }, function (err) {
264 + if (err) return cb(err)
265 + var ids = []
266 + for (var key in msgs) {
267 + if (!branched[key]) ids.push(key)
268 + }
269 + cb(null, ids)
270 + })
271 + )
272 +}
273 +
273274 // For each dependency that is not a bundledDependency, get message ids for
274275 // that dependency name + version.
275276 function publishSingleMention(sbot, mention, cb) {
276277 if (!sbot.links2) return cb(new Error('ssb-links scuttlebot plugin is required to publish ssb-npm packages'))
277- // Calculate dependencyBranch message ids.
278 + // Calculate dependencyBranch and versionBranch message ids.
278279 var value = {
279280 type: 'npm-packages',
280281 mentions: [mention]
281282 }
282283 var done = multicb({pluck: 1, spread: true})
283- getDependencyBranches(sbot, mention, function (err, branches) {
284 + getDependencyBranches(sbot, mention.link, done())
285 + getVersionBranches(sbot, mention, done())
286 + done(function (err, dependencyBranches, versionBranches) {
284287 if (err) return cb(err)
285- value.dependencyBranch = branches || undefined
288 + value.dependencyBranch = dependencyBranches || undefined
289 + value.versionBranch = versionBranches || undefined
286290 publishMsg(sbot, value, cb)
287291 })
288292 }
289293

Built with git-ssb-web