import u from"node:path";import{logger as n}from"../../tools/notifiers/logger.js";import{reporter as s}from"../../tools/notifiers/reporter.js";import{getServerProps as d}from"../../ssr/server-side-props/get-server-props.js";import{telemetry as f}from"../../../cli/telemetry/index.js";async function b(e,o){s.clearPageRenderProblems();const r=e.getAllRoutes().filter(t=>t.fsPath.match(/\.page\.tsx?$/));if(!r.length)return;const l=n.startTiming();n.info("Validating react pages");const g=await p(e.serverOutDir);for(const t of r){const c=await e.resolveRouteStaticData(t,o),m=await d(t,null,c,e);let a;try{a=(await g(t,m,null,e,f,!0)).error}catch(i){a=i}a&&s.reportPageRenderError({message:a.name==="PageMissingDefaultExportError"?a.message:`Runtime error: ${a.message}`,sourceFileRelativePath:t.fsPath})}n.infoTime(l,`Validated ${r.length} React pages`)}async function p(e){const r=await import(u.join(e,"index.mjs"));if(!r.renderPage)throw new Error("renderPage function not found in bundle");return r.renderPage}export{b as validateReactPages};
