How to use the @pnpm/fetch function in @pnpm/fetch

To help you get started, we’ve selected a few @pnpm/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 pnpm / pnpm / packages / server / src / connectStoreController.ts View on Github external
return limit(async () => {
    // TODO: the http://unix: should be also supported by the fetcher
    // but it fails with node-fetch-unix as of v2.3.0
    if (url.startsWith('http://unix:')) {
      url = url.replace('http://unix:', 'unix:')
    }
    const response = await fetch(url, {
      body: JSON.stringify(body),
      headers: { 'Content-Type': 'application/json' },
      method: 'POST',
      retry: {
        retries: 100,
      },
    })
    if (!response.ok) {
      throw await response.json()
    }
    const json = await response.json()
    if (json.error) {
      throw json.error
    }
    return json as T
  })
github pnpm / pnpm / packages / git-resolver / src / parsePref.ts View on Github external
} catch (e) {
      // ignore
    }
  }

  if (!fetchSpec) {
    const httpsUrl = hosted.https({ noGitPlus: true, noCommittish: true })
    if (httpsUrl) {
      try {
        // when git ls-remote private repo, it asks for login credentials.
        // use HTTP HEAD request to test whether this is a private repo, to avoid login prompt.
        // this is very similar to yarn's behaviour.
        // npm instead tries git ls-remote directly which prompts user for login credentials.

        // HTTP HEAD on https://domain/user/repo, strip out ".git"
        const response = await fetch(httpsUrl.substr(0, httpsUrl.length - 4), { method: 'HEAD', follow: 0 })
        if (response.ok) {
          fetchSpec = httpsUrl
        }
      } catch (e) {
        // ignore
      }
    }
  }

  if (!fetchSpec) {
    // use ssh url for likely private repo
    fetchSpec = hosted.sshurl({ noCommittish: true })
  }

  return {
    fetchSpec: fetchSpec!,

@pnpm/fetch

node-fetch with retries

MIT
Latest version published 7 days ago

Package Health Score

66 / 100
Full package analysis

Popular @pnpm/fetch functions