@stonerzju/opencode 1.2.19 → 1.2.21
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.
- package/README.md +15 -0
- package/bin/opencode +21 -1
- package/package.json +1 -1
package/README.md
ADDED
package/bin/opencode
CHANGED
|
@@ -4,10 +4,12 @@ import childProcess from "child_process"
|
|
|
4
4
|
import fs from "fs"
|
|
5
5
|
import path from "path"
|
|
6
6
|
import os from "os"
|
|
7
|
+
import { fileURLToPath } from "url"
|
|
7
8
|
|
|
8
9
|
function run(target) {
|
|
9
10
|
const result = childProcess.spawnSync(target, process.argv.slice(2), {
|
|
10
11
|
stdio: "inherit",
|
|
12
|
+
cwd: process.cwd(),
|
|
11
13
|
})
|
|
12
14
|
if (result.error) {
|
|
13
15
|
console.error(result.error.message)
|
|
@@ -22,7 +24,8 @@ const envPath = process.env.OPENCODE_BIN_PATH
|
|
|
22
24
|
if (envPath) {
|
|
23
25
|
run(envPath)
|
|
24
26
|
} else {
|
|
25
|
-
const
|
|
27
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
28
|
+
const __dirname = path.dirname(__filename)
|
|
26
29
|
const target = path.resolve(__dirname, "../src/index.ts")
|
|
27
30
|
|
|
28
31
|
// Check if we're running from a local build or from node_modules
|
|
@@ -31,8 +34,14 @@ if (envPath) {
|
|
|
31
34
|
path.resolve(__dirname, "../node_modules/.bin/bun"),
|
|
32
35
|
path.resolve(__dirname, "../../../.bun/bin/bun"),
|
|
33
36
|
path.resolve(os.homedir(), ".bun/bin/bun"),
|
|
37
|
+
path.resolve(os.homedir(), ".nvm/versions/node/v22.22.0/bin/bun"),
|
|
38
|
+
path.resolve(os.homedir(), ".nvm/versions/node/v22.21.0/bin/bun"),
|
|
39
|
+
path.resolve(os.homedir(), ".nvm/versions/node/v22.20.0/bin/bun"),
|
|
40
|
+
path.resolve(os.homedir(), ".nvm/versions/node/v20.0.0/bin/bun"),
|
|
41
|
+
path.resolve(os.homedir(), ".nvm/versions/node/v18.0.0/bin/bun"),
|
|
34
42
|
"/usr/local/bin/bun",
|
|
35
43
|
"/opt/homebrew/bin/bun",
|
|
44
|
+
"/usr/bin/bun",
|
|
36
45
|
]
|
|
37
46
|
|
|
38
47
|
for (const p of possiblePaths) {
|
|
@@ -45,6 +54,17 @@ if (envPath) {
|
|
|
45
54
|
if (bunPath) {
|
|
46
55
|
run(bunPath)
|
|
47
56
|
} else {
|
|
57
|
+
// Try to find bun using which command
|
|
58
|
+
try {
|
|
59
|
+
const whichResult = childProcess.execSync("which bun", { encoding: "utf-8" }).trim()
|
|
60
|
+
if (whichResult && fs.existsSync(whichResult)) {
|
|
61
|
+
bunPath = whichResult
|
|
62
|
+
run(bunPath)
|
|
63
|
+
}
|
|
64
|
+
} catch {
|
|
65
|
+
// which command failed, continue to fallback
|
|
66
|
+
}
|
|
67
|
+
|
|
48
68
|
// Fallback: try to run with bun from PATH
|
|
49
69
|
run("bun")
|
|
50
70
|
}
|