From 0b435300f486067364d4b41b9f351ae7a175ec2e Mon Sep 17 00:00:00 2001 From: Romain Lenzotti Date: Mon, 17 Jul 2023 12:25:49 +0200 Subject: [PATCH] fix(cli): fix issue on CLI when npm is on v9 --- .../cli-core/src/services/CliProxyAgent.ts | 28 ++++++++++++++++--- packages/cli/jest.config.js | 6 ++-- packages/cli/package.json | 13 +++++++-- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/packages/cli-core/src/services/CliProxyAgent.ts b/packages/cli-core/src/services/CliProxyAgent.ts index 4b7aaf912..b071e0178 100644 --- a/packages/cli-core/src/services/CliProxyAgent.ts +++ b/packages/cli-core/src/services/CliProxyAgent.ts @@ -4,6 +4,7 @@ import {CliExeca} from "./CliExeca"; import {camelCase} from "change-case"; import {URL} from "url"; import {coerce} from "../utils/coerce"; +import {ProjectPackageJson} from "./ProjectPackageJson"; export interface CliProxySettings { url: string; @@ -21,6 +22,9 @@ export class CliProxyAgent { @Value("proxy", {}) proxySettings: CliProxySettings; + @Inject() + protected projectPackageJson: ProjectPackageJson; + @Inject() protected cliExeca: CliExeca; @@ -61,10 +65,26 @@ export class CliProxyAgent { } const result = await Promise.all([ - this.cliExeca.getAsync("npm", ["config", "get", "proxy"]), - this.cliExeca.getAsync("npm", ["config", "get", "http-proxy"]), - this.cliExeca.getAsync("npm", ["config", "get", "https-proxy"]), - this.cliExeca.getAsync("npm", ["config", "get", "strict-ssl"]) + this.cliExeca + .getAsync("npm", ["config", "get", "proxy"], { + cwd: this.projectPackageJson.dir + }) + .catch(() => ""), + this.cliExeca + .getAsync("npm", ["config", "get", "http-proxy"], { + cwd: this.projectPackageJson.dir + }) + .catch(() => ""), + this.cliExeca + .getAsync("npm", ["config", "get", "https-proxy"], { + cwd: this.projectPackageJson.dir + }) + .catch(() => ""), + this.cliExeca + .getAsync("npm", ["config", "get", "strict-ssl"], { + cwd: this.projectPackageJson.dir + }) + .catch(() => "") ]); const [proxy, httpProxy, httpsProxy, strictSsl] = result.map(coerce); diff --git a/packages/cli/jest.config.js b/packages/cli/jest.config.js index 3ce0262e1..27e291cf8 100644 --- a/packages/cli/jest.config.js +++ b/packages/cli/jest.config.js @@ -7,10 +7,10 @@ module.exports = { coverageThreshold: { global: { - statements: 91.69, - branches: 78.62, + statements: 91.73, + branches: 79.51, functions: 76.25, - lines: 91.69 + lines: 91.73 } } }; diff --git a/packages/cli/package.json b/packages/cli/package.json index 886978853..9ef9f8021 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -63,7 +63,7 @@ "node": ">=14" }, "dependencies": { - "@tsed/cli-core": "4.6.2", + "@tsed/cli-core": ">=4.6.2", "@tsed/core": ">=7.14.2", "@tsed/di": ">=7.14.2", "@tsed/logger": ">=6.2.1", @@ -88,5 +88,12 @@ "eslint": "8.22.0", "jest": "29.5.0" }, - "peerDependencies": {} -} \ No newline at end of file + "peerDependencies": { + "@tsed/core": ">=7.14.2", + "@tsed/cli-core": ">=4.6.2", + "@tsed/di": ">=7.14.2", + "@tsed/logger": ">=6.2.1", + "@tsed/openspec": ">=7.14.2", + "@tsed/schema": ">=7.14.2" + } +}