JS: Recognise bun and tsx in shebang lines#21461
Merged
Conversation
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>
hvitved
approved these changes
Mar 12, 2026
Contributor
There was a problem hiding this comment.
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
bunandtsx. - Add a new TypeScript library-test suite covering
node,bun, andtsxshebangs. - Add a minimal
tsconfig.jsonfor 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. | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #21455