diff --git a/lib/bootstrap.ts b/lib/bootstrap.ts index 704c759f47..2035630fc5 100644 --- a/lib/bootstrap.ts +++ b/lib/bootstrap.ts @@ -226,3 +226,5 @@ $injector.require("applePortalApplicationService", "./services/apple-portal/appl $injector.require("watchIgnoreListService", "./services/watch-ignore-list-service"); $injector.requirePublicClass("initializeService", "./services/initialize-service"); + +$injector.require("npmConfigService", "./services/npm-config-service"); diff --git a/lib/declarations.d.ts b/lib/declarations.d.ts index 97f66953ed..0932afb0bb 100644 --- a/lib/declarations.d.ts +++ b/lib/declarations.d.ts @@ -1053,4 +1053,8 @@ interface IWatchIgnoreListService { addFileToIgnoreList(filePath: string): void; removeFileFromIgnoreList(filePath: string): void; isFileInIgnoreList(filePath: string): boolean; +} + +interface INpmConfigService { + getConfig(): IDictionary; } \ No newline at end of file diff --git a/lib/definitions/libnpmconfig.d.ts b/lib/definitions/libnpmconfig.d.ts new file mode 100644 index 0000000000..63d2ea0313 --- /dev/null +++ b/lib/definitions/libnpmconfig.d.ts @@ -0,0 +1,3 @@ +declare module "libnpmconfig" { + export function read(options?: Object): Object; +} diff --git a/lib/services/npm-config-service.ts b/lib/services/npm-config-service.ts new file mode 100644 index 0000000000..134144fc4e --- /dev/null +++ b/lib/services/npm-config-service.ts @@ -0,0 +1,22 @@ +import * as npmconfig from "libnpmconfig"; + +export class NpmConfigService implements INpmConfigService { + private config: IDictionary = { }; + + constructor() { + this.readConfig(); + } + + public getConfig(): IDictionary { + return this.config; + } + + private readConfig(): void { + const data = npmconfig.read(); + data.forEach((value: any, key: string) => { + // replace env ${VARS} in strings with the process.env value + this.config[key] = typeof value !== 'string' ? value : value.replace(/\${([^}]+)}/, (_, envVar) => process.env[envVar]); + }); + } +} +$injector.register("npmConfigService", NpmConfigService); diff --git a/lib/services/pacote-service.ts b/lib/services/pacote-service.ts index 212bb706b4..7e0a7e4a0f 100644 --- a/lib/services/pacote-service.ts +++ b/lib/services/pacote-service.ts @@ -7,7 +7,9 @@ export class PacoteService implements IPacoteService { constructor(private $fs: IFileSystem, private $injector: IInjector, private $logger: ILogger, - private $proxyService: IProxyService) { } + private $npmConfigService: INpmConfigService, + private $proxyService: IProxyService) { + } @cache() public get $packageManager(): INodePackageManager { @@ -18,13 +20,16 @@ export class PacoteService implements IPacoteService { public async manifest(packageName: string, options?: IPacoteManifestOptions): Promise { this.$logger.trace(`Calling pacoteService.manifest for packageName: '${packageName}' and options: ${options}`); const manifestOptions: IPacoteBaseOptions = await this.getPacoteBaseOptions(); + if (options) { _.extend(manifestOptions, options); } packageName = this.getRealPackageName(packageName); this.$logger.trace(`Calling pacote.manifest for packageName: ${packageName} and options: ${JSON.stringify(manifestOptions, null, 2)}`); - return pacote.manifest(packageName, manifestOptions); + const result = pacote.manifest(packageName, manifestOptions); + + return result; } public async extractPackage(packageName: string, destinationDirectory: string, options?: IPacoteExtractOptions): Promise { @@ -67,7 +72,10 @@ export class PacoteService implements IPacoteService { private async getPacoteBaseOptions(): Promise { // In case `tns create myapp --template https://github.com/NativeScript/template-hello-world.git` command is executed, pacote module throws an error if cache option is not provided. const cachePath = await this.$packageManager.getCachePath(); - const pacoteOptions = { cache: cachePath }; + + // Add NPM Configuration to our Manifest options + const npmConfig = this.$npmConfigService.getConfig(); + const pacoteOptions = _.extend(npmConfig, { cache: cachePath }); const proxySettings = await this.$proxyService.getCache(); if (proxySettings) { _.extend(pacoteOptions, proxySettings); diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index fdcbdca168..84de742a47 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -420,6 +420,15 @@ "integrity": "sha512-wBlsw+8n21e6eTd4yVv8YD/E3xq0O6nNnJIquutAsFGE7EyMKz7W6RNT6BRu1SmdgmlCZ9tb0X+j+D6HGr8pZw==", "dev": true }, + "JSONStream": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.5.tgz", + "integrity": "sha512-E+iruNOY8VV9s4JEbe1aNEm6MiszPRr/UfcHMz0TQh1BXSxHK+ASV1R6W4HpjBhSeS+54PIsAMCBmwD06LLsqQ==", + "requires": { + "jsonparse": "^1.2.0", + "through": ">=2.2.7 <3" + } + }, "abbrev": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", @@ -956,15 +965,16 @@ "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==" }, "cacache": { - "version": "11.3.3", - "resolved": "https://registry.npmjs.org/cacache/-/cacache-11.3.3.tgz", - "integrity": "sha512-p8WcneCytvzPxhDvYp31PD039vi77I12W+/KfR9S8AZbaiARFBCpsPJS+9uhWfeBfeAtW7o/4vt3MUqLkbY6nA==", + "version": "12.0.3", + "resolved": "https://registry.npmjs.org/cacache/-/cacache-12.0.3.tgz", + "integrity": "sha512-kqdmfXEGFepesTuROHMs3MpFLWrPkSSpRqOw80RCflZXy/khxaArvFrQ7uJxSUduzAufc6G0g1VUCOZXxWavPw==", "requires": { "bluebird": "^3.5.5", "chownr": "^1.1.1", "figgy-pudding": "^3.5.1", "glob": "^7.1.4", "graceful-fs": "^4.1.15", + "infer-owner": "^1.0.3", "lru-cache": "^5.1.1", "mississippi": "^3.0.0", "mkdirp": "^0.5.1", @@ -1006,9 +1016,9 @@ } }, "rimraf": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", - "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", "requires": { "glob": "^7.1.3" } @@ -1426,9 +1436,9 @@ }, "dependencies": { "rimraf": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", - "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", "requires": { "glob": "^7.1.3" } @@ -2623,8 +2633,7 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true, - "optional": true + "bundled": true }, "aproba": { "version": "1.2.0", @@ -2642,13 +2651,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2661,18 +2668,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -2775,8 +2779,7 @@ }, "inherits": { "version": "2.0.3", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -2786,7 +2789,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2799,20 +2801,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.3.5", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -2829,7 +2828,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -2902,8 +2900,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -2913,7 +2910,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -2989,8 +2985,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -3020,7 +3015,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -3038,7 +3032,6 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -3077,13 +3070,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.0.3", - "bundled": true, - "optional": true + "bundled": true } } }, @@ -3176,7 +3167,8 @@ "get-stream": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", - "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=" + "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=", + "dev": true }, "get-uri": { "version": "2.0.3", @@ -3915,6 +3907,11 @@ "repeating": "^2.0.0" } }, + "infer-owner": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/infer-owner/-/infer-owner-1.0.4.tgz", + "integrity": "sha512-IClj+Xz94+d7irH5qRyfJonOdfTzuDaifE6ZPWfx0N0+/ATZCbuTPq2prFl526urkQd90WyUKIh1DfBQ2hMz9A==" + }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -3932,8 +3929,7 @@ "ini": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", - "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", - "dev": true + "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==" }, "inquirer": { "version": "6.2.0", @@ -4700,6 +4696,11 @@ "integrity": "sha1-LHS27kHZPKUbe1qu6PUDYx0lKnM=", "dev": true }, + "jsonparse": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-1.3.1.tgz", + "integrity": "sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=" + }, "jsonpointer": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-4.0.1.tgz", @@ -4763,6 +4764,26 @@ "type-check": "~0.3.2" } }, + "libnpmconfig": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/libnpmconfig/-/libnpmconfig-1.2.1.tgz", + "integrity": "sha512-9esX8rTQAHqarx6qeZqmGQKBNZR5OIbl/Ayr0qQDy3oXja2iFVQQI81R6GZ2a02bSNZ9p3YOGX1O6HHCb1X7kA==", + "requires": { + "figgy-pudding": "^3.5.1", + "find-up": "^3.0.0", + "ini": "^1.3.5" + }, + "dependencies": { + "find-up": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", + "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "requires": { + "locate-path": "^3.0.0" + } + } + } + }, "lil-uuid": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/lil-uuid/-/lil-uuid-0.1.1.tgz", @@ -4801,6 +4822,22 @@ "strip-bom": "^2.0.0" } }, + "locate-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", + "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "requires": { + "p-locate": "^3.0.0", + "path-exists": "^3.0.0" + }, + "dependencies": { + "path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=" + } + } + }, "lodash": { "version": "4.17.11", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", @@ -4995,16 +5032,16 @@ } }, "make-fetch-happen": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-4.0.1.tgz", - "integrity": "sha512-7R5ivfy9ilRJ1EMKIOziwrns9fGeAD4bAha8EB7BIiBBLHm2KeTUGCrICFt2rbHfzheTLynv50GnNTK1zDTrcQ==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-5.0.0.tgz", + "integrity": "sha512-nFr/vpL1Jc60etMVKeaLOqfGjMMb3tAHFVJWxHOFCFS04Zmd7kGlMxo0l1tzfhoQje0/UPnd0X8OeGUiXXnfPA==", "requires": { "agentkeepalive": "^3.4.1", - "cacache": "^11.0.1", + "cacache": "^12.0.0", "http-cache-semantics": "^3.8.1", "http-proxy-agent": "^2.1.0", "https-proxy-agent": "^2.2.1", - "lru-cache": "^4.1.2", + "lru-cache": "^5.1.1", "mississippi": "^3.0.0", "node-fetch-npm": "^2.0.2", "promise-retry": "^1.1.1", @@ -5020,6 +5057,14 @@ "es6-promisify": "^5.0.0" } }, + "lru-cache": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", + "integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==", + "requires": { + "yallist": "^3.0.2" + } + }, "smart-buffer": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.0.2.tgz", @@ -5042,6 +5087,11 @@ "agent-base": "~4.2.1", "socks": "~2.3.2" } + }, + "yallist": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz", + "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==" } } }, @@ -5378,9 +5428,9 @@ }, "dependencies": { "rimraf": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", - "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", "requires": { "glob": "^7.1.3" } @@ -5665,13 +5715,13 @@ "integrity": "sha512-8/JCaftHwbd//k6y2rEWp6k1wxVfpFzB6t1p825+cUb7Ym2XQfhwIC5KwhrvzZRJu+LtDE585zVaS32+CGtf0g==" }, "npm-package-arg": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/npm-package-arg/-/npm-package-arg-6.1.0.tgz", - "integrity": "sha512-zYbhP2k9DbJhA0Z3HKUePUgdB1x7MfIfKssC+WLPFMKTBZKpZh5m13PgexJjCq6KW7j17r0jHWcCpxEqnnncSA==", + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/npm-package-arg/-/npm-package-arg-6.1.1.tgz", + "integrity": "sha512-qBpssaL3IOZWi5vEKUKW0cO7kzLeT+EQO9W8RsLOZf76KF9E/K9+wH0C7t06HXPpaH8WH5xF1MExLuCwbTqRUg==", "requires": { - "hosted-git-info": "^2.6.0", + "hosted-git-info": "^2.7.1", "osenv": "^0.1.5", - "semver": "^5.5.0", + "semver": "^5.6.0", "validate-npm-package-name": "^3.0.0" }, "dependencies": { @@ -5683,13 +5733,18 @@ "os-homedir": "^1.0.0", "os-tmpdir": "^1.0.0" } + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" } } }, "npm-packlist": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-1.4.1.tgz", - "integrity": "sha512-+TcdO7HJJ8peiiYhvPxsEDhF3PJFGUGRcFsGve3vxvxdcpO2Z4Z7rkosRM0kWj6LfbK/P0gu3dzk5RU1ffvFcw==", + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-1.4.4.tgz", + "integrity": "sha512-zTLo8UcVYtDU3gdeaFu2Xu0n0EvelfHDGuqtNIn5RO7yQj4H1TqNdBc/yZjxnWA0PVB8D3Woyp0i5B43JwQ6Vw==", "requires": { "ignore-walk": "^3.0.1", "npm-bundled": "^1.0.1" @@ -5705,6 +5760,34 @@ "semver": "^5.4.1" } }, + "npm-registry-fetch": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/npm-registry-fetch/-/npm-registry-fetch-4.0.0.tgz", + "integrity": "sha512-Jllq35Jag8dtv0M17ue74XtdQTyqKzuAYGiX9mAjOhkmNjib3bBUgK6mUY61+AHnXeSRobQkpY3/xIOS/omptw==", + "requires": { + "JSONStream": "^1.3.4", + "bluebird": "^3.5.1", + "figgy-pudding": "^3.4.1", + "lru-cache": "^5.1.1", + "make-fetch-happen": "^5.0.0", + "npm-package-arg": "^6.1.0" + }, + "dependencies": { + "lru-cache": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", + "integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==", + "requires": { + "yallist": "^3.0.2" + } + }, + "yallist": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz", + "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==" + } + } + }, "npm-run-path": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-1.0.0.tgz", @@ -5938,6 +6021,22 @@ "integrity": "sha1-nJRWmJ6fZYgBewQ01WCXZ1w9oF4=", "dev": true }, + "p-limit": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.1.tgz", + "integrity": "sha512-85Tk+90UCVWvbDavCLKPOLC9vvY8OwEX/RtKF+/1OADJMVlFfEHOiMTPVyxg7mk/dKa+ipdHm0OUkTvCpMTuwg==", + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", + "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "requires": { + "p-limit": "^2.0.0" + } + }, "p-timeout": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-2.0.1.tgz", @@ -5947,6 +6046,11 @@ "p-finally": "^1.0.0" } }, + "p-try": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==" + }, "pac-proxy-agent": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/pac-proxy-agent/-/pac-proxy-agent-2.0.2.tgz", @@ -6002,37 +6106,55 @@ } }, "pacote": { - "version": "8.1.6", - "resolved": "https://registry.npmjs.org/pacote/-/pacote-8.1.6.tgz", - "integrity": "sha512-wTOOfpaAQNEQNtPEx92x9Y9kRWVu45v583XT8x2oEV2xRB74+xdqMZIeGW4uFvAyZdmSBtye+wKdyyLaT8pcmw==", + "version": "9.5.4", + "resolved": "https://registry.npmjs.org/pacote/-/pacote-9.5.4.tgz", + "integrity": "sha512-nWr0ari6E+apbdoN0hToTKZElO5h4y8DGFa2pyNA5GQIdcP0imC96bA0bbPw1gpeguVIiUgHHaAlq/6xfPp8Qw==", "requires": { - "bluebird": "^3.5.1", - "cacache": "^11.0.2", - "get-stream": "^3.0.0", - "glob": "^7.1.2", - "lru-cache": "^4.1.3", - "make-fetch-happen": "^4.0.1", + "bluebird": "^3.5.3", + "cacache": "^12.0.0", + "figgy-pudding": "^3.5.1", + "get-stream": "^4.1.0", + "glob": "^7.1.3", + "lru-cache": "^5.1.1", + "make-fetch-happen": "^5.0.0", "minimatch": "^3.0.4", - "minipass": "^2.3.3", + "minipass": "^2.3.5", "mississippi": "^3.0.0", "mkdirp": "^0.5.1", "normalize-package-data": "^2.4.0", "npm-package-arg": "^6.1.0", - "npm-packlist": "^1.1.10", - "npm-pick-manifest": "^2.1.0", + "npm-packlist": "^1.1.12", + "npm-pick-manifest": "^2.2.3", + "npm-registry-fetch": "^4.0.0", "osenv": "^0.1.5", "promise-inflight": "^1.0.1", "promise-retry": "^1.1.1", - "protoduck": "^5.0.0", + "protoduck": "^5.0.1", "rimraf": "^2.6.2", "safe-buffer": "^5.1.2", - "semver": "^5.5.0", - "ssri": "^6.0.0", - "tar": "^4.4.3", - "unique-filename": "^1.1.0", - "which": "^1.3.0" + "semver": "^5.6.0", + "ssri": "^6.0.1", + "tar": "^4.4.8", + "unique-filename": "^1.1.1", + "which": "^1.3.1" }, "dependencies": { + "get-stream": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", + "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", + "requires": { + "pump": "^3.0.0" + } + }, + "lru-cache": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", + "integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==", + "requires": { + "yallist": "^3.0.2" + } + }, "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", @@ -6051,12 +6173,36 @@ } }, "rimraf": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", - "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", "requires": { "glob": "^7.1.3" } + }, + "semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" + }, + "tar": { + "version": "4.4.10", + "resolved": "https://registry.npmjs.org/tar/-/tar-4.4.10.tgz", + "integrity": "sha512-g2SVs5QIxvo6OLp0GudTqEf05maawKUxXru104iaayWA09551tFCTI8f1Asb4lPfkBr91k07iL4c11XO3/b0tA==", + "requires": { + "chownr": "^1.1.1", + "fs-minipass": "^1.2.5", + "minipass": "^2.3.5", + "minizlib": "^1.2.1", + "mkdirp": "^0.5.0", + "safe-buffer": "^5.1.2", + "yallist": "^3.0.3" + } + }, + "yallist": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz", + "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==" } } }, diff --git a/package.json b/package.json index 868d80bbba..c87c624dd9 100644 --- a/package.json +++ b/package.json @@ -61,10 +61,11 @@ "nativescript-dev-xcode": "0.2.0", "nativescript-doctor": "1.11.1", "nativescript-preview-sdk": "0.3.4", + "libnpmconfig": "1.2.1", "open": "0.0.5", "ora": "2.0.0", "osenv": "0.1.3", - "pacote": "8.1.6", + "pacote": "9.5.4", "pako": "1.0.6", "pbxproj-dom": "1.2.0", "plist": "1.1.0", diff --git a/test/services/pacote-service.ts b/test/services/pacote-service.ts index acdbaa96b4..415b710da2 100644 --- a/test/services/pacote-service.ts +++ b/test/services/pacote-service.ts @@ -4,15 +4,17 @@ import { PacoteService } from '../../lib/services/pacote-service'; import { LoggerStub } from "../stubs"; import { sandbox, SinonSandbox, SinonStub } from "sinon"; import { EventEmitter } from "events"; +import { NpmConfigService } from "../../lib/services/npm-config-service"; + const pacote = require("pacote"); const tar = require("tar"); const path = require("path"); -const npmCachePath = "npmCachePath"; +let defaultPacoteOpts: IPacoteBaseOptions = null; +let isNpmConfigSet = false; const packageName = "testPackage"; const fullPath = `/Users/username/${packageName}`; const destinationDir = "destinationDir"; -const defaultPacoteOpts: IPacoteBaseOptions = { cache: npmCachePath }; const errorMessage = "error message"; const proxySettings: IProxySettings = { hostname: "hostname", @@ -33,13 +35,22 @@ interface ITestCase extends ITestSetup { manifestOptions?: IPacoteManifestOptions; additionalExtractOpts?: IPacoteExtractOptions; name: string; - expectedArgs: any[]; + expectedPackageName?: string; } const createTestInjector = (opts?: ITestSetup): IInjector => { opts = opts || {}; - const testInjector = new Yok(); + testInjector.register("npmConfigService", NpmConfigService); + + if (!isNpmConfigSet) { + const npmConfigService: INpmConfigService = testInjector.resolve("npmConfigService"); + defaultPacoteOpts = npmConfigService.getConfig(); + isNpmConfigSet = true; + } + + const npmCachePath = defaultPacoteOpts['cache']; + testInjector.register("logger", LoggerStub); testInjector.register("pacoteService", PacoteService); testInjector.register("fs", { @@ -102,9 +113,17 @@ describe("pacoteService", () => { const setupTest = (opts?: ITestSetup): IPacoteService => { opts = opts || {}; + const testInjector = createTestInjector(opts); + if (opts.isLocalPackage) { - sandboxInstance.stub(path, "resolve").withArgs(packageName).returns(fullPath); + const oldPath = path.resolve; + sandboxInstance.stub(path, "resolve").callsFake((value:string) => { + if (value === packageName) { + return fullPath; + } + return oldPath(value); + }); } return testInjector.resolve("pacoteService"); @@ -116,48 +135,48 @@ describe("pacoteService", () => { const testData: ITestCase[] = [ { name: "with 'cache' only when no opts are passed", - expectedArgs: [packageName, defaultPacoteOpts] + expectedPackageName: packageName, }, { name: "with 'cache' and passed options", manifestOptions, - expectedArgs: [packageName, _.extend({}, defaultPacoteOpts, manifestOptions)] + expectedPackageName: packageName, }, { name: "with 'cache' and proxy settings", useProxySettings: true, - expectedArgs: [packageName, _.extend({}, defaultPacoteOpts, proxySettings)] + expectedPackageName: packageName, }, { name: "with 'cache', passed options and proxy settings when proxy is configured", manifestOptions, useProxySettings: true, - expectedArgs: [packageName, _.extend({}, defaultPacoteOpts, manifestOptions, proxySettings)] + expectedPackageName: packageName, }, { name: "with full path to file when it is local one", isLocalPackage: true, - expectedArgs: [fullPath, defaultPacoteOpts] + expectedPackageName: fullPath, }, { name: "with full path to file, 'cache' and passed options when local path is passed", manifestOptions, isLocalPackage: true, - expectedArgs: [fullPath, _.extend({}, defaultPacoteOpts, manifestOptions)] + expectedPackageName: fullPath, }, { name: "with full path to file, 'cache' and proxy settings when proxy is configured", manifestOptions, isLocalPackage: true, useProxySettings: true, - expectedArgs: [fullPath, _.extend({}, defaultPacoteOpts, manifestOptions, proxySettings)] + expectedPackageName: fullPath, }, { name: "with full path to file, 'cache', passed options and proxy settings when proxy is configured and local path is passed", manifestOptions, useProxySettings: true, isLocalPackage: true, - expectedArgs: [fullPath, _.extend({}, defaultPacoteOpts, manifestOptions, proxySettings)] + expectedPackageName: fullPath, }, ]; @@ -166,8 +185,10 @@ describe("pacoteService", () => { const pacoteService = setupTest(testCase); const result = await pacoteService.manifest(packageName, testCase.manifestOptions); + const expectedArgs = [testCase.expectedPackageName, _.extend({}, defaultPacoteOpts, testCase.manifestOptions || {}, testCase.useProxySettings ? proxySettings : {})]; + assert.equal(result, manifestResult); - assert.deepEqual(manifestStub.firstCall.args, testCase.expectedArgs); + assert.deepEqual(manifestStub.firstCall.args, expectedArgs); }); }); }); @@ -222,11 +243,9 @@ describe("pacoteService", () => { const testData: ITestCase[] = [ { name: "when only default options should be passed", - expectedArgs: [defaultExtractOpts], }, { name: "when additional options are passed", - expectedArgs: [_.extend({}, defaultExtractOpts, additionalExtractOpts)], additionalExtractOpts }, ]; @@ -242,7 +261,9 @@ describe("pacoteService", () => { await assert.isFulfilled(pacoteExtractPackagePromise); - assert.deepEqual(tarXStub.firstCall.args, testCase.expectedArgs); + const expectedArgs = [_.extend({}, defaultExtractOpts, testCase.additionalExtractOpts || {})]; + + assert.deepEqual(tarXStub.firstCall.args, expectedArgs); }); }); }); @@ -251,23 +272,23 @@ describe("pacoteService", () => { const testData: ITestCase[] = [ { name: "when proxy is not set", - expectedArgs: [packageName, defaultPacoteOpts] + expectedPackageName: packageName, }, { name: "when proxy is not set and a local path is passed", isLocalPackage: true, - expectedArgs: [fullPath, defaultPacoteOpts] + expectedPackageName: fullPath }, { name: "when proxy is set", useProxySettings: true, - expectedArgs: [packageName, _.extend({}, defaultPacoteOpts, proxySettings)] + expectedPackageName: packageName }, { name: "when proxy is set and a local path is passed", useProxySettings: true, isLocalPackage: true, - expectedArgs: [fullPath, _.extend({}, defaultPacoteOpts, proxySettings)] + expectedPackageName: fullPath }, ]; @@ -281,8 +302,10 @@ describe("pacoteService", () => { tarExtractDestinationStream.emit("finish"); }); + const expectedArgs = [testCase.expectedPackageName, _.extend({}, defaultPacoteOpts, testCase.useProxySettings ? proxySettings : {})]; + await assert.isFulfilled(pacoteExtractPackagePromise); - assert.deepEqual(tarballStreamStub.firstCall.args, testCase.expectedArgs); + assert.deepEqual(tarballStreamStub.firstCall.args, expectedArgs); }); }); });