-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.mjs
More file actions
48 lines (41 loc) · 1.42 KB
/
build.mjs
File metadata and controls
48 lines (41 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env node
/**
* Build script to bundle LSP tools with all dependencies.
*
* Each tool in .opencode/tools/*.ts becomes a self-contained bundled file
* in tools/*.ts with the same name.
*/
import * as esbuild from "esbuild";
import { readdirSync, mkdirSync, rmSync } from "node:fs";
import { join, basename } from "node:path";
const SOURCE_DIR = ".opencode/tools";
const OUTPUT_DIR = "tools";
// Find all top-level .ts tool files (not in lib/)
const toolFiles = readdirSync(SOURCE_DIR)
.filter((f) => f.endsWith(".ts") && !f.startsWith("."))
.map((f) => join(SOURCE_DIR, f));
console.log(`Found ${toolFiles.length} tools to bundle:`);
toolFiles.forEach((f) => console.log(` - ${basename(f)}`));
// Clean and create output directory
rmSync(OUTPUT_DIR, { recursive: true, force: true });
mkdirSync(OUTPUT_DIR, { recursive: true });
// Bundle each tool
await esbuild.build({
entryPoints: toolFiles,
outdir: OUTPUT_DIR,
bundle: true,
platform: "node",
target: "node20",
format: "esm",
// Keep .ts extension in output filenames
outExtension: { ".js": ".ts" },
// Bundle everything except node builtins
packages: "bundle",
// Mark @opencode-ai/plugin as external (provided by runtime)
external: ["@opencode-ai/plugin"],
// Generate readable output for debugging
minify: false,
// Preserve legal comments
legalComments: "inline",
});
console.log(`\nBundled ${toolFiles.length} tools to ${OUTPUT_DIR}/`);