prev-cli 0.24.13 → 0.24.15

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.
package/dist/cli.js CHANGED
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env node
2
+ import { createRequire } from "node:module";
3
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
2
4
 
3
5
  // src/cli.ts
4
6
  import { parseArgs } from "util";
5
7
  import path11 from "path";
6
- import { existsSync as existsSync8, mkdirSync as mkdirSync4, writeFileSync as writeFileSync6, rmSync as rmSync4, readFileSync as readFileSync7 } from "fs";
8
+ import { existsSync as existsSync9, mkdirSync as mkdirSync4, writeFileSync as writeFileSync6, rmSync as rmSync4, readFileSync as readFileSync7 } from "fs";
7
9
  import { fileURLToPath as fileURLToPath4 } from "url";
8
10
 
9
11
  // src/vite/start.ts
@@ -18,7 +20,7 @@ import rehypeHighlight from "rehype-highlight";
18
20
  import path8 from "path";
19
21
  import os from "os";
20
22
  import { fileURLToPath as fileURLToPath3 } from "url";
21
- import { existsSync as existsSync6, readFileSync as readFileSync6 } from "fs";
23
+ import { existsSync as existsSync7, readFileSync as readFileSync6 } from "fs";
22
24
 
23
25
  // src/vite/plugins/pages-plugin.ts
24
26
  import path2 from "path";
@@ -660,9 +662,20 @@ import { build as build2 } from "esbuild";
660
662
 
661
663
  // src/preview-runtime/tailwind.ts
662
664
  import { $ } from "bun";
663
- import { mkdtempSync, mkdirSync, writeFileSync as writeFileSync2, readFileSync as readFileSync4, rmSync } from "fs";
665
+ import { mkdtempSync, mkdirSync, writeFileSync as writeFileSync2, readFileSync as readFileSync4, rmSync, existsSync as existsSync4 } from "fs";
664
666
  import { join, dirname as dirname2 } from "path";
665
667
  import { tmpdir } from "os";
668
+ function findTailwindBin() {
669
+ try {
670
+ const tailwindPkg = __require.resolve("tailwindcss/package.json");
671
+ const tailwindDir = dirname2(tailwindPkg);
672
+ const binPath = join(tailwindDir, "lib/cli.js");
673
+ if (existsSync4(binPath))
674
+ return binPath;
675
+ } catch {}
676
+ return "bunx tailwindcss@3";
677
+ }
678
+ var tailwindCmd = findTailwindBin();
666
679
  async function compileTailwind(files) {
667
680
  const tempDir = mkdtempSync(join(tmpdir(), "prev-tailwind-"));
668
681
  try {
@@ -687,7 +700,11 @@ async function compileTailwind(files) {
687
700
  const inputPath = join(tempDir, "input.css");
688
701
  writeFileSync2(inputPath, inputCss);
689
702
  const outputPath = join(tempDir, "output.css");
690
- await $`bunx tailwindcss -c ${configPath} -i ${inputPath} -o ${outputPath} --minify`.quiet();
703
+ if (tailwindCmd.startsWith("bunx")) {
704
+ await $`bunx tailwindcss@3 -c ${configPath} -i ${inputPath} -o ${outputPath} --minify`.quiet();
705
+ } else {
706
+ await $`bun ${tailwindCmd} -c ${configPath} -i ${inputPath} -o ${outputPath} --minify`.quiet();
707
+ }
691
708
  const css = readFileSync4(outputPath, "utf-8");
692
709
  return { success: true, css };
693
710
  } catch (err) {
@@ -776,8 +793,11 @@ async function buildOptimizedPreview(config, options) {
776
793
  if (tailwindResult.success)
777
794
  css = tailwindResult.css;
778
795
  }
779
- const userCss = userCssCollected.join(`
796
+ let userCss = userCssCollected.join(`
780
797
  `);
798
+ if (config.tailwind) {
799
+ userCss = userCss.replace(/@import\s*["']tailwindcss["']\s*;?/g, "");
800
+ }
781
801
  const allCss = css + `
782
802
  ` + userCss;
783
803
  const html = `<!DOCTYPE html>
@@ -802,7 +822,7 @@ async function buildOptimizedPreview(config, options) {
802
822
  }
803
823
 
804
824
  // src/vite/plugins/previews-plugin.ts
805
- import { existsSync as existsSync4, mkdirSync as mkdirSync2, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
825
+ import { existsSync as existsSync5, mkdirSync as mkdirSync2, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
806
826
  import path5 from "path";
807
827
  var VIRTUAL_MODULE_ID2 = "virtual:prev-previews";
808
828
  var RESOLVED_VIRTUAL_MODULE_ID2 = "\x00" + VIRTUAL_MODULE_ID2;
@@ -868,10 +888,10 @@ export function getByStatus(status) {
868
888
  const vendorsDir = path5.join(targetDir, "_vendors");
869
889
  const previewsDir = path5.join(rootDir, "previews");
870
890
  const oldPreviewsDir = path5.join(distDir, "previews");
871
- if (existsSync4(oldPreviewsDir)) {
891
+ if (existsSync5(oldPreviewsDir)) {
872
892
  rmSync2(oldPreviewsDir, { recursive: true });
873
893
  }
874
- if (existsSync4(targetDir)) {
894
+ if (existsSync5(targetDir)) {
875
895
  rmSync2(targetDir, { recursive: true });
876
896
  }
877
897
  const previews = await scanPreviews(rootDir);
@@ -1021,15 +1041,15 @@ function validateConfig(raw) {
1021
1041
  return config;
1022
1042
  }
1023
1043
  // src/config/loader.ts
1024
- import { readFileSync as readFileSync5, existsSync as existsSync5, writeFileSync as writeFileSync4 } from "fs";
1044
+ import { readFileSync as readFileSync5, existsSync as existsSync6, writeFileSync as writeFileSync4 } from "fs";
1025
1045
  import path6 from "path";
1026
1046
  import yaml2 from "js-yaml";
1027
1047
  function findConfigFile(rootDir) {
1028
1048
  const yamlPath = path6.join(rootDir, ".prev.yaml");
1029
1049
  const ymlPath = path6.join(rootDir, ".prev.yml");
1030
- if (existsSync5(yamlPath))
1050
+ if (existsSync6(yamlPath))
1031
1051
  return yamlPath;
1032
- if (existsSync5(ymlPath))
1052
+ if (existsSync6(ymlPath))
1033
1053
  return ymlPath;
1034
1054
  return null;
1035
1055
  }
@@ -1224,7 +1244,7 @@ function findCliRoot2() {
1224
1244
  let dir = path8.dirname(fileURLToPath3(import.meta.url));
1225
1245
  for (let i = 0;i < 10; i++) {
1226
1246
  const pkgPath = path8.join(dir, "package.json");
1227
- if (existsSync6(pkgPath)) {
1247
+ if (existsSync7(pkgPath)) {
1228
1248
  try {
1229
1249
  const pkg = JSON.parse(readFileSync6(pkgPath, "utf-8"));
1230
1250
  if (pkg.name === "prev-cli") {
@@ -1241,7 +1261,7 @@ function findCliRoot2() {
1241
1261
  }
1242
1262
  function findNodeModules(cliRoot2) {
1243
1263
  const localNodeModules = path8.join(cliRoot2, "node_modules");
1244
- if (existsSync6(path8.join(localNodeModules, "react"))) {
1264
+ if (existsSync7(path8.join(localNodeModules, "react"))) {
1245
1265
  return localNodeModules;
1246
1266
  }
1247
1267
  let dir = cliRoot2;
@@ -1249,7 +1269,7 @@ function findNodeModules(cliRoot2) {
1249
1269
  const parent = path8.dirname(dir);
1250
1270
  if (parent === dir)
1251
1271
  break;
1252
- if (path8.basename(parent) === "node_modules" && existsSync6(path8.join(parent, "react"))) {
1272
+ if (path8.basename(parent) === "node_modules" && existsSync7(path8.join(parent, "react"))) {
1253
1273
  return parent;
1254
1274
  }
1255
1275
  dir = parent;
@@ -1333,7 +1353,7 @@ async function createViteConfig(options) {
1333
1353
  return next();
1334
1354
  }
1335
1355
  const indexPath = path8.join(srcRoot2, "theme/index.html");
1336
- if (existsSync6(indexPath)) {
1356
+ if (existsSync7(indexPath)) {
1337
1357
  server.transformIndexHtml(req.url, readFileSync6(indexPath, "utf-8")).then((html) => {
1338
1358
  res.setHeader("Content-Type", "text/html");
1339
1359
  res.end(html);
@@ -1362,7 +1382,7 @@ async function createViteConfig(options) {
1362
1382
  const urlPath = req.url?.split("?")[0] || "";
1363
1383
  if (urlPath === "/_preview-runtime") {
1364
1384
  const templatePath = path8.join(srcRoot2, "preview-runtime/template.html");
1365
- if (existsSync6(templatePath)) {
1385
+ if (existsSync7(templatePath)) {
1366
1386
  const html = readFileSync6(templatePath, "utf-8");
1367
1387
  res.setHeader("Content-Type", "text/html");
1368
1388
  res.end(html);
@@ -1377,13 +1397,13 @@ async function createViteConfig(options) {
1377
1397
  const [, type, name] = multiTypeMatch;
1378
1398
  const configPathYaml = path8.join(previewsDir, type, name, "index.yaml");
1379
1399
  const configPathYml = path8.join(previewsDir, type, name, "index.yml");
1380
- const configPath = existsSync6(configPathYaml) ? configPathYaml : configPathYml;
1400
+ const configPath = existsSync7(configPathYaml) ? configPathYaml : configPathYml;
1381
1401
  if (!configPath.startsWith(previewsDir)) {
1382
1402
  res.statusCode = 403;
1383
1403
  res.end("Forbidden");
1384
1404
  return;
1385
1405
  }
1386
- if (existsSync6(configPath)) {
1406
+ if (existsSync7(configPath)) {
1387
1407
  try {
1388
1408
  if (type === "flows") {
1389
1409
  const flow = await parseFlowDefinition(configPath);
@@ -1423,7 +1443,7 @@ async function createViteConfig(options) {
1423
1443
  res.end("Forbidden");
1424
1444
  return;
1425
1445
  }
1426
- if (existsSync6(previewDir)) {
1446
+ if (existsSync7(previewDir)) {
1427
1447
  try {
1428
1448
  const config2 = await buildPreviewConfig(previewDir);
1429
1449
  res.setHeader("Content-Type", "application/json");
@@ -1477,7 +1497,7 @@ async function createViteConfig(options) {
1477
1497
  if (!htmlPath.startsWith(previewsDir)) {
1478
1498
  return next();
1479
1499
  }
1480
- if (existsSync6(htmlPath)) {
1500
+ if (existsSync7(htmlPath)) {
1481
1501
  try {
1482
1502
  let html = readFileSync6(htmlPath, "utf-8");
1483
1503
  const previewBase = `/_preview/${previewName}/`;
@@ -1606,7 +1626,7 @@ async function findAvailablePort(minPort, maxPort) {
1606
1626
 
1607
1627
  // src/vite/start.ts
1608
1628
  import { exec } from "child_process";
1609
- import { existsSync as existsSync7, rmSync as rmSync3, copyFileSync } from "fs";
1629
+ import { existsSync as existsSync8, rmSync as rmSync3, copyFileSync } from "fs";
1610
1630
  import path9 from "path";
1611
1631
  function printWelcome(type) {
1612
1632
  console.log();
@@ -1643,11 +1663,11 @@ function clearCache(rootDir) {
1643
1663
  const viteCacheDir = path9.join(rootDir, ".vite");
1644
1664
  const nodeModulesVite = path9.join(rootDir, "node_modules", ".vite");
1645
1665
  let cleared = 0;
1646
- if (existsSync7(viteCacheDir)) {
1666
+ if (existsSync8(viteCacheDir)) {
1647
1667
  rmSync3(viteCacheDir, { recursive: true });
1648
1668
  cleared++;
1649
1669
  }
1650
- if (existsSync7(nodeModulesVite)) {
1670
+ if (existsSync8(nodeModulesVite)) {
1651
1671
  rmSync3(nodeModulesVite, { recursive: true });
1652
1672
  cleared++;
1653
1673
  }
@@ -1769,7 +1789,7 @@ async function buildSite(rootDir, options = {}) {
1769
1789
  const distDir = path9.join(rootDir, "dist");
1770
1790
  const indexPath = path9.join(distDir, "index.html");
1771
1791
  const notFoundPath = path9.join(distDir, "404.html");
1772
- if (existsSync7(indexPath)) {
1792
+ if (existsSync8(indexPath)) {
1773
1793
  copyFileSync(indexPath, notFoundPath);
1774
1794
  }
1775
1795
  console.log();
@@ -1854,7 +1874,7 @@ function getVersion() {
1854
1874
  let dir = path11.dirname(fileURLToPath4(import.meta.url));
1855
1875
  for (let i = 0;i < 5; i++) {
1856
1876
  const pkgPath = path11.join(dir, "package.json");
1857
- if (existsSync8(pkgPath)) {
1877
+ if (existsSync9(pkgPath)) {
1858
1878
  const pkg = JSON.parse(readFileSync7(pkgPath, "utf-8"));
1859
1879
  if (pkg.name === "prev-cli")
1860
1880
  return pkg.version;
@@ -1982,7 +2002,7 @@ async function clearViteCache(rootDir2) {
1982
2002
  let cleared = 0;
1983
2003
  try {
1984
2004
  const prevCacheDir = await getCacheDir(rootDir2);
1985
- if (existsSync8(prevCacheDir)) {
2005
+ if (existsSync9(prevCacheDir)) {
1986
2006
  rmSync4(prevCacheDir, { recursive: true });
1987
2007
  cleared++;
1988
2008
  console.log(` ✓ Removed ${prevCacheDir}`);
@@ -1990,12 +2010,12 @@ async function clearViteCache(rootDir2) {
1990
2010
  } catch {}
1991
2011
  const viteCacheDir = path11.join(rootDir2, ".vite");
1992
2012
  const nodeModulesVite = path11.join(rootDir2, "node_modules", ".vite");
1993
- if (existsSync8(viteCacheDir)) {
2013
+ if (existsSync9(viteCacheDir)) {
1994
2014
  rmSync4(viteCacheDir, { recursive: true });
1995
2015
  cleared++;
1996
2016
  console.log(` ✓ Removed .vite/`);
1997
2017
  }
1998
- if (existsSync8(nodeModulesVite)) {
2018
+ if (existsSync9(nodeModulesVite)) {
1999
2019
  rmSync4(nodeModulesVite, { recursive: true });
2000
2020
  cleared++;
2001
2021
  console.log(` ✓ Removed node_modules/.vite/`);
@@ -2101,7 +2121,7 @@ Available subcommands: show, init, path`);
2101
2121
  }
2102
2122
  function createPreview(rootDir2, name) {
2103
2123
  const previewDir = path11.join(rootDir2, "previews", name);
2104
- if (existsSync8(previewDir)) {
2124
+ if (existsSync9(previewDir)) {
2105
2125
  console.error(`Preview "${name}" already exists at: ${previewDir}`);
2106
2126
  process.exit(1);
2107
2127
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prev-cli",
3
- "version": "0.24.13",
3
+ "version": "0.24.15",
4
4
  "description": "Transform MDX directories into beautiful documentation websites",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -64,7 +64,7 @@
64
64
  "rehype-highlight": "^7.0.0",
65
65
  "remark-gfm": "^4.0.0",
66
66
  "tailwind-merge": "^2.5.0",
67
- "tailwindcss": "^4.0.0",
67
+ "tailwindcss": "3",
68
68
  "vite": "npm:rolldown-vite@^7.3.1",
69
69
  "zod": "^4.3.5"
70
70
  },
@@ -110,7 +110,12 @@ export async function buildOptimizedPreview(
110
110
  if (tailwindResult.success) css = tailwindResult.css
111
111
  }
112
112
 
113
- const userCss = userCssCollected.join('\n')
113
+ // Strip @import "tailwindcss" from user CSS when Tailwind is compiled
114
+ // (the import is Tailwind v4 dev syntax, not valid for static HTML)
115
+ let userCss = userCssCollected.join('\n')
116
+ if (config.tailwind) {
117
+ userCss = userCss.replace(/@import\s*["']tailwindcss["']\s*;?/g, '')
118
+ }
114
119
  const allCss = css + '\n' + userCss
115
120
 
116
121
  const html = `<!DOCTYPE html>
@@ -1,8 +1,24 @@
1
1
  import { $ } from 'bun'
2
- import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync } from 'fs'
2
+ import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, existsSync } from 'fs'
3
3
  import { join, dirname } from 'path'
4
4
  import { tmpdir } from 'os'
5
5
 
6
+ // Resolve tailwindcss CLI - try multiple locations
7
+ function findTailwindBin(): string {
8
+ // Try require.resolve to find the tailwindcss package
9
+ try {
10
+ const tailwindPkg = require.resolve('tailwindcss/package.json')
11
+ const tailwindDir = dirname(tailwindPkg)
12
+ const binPath = join(tailwindDir, 'lib/cli.js')
13
+ if (existsSync(binPath)) return binPath
14
+ } catch {}
15
+
16
+ // Fallback: use bunx (slower but always works)
17
+ return 'bunx tailwindcss@3'
18
+ }
19
+
20
+ const tailwindCmd = findTailwindBin()
21
+
6
22
  export interface TailwindResult {
7
23
  success: boolean
8
24
  css: string
@@ -47,7 +63,11 @@ export async function compileTailwind(files: ContentFile[]): Promise<TailwindRes
47
63
  const outputPath = join(tempDir, 'output.css')
48
64
 
49
65
  // Run Tailwind CLI
50
- await $`bunx tailwindcss -c ${configPath} -i ${inputPath} -o ${outputPath} --minify`.quiet()
66
+ if (tailwindCmd.startsWith('bunx')) {
67
+ await $`bunx tailwindcss@3 -c ${configPath} -i ${inputPath} -o ${outputPath} --minify`.quiet()
68
+ } else {
69
+ await $`bun ${tailwindCmd} -c ${configPath} -i ${inputPath} -o ${outputPath} --minify`.quiet()
70
+ }
51
71
 
52
72
  const css = readFileSync(outputPath, 'utf-8')
53
73