-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-node-pty-permissions.js
More file actions
36 lines (32 loc) · 1.17 KB
/
fix-node-pty-permissions.js
File metadata and controls
36 lines (32 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env node
/**
* On macOS / Linux, npm 10 sometimes extracts node-pty's `spawn-helper`
* prebuild without preserving the executable bit, which causes
* `posix_spawnp failed` at runtime. This postinstall step fixes that.
*
* No-op on Windows or when the file isn't present.
*/
import { chmodSync, existsSync, statSync } from "node:fs";
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";
const here = dirname(fileURLToPath(import.meta.url));
const root = join(here, "..");
const targets = [
join(root, "node_modules", "node-pty", "prebuilds", `${process.platform}-${process.arch}`, "spawn-helper"),
join(root, "node_modules", "node-pty", "build", "Release", "spawn-helper"),
];
let fixed = 0;
for (const target of targets) {
if (!existsSync(target)) continue;
try {
const mode = statSync(target).mode;
// Add executable bits for user / group / other (0o111).
chmodSync(target, mode | 0o111);
fixed++;
} catch (err) {
process.stderr.write(`[agentic-rc] could not chmod ${target}: ${err && err.message}\n`);
}
}
if (fixed > 0) {
process.stdout.write(`[agentic-rc] fixed exec bit on ${fixed} node-pty helper(s)\n`);
}