prev-cli 0.24.14 → 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,10 +1,12 @@
|
|
|
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
|
|
7
|
-
import { fileURLToPath as
|
|
8
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync4, writeFileSync as writeFileSync6, rmSync as rmSync4, readFileSync as readFileSync7 } from "fs";
|
|
9
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
8
10
|
|
|
9
11
|
// src/vite/start.ts
|
|
10
12
|
import { createServer as createServer2, build as build3, preview } from "vite";
|
|
@@ -17,8 +19,8 @@ import remarkGfm from "remark-gfm";
|
|
|
17
19
|
import rehypeHighlight from "rehype-highlight";
|
|
18
20
|
import path8 from "path";
|
|
19
21
|
import os from "os";
|
|
20
|
-
import { fileURLToPath as
|
|
21
|
-
import { existsSync as
|
|
22
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
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,12 +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";
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
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();
|
|
669
679
|
async function compileTailwind(files) {
|
|
670
680
|
const tempDir = mkdtempSync(join(tmpdir(), "prev-tailwind-"));
|
|
671
681
|
try {
|
|
@@ -690,7 +700,11 @@ async function compileTailwind(files) {
|
|
|
690
700
|
const inputPath = join(tempDir, "input.css");
|
|
691
701
|
writeFileSync2(inputPath, inputCss);
|
|
692
702
|
const outputPath = join(tempDir, "output.css");
|
|
693
|
-
|
|
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
|
+
}
|
|
694
708
|
const css = readFileSync4(outputPath, "utf-8");
|
|
695
709
|
return { success: true, css };
|
|
696
710
|
} catch (err) {
|
|
@@ -779,8 +793,11 @@ async function buildOptimizedPreview(config, options) {
|
|
|
779
793
|
if (tailwindResult.success)
|
|
780
794
|
css = tailwindResult.css;
|
|
781
795
|
}
|
|
782
|
-
|
|
796
|
+
let userCss = userCssCollected.join(`
|
|
783
797
|
`);
|
|
798
|
+
if (config.tailwind) {
|
|
799
|
+
userCss = userCss.replace(/@import\s*["']tailwindcss["']\s*;?/g, "");
|
|
800
|
+
}
|
|
784
801
|
const allCss = css + `
|
|
785
802
|
` + userCss;
|
|
786
803
|
const html = `<!DOCTYPE html>
|
|
@@ -805,7 +822,7 @@ async function buildOptimizedPreview(config, options) {
|
|
|
805
822
|
}
|
|
806
823
|
|
|
807
824
|
// src/vite/plugins/previews-plugin.ts
|
|
808
|
-
import { existsSync as
|
|
825
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync2, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
809
826
|
import path5 from "path";
|
|
810
827
|
var VIRTUAL_MODULE_ID2 = "virtual:prev-previews";
|
|
811
828
|
var RESOLVED_VIRTUAL_MODULE_ID2 = "\x00" + VIRTUAL_MODULE_ID2;
|
|
@@ -871,10 +888,10 @@ export function getByStatus(status) {
|
|
|
871
888
|
const vendorsDir = path5.join(targetDir, "_vendors");
|
|
872
889
|
const previewsDir = path5.join(rootDir, "previews");
|
|
873
890
|
const oldPreviewsDir = path5.join(distDir, "previews");
|
|
874
|
-
if (
|
|
891
|
+
if (existsSync5(oldPreviewsDir)) {
|
|
875
892
|
rmSync2(oldPreviewsDir, { recursive: true });
|
|
876
893
|
}
|
|
877
|
-
if (
|
|
894
|
+
if (existsSync5(targetDir)) {
|
|
878
895
|
rmSync2(targetDir, { recursive: true });
|
|
879
896
|
}
|
|
880
897
|
const previews = await scanPreviews(rootDir);
|
|
@@ -1024,15 +1041,15 @@ function validateConfig(raw) {
|
|
|
1024
1041
|
return config;
|
|
1025
1042
|
}
|
|
1026
1043
|
// src/config/loader.ts
|
|
1027
|
-
import { readFileSync as readFileSync5, existsSync as
|
|
1044
|
+
import { readFileSync as readFileSync5, existsSync as existsSync6, writeFileSync as writeFileSync4 } from "fs";
|
|
1028
1045
|
import path6 from "path";
|
|
1029
1046
|
import yaml2 from "js-yaml";
|
|
1030
1047
|
function findConfigFile(rootDir) {
|
|
1031
1048
|
const yamlPath = path6.join(rootDir, ".prev.yaml");
|
|
1032
1049
|
const ymlPath = path6.join(rootDir, ".prev.yml");
|
|
1033
|
-
if (
|
|
1050
|
+
if (existsSync6(yamlPath))
|
|
1034
1051
|
return yamlPath;
|
|
1035
|
-
if (
|
|
1052
|
+
if (existsSync6(ymlPath))
|
|
1036
1053
|
return ymlPath;
|
|
1037
1054
|
return null;
|
|
1038
1055
|
}
|
|
@@ -1224,10 +1241,10 @@ function createFriendlyLogger() {
|
|
|
1224
1241
|
};
|
|
1225
1242
|
}
|
|
1226
1243
|
function findCliRoot2() {
|
|
1227
|
-
let dir = path8.dirname(
|
|
1244
|
+
let dir = path8.dirname(fileURLToPath3(import.meta.url));
|
|
1228
1245
|
for (let i = 0;i < 10; i++) {
|
|
1229
1246
|
const pkgPath = path8.join(dir, "package.json");
|
|
1230
|
-
if (
|
|
1247
|
+
if (existsSync7(pkgPath)) {
|
|
1231
1248
|
try {
|
|
1232
1249
|
const pkg = JSON.parse(readFileSync6(pkgPath, "utf-8"));
|
|
1233
1250
|
if (pkg.name === "prev-cli") {
|
|
@@ -1240,11 +1257,11 @@ function findCliRoot2() {
|
|
|
1240
1257
|
break;
|
|
1241
1258
|
dir = parent;
|
|
1242
1259
|
}
|
|
1243
|
-
return path8.dirname(path8.dirname(
|
|
1260
|
+
return path8.dirname(path8.dirname(fileURLToPath3(import.meta.url)));
|
|
1244
1261
|
}
|
|
1245
1262
|
function findNodeModules(cliRoot2) {
|
|
1246
1263
|
const localNodeModules = path8.join(cliRoot2, "node_modules");
|
|
1247
|
-
if (
|
|
1264
|
+
if (existsSync7(path8.join(localNodeModules, "react"))) {
|
|
1248
1265
|
return localNodeModules;
|
|
1249
1266
|
}
|
|
1250
1267
|
let dir = cliRoot2;
|
|
@@ -1252,7 +1269,7 @@ function findNodeModules(cliRoot2) {
|
|
|
1252
1269
|
const parent = path8.dirname(dir);
|
|
1253
1270
|
if (parent === dir)
|
|
1254
1271
|
break;
|
|
1255
|
-
if (path8.basename(parent) === "node_modules" &&
|
|
1272
|
+
if (path8.basename(parent) === "node_modules" && existsSync7(path8.join(parent, "react"))) {
|
|
1256
1273
|
return parent;
|
|
1257
1274
|
}
|
|
1258
1275
|
dir = parent;
|
|
@@ -1336,7 +1353,7 @@ async function createViteConfig(options) {
|
|
|
1336
1353
|
return next();
|
|
1337
1354
|
}
|
|
1338
1355
|
const indexPath = path8.join(srcRoot2, "theme/index.html");
|
|
1339
|
-
if (
|
|
1356
|
+
if (existsSync7(indexPath)) {
|
|
1340
1357
|
server.transformIndexHtml(req.url, readFileSync6(indexPath, "utf-8")).then((html) => {
|
|
1341
1358
|
res.setHeader("Content-Type", "text/html");
|
|
1342
1359
|
res.end(html);
|
|
@@ -1365,7 +1382,7 @@ async function createViteConfig(options) {
|
|
|
1365
1382
|
const urlPath = req.url?.split("?")[0] || "";
|
|
1366
1383
|
if (urlPath === "/_preview-runtime") {
|
|
1367
1384
|
const templatePath = path8.join(srcRoot2, "preview-runtime/template.html");
|
|
1368
|
-
if (
|
|
1385
|
+
if (existsSync7(templatePath)) {
|
|
1369
1386
|
const html = readFileSync6(templatePath, "utf-8");
|
|
1370
1387
|
res.setHeader("Content-Type", "text/html");
|
|
1371
1388
|
res.end(html);
|
|
@@ -1380,13 +1397,13 @@ async function createViteConfig(options) {
|
|
|
1380
1397
|
const [, type, name] = multiTypeMatch;
|
|
1381
1398
|
const configPathYaml = path8.join(previewsDir, type, name, "index.yaml");
|
|
1382
1399
|
const configPathYml = path8.join(previewsDir, type, name, "index.yml");
|
|
1383
|
-
const configPath =
|
|
1400
|
+
const configPath = existsSync7(configPathYaml) ? configPathYaml : configPathYml;
|
|
1384
1401
|
if (!configPath.startsWith(previewsDir)) {
|
|
1385
1402
|
res.statusCode = 403;
|
|
1386
1403
|
res.end("Forbidden");
|
|
1387
1404
|
return;
|
|
1388
1405
|
}
|
|
1389
|
-
if (
|
|
1406
|
+
if (existsSync7(configPath)) {
|
|
1390
1407
|
try {
|
|
1391
1408
|
if (type === "flows") {
|
|
1392
1409
|
const flow = await parseFlowDefinition(configPath);
|
|
@@ -1426,7 +1443,7 @@ async function createViteConfig(options) {
|
|
|
1426
1443
|
res.end("Forbidden");
|
|
1427
1444
|
return;
|
|
1428
1445
|
}
|
|
1429
|
-
if (
|
|
1446
|
+
if (existsSync7(previewDir)) {
|
|
1430
1447
|
try {
|
|
1431
1448
|
const config2 = await buildPreviewConfig(previewDir);
|
|
1432
1449
|
res.setHeader("Content-Type", "application/json");
|
|
@@ -1480,7 +1497,7 @@ async function createViteConfig(options) {
|
|
|
1480
1497
|
if (!htmlPath.startsWith(previewsDir)) {
|
|
1481
1498
|
return next();
|
|
1482
1499
|
}
|
|
1483
|
-
if (
|
|
1500
|
+
if (existsSync7(htmlPath)) {
|
|
1484
1501
|
try {
|
|
1485
1502
|
let html = readFileSync6(htmlPath, "utf-8");
|
|
1486
1503
|
const previewBase = `/_preview/${previewName}/`;
|
|
@@ -1609,7 +1626,7 @@ async function findAvailablePort(minPort, maxPort) {
|
|
|
1609
1626
|
|
|
1610
1627
|
// src/vite/start.ts
|
|
1611
1628
|
import { exec } from "child_process";
|
|
1612
|
-
import { existsSync as
|
|
1629
|
+
import { existsSync as existsSync8, rmSync as rmSync3, copyFileSync } from "fs";
|
|
1613
1630
|
import path9 from "path";
|
|
1614
1631
|
function printWelcome(type) {
|
|
1615
1632
|
console.log();
|
|
@@ -1646,11 +1663,11 @@ function clearCache(rootDir) {
|
|
|
1646
1663
|
const viteCacheDir = path9.join(rootDir, ".vite");
|
|
1647
1664
|
const nodeModulesVite = path9.join(rootDir, "node_modules", ".vite");
|
|
1648
1665
|
let cleared = 0;
|
|
1649
|
-
if (
|
|
1666
|
+
if (existsSync8(viteCacheDir)) {
|
|
1650
1667
|
rmSync3(viteCacheDir, { recursive: true });
|
|
1651
1668
|
cleared++;
|
|
1652
1669
|
}
|
|
1653
|
-
if (
|
|
1670
|
+
if (existsSync8(nodeModulesVite)) {
|
|
1654
1671
|
rmSync3(nodeModulesVite, { recursive: true });
|
|
1655
1672
|
cleared++;
|
|
1656
1673
|
}
|
|
@@ -1772,7 +1789,7 @@ async function buildSite(rootDir, options = {}) {
|
|
|
1772
1789
|
const distDir = path9.join(rootDir, "dist");
|
|
1773
1790
|
const indexPath = path9.join(distDir, "index.html");
|
|
1774
1791
|
const notFoundPath = path9.join(distDir, "404.html");
|
|
1775
|
-
if (
|
|
1792
|
+
if (existsSync8(indexPath)) {
|
|
1776
1793
|
copyFileSync(indexPath, notFoundPath);
|
|
1777
1794
|
}
|
|
1778
1795
|
console.log();
|
|
@@ -1854,10 +1871,10 @@ async function cleanCache(options) {
|
|
|
1854
1871
|
import yaml3 from "js-yaml";
|
|
1855
1872
|
function getVersion() {
|
|
1856
1873
|
try {
|
|
1857
|
-
let dir = path11.dirname(
|
|
1874
|
+
let dir = path11.dirname(fileURLToPath4(import.meta.url));
|
|
1858
1875
|
for (let i = 0;i < 5; i++) {
|
|
1859
1876
|
const pkgPath = path11.join(dir, "package.json");
|
|
1860
|
-
if (
|
|
1877
|
+
if (existsSync9(pkgPath)) {
|
|
1861
1878
|
const pkg = JSON.parse(readFileSync7(pkgPath, "utf-8"));
|
|
1862
1879
|
if (pkg.name === "prev-cli")
|
|
1863
1880
|
return pkg.version;
|
|
@@ -1985,7 +2002,7 @@ async function clearViteCache(rootDir2) {
|
|
|
1985
2002
|
let cleared = 0;
|
|
1986
2003
|
try {
|
|
1987
2004
|
const prevCacheDir = await getCacheDir(rootDir2);
|
|
1988
|
-
if (
|
|
2005
|
+
if (existsSync9(prevCacheDir)) {
|
|
1989
2006
|
rmSync4(prevCacheDir, { recursive: true });
|
|
1990
2007
|
cleared++;
|
|
1991
2008
|
console.log(` ✓ Removed ${prevCacheDir}`);
|
|
@@ -1993,12 +2010,12 @@ async function clearViteCache(rootDir2) {
|
|
|
1993
2010
|
} catch {}
|
|
1994
2011
|
const viteCacheDir = path11.join(rootDir2, ".vite");
|
|
1995
2012
|
const nodeModulesVite = path11.join(rootDir2, "node_modules", ".vite");
|
|
1996
|
-
if (
|
|
2013
|
+
if (existsSync9(viteCacheDir)) {
|
|
1997
2014
|
rmSync4(viteCacheDir, { recursive: true });
|
|
1998
2015
|
cleared++;
|
|
1999
2016
|
console.log(` ✓ Removed .vite/`);
|
|
2000
2017
|
}
|
|
2001
|
-
if (
|
|
2018
|
+
if (existsSync9(nodeModulesVite)) {
|
|
2002
2019
|
rmSync4(nodeModulesVite, { recursive: true });
|
|
2003
2020
|
cleared++;
|
|
2004
2021
|
console.log(` ✓ Removed node_modules/.vite/`);
|
|
@@ -2104,7 +2121,7 @@ Available subcommands: show, init, path`);
|
|
|
2104
2121
|
}
|
|
2105
2122
|
function createPreview(rootDir2, name) {
|
|
2106
2123
|
const previewDir = path11.join(rootDir2, "previews", name);
|
|
2107
|
-
if (
|
|
2124
|
+
if (existsSync9(previewDir)) {
|
|
2108
2125
|
console.error(`Preview "${name}" already exists at: ${previewDir}`);
|
|
2109
2126
|
process.exit(1);
|
|
2110
2127
|
}
|
package/package.json
CHANGED
|
@@ -110,7 +110,12 @@ export async function buildOptimizedPreview(
|
|
|
110
110
|
if (tailwindResult.success) css = tailwindResult.css
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
|
|
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,12 +1,23 @@
|
|
|
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
|
-
import { fileURLToPath } from 'url'
|
|
6
5
|
|
|
7
|
-
// Resolve tailwindcss CLI
|
|
8
|
-
|
|
9
|
-
|
|
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()
|
|
10
21
|
|
|
11
22
|
export interface TailwindResult {
|
|
12
23
|
success: boolean
|
|
@@ -51,8 +62,12 @@ export async function compileTailwind(files: ContentFile[]): Promise<TailwindRes
|
|
|
51
62
|
|
|
52
63
|
const outputPath = join(tempDir, 'output.css')
|
|
53
64
|
|
|
54
|
-
// Run Tailwind CLI
|
|
55
|
-
|
|
65
|
+
// Run Tailwind CLI
|
|
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
|
+
}
|
|
56
71
|
|
|
57
72
|
const css = readFileSync(outputPath, 'utf-8')
|
|
58
73
|
|