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。
I haven't done it exactly as you're trying to parse it, but I was able to use the resolveModuleName method in the typescript API to accomplish what you're asking, following the docs here