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

Function answerFromProgram

ark/aot/turbopack.ts:221–262  ·  view source on GitHub ↗
(
	context: TurbopackLoaderContext,
	source: string,
	opts: PrecompilePluginOptions
)

Source from the content-addressed store, hash-verified

219 !!packageRootOf("next", context.rootContext)
220
221const answerFromProgram = async (
222 context: TurbopackLoaderContext,
223 source: string,
224 opts: PrecompilePluginOptions
225): Promise<string | undefined> => {
226 const id = context.resourcePath
227 if (isProgramUnit(id)) return source
228 const program = programOf(context.rootContext!, opts)
229 // what Turbopack's build cache keeps its output against
230 context.addDependency(doneFileOf(program.dir))
231 if (program.refused) {
232 if (opts.prune === true) throwBuildError(program.refused)
233 // next.config's wrapper reports why it can't read the project
234 if (!isProgramRead() && isFirstToWarn(program.dir))
235 context.emitWarning(new Error(program.refused))
236 return answerAlone(context, source, opts)
237 }
238 context.addDependency(answerFileOf(program.dir, id))
239 const answer = programAnswerOf(program, id)
240 // a dependency it leaves is checked as ever, and one it doesn't is a module
241 // the read missed, whose reads it can't have planned for
242 if (!answer) {
243 if (dependencyOf(id) || isArkFile(id))
244 return answerAlone(context, source, opts)
245 throwBuildError(
246 writeMissedByProgramMessage(
247 printablePathOf(context.rootContext!, id),
248 "is built"
249 )
250 )
251 }
252 if (!isSourceRead(answer!, source)) {
253 throwBuildError(
254 writeMissedByProgramMessage(
255 printablePathOf(context.rootContext!, id),
256 "reaches this loader rewritten"
257 )
258 )
259 }
260 await checkImports(context, program, answer!)
261 return loadedOf(context, () => precompilerOf(opts), answer!, source, opts)
262}
263
264// the first of a build's processes, whose parent each shares, to ask
265const isFirstToWarn = (dir: string) => {

Callers 1

turbopack.tsFile · 0.85

Calls 15

isProgramUnitFunction · 0.90
programOfFunction · 0.90
doneFileOfFunction · 0.90
throwBuildErrorFunction · 0.90
isProgramReadFunction · 0.90
answerFileOfFunction · 0.90
programAnswerOfFunction · 0.90
dependencyOfFunction · 0.90
isArkFileFunction · 0.90
printablePathOfFunction · 0.90
isSourceReadFunction · 0.90
isFirstToWarnFunction · 0.85

Tested by

no test coverage detected