@stonerzju/opencode 1.2.22 → 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 +19 -52
  2. package/package.json +1 -1
package/bin/opencode CHANGED
@@ -1,9 +1,7 @@
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
7
  const envPath = process.env.OPENCODE_BIN_PATH
@@ -19,57 +17,26 @@ if (envPath) {
19
17
  const __dirname = path.dirname(__filename)
20
18
  const target = path.resolve(__dirname, "../src/index.ts")
21
19
 
22
- // Check if we're running from a local build or from node_modules
23
- let bunPath = null
24
- const possiblePaths = [
25
- path.resolve(__dirname, "../node_modules/.bin/bun"),
26
- path.resolve(__dirname, "../../../.bun/bin/bun"),
27
- path.resolve(os.homedir(), ".bun/bin/bun"),
28
- path.resolve(os.homedir(), ".nvm/versions/node/v22.22.0/bin/bun"),
29
- path.resolve(os.homedir(), ".nvm/versions/node/v22.21.0/bin/bun"),
30
- path.resolve(os.homedir(), ".nvm/versions/node/v22.20.0/bin/bun"),
31
- path.resolve(os.homedir(), ".nvm/versions/node/v20.0.0/bin/bun"),
32
- path.resolve(os.homedir(), ".nvm/versions/node/v18.0.0/bin/bun"),
33
- "/usr/local/bin/bun",
34
- "/opt/homebrew/bin/bun",
35
- "/usr/bin/bun",
36
- ]
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
+ })
37
27
 
38
- for (const p of possiblePaths) {
39
- if (fs.existsSync(p)) {
40
- bunPath = p
41
- break
42
- }
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("")
43
39
  }
44
40
 
45
- if (bunPath) {
46
- // Use execSync instead of spawnSync for better handling
47
- const result = childProcess.spawnSync(bunPath, [target, ...process.argv.slice(2)], {
48
- stdio: "inherit",
49
- cwd: process.cwd(),
50
- env: { ...process.env }
51
- })
52
- process.exit(result.status ?? 1)
53
- } else {
54
- // Try to find bun using which command
55
- try {
56
- const whichResult = childProcess.execSync("which bun", { encoding: "utf-8" }).trim()
57
- if (whichResult && fs.existsSync(whichResult)) {
58
- const result = childProcess.spawnSync(whichResult, [target, ...process.argv.slice(2)], {
59
- stdio: "inherit",
60
- cwd: process.cwd(),
61
- })
62
- process.exit(result.status ?? 1)
63
- }
64
- } catch {
65
- // which command failed, continue to fallback
66
- }
67
-
68
- // Fallback: try to run with bun from PATH
69
- const result = childProcess.spawnSync("bun", [target, ...process.argv.slice(2)], {
70
- stdio: "inherit",
71
- cwd: process.cwd(),
72
- })
73
- process.exit(result.status ?? 1)
74
- }
41
+ process.exit(result.status ?? 1)
75
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "1.2.22",
3
+ "version": "1.2.23",
4
4
  "name": "@stonerzju/opencode",
5
5
  "type": "module",
6
6
  "license": "MIT",