( targetPath: string, fromFile: string, toPath: string )
| 6 | * Detects existing alias patterns in the file and uses them for consistency |
| 7 | */ |
| 8 | export async function determineImportPath( |
| 9 | targetPath: string, |
| 10 | fromFile: string, |
| 11 | toPath: string |
| 12 | ): Promise<string> { |
| 13 | // Check existing imports in the file to detect alias patterns |
| 14 | const content = await fs.readFile(fromFile, "utf8"); |
| 15 | const pathAlias = detectAliasFromImports(content); |
| 16 | |
| 17 | if (pathAlias) { |
| 18 | return `${pathAlias}/${toPath}`; |
| 19 | } |
| 20 | |
| 21 | // Determine relative path based on file location |
| 22 | const fromDir = path.dirname(fromFile); |
| 23 | const relativePath = path.relative(fromDir, path.join(targetPath, toPath)); |
| 24 | |
| 25 | // Ensure path starts with ./ or ../ |
| 26 | if (!relativePath.startsWith(".")) { |
| 27 | return `./${relativePath}`; |
| 28 | } |
| 29 | |
| 30 | return relativePath; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Analyzes existing import statements to detect path alias patterns |
no test coverage detected