Skip to content

Commit 310867d

Browse files
committed
fix(ai): replace raw require(node:fs) with loadNodeBuiltinModule in getProcEnv
1 parent c87b9a7 commit 310867d

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

packages/ai/src/env-api-keys.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,11 @@ function getProcEnv(key: string): string | undefined {
8989
if (procEnvCache === null) {
9090
procEnvCache = new Map();
9191
try {
92-
const { readFileSync } = require("node:fs") as typeof import("node:fs");
93-
const data = readFileSync("/proc/self/environ", "utf-8");
92+
const fsModule = loadNodeBuiltinModule(NODE_FS_SPECIFIER) as typeof import("node:fs") | null;
93+
if (!fsModule) {
94+
return undefined;
95+
}
96+
const data = fsModule.readFileSync("/proc/self/environ", "utf-8");
9497
for (const entry of data.split("\0")) {
9598
const idx = entry.indexOf("=");
9699
if (idx > 0) {

0 commit comments

Comments
 (0)