MCPcopy Create free account
hub / github.com/code-forge-io/Remix-Forge / convertRoutePathToTildeFromRelative

Function convertRoutePathToTildeFromRelative

src/utils/dependencies.ts:34–52  ·  view source on GitHub ↗
(routePath: string, routesFolderNesting: number)

Source from the content-addressed store, hash-verified

32};
33
34export const convertRoutePathToTildeFromRelative = (routePath: string, routesFolderNesting: number) => {
35 const parentPath = routePath.match(/\.\.\//g);
36 const numParentLevels = parentPath ? parentPath.length : 0;
37 const convertedPath = routePath.replace(/\.\.\//g, "");
38 // because everything is moved to root we do not need to change this
39 if (routePath.startsWith("./")) {
40 return routePath;
41 }
42 // means its a package dep such as "@remix-run/react"
43 if (!routePath.startsWith("../") && !routePath.startsWith("~/")) {
44 return routePath;
45 }
46 // if outside of routes folder we change the levels eg ../../../server to ../server
47 if (numParentLevels > routesFolderNesting) {
48 return "../".repeat(numParentLevels - routesFolderNesting) + convertedPath;
49 }
50 // We add a ~/ to the path eg routes/something => ~/routes/something
51 return convertedPath.startsWith("~/") ? convertedPath : `~/${convertedPath}`;
52};
53
54/**
55 * Helps calculate the nesting difference between two paths

Callers 1

updateFileDependenciesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected