// in index.ts, simplify async function _renderUniversal( routes: string[], context: BuilderContext, clientPath: string, serverPath: string, indexFile: string ): Promise<BuilderOutput> { // the server bundle is server/main.js const serverBundlePath = path.join(serverPath, 'main.js'); // no more loop into outputPaths if (!fs.existsSync(serverBundlePath)) { throw new Error(`Could not find the main bundle: ${serverBundlePath}`); } context.logger.info(`Prerendering ${routes.length} route(s) to ${clientPath}...`); try { // reduced the two tries into one // this map is alright, I'll keep it const results = (await Promise.all( routes.map((route) => { // removed deployUrl, and assume css related props const options: RenderOptions = { indexFile, clientPath, // this is outputPath route, serverBundlePath }; // direct import from worker, no more Piscina worker return PreRender(options); }) )) as RenderResult[]; let numErrors = 0; for (const { errors, warnings } of results) { errors?.forEach((e) => context.logger.error(e)); warnings?.forEach((e) => context.logger.warn(e)); numErrors += errors?.length ?? 0; } if (numErrors > 0) { throw Error(`Rendering failed with ${numErrors} worker errors.`); } context.logger.info(`Prerendering routes to ${clientPath} complete.`); } catch (err) { context.logger.error(`Prerendering routes to ${clientPath} failed.`); return { success: false, error: err.message }; } return { success: true}; }