Skip to content

Add bun and deno to interpreters in languages.yml for JavaScript#7878

Open
oopsio wants to merge 16 commits intogithub-linguist:mainfrom
oopsio:main
Open

Add bun and deno to interpreters in languages.yml for JavaScript#7878
oopsio wants to merge 16 commits intogithub-linguist:mainfrom
oopsio:main

Conversation

@oopsio
Copy link
Copy Markdown

@oopsio oopsio commented Mar 26, 2026

Added the bun and deno interpreters to languages.yml.

Description

This PR adds 4 examples, each with the MIT license, and adds the deno and bun interpreters to languages.yml for the JavaScript language. The license(s) are included as comments in the code.

Checklist:

@oopsio oopsio marked this pull request as ready for review March 26, 2026 13:17
@oopsio oopsio requested a review from a team as a code owner March 26, 2026 13:17
@oopsio oopsio changed the title Add 'bun' and 'deno' to interpreters in languages.yml Add bun and deno to interpreters in languages.yml Mar 26, 2026
@oopsio oopsio changed the title Add bun and deno to interpreters in languages.yml Add bun and deno to interpreters in languages.yml for JavaScript Mar 26, 2026
Comment thread test/test_language.rb Outdated
def test_find_by_interpreter
{
"bun" => "JavaScript",
"deno" => "JavaScript",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤔 this is ignoring these two are already associated with TypeScript:

TypeScript:
type: programming
color: "#3178c6"
aliases:
- ts
interpreters:
- bun
- deno
- ts-node
- tsx
extensions:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed, please review it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wasn't thinking about removing it, I was thinking about changing it into an array with both languages.

If you'd run the tests you'd have seen it fail with this:

TestLanguage#test_find_by_interpreter [test/test_language.rb:222]:
--- expected
+++ actual
@@ -1 +1 @@
-[#<Linguist::Language name=JavaScript>]
+[#<Linguist::Language name=JavaScript>, #<Linguist::Language name=TypeScript>]

However now I look at the test code, this would also require an update to the test as it isn't expecting more than one language with the same interpreter.

This change would be required too:

--- test/test_language.rb
+++ test/test_language.rb
@@ -217,7 +217,8 @@ def test_find_by_interpreter
       "sbcl" => "Common Lisp",
       "sclang" => "SuperCollider"
     }.each do |interpreter, language|
-      assert_equal [Language[language]], Language.find_by_interpreter(interpreter)
+      languages = Array(language).map { |lang| Language[lang] }
+      assert_equal languages, Language.find_by_interpreter(interpreter)
     end
 
     assert_equal [], Language.find_by_interpreter(nil)

So if we put both together, please make this change:

--- test/test_language.rb
+++ test/test_language.rb
@@ -207,6 +207,8 @@ def test_find_by_filename
 
   def test_find_by_interpreter
     {
+      "bun" => ["JavaScript", "TypeScript"],
+      "deno" => ["JavaScript", "TypeScript"],
       "ruby" => "Ruby",
       "Rscript" => "R",
       "sh" => "Shell",
@@ -217,7 +219,8 @@ def test_find_by_interpreter
       "sbcl" => "Common Lisp",
       "sclang" => "SuperCollider"
     }.each do |interpreter, language|
-      assert_equal [Language[language]], Language.find_by_interpreter(interpreter)
+      languages = Array(language).map { |lang| Language[lang] }
+      assert_equal languages, Language.find_by_interpreter(interpreter)
     end
 
     assert_equal [], Language.find_by_interpreter(nil)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have added the changes, it adds the changes you required me to and added samples of Deno and Bun with the shebangs. Also, a question, can linguist handle multiple arguments of shebang's? (example: if i have #!/usr/bin/env -S deno run, does it detect the deno interpreter?.) Let me know!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, a question, can linguist handle multiple arguments of shebang's? (example: if i have #!/usr/bin/env -S deno run, does it detect the deno interpreter?.) Let me know!

Yup:

# if /usr/bin/env type shebang then walk the string
if script == 'env'
s.scan(/\s+/)
while s.scan(/((-[i0uCSv]*|--\S+)\s+)+/) || # skip over optional arguments e.g. -vS
s.scan(/(\S+=\S+\s+)+/) # skip over variable arguments e.g. foo=bar
# do nothing
end
script = s.scan(/\S+/)
end

…th the `TypeScript` language.

Removed JavaScript entries from interpreter test.
Copy link
Copy Markdown
Member

@lildude lildude left a comment

Choose a reason for hiding this comment

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

Along with my inline comment, you've got test failures due to the extensionless test/fixtures/TypeScript/main test file. I've searched GitHub and there are only 2 other users of this that are not Linguist and it's forks.

With that in mind, please:

  • remove that file
  • add real-world samples for both JavaScript and TypeScript which have bun and deno shebangs into their respective samples/ directories.

@oopsio oopsio requested a review from lildude March 27, 2026 15:27
Copy link
Copy Markdown
Member

@lildude lildude left a comment

Choose a reason for hiding this comment

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

Please update the PR body to use the "I am adding a new extension to a language." part of the template and fill it in as if you're adding an extension.

The important part is we need real-world samples with their original filenames, and a link to the original source location and the license for legal reasons.

Please also add equivalent samples for TypeScript too.

@Alhadis
Copy link
Copy Markdown
Collaborator

Alhadis commented Mar 28, 2026

@lildude Hold on, I thought Linguist had troubles disambiguating between multiple languages that share the same interpreter? (Or am I misremembering something?)

I ask because osascript, normally used for executing AppleScript programs, can also be used to execute JavaScript that runs atop macOS's Open Scripting Architecture (which is the "OSA" in osascript). Unlike TypeScript/JavaScript, it'd be relatively trivial to write a heuristic to disambiguate JavaScript and AppleScript.

oopsio and others added 8 commits March 28, 2026 09:37
This file demonstrates OOP in Deno using TypeScript with a User class that encapsulates user data and provides methods to display and update user information.
This script demonstrates OOP principles in TypeScript using Bun, including abstraction, encapsulation, inheritance, and polymorphism.
Added a software license notice to the deno.ts file.
Added author, copyright, and license information to the file.
Added author, copyright, and license comments to deno.js
@lildude
Copy link
Copy Markdown
Member

lildude commented Mar 28, 2026

@lildude Hold on, I thought Linguist had troubles disambiguating between multiple languages that share the same interpreter? (Or am I misremembering something?)

I thought the same thing but this PR prompted me to look at the code again and I found it works like all the other strategies (makes sense) and the shebang strategy will return multiple languages down to the next strategy. The only issue seems to have been that the tests didn't expect this, but they do now thanks to the changes in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants