Skip to content

Commit a0af4c9

Browse files
authored
Merge pull request #18622 from asgerf/js/typescript-tsconfig-names
JS: Treat more file patterns as tsconfig-like files
2 parents a45da05 + 2e65fe9 commit a0af4c9

File tree

8 files changed

+47
-4
lines changed

8 files changed

+47
-4
lines changed

javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ private void setupFilters() {
394394
for (FileType filetype : defaultExtract)
395395
for (String extension : filetype.getExtensions()) patterns.add("**/*" + extension);
396396

397-
// include .eslintrc files, .xsaccess files, package.json files,
397+
// include .eslintrc files, .xsaccess files, package.json files,
398398
// tsconfig.json files, and codeql-javascript-*.json files
399399
patterns.add("**/.eslintrc*");
400400
patterns.add("**/.xsaccess");
@@ -895,7 +895,7 @@ protected DependencyInstallationResult preparePackagesAndDependencies(Set<Path>
895895
// For named packages, find the main file.
896896
String name = packageJson.getName();
897897
if (name != null) {
898-
Path entryPoint = null;
898+
Path entryPoint = null;
899899
try {
900900
entryPoint = guessPackageMainFile(path, packageJson, FileType.TYPESCRIPT.getExtensions());
901901
if (entryPoint == null) {
@@ -1108,6 +1108,10 @@ private boolean hasTypeScriptFiles(Set<Path> filesToExtract) {
11081108
return false;
11091109
}
11101110

1111+
public static boolean treatAsTSConfig(String basename) {
1112+
return basename.contains("tsconfig.") && basename.endsWith(".json");
1113+
}
1114+
11111115
private void findFilesToExtract(
11121116
FileExtractor extractor, final Set<Path> filesToExtract, final List<Path> tsconfigFiles)
11131117
throws IOException {
@@ -1140,7 +1144,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
11401144

11411145
// extract TypeScript projects from 'tsconfig.json'
11421146
if (typeScriptMode == TypeScriptMode.FULL
1143-
&& file.getFileName().endsWith("tsconfig.json")
1147+
&& treatAsTSConfig(file.getFileName().toString())
11441148
&& !excludes.contains(file)
11451149
&& isFileIncluded(file)) {
11461150
tsconfigFiles.add(file);

javascript/extractor/src/com/semmle/js/extractor/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ private void collectFiles(File root, boolean explicit) {
539539
}
540540

541541
if (extractorConfig.getTypeScriptMode() == TypeScriptMode.FULL
542-
&& root.getName().equals("tsconfig.json")
542+
&& AutoBuild.treatAsTSConfig(root.getName())
543543
&& !excludeMatcher.matches(path)) {
544544
projectFiles.add(root);
545545
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: majorAnalysis
3+
---
4+
* TypeScript extraction is now better at analyzing projects where the main `tsconfig.json` file does not include any
5+
source files, but references other `tsconfig.json`-like files that do include source files.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export function main(foo: string) {
2+
let x = foo;
3+
console.log(x);
4+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
types
2+
| (...data: any[]) => void |
3+
| (foo: string) => void |
4+
| Console |
5+
| any |
6+
| any[] |
7+
| string |
8+
| void |
9+
jsonFiles
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import javascript
2+
3+
query predicate types(Type type) { any() }
4+
5+
query predicate jsonFiles(File file) { file.getExtension() = "json" }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"include": [
4+
"src"
5+
],
6+
"compilerOptions": {
7+
"composite": true
8+
}
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"include": [],
3+
"files": [],
4+
"references": [
5+
{ "path": "./tsconfig.foo.json" },
6+
],
7+
}

0 commit comments

Comments
 (0)