Skip to content

JS: Recognise bun and tsx in shebang lines#21461

Merged
asgerf merged 2 commits intomainfrom
asger/js-shebang-bun-tsx
Mar 13, 2026
Merged

JS: Recognise bun and tsx in shebang lines#21461
asgerf merged 2 commits intomainfrom
asger/js-shebang-bun-tsx

Conversation

@asgerf
Copy link
Contributor

@asgerf asgerf commented Mar 12, 2026

Fixes #21455

asgerf and others added 2 commits March 12, 2026 09:35
Update the shebang regexp (renamed NODE_INVOCATION -> JS_INVOCATION) to
also match 'bun' and 'tsx' so that scripts using these runtimes are
correctly identified as JavaScript files.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add test files with #!/usr/bin/env bun, #!/usr/bin/env tsx, and
#!/usr/bin/env node shebangs. The query lists extracted .ts files,
verifying that all three shebangs are recognized and the files are
not skipped by the extractor.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions bot added the JS label Mar 12, 2026
@asgerf asgerf changed the title JS extractor: recognise bun and tsx in shebang lines JS: Recognise bun and tsx in shebang lines Mar 12, 2026
@asgerf asgerf marked this pull request as ready for review March 13, 2026 14:06
@asgerf asgerf requested review from a team as code owners March 13, 2026 14:06
Copilot AI review requested due to automatic review settings March 13, 2026 14:06
@asgerf asgerf merged commit 7d6e08e into main Mar 13, 2026
22 checks passed
@asgerf asgerf deleted the asger/js-shebang-bun-tsx branch March 13, 2026 14:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support and regression coverage for TypeScript files that start with common non-Node shebangs, ensuring such files are still extracted rather than filtered out as having an unrecognized header.

Changes:

  • Expand recognized JavaScript-runtime shebang detection to include bun and tsx.
  • Add a new TypeScript library-test suite covering node, bun, and tsx shebangs.
  • Add a minimal tsconfig.json for the new TypeScript test project.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
javascript/extractor/src/com/semmle/js/extractor/FileExtractor.java Broaden shebang recognition used by TypeScript header sniffing (and extensionless script detection) to include bun/tsx.
javascript/ql/test/library-tests/TypeScript/Shebangs/tsconfig.json Minimal TS project config to ensure the test files are compiled/considered together.
javascript/ql/test/library-tests/TypeScript/Shebangs/Shebangs.ql Test query that enumerates extracted files in the test project.
javascript/ql/test/library-tests/TypeScript/Shebangs/Shebangs.expected Expected extracted file list including the shebang-bearing .ts files.
javascript/ql/test/library-tests/TypeScript/Shebangs/shebang_tsx.ts Test input: TypeScript file with tsx shebang.
javascript/ql/test/library-tests/TypeScript/Shebangs/shebang_node.ts Test input: TypeScript file with node shebang.
javascript/ql/test/library-tests/TypeScript/Shebangs/shebang_bun.ts Test input: TypeScript file with bun shebang.

You can also share your feedback on Copilot code review. Take the survey.

@@ -302,7 +302,7 @@ private boolean hasUnrecognizedShebang(byte[] bytes, int length) {
int lengthOfText = endOfLine - startOfText;
String text = new String(bytes, startOfText, lengthOfText, StandardCharsets.UTF_8);
// Check if the shebang is a recognized JavaScript intepreter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shebang in typescript files leads to not being processed

3 participants