(tsConfigInfo?: TsconfigInfo)
| 25 | private tsConfigInfo!: TsconfigInfo |
| 26 | |
| 27 | constructor(tsConfigInfo?: TsconfigInfo) { |
| 28 | if (TsServer._instance) return TsServer._instance |
| 29 | |
| 30 | this.tsConfigInfo = tsConfigInfo ?? getTsConfigInfoOrThrow() |
| 31 | |
| 32 | const tsLibPaths = getTsLibFiles(this.tsConfigInfo.parsed.options) |
| 33 | |
| 34 | // TS represents windows paths as `C:/Users/ssalb/...` |
| 35 | const normalizedCwd = fromCwd().replace(/\\/g, "/") |
| 36 | |
| 37 | this.rootFiles = narrowToNamedTestFiles( |
| 38 | this.tsConfigInfo.parsed.fileNames.filter(path => { |
| 39 | if (!path.startsWith(normalizedCwd)) return |
| 40 | |
| 41 | // exclude empty files as they lead to a crash |
| 42 | // when createVirtualTypeScriptEnvironment is called |
| 43 | const contents = readFile(path).trim() |
| 44 | |
| 45 | return contents !== "" |
| 46 | }) |
| 47 | ) |
| 48 | |
| 49 | const system = tsvfs.createFSBackedSystem( |
| 50 | tsLibPaths.defaultMapFromNodeModules, |
| 51 | this.tsConfigInfo.path ? dirname(this.tsConfigInfo.path) : fromCwd(), |
| 52 | ts |
| 53 | ) |
| 54 | |
| 55 | this.virtualEnv = tsvfs.createVirtualTypeScriptEnvironment( |
| 56 | system, |
| 57 | this.rootFiles, |
| 58 | ts, |
| 59 | this.tsConfigInfo.parsed.options |
| 60 | ) |
| 61 | |
| 62 | this.program = this.virtualEnv.languageService.getProgram()! |
| 63 | |
| 64 | TsServer._instance = this |
| 65 | } |
| 66 | |
| 67 | getSourceFileOrThrow(path: string): ts.SourceFile { |
| 68 | const tsPath = path.replace(/\\/g, "/") |
nothing calls this directly
no test coverage detected