import { build } from 'esbuild';
import { fileURLToPath } from 'node:url';

// Bundle the server + its shared `@/lib/*` imports (model, sync types) into one
// ESM file. npm deps (fastify, zod, …) stay external and install at runtime.
await build({
  entryPoints: ['server/src/index.ts'],
  outfile: 'server/dist/index.js',
  bundle: true,
  platform: 'node',
  format: 'esm',
  target: 'node20',
  packages: 'external',
  banner: { js: "import { createRequire } from 'module'; const require = createRequire(import.meta.url);" },
  alias: { '@': fileURLToPath(new URL('../src', import.meta.url)) },
});
console.log('server bundled → server/dist/index.js');
