MCPcopy Create free account
hub / github.com/angular/angular / getProjectRelativePath

Function getProjectRelativePath

packages/compiler-cli/src/ngtsc/util/src/path.ts:29–48  ·  view source on GitHub ↗
(
  fileName: string,
  rootDirs: readonly string[],
  compilerHost: Pick<ts.CompilerHost, 'getCanonicalFileName'>,
)

Source from the content-addressed store, hash-verified

27 * @returns
28 */
29export function getProjectRelativePath(
30 fileName: string,
31 rootDirs: readonly string[],
32 compilerHost: Pick<ts.CompilerHost, 'getCanonicalFileName'>,
33): string | null {
34 // Note: we need to pass both the file name and the root directories through getCanonicalFileName,
35 // because the root directories might've been passed through it already while the source files
36 // definitely have not. This can break the relative return value, because in some platforms
37 // getCanonicalFileName lowercases the path.
38 const filePath = compilerHost.getCanonicalFileName(fileName);
39
40 for (const rootDir of rootDirs) {
41 const rel = relative(compilerHost.getCanonicalFileName(rootDir), filePath);
42 if (!rel.startsWith('..')) {
43 return rel;
44 }
45 }
46
47 return null;
48}

Callers 3

analyzeMethod · 0.90
extractClassDebugInfoFunction · 0.90
extractHmrMetatadataFunction · 0.90

Calls 2

relativeFunction · 0.90
getCanonicalFileNameMethod · 0.45

Tested by

no test coverage detected