1const { cleanUrl } = require('npm-registry-fetch') 2const log = require('../utils/log-shim') 3const pingUtil = require('../utils/ping.js') 4const BaseCommand = require('../base-command.js') 5 6class Ping extends BaseCommand { 7 static description = 'Ping npm registry' 8 static params = ['registry'] 9 static name = 'ping' 10 11 async exec (args) { 12 const cleanRegistry = cleanUrl(this.npm.config.get('registry')) 13 log.notice('PING', cleanRegistry) 14 const start = Date.now() 15 const details = await pingUtil({ ...this.npm.flatOptions }) 16 const time = Date.now() - start 17 log.notice('PONG', `${time}ms`) 18 if (this.npm.config.get('json')) { 19 this.npm.output(JSON.stringify({ 20 registry: cleanRegistry, 21 time, 22 details, 23 }, null, 2)) 24 } else if (Object.keys(details).length) { 25 log.notice('PONG', `${JSON.stringify(details, null, 2)}`) 26 } 27 } 28} 29module.exports = Ping 30