I try to get the path information as follows:
const typeChecker = program.getTypeChecker();
const importFileSymbol = typeChecker.getSymbolAtLocation(
importDeclarationNode.moduleSpecifier
);
const path = importFileSymbol?.valueDeclaration?.path || '';
In this way, I can get the sourceFile object of the module source file, and get the absolute path of the module through the path attribute on sourceFile. But path is an internal property of typescript and does not expose the type, so I think there may be some problems with this usage.
So I wonder if there is any other way to get it?
I also tried to get it through the fileName property of sourceFile, but for modules imported through path mapping, the obtained path is not an absolute path。
sourceFile.fileNameif the compiler host always ensures that source files are created with an absolute path.