How to use the npm-registry-fetch.pickRegistry function in npm-registry-fetch

To help you get started, we’ve selected a few npm-registry-fetch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github npm / pacote / lib / fetchers / registry / manifest.js View on Github external
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
}
github npm / pacote / lib / registry.js View on Github external
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.
  }
github npm / pacote / lib / fetchers / registry / tarball.js View on Github external
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 {
github npm / pacote / lib / fetchers / registry / packument.js View on Github external
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)
}
github npm / pacote / lib / fetchers / registry / tarball.js View on Github external
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')
github npm / proxy-registry / fetch-packument.js View on Github external
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)
}

npm-registry-fetch

Fetch-based http client for use with npm registry APIs

ISC
Latest version published 2 months ago

Package Health Score

92 / 100
Full package analysis