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

Function loadTypeScript

ark/aot/declare.ts:715–732  ·  view source on GitHub ↗
(cwd: string)

Source from the content-addressed store, hash-verified

713
714// a TypeScript 7 project installs TypeScript 6 as `typescript-6`
715export const loadTypeScript = (cwd: string): TypeScript => {
716 for (const from of [join(cwd, "package.json"), import.meta.url]) {
717 const require = createRequire(from)
718 for (const name of ["typescript", "typescript-6"]) {
719 let candidate: Partial<typeof ts> | undefined
720 try {
721 candidate = require(name)
722 } catch {
723 continue
724 }
725 if (/^(?:5\.(?:[5-9]|\d{2,})|6)\./.test(candidate?.version ?? ""))
726 return candidate as never
727 }
728 }
729 return throwError(
730 "ark declare and ark emit read the compiler API of TypeScript 5.5 to 6. Install `typescript`, or beside TypeScript 7, `typescript-6` as an alias: `npm i -D typescript-6@npm:typescript@6`"
731 )
732}
733
734export const parseConfig = (
735 ts: TypeScript,

Callers 2

emitPrecompiledFunction · 0.90
emitDeclarationsJsFunction · 0.85

Calls 3

throwErrorFunction · 0.90
joinFunction · 0.85
testMethod · 0.80

Tested by

no test coverage detected