@xinleibird/bridge-opencode 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bridge.ts +41 -5
  2. package/package.json +3 -4
package/bridge.ts CHANGED
@@ -1,10 +1,46 @@
1
1
  import type { Plugin } from "@opencode-ai/plugin";
2
2
  import { isAbsolute, join } from "node:path";
3
- import {
4
- checkBuffer,
5
- refreshBuffer,
6
- getVisualSelections,
7
- } from "./bridge-opencode.js";
3
+ import { createRequire } from "node:module";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ const _require = createRequire(import.meta.url);
7
+ const __dirname = join(fileURLToPath(import.meta.url), "..");
8
+
9
+ const TRIPLES = [
10
+ `bridge-opencode.${process.platform}-${process.arch}.node`,
11
+ "bridge-opencode.node",
12
+ ];
13
+
14
+ let native: {
15
+ checkBuffer(filePath: string): { isCurrent: boolean; hasUnsavedChanges: boolean };
16
+ refreshBuffer(filePath: string): void;
17
+ getVisualSelections(): Array<{
18
+ filePath: string;
19
+ startLine: number;
20
+ endLine: number;
21
+ cwd: string;
22
+ content: string;
23
+ }>;
24
+ sendMessage(message: string): void;
25
+ };
26
+
27
+ for (const name of TRIPLES) {
28
+ try {
29
+ native = _require(join(__dirname, name));
30
+ break;
31
+ } catch {
32
+ // try next triple
33
+ }
34
+ }
35
+
36
+ if (!native) {
37
+ throw new Error(
38
+ "bridge-opencode: native addon not found (tried darwin-arm64 and generic). " +
39
+ "Install with `npm install @xinleibird/bridge-opencode` to compile from source.",
40
+ );
41
+ }
42
+
43
+ const { checkBuffer, refreshBuffer, getVisualSelections } = native;
8
44
 
9
45
  type ToolName = "Edit" | "Write";
10
46
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xinleibird/bridge-opencode",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -13,8 +13,7 @@
13
13
  }
14
14
  },
15
15
  "scripts": {
16
- "build": "napi build --platform --release",
17
- "postinstall": "npm run build"
16
+ "build": "napi build --platform --release"
18
17
  },
19
18
  "napi": {
20
19
  "name": "bridge-opencode",
@@ -26,7 +25,7 @@
26
25
  ]
27
26
  }
28
27
  },
29
- "dependencies": {
28
+ "devDependencies": {
30
29
  "@napi-rs/cli": "^2.18.0"
31
30
  },
32
31
  "peerDependencies": {