Description
Local plugins written in TypeScript (@plugin(./my-plugin.ts)) should work when the app runs in Bun and loads env through varlock/auto-load (e.g. preload in bunfig.toml). Today they only work when the CLI is started explicitly with --bun.
| How env is loaded |
.ts plugin |
bunx --bun varlock load |
works |
bunx varlock load |
fails: "TypeScript plugins (.ts) require Bun" |
import "varlock/auto-load" inside a Bun process |
fails: same error |
Motivation
auto-load spawns the CLI via execSync, and the bin's shebang is #!/usr/bin/env node, so the child process runs on Node even though the parent is Bun, and rejects the .ts plugin. bunx honours the same shebang unless you pass --bun.
In a Bun project that means a .ts plugin works from one entry point and breaks bun test / bun run, so in practice it's unusable and you have to write .cjs / .mjs.
Proposed Solution
When auto-load detects it's running in Bun (isBun already exists), spawn the CLI with process.execPath (bun) instead of relying on the shebang.
Alternatives
- Document that
.ts plugins only work when the CLI is started with --bun, and not through auto-load.
- Keep writing local plugins as
.cjs / .mjs (what I'm doing now).
Description
Local plugins written in TypeScript (
@plugin(./my-plugin.ts)) should work when the app runs in Bun and loads env throughvarlock/auto-load(e.g.preloadinbunfig.toml). Today they only work when the CLI is started explicitly with--bun..tspluginbunx --bun varlock loadbunx varlock loadimport "varlock/auto-load"inside a Bun processMotivation
auto-loadspawns the CLI viaexecSync, and the bin's shebang is#!/usr/bin/env node, so the child process runs on Node even though the parent is Bun, and rejects the.tsplugin.bunxhonours the same shebang unless you pass--bun.In a Bun project that means a
.tsplugin works from one entry point and breaksbun test/bun run, so in practice it's unusable and you have to write.cjs/.mjs.Proposed Solution
When
auto-loaddetects it's running in Bun (isBunalready exists), spawn the CLI withprocess.execPath(bun) instead of relying on the shebang.Alternatives
.tsplugins only work when the CLI is started with--bun, and not throughauto-load..cjs/.mjs(what I'm doing now).