meet-code 1.2.6
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/bin/opencode +61 -0
- package/bin/opencode.cmd +58 -0
- package/package.json +20 -0
- package/postinstall.mjs +135 -0
- package/preinstall.mjs +44 -0
package/bin/opencode
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
set -e
|
|
3
|
+
|
|
4
|
+
if [ -n "$OPENCODE_BIN_PATH" ]; then
|
|
5
|
+
resolved="$OPENCODE_BIN_PATH"
|
|
6
|
+
else
|
|
7
|
+
# Get the real path of this script, resolving any symlinks
|
|
8
|
+
script_path="$0"
|
|
9
|
+
while [ -L "$script_path" ]; do
|
|
10
|
+
link_target="$(readlink "$script_path")"
|
|
11
|
+
case "$link_target" in
|
|
12
|
+
/*) script_path="$link_target" ;;
|
|
13
|
+
*) script_path="$(dirname "$script_path")/$link_target" ;;
|
|
14
|
+
esac
|
|
15
|
+
done
|
|
16
|
+
script_dir="$(dirname "$script_path")"
|
|
17
|
+
script_dir="$(cd "$script_dir" && pwd)"
|
|
18
|
+
|
|
19
|
+
# Map platform names
|
|
20
|
+
case "$(uname -s)" in
|
|
21
|
+
Darwin) platform="darwin" ;;
|
|
22
|
+
Linux) platform="linux" ;;
|
|
23
|
+
MINGW*|CYGWIN*|MSYS*) platform="win32" ;;
|
|
24
|
+
*) platform="$(uname -s | tr '[:upper:]' '[:lower:]')" ;;
|
|
25
|
+
esac
|
|
26
|
+
|
|
27
|
+
# Map architecture names
|
|
28
|
+
case "$(uname -m)" in
|
|
29
|
+
x86_64|amd64) arch="x64" ;;
|
|
30
|
+
aarch64) arch="arm64" ;;
|
|
31
|
+
armv7l) arch="arm" ;;
|
|
32
|
+
*) arch="$(uname -m)" ;;
|
|
33
|
+
esac
|
|
34
|
+
|
|
35
|
+
name="opencode-${platform}-${arch}"
|
|
36
|
+
binary="opencode"
|
|
37
|
+
[ "$platform" = "win32" ] && binary="opencode.exe"
|
|
38
|
+
|
|
39
|
+
# Search for the binary starting from real script location
|
|
40
|
+
resolved=""
|
|
41
|
+
current_dir="$script_dir"
|
|
42
|
+
while [ "$current_dir" != "/" ]; do
|
|
43
|
+
candidate="$current_dir/node_modules/$name/bin/$binary"
|
|
44
|
+
if [ -f "$candidate" ]; then
|
|
45
|
+
resolved="$candidate"
|
|
46
|
+
break
|
|
47
|
+
fi
|
|
48
|
+
current_dir="$(dirname "$current_dir")"
|
|
49
|
+
done
|
|
50
|
+
|
|
51
|
+
if [ -z "$resolved" ]; then
|
|
52
|
+
printf "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 \"%s\" package\n" "$name" >&2
|
|
53
|
+
exit 1
|
|
54
|
+
fi
|
|
55
|
+
fi
|
|
56
|
+
|
|
57
|
+
# Handle SIGINT gracefully
|
|
58
|
+
trap '' INT
|
|
59
|
+
|
|
60
|
+
# Execute the binary with all arguments
|
|
61
|
+
exec "$resolved" "$@"
|
package/bin/opencode.cmd
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
setlocal enabledelayedexpansion
|
|
3
|
+
|
|
4
|
+
if defined OPENCODE_BIN_PATH (
|
|
5
|
+
set "resolved=%OPENCODE_BIN_PATH%"
|
|
6
|
+
goto :execute
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
rem Get the directory of this script
|
|
10
|
+
set "script_dir=%~dp0"
|
|
11
|
+
set "script_dir=%script_dir:~0,-1%"
|
|
12
|
+
|
|
13
|
+
rem Detect platform and architecture
|
|
14
|
+
set "platform=windows"
|
|
15
|
+
|
|
16
|
+
rem Detect architecture
|
|
17
|
+
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
|
|
18
|
+
set "arch=x64"
|
|
19
|
+
) else if "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
|
|
20
|
+
set "arch=arm64"
|
|
21
|
+
) else if "%PROCESSOR_ARCHITECTURE%"=="x86" (
|
|
22
|
+
set "arch=x86"
|
|
23
|
+
) else (
|
|
24
|
+
set "arch=x64"
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
set "name=opencode-!platform!-!arch!"
|
|
28
|
+
set "binary=opencode.exe"
|
|
29
|
+
|
|
30
|
+
rem Search for the binary starting from script location
|
|
31
|
+
set "resolved="
|
|
32
|
+
set "current_dir=%script_dir%"
|
|
33
|
+
|
|
34
|
+
:search_loop
|
|
35
|
+
set "candidate=%current_dir%\node_modules\%name%\bin\%binary%"
|
|
36
|
+
if exist "%candidate%" (
|
|
37
|
+
set "resolved=%candidate%"
|
|
38
|
+
goto :execute
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
rem Move up one directory
|
|
42
|
+
for %%i in ("%current_dir%") do set "parent_dir=%%~dpi"
|
|
43
|
+
set "parent_dir=%parent_dir:~0,-1%"
|
|
44
|
+
|
|
45
|
+
rem Check if we've reached the root
|
|
46
|
+
if "%current_dir%"=="%parent_dir%" goto :not_found
|
|
47
|
+
set "current_dir=%parent_dir%"
|
|
48
|
+
goto :search_loop
|
|
49
|
+
|
|
50
|
+
:not_found
|
|
51
|
+
echo 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 "%name%" package >&2
|
|
52
|
+
exit /b 1
|
|
53
|
+
|
|
54
|
+
:execute
|
|
55
|
+
rem Execute the binary with all arguments in the same console window
|
|
56
|
+
rem Use start /b /wait to ensure it runs in the current shell context for all shells
|
|
57
|
+
start /b /wait "" "%resolved%" %*
|
|
58
|
+
exit /b %ERRORLEVEL%
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "meet-code",
|
|
3
|
+
"bin": {
|
|
4
|
+
"meet-code": "./bin/opencode"
|
|
5
|
+
},
|
|
6
|
+
"scripts": {
|
|
7
|
+
"preinstall": "node ./preinstall.mjs",
|
|
8
|
+
"postinstall": "node ./postinstall.mjs"
|
|
9
|
+
},
|
|
10
|
+
"version": "1.2.6",
|
|
11
|
+
"optionalDependencies": {
|
|
12
|
+
"meet-code-windows-x64": "1.2.6",
|
|
13
|
+
"meet-code-linux-arm64": "1.2.6",
|
|
14
|
+
"meet-code-linux-x64": "1.2.6",
|
|
15
|
+
"meet-code-linux-x64-baseline": "1.2.6",
|
|
16
|
+
"meet-code-darwin-x64": "1.2.6",
|
|
17
|
+
"meet-code-darwin-x64-baseline": "1.2.6",
|
|
18
|
+
"meet-code-darwin-arm64": "1.2.6"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/postinstall.mjs
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
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
|
+
|
|
12
|
+
function detectPlatformAndArch() {
|
|
13
|
+
// Map platform names
|
|
14
|
+
let platform
|
|
15
|
+
switch (os.platform()) {
|
|
16
|
+
case "darwin":
|
|
17
|
+
platform = "darwin"
|
|
18
|
+
break
|
|
19
|
+
case "linux":
|
|
20
|
+
platform = "linux"
|
|
21
|
+
break
|
|
22
|
+
case "win32":
|
|
23
|
+
platform = "windows"
|
|
24
|
+
break
|
|
25
|
+
default:
|
|
26
|
+
platform = os.platform()
|
|
27
|
+
break
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Map architecture names
|
|
31
|
+
let arch
|
|
32
|
+
switch (os.arch()) {
|
|
33
|
+
case "x64":
|
|
34
|
+
arch = "x64"
|
|
35
|
+
break
|
|
36
|
+
case "arm64":
|
|
37
|
+
arch = "arm64"
|
|
38
|
+
break
|
|
39
|
+
case "arm":
|
|
40
|
+
arch = "arm"
|
|
41
|
+
break
|
|
42
|
+
default:
|
|
43
|
+
arch = os.arch()
|
|
44
|
+
break
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return { platform, arch }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function findBinary() {
|
|
51
|
+
const { platform, arch } = detectPlatformAndArch()
|
|
52
|
+
const packageName = `meet-code-${platform}-${arch}`
|
|
53
|
+
const binary = platform === "windows" ? "opencode.exe" : "opencode"
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
// Use require.resolve to find the package
|
|
57
|
+
const packageJsonPath = require.resolve(`${packageName}/package.json`)
|
|
58
|
+
const packageDir = path.dirname(packageJsonPath)
|
|
59
|
+
const binaryPath = path.join(packageDir, "bin", binary)
|
|
60
|
+
|
|
61
|
+
if (!fs.existsSync(binaryPath)) {
|
|
62
|
+
throw new Error(`Binary not found at ${binaryPath}`)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return binaryPath
|
|
66
|
+
} catch (error) {
|
|
67
|
+
throw new Error(`Could not find package ${packageName}: ${error.message}`)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function regenerateWindowsCmdWrappers() {
|
|
72
|
+
console.log("Windows + npm detected: Forcing npm to rebuild bin links")
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const { execSync } = require("child_process")
|
|
76
|
+
const pkgPath = path.join(__dirname, "..")
|
|
77
|
+
|
|
78
|
+
// npm_config_global is string | undefined
|
|
79
|
+
// if it exists, the value is true
|
|
80
|
+
const isGlobal = process.env.npm_config_global === "true" || pkgPath.includes(path.join("npm", "node_modules"))
|
|
81
|
+
|
|
82
|
+
// The npm rebuild command does 2 things - Execute lifecycle scripts and rebuild bin links
|
|
83
|
+
// We want to skip lifecycle scripts to avoid infinite loops, so we use --ignore-scripts
|
|
84
|
+
const cmd = `npm rebuild opencode-ai --ignore-scripts${isGlobal ? " -g" : ""}`
|
|
85
|
+
const opts = {
|
|
86
|
+
stdio: "inherit",
|
|
87
|
+
shell: true,
|
|
88
|
+
...(isGlobal ? {} : { cwd: path.join(pkgPath, "..", "..") }), // For local, run from project root
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
console.log(`Running: ${cmd}`)
|
|
92
|
+
execSync(cmd, opts)
|
|
93
|
+
console.log("Successfully rebuilt npm bin links")
|
|
94
|
+
} catch (error) {
|
|
95
|
+
console.error("Error rebuilding npm links:", error.message)
|
|
96
|
+
console.error("npm rebuild failed. You may need to manually run: npm rebuild opencode-ai --ignore-scripts")
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function main() {
|
|
101
|
+
try {
|
|
102
|
+
if (os.platform() === "win32") {
|
|
103
|
+
// NPM eg format - npm/11.4.2 node/v24.4.1 win32 x64
|
|
104
|
+
// Bun eg format - bun/1.2.19 npm/? node/v24.3.0 win32 x64
|
|
105
|
+
if (process.env.npm_config_user_agent.startsWith("npm")) {
|
|
106
|
+
await regenerateWindowsCmdWrappers()
|
|
107
|
+
} else {
|
|
108
|
+
console.log("Windows detected but not npm, skipping postinstall")
|
|
109
|
+
}
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const binaryPath = findBinary()
|
|
114
|
+
const binScript = path.join(__dirname, "bin", "opencode")
|
|
115
|
+
|
|
116
|
+
// Remove existing bin script if it exists
|
|
117
|
+
if (fs.existsSync(binScript)) {
|
|
118
|
+
fs.unlinkSync(binScript)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Create symlink to the actual binary
|
|
122
|
+
fs.symlinkSync(binaryPath, binScript)
|
|
123
|
+
console.log(`opencode binary symlinked: ${binScript} -> ${binaryPath}`)
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error("Failed to create opencode binary symlink:", error.message)
|
|
126
|
+
process.exit(1)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
main()
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.error("Postinstall script error:", error.message)
|
|
134
|
+
process.exit(0)
|
|
135
|
+
}
|
package/preinstall.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
|
|
8
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
9
|
+
|
|
10
|
+
function main() {
|
|
11
|
+
if (os.platform() !== "win32") {
|
|
12
|
+
console.log("Non-Windows platform detected, skipping preinstall")
|
|
13
|
+
return
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
console.log("Windows detected: Modifying package.json bin entry")
|
|
17
|
+
|
|
18
|
+
// Read package.json
|
|
19
|
+
const packageJsonPath = path.join(__dirname, "package.json")
|
|
20
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"))
|
|
21
|
+
|
|
22
|
+
// Modify bin to point to .cmd file on Windows
|
|
23
|
+
packageJson.bin = {
|
|
24
|
+
opencode: "./bin/opencode.cmd",
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Write it back
|
|
28
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
|
|
29
|
+
console.log("Updated package.json bin to use opencode.cmd")
|
|
30
|
+
|
|
31
|
+
// Now you can also remove the Unix script if you want
|
|
32
|
+
const unixScript = path.join(__dirname, "bin", "opencode")
|
|
33
|
+
if (fs.existsSync(unixScript)) {
|
|
34
|
+
console.log("Removing Unix shell script")
|
|
35
|
+
fs.unlinkSync(unixScript)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
main()
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.error("Preinstall script error:", error.message)
|
|
43
|
+
process.exit(0)
|
|
44
|
+
}
|