-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfix-env.js
More file actions
26 lines (26 loc) · 827 Bytes
/
fix-env.js
File metadata and controls
26 lines (26 loc) · 827 Bytes
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
/**
* Bun environment fix for Termux
*
* Bun on glibc/Termux has a bug where process.env and Bun.env return zero
* entries even though the kernel provides the full environment. This preload
* script reads /proc/self/environ and populates process.env.
*
* Usage: bun --preload /path/to/fix-env.js your-script.ts
*/
const fs = require("fs");
try {
const raw = fs.readFileSync("/proc/self/environ", "utf8");
const vars = raw.split("\0").filter(Boolean);
for (const v of vars) {
const eq = v.indexOf("=");
if (eq > 0) {
const key = v.substring(0, eq);
const val = v.substring(eq + 1);
if (!(key in process.env)) {
process.env[key] = val;
}
}
}
} catch (e) {
// Silently fail if /proc/self/environ is not readable
}