packument.js 822 B

1234567891011121314151617181920212223242526272829
  1. 'use strict'
  2. const fetchPackument = require('./lib/fetch').packument
  3. const optCheck = require('./lib/util/opt-check')
  4. const pinflight = require('promise-inflight')
  5. const npa = require('npm-package-arg')
  6. module.exports = packument
  7. function packument (spec, opts) {
  8. opts = optCheck(opts)
  9. spec = npa(spec, opts.where)
  10. const label = [
  11. spec.name,
  12. spec.saveSpec || spec.fetchSpec,
  13. spec.type,
  14. opts.cache,
  15. opts.registry,
  16. opts.scope
  17. ].join(':')
  18. const startTime = Date.now()
  19. return pinflight(label, () => {
  20. return fetchPackument(spec, opts)
  21. }).then(p => {
  22. const elapsedTime = Date.now() - startTime
  23. opts.log.silly('pacote', `${spec.registry ? 'registry' : spec.type} packument for ${spec.name}@${spec.saveSpec || spec.fetchSpec} fetched in ${elapsedTime}ms`)
  24. return p
  25. })
  26. }