(importPath: string, projectRoot?: string)
| 1005 | } |
| 1006 | |
| 1007 | function stripToProjectRelative(importPath: string, projectRoot?: string): string { |
| 1008 | if (!importPath) { |
| 1009 | return ''; |
| 1010 | } |
| 1011 | |
| 1012 | let normalized = importPath.replace(/\\/g, '/'); |
| 1013 | normalized = normalized.replace(/^\/?@fs\//, '/'); |
| 1014 | if (normalized.startsWith('file://')) { |
| 1015 | normalized = normalized.replace(/^file:\/\//, '/'); |
| 1016 | } |
| 1017 | |
| 1018 | const documentsMarker = '/Documents/'; |
| 1019 | const documentsIndex = normalized.indexOf(documentsMarker); |
| 1020 | if (documentsIndex !== -1) { |
| 1021 | return normalized.substring(documentsIndex + documentsMarker.length); |
| 1022 | } |
| 1023 | |
| 1024 | if (projectRoot) { |
| 1025 | const normalizedRoot = projectRoot.replace(/\\/g, '/').replace(/\/+$/, ''); |
| 1026 | const rootIndex = normalized.indexOf(normalizedRoot); |
| 1027 | if (rootIndex !== -1) { |
| 1028 | const sliced = normalized.substring(rootIndex + normalizedRoot.length); |
| 1029 | return sliced.replace(/^\/+/, ''); |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | return normalized.replace(/^\/+/, ''); |
| 1034 | } |
| 1035 | |
| 1036 | /** |
| 1037 | * Convert absolute application import to relative .mjs path for Documents folder |
no test coverage detected