( context: TurbopackLoaderContext, source: string, opts: PrecompilePluginOptions )
| 219 | !!packageRootOf("next", context.rootContext) |
| 220 | |
| 221 | const 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 |
| 265 | const isFirstToWarn = (dir: string) => { |
no test coverage detected