Commit 95a2fd6cf1a985c8b6464b1cd942976514dd2a8a
Merge remote-tracking branch 'origin/versionbranch'
cel committed on 9/15/2018, 4:36:22 AMParent: 5ee0a01a69c91c5160041d83a15cff5fedbd9868
Parent: bf1c5c86632296f2a3cd1dd494c169143d5a2d7c
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -147,11 +147,9 @@ | ||
147 | 147 … | cb(err, msg) |
148 | 148 … | }) |
149 | 149 … | } |
150 | 150 … | |
151 | -function getDependencyBranches(sbot, link, cb) { | |
152 | - var id = link.link | |
153 | - | |
151 … | +function getDependencyBranches(sbot, id, cb) { | |
154 | 152 … | // get ids of heads of tree of dependencyBranch message links to include all |
155 | 153 … | // the dependencies of the given tarball id. |
156 | 154 … | var getPackageJsonCached = memo(getPackageJsonFromTarballBlob, sbot) |
157 | 155 … | var msgs = {} |
@@ -204,48 +202,22 @@ | ||
204 | 202 … | var version = distTags[spec] |
205 | 203 … | || semver.maxSatisfying(Object.keys(versions), spec) |
206 | 204 … | var item = versions[version] |
207 | 205 … | 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 … | + } | |
209 | 213 … | // console.log('add', item.msg.key, item.mentionData.name, item.mentionData.version) |
210 | 214 … | addPkgById(item.mention.link, cb) |
211 | 215 … | }) |
212 | 216 … | ) |
213 | 217 … | } |
214 | 218 … | |
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) { | |
248 | 220 … | if (err) return cb(err) |
249 | 221 … | var ids = [] |
250 | 222 … | for (var key in msgs) { |
251 | 223 … | if (!branched[key]) ids.push(key) |
@@ -269,21 +241,53 @@ | ||
269 | 241 … | }) |
270 | 242 … | ) |
271 | 243 … | } |
272 | 244 … | |
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 … | + | |
273 | 274 … | // For each dependency that is not a bundledDependency, get message ids for |
274 | 275 … | // that dependency name + version. |
275 | 276 … | function publishSingleMention(sbot, mention, cb) { |
276 | 277 … | 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. | |
278 | 279 … | var value = { |
279 | 280 … | type: 'npm-packages', |
280 | 281 … | mentions: [mention] |
281 | 282 … | } |
282 | 283 … | 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) { | |
284 | 287 … | if (err) return cb(err) |
285 | - value.dependencyBranch = branches || undefined | |
288 … | + value.dependencyBranch = dependencyBranches || undefined | |
289 … | + value.versionBranch = versionBranches || undefined | |
286 | 290 … | publishMsg(sbot, value, cb) |
287 | 291 … | }) |
288 | 292 … | } |
289 | 293 … |
Built with git-ssb-web