"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/repo.js" (8 Mar 2017, 1464 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 module.exports = repo
    2 
    3 repo.usage = 'npm repo [<pkg>]'
    4 
    5 var npm = require('./npm.js')
    6 var opener = require('opener')
    7 var hostedGitInfo = require('hosted-git-info')
    8 var url_ = require('url')
    9 var fetchPackageMetadata = require('./fetch-package-metadata.js')
   10 
   11 repo.completion = function (opts, cb) {
   12   // FIXME: there used to be registry completion here, but it stopped making
   13   // sense somewhere around 50,000 packages on the registry
   14   cb()
   15 }
   16 
   17 function repo (args, cb) {
   18   var n = args.length ? args[0] : '.'
   19   fetchPackageMetadata(n, '.', function (er, d) {
   20     if (er) return cb(er)
   21     getUrlAndOpen(d, cb)
   22   })
   23 }
   24 
   25 function getUrlAndOpen (d, cb) {
   26   var r = d.repository
   27   if (!r) return cb(new Error('no repository'))
   28   // XXX remove this when npm@v1.3.10 from node 0.10 is deprecated
   29   // from https://github.com/npm/npm-www/issues/418
   30   var info = hostedGitInfo.fromUrl(r.url)
   31   var url = info ? info.browse() : unknownHostedUrl(r.url)
   32 
   33   if (!url) return cb(new Error('no repository: could not get url'))
   34 
   35   opener(url, { command: npm.config.get('browser') }, cb)
   36 }
   37 
   38 function unknownHostedUrl (url) {
   39   try {
   40     var idx = url.indexOf('@')
   41     if (idx !== -1) {
   42       url = url.slice(idx + 1).replace(/:([^\d]+)/, '/$1')
   43     }
   44     url = url_.parse(url)
   45     var protocol = url.protocol === 'https:'
   46                  ? 'https:'
   47                  : 'http:'
   48     return protocol + '//' + (url.host || '') +
   49       url.path.replace(/\.git$/, '')
   50   } catch (e) {}
   51 }