(dependencyPath: string, newFilePath: string)
| 8 | return ""; |
| 9 | } |
| 10 | export const convertDependencyPath = (dependencyPath: string, newFilePath: string) => { |
| 11 | // Converts ./some/path to ./some.path |
| 12 | if (dependencyPath.startsWith("./")) { |
| 13 | const trailingPath = removeAfterLastDot(newFilePath.split("routes/")[1].replace(".jsx", "").replace(".tsx", "")); |
| 14 | return ( |
| 15 | "./" + |
| 16 | (trailingPath ? trailingPath + "." : "") + |
| 17 | dependencyPath.replace("./", "").replace(/__/g, "_").replace(/index/g, "_index").replace(/\//g, ".") |
| 18 | ); |
| 19 | } |
| 20 | // We return if it's not a routes folder dependency |
| 21 | if (!dependencyPath.includes("routes")) { |
| 22 | return dependencyPath; |
| 23 | } |
| 24 | const parts = dependencyPath.split("routes/"); |
| 25 | if (parts.length < 2) { |
| 26 | return dependencyPath; |
| 27 | } |
| 28 | // converts some/thing/path => some.thing.path |
| 29 | const convertedPath = parts[1].replace(".tsx", "").replace(".jsx", "").replace(/\//g, "."); |
| 30 | // returns the path converted eg routes/some/path => routes/some.path |
| 31 | return parts[0] + "routes/" + convertedPath; |
| 32 | }; |
| 33 | |
| 34 | export const convertRoutePathToTildeFromRelative = (routePath: string, routesFolderNesting: number) => { |
| 35 | const parentPath = routePath.match(/\.\.\//g); |
no test coverage detected