@tsed/cli-core 7.5.0-rc.2 → 7.5.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -81,7 +81,6 @@ export class CliCore {
81
81
  try {
82
82
  const cliService = inject(CliService);
83
83
  constant("plugins") && (await loadPlugins());
84
- await $asyncEmit("$beforeInit");
85
84
  await injector().load();
86
85
  await $asyncEmit("$afterInit");
87
86
  injector().settings.set("loaded", true);
@@ -9,39 +9,38 @@ export class CliHttpClient extends CliHttpLogClient {
9
9
  constructor() {
10
10
  super(...arguments);
11
11
  this.cliProxyAgent = inject(CliProxyAgent);
12
+ this.proxySettingsInitialized = false;
12
13
  }
13
14
  static getParamsSerializer(params) {
14
15
  return stringify(cleanObject(params));
15
16
  }
16
- async $afterInit() {
17
- await this.cliProxyAgent.resolveProxySettings();
18
- }
19
17
  async head(endpoint, options = {}) {
20
- const { headers } = await axios(this.getRequestParameters("HEAD", endpoint, options));
18
+ const { headers } = await axios(await this.getRequestParameters("HEAD", endpoint, options));
21
19
  return headers;
22
20
  }
23
21
  async get(endpoint, options = {}) {
24
- const result = await this.send(this.getRequestParameters("GET", endpoint, options));
22
+ const result = await this.send(await this.getRequestParameters("GET", endpoint, options));
25
23
  return this.mapResponse(result, options);
26
24
  }
27
25
  async post(endpoint, options = {}) {
28
- const result = await this.send(this.getRequestParameters("POST", endpoint, options));
26
+ const result = await this.send(await this.getRequestParameters("POST", endpoint, options));
29
27
  return this.mapResponse(result, options);
30
28
  }
31
29
  async put(endpoint, options = {}) {
32
- const result = await this.send(this.getRequestParameters("PUT", endpoint, options));
30
+ const result = await this.send(await this.getRequestParameters("PUT", endpoint, options));
33
31
  return this.mapResponse(result, options);
34
32
  }
35
33
  async patch(endpoint, options = {}) {
36
- const result = await this.send(this.getRequestParameters("PATCH", endpoint, options));
34
+ const result = await this.send(await this.getRequestParameters("PATCH", endpoint, options));
37
35
  return this.mapResponse(result, options);
38
36
  }
39
37
  async delete(endpoint, options = {}) {
40
- const result = await this.send(this.getRequestParameters("DELETE", endpoint, options));
38
+ const result = await this.send(await this.getRequestParameters("DELETE", endpoint, options));
41
39
  return this.mapResponse(result, options);
42
40
  }
43
- getRequestParameters(method, endpoint, options) {
41
+ async getRequestParameters(method, endpoint, options) {
44
42
  const url = (this.host || "") + endpoint.replace(this.host || "", "");
43
+ await this.resolveProxySettingsOnce();
45
44
  options = {
46
45
  method,
47
46
  ...options,
@@ -54,20 +53,36 @@ export class CliHttpClient extends CliHttpLogClient {
54
53
  ...(options.headers || {})
55
54
  }
56
55
  };
57
- this.configureProxy(url, options);
56
+ await this.configureProxy(url, options);
58
57
  return options;
59
58
  }
60
- configureProxy(endpoint, options) {
59
+ async resolveProxySettingsOnce() {
60
+ if (this.proxySettingsInitialized) {
61
+ return;
62
+ }
63
+ if (!this.proxySettingsPromise) {
64
+ this.proxySettingsPromise = this.cliProxyAgent
65
+ .resolveProxySettings()
66
+ .catch(() => {
67
+ return;
68
+ })
69
+ .finally(() => {
70
+ this.proxySettingsInitialized = true;
71
+ });
72
+ }
73
+ await this.proxySettingsPromise;
74
+ }
75
+ async configureProxy(endpoint, options) {
61
76
  const url = new URL(endpoint);
62
77
  if (this.cliProxyAgent.hasProxy()) {
63
78
  const protocol = url.protocol.replace(":", "");
64
79
  switch (protocol) {
65
80
  case "https":
66
- options.httpsAgent = this.cliProxyAgent.get(protocol);
81
+ options.httpsAgent = await this.cliProxyAgent.get(protocol);
67
82
  options.proxy = false;
68
83
  break;
69
84
  case "http":
70
- options.httpAgent = this.cliProxyAgent.get(protocol);
85
+ options.httpAgent = await this.cliProxyAgent.get(protocol);
71
86
  options.proxy = false;
72
87
  break;
73
88
  default:
@@ -10,14 +10,12 @@ export class CliProxyAgent {
10
10
  this.projectPackageJson = inject(ProjectPackageJson);
11
11
  this.cliExeca = inject(CliExeca);
12
12
  }
13
- async $onInit() {
14
- this.tunnel = await import("tunnel");
15
- }
16
13
  hasProxy() {
17
14
  return !!this.proxySettings.value.url;
18
15
  }
19
- get(type) {
16
+ async get(type) {
20
17
  if (this.hasProxy()) {
18
+ const tunnel = await import("tunnel");
21
19
  const { strictSsl = true } = this.proxySettings.value;
22
20
  const url = new URL(this.proxySettings.value.url);
23
21
  const protocol = url.protocol.replace(":", "");
@@ -30,8 +28,8 @@ export class CliProxyAgent {
30
28
  }
31
29
  };
32
30
  const method = camelCase([type, "over", protocol].join(" "));
33
- if (this.tunnel[method]) {
34
- return this.tunnel[method](options);
31
+ if (tunnel[method]) {
32
+ return tunnel[method](options);
35
33
  }
36
34
  }
37
35
  return null;
@@ -8,16 +8,18 @@ export interface CliHttpClientOptions extends AxiosRequestConfig, Record<string,
8
8
  export declare class CliHttpClient extends CliHttpLogClient {
9
9
  protected cliProxyAgent: CliProxyAgent;
10
10
  protected host: string;
11
+ private proxySettingsInitialized;
12
+ private proxySettingsPromise?;
11
13
  static getParamsSerializer(params: any): string;
12
- $afterInit(): Promise<void>;
13
14
  head<T = Record<string, any>>(endpoint: string, options?: CliHttpClientOptions): Promise<T>;
14
15
  get<T = unknown>(endpoint: string, options?: CliHttpClientOptions): Promise<T>;
15
16
  post<T = unknown>(endpoint: string, options?: CliHttpClientOptions): Promise<T>;
16
17
  put<T = any>(endpoint: string, options?: CliHttpClientOptions): Promise<T>;
17
18
  patch<T = any>(endpoint: string, options?: CliHttpClientOptions): Promise<T>;
18
19
  delete<T = any>(endpoint: string, options?: CliHttpClientOptions): Promise<T>;
19
- protected getRequestParameters(method: Method, endpoint: string, options: CliHttpClientOptions): CliHttpClientOptions;
20
- protected configureProxy(endpoint: string, options: CliHttpClientOptions): void;
20
+ protected getRequestParameters(method: Method, endpoint: string, options: CliHttpClientOptions): Promise<CliHttpClientOptions>;
21
+ private resolveProxySettingsOnce;
22
+ protected configureProxy(endpoint: string, options: CliHttpClientOptions): Promise<void>;
21
23
  protected send(options: AxiosRequestConfig): Promise<import("axios").AxiosResponse<any, any, {}>>;
22
24
  protected mapResponse(result: any, options: CliHttpClientOptions): any;
23
25
  }
@@ -10,9 +10,7 @@ export declare class CliProxyAgent {
10
10
  };
11
11
  protected projectPackageJson: ProjectPackageJson;
12
12
  protected cliExeca: CliExeca;
13
- protected tunnel: typeof import("tunnel");
14
- $onInit(): Promise<void>;
15
13
  hasProxy(): boolean;
16
- get(type: "http" | "https"): any;
14
+ get(type: "http" | "https"): Promise<any>;
17
15
  resolveProxySettings(): Promise<void>;
18
16
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tsed/cli-core",
3
3
  "description": "Build your CLI with TypeScript and Decorators",
4
- "version": "7.5.0-rc.2",
4
+ "version": "7.5.0-rc.3",
5
5
  "type": "module",
6
6
  "main": "./lib/esm/index.js",
7
7
  "source": "./src/index.ts",
@@ -33,8 +33,8 @@
33
33
  ],
34
34
  "dependencies": {
35
35
  "@ts-morph/common": "0.28.0",
36
- "@tsed/cli-prompts": "7.5.0-rc.2",
37
- "@tsed/cli-tasks": "7.5.0-rc.2",
36
+ "@tsed/cli-prompts": "7.5.0-rc.3",
37
+ "@tsed/cli-tasks": "7.5.0-rc.3",
38
38
  "@tsed/logger": ">=8.0.3",
39
39
  "@tsed/logger-pattern-layout": ">=8.0.3",
40
40
  "@tsed/logger-std": ">=8.0.3",
@@ -62,7 +62,7 @@
62
62
  "uuid": "^10.0.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@tsed/typescript": "7.5.0-rc.2",
65
+ "@tsed/typescript": "7.5.0-rc.3",
66
66
  "@types/commander": "2.12.2",
67
67
  "@types/figures": "3.0.1",
68
68
  "@types/fs-extra": "^11.0.4",