mnfst-render 0.1.7 → 0.1.8

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  /* Manifest Render */
4
4
 
5
- import { readFileSync, mkdirSync, writeFileSync, existsSync, rmSync, statSync, readdirSync, cpSync, unlinkSync } from 'node:fs';
5
+ import { readFileSync, readSync, mkdirSync, writeFileSync, existsSync, rmSync, statSync, readdirSync, cpSync, unlinkSync } from 'node:fs';
6
6
  import { spawnSync } from 'node:child_process';
7
7
  import { join, resolve, dirname, relative, basename, sep } from 'node:path';
8
8
  import { createServer } from 'node:http';
@@ -472,6 +472,38 @@ function indexHtmlUsesTailwind(rootDir) {
472
472
  return /\sdata-tailwind(?:=(["']).*?\1)?/i.test(html) && /<script[^>]*manifest\.min\.js/i.test(html);
473
473
  }
474
474
 
475
+ function promptContinueWithRuntimeTailwind(rootDir) {
476
+ const installMsg = [
477
+ 'prerender: tailwindcss package is not installed for this project.',
478
+ '',
479
+ 'To enable static Tailwind CSS compilation, install:',
480
+ ' npm i -D tailwindcss @tailwindcss/cli',
481
+ '',
482
+ `Project: ${rootDir}`,
483
+ '',
484
+ 'Continue prerender with runtime data-tailwind instead? [P]roceed/[E]nd (default: P): ',
485
+ ].join('\n');
486
+ process.stdout.write(`${installMsg}\n`);
487
+
488
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
489
+ process.stdout.write(
490
+ 'prerender: non-interactive terminal detected; continuing with runtime data-tailwind behavior.\n'
491
+ );
492
+ return true;
493
+ }
494
+ const buf = Buffer.alloc(1);
495
+ let answer = '';
496
+ while (true) {
497
+ const n = readSync(0, buf, 0, 1, null);
498
+ if (n <= 0) break;
499
+ const ch = buf.toString('utf8', 0, n);
500
+ if (ch === '\n' || ch === '\r') break;
501
+ answer += ch;
502
+ }
503
+ const normalized = answer.trim().toLowerCase();
504
+ return normalized === '' || normalized === 'p' || normalized === 'proceed' || normalized === 'y' || normalized === 'yes';
505
+ }
506
+
475
507
  /**
476
508
  * Build a static Tailwind stylesheet via @tailwindcss/cli (v4+), scanning project sources.
477
509
  * Only runs when the project opts in (data-tailwind on manifest script) or manifest.prerender.tailwind === true.
@@ -483,6 +515,16 @@ function runTailwindCliForPrerender(rootDir, outputDir, pre) {
483
515
  if (!usesTailwind) return false;
484
516
 
485
517
  const outCss = join(outputDir, 'prerender.tailwind.css');
518
+ try {
519
+ require.resolve('tailwindcss', { paths: [rootDir] });
520
+ } catch {
521
+ const proceed = promptContinueWithRuntimeTailwind(rootDir);
522
+ if (!proceed) {
523
+ throw new Error('prerender aborted: install tailwindcss/@tailwindcss/cli or disable prerender.tailwind.');
524
+ }
525
+ process.stdout.write('prerender: continuing with runtime data-tailwind behavior.\n');
526
+ return false;
527
+ }
486
528
  let inputPath = null;
487
529
  let createdTempInput = false;
488
530
  const userInput = pre?.tailwindInput;
@@ -1354,7 +1396,9 @@ async function runPrerender(config) {
1354
1396
  let html = await page.evaluate(() => document.documentElement.outerHTML);
1355
1397
  html = stripDevOnlyContent(html);
1356
1398
  html = stripInjectedPluginScripts(html);
1357
- html = stripRuntimeTailwindArtifacts(html);
1399
+ if (tailwindBuilt) {
1400
+ html = stripRuntimeTailwindArtifacts(html);
1401
+ }
1358
1402
  if (bundleUtilities) {
1359
1403
  const extracted = extractUtilityStyleBlocks(html);
1360
1404
  html = extracted.html;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mnfst-render",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Render Manifest sites to static HTML for SEO",
5
5
  "type": "module",
6
6
  "bin": {