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

Function openNative

ark/aot/declareNative.ts:726–1098  ·  view source on GitHub ↗
(
	cwd: string,
	checker: NativeChecker,
	tsconfig: string | undefined,
	overlay?: VirtualDeclarations
)

Source from the content-addressed store, hash-verified

724}
725
726export const openNative = (
727 cwd: string,
728 checker: NativeChecker,
729 tsconfig: string | undefined,
730 overlay?: VirtualDeclarations
731): OpenedDeclarationProject => {
732 const native = loadNative(cwd, checker)
733 const { sync, ast } = native
734 const configPath =
735 tsconfig ?
736 resolve(cwd, tsconfig)
737 : (findConfig(cwd) ??
738 throwError(
739 `No tsconfig.json is in ${cwd} or a directory above it. Create ${join(cwd, "tsconfig.json")}, as { "compilerOptions": { "rootDir": "src", "outDir": "dist" }, "include": ["src"] }, or name the one tsc builds with as --tsconfig, or as "tsconfig" in ark.json.`
740 ))
741 const fs =
742 overlay?.files.size && native.fs ?
743 nativeOverlayFs(overlay, native.fs.serverFS, cwd)
744 : undefined
745 const api = new sync.API(fs ? { cwd, fs } : { cwd })
746 try {
747 const project =
748 api
749 .createSnapshot({ openProjects: [configPath] })
750 .getConfiguredProject(configPath) ??
751 throwError(`${configPath} couldn't be read as a tsconfig`)
752 const views = new Views(native, project)
753 const tsView = typeScriptOf(native)
754 const checkerView = checkerOf(views)
755 const program = programOf(project, checkerView)
756 const raw = project.program
757 const canonical = (path: string) => {
758 const normalized = path.split("\\").join("/")
759 return isCaseSensitive ? normalized : normalized.toLowerCase()
760 }
761 const parsed = api.parseConfigFile(configPath)
762 if (!parsed.fileNames.length && parsed.projectReferences?.length) {
763 const configDiagnostics = raw.getConfigFileParsingDiagnostics()
764 const referencePaths = parsed.projectReferences.map(({ path }) =>
765 /\.json$/i.test(path) ? path : join(path, "tsconfig.json")
766 )
767 const result: SolutionReferences = {
768 configPath,
769 references: referencePaths,
770 diagnostics: sync.formatDiagnostics(configDiagnostics, {
771 getCanonicalFileName: path => path,
772 getCurrentDirectory: () => cwd,
773 getNewLine: () => "\n"
774 }),
775 errors: configDiagnostics.filter(
776 diagnostic => diagnostic.category === sync.DiagnosticCategory.Error
777 ).length
778 }
779 api.close()
780 return result
781 }
782 // when a project has projectReferences, tsgo loads referenced projects' source
783 // files alongside its own; exclude referenced projects' files (while keeping

Callers 1

emitDeclarationsFunction · 0.90

Calls 15

throwErrorFunction · 0.90
sourceRootOfFunction · 0.90
loadNativeFunction · 0.85
findConfigFunction · 0.85
joinFunction · 0.85
nativeOverlayFsFunction · 0.85
typeScriptOfFunction · 0.85
checkerOfFunction · 0.85
testMethod · 0.80
filterMethod · 0.80
sortMethod · 0.80

Tested by

no test coverage detected