MCPcopy Index your code
hub / github.com/angular/angular / projectFile

Function projectFile

packages/core/schematics/utils/tsurge/project_paths.ts:95–122  ·  view source on GitHub ↗
(
  file: ts.SourceFile | AbsoluteFsPath,
  {sortedRootDirs, projectRoot}: Pick<ProgramInfo, 'sortedRootDirs' | 'projectRoot'>,
)

Source from the content-addressed store, hash-verified

93 * See {@link ProjectFile}.
94 */
95export function projectFile(
96 file: ts.SourceFile | AbsoluteFsPath,
97 {sortedRootDirs, projectRoot}: Pick<ProgramInfo, 'sortedRootDirs' | 'projectRoot'>,
98): ProjectFile {
99 const fs = getFileSystem();
100 const filePath = fs.resolve(typeof file === 'string' ? file : file.fileName);
101
102 // Sorted root directories are sorted longest to shortest. First match
103 // is the appropriate root directory for ID computation.
104 for (const rootDir of sortedRootDirs) {
105 if (!isWithinBasePath(fs, rootDir, filePath)) {
106 continue;
107 }
108 return {
109 id: fs.relative(rootDir, filePath) as string as ProjectFileID,
110 rootRelativePath: fs.relative(projectRoot, filePath) as string as ProjectRootRelativePath,
111 };
112 }
113
114 // E.g. project directory may be `src/`, but files may be looked up
115 // from `node_modules/`. This is fine, but in those cases, no root
116 // directory matches.
117 const rootRelativePath = fs.relative(projectRoot, filePath);
118 return {
119 id: rootRelativePath as string as ProjectFileID,
120 rootRelativePath: rootRelativePath as string as ProjectRootRelativePath,
121 };
122}
123
124/**
125 * Whether `path` is a descendant of the `base`?

Callers 15

insertPrecedingLineFunction · 0.90
getIdOfOutputFunction · 0.90
migrateMethod · 0.90
analyzeMethod · 0.90
replaceQueryListGetCallFunction · 0.90

Calls 4

getFileSystemFunction · 0.90
isWithinBasePathFunction · 0.70
resolveMethod · 0.65
relativeMethod · 0.65

Tested by 1

analyzeMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…