MCPcopy Create free account
hub / github.com/arktypeio/arktype / constructor

Method constructor

ark/attest/cache/ts.ts:27–65  ·  view source on GitHub ↗
(tsConfigInfo?: TsconfigInfo)

Source from the content-addressed store, hash-verified

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, "/")

Callers

nothing calls this directly

Calls 7

fromCwdFunction · 0.90
narrowToNamedTestFilesFunction · 0.90
readFileFunction · 0.90
getTsConfigInfoOrThrowFunction · 0.85
getTsLibFilesFunction · 0.85
replaceMethod · 0.80
filterMethod · 0.80

Tested by

no test coverage detected