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

Function loadNative

ark/aot/declareNative.ts:102–124  ·  view source on GitHub ↗
(cwd: string, checker: NativeChecker)

Source from the content-addressed store, hash-verified

100}
101
102const loadNative = (cwd: string, checker: NativeChecker): Native => {
103 for (const require of requiresFor(cwd)) {
104 if (checker === "tsrs" && !hasTsrsBinary(require)) continue
105 for (const entry of entriesByChecker[checker]) {
106 const version = nativeVersionOf(require, entry)
107 if (!version || (checker === "tsgo" && !isNativeVersion(version)))
108 continue
109 let fs: Fs | undefined
110 try {
111 fs = require(`${entry}/fs`)
112 } catch {
113 // older tsrs builds without /fs fall back to OS filesystem reads
114 }
115 return {
116 sync: require(`${entry}/sync`),
117 ast: require(`${entry}/ast`),
118 fs,
119 version
120 }
121 }
122 }
123 return throwError(writeNoNativeMessage(checker))
124}
125
126export const writeNoNativeMessage = (checker: NativeChecker): string =>
127 checker === "tsgo" ?

Callers 2

discoverNativeProjectsFunction · 0.85
openNativeFunction · 0.85

Calls 6

throwErrorFunction · 0.90
requiresForFunction · 0.85
nativeVersionOfFunction · 0.85
isNativeVersionFunction · 0.85
writeNoNativeMessageFunction · 0.85
hasTsrsBinaryFunction · 0.70

Tested by

no test coverage detected