From 4a9f55cdf02c4e8de7a6ca425f4f1be643468784 Mon Sep 17 00:00:00 2001 From: Julian Cuni Date: Fri, 1 May 2026 10:49:48 +0200 Subject: [PATCH] Copy SQL migration files into dist/ as part of build tsc only emits .ts -> .js; non-TypeScript assets like SQL migration files don't make it into dist/ by default. The migration runner reads *.sql from dist/db/migrations/ at runtime in production (relative to the compiled migrate.js), so the missing files surface as a fatal ENOENT on container startup. Fix: small node script (scripts/copy-assets.mjs) using fs.cpSync, invoked after tsc in the build script. Cross-platform, no new dependencies. The script is in the Docker build context but not copied into the runtime stage, so it doesn't bloat the final image. Verified: pnpm build now produces dist/db/migrations/0001_positions.sql. --- package.json | 2 +- scripts/copy-assets.mjs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 scripts/copy-assets.mjs diff --git a/package.json b/package.json index c8b350f..0380742 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "node": ">=22" }, "scripts": { - "build": "tsc --project tsconfig.json", + "build": "tsc --project tsconfig.json && node scripts/copy-assets.mjs", "dev": "tsx watch src/main.ts", "start": "node dist/main.js", "test": "vitest run", diff --git a/scripts/copy-assets.mjs b/scripts/copy-assets.mjs new file mode 100644 index 0000000..76686ed --- /dev/null +++ b/scripts/copy-assets.mjs @@ -0,0 +1,16 @@ +// Copies non-TypeScript build artifacts into dist/ after tsc. +// Currently: SQL migration files for the runtime migration runner. +// tsc only emits .ts → .js; everything else has to be copied explicitly. + +import { cpSync, existsSync } from 'node:fs'; + +const assets = [{ src: 'src/db/migrations', dest: 'dist/db/migrations' }]; + +for (const { src, dest } of assets) { + if (!existsSync(src)) { + console.error(`copy-assets: source missing: ${src}`); + process.exit(1); + } + cpSync(src, dest, { recursive: true }); + console.log(`copy-assets: ${src} -> ${dest}`); +}