Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib/node_mod.../npm/lib
File: whoami.js
'use strict'
[0] Fix | Delete
[1] Fix | Delete
const BB = require('bluebird')
[2] Fix | Delete
[3] Fix | Delete
const npmConfig = require('./config/figgy-config.js')
[4] Fix | Delete
const fetch = require('libnpm/fetch')
[5] Fix | Delete
const figgyPudding = require('figgy-pudding')
[6] Fix | Delete
const npm = require('./npm.js')
[7] Fix | Delete
const output = require('./utils/output.js')
[8] Fix | Delete
[9] Fix | Delete
const WhoamiConfig = figgyPudding({
[10] Fix | Delete
json: {},
[11] Fix | Delete
registry: {}
[12] Fix | Delete
})
[13] Fix | Delete
[14] Fix | Delete
module.exports = whoami
[15] Fix | Delete
[16] Fix | Delete
whoami.usage = 'npm whoami [--registry <registry>]\n(just prints username according to given registry)'
[17] Fix | Delete
[18] Fix | Delete
function whoami ([spec], silent, cb) {
[19] Fix | Delete
// FIXME: need tighter checking on this, but is a breaking change
[20] Fix | Delete
if (typeof cb !== 'function') {
[21] Fix | Delete
cb = silent
[22] Fix | Delete
silent = false
[23] Fix | Delete
}
[24] Fix | Delete
const opts = WhoamiConfig(npmConfig())
[25] Fix | Delete
return BB.try(() => {
[26] Fix | Delete
// First, check if we have a user/pass-based auth
[27] Fix | Delete
const registry = opts.registry
[28] Fix | Delete
if (!registry) throw new Error('no default registry set')
[29] Fix | Delete
return npm.config.getCredentialsByURI(registry)
[30] Fix | Delete
}).then(({username, token}) => {
[31] Fix | Delete
if (username) {
[32] Fix | Delete
return username
[33] Fix | Delete
} else if (token) {
[34] Fix | Delete
return fetch.json('/-/whoami', opts.concat({
[35] Fix | Delete
spec
[36] Fix | Delete
})).then(({username}) => {
[37] Fix | Delete
if (username) {
[38] Fix | Delete
return username
[39] Fix | Delete
} else {
[40] Fix | Delete
throw Object.assign(new Error(
[41] Fix | Delete
'Your auth token is no longer valid. Please log in again.'
[42] Fix | Delete
), {code: 'ENEEDAUTH'})
[43] Fix | Delete
}
[44] Fix | Delete
})
[45] Fix | Delete
} else {
[46] Fix | Delete
// At this point, if they have a credentials object, it doesn't have a
[47] Fix | Delete
// token or auth in it. Probably just the default registry.
[48] Fix | Delete
throw Object.assign(new Error(
[49] Fix | Delete
'This command requires you to be logged in.'
[50] Fix | Delete
), {code: 'ENEEDAUTH'})
[51] Fix | Delete
}
[52] Fix | Delete
}).then(username => {
[53] Fix | Delete
if (silent) {
[54] Fix | Delete
} else if (opts.json) {
[55] Fix | Delete
output(JSON.stringify(username))
[56] Fix | Delete
} else {
[57] Fix | Delete
output(username)
[58] Fix | Delete
}
[59] Fix | Delete
return username
[60] Fix | Delete
}).nodeify(cb)
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function