Files
hapi/cli/src/utils/bunRuntime.ts
T
weishu 76b84a0b52 refactor: unify bun compiled detection with windows support
- Add shared isBunCompiled() function for consistent runtime detection
- Support Windows virtual filesystem paths (/~BUN/) alongside Linux/macOS (/$bunfs/)
- Use Bun.main for reliable detection instead of process.argv[1]
- Remove redundant $bunfs checks from cli/src/index.ts
- Update cli/src/utils/bunRuntime.ts to use shared detection function
- Create server/src/utils/bunCompiled.ts for server-side compilation check
2025-12-26 11:29:12 +08:00

34 lines
665 B
TypeScript

import { isBunCompiled } from '@/projectPath';
export type BunRuntimeEnvOptions = {
allowBunBeBun?: boolean;
};
function stripBunBeBun(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
if (!('BUN_BE_BUN' in env)) {
return env;
}
const copy = { ...env };
delete copy.BUN_BE_BUN;
return copy;
}
export function withBunRuntimeEnv(
env: NodeJS.ProcessEnv = process.env,
options: BunRuntimeEnvOptions = {}
): NodeJS.ProcessEnv {
if (!isBunCompiled()) {
return env;
}
if (options.allowBunBeBun === false) {
return stripBunBeBun(env);
}
return {
...env,
BUN_BE_BUN: '1'
};
}