diff --git a/apps/web/next.config.ts b/apps/web/next.config.ts index bb1116c..03dcaab 100644 --- a/apps/web/next.config.ts +++ b/apps/web/next.config.ts @@ -1,27 +1,24 @@ import type { NextConfig } from "next"; import { join } from "node:path"; -// In a pnpm workspace + Turbopack setup, Next can't always infer the monorepo -// root (it walks up looking for next/package.json). Pin it explicitly so both -// dev and production builds resolve files correctly inside the Docker image. +// Pin Turbopack's workspace root explicitly — pnpm + Turbopack can't always +// infer it inside Docker bind mounts. const workspaceRoot = join(import.meta.dirname, "..", ".."); +// We consume @cmbot/db and @cmbot/shared via their compiled dist (their +// package.json `main` points at ./dist/index.js). The dist is built at +// container start (see docker-compose.dev.yml) and during the production +// Docker build (see docker/web.Dockerfile). This sidesteps Turbopack's +// inability to resolve NodeNext-style `.js` extensions to `.ts` source. const nextConfig: NextConfig = { reactStrictMode: true, output: "standalone", outputFileTracingRoot: workspaceRoot, - transpilePackages: ["@cmbot/db", "@cmbot/shared"], experimental: { typedRoutes: true, }, turbopack: { root: workspaceRoot, - resolveExtensions: [".tsx", ".ts", ".jsx", ".js", ".mjs", ".json"], - resolveAlias: { - // Turbopack doesn't strip the `.js` extension alias that NodeNext requires. - // Map the compiled-style paths back to the real TS source files. - "@cmbot/db/schema.js": `${workspaceRoot}/packages/db/src/schema.ts`, - }, }, }; diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 8a73ca5..baf2d26 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -43,13 +43,16 @@ services: container_name: cmbot-web user: "${HOST_UID:-1000}:${HOST_GID:-1000}" working_dir: /app - command: ["pnpm", "--filter", "@cmbot/web", "dev"] + command: + - sh + - -c + - "pnpm --filter @cmbot/shared build && pnpm --filter @cmbot/db build && pnpm --filter @cmbot/web dev" restart: unless-stopped volumes: - .:/app - ./dev-data:/data ports: - - "127.0.0.1:${WEB_PORT}:3000" + - "${WEB_PORT}:3000" environment: NODE_ENV: development DATABASE_URL: ${DATABASE_URL} diff --git a/packages/db/package.json b/packages/db/package.json index d85468a..5439df3 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -3,11 +3,17 @@ "version": "0.1.0", "private": true, "type": "module", - "main": "./src/index.ts", - "types": "./src/index.ts", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", "exports": { - ".": "./src/index.ts", - "./schema": "./src/schema.ts" + ".": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + }, + "./schema": { + "types": "./dist/schema.d.ts", + "default": "./dist/schema.js" + } }, "scripts": { "build": "tsc -p tsconfig.json", diff --git a/packages/db/src/index.ts b/packages/db/src/index.ts index de3477a..f36c389 100644 --- a/packages/db/src/index.ts +++ b/packages/db/src/index.ts @@ -1,8 +1,8 @@ import { drizzle, type NodePgDatabase } from "drizzle-orm/node-postgres"; import { Pool } from "pg"; -import * as schema from "./schema"; +import * as schema from "./schema.js"; -export * from "./schema"; +export * from "./schema.js"; export type DB = NodePgDatabase; diff --git a/packages/db/src/migrate.ts b/packages/db/src/migrate.ts index 962a365..dc14764 100644 --- a/packages/db/src/migrate.ts +++ b/packages/db/src/migrate.ts @@ -1,5 +1,5 @@ import { migrate } from "drizzle-orm/node-postgres/migrator"; -import { createClient } from "./index"; +import { createClient } from "./index.js"; const databaseUrl = process.env.DATABASE_URL; if (!databaseUrl) { diff --git a/packages/db/src/seed.ts b/packages/db/src/seed.ts index 3fa93f6..6c75e3a 100644 --- a/packages/db/src/seed.ts +++ b/packages/db/src/seed.ts @@ -1,4 +1,4 @@ -import { createClient, operators } from "./index"; +import { createClient, operators } from "./index.js"; const databaseUrl = process.env.DATABASE_URL; const operatorTelegramId = process.env.SEED_OPERATOR_TELEGRAM_ID; diff --git a/packages/db/tsconfig.json b/packages/db/tsconfig.json index 20c4917..8f24167 100644 --- a/packages/db/tsconfig.json +++ b/packages/db/tsconfig.json @@ -2,9 +2,7 @@ "extends": "../../tsconfig.base.json", "compilerOptions": { "outDir": "./dist", - "rootDir": "./src", - "module": "ESNext", - "moduleResolution": "Bundler" + "rootDir": "./src" }, "include": ["src/**/*"] } diff --git a/packages/shared/package.json b/packages/shared/package.json index 7859a16..0e240f0 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -3,10 +3,13 @@ "version": "0.1.0", "private": true, "type": "module", - "main": "./src/index.ts", - "types": "./src/index.ts", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", "exports": { - ".": "./src/index.ts" + ".": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } }, "scripts": { "build": "tsc -p tsconfig.json",