mnfst-render 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1218,6 +1218,7 @@ async function runPrerender(config) {
1218
1218
  const timeout = config.wait ?? 15000;
1219
1219
  const concurrency = config.concurrency;
1220
1220
  const pathTotal = pathList.length;
1221
+ const failedPaths = [];
1221
1222
  process.stdout.write(`Prerendering ${pathTotal} path(s)...\n`);
1222
1223
 
1223
1224
  async function processPath(pathSeg, pathIndex) {
@@ -1229,6 +1230,12 @@ async function runPrerender(config) {
1229
1230
  const fileSegments = is404 ? [] : pathToFileSegments(pathSeg ? `/${pathSeg}` : '/');
1230
1231
  const outDir = is404 ? config.output : join(config.output, ...fileSegments);
1231
1232
  const outFile = is404 ? join(config.output, '404.html') : join(outDir, 'index.html');
1233
+ const currentLocale =
1234
+ pathSeg && locales.length > 0
1235
+ ? locales.includes(pathSeg.split('/')[0])
1236
+ ? pathSeg.split('/')[0]
1237
+ : defaultLocale || 'en'
1238
+ : defaultLocale || 'en';
1232
1239
 
1233
1240
  const page = await browser.newPage();
1234
1241
  try {
@@ -1325,7 +1332,7 @@ async function runPrerender(config) {
1325
1332
  // no-op
1326
1333
  }
1327
1334
  }, { allLocales: locales, currentLocale }).catch(() => { });
1328
- await page.waitForTimeout(60).catch(() => { });
1335
+ await new Promise((resolve) => setTimeout(resolve, 60));
1329
1336
 
1330
1337
  // Optional extra delay so in-page async (e.g. fetch() in x-init for client logos) can complete before snapshot.
1331
1338
  if (config.waitAfterIdle > 0) {
@@ -1478,12 +1485,6 @@ async function runPrerender(config) {
1478
1485
  }
1479
1486
  html = stripDuplicatedLoopDirectives(html);
1480
1487
  html = stripPrerenderedXDataDirectives(html);
1481
- const currentLocale =
1482
- pathSeg && locales.length > 0
1483
- ? locales.includes(pathSeg.split('/')[0])
1484
- ? pathSeg.split('/')[0]
1485
- : defaultLocale || 'en'
1486
- : defaultLocale || 'en';
1487
1488
  const content = loadContentForPrerender(manifest, config.root, currentLocale);
1488
1489
  const xData = { manifest, content };
1489
1490
  html = resolveHeadXBindings(html, xData);
@@ -1501,7 +1502,13 @@ async function runPrerender(config) {
1501
1502
  mkdirSync(outDir, { recursive: true });
1502
1503
  writeFileSync(outFile, html, 'utf8');
1503
1504
  } catch (err) {
1504
- // path failed (swallowed to allow other paths to complete)
1505
+ failedPaths.push({
1506
+ path: displayPath,
1507
+ message: err && err.message ? err.message : String(err)
1508
+ });
1509
+ if (failedPaths.length <= 10) {
1510
+ process.stderr.write(`prerender: failed ${displayPath}: ${failedPaths[failedPaths.length - 1].message}\n`);
1511
+ }
1505
1512
  } finally {
1506
1513
  await page.close();
1507
1514
  }
@@ -1523,6 +1530,11 @@ async function runPrerender(config) {
1523
1530
  await browser.close();
1524
1531
  }
1525
1532
 
1533
+ if (failedPaths.length > 0) {
1534
+ const sample = failedPaths.slice(0, 5).map((f) => `${f.path}: ${f.message}`).join(' | ');
1535
+ throw new Error(`prerender failed for ${failedPaths.length}/${pathTotal} paths. Sample: ${sample}`);
1536
+ }
1537
+
1526
1538
  if (bundleUtilities) {
1527
1539
  const utilMerged = mergeUtilityCssBlocks(utilityBlocks);
1528
1540
  if (utilMerged.trim()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mnfst-render",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Render Manifest sites to static HTML for SEO",
5
5
  "type": "module",
6
6
  "bin": {