@stonerzju/opencode 1.2.20 → 1.2.22

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 +25 -18
  2. package/package.json +1 -1
package/bin/opencode CHANGED
@@ -4,25 +4,19 @@ import childProcess from "child_process"
4
4
  import fs from "fs"
5
5
  import path from "path"
6
6
  import os from "os"
7
-
8
- function run(target) {
9
- const result = childProcess.spawnSync(target, process.argv.slice(2), {
10
- stdio: "inherit",
11
- })
12
- if (result.error) {
13
- console.error(result.error.message)
14
- process.exit(1)
15
- }
16
- const code = typeof result.status === "number" ? result.status : 0
17
- process.exit(code)
18
- }
7
+ import { fileURLToPath } from "url"
19
8
 
20
9
  const envPath = process.env.OPENCODE_BIN_PATH
21
10
 
22
11
  if (envPath) {
23
- run(envPath)
12
+ const result = childProcess.spawnSync(envPath, process.argv.slice(2), {
13
+ stdio: "inherit",
14
+ cwd: process.cwd(),
15
+ })
16
+ process.exit(result.status ?? 1)
24
17
  } else {
25
- const __dirname = path.dirname(new URL(import.meta.url).pathname)
18
+ const __filename = fileURLToPath(import.meta.url)
19
+ const __dirname = path.dirname(__filename)
26
20
  const target = path.resolve(__dirname, "../src/index.ts")
27
21
 
28
22
  // Check if we're running from a local build or from node_modules
@@ -49,20 +43,33 @@ if (envPath) {
49
43
  }
50
44
 
51
45
  if (bunPath) {
52
- run(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
53
  } else {
54
54
  // Try to find bun using which command
55
55
  try {
56
56
  const whichResult = childProcess.execSync("which bun", { encoding: "utf-8" }).trim()
57
57
  if (whichResult && fs.existsSync(whichResult)) {
58
- bunPath = whichResult
59
- run(bunPath)
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)
60
63
  }
61
64
  } catch {
62
65
  // which command failed, continue to fallback
63
66
  }
64
67
 
65
68
  // Fallback: try to run with bun from PATH
66
- run("bun")
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)
67
74
  }
68
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "1.2.20",
3
+ "version": "1.2.22",
4
4
  "name": "@stonerzju/opencode",
5
5
  "type": "module",
6
6
  "license": "MIT",