mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 17:54:23 +01:00
feat: make npm package install work on windows (#2419)
This commit is contained in:
committed by
GitHub
parent
eb3c820fb8
commit
bbaae459c6
@@ -52,5 +52,7 @@ echo It seems that your package manager failed to install the right version of t
|
|||||||
exit /b 1
|
exit /b 1
|
||||||
|
|
||||||
:execute
|
:execute
|
||||||
rem Execute the binary with all arguments
|
rem Execute the binary with all arguments in the same console window
|
||||||
"%resolved%" %*
|
rem Use start /b /wait to ensure it runs in the current shell context for all shells
|
||||||
|
start /b /wait "" "%resolved%" %*
|
||||||
|
exit /b %ERRORLEVEL%
|
||||||
|
|||||||
@@ -70,6 +70,11 @@ function findBinary() {
|
|||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
try {
|
try {
|
||||||
|
if (os.platform() === "win32") {
|
||||||
|
console.log("Windows detected, skipping postinstall")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const binaryPath = findBinary()
|
const binaryPath = findBinary()
|
||||||
const binScript = path.join(__dirname, "bin", "opencode")
|
const binScript = path.join(__dirname, "bin", "opencode")
|
||||||
|
|
||||||
|
|||||||
32
packages/opencode/script/preinstall.mjs
Normal file
32
packages/opencode/script/preinstall.mjs
Normal file
@@ -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)
|
||||||
|
}
|
||||||
@@ -66,6 +66,7 @@ for (const [os, arch] of targets) {
|
|||||||
|
|
||||||
await $`mkdir -p ./dist/${pkg.name}`
|
await $`mkdir -p ./dist/${pkg.name}`
|
||||||
await $`cp -r ./bin ./dist/${pkg.name}/bin`
|
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 $`cp ./script/postinstall.mjs ./dist/${pkg.name}/postinstall.mjs`
|
||||||
await Bun.file(`./dist/${pkg.name}/package.json`).write(
|
await Bun.file(`./dist/${pkg.name}/package.json`).write(
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
@@ -75,6 +76,7 @@ await Bun.file(`./dist/${pkg.name}/package.json`).write(
|
|||||||
[pkg.name]: `./bin/${pkg.name}`,
|
[pkg.name]: `./bin/${pkg.name}`,
|
||||||
},
|
},
|
||||||
scripts: {
|
scripts: {
|
||||||
|
preinstall: "node ./preinstall.mjs",
|
||||||
postinstall: "node ./postinstall.mjs",
|
postinstall: "node ./postinstall.mjs",
|
||||||
},
|
},
|
||||||
version,
|
version,
|
||||||
|
|||||||
Reference in New Issue
Block a user