2024-04-11 18:24:57 -07:00
|
|
|
const { redact } = require('@npmcli/redact')
|
2024-04-30 23:53:22 -07:00
|
|
|
const { log, output } = require('proc-log')
|
2021-11-04 20:42:47 +00:00
|
|
|
const pingUtil = require('../utils/ping.js')
|
2024-04-30 23:53:22 -07:00
|
|
|
const BaseCommand = require('../base-cmd.js')
|
2019-01-29 14:43:00 -08:00
|
|
|
|
2021-03-11 17:54:23 -05:00
|
|
|
class Ping extends BaseCommand {
|
2021-11-18 20:58:02 +00:00
|
|
|
static description = 'Ping npm registry'
|
|
|
|
static params = ['registry']
|
|
|
|
static name = 'ping'
|
2015-07-09 20:48:26 -07:00
|
|
|
|
2024-04-30 23:53:22 -07:00
|
|
|
async exec () {
|
2024-04-11 18:24:57 -07:00
|
|
|
const cleanRegistry = redact(this.npm.config.get('registry'))
|
2023-01-16 22:38:23 -05:00
|
|
|
log.notice('PING', cleanRegistry)
|
2021-03-04 17:40:28 -05:00
|
|
|
const start = Date.now()
|
2022-02-24 21:41:49 +00:00
|
|
|
const details = await pingUtil({ ...this.npm.flatOptions })
|
2021-03-04 17:40:28 -05:00
|
|
|
const time = Date.now() - start
|
2021-07-01 17:32:45 +00:00
|
|
|
log.notice('PONG', `${time}ms`)
|
2021-03-23 14:58:11 -04:00
|
|
|
if (this.npm.config.get('json')) {
|
2024-05-30 04:21:05 -07:00
|
|
|
output.buffer({
|
2023-01-16 22:38:23 -05:00
|
|
|
registry: cleanRegistry,
|
2021-03-04 17:40:28 -05:00
|
|
|
time,
|
|
|
|
details,
|
2024-05-30 04:21:05 -07:00
|
|
|
})
|
2021-11-18 20:58:02 +00:00
|
|
|
} else if (Object.keys(details).length) {
|
2024-04-30 23:53:22 -07:00
|
|
|
log.notice('PONG', JSON.stringify(details, null, 2))
|
2021-11-18 20:58:02 +00:00
|
|
|
}
|
2021-03-04 17:40:28 -05:00
|
|
|
}
|
|
|
|
}
|
2024-04-30 23:53:22 -07:00
|
|
|
|
2021-03-04 17:40:28 -05:00
|
|
|
module.exports = Ping
|