diff options
author | Kat Marchán <kzm@zkat.tech> | 2018-04-06 07:29:23 +0300 |
---|---|---|
committer | Kat Marchán <kzm@zkat.tech> | 2018-12-11 01:55:39 +0300 |
commit | 584613ea8ff94b927db4957e5647504b30ca2b1f (patch) | |
tree | aec3e16fb0471a1fd99035135ea17af375a23d27 /lib | |
parent | 6e922aefbb4634bbd77ed3b143e0765d63afc7f9 (diff) |
ping: stop using npm-registry-client
Diffstat (limited to 'lib')
-rw-r--r-- | lib/doctor/check-ping.js | 8 | ||||
-rw-r--r-- | lib/ping.js | 46 |
2 files changed, 39 insertions, 15 deletions
diff --git a/lib/doctor/check-ping.js b/lib/doctor/check-ping.js index e7e82902a..70db25548 100644 --- a/lib/doctor/check-ping.js +++ b/lib/doctor/check-ping.js @@ -4,8 +4,12 @@ var ping = require('../ping.js') function checkPing (cb) { var tracker = log.newItem('checkPing', 1) tracker.info('checkPing', 'Pinging registry') - ping({}, true, (_err, pong, data, res) => { - cb(null, [res.statusCode, res.statusMessage]) + ping({}, true, (err, pong) => { + if (err && err.code && err.code.match(/^E\d{3}$/)) { + return cb(null, [err.code.substr(1)]) + } else { + cb(null, [200, 'OK']) + } }) } diff --git a/lib/ping.js b/lib/ping.js index 13f390397..3023bab00 100644 --- a/lib/ping.js +++ b/lib/ping.js @@ -1,5 +1,16 @@ -var npm = require('./npm.js') -var output = require('./utils/output.js') +'use strict' + +const npmConfig = require('./config/figgy-config.js') +const fetch = require('libnpm/fetch') +const figgyPudding = require('figgy-pudding') +const log = require('npmlog') +const npm = require('./npm.js') +const output = require('./utils/output.js') + +const PingConfig = figgyPudding({ + json: {}, + registry: {} +}) module.exports = ping @@ -10,18 +21,27 @@ function ping (args, silent, cb) { cb = silent silent = false } - var registry = npm.config.get('registry') - if (!registry) return cb(new Error('no default registry set')) - var auth = npm.config.getCredentialsByURI(registry) - npm.registry.ping(registry, {auth: auth}, function (er, pong, data, res) { - if (!silent) { - if (er) { - output('Ping error: ' + er) - } else { - output('Ping success: ' + JSON.stringify(pong)) + const opts = PingConfig(npmConfig()) + const registry = opts.registry + log.notice('PING', registry) + const start = Date.now() + return fetch('/-/ping?write=true', opts).then( + res => res.json().catch(() => ({})) + ).then(details => { + if (silent) { + } else { + const time = Date.now() - start + log.notice('PONG', `${time / 1000}ms`) + if (npm.config.get('json')) { + output(JSON.stringify({ + registry, + time, + details + }, null, 2)) + } else if (Object.keys(details).length) { + log.notice('PONG', `${JSON.stringify(details, null, 2)}`) } } - cb(er, er ? null : pong, data, res) - }) + }).nodeify(cb) } |