Merge pull request #18622 from asgerf/js/typescript-tsconfig-names

JS: Treat more file patterns as tsconfig-like files
This commit is contained in:
Asger F
2025-01-31 09:42:50 +01:00
committed by GitHub
8 changed files with 47 additions and 4 deletions

View File

@@ -394,7 +394,7 @@ public class AutoBuild {
for (FileType filetype : defaultExtract)
for (String extension : filetype.getExtensions()) patterns.add("**/*" + extension);
// include .eslintrc files, .xsaccess files, package.json files,
// include .eslintrc files, .xsaccess files, package.json files,
// tsconfig.json files, and codeql-javascript-*.json files
patterns.add("**/.eslintrc*");
patterns.add("**/.xsaccess");
@@ -895,7 +895,7 @@ protected DependencyInstallationResult preparePackagesAndDependencies(Set<Path>
// For named packages, find the main file.
String name = packageJson.getName();
if (name != null) {
Path entryPoint = null;
Path entryPoint = null;
try {
entryPoint = guessPackageMainFile(path, packageJson, FileType.TYPESCRIPT.getExtensions());
if (entryPoint == null) {
@@ -1108,6 +1108,10 @@ protected DependencyInstallationResult preparePackagesAndDependencies(Set<Path>
return false;
}
public static boolean treatAsTSConfig(String basename) {
return basename.contains("tsconfig.") && basename.endsWith(".json");
}
private void findFilesToExtract(
FileExtractor extractor, final Set<Path> filesToExtract, final List<Path> tsconfigFiles)
throws IOException {
@@ -1140,7 +1144,7 @@ protected DependencyInstallationResult preparePackagesAndDependencies(Set<Path>
// extract TypeScript projects from 'tsconfig.json'
if (typeScriptMode == TypeScriptMode.FULL
&& file.getFileName().endsWith("tsconfig.json")
&& treatAsTSConfig(file.getFileName().toString())
&& !excludes.contains(file)
&& isFileIncluded(file)) {
tsconfigFiles.add(file);

View File

@@ -539,7 +539,7 @@ public class Main {
}
if (extractorConfig.getTypeScriptMode() == TypeScriptMode.FULL
&& root.getName().equals("tsconfig.json")
&& AutoBuild.treatAsTSConfig(root.getName())
&& !excludeMatcher.matches(path)) {
projectFiles.add(root);
}

View File

@@ -0,0 +1,5 @@
---
category: majorAnalysis
---
* TypeScript extraction is now better at analyzing projects where the main `tsconfig.json` file does not include any
source files, but references other `tsconfig.json`-like files that do include source files.

View File

@@ -0,0 +1,4 @@
export function main(foo: string) {
let x = foo;
console.log(x);
}

View File

@@ -0,0 +1,9 @@
types
| (...data: any[]) => void |
| (foo: string) => void |
| Console |
| any |
| any[] |
| string |
| void |
jsonFiles

View File

@@ -0,0 +1,5 @@
import javascript
query predicate types(Type type) { any() }
query predicate jsonFiles(File file) { file.getExtension() = "json" }

View File

@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"include": [
"src"
],
"compilerOptions": {
"composite": true
}
}

View File

@@ -0,0 +1,7 @@
{
"include": [],
"files": [],
"references": [
{ "path": "./tsconfig.foo.json" },
],
}