#!/usr/bin/env node /** * Build script for xo-complete autocomplete helper. * * Bundles the autocomplete script with all dependencies into a single file * for faster startup time. This avoids the ~600ms module import overhead * that occurs with dynamic ESM imports. */ import * as esbuild from "esbuild"; import { join, dirname } from "path"; import { fileURLToPath } from "url"; const __dirname = dirname(fileURLToPath(import.meta.url)); const projectRoot = join(__dirname, ".."); async function build() { try { const result = await esbuild.build({ entryPoints: [join(projectRoot, "src/cli/autocomplete/complete.ts")], bundle: true, platform: "node", target: "node20", format: "esm", outfile: join(projectRoot, "dist/cli/autocomplete/complete.bundle.js"), // Mark modules as external that either have native components or bundling issues // We keep heavy deps external, and also keep offline-engine external so it stays // as a dynamic import (it pulls in the heavy engine dependencies) external: [ "better-sqlite3", "fsevents", "@bitauth/libauth", "@xo-cash/*", "@electrum-cash/*", "./offline-engine.js", ], // Generate source maps for debugging sourcemap: true, // Minify for slightly smaller bundle minify: false, // Keep names for better error messages keepNames: true, // Log build info logLevel: "info", }); console.log("Autocomplete bundle built successfully!"); if (result.warnings.length > 0) { console.warn("Warnings:", result.warnings); } } catch (error) { console.error("Build failed:", error); process.exit(1); } } build();