import { createRequire } from "node:module";
import * as esbuild from "esbuild";
const _require = createRequire(import.meta.url);
// Plugin to ignore Zod locale imports (except English)
const ignoreZodLocalesPlugin = {
name: "ignore-zod-locales",
setup(build) {
// Intercept zod locale imports and return empty modules for non-English locales
build.onResolve({ filter: /^zod\/v4\/locales\/.+$/ }, (args) => {
// Keep English locale, ignore all others
if (
args.path === "zod/v4/locales/en" ||
args.path === "zod/v4/locales/index"
) {
return null; // Let esbuild handle it normally
}
// Replace other locales with empty module
return { path: args.path, namespace: "zod-locale-stub" };
});
build.onLoad({ filter: /.*/, namespace: "zod-locale-stub" }, () => {
return { contents: "export default {}", loader: "js" };
});
},
};
const isProduction = process.argv.includes("--production");
const buildOptions = {
entryPoints: ["dist/index.js"],
bundle: true,
platform: "node",
format: "cjs",
outfile: "dist/bundle/index.cjs",
plugins: [ignoreZodLocalesPlugin],
treeShaking: true,
minify: isProduction,
sourcemap: !isProduction,
// Target modern Node.js (reduces polyfills)
target: "node18",
// Mark packages that Node.js will load at runtime as external
external: [],
banner: {
js: "/* YNAB MCP Server Bundle - Generated by esbuild */",
},
logLevel: "info",
};
try {
const _result = await esbuild.build(buildOptions);
// Show bundle size
const fs = await import("node:fs");
const stats = fs.statSync("dist/bundle/index.cjs");
const sizeMB = (stats.size / 1024 / 1024).toFixed(2);
console.log(`\n✓ Bundle created: ${sizeMB} MB`);
if (isProduction) {
console.log("✓ Production build (minified)");
} else {
console.log("✓ Development build (with sourcemap)");
}
process.exit(0);
} catch (error) {
console.error("Build failed:", error);
process.exit(1);
}