Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function annotateManifest (spec, manifest, opts) {
const shasum = manifest.dist && manifest.dist.shasum
manifest._integrity = manifest.dist && manifest.dist.integrity
manifest._shasum = shasum
if (!manifest._integrity && shasum) {
// Use legacy dist.shasum field if available.
manifest._integrity = ssri.fromHex(shasum, 'sha1').toString()
}
manifest._resolved = (
manifest.dist && manifest.dist.tarball
)
if (!manifest._resolved) {
const registry = fetch.pickRegistry(spec, opts)
const uri = registry.replace(/\/?$/, '/') + spec.escapedName
const err = new Error(
`Manifest for ${manifest.name}@${manifest.version} from ${uri} is missing a tarball url (pkg.dist.tarball). Guessing a default.`
)
err.code = 'ENOTARBALL'
err.manifest = manifest
if (!manifest._warnings) { manifest._warnings = [] }
manifest._warnings.push(err.message)
manifest._resolved =
`${registry}/${manifest.name}/-/${manifest.name}-${manifest.version}.tgz`
}
return manifest
}
constructor (spec, opts) {
super(spec, opts)
// try to use corgis if available
this.fullMetadata = !!opts.fullMetadata
// handle case when npm-package-arg guesses wrong.
if (this.spec.type === 'tag' &&
this.spec.rawSpec === '' &&
this.tag !== 'latest')
this.spec = npa(`${this.spec.name}@${this.tag}`)
this.registry = fetch.pickRegistry(spec, opts)
this.packumentUrl = this.registry.replace(/\/*$/, '/') +
this.spec.escapedName
// XXX pacote <=9 has some logic to ignore opts.resolved if
// the resolved URL doesn't go to the same registry.
// Consider reproducing that here, to throw away this.resolved
// in that case.
}
function tarball (spec, opts) {
opts = optCheck(opts)
const registry = fetch.pickRegistry(spec, opts)
const stream = new PassThrough()
let mani
if (
opts.resolved &&
// spec.type === 'version' &&
opts.resolved.indexOf(registry) === 0
) {
// fakeChild is a shortcut to avoid looking up a manifest!
mani = BB.resolve({
name: spec.name,
version: spec.fetchSpec,
_integrity: opts.integrity,
_resolved: opts.resolved,
_fakeChild: true
})
} else {
function packument (spec, opts) {
opts = optCheck(opts)
const registry = fetch.pickRegistry(spec, opts)
const uri = registry.replace(/\/?$/, '/') + spec.escapedName
return fetchPackument(uri, registry, spec, opts)
}
function fromManifest (manifest, spec, opts) {
opts = optCheck(opts)
if (spec.scope) { opts = opts.concat({ scope: spec.scope }) }
const stream = new PassThrough()
const registry = fetch.pickRegistry(spec, opts)
const uri = getTarballUrl(spec, registry, manifest, opts)
fetch(uri, opts.concat({
headers: {
'pacote-req-type': 'tarball',
'pacote-pkg-id': `registry:${manifest.name}@${uri}`
},
integrity: manifest._integrity,
algorithms: [
manifest._integrity
? ssri.parse(manifest._integrity).pickAlgorithm()
: 'sha1'
],
spec
}, opts))
.then(res => {
const hash = res.headers.get('x-local-cache-hash')
function packument (name, opts) {
opts = optCheck(opts)
const registry = fetch.pickRegistry(name, opts)
const uri = registry.replace(/\/?$/, `/${name.replace(/[/]/g, '%2f')}`)
return fetchPackument(uri, name, registry, opts)
}