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

Function modulesLoadingArktype

ark/aot/host.ts:404–432  ·  view source on GitHub ↗
(
	specifier: string,
	from: string
)

Source from the content-addressed store, hash-verified

402// t3-env's presets-arktype: none where it can't load arktype, and the specifier
403// where its modules can't be read
404export const modulesLoadingArktype = (
405 specifier: string,
406 from: string
407): string[] => {
408 const name = packageNameOf(specifier)
409 if (!dependsOnArktype(name, from)) return []
410 if (arktypeEntries.includes(name)) return [specifier]
411 const host = (nodeHost ??= createNodeHost())
412 const entry = host.resolve(specifier, join(from, "_"))
413 if (!entry) return [specifier]
414 const modules = new Set<string>()
415 const seen = new Set<string>()
416 const read = (file: string) => {
417 if (seen.has(file)) return
418 seen.add(file)
419 for (const [, imported] of (host.readFile(file) ?? "").matchAll(
420 importOrComputed
421 )) {
422 if (!imported || arktypeEntries.includes(packageNameOf(imported)))
423 modules.add(file)
424 else {
425 const resolved = host.resolve(imported, file)
426 if (resolved) read(resolved)
427 }
428 }
429 }
430 read(entry)
431 return [...modules]
432}
433
434export const packageRootOf = (
435 name: string,

Callers 1

Calls 6

packageNameOfFunction · 0.85
dependsOnArktypeFunction · 0.85
createNodeHostFunction · 0.85
joinFunction · 0.85
readFunction · 0.70
resolveMethod · 0.65

Tested by

no test coverage detected