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

Function createOverlayHost

ark/aot/declare.ts:534–597  ·  view source on GitHub ↗
(
	ts: TypeScript,
	options: ts.CompilerOptions,
	overlay: VirtualDeclarations
)

Source from the content-addressed store, hash-verified

532}
533
534const createOverlayHost = (
535 ts: TypeScript,
536 options: ts.CompilerOptions,
537 overlay: VirtualDeclarations
538): ts.CompilerHost => {
539 const host = ts.createCompilerHost(options)
540 if (!overlay.files.size) return host
541 const baseFileExists = host.fileExists.bind(host)
542 const baseReadFile = host.readFile.bind(host)
543 const baseGetSourceFile = host.getSourceFile.bind(host)
544 const baseGetSourceFileByPath = host.getSourceFileByPath?.bind(host)
545 const baseDirectoryExists = host.directoryExists?.bind(host)
546 const baseRealpath = host.realpath?.bind(host)
547 host.fileExists = fileName =>
548 overlay.get(fileName) !== undefined || baseFileExists(fileName)
549 host.readFile = fileName => overlay.get(fileName) ?? baseReadFile(fileName)
550 host.getSourceFile = (
551 fileName,
552 languageVersionOrOptions,
553 onError,
554 shouldCreateNewSourceFile
555 ) => {
556 const content = overlay.get(fileName)
557 if (content !== undefined)
558 return ts.createSourceFile(fileName, content, languageVersionOrOptions)
559 return baseGetSourceFile(
560 fileName,
561 languageVersionOrOptions,
562 onError,
563 shouldCreateNewSourceFile
564 )
565 }
566 if (baseGetSourceFileByPath) {
567 host.getSourceFileByPath = (
568 fileName,
569 path,
570 languageVersionOrOptions,
571 onError,
572 shouldCreateNewSourceFile
573 ) => {
574 const content = overlay.get(fileName) ?? overlay.get(path)
575 if (content !== undefined)
576 return ts.createSourceFile(fileName, content, languageVersionOrOptions)
577 return baseGetSourceFileByPath(
578 fileName,
579 path,
580 languageVersionOrOptions,
581 onError,
582 shouldCreateNewSourceFile
583 )
584 }
585 }
586 if (baseDirectoryExists) {
587 host.directoryExists = dirName =>
588 overlay.hasDir(dirName) || baseDirectoryExists(dirName)
589 }
590 if (baseRealpath) {
591 host.realpath = path =>

Callers 1

openParsedJsFunction · 0.85

Calls 5

realpathLongestAncestorFunction · 0.85
bindMethod · 0.80
hasDirMethod · 0.80
tsPathFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected