mirror of
https://github.com/wu736139669/hapi.git
synced 2026-12-05 07:07:04 +00:00
- 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
34 lines
665 B
TypeScript
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'
|
|
};
|
|
}
|