private _resolveFileSpecifier()

in ng-dev/ts-circular-dependencies/analyzer.ts [121:141]


  private _resolveFileSpecifier(specifier: string, containingFilePath?: string): string | null {
    const importFullPath =
      containingFilePath !== undefined ? join(dirname(containingFilePath), specifier) : specifier;
    const stat = getFileStatus(importFullPath);
    if (stat && stat.isFile()) {
      return importFullPath;
    }
    for (const extension of this.extensions) {
      const pathWithExtension = `${importFullPath}.${extension}`;
      const stat = getFileStatus(pathWithExtension);
      if (stat && stat.isFile()) {
        return pathWithExtension;
      }
    }
    // Directories should be considered last. TypeScript first looks for source files, then
    // falls back to directories if no file with appropriate extension could be found.
    if (stat && stat.isDirectory()) {
      return this._resolveFileSpecifier(join(importFullPath, 'index'));
    }
    return null;
  }