Bun

指南工具程式

使用 Bun 取得目前進入點的絕對路徑

Bun.main 屬性包含目前進入點的絕對路徑。

foo.ts
index.ts
foo.ts
console.log(Bun.main);
index.ts
import "./foo.ts";

列印的路徑對應到使用 bun run 執行的檔案。

bun run index.ts
/path/to/index.ts
bun run foo.ts
/path/to/foo.ts

請參閱 文件 > API > 工具程式 以取得更多有用的工具程式。