Skip to content
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 @@ -60,7 +60,7 @@ function loadProgram() {
configPath,
);
return ts.createProgram({
rootNames: configuredRootNames(parsed.fileNames, rootNames),
rootNames: rootNames || parsed.fileNames.filter((name) => isWithinTarget(path.resolve(name))),
options: parsed.options,
});
}
Expand All @@ -71,15 +71,6 @@ function loadProgram() {
});
}

function configuredRootNames(configuredFiles, corpusFiles) {
const withinTarget = configuredFiles.filter((name) => isWithinTarget(path.resolve(name)));
if (!Array.isArray(corpusFiles)) {
return withinTarget;
}
const corpus = new Set(corpusFiles.map((name) => path.resolve(name)));
return withinTarget.filter((name) => corpus.has(path.resolve(name)));
}

function findConfigPath() {
return ts.findConfigFile(targetPath, ts.sys.fileExists, "tsconfig.json") ||
ts.findConfigFile(targetPath, ts.sys.fileExists, "jsconfig.json");
Expand Down
14 changes: 5 additions & 9 deletions internal/codeguard/checks/support/typescript_semantic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestTypeScriptRuntimeDiscoveryHonorsExplicitRuntime(t *testing.T) {
}
}

func TestTypeScriptSemanticRunnerIntersectsCorpusWithConfiguredFiles(t *testing.T) {
func TestTypeScriptSemanticRunnerUsesCorpusDespiteConfiguredFiles(t *testing.T) {
if _, err := exec.LookPath("node"); err != nil {
t.Skip("node is required for the embedded semantic runner test")
}
Expand Down Expand Up @@ -73,21 +73,17 @@ module.exports = {
TargetPath: root,
SourceFiles: []string{
filepath.Join(root, "src/app.ts"),
filepath.Join(root, "vendor/excluded.ts"),
filepath.Join(root, "node_modules/pkg/index.ts"),
filepath.Join(root, "src/tsconfig-excluded.ts"),
},
}
_, err := runTypeScriptSemanticRunner(context.Background(), input)
if err == nil {
t.Fatal("semantic runner succeeded; want fake compiler root report")
}
message := err.Error()
if !strings.Contains(message, filepath.Join(root, "src/app.ts")) {
t.Fatalf("configured corpus root missing from compiler roots: %s", message)
}
for _, excluded := range []string{"vendor/excluded.ts", "node_modules/pkg/index.ts"} {
if strings.Contains(message, excluded) {
t.Fatalf("tsconfig-excluded corpus file %q reached compiler roots: %s", excluded, message)
for _, sourceFile := range input.SourceFiles {
if !strings.Contains(message, sourceFile) {
t.Fatalf("corpus root %q missing from compiler roots: %s", sourceFile, message)
}
}
}
Expand Down
Loading