forked from softarc-consulting/sheriff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.info.ts
More file actions
57 lines (48 loc) · 1.55 KB
/
Copy pathfile.info.ts
File metadata and controls
57 lines (48 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { UnassignedFileInfo } from '../file-info/unassigned-file-info';
import { Module } from './module';
import { FsPath } from '../file-info/fs-path';
/**
* Central element representing a TypeScript file with its
* imports and assigned module.
*
* Due to ESLint, we can have partial imports (dev is still
* typing). That's why there is `getRawImportForImportedFileInfo`.
*/
export class FileInfo {
#imports: FileInfo[] | undefined;
constructor(
private unassignedFileInfo: UnassignedFileInfo,
public moduleInfo: Module,
private getFileInfo: (fsPath: FsPath) => FileInfo,
) {}
get path(): FsPath {
return this.unassignedFileInfo.path;
}
get imports(): FileInfo[] {
if (this.#imports === undefined) {
this.#imports = this.unassignedFileInfo.imports.map(
(unassignedFileInfo) => this.getFileInfo(unassignedFileInfo.path),
);
}
return this.#imports;
}
/**
* For unresolvable imports (ESLint while user is typing) we want
* to get the string as it is in the file.
*/
getRawImportForImportedFileInfo(path: FsPath): string {
return this.unassignedFileInfo.getRawImportForImportedFileInfo(path);
}
get unresolvableImports() {
return this.unassignedFileInfo.unresolvableImports;
}
isUnresolvableImport(importCommand: string) {
return this.unassignedFileInfo.isUnresolvableImport(importCommand);
}
hasUnresolvedImports() {
return this.unassignedFileInfo.hasUnresolvableImports();
}
getExternalLibraries() {
return this.unassignedFileInfo.getExternalLibraries();
}
}