import { defineConfig } from 'vite';

/**
 * Builds the Tier 1 runner (src/tier1/entry.ts) into a single ES module the
 * extension's service worker can import. Everything reachable from the entry
 * must be Node-free (specGates, localLlm, scaffolds) — the build fails loudly
 * if a node: import sneaks in, rather than shipping a broken bundle.
 */
export default defineConfig({
  build: {
    lib: {
      entry: 'src/tier1/entry.ts',
      formats: ['es'],
      fileName: () => 'tier1.bundle.js',
    },
    outDir: 'extension',
    emptyOutDir: false,
    rollupOptions: {
      external: (id: string) => {
        if (id.startsWith('node:')) {
          throw new Error(`tier1 bundle must stay browser-pure; found import of ${id}`);
        }
        return false;
      },
    },
  },
});
