diff options
| author | Mani Sundararajan <[email protected]> | 2025-09-08 16:14:18 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-09-08 16:14:18 -0400 |
| commit | bbaae459c6979aab46d8625621cbf96c10c932c4 (patch) | |
| tree | 51d0284617a1f95262a141296b4a8e294fda9c43 | |
| parent | eb3c820fb81c579bb6d5ba7f1dd0b95a63083e5f (diff) | |
| download | opencode-bbaae459c6979aab46d8625621cbf96c10c932c4.tar.gz opencode-bbaae459c6979aab46d8625621cbf96c10c932c4.zip | |
feat: make npm package install work on windows (#2419)
| -rw-r--r-- | packages/opencode/bin/opencode.cmd | 6 | ||||
| -rw-r--r-- | packages/opencode/script/postinstall.mjs | 5 | ||||
| -rw-r--r-- | packages/opencode/script/preinstall.mjs | 32 | ||||
| -rwxr-xr-x | packages/opencode/script/publish.ts | 2 |
4 files changed, 43 insertions, 2 deletions
diff --git a/packages/opencode/bin/opencode.cmd b/packages/opencode/bin/opencode.cmd index 3a4ef3e72..775bfe688 100644 --- a/packages/opencode/bin/opencode.cmd +++ b/packages/opencode/bin/opencode.cmd @@ -52,5 +52,7 @@ echo It seems that your package manager failed to install the right version of t exit /b 1 :execute -rem Execute the binary with all arguments -"%resolved%" %* +rem Execute the binary with all arguments in the same console window +rem Use start /b /wait to ensure it runs in the current shell context for all shells +start /b /wait "" "%resolved%" %* +exit /b %ERRORLEVEL% diff --git a/packages/opencode/script/postinstall.mjs b/packages/opencode/script/postinstall.mjs index 2c6974123..40796562c 100644 --- a/packages/opencode/script/postinstall.mjs +++ b/packages/opencode/script/postinstall.mjs @@ -70,6 +70,11 @@ function findBinary() { function main() { try { + if (os.platform() === "win32") { + console.log("Windows detected, skipping postinstall") + return + } + const binaryPath = findBinary() const binScript = path.join(__dirname, "bin", "opencode") diff --git a/packages/opencode/script/preinstall.mjs b/packages/opencode/script/preinstall.mjs new file mode 100644 index 000000000..49c8db5e5 --- /dev/null +++ b/packages/opencode/script/preinstall.mjs @@ -0,0 +1,32 @@ +#!/usr/bin/env node + +import fs from "fs" +import path from "path" +import os from "os" +import { fileURLToPath } from "url" + +const __dirname = path.dirname(fileURLToPath(import.meta.url)) + +function main() { + if (os.platform() !== "win32") { + console.log("Non-Windows platform detected, skipping preinstall") + return + } + + const binDir = path.join(__dirname, "bin") + const unixScript = path.join(binDir, "opencode") + + console.log("Windows detected: Configuring bin scripts for Windows") + + if (fs.existsSync(unixScript)) { + console.log("Removing Unix shell script from bin/") + fs.unlinkSync(unixScript) + } +} + +try { + main() +} catch (error) { + console.error("Preinstall script error:", error.message) + process.exit(0) +} diff --git a/packages/opencode/script/publish.ts b/packages/opencode/script/publish.ts index 33ddeff05..0de48fe67 100755 --- a/packages/opencode/script/publish.ts +++ b/packages/opencode/script/publish.ts @@ -66,6 +66,7 @@ for (const [os, arch] of targets) { await $`mkdir -p ./dist/${pkg.name}` await $`cp -r ./bin ./dist/${pkg.name}/bin` +await $`cp ./script/preinstall.mjs ./dist/${pkg.name}/preinstall.mjs` await $`cp ./script/postinstall.mjs ./dist/${pkg.name}/postinstall.mjs` await Bun.file(`./dist/${pkg.name}/package.json`).write( JSON.stringify( @@ -75,6 +76,7 @@ await Bun.file(`./dist/${pkg.name}/package.json`).write( [pkg.name]: `./bin/${pkg.name}`, }, scripts: { + preinstall: "node ./preinstall.mjs", postinstall: "node ./postinstall.mjs", }, version, |
