Skip to content

Commit 781f373

Browse files
committed
fix: fix PR comments
1 parent 79bd4da commit 781f373

File tree

6 files changed

+295
-124
lines changed

6 files changed

+295
-124
lines changed

lib/bootstrap.ts

+2
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,5 @@ $injector.require("applePortalApplicationService", "./services/apple-portal/appl
226226
$injector.require("watchIgnoreListService", "./services/watch-ignore-list-service");
227227

228228
$injector.requirePublicClass("initializeService", "./services/initialize-service");
229+
230+
$injector.require("npmConfigService", "./services/npm-config-service");

lib/declarations.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1053,4 +1053,8 @@ interface IWatchIgnoreListService {
10531053
addFileToIgnoreList(filePath: string): void;
10541054
removeFileFromIgnoreList(filePath: string): void;
10551055
isFileInIgnoreList(filePath: string): boolean;
1056+
}
1057+
1058+
interface INpmConfigService {
1059+
getConfig(): IDictionary<any>;
10561060
}

lib/services/npm-config-service.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as npmconfig from "libnpmconfig";
2+
3+
export class NpmConfigService implements INpmConfigService {
4+
private config: IDictionary<any> = { };
5+
6+
constructor() {
7+
this.readConfig();
8+
}
9+
10+
public getConfig(): IDictionary<any> {
11+
return this.config;
12+
}
13+
14+
private readConfig(): void {
15+
const data = npmconfig.read();
16+
data.forEach((value: any, key: string) => {
17+
// replace env ${VARS} in strings with the process.env value
18+
this.config[key] = typeof value !== 'string' ? value : value.replace(/\${([^}]+)}/, (_, envVar) => process.env[envVar]);
19+
});
20+
}
21+
}
22+
$injector.register("npmConfigService", NpmConfigService);

lib/services/pacote-service.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,13 @@ import * as pacote from "pacote";
22
import * as tar from "tar";
33
import * as path from "path";
44
import { cache } from "../common/decorators";
5-
import * as npmconfig from "libnpmconfig";
65

76
export class PacoteService implements IPacoteService {
8-
private npmConfig: { [index: string]: any } = {};
9-
107
constructor(private $fs: IFileSystem,
118
private $injector: IInjector,
129
private $logger: ILogger,
10+
private $npmConfigService: INpmConfigService,
1311
private $proxyService: IProxyService) {
14-
npmconfig.read().forEach((value: any, key: string) => {
15-
// replace env ${VARS} in strings with the process.env value
16-
this.npmConfig[key] = typeof value !== 'string' ? value : value.replace(/\${([^}]+)}/, (_, envVar) => process.env[envVar] );
17-
});
1812
}
1913

2014
@cache()
@@ -33,7 +27,9 @@ export class PacoteService implements IPacoteService {
3327

3428
packageName = this.getRealPackageName(packageName);
3529
this.$logger.trace(`Calling pacote.manifest for packageName: ${packageName} and options: ${JSON.stringify(manifestOptions, null, 2)}`);
36-
return pacote.manifest(packageName, manifestOptions);
30+
const result = pacote.manifest(packageName, manifestOptions);
31+
32+
return result;
3733
}
3834

3935
public async extractPackage(packageName: string, destinationDirectory: string, options?: IPacoteExtractOptions): Promise<void> {
@@ -78,7 +74,8 @@ export class PacoteService implements IPacoteService {
7874
const cachePath = await this.$packageManager.getCachePath();
7975

8076
// Add NPM Configuration to our Manifest options
81-
const pacoteOptions = _.extend( this.npmConfig, {cache: cachePath });
77+
const npmConfig = this.$npmConfigService.getConfig();
78+
const pacoteOptions = _.extend(npmConfig, { cache: cachePath });
8279
const proxySettings = await this.$proxyService.getCache();
8380
if (proxySettings) {
8481
_.extend(pacoteOptions, proxySettings);

0 commit comments

Comments
 (0)