Skip to content

JavaScript: Ignore outDirs that would exclude everything #20030

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

Merged
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 @@ -754,7 +754,11 @@ private CompletableFuture<?> extractSource() throws IOException {
continue;
}
Path odir = cfg.getParent().resolve(root.getCompilerOptions().getOutDir()).toAbsolutePath().normalize();
outDirs.add(odir);
// Only exclude outDirs that are proper subdirectories of the source root
// This prevents excluding all code when outDir points outside the source root or to the source root itself
if (tryRelativize(LGTM_SRC, odir) != null && !odir.equals(LGTM_SRC)) {
outDirs.add(odir);
}
}
} catch (Exception e) {
// ignore malformed tsconfig or missing fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,51 @@ public void skipFilesInTsconfigOutDir() throws IOException {
runTest();
}

@Test
public void skipFilesInTsconfigOutDirPointingToParent() throws IOException {
// Test that outDir pointing to parent directory (outside source root) is ignored
addFile(true, LGTM_SRC, "tsconfig.json");
Path config = Paths.get(LGTM_SRC.toString(), "tsconfig.json");
Files.write(config,
"{\"compilerOptions\":{\"outDir\":\"..\"}}".getBytes(StandardCharsets.UTF_8));

// All files should be extracted since outDir pointing outside source root should be ignored
addFile(true, LGTM_SRC, "src", "app.ts");
addFile(true, LGTM_SRC, "main.js");

runTest();
}

@Test
public void skipFilesInTsconfigOutDirPointingToSourceRoot() throws IOException {
// Test that outDir pointing to source root itself is ignored
addFile(true, LGTM_SRC, "tsconfig.json");
Path config = Paths.get(LGTM_SRC.toString(), "tsconfig.json");
Files.write(config,
"{\"compilerOptions\":{\"outDir\":\".\"}}".getBytes(StandardCharsets.UTF_8));

// All files should be extracted since outDir pointing to source root should be ignored
addFile(true, LGTM_SRC, "src", "app.ts");
addFile(true, LGTM_SRC, "main.js");

runTest();
}

@Test
public void skipFilesInTsconfigOutDirWithRelativePath() throws IOException {
// Test that outDir with relative path "somedir/.." (resolves to root) is ignored
addFile(true, LGTM_SRC, "tsconfig.json");
Path config = Paths.get(LGTM_SRC.toString(), "tsconfig.json");
Files.write(config,
"{\"compilerOptions\":{\"outDir\":\"somedir/..\"}}".getBytes(StandardCharsets.UTF_8));

// All files should be extracted since outDir resolving to root should be ignored
addFile(true, LGTM_SRC, "src", "app.ts");
addFile(true, LGTM_SRC, "main.js");

runTest();
}

@Test
public void includeFile() throws IOException {
envVars.put("LGTM_INDEX_INCLUDE", "tst.js");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: fix
---
* The JavaScript extractor no longer ignores source files specified in the `tsconfig.json` compiler options `outDir` if doing so would result in excluding all source code.