fix install issue

This commit is contained in:
Wendong-Fan 2025-08-22 21:20:21 +08:00
parent 086dcc6baa
commit 7e448ffd79
4 changed files with 79 additions and 37 deletions

View file

@ -59,7 +59,8 @@
"/core/concepts",
"/core/workforce",
"/core/models",
"/core/tools"
"/core/tools",
"workers"
]
},
{

View file

@ -27,11 +27,44 @@ export async function downloadWithRedirects(url, destinationPath) {
reject(new Error(`Download failed: ${response.statusCode} ${response.statusMessage}`))
return
}
const file = fs.createWriteStream(destinationPath)
let downloadedBytes = 0
const expectedBytes = parseInt(response.headers['content-length'] || '0')
response.on('data', (chunk) => {
downloadedBytes += chunk.length
})
response.pipe(file)
file.on('finish', () => {
file.close(() => {
clearTimeout(timeout);
// Verify the download is complete
if (expectedBytes > 0 && downloadedBytes !== expectedBytes) {
fs.unlinkSync(destinationPath)
reject(new Error(`Download incomplete: received ${downloadedBytes} bytes, expected ${expectedBytes}`))
return
}
// Check if file exists and has size > 0
const stats = fs.statSync(destinationPath)
if (stats.size === 0) {
fs.unlinkSync(destinationPath)
reject(new Error('Downloaded file is empty'))
return
}
resolve()
})
})
file.on('error', (err) => {
clearTimeout(timeout);
resolve()
fs.unlinkSync(destinationPath)
reject(err)
})
})
.on('error', (err) => {

View file

@ -65,33 +65,44 @@ async function downloadBunBinary(bun_download_url,platform, arch, version = DEFA
// Extract the zip file using adm-zip
console.log(`Extracting ${packageName} to ${binDir}...`)
const zip = new AdmZip(tempFilename)
zip.extractAllTo(tempdir, true)
// Move files using Node.js fs
const sourceDir = path.join(tempdir, packageName.split('.')[0])
const files = fs.readdirSync(sourceDir)
for (const file of files) {
const sourcePath = path.join(sourceDir, file)
const destPath = path.join(binDir, file)
fs.copyFileSync(sourcePath, destPath)
fs.unlinkSync(sourcePath)
// Set executable permissions for non-Windows platforms
if (platform !== 'win32') {
try {
// 755 permission: rwxr-xr-x
fs.chmodSync(destPath, '755')
} catch (error) {
console.warn(`Warning: Failed to set executable permissions: ${error.message}`)
// Get all entries and find the bun binary
const entries = zip.getEntries()
let bunFound = false
for (const entry of entries) {
const entryName = entry.entryName
// Look for the bun binary (could be in root or in a subdirectory)
if (entryName === 'bun' || entryName === 'bun.exe' ||
entryName.endsWith('/bun') || entryName.endsWith('/bun.exe') ||
entryName.endsWith('\\bun') || entryName.endsWith('\\bun.exe')) {
// Extract just the binary name
const fileName = path.basename(entryName)
const destPath = path.join(binDir, fileName)
// Extract the specific file
zip.extractEntryTo(entry, binDir, false, true)
// Set executable permissions for non-Windows platforms
if (platform !== 'win32' && fileName === 'bun') {
try {
fs.chmodSync(destPath, '755')
} catch (error) {
console.warn(`Warning: Failed to set executable permissions: ${error.message}`)
}
}
bunFound = true
}
}
if (!bunFound) {
throw new Error('bun binary not found in archive')
}
// Clean up
fs.unlinkSync(tempFilename)
fs.rmSync(sourceDir, { recursive: true })
console.log(`Successfully installed bun ${version} for ${platformKey}`)
return true

View file

@ -89,23 +89,21 @@ async function downloadUvBinary(
// handle tar.gz file
await tar.x({
file: tempFilename,
cwd: tempdir,
cwd: binDir,
strip: 1,
z: true,
filter: (path) => {
// Only extract the uv binary
return path.endsWith('uv') || path.endsWith('uv.exe');
}
});
// Move files using Node.js fs
const sourceDir = path.join(tempdir, packageName.split(".")[0]);
const files = fs.readdirSync(sourceDir);
for (const file of files) {
const sourcePath = path.join(sourceDir, file);
const destPath = path.join(binDir, file);
fs.copyFileSync(sourcePath, destPath);
fs.unlinkSync(sourcePath);
// Set executable permissions for non-Windows platforms
if (platform !== "win32") {
// Set executable permissions for non-Windows platforms
if (platform !== "win32") {
const uvPath = path.join(binDir, "uv");
if (fs.existsSync(uvPath)) {
try {
fs.chmodSync(destPath, "755");
fs.chmodSync(uvPath, "755");
} catch (error) {
console.warn(
`Warning: Failed to set executable permissions: ${error.message}`
@ -116,7 +114,6 @@ async function downloadUvBinary(
// Clean up
fs.unlinkSync(tempFilename);
fs.rmSync(sourceDir, { recursive: true });
}
console.log(`Successfully installed uv ${version} for ${platform}-${arch}`);