From 123f13cf99413f8424d30ee777600be4f30f5695 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Tue, 29 May 2018 11:03:41 -0400 Subject: [PATCH] fix(@schematics/update): support npm auth options --- packages/schematics/update/update/npm.ts | 38 +++++++++++++++++++----- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/packages/schematics/update/update/npm.ts b/packages/schematics/update/update/npm.ts index f2658f2e94..56f30d71f2 100644 --- a/packages/schematics/update/update/npm.ts +++ b/packages/schematics/update/update/npm.ts @@ -120,40 +120,62 @@ export function getNpmPackageJson( `Getting package.json from '${packageName}' (url: ${JSON.stringify(fullUrl)})...`, ); - return fullUrl.toString(); + return fullUrl; }), concatMap(fullUrl => { - let maybeRequest = npmPackageJsonCache.get(fullUrl); + let maybeRequest = npmPackageJsonCache.get(fullUrl.toString()); if (maybeRequest) { return maybeRequest; } + const registryKey = `//${fullUrl.host}/`; + return concat( getNpmConfigOption('proxy'), getNpmConfigOption('https-proxy'), getNpmConfigOption('strict-ssl'), getNpmConfigOption('cafile'), + getNpmConfigOption('_auth', registryKey, true), + getNpmConfigOption('username', registryKey, true), + getNpmConfigOption('password', registryKey, true), + getNpmConfigOption('alwaysAuth', registryKey, true), ).pipe( toArray(), concatMap(options => { + const [ + http, + https, + strictSsl, + cafile, + token, + username, + password, + alwaysAuth, + ] = options; + const subject = new ReplaySubject(1); - const sslOptions = getNpmClientSslOptions(options[2], options[3]); + const sslOptions = getNpmClientSslOptions(strictSsl, cafile); + + let auth; + if (token) { + auth = { token, alwaysAuth }; + } else if (username) { + auth = { username, password, alwaysAuth }; + } const client = new RegistryClient({ - proxy: { - http: options[0], - https: options[1], - }, + proxy: { http, https }, ssl: sslOptions, }); client.log.level = 'silent'; const params = { timeout: 30000, + auth, }; client.get( - fullUrl, + fullUrl.toString(), params, (error: object, data: NpmRepositoryPackageJson) => { if (error) {