How to use npm-registry-fetch - 10 common examples

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 callstack / haul / packages / haul-cli / src / commands / init.ts View on Github external
async function getAvailableHaulPreset(
  progress: Ora,
  targetHaulPreset: string
): Promise<string> {
  // Stop searching on 0.59 - there's no preset below 0.59.
  if (targetHaulPreset.includes('0.59')) {
    return targetHaulPreset;
  }

  try {
    await npmFetch(targetHaulPreset);
    return targetHaulPreset;
  } catch (error) {
    if (error.statusCode === 404) {
      progress.info(
        `${targetHaulPreset} not available. Trying older version...`
      );
      const previousHaulPreset = targetHaulPreset.replace(/-0\.\d+$/, match => {
        const [major, minor] = match.slice(1).split('.');
        return `-${major}.${parseInt(minor, 10) - 1}`;
      });
      return await getAvailableHaulPreset(progress, previousHaulPreset);
    }

    return targetHaulPreset;
  }
}
github graalvm / graaljs / deps / npm / lib / unpublish.js View on Github external
return libaccess.lsPackages(username, opts).then(access => {
      // do a bit of filtering at this point, so that we don't need
      // to fetch versions for more than one thing, but also don't
      // accidentally a whole project.
      let pkgs = Object.keys(access)
      if (!cliOpts.partialWord || !pkgs.length) { return pkgs }
      const pp = npa(cliOpts.partialWord).name
      pkgs = pkgs.filter(p => !p.indexOf(pp))
      if (pkgs.length > 1) return pkgs
      return npmFetch.json(npa(pkgs[0]).escapedName, opts).then(doc => {
        const vers = Object.keys(doc.versions)
        if (!vers.length) {
          return pkgs
        } else {
          return vers.map(v => `${pkgs[0]}@${v}`)
        }
      })
    })
  }).nodeify(cb)
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 / npm-profile / lib / index.js View on Github external
const body = {
    _id: 'org.couchdb.user:' + username,
    name: username,
    password: password,
    type: 'user',
    roles: [],
    date: new Date().toISOString()
  }
  const logObj = {}
  Object.keys(body).forEach(k => {
    logObj[k] = k === 'password' ? 'XXXXX' : body[k]
  })
  process.emit('log', 'verbose', 'login', 'before first PUT', logObj)

  const target = '-/user/org.couchdb.user:' + encodeURIComponent(username)
  return fetch.json(target, opts.concat({
    method: 'PUT',
    body
  })).catch(err => {
    if (err.code === 'E400') {
      err.message = `There is no user with the username "${username}".`
      throw err
    }
    if (err.code !== 'E409') throw err
    return fetch.json(target, opts.concat({
      query: {write: true}
    })).then(result => {
      Object.keys(result).forEach(function (k) {
        if (!body[k] || k === 'roles') {
          body[k] = result[k]
        }
      })
github npm / npm-profile / lib / index.js View on Github external
_id: 'org.couchdb.user:' + username,
    name: username,
    password: password,
    email: email,
    type: 'user',
    roles: [],
    date: new Date().toISOString()
  }
  const logObj = {}
  Object.keys(body).forEach(k => {
    logObj[k] = k === 'password' ? 'XXXXX' : body[k]
  })
  process.emit('log', 'verbose', 'adduser', 'before first PUT', logObj)

  const target = '/-/user/org.couchdb.user:' + encodeURIComponent(username)
  return fetch.json(target, opts.concat({
    method: 'PUT',
    body
  })).then(result => {
    result.username = username
    return result
  })
}
github graalvm / graaljs / graal-nodejs / deps / npm / node_modules / libnpmorg / index.js View on Github external
return new opts.Promise((resolve, reject) => {
    validate('SSSO|SSZO', [org, user, role, opts])
    user = user.replace(/^@?/, '')
    org = org.replace(/^@?/, '')
    fetch.json(`/-/org/${eu(org)}/user`, opts.concat({
      method: 'PUT',
      body: { user, role }
    })).then(resolve, reject)
  }).then(ret => Object.assign(new MembershipDetail(), ret))
}
github npm / npm-profile / lib / index.js View on Github external
function get (opts) {
  validate('O', arguments)
  return fetch.json('/-/npm/v1/user', opts)
}
github npm / libnpmhook / index.js View on Github external
cmd.find = (id, opts) => {
  opts = HooksConfig(opts)
  validate('SO', [id, opts])
  return fetch.json(`/-/npm/v1/hooks/hook/${eu(id)}`, opts)
}

npm-registry-fetch

Fetch-based http client for use with npm registry APIs

ISC
Latest version published 1 month ago

Package Health Score

92 / 100
Full package analysis