Skip to content

Commit 3f0f910

Browse files
CaffeeLakeopencode
authored andcommitted
Fix: Error [ERR_DLOPEN_FAILED] (anomalyco#1546)
1 parent 5bf841a commit 3f0f910

7 files changed

Lines changed: 79 additions & 35 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717

1818
- uses: oven-sh/setup-bun@v1
1919
with:
20-
bun-version: 1.2.17
20+
bun-version: 1.2.19
2121

2222
- run: bun install
2323

.github/workflows/publish-vscode.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
- uses: oven-sh/setup-bun@v2
2323
with:
24-
bun-version: 1.2.17
24+
bun-version: 1.2.19
2525

2626
- run: git fetch --force --tags
2727
- run: bun install -g @vscode/vsce

bun.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "opencode",
44
"private": true,
55
"type": "module",
6-
"packageManager": "bun@1.2.14",
6+
"packageManager": "bun@1.2.19",
77
"scripts": {
88
"dev": "bun run --conditions=development packages/opencode/src/index.ts",
99
"typecheck": "bun run --filter='*' typecheck",
@@ -46,7 +46,10 @@
4646
"trustedDependencies": [
4747
"esbuild",
4848
"protobufjs",
49-
"sharp"
49+
"sharp",
50+
"tree-sitter",
51+
"tree-sitter-bash",
52+
"web-tree-sitter"
5053
],
5154
"patchedDependencies": {}
5255
}

packages/opencode/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"remeda": "catalog:",
5353
"tree-sitter": "0.22.4",
5454
"tree-sitter-bash": "0.23.3",
55+
"web-tree-sitter": "0.22.6",
5556
"turndown": "7.2.0",
5657
"vscode-jsonrpc": "8.2.1",
5758
"xdg-basedir": "5.1.0",

packages/opencode/src/tool/bash.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,28 @@ const MAX_TIMEOUT = 10 * 60 * 1000
1919
const log = Log.create({ service: "bash-tool" })
2020

2121
const parser = lazy(async () => {
22-
const { default: Parser } = await import("tree-sitter")
23-
const Bash = await import("tree-sitter-bash")
24-
const p = new Parser()
25-
p.setLanguage(Bash.language as any)
26-
return p
22+
try {
23+
const { default: Parser } = await import("tree-sitter")
24+
const Bash = await import("tree-sitter-bash")
25+
const p = new Parser()
26+
p.setLanguage(Bash.language as any)
27+
return p
28+
} catch (e) {
29+
const { default: Parser } = await import("web-tree-sitter")
30+
const { default: treeWasm } = await import("web-tree-sitter/tree-sitter.wasm" as string, { with: { type: "wasm" } })
31+
await Parser.init({
32+
locateFile() {
33+
return treeWasm
34+
},
35+
})
36+
const { default: bashWasm } = await import("tree-sitter-bash/tree-sitter-bash.wasm" as string, {
37+
with: { type: "wasm" },
38+
})
39+
const bashLanguage = await Parser.Language.load(bashWasm)
40+
const p = new Parser()
41+
p.setLanguage(bashLanguage)
42+
return p
43+
}
2744
})
2845

2946
export const BashTool = Tool.define("bash", {

packages/opencode/src/tool/test.ts

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,70 @@
1-
import Parser from "tree-sitter";
2-
import Bash from "tree-sitter-bash";
3-
4-
const parser = new Parser();
5-
parser.setLanguage(Bash.language as any);
1+
const parser = async () => {
2+
try {
3+
const { default: Parser } = await import("tree-sitter")
4+
const Bash = await import("tree-sitter-bash")
5+
const p = new Parser()
6+
p.setLanguage(Bash.language as any)
7+
return p
8+
} catch (e) {
9+
const { default: Parser } = await import("web-tree-sitter")
10+
const { default: treeWasm } = await import("web-tree-sitter/tree-sitter.wasm" as string, { with: { type: "wasm" } })
11+
await Parser.init({
12+
locateFile() {
13+
return treeWasm
14+
},
15+
})
16+
const { default: bashWasm } = await import("tree-sitter-bash/tree-sitter-bash.wasm" as string, {
17+
with: { type: "wasm" },
18+
})
19+
const bashLanguage = await Parser.Language.load(bashWasm)
20+
const p = new Parser()
21+
p.setLanguage(bashLanguage)
22+
return p
23+
}
24+
}
625

7-
const sourceCode = `cd --foo foo/bar && echo "hello" && cd ../baz`;
26+
const sourceCode = `cd --foo foo/bar && echo "hello" && cd ../baz`
827

9-
const tree = parser.parse(sourceCode);
28+
const tree = await parser().then((p) => p.parse(sourceCode))
1029

1130
// Function to extract commands and arguments
12-
function extractCommands(
13-
node: any,
14-
): Array<{ command: string; args: string[] }> {
15-
const commands: Array<{ command: string; args: string[] }> = [];
31+
function extractCommands(node: any): Array<{ command: string; args: string[] }> {
32+
const commands: Array<{ command: string; args: string[] }> = []
1633

1734
function traverse(node: any) {
1835
if (node.type === "command") {
19-
const commandNode = node.child(0);
36+
const commandNode = node.child(0)
2037
if (commandNode) {
21-
const command = commandNode.text;
22-
const args: string[] = [];
38+
const command = commandNode.text
39+
const args: string[] = []
2340

2441
// Extract arguments
2542
for (let i = 1; i < node.childCount; i++) {
26-
const child = node.child(i);
43+
const child = node.child(i)
2744
if (child && child.type === "word") {
28-
args.push(child.text);
45+
args.push(child.text)
2946
}
3047
}
3148

32-
commands.push({ command, args });
49+
commands.push({ command, args })
3350
}
3451
}
3552

3653
// Traverse children
3754
for (let i = 0; i < node.childCount; i++) {
38-
traverse(node.child(i));
55+
traverse(node.child(i))
3956
}
4057
}
4158

42-
traverse(node);
43-
return commands;
59+
traverse(node)
60+
return commands
4461
}
4562

4663
// Extract and display commands
47-
console.log("Source code: " + sourceCode);
48-
const commands = extractCommands(tree.rootNode);
49-
console.log("Extracted commands:");
64+
console.log("Source code: " + sourceCode)
65+
const commands = extractCommands(tree.rootNode)
66+
console.log("Extracted commands:")
5067
commands.forEach((cmd, index) => {
51-
console.log(`${index + 1}. Command: ${cmd.command}`);
52-
console.log(` Args: [${cmd.args.join(", ")}]`);
53-
});
68+
console.log(`${index + 1}. Command: ${cmd.command}`)
69+
console.log(` Args: [${cmd.args.join(", ")}]`)
70+
})

0 commit comments

Comments
 (0)