fix: installation of private packages

This commit is contained in:
zkochan
2016-10-19 22:49:51 +03:00
parent 74be048f7b
commit d027155c84
2 changed files with 25 additions and 10 deletions

View File

@@ -51,7 +51,7 @@
"promisequence": "1.1.6",
"rc": "1.1.6",
"read-pkg-up": "1.0.1",
"registry-auth-token": "3.0.1",
"registry-auth-token": "3.1.0",
"registry-url": "3.1.0",
"retry": "0.10.0",
"rimraf-then": "1.0.0",

View File

@@ -1,12 +1,15 @@
import {IncomingMessage} from 'http'
import pauseStream = require('pause-stream')
import getAuthToken = require('registry-auth-token')
import getRegistryAuthInfo = require('registry-auth-token')
import createCache from './createCache'
import memoize = require('lodash.memoize')
export type RequestParams = {
headers?: {
authorization: string
auth?: {
token: string
} | {
username: string,
password: string
}
}
@@ -69,12 +72,24 @@ export default (client: NpmRegistryClient, opts: {cachePath: string, cacheTTL: n
}
function createOptions (url: string): RequestParams {
const authToken = getAuthToken(url, {recursive: true})
if (!authToken) return {}
return {
headers: {
authorization: `${authToken.type} ${authToken.token}`
}
const authInfo = getRegistryAuthInfo(url, {recursive: true})
if (!authInfo) return {}
switch (authInfo.type) {
case 'Bearer':
return {
auth: {
token: authInfo.token
}
}
case 'Basic':
return {
auth: {
username: authInfo.username,
password: authInfo.password
}
}
default:
throw new Error(`Unsupported authorization type '${authInfo.type}'`)
}
}