|
28 | 28 | */ |
29 | 29 | public class FileExtractor { |
30 | 30 | /** |
31 | | - * Pattern to use on the shebang line of a script to identify whether it is a Node.js script. |
| 31 | + * Pattern to use on the shebang line of a script to identify whether it is a JavaScript script. |
32 | 32 | * |
33 | | - * <p>There are many different ways of invoking the Node.js interpreter (directly, through {@code |
| 33 | + * <p>There are many different ways of invoking a JavaScript interpreter (directly, through {@code |
34 | 34 | * env}, with or without flags, with or without modified environment, etc.), so we simply look for |
35 | | - * the word {@code "node"} or {@code "nodejs"}. |
| 35 | + * the word {@code "node"}, {@code "nodejs"}, {@code "bun"}, or {@code "tsx"}. |
36 | 36 | */ |
37 | | - private static final Pattern NODE_INVOCATION = Pattern.compile("\\bnode(js)?\\b"); |
| 37 | + private static final Pattern JS_INVOCATION = Pattern.compile("\\b(node(js)?|bun|tsx)\\b"); |
38 | 38 |
|
39 | 39 | /** A pattern that matches strings starting with `{ "...":`, suggesting JSON data. */ |
40 | 40 | public static final Pattern JSON_OBJECT_START = |
@@ -157,7 +157,7 @@ protected boolean contains(File f, String lcExt, ExtractorConfig config) { |
157 | 157 | // do a cheap check first |
158 | 158 | if (firstLine != null && firstLine.startsWith("#!")) { |
159 | 159 | // now do the slightly more expensive one |
160 | | - return NODE_INVOCATION.matcher(firstLine).find(); |
| 160 | + return JS_INVOCATION.matcher(firstLine).find(); |
161 | 161 | } |
162 | 162 | } catch (IOException e) { |
163 | 163 | Exceptions.ignore(e, "We simply skip this file."); |
@@ -302,7 +302,7 @@ private boolean hasUnrecognizedShebang(byte[] bytes, int length) { |
302 | 302 | int lengthOfText = endOfLine - startOfText; |
303 | 303 | String text = new String(bytes, startOfText, lengthOfText, StandardCharsets.UTF_8); |
304 | 304 | // Check if the shebang is a recognized JavaScript intepreter. |
305 | | - return !NODE_INVOCATION.matcher(text).find(); |
| 305 | + return !JS_INVOCATION.matcher(text).find(); |
306 | 306 | } |
307 | 307 |
|
308 | 308 | @Override |
|
0 commit comments