MCPcopy Create free account
hub / github.com/craftreactnative/ui / determineImportPath

Function determineImportPath

cli/src/utils/file-system.ts:8–31  ·  view source on GitHub ↗
(
  targetPath: string,
  fromFile: string,
  toPath: string
)

Source from the content-addressed store, hash-verified

6 * Detects existing alias patterns in the file and uses them for consistency
7 */
8export 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

Callers 2

addUnistylesImportFunction · 0.90
addCommandFunction · 0.90

Calls 1

detectAliasFromImportsFunction · 0.85

Tested by

no test coverage detected