manifest.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict'
  2. const fetchManifest = require('./lib/fetch').manifest
  3. const finalizeManifest = require('./lib/finalize-manifest')
  4. const optCheck = require('./lib/util/opt-check')
  5. const pinflight = require('promise-inflight')
  6. const npa = require('npm-package-arg')
  7. module.exports = manifest
  8. function manifest (spec, opts) {
  9. opts = optCheck(opts)
  10. spec = npa(spec, opts.where)
  11. const label = [
  12. spec.name,
  13. spec.saveSpec || spec.fetchSpec,
  14. spec.type,
  15. opts.cache,
  16. opts.registry,
  17. opts.scope
  18. ].join(':')
  19. return pinflight(label, () => {
  20. const startTime = Date.now()
  21. return fetchManifest(spec, opts).then(rawManifest => {
  22. return finalizeManifest(rawManifest, spec, opts)
  23. }).then(manifest => {
  24. if (opts.annotate) {
  25. manifest._from = spec.saveSpec || spec.raw
  26. manifest._requested = spec
  27. manifest._spec = spec.raw
  28. manifest._where = opts.where
  29. }
  30. const elapsedTime = Date.now() - startTime
  31. opts.log.silly('pacote', `${spec.type} manifest for ${spec.name}@${spec.saveSpec || spec.fetchSpec} fetched in ${elapsedTime}ms`)
  32. return manifest
  33. })
  34. })
  35. }