@stonerzju/opencode 1.2.21 → 1.2.23

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/bin/opencode +24 -53
  2. package/package.json +1 -1
package/bin/opencode CHANGED
@@ -1,71 +1,42 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import childProcess from "child_process"
4
- import fs from "fs"
5
4
  import path from "path"
6
- import os from "os"
7
5
  import { fileURLToPath } from "url"
8
6
 
9
- function run(target) {
10
- const result = childProcess.spawnSync(target, process.argv.slice(2), {
11
- stdio: "inherit",
12
- cwd: process.cwd(),
13
- })
14
- if (result.error) {
15
- console.error(result.error.message)
16
- process.exit(1)
17
- }
18
- const code = typeof result.status === "number" ? result.status : 0
19
- process.exit(code)
20
- }
21
-
22
7
  const envPath = process.env.OPENCODE_BIN_PATH
23
8
 
24
9
  if (envPath) {
25
- run(envPath)
10
+ const result = childProcess.spawnSync(envPath, process.argv.slice(2), {
11
+ stdio: "inherit",
12
+ cwd: process.cwd(),
13
+ })
14
+ process.exit(result.status ?? 1)
26
15
  } else {
27
16
  const __filename = fileURLToPath(import.meta.url)
28
17
  const __dirname = path.dirname(__filename)
29
18
  const target = path.resolve(__dirname, "../src/index.ts")
30
19
 
31
- // Check if we're running from a local build or from node_modules
32
- let bunPath = null
33
- const possiblePaths = [
34
- path.resolve(__dirname, "../node_modules/.bin/bun"),
35
- path.resolve(__dirname, "../../../.bun/bin/bun"),
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"),
42
- "/usr/local/bin/bun",
43
- "/opt/homebrew/bin/bun",
44
- "/usr/bin/bun",
45
- ]
20
+ // Standard practice: rely on PATH to find bun
21
+ // This is how npm, cross-spawn, execa, and all major packages do it
22
+ const result = childProcess.spawnSync("bun", [target, ...process.argv.slice(2)], {
23
+ stdio: "inherit",
24
+ cwd: process.cwd(),
25
+ env: { ...process.env }
26
+ })
46
27
 
47
- for (const p of possiblePaths) {
48
- if (fs.existsSync(p)) {
49
- bunPath = p
50
- break
51
- }
28
+ if (result.error && result.error.code === "ENOENT") {
29
+ console.error("Error: bun not found in PATH")
30
+ console.error("")
31
+ console.error("Please install bun:")
32
+ console.error(" curl -fsSL https://bun.sh/install | bash")
33
+ console.error("")
34
+ console.error("Or visit: https://bun.sh/docs/installation")
35
+ console.error("")
36
+ console.error("After installation, make sure bun is in your PATH:")
37
+ console.error(" which bun")
38
+ console.error("")
52
39
  }
53
40
 
54
- if (bunPath) {
55
- run(bunPath)
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
-
68
- // Fallback: try to run with bun from PATH
69
- run("bun")
70
- }
41
+ process.exit(result.status ?? 1)
71
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "1.2.21",
3
+ "version": "1.2.23",
4
4
  "name": "@stonerzju/opencode",
5
5
  "type": "module",
6
6
  "license": "MIT",