mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
### What does this PR do? Fix bytecode CJS pragma detection when source file contains a shebang. When bundling with `--bytecode` and the source file has a shebang, the output silently fails to execute (exits 0, no output). Reproduction: [github.com/kjanat/bun-bytecode-banner-bug](https://github.com/kjanat/bun-bytecode-banner-bug) ```js // Bundled output: #!/usr/bin/env bun // shebang preserved // @bun @bytecode @bun-cjs // pragma on line 2 (function(exports, require, module, __filename, __dirname) { ... }) ``` The pragma parser in `hasBunPragma()` correctly skips the shebang line, but uses `self.lexer.end` instead of `contents.len` when scanning for `@bun-cjs`/`@bytecode` tokens. This causes the pragma to not be recognized. **Fix:** ```zig // Before while (cursor < self.lexer.end) : (cursor += 1) { // After while (cursor < end) : (cursor += 1) { ``` Where `end` is already defined as `contents.len` at the top of the function. ### How did you verify your code works? - Added bundler test `banner/SourceHashbangWithBytecodeAndCJSTargetBun` in `test/bundler/bundler_banner.test.ts` - Added regression tests in `test/regression/issue/bun-bytecode-shebang.test.ts` that verify: - CJS wrapper executes when source has shebang - CJS wrapper executes when source has shebang + bytecode pragma - End-to-end: bundled bytecode output with source shebang runs correctly - Ran the tests in the [kjanat/bun-bytecode-banner-bug](https://github.com/kjanat/bun-bytecode-banner-bug) repo to verify the issue is fixed --------- Signed-off-by: Kaj Kowalski <info@kajkowalski.nl> Co-authored-by: Dylan Conway <dylan.conway567@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>