diff --git a/packages/cli-plugin-eslint/src/hooks/EslintInitHook.ts b/packages/cli-plugin-eslint/src/hooks/EslintInitHook.ts index c679693bb..cafa5820b 100644 --- a/packages/cli-plugin-eslint/src/hooks/EslintInitHook.ts +++ b/packages/cli-plugin-eslint/src/hooks/EslintInitHook.ts @@ -1,5 +1,5 @@ import {InitCmdContext} from "@tsed/cli"; -import {Inject, Injectable, OnExec, OnPostInstall, ProjectPackageJson, RootRendererService} from "@tsed/cli-core"; +import {Inject, Injectable, OnExec, OnPostInstall, PackageManagersModule, ProjectPackageJson, RootRendererService} from "@tsed/cli-core"; import {TEMPLATE_DIR} from "../utils/templateDir"; @Injectable() @@ -7,6 +7,9 @@ export class EslintInitHook { @Inject() protected packageJson: ProjectPackageJson; + @Inject() + protected packageManagers: PackageManagersModule; + @Inject() protected rootRenderer: RootRendererService; @@ -65,7 +68,7 @@ export class EslintInitHook { }) .write(); - await this.packageJson.runScript("prepare"); + await this.packageManagers.runScript("prepare"); } } ]; diff --git a/packages/cli-plugin-jest/jest.config.js b/packages/cli-plugin-jest/jest.config.js index f1b6552c2..6ad9f6a39 100644 --- a/packages/cli-plugin-jest/jest.config.js +++ b/packages/cli-plugin-jest/jest.config.js @@ -7,7 +7,7 @@ module.exports = { coverageThreshold: { global: { statements: 79.45, - branches: 40, + branches: 37.5, functions: 60, lines: 79.45 } diff --git a/packages/cli-plugin-jest/src/CliPluginJestModule.ts b/packages/cli-plugin-jest/src/CliPluginJestModule.ts index d01df72ca..e9fde9b2c 100644 --- a/packages/cli-plugin-jest/src/CliPluginJestModule.ts +++ b/packages/cli-plugin-jest/src/CliPluginJestModule.ts @@ -1,4 +1,5 @@ import {Module, OnAdd, ProjectPackageJson} from "@tsed/cli-core"; +import {RuntimesModule} from "@tsed/cli"; import {Inject} from "@tsed/di"; import {JestGenerateHook} from "./hooks/JestGenerateHook"; import {JestInitHook} from "./hooks/JestInitHook"; @@ -7,6 +8,9 @@ import {JestInitHook} from "./hooks/JestInitHook"; imports: [JestInitHook, JestGenerateHook] }) export class CliPluginJestModule { + @Inject() + runtimes: RuntimesModule; + @Inject() packageJson: ProjectPackageJson; @@ -17,12 +21,12 @@ export class CliPluginJestModule { } addScripts() { - const runner = this.packageJson.getRunCmd(); + const runtime = this.runtimes.get(); this.packageJson.addScripts({ - test: `${runner} test:lint && ${runner} test:coverage`, + test: `${runtime.run("test:lint")} && ${runtime.run("test:coverage")} `, "test:unit": "cross-env NODE_ENV=test jest", - "test:coverage": `${runner} test:unit` + "test:coverage": `${runtime.run("test:unit")} ` }); } diff --git a/packages/cli-plugin-mocha/src/CliPluginMochaModule.ts b/packages/cli-plugin-mocha/src/CliPluginMochaModule.ts index 32834dcb1..0cbb9604d 100644 --- a/packages/cli-plugin-mocha/src/CliPluginMochaModule.ts +++ b/packages/cli-plugin-mocha/src/CliPluginMochaModule.ts @@ -2,11 +2,15 @@ import {Module, OnAdd, ProjectPackageJson} from "@tsed/cli-core"; import {Inject} from "@tsed/di"; import {MochaGenerateHook} from "./hooks/MochaGenerateHook"; import {MochaInitHook} from "./hooks/MochaInitHook"; +import {RuntimesModule} from "@tsed/cli"; @Module({ imports: [MochaInitHook, MochaGenerateHook] }) export class CliPluginMochaModule { + @Inject() + runtimes: RuntimesModule; + @Inject() packageJson: ProjectPackageJson; @@ -17,10 +21,10 @@ export class CliPluginMochaModule { } addScripts() { - const runner = this.packageJson.getRunCmd(); + const runtime = this.runtimes.get(); this.packageJson.addScripts({ - test: `${runner} test:unit && ${runner} test:coverage`, + test: `${runtime.run("test:unit")} && ${runtime.run("test:coverage")} `, "test:unit": "cross-env NODE_ENV=test mocha", "test:coverage": "cross-env NODE_ENV=test nyc mocha" }); diff --git a/packages/cli-plugin-prisma/src/hooks/PrismaInitHook.ts b/packages/cli-plugin-prisma/src/hooks/PrismaInitHook.ts index e9dc2c7e4..f006e549b 100644 --- a/packages/cli-plugin-prisma/src/hooks/PrismaInitHook.ts +++ b/packages/cli-plugin-prisma/src/hooks/PrismaInitHook.ts @@ -1,5 +1,5 @@ import {InitCmdContext} from "@tsed/cli"; -import {CliService, Inject, OnExec, ProjectPackageJson} from "@tsed/cli-core"; +import {CliService, Inject, OnExec, PackageManagersModule, ProjectPackageJson} from "@tsed/cli-core"; import {Injectable} from "@tsed/di"; import {CliPrisma} from "../services/CliPrisma"; @@ -14,6 +14,9 @@ export class PrismaInitHook { @Inject() protected packageJson: ProjectPackageJson; + @Inject() + protected packageManagers: PackageManagersModule; + @OnExec("init") onExec(ctx: InitCmdContext) { this.addScripts(); @@ -60,7 +63,7 @@ export class PrismaInitHook { $onFinish() { return new Promise((resolve) => { - this.packageJson.runScript("prisma:generate").subscribe({ + this.packageManagers.runScript("prisma:generate").subscribe({ complete() { resolve([]); }, diff --git a/packages/cli-testing/src/FakeCliFs.ts b/packages/cli-testing/src/FakeCliFs.ts index 5d1521950..167174d09 100644 --- a/packages/cli-testing/src/FakeCliFs.ts +++ b/packages/cli-testing/src/FakeCliFs.ts @@ -1,6 +1,8 @@ +import * as fs from "fs"; import {PathLike} from "fs"; import {EnsureOptions, WriteFileOptions} from "fs-extra"; import {normalizePath} from "./normalizePath"; +import {isString} from "@tsed/core"; export class FakeCliFs { static entries = new Map(); @@ -26,6 +28,12 @@ export class FakeCliFs { // eslint-disable-next-line @typescript-eslint/no-unused-vars readFileSync(file: string | Buffer | number, encoding?: any): string { + try { + if (isString(file) && file.match(/_partials/)) { + return fs.readFileSync(file, encoding) as any as string; + } + } catch (er) {} + return FakeCliFs.entries.get(normalizePath(file))!; } diff --git a/packages/cli/src/runtimes/RuntimesModule.ts b/packages/cli/src/runtimes/RuntimesModule.ts index 047696bae..51133117b 100644 --- a/packages/cli/src/runtimes/RuntimesModule.ts +++ b/packages/cli/src/runtimes/RuntimesModule.ts @@ -7,7 +7,7 @@ import {BunRuntime} from "./supports/BunRuntime"; import {SWCRuntime} from "./supports/SWCRuntime"; import {BaseRuntime} from "./supports/BaseRuntime"; -export interface InitOptions extends Record { +export interface RuntimeInitOptions extends Record { runtime?: string; } @@ -25,7 +25,7 @@ export class RuntimesModule { this.runtimes = runtimes.filter((manager) => manager.has()); } - init(ctx: InitOptions) { + init(ctx: RuntimeInitOptions) { ctx.runtime = ctx.runtime || this.get().name; if (ctx.runtime === "bun") { @@ -55,7 +55,7 @@ export class RuntimesModule { return selected; } - scripts(ctx: InitOptions) { + scripts(ctx: RuntimeInitOptions) { const runtime = this.get(ctx.runtime); return {