mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-10-29 18:52:45 +08:00
perf(vscode): parallelize build validation and cache SDK generation (#12807)
Run extension typecheck, webview typecheck, ESLint, and esbuild concurrently instead of serially. Replace tsc with the repository-standard tsgo for both typechecks. Enable ESLint's content-addressed cache. Run the esbuild driver with Bun instead of Node. Add a launch-only SDK generation cache keyed by CLI/API input fingerprint and generated SDK output fingerprint. Explicit compile, package, and rebuild-sdk commands still force full SDK regeneration. Add CSS module declarations required by tsgo for the webview.
This commit is contained in:
@@ -1191,23 +1191,29 @@
|
||||
},
|
||||
"scripts": {
|
||||
"prepare:cli-binary": "bun script/local-bin.ts",
|
||||
"compile": "bun run prepare:cli-binary -- --force && bun run rebuild-sdk && bun run typecheck && bun run lint && node esbuild.js",
|
||||
"prepare:sdk": "bun script/prepare-sdk.ts",
|
||||
"build:launch": "bun run prepare:cli-binary && bun run prepare:sdk && bun run build:check:production",
|
||||
"compile": "bun run prepare:cli-binary -- --force && bun run rebuild-sdk && bun run build:check",
|
||||
"watch": "bun run rebuild-sdk && bun run --parallel watch:esbuild watch:tsc",
|
||||
"watch:esbuild": "bun run prepare:cli-binary && node esbuild.js --watch",
|
||||
"watch:tsc": "tsc --noEmit --watch --project tsconfig.json",
|
||||
"watch:cli": "bun script/watch-cli.ts",
|
||||
"package": "bun run prepare:cli-binary && bun run rebuild-sdk && bun run typecheck && bun run lint && node esbuild.js --production",
|
||||
"package": "bun run prepare:cli-binary && bun run rebuild-sdk && bun run build:check:production",
|
||||
"build:check": "bun run --parallel check-types check-types:webview lint bundle",
|
||||
"build:check:production": "bun run --parallel check-types check-types:webview lint bundle:production",
|
||||
"bundle": "bun esbuild.js",
|
||||
"bundle:production": "bun esbuild.js --production",
|
||||
"compile-tests": "tsc -p . --outDir out",
|
||||
"watch-tests": "tsc -p . -w --outDir out",
|
||||
"pretest": "bun run compile-tests && bun run compile && bun run lint",
|
||||
"check-types": "tsc --noEmit",
|
||||
"check-types:webview": "tsc --noEmit --project webview-ui/tsconfig.json",
|
||||
"typecheck": "bun run check-types && bun run check-types:webview",
|
||||
"check-types": "tsgo --noEmit",
|
||||
"check-types:webview": "tsgo --noEmit --project webview-ui/tsconfig.json",
|
||||
"typecheck": "bun run --parallel check-types check-types:webview",
|
||||
"format": "prettier --write .",
|
||||
"format:check": "prettier --check .",
|
||||
"knip": "knip",
|
||||
"check-kilocode-change": "! grep -rIn 'kilocode_change' . ../kilo-ui/ --exclude='package.json' --exclude='*.md' --exclude-dir='node_modules' --exclude-dir='dist' | grep -v '`kilocode_change`'",
|
||||
"lint": "eslint src webview-ui",
|
||||
"lint": "eslint --cache --cache-strategy content --cache-location node_modules/.cache/eslint src webview-ui",
|
||||
"test": "vscode-test",
|
||||
"test:unit": "bun test tests/unit/ --dots",
|
||||
"rebuild-sdk": "bun run --cwd ../sdk/js build",
|
||||
|
||||
@@ -241,7 +241,7 @@ async function compile() {
|
||||
}
|
||||
|
||||
console.log("[launch] Building extension...")
|
||||
await $`bun run package`.cwd(root).env(cleanEnv(process.env))
|
||||
await $`bun run build:launch`.cwd(root).env(cleanEnv(process.env))
|
||||
console.log("[launch] Build complete")
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env bun
|
||||
import { $ } from "bun"
|
||||
import { createHash } from "node:crypto"
|
||||
import { existsSync, mkdirSync } from "node:fs"
|
||||
import { dirname, join } from "node:path"
|
||||
|
||||
const root = join(import.meta.dir, "..")
|
||||
const repo = join(root, "..", "..")
|
||||
const sdk = join(repo, "packages", "sdk", "js")
|
||||
const cache = join(root, "node_modules", ".cache", "sdk-build.json")
|
||||
const inputs = [
|
||||
"package.json",
|
||||
"bun.lock",
|
||||
"packages/opencode",
|
||||
"packages/core",
|
||||
"packages/effect-drizzle-sqlite",
|
||||
"packages/effect-sqlite-node",
|
||||
"packages/kilo-gateway",
|
||||
"packages/kilo-indexing",
|
||||
"packages/kilo-memory",
|
||||
"packages/kilo-sandbox",
|
||||
"packages/kilo-telemetry",
|
||||
"packages/llm",
|
||||
"packages/plugin",
|
||||
"packages/plugin-atomic-chat",
|
||||
"packages/server",
|
||||
"packages/util",
|
||||
"packages/sdk/js/package.json",
|
||||
"packages/sdk/js/tsconfig.json",
|
||||
"packages/sdk/js/script",
|
||||
"packages/kilo-vscode/script/prepare-sdk.ts",
|
||||
]
|
||||
const outputs = ["packages/sdk/js/src"]
|
||||
|
||||
function log(msg: string) {
|
||||
console.log(`[prepare-sdk] ${msg}`)
|
||||
}
|
||||
|
||||
async function fingerprint(paths: string[]) {
|
||||
const [tree, diff, extra] = await Promise.all([
|
||||
$`git ls-tree -r HEAD -- ${paths}`.cwd(repo).quiet(),
|
||||
$`git diff --binary HEAD -- ${paths}`.cwd(repo).quiet(),
|
||||
$`git ls-files --others --exclude-standard -z -- ${paths}`.cwd(repo).quiet(),
|
||||
])
|
||||
const hash = createHash("sha256").update(tree.text()).update(diff.text())
|
||||
const files = extra.text().split("\0").filter(Boolean).sort()
|
||||
|
||||
for (const file of files) {
|
||||
hash.update(file)
|
||||
hash.update(new Uint8Array(await Bun.file(join(repo, file)).arrayBuffer()))
|
||||
}
|
||||
|
||||
return hash.digest("hex")
|
||||
}
|
||||
|
||||
async function load() {
|
||||
const file = Bun.file(cache)
|
||||
if (!(await file.exists())) return
|
||||
|
||||
try {
|
||||
const value: unknown = await file.json()
|
||||
if (!value || typeof value !== "object") return
|
||||
const input = Reflect.get(value, "input")
|
||||
const output = Reflect.get(value, "output")
|
||||
if (typeof input === "string" && typeof output === "string") return { input, output }
|
||||
} catch (err) {
|
||||
log(`Ignoring invalid cache: ${err instanceof Error ? err.message : String(err)}`)
|
||||
}
|
||||
}
|
||||
|
||||
const input = await fingerprint(inputs)
|
||||
const prior = await load()
|
||||
const ready = existsSync(join(sdk, "dist", "index.js")) && existsSync(join(sdk, "dist", "v2", "index.js"))
|
||||
|
||||
if (prior?.input === input && prior.output === (await fingerprint(outputs)) && ready) {
|
||||
log("SDK inputs and generated output are unchanged")
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
log("SDK inputs changed, rebuilding generated client")
|
||||
await $`bun run build`.cwd(sdk)
|
||||
|
||||
mkdirSync(dirname(cache), { recursive: true })
|
||||
await Bun.write(cache, JSON.stringify({ input, output: await fingerprint(outputs) }) + "\n")
|
||||
@@ -3,6 +3,9 @@ declare module "*.svg" {
|
||||
export default src
|
||||
}
|
||||
|
||||
declare module "*.css"
|
||||
declare module "@kilocode/kilo-ui/styles"
|
||||
|
||||
declare module "*?worker&url" {
|
||||
const src: string
|
||||
export default src
|
||||
|
||||
Reference in New Issue
Block a user