diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2018-04-21 21:19:09 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2018-04-21 21:20:59 -1000 |
commit | 47a922112154cbc356eccd14c6e4f23ed668c322 (patch) | |
tree | b76f150ee94afa75e242fabf82b2cc6018a8e6de /lib | |
parent | d4ebc65ac4f4a72c0ae1bd9cd5aa1fc7c7f5b22e (diff) | |
download | patchfoo-47a922112154cbc356eccd14c6e4f23ed668c322.tar.gz patchfoo-47a922112154cbc356eccd14c6e4f23ed668c322.zip |
Include ssb-npm
- Serve ssb-npm-registry requests under /npm-registry
- Show install command for npm-packages messages
Diffstat (limited to 'lib')
-rw-r--r-- | lib/app.js | 2 | ||||
-rw-r--r-- | lib/render-msg.js | 12 | ||||
-rw-r--r-- | lib/serve.js | 7 |
3 files changed, 21 insertions, 0 deletions
@@ -17,6 +17,7 @@ var proc = require('child_process') var toPull = require('stream-to-pull-stream') var BoxStream = require('pull-box-stream') var crypto = require('crypto') +var SsbNpmRegistry = require('ssb-npm-registry') var zeros = new Buffer(24); zeros.fill(0) @@ -65,6 +66,7 @@ function App(sbot, config) { this.git = new Git(this.sbot, this.config) this.contacts = new Contacts(this.sbot) this.follows = new Follows(this.sbot, this.contacts) + this.serveSsbNpmRegistry = SsbNpmRegistry.respond(this.sbot, this.config) this.monitorBlobWants() } diff --git a/lib/render-msg.js b/lib/render-msg.js index b4ba87a..684ea40 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -1111,12 +1111,24 @@ RenderMsg.prototype.npmPackages = function (cb) { function renderIdLink(id) { return [h('a', {href: self.toUrl(id)}, truncate(id, 8)), ' '] } + var singlePkg = self.c.mentions + && self.c.mentions.length === 1 + && self.c.mentions[0] + var m = singlePkg && /^npm:(.*?):(.*?):/.exec(singlePkg.name) + var singlePkgSpec = m && (m[1] + (m[2] ? '@' + m[2] : '')) self.render.npmPackageMentions(self.c.mentions, function (err, el) { if (err) return cb(err) var dependencyLinks = u.toArray(self.c.dependencyBranch) var versionLinks = u.toArray(self.c.versionBranch) self.wrap(h('div', [ el, + singlePkg ? h('p', + h('code', + 'npm install --registry=' + + 'http://' + self.app.host + ':' + self.app.port + + '/npm-registry/' + encodeURIComponent(self.msg.key) + ' ' + + singlePkgSpec), + ) : '', dependencyLinks.length ? h('div', 'dependencies via: ', dependencyLinks.map(renderIdLink) ) : '', diff --git a/lib/serve.js b/lib/serve.js index 0e497ea..4b9eb1b 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -352,6 +352,7 @@ Serve.prototype.path = function (url) { case '/npm': return this.npm(m[2]) case '/npm-prebuilds': return this.npmPrebuilds(m[2]) case '/npm-readme': return this.npmReadme(m[2]) + case '/npm-registry': return this.npmRegistry(m[2]) case '/markdown': return this.markdown(m[2]) case '/zip': return this.zip(m[2]) case '/web': return this.web(m[2]) @@ -2534,6 +2535,12 @@ Serve.prototype.npmReadme = function (url) { ) } +Serve.prototype.npmRegistry = function (url) { + var self = this + self.req.url = url + self.app.serveSsbNpmRegistry(self.req, self.res) +} + Serve.prototype.markdown = function (url) { var self = this var id = decodeURIComponent(url.substr(1)) |