fix: auto-chmod binary on first run to fix EACCES on macOS (#354)
Bun blocks postinstall scripts by default, leaving the binary without execute permissions. The wrapper now fixes this automatically. Fixes #344
This commit is contained in:
+18
-1
@@ -9,7 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { spawn } from 'child_process';
|
import { spawn } from 'child_process';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync, accessSync, chmodSync, constants } from 'fs';
|
||||||
import { dirname, join } from 'path';
|
import { dirname, join } from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import { platform, arch } from 'os';
|
import { platform, arch } from 'os';
|
||||||
@@ -73,6 +73,23 @@ function main() {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure binary is executable (fixes EACCES on macOS/Linux when postinstall didn't run,
|
||||||
|
// e.g., when using bun which blocks lifecycle scripts by default)
|
||||||
|
if (platform() !== 'win32') {
|
||||||
|
try {
|
||||||
|
accessSync(binaryPath, constants.X_OK);
|
||||||
|
} catch {
|
||||||
|
// Binary exists but isn't executable - fix it
|
||||||
|
try {
|
||||||
|
chmodSync(binaryPath, 0o755);
|
||||||
|
} catch (chmodErr) {
|
||||||
|
console.error(`Error: Cannot make binary executable: ${chmodErr.message}`);
|
||||||
|
console.error('Try running: chmod +x ' + binaryPath);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Spawn the native binary with inherited stdio
|
// Spawn the native binary with inherited stdio
|
||||||
const child = spawn(binaryPath, process.argv.slice(2), {
|
const child = spawn(binaryPath, process.argv.slice(2), {
|
||||||
stdio: 'inherit',
|
stdio: 'inherit',
|
||||||
|
|||||||
Reference in New Issue
Block a user