feat(compile): add --compile-autoload-tsconfig and --compile-autoload-package-json flags (#25340)

## Summary

By default, standalone executables no longer load `tsconfig.json` and
`package.json` at runtime. This improves startup performance and
prevents unexpected behavior from config files in the runtime
environment.

- Added `--compile-autoload-tsconfig` / `--no-compile-autoload-tsconfig`
CLI flags (default: false)
- Added `--compile-autoload-package-json` /
`--no-compile-autoload-package-json` CLI flags (default: false)
- Added `autoloadTsconfig` and `autoloadPackageJson` options to the
`Bun.build()` compile config
- Flags are stored in `StandaloneModuleGraph.Flags` and applied at
runtime boot

This follows the same pattern as the existing
`--compile-autoload-dotenv` and `--compile-autoload-bunfig` flags.

## Test plan

- [x] Added tests in `test/bundler/bundler_compile_autoload.test.ts`
- [x] Verified standalone executables work correctly with runtime config
files that differ from compile-time configs
- [x] Verified the new CLI flags are properly parsed and applied
- [x] Verified the JS API options work correctly

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
This commit is contained in:
robobun
2025-12-05 14:43:53 -08:00
committed by GitHub
parent 0d5a7c36ed
commit 23383b32b0
11 changed files with 321 additions and 21 deletions

View File

@@ -296,7 +296,9 @@ pub const StandaloneModuleGraph = struct {
pub const Flags = packed struct(u32) {
disable_default_env_files: bool = false,
disable_autoload_bunfig: bool = false,
_padding: u30 = 0,
disable_autoload_tsconfig: bool = false,
disable_autoload_package_json: bool = false,
_padding: u28 = 0,
};
const trailer = "\n---- Bun! ----\n";