Skip to content
This repository has been archived by the owner on Apr 9, 2022. It is now read-only.

Commit

Permalink
fix(@schematics/update): support npm auth options
Browse files Browse the repository at this point in the history
  • Loading branch information
clydin authored and hansl committed May 30, 2018
1 parent 49808ea commit 3cf0aec
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions packages/schematics/update/update/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NpmRepositoryPackageJson>(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) {
Expand Down

0 comments on commit 3cf0aec

Please sign in to comment.