UNPKG

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