fix: get auth info by registry URL

Ref #708
This commit is contained in:
zkochan
2017-06-21 02:04:34 +03:00
parent 79c67b519e
commit 16dcc63d81
3 changed files with 7 additions and 6 deletions

View File

@@ -31,7 +31,7 @@ export type Got = {
onProgress?: (downloaded: number, totalSize: number) => void,
integrity?: string
}): Promise<{}>,
getJSON<T>(url: string): Promise<T>,
getJSON<T>(url: string, registry: string): Promise<T>,
}
export type NpmRegistryClient = {
@@ -58,10 +58,10 @@ export default (
const limit = pLimit(opts.networkConcurrency)
async function getJSON (url: string) {
async function getJSON (url: string, registry: string) {
return limit(() => new Promise((resolve, reject) => {
const getOpts = {
auth: getCredentialsByURI(url),
auth: getCredentialsByURI(registry),
fullMetadata: false,
}
client.get(url, getOpts, (err: Error, data: Object, raw: Object, res: HttpResponse) => {
@@ -81,7 +81,7 @@ export default (
return limit(async () => {
await mkdirp(path.dirname(saveto))
const auth = getCredentialsByURI(opts.registry || url)
const auth = opts.registry && getCredentialsByURI(opts.registry)
// If a tarball is hosted on a different place than the manifest, only send
// credentials on `alwaysAuth`
const shouldAuth = auth && (

View File

@@ -110,7 +110,8 @@ async function tryResolveViaGitHubApi (
'commits',
spec.ref
].join('/')
const body = await got.getJSON<GitHubRepoResponse>(url)
// TODO: investigate what should be the correct registry path here
const body = await got.getJSON<GitHubRepoResponse>(url, url)
return body.sha
}

View File

@@ -83,7 +83,7 @@ export default async function loadPkgMetaNonCached (
async function fromRegistry (got: Got, spec: PackageSpec, registry: string) {
const uri = toUri(spec, registry)
const meta = <PackageMeta>await got.getJSON(uri)
const meta = <PackageMeta>await got.getJSON(uri, registry)
return meta
}