@tsed/cli-core 6.4.4 → 6.6.0

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.
@@ -2,9 +2,9 @@ var NpmRegistryClient_1;
2
2
  import { __decorate } from "tslib";
3
3
  import url from "node:url";
4
4
  import { inject, Injectable } from "@tsed/di";
5
+ import registry_auth_token from "registry-auth-token";
5
6
  import registry_url from "registry-url";
6
7
  import { CliHttpClient } from "./CliHttpClient.js";
7
- const HOST = registry_url();
8
8
  const REGEX_REGISTRY_ENFORCED_HTTPS = /^https?:\/\/([^\/]+\.)?(yarnpkg\.com|npmjs\.(org|com))(\/|$)/;
9
9
  const REGEX_REGISTRY_PREFIX = /^(https?:)?\/\//i;
10
10
  export function addSuffix(pattern, suffix) {
@@ -17,18 +17,22 @@ export const SCOPE_SEPARATOR = "%2f";
17
17
  let NpmRegistryClient = NpmRegistryClient_1 = class NpmRegistryClient {
18
18
  constructor() {
19
19
  this.httpClient = inject(CliHttpClient);
20
+ this.host = registry_url();
20
21
  }
21
22
  static escapeName(name) {
22
23
  // scoped packages contain slashes and the npm registry expects them to be escaped
23
24
  return name.replace("/", SCOPE_SEPARATOR);
24
25
  }
25
26
  async request(pathname, opts = {}) {
26
- const registry = opts.registry || HOST;
27
+ const registry = opts.registry || this.host;
27
28
  const requestUrl = this.getRequestUrl(registry, pathname);
28
29
  const headers = {
29
30
  Accept: opts.unfiltered ? "application/json" : "application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*",
30
31
  ...opts.headers
31
32
  };
33
+ if (!headers.Authorization) {
34
+ this.addAuthorization(registry, headers);
35
+ }
32
36
  try {
33
37
  return await this.httpClient.get(requestUrl, {
34
38
  ...opts,
@@ -108,6 +112,12 @@ let NpmRegistryClient = NpmRegistryClient_1 = class NpmRegistryClient {
108
112
  }
109
113
  };
110
114
  }
115
+ addAuthorization(registry, headers) {
116
+ const authInfo = registry_auth_token(registry, { recursive: true });
117
+ if (authInfo) {
118
+ headers.Authorization = `${authInfo.type} ${authInfo.token}`;
119
+ }
120
+ }
111
121
  };
112
122
  NpmRegistryClient = NpmRegistryClient_1 = __decorate([
113
123
  Injectable()
@@ -243,7 +243,12 @@ let ProjectPackageJson = class ProjectPackageJson {
243
243
  const name = constant("name");
244
244
  const pkgPath = join(String(cwd), "package.json");
245
245
  const fileExists = this.fs.exists(pkgPath);
246
- if (!disableReadUpPkg && !fileExists) {
246
+ if (fileExists) {
247
+ const pkg = this.fs.readJsonSync(pkgPath, { encoding: "utf8" });
248
+ configuration().set("project.root", pkgPath);
249
+ return { ...this.getEmptyPackageJson(name), ...pkg };
250
+ }
251
+ if (!disableReadUpPkg) {
247
252
  const result = readPackageUpSync({
248
253
  cwd
249
254
  });
@@ -254,11 +259,6 @@ let ProjectPackageJson = class ProjectPackageJson {
254
259
  return { ...this.getEmptyPackageJson(name), ...pkg };
255
260
  }
256
261
  }
257
- if (disableReadUpPkg && fileExists) {
258
- const pkg = this.fs.readJsonSync(pkgPath, { encoding: "utf8" });
259
- configuration().set("project.root", pkgPath);
260
- return { ...this.getEmptyPackageJson(name), ...pkg };
261
- }
262
262
  return this.getEmptyPackageJson(name);
263
263
  }
264
264
  getEmptyPackageJson(name) {
@@ -3,6 +3,7 @@ export declare function addSuffix(pattern: string, suffix: string): string;
3
3
  export declare const SCOPE_SEPARATOR = "%2f";
4
4
  export declare class NpmRegistryClient {
5
5
  private httpClient;
6
+ private host;
6
7
  static escapeName(name: string): string;
7
8
  request(pathname: string, opts?: any): Promise<any>;
8
9
  getRequestUrl(registry: string, pathname: string): string;
@@ -20,4 +21,5 @@ export declare class NpmRegistryClient {
20
21
  }): Promise<any>;
21
22
  info(packageName: string, retry?: number): Promise<PackageInfo>;
22
23
  private fallback;
24
+ private addAuthorization;
23
25
  }
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": "6.4.4",
4
+ "version": "6.6.0",
5
5
  "type": "module",
6
6
  "main": "./lib/esm/index.js",
7
7
  "source": "./src/index.ts",
@@ -50,6 +50,7 @@
50
50
  "js-yaml": "^4.1.0",
51
51
  "listr2": "^8.2.4",
52
52
  "read-pkg-up": "^11.0.0",
53
+ "registry-auth-token": "^5.1.0",
53
54
  "registry-url": "^6.0.1",
54
55
  "rxjs": "^7.8.1",
55
56
  "semver": "^7.6.3",
@@ -61,7 +62,7 @@
61
62
  "uuid": "^10.0.0"
62
63
  },
63
64
  "devDependencies": {
64
- "@tsed/typescript": "6.4.4",
65
+ "@tsed/typescript": "6.6.0",
65
66
  "@types/commander": "2.12.2",
66
67
  "@types/figures": "3.0.1",
67
68
  "@types/fs-extra": "^11.0.4",
@@ -75,7 +76,7 @@
75
76
  "cross-env": "7.0.3",
76
77
  "deps": "^1.0.0",
77
78
  "typescript": "5.6.2",
78
- "vitest": "3.0.9"
79
+ "vitest": "3.2.4"
79
80
  },
80
81
  "peerDependencies": {
81
82
  "@tsed/core": ">=8.3.1",