Bun 在 import.meta 对象上提供了一些模块特定的实用程序。使用 import.meta.main 来检查当前文件是否是当前进程的入口点。
if (import.meta.main) {
// this file is directly executed with `bun run`
} else {
// this file is being imported by another file
}
有关完整的文档,请参阅 文档 > API > import.meta。