| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- /* eslint-disable no-undef */
- import esbuild from "esbuild"
- import { chmodSync, mkdirSync, copyFileSync } from "fs"
- import { rimrafSync } from "rimraf"
- // Function to copy post-build files
- function copyPostBuildFiles() {
- try {
- mkdirSync("dist/config", { recursive: true })
- copyFileSync("src/config/schema.json", "dist/config/schema.json")
- copyFileSync("package.dist.json", "dist/package.json")
- copyFileSync("npm-shrinkwrap.dist.json", "dist/npm-shrinkwrap.json")
- copyFileSync("README.md", "dist/README.md")
- try {
- copyFileSync(".env", "dist/.env")
- copyFileSync(".env", "dist/kilocode/.env")
- } catch {
- // .env might not exist, that's okay
- }
- console.log("✓ Post-build files copied")
- } catch (err) {
- console.error("Error copying post-build files:", err)
- }
- }
- function removeUnneededFiles() {
- rimrafSync("dist/kilocode/webview-ui")
- rimrafSync("dist/kilocode/assets")
- console.log("✓ Unneeded files removed")
- }
- const afterBuildPlugin = {
- name: "after-build",
- setup(build) {
- build.onEnd((result) => {
- if (result.errors.length > 0) return
- copyPostBuildFiles()
- removeUnneededFiles()
- try {
- chmodSync("dist/index.js", 0o755)
- console.log("✓ dist/index.js made executable")
- } catch (err) {
- console.error("Error making dist/index.js executable:", err)
- }
- })
- },
- }
- const config = {
- entryPoints: ["src/index.ts"],
- bundle: true,
- platform: "node",
- target: "node20",
- format: "esm",
- outfile: "dist/index.js",
- banner: {
- js: `import { createRequire as __createRequire__ } from 'module';
- import { fileURLToPath as __fileURLToPath__ } from 'url';
- import { dirname as __dirname__ } from 'path';
- const require = __createRequire__(import.meta.url);
- const __filename = __fileURLToPath__(import.meta.url);
- const __dirname = __dirname__(__filename);
- `,
- },
- external: [
- // Keep these as external dependencies (will be installed via npm)
- "@anthropic-ai/bedrock-sdk",
- "@anthropic-ai/sdk",
- "@anthropic-ai/vertex-sdk",
- "@aws-sdk/client-bedrock-runtime",
- "@aws-sdk/credential-providers",
- "@google/genai",
- "@lmstudio/sdk",
- "@mistralai/mistralai",
- "@modelcontextprotocol/sdk",
- "@qdrant/js-client-rest",
- "@vscode/codicons",
- "@vscode/ripgrep",
- "async-mutex",
- "axios",
- "chalk",
- "cheerio",
- "chokidar",
- "clone-deep",
- "commander",
- "default-shell",
- "delay",
- "diff",
- "diff-match-patch",
- "dotenv",
- "eventemitter3",
- "exceljs",
- "fast-deep-equal",
- "fast-xml-parser",
- "fastest-levenshtein",
- "fs-extra",
- "fuse.js",
- "fzf",
- "get-folder-size",
- "google-auth-library",
- "gray-matter",
- "i18next",
- "ignore",
- "ink",
- "ink-big-text",
- "ink-gradient",
- "ink-select-input",
- "ink-spinner",
- "ink-table",
- "ink-text-input",
- "is-wsl",
- "isbinaryfile",
- "jotai",
- "jsdom",
- "json5",
- "jwt-decode",
- "lodash.debounce",
- "lru-cache",
- "mammoth",
- "marked",
- "marked-terminal",
- "monaco-vscode-textmate-theme-converter",
- "node-cache",
- "node-ipc",
- "ollama",
- "openai",
- "os-name",
- "p-limit",
- "p-wait-for",
- "pdf-parse",
- "pkce-challenge",
- "pretty-bytes",
- "proper-lockfile",
- "ps-tree",
- "puppeteer-chromium-resolver",
- "puppeteer-core",
- "react",
- "reconnecting-eventsource",
- "sanitize-filename",
- "say",
- "semver",
- "serialize-error",
- "shiki",
- "simple-git",
- "socket.io-client",
- "sound-play",
- "stream-json",
- "strip-bom",
- "tiktoken",
- "tmp",
- "tree-sitter-wasms",
- "ts-node",
- "turndown",
- "undici",
- "uri-js",
- "uuid",
- "vscode-material-icons",
- "vscode-uri",
- "web-tree-sitter",
- "workerpool",
- "yaml",
- "zod",
- ],
- sourcemap: false,
- minify: false,
- treeShaking: true,
- logLevel: "info",
- plugins: [afterBuildPlugin],
- }
- if (process.argv.includes("--watch")) {
- const ctx = await esbuild.context(config)
- await ctx.watch()
- console.log("Watching for changes...")
- } else {
- // Single build
- await esbuild.build(config)
- }
|