Skip to content

Commit caeb7ba

Browse files
committed
fix(@schematics/update): use rc to find and read npm config
1 parent 914931a commit caeb7ba

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
"postcss-url": "^7.3.2",
133133
"protractor": "^5.3.1",
134134
"raw-loader": "^0.5.1",
135+
"rc": "^1.2.8",
135136
"rxjs": "^6.0.0",
136137
"sass-loader": "^7.0.2",
137138
"semver": "^5.3.0",

packages/schematics/update/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"npm-registry-client": "^8.5.1",
1919
"semver": "^5.3.0",
2020
"semver-intersect": "^1.1.2",
21+
"rc": "^1.2.8",
2122
"rxjs": "^6.0.0"
2223
}
2324
}

packages/schematics/update/update/npm.ts

+10-18
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import { logging } from '@angular-devkit/core';
9-
import { exec } from 'child_process';
109
import { readFileSync } from 'fs';
1110
import { Observable, ReplaySubject, concat, of } from 'rxjs';
1211
import { concatMap, defaultIfEmpty, filter, first, map, toArray } from 'rxjs/operators';
1312
import * as url from 'url';
1413
import { NpmRepositoryPackageJson } from './npm-package-json';
1514

1615
const RegistryClient = require('npm-registry-client');
16+
const rc = require('rc');
1717

1818
const npmPackageJsonCache = new Map<string, Observable<NpmRepositoryPackageJson>>();
1919
const npmConfigOptionCache = new Map<string, Observable<string | undefined>>();
2020

21+
22+
const npmConfig = rc('npm', {}, {});
23+
2124
function getNpmConfigOption(
2225
option: string,
2326
scope?: string,
@@ -43,26 +46,15 @@ function getNpmConfigOption(
4346

4447
const subject = new ReplaySubject<string | undefined>(1);
4548

46-
try {
47-
exec(`npm get ${fullOption}`, (error, data) => {
48-
if (error) {
49-
subject.next();
50-
} else {
51-
data = data.trim();
52-
if (!data || data === 'undefined' || data === 'null') {
53-
subject.next();
54-
} else {
55-
subject.next(data);
56-
}
57-
}
58-
59-
subject.complete();
60-
});
61-
} catch {
49+
const optionValue = npmConfig && npmConfig[fullOption];
50+
if (optionValue == undefined || optionValue == null) {
6251
subject.next();
63-
subject.complete();
52+
} else {
53+
subject.next(optionValue);
6454
}
6555

56+
subject.complete();
57+
6658
value = subject.asObservable();
6759
npmConfigOptionCache.set(fullOption, value);
6860

0 commit comments

Comments
 (0)