ping.js 873 B

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