Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tsed 8 beta #415

Merged
merged 6 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"packages": [
"packages/*"
],
"version": "6.0.0-alpha.10"
}
"version": "6.0.0-beta.1"
}
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tsed/cli-root",
"version": "6.0.0-alpha.10",
"version": "6.0.0-beta.1",
"description": "CLI to bootstrap your Ts.ED project",
"private": true,
"type": "module",
Expand Down Expand Up @@ -44,12 +44,12 @@
},
"homepage": "https://github.com/tsedio/tsed-cli",
"dependencies": {
"@tsed/core": ">=7.83.3",
"@tsed/di": ">=7.83.3",
"@tsed/core": ">=8.0.0-beta.2",
"@tsed/di": ">=8.0.0-beta.2",
"@tsed/logger": ">=6.2.1",
"@tsed/normalize-path": ">=7.83.3",
"@tsed/openspec": ">=7.83.3",
"@tsed/schema": ">=7.83.3",
"@tsed/normalize-path": ">=8.0.0-beta.2",
"@tsed/openspec": ">=8.0.0-beta.2",
"@tsed/schema": ">=8.0.0-beta.2",
"axios": "^1.7.7",
"chalk": "^5.3.0",
"commander": "^12.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/barrels/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/barrels",
"description": "A simple tool to generate barrels for your TypeScript project",
"version": "6.0.0-alpha.10",
"version": "6.0.0-beta.1",
"type": "module",
"bin": "bin/barrels.js",
"keywords": [
Expand Down
6 changes: 3 additions & 3 deletions packages/cli-core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tsed/cli-core",
"description": "Build your CLI with TypeScript and Decorators",
"version": "6.0.0-alpha.10",
"version": "6.0.0-beta.1",
"type": "module",
"main": "./lib/esm/index.js",
"source": "./src/index.ts",
Expand Down Expand Up @@ -83,7 +83,7 @@
"vitest": "2.1.1"
},
"peerDependencies": {
"@tsed/core": ">=7.14.2",
"@tsed/di": ">=7.14.2"
"@tsed/core": ">=8.0.0-beta.2",
"@tsed/di": ">=8.0.0-beta.2"
}
}
11 changes: 4 additions & 7 deletions packages/cli-core/src/CliCore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Type} from "@tsed/core";
import {Inject, InjectorService, Module} from "@tsed/di";
import {inject, InjectorService, Module} from "@tsed/di";
import chalk from "chalk";
import {Command} from "commander";
import {join, resolve} from "path";
Expand All @@ -23,11 +23,8 @@ function isHelpManual(argv: string[]) {
imports: [CliPackageJson, ProjectPackageJson, CliService, CliConfiguration]
})
export class CliCore {
@Inject()
readonly injector: InjectorService;

@Inject()
readonly cliService: CliService;
readonly injector = inject(InjectorService);
readonly cliService = inject(CliService);

static checkNodeVersion(wanted: string, id: string) {
if (!semver.satisfies(process.version, wanted)) {
Expand All @@ -53,7 +50,7 @@ export class CliCore {

const injector = this.createInjector(settings);

settings.plugins && (await loadPlugins(injector));
settings.plugins && (await loadPlugins());

await this.loadInjector(injector, module);

Expand Down
13 changes: 4 additions & 9 deletions packages/cli-core/src/services/CliDockerComposeYaml.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {setValue} from "@tsed/core";
import {Inject, Injectable} from "@tsed/di";
import {inject, Injectable} from "@tsed/di";
import {snakeCase} from "change-case";
import {join} from "path";

Expand All @@ -9,14 +9,9 @@ import {ProjectPackageJson} from "./ProjectPackageJson.js";

@Injectable()
export class CliDockerComposeYaml {
@Inject()
protected cliYaml: CliYaml;

@Inject()
protected fs: CliFs;

@Inject()
protected projectPackageJson: ProjectPackageJson;
protected cliYaml = inject(CliYaml);
protected fs = inject(CliFs);
protected projectPackageJson = inject(ProjectPackageJson);

read() {
const path = "docker-compose.yml";
Expand Down
10 changes: 4 additions & 6 deletions packages/cli-core/src/services/CliHooks.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import {Inject, Injectable, InjectorService} from "@tsed/di";
import {Injectable, injector} from "@tsed/di";

@Injectable()
export class CliHooks {
@Inject()
injector: InjectorService;

async emit(hookName: string, cmd: string, ...args: any[]) {
const providers = this.injector.getProviders();
const inj = injector();
const providers = inj.getProviders();
let results: any = [];

for (const provider of providers) {
if (provider.useClass) {
const instance: any = this.injector.get(provider.token)!;
const instance: any = inj.get(provider.token)!;

if (provider.store.has(hookName)) {
const props = provider.store.get(hookName)[cmd];
Expand Down
5 changes: 2 additions & 3 deletions packages/cli-core/src/services/CliHttpClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {cleanObject} from "@tsed/core";
import {Inject, Injectable} from "@tsed/di";
import {inject, Injectable} from "@tsed/di";
import axios, {type AxiosRequestConfig, type Method} from "axios";
import {stringify} from "querystring";
import {URL} from "url";
Expand All @@ -14,8 +14,7 @@ export interface CliHttpClientOptions extends AxiosRequestConfig, Record<string,

@Injectable()
export class CliHttpClient extends CliHttpLogClient {
@Inject()
protected cliProxyAgent: CliProxyAgent;
protected cliProxyAgent = inject(CliProxyAgent);

protected host: string;

Expand Down
6 changes: 2 additions & 4 deletions packages/cli-core/src/services/CliHttpLogClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {getValue} from "@tsed/core";
import {Inject, Opts} from "@tsed/di";
import {inject, Opts} from "@tsed/di";
import {Logger} from "@tsed/logger";
import querystring from "querystring";

Expand All @@ -11,9 +11,7 @@ export interface BaseLogClientOptions {

export class CliHttpLogClient {
callee: string;

@Inject()
protected logger: Logger;
protected logger = inject(Logger);

// @ts-ignore
constructor(@Opts options: Partial<BaseLogClientOptions> = {}) {
Expand Down
9 changes: 3 additions & 6 deletions packages/cli-core/src/services/CliLoadFile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Inject, Injectable} from "@tsed/di";
import {inject, Injectable} from "@tsed/di";
import {default as Ajv, type Schema} from "ajv";
import {extname} from "path";

Expand All @@ -7,11 +7,8 @@ import {CliYaml} from "./CliYaml.js";

@Injectable()
export class CliLoadFile {
@Inject()
protected cliYaml: CliYaml;

@Inject()
protected cliFs: CliFs;
protected cliYaml: CliYaml = inject(CliYaml);
protected cliFs = inject(CliFs);

// @ts-ignore
#ajv: Ajv;
Expand Down
8 changes: 6 additions & 2 deletions packages/cli-core/src/services/CliPackageJson.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import {Configuration, Inject, registerProvider} from "@tsed/di";
import {Configuration, Inject, inject, registerProvider} from "@tsed/di";

import {type PackageJson} from "../interfaces/PackageJson.js";

export type CliPackageJson = PackageJson;

export function CliPackageJson() {
export function CliPackageJson(): any {
return Inject(CliPackageJson);
}

export function cliPackageJson() {
return inject<PackageJson>(CliPackageJson);
}

registerProvider({
provide: CliPackageJson,
deps: [Configuration],
Expand Down
29 changes: 7 additions & 22 deletions packages/cli-core/src/services/CliPlugins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Constant, Inject, Injectable, InjectorService} from "@tsed/di";
import {constant, inject, Injectable} from "@tsed/di";
import chalk from "chalk";

import {CommandStoreKeys} from "../domains/CommandStoreKeys.js";
Expand All @@ -20,34 +20,19 @@ function mapPlugins({package: {name, description = "", ...otherProps}}: any) {

@Injectable()
export class CliPlugins {
@Constant("name")
name: string;

@Inject(NpmRegistryClient)
private npmRegistryClient: NpmRegistryClient;

@Inject(InjectorService)
private injector: InjectorService;

@Inject(CliHooks)
private cliHooks: CliHooks;

@Inject(ProjectPackageJson)
private packageJson: ProjectPackageJson;

@Inject(PackageManagersModule)
private packageManagers: PackageManagersModule;
name = constant<string>("name", "");
readonly loadPlugins = loadPlugins;
private npmRegistryClient = inject(NpmRegistryClient);
private cliHooks = inject(CliHooks);
private packageJson = inject(ProjectPackageJson);
private packageManagers = inject(PackageManagersModule);

async searchPlugins(keyword = "", options: any = {}) {
const result = await this.npmRegistryClient.search(this.getKeyword(keyword), options);

return result.filter(({package: {name}}: any) => this.isPlugin(name)).map(mapPlugins);
}

loadPlugins() {
return loadPlugins(this.injector);
}

addPluginsDependencies(ctx: any): Task[] {
const plugins = Object.keys(this.packageJson.devDependencies).filter((name) => this.isPlugin(name));

Expand Down
20 changes: 10 additions & 10 deletions packages/cli-core/src/services/CliProxyAgent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("CliPlugins", () => {

await cliProxyAgent.resolveProxySettings();

expect(cliProxyAgent.proxySettings).toEqual({url: "http://login:password@host:3000"});
expect(cliProxyAgent.proxySettings.value).toEqual({url: "http://login:password@host:3000"});
});

it("should get proxy url from env (HTTP_PROXY -2)", async () => {
Expand All @@ -46,7 +46,7 @@ describe("CliPlugins", () => {

await cliProxyAgent.resolveProxySettings();

expect(cliProxyAgent.proxySettings).toEqual({strictSsl: false, url: "https://login:password@host:3000"});
expect(cliProxyAgent.proxySettings.value).toEqual({strictSsl: false, url: "https://login:password@host:3000"});
});
});
describe("from npm config", () => {
Expand All @@ -73,11 +73,11 @@ describe("CliPlugins", () => {
]);

// @ts-ignore
cliProxyAgent.proxySettings.url = undefined;
cliProxyAgent.proxySettings.value.url = undefined;

await cliProxyAgent.resolveProxySettings();

expect(cliProxyAgent.proxySettings).toEqual({
expect(cliProxyAgent.proxySettings.value).toEqual({
url: "https://login:password@host:3000",
strictSsl: false
});
Expand Down Expand Up @@ -105,11 +105,11 @@ describe("CliPlugins", () => {
]);

// @ts-ignore
cliProxyAgent.proxySettings.url = undefined;
cliProxyAgent.proxySettings.value.url = undefined;

await cliProxyAgent.resolveProxySettings();

expect(cliProxyAgent.proxySettings).toEqual({
expect(cliProxyAgent.proxySettings.value).toEqual({
url: "https://login:password@host:3000",
strictSsl: true
});
Expand Down Expand Up @@ -137,11 +137,11 @@ describe("CliPlugins", () => {
]);

// @ts-ignore
cliProxyAgent.proxySettings.url = undefined;
cliProxyAgent.proxySettings.value.url = undefined;

await cliProxyAgent.resolveProxySettings();

expect(cliProxyAgent.proxySettings).toEqual({
expect(cliProxyAgent.proxySettings.value).toEqual({
url: "https://login:password@host:3000",
strictSsl: true
});
Expand Down Expand Up @@ -169,11 +169,11 @@ describe("CliPlugins", () => {
]);

// @ts-ignore
cliProxyAgent.proxySettings.url = undefined;
cliProxyAgent.proxySettings.value.url = undefined;

await cliProxyAgent.resolveProxySettings();

expect(cliProxyAgent.proxySettings).toEqual({
expect(cliProxyAgent.proxySettings.value).toEqual({
url: "https://host:3000",
strictSsl: true
});
Expand Down
21 changes: 8 additions & 13 deletions packages/cli-core/src/services/CliProxyAgent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Configuration, Inject, Injectable, Value} from "@tsed/di";
import {Configuration, Inject, inject, Injectable, refValue} from "@tsed/di";
import {camelCase} from "change-case";
import tunnel from "tunnel";
import {URL} from "url";
Expand All @@ -20,23 +20,18 @@ export interface CliProxySettings {
}
})
export class CliProxyAgent {
@Value("proxy", {})
proxySettings: CliProxySettings;

@Inject()
protected projectPackageJson: ProjectPackageJson;

@Inject()
protected cliExeca: CliExeca;
readonly proxySettings = refValue<CliProxySettings>("proxy", {} as never);
protected projectPackageJson = Inject(ProjectPackageJson);
protected cliExeca = inject(CliExeca);

hasProxy() {
return !!this.proxySettings.url;
return !!this.proxySettings.value.url;
}

get(type: "http" | "https") {
if (this.hasProxy()) {
const {strictSsl = true} = this.proxySettings;
const url = new URL(this.proxySettings.url);
const {strictSsl = true} = this.proxySettings.value;
const url = new URL(this.proxySettings.value.url);
const protocol = url.protocol.replace(":", "");

const options = {
Expand Down Expand Up @@ -92,7 +87,7 @@ export class CliProxyAgent {
const url = httpsProxy || httpProxy || proxy;

if (url) {
this.proxySettings = {
this.proxySettings.value = {
url,
strictSsl: coerce(strictSsl) !== false
};
Expand Down
Loading
Loading