setup swc

This commit is contained in:
olehhapuk
2026-12-01 12:22:44 +02:00
parent ebf6ec2e39
commit f8de87955b
19 changed files with 1302 additions and 164 deletions
+2
View File
@@ -8,6 +8,8 @@
// Nest reads constructor parameter types at runtime for dependency // Nest reads constructor parameter types at runtime for dependency
// injection, so a class imported "only as a type" must stay a real import. // injection, so a class imported "only as a type" must stay a real import.
"typescript/consistent-type-imports": "off", "typescript/consistent-type-imports": "off",
// Relative imports are written without an extension; the build adds it.
"import/extensions": ["warn", "never"],
"typescript/no-explicit-any": "off", "typescript/no-explicit-any": "off",
"typescript/no-floating-promises": "error" "typescript/no-floating-promises": "error"
} }
+6
View File
@@ -0,0 +1,6 @@
{
"$schema": "https://swc.rs/schema.json",
"jsc": {
"baseUrl": "."
}
}
+1 -1
View File
@@ -25,7 +25,7 @@ Validation works with Zod, Valibot, ArkType or any other Standard Schema library
A route handler can return a web `Response`, a `ReadableStream` or an async generator, and Nest streams it as it's produced (https://docs.nestjs.com/http/streaming-responses.md). A route handler can return a web `Response`, a `ReadableStream` or an async generator, and Nest streams it as it's produced (https://docs.nestjs.com/http/streaming-responses.md).
Nest's packages are ESM only, and this project is ESM too: relative imports end in `.js`, `__dirname` doesn't exist (use `import.meta.dirname`), and tests run on Vitest, so mocks are `vi.fn()`, not `jest.fn()`. Nest's packages are ESM only, and this project is ESM too: relative imports are written without a file extension (the SWC build adds `.js`; `nest generate` still writes `.js`, which works but should be trimmed to match), `__dirname` doesn't exist (use `import.meta.dirname`), and tests run on Vitest, so mocks are `vi.fn()`, not `jest.fn()`.
In this project, `src/main.ts` creates the app and listens on `PORT` (3000 by default), `src/app.module.ts` is the root module that imports the others, and `AppController` and `AppService` are samples. Unit tests sit beside the code as `*.spec.ts` and the e2e test is in `test/`; Vitest runs them (`npm test`, `npm run test:e2e`). In this project, `src/main.ts` creates the app and listens on `PORT` (3000 by default), `src/app.module.ts` is the root module that imports the others, and `AppController` and `AppService` are samples. Unit tests sit beside the code as `*.spec.ts` and the e2e test is in `test/`; Vitest runs them (`npm test`, `npm run test:e2e`).
+2
View File
@@ -3,6 +3,8 @@
"collection": "@nestjs/schematics", "collection": "@nestjs/schematics",
"sourceRoot": "src", "sourceRoot": "src",
"compilerOptions": { "compilerOptions": {
"builder": "swc",
"typeCheck": true,
"deleteOutDir": true "deleteOutDir": true
} }
} }
+2
View File
@@ -46,6 +46,8 @@
"@nestjs/mau": "^0.2.6", "@nestjs/mau": "^0.2.6",
"@nestjs/schematics": "^12.0.0", "@nestjs/schematics": "^12.0.0",
"@nestjs/testing": "^12.0.1", "@nestjs/testing": "^12.0.1",
"@swc/cli": "^0.8.2",
"@swc/core": "^1.16.22",
"@types/express": "^5.0.0", "@types/express": "^5.0.0",
"@types/node": "^24.0.0", "@types/node": "^24.0.0",
"@types/pg": "^8.23.1", "@types/pg": "^8.23.1",
+2 -2
View File
@@ -1,6 +1,6 @@
import { Test, TestingModule } from '@nestjs/testing'; import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller.js'; import { AppController } from './app.controller';
import { AppService } from './app.service.js'; import { AppService } from './app.service';
describe('AppController', () => { describe('AppController', () => {
let appController: AppController; let appController: AppController;
+2 -2
View File
@@ -4,8 +4,8 @@ import {
Session, Session,
type UserSession, type UserSession,
} from '@thallesp/nestjs-better-auth'; } from '@thallesp/nestjs-better-auth';
import { AppService } from './app.service.js'; import { AppService } from './app.service';
import type { Auth } from './auth/auth.js'; import type { Auth } from './auth/auth';
@Controller() @Controller()
export class AppController { export class AppController {
+5 -5
View File
@@ -3,11 +3,11 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
import { DrizzleModule, getDrizzleToken } from '@nestjs/drizzle'; import { DrizzleModule, getDrizzleToken } from '@nestjs/drizzle';
import { AuthModule } from '@thallesp/nestjs-better-auth'; import { AuthModule } from '@thallesp/nestjs-better-auth';
import { drizzle } from 'drizzle-orm/node-postgres'; import { drizzle } from 'drizzle-orm/node-postgres';
import { AppController } from './app.controller.js'; import { AppController } from './app.controller';
import { AppService } from './app.service.js'; import { AppService } from './app.service';
import { createAuth } from './auth/auth.js'; import { createAuth } from './auth/auth';
import type { Database } from './db/database.js'; import type { Database } from './db/database';
import { relations } from './db/relations.js'; import { relations } from './db/relations';
@Module({ @Module({
imports: [ imports: [
+2 -2
View File
@@ -4,8 +4,8 @@
* pool is lazy and the CLI only reads the options. * pool is lazy and the CLI only reads the options.
*/ */
import { drizzle } from 'drizzle-orm/node-postgres'; import { drizzle } from 'drizzle-orm/node-postgres';
import { relations } from '../db/relations.js'; import { relations } from '../db/relations';
import { createAuth } from './auth.js'; import { createAuth } from './auth';
export const auth = createAuth( export const auth = createAuth(
drizzle(process.env.DATABASE_URL ?? 'postgres://localhost/unused', { drizzle(process.env.DATABASE_URL ?? 'postgres://localhost/unused', {
+2 -2
View File
@@ -1,7 +1,7 @@
import { drizzleAdapter } from '@better-auth/drizzle-adapter/relations-v2'; import { drizzleAdapter } from '@better-auth/drizzle-adapter/relations-v2';
import { betterAuth } from 'better-auth'; import { betterAuth } from 'better-auth';
import type { Database } from '../db/database.js'; import type { Database } from '../db/database';
import * as schema from '../db/schema/index.js'; import * as schema from '../db/schema';
export interface AuthConfig { export interface AuthConfig {
/** Signs cookies and tokens. At least 32 random bytes. */ /** Signs cookies and tokens. At least 32 random bytes. */
+1 -1
View File
@@ -1,5 +1,5 @@
import type { NodePgDatabase } from 'drizzle-orm/node-postgres'; import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
import type { relations } from './relations.js'; import type { relations } from './relations';
/** The injected database: `@InjectDrizzle() private readonly db: Database`. */ /** The injected database: `@InjectDrizzle() private readonly db: Database`. */
export type Database = NodePgDatabase<typeof relations>; export type Database = NodePgDatabase<typeof relations>;
+2 -2
View File
@@ -1,6 +1,6 @@
import { defineRelations } from 'drizzle-orm'; import { defineRelations } from 'drizzle-orm';
import { authRelations } from './schema/auth.js'; import { authRelations } from './schema/auth';
import * as schema from './schema/index.js'; import * as schema from './schema';
// Relations between the app's own tables (used by db.query...). // Relations between the app's own tables (used by db.query...).
const appRelations = defineRelations(schema, () => ({})); const appRelations = defineRelations(schema, () => ({}));
+1 -1
View File
@@ -3,4 +3,4 @@
// //
// auth.ts is generated by `pnpm auth:generate`; put your own tables in // auth.ts is generated by `pnpm auth:generate`; put your own tables in
// separate files next to it and re-export them below. // separate files next to it and re-export them below.
export * from './auth.js'; export * from './auth';
+1 -1
View File
@@ -1,5 +1,5 @@
import { NestFactory } from '@nestjs/core'; import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module.js'; import { AppModule } from './app.module';
async function bootstrap() { async function bootstrap() {
const app = await NestFactory.create(AppModule, { const app = await NestFactory.create(AppModule, {
+2 -2
View File
@@ -1,8 +1,8 @@
import { Test, TestingModule } from '@nestjs/testing'; import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common'; import { INestApplication } from '@nestjs/common';
import request from 'supertest'; import request from 'supertest';
import { App } from 'supertest/types.js'; import type { App } from 'supertest/types';
import { AppModule } from './../src/app.module.js'; import { AppModule } from './../src/app.module';
describe('AppController (e2e)', () => { describe('AppController (e2e)', () => {
let app: INestApplication<App>; let app: INestApplication<App>;
+2 -3
View File
@@ -1,8 +1,7 @@
{ {
"compilerOptions": { "compilerOptions": {
"module": "nodenext", "module": "esnext",
"moduleResolution": "nodenext", "moduleResolution": "bundler",
"resolvePackageJsonExports": true,
"esModuleInterop": true, "esModuleInterop": true,
"isolatedModules": true, "isolatedModules": true,
"declaration": true, "declaration": true,
+2
View File
@@ -0,0 +1,2 @@
# Generated by TanStack Router; it is rewritten on every build.
src/routeTree.gen.ts
+1263 -140
View File
File diff suppressed because it is too large Load Diff
+2
View File
@@ -7,3 +7,5 @@ allowBuilds:
lightningcss: true lightningcss: true
unrs-resolver: true unrs-resolver: true
msw: false msw: false
# Its install script only checks for the native binary, which pnpm already installs.
'@swc/core': false