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

Function emitProject

ark/aot/emit.ts:94–193  ·  view source on GitHub ↗
(
	ts: TypeScript,
	config: ts.ParsedCommandLine,
	result: EmittedModules,
	request: ReturnType<typeof createSyncPrecompiler>,
	rewrites: (specifier: string) => boolean
)

Source from the content-addressed store, hash-verified

92 config.options.configFilePath as string
93
94const emitProject = (
95 ts: TypeScript,
96 config: ts.ParsedCommandLine,
97 result: EmittedModules,
98 request: ReturnType<typeof createSyncPrecompiler>,
99 rewrites: (specifier: string) => boolean
100) => {
101 if (!config.fileNames.length) return
102 const { options } = config
103 if (options.noEmit || options.emitDeclarationOnly)
104 throwError(writeUnemittedMessage(resolve(configPathOf(config))))
105 const emitOptions = emitOptionsOf(options)
106 const host = ts.createCompilerHost(emitOptions)
107 const { getSourceFile } = host
108 const precompiled: Record<string, TransformedModule> = {}
109 // the program precompiled modules are emitted from reuses the others
110 const sourceFiles: Record<string, ts.SourceFile | undefined> = {}
111 host.getSourceFile = (fileName, languageVersion, ...rest) =>
112 fileName in precompiled ?
113 ts.createSourceFile(
114 fileName,
115 precompiled[fileName].code!,
116 languageVersion,
117 true
118 )
119 : (sourceFiles[fileName] ??= getSourceFile(
120 fileName,
121 languageVersion,
122 ...rest
123 ))
124 const programOptions: ts.CreateProgramOptions = {
125 rootNames: config.fileNames,
126 options: emitOptions,
127 host,
128 ...(config.projectReferences && {
129 projectReferences: config.projectReferences
130 })
131 }
132 const program = ts.createProgram(programOptions)
133 const emitted: ts.SourceFile[] = []
134 const { rootDir } = options
135 // tsc fails on a module outside rootDir, as one resolved to its source
136 const files = emittedFilesOf(program).filter(
137 file => !rootDir || isInside(rootDir, file.fileName)
138 )
139 // the project is the whole program, so a site another module may write a
140 // value of is refused
141 request("program", {
142 modules: Object.fromEntries(
143 files.map(file => [realPathOf(file.fileName), { source: file.text }])
144 )
145 } satisfies ReadProgram)
146 for (const file of files) {
147 const transformed = request(
148 "transform",
149 file.text,
150 realPathOf(file.fileName)
151 ) as TransformedModule | undefined

Callers 1

emitPrecompiledFunction · 0.85

Calls 15

throwErrorFunction · 0.90
emittedFilesOfFunction · 0.90
realPathOfFunction · 0.90
writeUnemittedMessageFunction · 0.85
configPathOfFunction · 0.85
emitOptionsOfFunction · 0.85
getSourceFileFunction · 0.85
isInsideFunction · 0.85
hoistImportsOfFunction · 0.85
rewriterOfFunction · 0.85
writeOutputsFunction · 0.85
filterMethod · 0.80

Tested by

no test coverage detected