Utilizing ts-morph
, I am examining the inheritance relationships of classes in a project:
For testing purposes, I have downloaded an open-source projectantv/x6:
import { Project } from "ts-morph";
const project = new Project();
project.addDirectoryAtPath("/Users/john/github_repo/@antv/X6/packages/")
const classes = project.getSourceFiles().flatMap((sourceFile) =>
sourceFile.getClasses()
);
const classNames = classes.map((classDecl) => ({
name: classDecl.getName(),
fileName: classDecl.getSourceFile().getFilePath(),
}));
console.log(classNames) // the output is `[]`
Why does it return an empty array?
Edit-01
I noticed that even though there are thousands of classes in the source code under the packages, when I log the classes, it shows as an empty array:
const classes = project.getSourceFiles().flatMap((sourceFile) =>
sourceFile.getClasses()
);
console.log("classes: ", classes) // classes: []