"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/whoami.js" (7 Feb 2017, 1455 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 var npm = require('./npm.js')
    2 var output = require('./utils/output.js')
    3 
    4 module.exports = whoami
    5 
    6 whoami.usage = 'npm whoami [--registry <registry>]\n(just prints username according to given registry)'
    7 
    8 function whoami (args, silent, cb) {
    9   // FIXME: need tighter checking on this, but is a breaking change
   10   if (typeof cb !== 'function') {
   11     cb = silent
   12     silent = false
   13   }
   14 
   15   var registry = npm.config.get('registry')
   16   if (!registry) return cb(new Error('no default registry set'))
   17 
   18   var auth = npm.config.getCredentialsByURI(registry)
   19   if (auth) {
   20     if (auth.username) {
   21       if (!silent) output(auth.username)
   22       return process.nextTick(cb.bind(this, null, auth.username))
   23     } else if (auth.token) {
   24       return npm.registry.whoami(registry, { auth: auth }, function (er, username) {
   25         if (er) return cb(er)
   26         if (!username) {
   27           var needNewSession = new Error(
   28             'Your auth token is no longer valid. Please log in again.'
   29           )
   30           needNewSession.code = 'ENEEDAUTH'
   31           return cb(needNewSession)
   32         }
   33 
   34         if (!silent) output(username)
   35         cb(null, username)
   36       })
   37     }
   38   }
   39 
   40   // At this point, if they have a credentials object, it doesn't have a token
   41   // or auth in it.  Probably just the default registry.
   42   var needAuth = new Error(
   43     'this command requires you to be logged in.'
   44   )
   45   needAuth.code = 'ENEEDAUTH'
   46   process.nextTick(cb.bind(this, needAuth))
   47 }