alias-it
Version:
Intelligent TypeScript path mapping with auto-discovery and validation
73 lines (69 loc) • 2.38 kB
text/typescript
interface PathMapping {
[key: string]: string;
}
interface PathMapperOptions {
rootDir?: string;
includePatterns?: string[];
excludePatterns?: string[];
maxDepth?: number;
autoGenerate?: boolean;
validateExisting?: boolean;
}
interface DiscoveredPath {
alias: string;
path: string;
relativePath: string;
type: 'directory' | 'file';
depth: number;
}
interface PathMapperResult {
mappings: PathMapping;
discovered: DiscoveredPath[];
suggestions: string[];
warnings: string[];
errors: string[];
}
interface ValidationResult {
isValid: boolean;
issues: ValidationIssue[];
}
interface ValidationIssue {
type: 'error' | 'warning' | 'info';
message: string;
path?: string;
suggestion?: string;
}
declare class PathMapper {
private rootDir;
private options;
constructor(options?: PathMapperOptions);
/**
* Discover potential path mappings in the project
*/
discoverPaths(): Promise<DiscoveredPath[]>;
/**
* Generate path mappings from discovered paths
*/
generateMappings(): Promise<PathMapperResult>;
/**
* Validate existing path mappings in tsconfig.json
*/
validateExistingMappings(tsConfigPath?: string): Promise<ValidationResult>;
/**
* Update tsconfig.json with new path mappings
*/
updateTsConfig(newMappings: PathMapping, tsConfigPath?: string, merge?: boolean): Promise<void>;
/**
* Get intelligent suggestions for path mappings
*/
getSuggestions(): Promise<string[]>;
private calculateDepth;
private resolveAliasConflict;
private findBetterMapping;
private analyzeImportPatterns;
}
declare function generatePathMappings(options?: PathMapperOptions): Promise<PathMapping>;
declare function validatePathMappings(tsConfigPath?: string, options?: PathMapperOptions): Promise<boolean>;
declare function updateTsConfigMappings(mappings: PathMapping, tsConfigPath?: string, merge?: boolean, options?: PathMapperOptions): Promise<void>;
declare function getPathMappingSuggestions(options?: PathMapperOptions): Promise<string[]>;
export { type DiscoveredPath, PathMapper, type PathMapperOptions, type PathMapperResult, type PathMapping, type ValidationIssue, type ValidationResult, generatePathMappings, getPathMappingSuggestions, updateTsConfigMappings, validatePathMappings };