@code0123/opencode-ai 1.1.53

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 opencode
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/bin/opencode ADDED
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env node
2
+
3
+ const childProcess = require("child_process")
4
+ const fs = require("fs")
5
+ const path = require("path")
6
+ const { detectPlatformAndArch, packageNames } = require("./platform.cjs")
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
+ }
19
+
20
+ const envPath = process.env.OPENCODE_BIN_PATH
21
+ if (envPath) {
22
+ run(envPath)
23
+ }
24
+
25
+ const scriptPath = fs.realpathSync(__filename)
26
+ const scriptDir = path.dirname(scriptPath)
27
+
28
+ const { platform, arch } = detectPlatformAndArch()
29
+ const prefixes = packageNames(platform, arch)
30
+ const base = prefixes[0]
31
+ const binary = platform === "windows" ? "opencode.exe" : "opencode"
32
+
33
+ function match(entry, prefix) {
34
+ return entry === prefix || entry === prefix + "-baseline"
35
+ }
36
+
37
+ function matchInModules(modules, prefix) {
38
+ const entries = fs.readdirSync(modules)
39
+ for (const entry of entries) {
40
+ if (match(entry, prefix)) {
41
+ const candidate = path.join(modules, entry, "bin", binary)
42
+ if (fs.existsSync(candidate)) {
43
+ return candidate
44
+ }
45
+ }
46
+ if (!entry.startsWith("@")) {
47
+ continue
48
+ }
49
+ const scope = path.join(modules, entry)
50
+ if (!fs.existsSync(scope) || !fs.statSync(scope).isDirectory()) {
51
+ continue
52
+ }
53
+ for (const nested of fs.readdirSync(scope)) {
54
+ if (!match(nested, prefix)) {
55
+ continue
56
+ }
57
+ const candidate = path.join(scope, nested, "bin", binary)
58
+ if (fs.existsSync(candidate)) {
59
+ return candidate
60
+ }
61
+ }
62
+ }
63
+ }
64
+
65
+ function findBinary(startDir) {
66
+ let current = startDir
67
+ for (;;) {
68
+ const modules = path.join(current, "node_modules")
69
+ if (fs.existsSync(modules)) {
70
+ for (const prefix of prefixes) {
71
+ const candidate = matchInModules(modules, prefix)
72
+ if (candidate) {
73
+ return candidate
74
+ }
75
+ }
76
+ }
77
+ const parent = path.dirname(current)
78
+ if (parent === current) {
79
+ return
80
+ }
81
+ current = parent
82
+ }
83
+ }
84
+
85
+ const resolved = findBinary(scriptDir)
86
+ if (!resolved) {
87
+ console.error(
88
+ 'It seems that your package manager failed to install the right version of the opencode CLI for your platform. You can try manually installing the "' +
89
+ base +
90
+ '" package',
91
+ )
92
+ process.exit(1)
93
+ }
94
+
95
+ run(resolved)
@@ -0,0 +1,35 @@
1
+ const os = require("os")
2
+
3
+ const platformMap = {
4
+ android: "android",
5
+ darwin: "darwin",
6
+ linux: "linux",
7
+ win32: "windows",
8
+ }
9
+
10
+ const archMap = {
11
+ x64: "x64",
12
+ arm64: "arm64",
13
+ arm: "arm",
14
+ }
15
+
16
+ function detectPlatformAndArch() {
17
+ const platform = platformMap[os.platform()] || os.platform()
18
+ const arch = archMap[os.arch()] || os.arch()
19
+ return { platform, arch }
20
+ }
21
+
22
+ function packageNames(platform, arch) {
23
+ const names = [`opencode-${platform}-${arch}`]
24
+ if (platform !== "android") {
25
+ return names
26
+ }
27
+ names.push(`opencode-linux-${arch}`)
28
+ names.push(`opencode-linux-${arch}-musl`)
29
+ return names
30
+ }
31
+
32
+ module.exports = {
33
+ detectPlatformAndArch,
34
+ packageNames,
35
+ }
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@code0123/opencode-ai",
3
+ "bin": {
4
+ "opencode": "./bin/opencode"
5
+ },
6
+ "scripts": {
7
+ "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
8
+ },
9
+ "version": "1.1.53",
10
+ "license": "MIT",
11
+ "optionalDependencies": {
12
+ "@code0123/opencode-android-arm64": "1.1.53"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ }
17
+ }
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "fs"
4
+ import path from "path"
5
+ import os from "os"
6
+ import { fileURLToPath } from "url"
7
+ import { createRequire } from "module"
8
+
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
10
+ const require = createRequire(import.meta.url)
11
+ const platformPath = fs.existsSync(path.join(__dirname, "bin", "platform.cjs")) ? "./bin/platform.cjs" : "../bin/platform.cjs"
12
+ const { detectPlatformAndArch, packageNames } = require(platformPath)
13
+
14
+ function packageCandidates(names) {
15
+ const values = [...names]
16
+ let current = __dirname
17
+ for (;;) {
18
+ const modules = path.join(current, "node_modules")
19
+ if (fs.existsSync(modules)) {
20
+ for (const entry of fs.readdirSync(modules)) {
21
+ if (!entry.startsWith("@")) {
22
+ continue
23
+ }
24
+ for (const name of names) {
25
+ values.push(`${entry}/${name}`)
26
+ }
27
+ }
28
+ break
29
+ }
30
+ const parent = path.dirname(current)
31
+ if (parent === current) {
32
+ break
33
+ }
34
+ current = parent
35
+ }
36
+ return [...new Set(values)]
37
+ }
38
+
39
+ function findBinary() {
40
+ const { platform, arch } = detectPlatformAndArch()
41
+ const names = packageCandidates(packageNames(platform, arch))
42
+ const binaryName = platform === "windows" ? "opencode.exe" : "opencode"
43
+ let reason = ""
44
+
45
+ for (const packageName of names) {
46
+ try {
47
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
48
+ const packageDir = path.dirname(packageJsonPath)
49
+ const binaryPath = path.join(packageDir, "bin", binaryName)
50
+
51
+ if (!fs.existsSync(binaryPath)) {
52
+ reason = `Binary not found at ${binaryPath}`
53
+ continue
54
+ }
55
+
56
+ return { binaryPath, binaryName, packageName }
57
+ } catch (error) {
58
+ reason = error.message
59
+ }
60
+ }
61
+
62
+ throw new Error(`Could not find compatible package (${names.join(", ")}): ${reason}`)
63
+ }
64
+
65
+ function prepareBinDirectory(binaryName) {
66
+ const binDir = path.join(__dirname, "bin")
67
+ const targetPath = path.join(binDir, binaryName)
68
+
69
+ // Ensure bin directory exists
70
+ if (!fs.existsSync(binDir)) {
71
+ fs.mkdirSync(binDir, { recursive: true })
72
+ }
73
+
74
+ // Remove existing binary/symlink if it exists
75
+ if (fs.existsSync(targetPath)) {
76
+ fs.unlinkSync(targetPath)
77
+ }
78
+
79
+ return { binDir, targetPath }
80
+ }
81
+
82
+ function symlinkBinary(sourcePath, binaryName) {
83
+ const { targetPath } = prepareBinDirectory(binaryName)
84
+
85
+ fs.symlinkSync(sourcePath, targetPath)
86
+ console.log(`opencode binary symlinked: ${targetPath} -> ${sourcePath}`)
87
+
88
+ // Verify the file exists after operation
89
+ if (!fs.existsSync(targetPath)) {
90
+ throw new Error(`Failed to symlink binary to ${targetPath}`)
91
+ }
92
+ }
93
+
94
+ async function main() {
95
+ try {
96
+ if (os.platform() === "win32") {
97
+ // On Windows, the .exe is already included in the package and bin field points to it
98
+ // No postinstall setup needed
99
+ console.log("Windows detected: binary setup not needed (using packaged .exe)")
100
+ return
101
+ }
102
+
103
+ // On non-Windows platforms, just verify the binary package exists
104
+ // Don't replace the wrapper script - it handles binary execution
105
+ const { binaryPath, packageName } = findBinary()
106
+ console.log(`Resolved package: ${packageName}`)
107
+ console.log(`Platform binary verified at: ${binaryPath}`)
108
+ console.log("Wrapper script will handle binary execution")
109
+ } catch (error) {
110
+ console.error("Failed to setup opencode binary:", error.message)
111
+ process.exit(1)
112
+ }
113
+ }
114
+
115
+ try {
116
+ main()
117
+ } catch (error) {
118
+ console.error("Postinstall script error:", error.message)
119
+ process.exit(0)
120
+ }