Skip to content

Commit 7626abe

Browse files
Nathanael AndersonFatme
authored andcommitted
Fix TNS to be able to use alternate registries
1 parent f2bffae commit 7626abe

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

lib/definitions/libnpmconfig.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare module "libnpmconfig" {
2+
export function read(options?: Object): Object;
3+
}

lib/services/pacote-service.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@ 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";
56

67
export class PacoteService implements IPacoteService {
8+
private npmConfig: { [index: string]: any } = {};
9+
710
constructor(private $fs: IFileSystem,
811
private $injector: IInjector,
912
private $logger: ILogger,
10-
private $proxyService: IProxyService) { }
13+
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+
});
18+
}
1119

1220
@cache()
1321
public get $packageManager(): INodePackageManager {
@@ -18,6 +26,10 @@ export class PacoteService implements IPacoteService {
1826
public async manifest(packageName: string, options?: IPacoteManifestOptions): Promise<any> {
1927
this.$logger.trace(`Calling pacoteService.manifest for packageName: '${packageName}' and options: ${options}`);
2028
const manifestOptions: IPacoteBaseOptions = await this.getPacoteBaseOptions();
29+
30+
// Add NPM Configuration to our Manifest options
31+
_.extend(manifestOptions, this.npmConfig);
32+
2133
if (options) {
2234
_.extend(manifestOptions, options);
2335
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@
6161
"nativescript-dev-xcode": "0.2.0",
6262
"nativescript-doctor": "1.11.1",
6363
"nativescript-preview-sdk": "0.3.4",
64+
"libnpmconfig": "1.2.1",
6465
"open": "0.0.5",
6566
"ora": "2.0.0",
6667
"osenv": "0.1.3",
67-
"pacote": "8.1.6",
68+
"pacote": "9.5.4",
6869
"pako": "1.0.6",
6970
"pbxproj-dom": "1.2.0",
7071
"plist": "1.1.0",

0 commit comments

Comments
 (0)