mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 21:01:52 +00:00
## Summary
Fixes an issue where `--compile-exec-argv` options were incorrectly
appearing in `process.argv` when no user arguments were provided to a
compiled standalone binary.
## Problem
When building a standalone binary with `--compile-exec-argv`, the exec
argv options would leak into `process.argv` when running the binary
without any user arguments:
```bash
# Build with exec argv
bun build --compile-exec-argv="--user-agent=hello" --compile ./a.js
# Run without arguments - BEFORE fix
./a
# Output showed --user-agent=hello in both execArgv AND argv (incorrect)
{
execArgv: [ "--user-agent=hello" ],
argv: [ "bun", "/$bunfs/root/a", "--user-agent=hello" ], # <- BUG: exec argv leaked here
}
# Expected behavior (matches runtime):
bun --user-agent=hello a.js
{
execArgv: [ "--user-agent=hello" ],
argv: [ "/path/to/bun", "/path/to/a.js" ], # <- No exec argv in process.argv
}
```
## Solution
The issue was in the offset calculation for determining which arguments
to pass through to the JavaScript runtime. The offset was being
calculated before modifying the argv array with exec argv options,
causing it to be incorrect when the original argv only contained the
executable name.
The fix ensures that:
- `process.execArgv` correctly contains the compile-exec-argv options
- `process.argv` only contains the executable, script path, and user
arguments
- exec argv options never leak into `process.argv`
## Test plan
Added comprehensive tests to verify:
1. Exec argv options don't leak into process.argv when no user arguments
are provided
2. User arguments are properly passed through when exec argv is present
3. Existing behavior continues to work correctly
All tests pass:
```
bun test compile-argv.test.ts
✓ 3 tests pass
```
🤖 Generated with [Claude Code](https://claude.ai/code)
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
77 lines
1.3 KiB
Markdown
77 lines
1.3 KiB
Markdown
---
|
|
name: Import a YAML file
|
|
---
|
|
|
|
Bun natively supports `.yaml` and `.yml` imports.
|
|
|
|
```yaml#config.yaml
|
|
database:
|
|
host: localhost
|
|
port: 5432
|
|
name: myapp
|
|
|
|
server:
|
|
port: 3000
|
|
timeout: 30
|
|
|
|
features:
|
|
auth: true
|
|
rateLimit: true
|
|
```
|
|
|
|
---
|
|
|
|
Import the file like any other source file.
|
|
|
|
```ts
|
|
import config from "./config.yaml";
|
|
|
|
config.database.host; // => "localhost"
|
|
config.server.port; // => 3000
|
|
config.features.auth; // => true
|
|
```
|
|
|
|
---
|
|
|
|
You can also use named imports to destructure top-level properties:
|
|
|
|
```ts
|
|
import { database, server, features } from "./config.yaml";
|
|
|
|
console.log(database.name); // => "myapp"
|
|
console.log(server.timeout); // => 30
|
|
console.log(features.rateLimit); // => true
|
|
```
|
|
|
|
---
|
|
|
|
Bun also supports [Import Attributes](https://github.com/tc39/proposal-import-attributes) syntax:
|
|
|
|
```ts
|
|
import config from "./config.yaml" with { type: "yaml" };
|
|
|
|
config.database.port; // => 5432
|
|
```
|
|
|
|
---
|
|
|
|
For parsing YAML strings at runtime, use `Bun.YAML.parse()`:
|
|
|
|
```ts
|
|
const yamlString = `
|
|
name: John Doe
|
|
age: 30
|
|
hobbies:
|
|
- reading
|
|
- coding
|
|
`;
|
|
|
|
const data = Bun.YAML.parse(yamlString);
|
|
console.log(data.name); // => "John Doe"
|
|
console.log(data.hobbies); // => ["reading", "coding"]
|
|
```
|
|
|
|
---
|
|
|
|
See [Docs > API > YAML](https://bun.com/docs/api/yaml) for complete documentation on YAML support in Bun.
|