diff --git a/packages/barrels/bin/barrels.js b/packages/barrels/bin/barrels.js index 9abaafaa3..25546a533 100755 --- a/packages/barrels/bin/barrels.js +++ b/packages/barrels/bin/barrels.js @@ -1,7 +1,7 @@ #!/usr/bin/env node import {existsSync} from "node:fs"; import {readFile, writeFile} from "node:fs/promises"; -import {join} from "node:path"; +import {dirname, join} from "node:path"; import {globby} from "globby"; @@ -46,8 +46,16 @@ async function build() { const excluded = exclude.map((path) => `!${path}`).concat(directory.map((path) => `!${path}/index.ts`)); - const promises = directory.map(async (directory) => { - const baseIndex = join(process.cwd(), directory); + const directories = ( + await globby(directory, { + cwd: process.cwd() + }) + ).reduce((set, file) => { + return set.add(dirname(file)); + }, new Set()); + + const promises = [...directories.keys()].map(async (directory) => { + const baseIndex = join(process.cwd(), directory?.path ?? directory); const files = await globby(["**/*.ts", "!index.ts", ...excluded], { cwd: directory diff --git a/packages/cli-core/src/utils/createTasksRunner.ts b/packages/cli-core/src/utils/createTasksRunner.ts index 420f3d6e6..4b020374d 100644 --- a/packages/cli-core/src/utils/createTasksRunner.ts +++ b/packages/cli-core/src/utils/createTasksRunner.ts @@ -1,6 +1,6 @@ // @ts-ignore import {isFunction} from "@tsed/core"; -import {Listr, ListrTaskWrapper, Logger} from "listr2"; +import {Listr, type ListrTaskWrapper, Logger} from "listr2"; import type {TaskOptions, Tasks} from "../interfaces/Tasks.js"; import {getLogger} from "./createInjector.js"; diff --git a/packages/cli-core/src/utils/loadPlugins.ts b/packages/cli-core/src/utils/loadPlugins.ts index 6a390f42b..13d7c0eda 100644 --- a/packages/cli-core/src/utils/loadPlugins.ts +++ b/packages/cli-core/src/utils/loadPlugins.ts @@ -1,5 +1,3 @@ -import {fileURLToPath} from "node:url"; - import {GlobalProviders, InjectorService} from "@tsed/di"; import chalk from "chalk"; // @ts-ignore @@ -21,7 +19,7 @@ export async function loadPlugins(injector: InjectorService) { .filter((mod) => mod.startsWith(`@${name}/cli-plugin`) || mod.includes(`${name}-cli-plugin`)) .map(async (mod) => { try { - const {default: plugin} = await fs.importModule(mod, fileURLToPath(rootDir)); + const {default: plugin} = await fs.importModule(mod, rootDir); if (!injector.has(plugin)) { const provider = GlobalProviders.get(plugin)?.clone(); diff --git a/packages/cli-core/src/utils/mapCommanderOptions.ts b/packages/cli-core/src/utils/mapCommanderOptions.ts index 51148a720..637347ab5 100644 --- a/packages/cli-core/src/utils/mapCommanderOptions.ts +++ b/packages/cli-core/src/utils/mapCommanderOptions.ts @@ -1,6 +1,6 @@ -import commander from "commander"; +import type {Command} from "commander"; -export function mapCommanderOptions(commands: commander.Command[]) { +export function mapCommanderOptions(commands: Command[]) { const options: any = {}; commands.forEach((command) => { Object.entries(command.opts()) diff --git a/packages/cli-plugin-eslint/src/hooks/EslintInitHook.ts b/packages/cli-plugin-eslint/src/hooks/EslintInitHook.ts index d474e3457..897375fe7 100644 --- a/packages/cli-plugin-eslint/src/hooks/EslintInitHook.ts +++ b/packages/cli-plugin-eslint/src/hooks/EslintInitHook.ts @@ -70,6 +70,14 @@ export class EslintInitHook { await this.packageManagers.runScript("prepare"); } + }, + { + title: "Run linter", + task: () => { + return this.packageManagers.runScript("test:lint:fix", { + ignoreError: true + }); + } } ]; } @@ -115,6 +123,15 @@ export class EslintInitHook { ); } + if (ctx.vitest) { + this.packageJson.addDevDependencies( + { + "eslint-plugin-vitest": "latest" + }, + ctx + ); + } + if (ctx.prettier) { this.packageJson.addDevDependencies( { diff --git a/packages/cli-plugin-eslint/templates/init/eslint.config.mjs.hbs b/packages/cli-plugin-eslint/templates/init/eslint.config.mjs.hbs index 705f34168..bbdb5f078 100644 --- a/packages/cli-plugin-eslint/templates/init/eslint.config.mjs.hbs +++ b/packages/cli-plugin-eslint/templates/init/eslint.config.mjs.hbs @@ -3,7 +3,7 @@ import typescriptParser from "@typescript-eslint/parser"; {{#if prettier}}import pluginPrettierRecommended from "eslint-plugin-prettier/recommended"; {{/if}}import pluginSimpleImportSort from "eslint-plugin-simple-import-sort"; {{#if vitest}}import vitest from "eslint-plugin-vitest"; -i{{/if}}import globals from "globals"; +{{/if}}import globals from "globals"; export default [ { @@ -58,8 +58,7 @@ export default [ }, rules: { "simple-import-sort/imports": "error", - "simple-import-sort/exports": "error", - "workspaces/no-absolute-imports": "error" + "simple-import-sort/exports": "error" } }{{#if prettier}}, pluginPrettierRecommended{{/if}} diff --git a/packages/cli-plugin-vitest/src/CliPluginVitestModule.ts b/packages/cli-plugin-vitest/src/CliPluginVitestModule.ts index ce6f47afd..5ec0cd05b 100644 --- a/packages/cli-plugin-vitest/src/CliPluginVitestModule.ts +++ b/packages/cli-plugin-vitest/src/CliPluginVitestModule.ts @@ -25,7 +25,7 @@ export class CliPluginVitestModule { const runtime = this.runtimes.get(); this.packageJson.addScripts({ - test: `${runtime.run("test:lint")} && ${runtime.run("test:coverage")} `, + test: `${runtime.run("test:lint")} && ${runtime.run("test:coverage")}`, "test:unit": "cross-env NODE_ENV=test vitest run", "test:watch": "cross-env NODE_ENV=test vitest", "test:coverage": `cross-env NODE_ENV=test vitest run --coverage` diff --git a/packages/cli/src/commands/generate/GenerateCmd.spec.ts b/packages/cli/src/commands/generate/GenerateCmd.spec.ts index d3e66cf2a..65f79236d 100644 --- a/packages/cli/src/commands/generate/GenerateCmd.spec.ts +++ b/packages/cli/src/commands/generate/GenerateCmd.spec.ts @@ -115,7 +115,7 @@ describe("GenerateCmd", () => { express: false, koa: false, platformSymbol: undefined, - barrels: '["./src/controllers/rest/index.js"]', + barrels: '["./src/controllers/rest"]', imports: [ {from: "@tsed/ajv"}, {symbols: "{config}", from: "./config/index.js"}, @@ -169,7 +169,7 @@ describe("GenerateCmd", () => { express: false, koa: false, platformSymbol: undefined, - barrels: '["./src/controllers/rest/index.js"]', + barrels: '["./src/controllers/rest"]', imports: [ {from: "@tsed/ajv"}, {symbols: "{config}", from: "./config/index.js"}, diff --git a/packages/cli/src/utils/__snapshots__/fillImport.spec.ts.snap b/packages/cli/src/utils/__snapshots__/fillImport.spec.ts.snap index 4448675ca..d050719fc 100644 --- a/packages/cli/src/utils/__snapshots__/fillImport.spec.ts.snap +++ b/packages/cli/src/utils/__snapshots__/fillImport.spec.ts.snap @@ -3,7 +3,7 @@ exports[`fillImports() > should return barrels and imports files for ('arc_default', oidc: false, graphql: false, swagger: true, passportjs: false, express: false, koa: false, mongoose: false) 1`] = ` { "architecture": "arc_default", - "barrels": "["./src/controllers/rest/index.js","./src/controllers/pages/index.js"]", + "barrels": "["./src/controllers/rest","./src/controllers/pages"]", "express": false, "graphql": false, "imports": [ @@ -37,7 +37,7 @@ exports[`fillImports() > should return barrels and imports files for ('arc_defau exports[`fillImports() > should return barrels and imports files for ('arc_default', oidc: true, graphql: false, swagger: false, passportjs: false, express: false, koa: true, mongoose: false) 1`] = ` { "architecture": "arc_default", - "barrels": "["./src/controllers/rest/index.js","./src/interactions/index.js"]", + "barrels": "["./src/controllers/rest","./src/interactions"]", "express": false, "graphql": false, "imports": [ @@ -75,7 +75,7 @@ exports[`fillImports() > should return barrels and imports files for ('arc_defau exports[`fillImports() > should return barrels and imports files for ('arc_default', oidc: true, graphql: true, swagger: true, passportjs: true, express: false, koa: true, mongoose: true) 1`] = ` { "architecture": "arc_default", - "barrels": "["./src/controllers/rest/index.js","./src/controllers/pages/index.js","./src/interactions/index.js","./src/datasources/index.js","./src/resolvers/index.js"]", + "barrels": "["./src/controllers/rest","./src/controllers/pages","./src/interactions","./src/datasources","./src/resolvers"]", "express": false, "graphql": true, "imports": [ @@ -131,7 +131,7 @@ exports[`fillImports() > should return barrels and imports files for ('arc_defau exports[`fillImports() > should return barrels and imports files for ('feature', oidc: false, graphql: false, swagger: false, passportjs: false, express: false, koa: false, mongoose: false) 1`] = ` { "architecture": "feature", - "barrels": "["./src/rest/index.js"]", + "barrels": "["./src/rest"]", "express": false, "graphql": false, "imports": [ @@ -158,7 +158,7 @@ exports[`fillImports() > should return barrels and imports files for ('feature', exports[`fillImports() > should return barrels and imports files for ('feature', oidc: false, graphql: false, swagger: true, passportjs: false, express: false, koa: false, mongoose: false) 1`] = ` { "architecture": "feature", - "barrels": "["./src/rest/index.js","./src/pages/index.js"]", + "barrels": "["./src/rest","./src/pages"]", "express": false, "graphql": false, "imports": [ @@ -192,7 +192,7 @@ exports[`fillImports() > should return barrels and imports files for ('feature', exports[`fillImports() > should return barrels and imports files for ('feature', oidc: true, graphql: false, swagger: false, passportjs: false, express: true, koa: false, mongoose: false) 1`] = ` { "architecture": "feature", - "barrels": "["./src/rest/index.js","./src/interactions/index.js"]", + "barrels": "["./src/rest","./src/interactions"]", "express": false, "graphql": false, "imports": [ @@ -230,7 +230,7 @@ exports[`fillImports() > should return barrels and imports files for ('feature', exports[`fillImports() > should return barrels and imports files for ('feature', oidc: true, graphql: true, swagger: true, passportjs: true, express: true, koa: false, mongoose: true) 1`] = ` { "architecture": "feature", - "barrels": "["./src/rest/index.js","./src/pages/index.js","./src/interactions/index.js","./src/datasources/index.js","./src/resolvers/index.js"]", + "barrels": "["./src/rest","./src/pages","./src/interactions","./src/datasources","./src/resolvers"]", "express": false, "graphql": true, "imports": [ diff --git a/packages/cli/src/utils/fillImports.ts b/packages/cli/src/utils/fillImports.ts index 4296412e7..242b71a51 100644 --- a/packages/cli/src/utils/fillImports.ts +++ b/packages/cli/src/utils/fillImports.ts @@ -10,11 +10,11 @@ export function fillImports(ctx: any) { ctx.barrels = JSON.stringify( [ - isFeature ? "./src/rest/index.js" : "./src/controllers/rest/index.js", - ctx.swagger && (isFeature ? "./src/pages/index.js" : "./src/controllers/pages/index.js"), - ctx.oidc && "./src/interactions/index.js", - ctx.graphql && "./src/datasources/index.js", - ctx.graphql && "./src/resolvers/index.js" + isFeature ? "./src/rest" : "./src/controllers/rest", + ctx.swagger && (isFeature ? "./src/pages" : "./src/controllers/pages"), + ctx.oidc && "./src/interactions", + ctx.graphql && "./src/datasources", + ctx.graphql && "./src/resolvers" ].filter(Boolean) ); diff --git a/packages/cli/templates/init/.dockerignore.hbs b/packages/cli/templates/init/.dockerignore.hbs index fec4b2af0..3a9f7b09d 100644 --- a/packages/cli/templates/init/.dockerignore.hbs +++ b/packages/cli/templates/init/.dockerignore.hbs @@ -2,3 +2,4 @@ node_modules Dockerfile .env.local .env.development +**/*.spec.ts diff --git a/packages/cli/templates/init/.swcrc.hbs b/packages/cli/templates/init/.swcrc.hbs index 6fb5a60fa..f686f85cc 100644 --- a/packages/cli/templates/init/.swcrc.hbs +++ b/packages/cli/templates/init/.swcrc.hbs @@ -6,7 +6,7 @@ "decorators": true, "dynamicImport": true }, - "target": "es2023", + "target": "es2022", "externalHelpers": true, "keepClassNames": true, "transform": { diff --git a/packages/cli/templates/init/docker/npm/Dockerfile.hbs b/packages/cli/templates/init/docker/npm/Dockerfile.hbs index f0b94268b..013823ee5 100644 --- a/packages/cli/templates/init/docker/npm/Dockerfile.hbs +++ b/packages/cli/templates/init/docker/npm/Dockerfile.hbs @@ -13,7 +13,7 @@ COPY ./src ./src RUN npm run build -FROM node:${NODE_VERSION}-alpine as runtime +FROM node:${NODE_VERSION}-alpine AS runtime ENV WORKDIR /opt WORKDIR $WORKDIR diff --git a/packages/cli/templates/init/docker/pnpm/Dockerfile.hbs b/packages/cli/templates/init/docker/pnpm/Dockerfile.hbs index a06c501d5..d30c383c6 100644 --- a/packages/cli/templates/init/docker/pnpm/Dockerfile.hbs +++ b/packages/cli/templates/init/docker/pnpm/Dockerfile.hbs @@ -13,7 +13,7 @@ COPY ./src ./src RUN pnpm run build -FROM node:${NODE_VERSION}-alpine as runtime +FROM node:${NODE_VERSION}-alpine AS runtime ENV WORKDIR /opt WORKDIR $WORKDIR