import * as esbuild from "esbuild"; import { rm } from "node:fs/promises"; const watch = process.argv.includes("--watch"); // Remove previous outputs first. esbuild only overwrites the files its current // entry points produce, so without this a packaged VSIX can ship stale // artifacts from an older layout (e.g. the pre-`outbase` dist/mcpServer.js // next to the current dist/agent/mcpServer.js). await rm("dist", { recursive: true, force: true }); const ctx = await esbuild.context({ entryPoints: [ "./src/extension.ts", "./src/agent/mcpServer.ts", "./src/agent/cli.ts", ], bundle: true, outdir: "dist", outbase: "src", external: ["vscode"], format: "cjs", platform: "node", target: "es2022", sourcemap: true, logLevel: "info", }); if (watch) { await ctx.watch(); console.log("Watching for changes..."); } else { await ctx.rebuild(); await ctx.dispose(); }