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