mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
Merge 86b9541fcb into 83397ebde2
This commit is contained in:
commit
063031f4a0
2 changed files with 55 additions and 0 deletions
|
|
@ -5,6 +5,29 @@ const fs = require("fs")
|
|||
const path = require("path")
|
||||
const os = require("os")
|
||||
|
||||
function cleanupTempDirectories() {
|
||||
if (os.platform() !== "win32") return
|
||||
|
||||
try {
|
||||
const globalNodeModules = path.join(process.env.APPDATA || "", "npm", "node_modules")
|
||||
if (!fs.existsSync(globalNodeModules)) return
|
||||
|
||||
const entries = fs.readdirSync(globalNodeModules, { withFileTypes: true })
|
||||
for (const entry of entries) {
|
||||
if (entry.isDirectory() && entry.name.startsWith(".opencode-ai-")) {
|
||||
const tempDir = path.join(globalNodeModules, entry.name)
|
||||
try {
|
||||
fs.rmSync(tempDir, { recursive: true, force: true })
|
||||
} catch (cleanupError) {
|
||||
// Silently ignore cleanup errors
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// Silently ignore cleanup errors
|
||||
}
|
||||
}
|
||||
|
||||
function run(target) {
|
||||
const result = childProcess.spawnSync(target, process.argv.slice(2), {
|
||||
stdio: "inherit",
|
||||
|
|
@ -19,6 +42,8 @@ function run(target) {
|
|||
|
||||
const envPath = process.env.OPENCODE_BIN_PATH
|
||||
if (envPath) {
|
||||
// Clean up temp directories before running
|
||||
cleanupTempDirectories()
|
||||
run(envPath)
|
||||
}
|
||||
|
||||
|
|
@ -81,4 +106,7 @@ if (!resolved) {
|
|||
process.exit(1)
|
||||
}
|
||||
|
||||
// Clean up temp directories before running
|
||||
cleanupTempDirectories()
|
||||
|
||||
run(resolved)
|
||||
|
|
|
|||
|
|
@ -97,12 +97,39 @@ function symlinkBinary(sourcePath, binaryName) {
|
|||
}
|
||||
}
|
||||
|
||||
function cleanupTempDirectories() {
|
||||
if (os.platform() !== "win32") return
|
||||
|
||||
try {
|
||||
const globalNodeModules = path.join(process.env.APPDATA || "", "npm", "node_modules")
|
||||
if (!fs.existsSync(globalNodeModules)) return
|
||||
|
||||
const entries = fs.readdirSync(globalNodeModules, { withFileTypes: true })
|
||||
for (const entry of entries) {
|
||||
if (entry.isDirectory() && entry.name.startsWith(".opencode-ai-")) {
|
||||
const tempDir = path.join(globalNodeModules, entry.name)
|
||||
try {
|
||||
fs.rmSync(tempDir, { recursive: true, force: true })
|
||||
console.log(`Cleaned up temporary directory: ${entry.name}`)
|
||||
} catch (cleanupError) {
|
||||
console.warn(`Failed to clean up ${entry.name}:`, cleanupError.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn("Failed to cleanup temporary directories:", error.message)
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
if (os.platform() === "win32") {
|
||||
// On Windows, the .exe is already included in the package and bin field points to it
|
||||
// No postinstall setup needed
|
||||
console.log("Windows detected: binary setup not needed (using packaged .exe)")
|
||||
|
||||
// Clean up any leftover temporary directories from previous installations
|
||||
cleanupTempDirectories()
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue