mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-08-28 11:05:31 +08:00
fix(cli): preserve tree-sitter installer resources
This commit is contained in:
@@ -348,6 +348,10 @@ download_and_install() {
|
||||
|
||||
# kilocode_change start
|
||||
mv "$tmp_dir/kilo" "$INSTALL_DIR"
|
||||
rm -rf "${INSTALL_DIR}/tree-sitter"
|
||||
if [ -d "$tmp_dir/tree-sitter" ]; then
|
||||
mv "$tmp_dir/tree-sitter" "$INSTALL_DIR"
|
||||
fi
|
||||
chmod 755 "${INSTALL_DIR}/kilo"
|
||||
# kilocode_change end
|
||||
rm -rf "$tmp_dir"
|
||||
|
||||
@@ -5,13 +5,17 @@ const fs = require("fs")
|
||||
const path = require("path")
|
||||
const os = require("os")
|
||||
|
||||
function run(target) {
|
||||
// kilocode_change start - point packaged binaries at co-located tree-sitter WASM resources
|
||||
// kilocode_change start - point packaged binaries at co-located tree-sitter WASM resources
|
||||
function configureTreeSitterResources(target) {
|
||||
const wasmDir = path.join(path.dirname(target), "tree-sitter")
|
||||
if (!process.env.KILO_TREE_SITTER_WASM_DIR && fs.existsSync(path.join(wasmDir, "tree-sitter.wasm"))) {
|
||||
process.env.KILO_TREE_SITTER_WASM_DIR = wasmDir
|
||||
}
|
||||
// kilocode_change end
|
||||
}
|
||||
// kilocode_change end
|
||||
|
||||
function run(target) {
|
||||
configureTreeSitterResources(target) // kilocode_change
|
||||
const result = childProcess.spawnSync(target, process.argv.slice(2), {
|
||||
stdio: "inherit",
|
||||
})
|
||||
@@ -34,6 +38,7 @@ const scriptDir = path.dirname(scriptPath)
|
||||
// kilocode_change start - fall through to findBinary() if cached binary fails
|
||||
const cached = path.join(scriptDir, ".kilo")
|
||||
if (fs.existsSync(cached)) {
|
||||
configureTreeSitterResources(cached)
|
||||
const result = childProcess.spawnSync(cached, process.argv.slice(2), {
|
||||
stdio: "inherit",
|
||||
})
|
||||
|
||||
@@ -18,25 +18,28 @@ describe("bin/kilo tree-sitter resources", () => {
|
||||
await writeFile(join(wasm, "tree-sitter.wasm"), "wasm")
|
||||
await writeFile(bin, "binary")
|
||||
|
||||
return { bin, log, wasm }
|
||||
return { bin, log, wasm, wrapper: join(dir, "kilo") }
|
||||
}
|
||||
|
||||
async function run(root: string, bin: string, log: string) {
|
||||
async function run(root: string, bin: string | undefined, log: string, wrapper?: string) {
|
||||
const capture = `
|
||||
const kiloFs = require("fs")
|
||||
const kiloChild = require("child_process")
|
||||
const log = process.argv[1]
|
||||
const wrapper = process.argv[2]
|
||||
const realpathSync = kiloFs.realpathSync
|
||||
kiloFs.realpathSync = (file) => wrapper && file === __filename ? wrapper : realpathSync(file)
|
||||
kiloChild.spawnSync = () => {
|
||||
kiloFs.writeFileSync(log, process.env.KILO_TREE_SITTER_WASM_DIR || "")
|
||||
return { status: 0 }
|
||||
}
|
||||
`
|
||||
const source = (await Bun.file(script).text()).replace(/^#!.*\n/, "")
|
||||
return Bun.spawnSync(["node", "--input-type=commonjs", "--eval", capture + source, log], {
|
||||
return Bun.spawnSync(["node", "--input-type=commonjs", "--eval", capture + source, log, wrapper ?? ""], {
|
||||
cwd: root,
|
||||
env: {
|
||||
PATH: process.env.PATH ?? "",
|
||||
KILO_BIN_PATH: bin,
|
||||
...(bin ? { KILO_BIN_PATH: bin } : {}),
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -58,7 +61,7 @@ kiloChild.spawnSync = () => {
|
||||
const root = await mkdtemp(join(tmpdir(), "kilo-bin-tree-sitter-"))
|
||||
try {
|
||||
const item = await setup(root, false)
|
||||
const proc = await run(root, item.bin, item.log)
|
||||
const proc = await run(root, undefined, item.log, item.wrapper)
|
||||
|
||||
expect(proc.exitCode).toBe(0)
|
||||
expect(await Bun.file(item.log).text()).toBe(item.wasm)
|
||||
|
||||
Reference in New Issue
Block a user