Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS: Treat more file patterns as tsconfig-like files #18622

Merged
merged 5 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ private void setupFilters() {
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");
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -1108,6 +1108,10 @@ private boolean hasTypeScriptFiles(Set<Path> filesToExtract) {
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 {
Expand Down Expand Up @@ -1140,7 +1144,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)

// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ private void collectFiles(File root, boolean explicit) {
}

if (extractorConfig.getTypeScriptMode() == TypeScriptMode.FULL
&& root.getName().equals("tsconfig.json")
&& AutoBuild.treatAsTSConfig(root.getName())
&& !excludeMatcher.matches(path)) {
projectFiles.add(root);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function main(foo: string) {
let x = foo;
console.log(x);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
types
| (...data: any[]) => void |
| (foo: string) => void |
| Console |
| any |
| any[] |
| string |
| void |
jsonFiles
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import javascript

query predicate types(Type type) { any() }

query predicate jsonFiles(File file) { file.getExtension() = "json" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"include": [
"src"
],
"compilerOptions": {
"composite": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"include": [],
"files": [],
"references": [
{ "path": "./tsconfig.foo.json" },
],
}