import { readFileSync } from "node:fs";
import { defineConfig } from "tsup";

const pkg = JSON.parse(readFileSync("./package.json", "utf-8")) as {
  version: string;
};

export default defineConfig({
  entry: ["src/cli/index.ts"],
  format: ["esm"],
  target: "node22",
  splitting: false,
  dts: true,
  clean: true,
  sourcemap: true,
  outDir: "dist/cli",
  define: {
    __VERSION__: JSON.stringify(pkg.version),
  },
  banner: {
    js: "#!/usr/bin/env node",
  },
  // Externalize inquirer's internals. They are transitive deps (not in our
  // `dependencies`), so tsup would otherwise bundle them — and `@inquirer/core`
  // pulls in CJS modules like `mute-stream` that use dynamic `require("stream")`,
  // which a single ESM bundle cannot satisfy. Leaving them as runtime imports
  // makes Node resolve them from node_modules where their CJS works natively.
  external: ["@inquirer/core", "@inquirer/figures"],
});
