Initialize the AST-based Path Alias Resolver
Loads path mappings from options and prepares for resolution.
Optionaloptions: ASTPathAliasResolverOptionsConfiguration options
Add a custom path alias at runtime
Path alias configuration to add
Clear the resolution cache
Useful when aliases are modified at runtime.
Get the count of registered aliases
Number of aliases
Get all registered path aliases
Array of all path alias configurations
Get cache statistics
Cache size information
Number of cached alias resolutions.
Load path aliases from tsconfig.json
Reads the "paths" property from tsconfig.json and converts it to PathAliasMapping entries for efficient lookup.
Path to tsconfig.json file
Resolve path aliases directly in the AST
This method modifies import/export declarations in-place without any string manipulation or re-parsing.
Algorithm:
Performance:
ts-morph SourceFile to modify
Result with count of resolved aliases and modified imports
const sourceFile = project.createSourceFile('component.ts', content);
const result = resolver.resolveAliasesInAST(sourceFile);
console.info(`Resolved ${result.aliasesResolved} aliases`);
result.modifiedImports.forEach(({ from, to }) => {
console.info(` ${from} → ${to}`);
});
// AST is already modified, get transformed code
const code = sourceFile.getFullText();
AST-based Path Alias Resolver
Resolves TypeScript path aliases by modifying the AST directly, eliminating string manipulation and re-parsing overhead. Path mappings are loaded from tsconfig.json. AST-based alternative to PathAliasResolver.preprocessFileContent.
Key Advantages over String-based Resolver:
Use Cases
Custom Path Aliases
External Decorator Projects
Monorepo Packages
Architecture
Example