tailwind-hyperclay 0.1.1 → 0.1.2
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/index.js +31 -5
- package/package.json +1 -1
- package/test/test.js +49 -10
package/index.js
CHANGED
|
@@ -80,18 +80,44 @@ export function extractCandidates(html) {
|
|
|
80
80
|
return Array.from(candidates);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
function parseTailwindUrl(urlString) {
|
|
84
|
+
try {
|
|
85
|
+
const url = new URL(urlString);
|
|
86
|
+
if (url.host === 'hyperclay.com' &&
|
|
87
|
+
url.pathname.startsWith('/tailwindcss/') &&
|
|
88
|
+
url.pathname.endsWith('.css')) {
|
|
89
|
+
return url.pathname.slice(13, -4); // extract app name between /tailwindcss/ and .css
|
|
90
|
+
}
|
|
91
|
+
} catch {}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function extractHrefs(html) {
|
|
96
|
+
const hrefs = [];
|
|
97
|
+
const regex = /href\s*=\s*["']([^"']+)["']/gi;
|
|
98
|
+
let match;
|
|
99
|
+
while ((match = regex.exec(html)) !== null) {
|
|
100
|
+
hrefs.push(match[1]);
|
|
101
|
+
}
|
|
102
|
+
return hrefs;
|
|
103
|
+
}
|
|
104
|
+
|
|
83
105
|
export function hasTailwindLink(html, appName) {
|
|
84
|
-
|
|
85
|
-
return pattern.test(html);
|
|
106
|
+
return extractHrefs(html).some(url => parseTailwindUrl(url) === appName);
|
|
86
107
|
}
|
|
87
108
|
|
|
88
109
|
export function hasAnyTailwindLink(html) {
|
|
89
|
-
return
|
|
110
|
+
return extractHrefs(html).some(url => parseTailwindUrl(url) !== null);
|
|
90
111
|
}
|
|
91
112
|
|
|
92
113
|
export function replaceTailwindLink(html, newName) {
|
|
93
114
|
return html.replace(
|
|
94
|
-
/
|
|
95
|
-
|
|
115
|
+
/(href\s*=\s*["'])([^"']+)(["'])/gi,
|
|
116
|
+
(match, prefix, url, suffix) => {
|
|
117
|
+
if (parseTailwindUrl(url) !== null) {
|
|
118
|
+
return `${prefix}https://hyperclay.com/tailwindcss/${newName}.css${suffix}`;
|
|
119
|
+
}
|
|
120
|
+
return match;
|
|
121
|
+
}
|
|
96
122
|
);
|
|
97
123
|
}
|
package/package.json
CHANGED
package/test/test.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { compileTailwind, hasTailwindLink } from '../index.js';
|
|
1
|
+
import { compileTailwind, hasTailwindLink, hasAnyTailwindLink, replaceTailwindLink } from '../index.js';
|
|
2
2
|
|
|
3
3
|
const testHTML = `
|
|
4
4
|
<!DOCTYPE html>
|
|
@@ -15,20 +15,59 @@ const testHTML = `
|
|
|
15
15
|
</html>
|
|
16
16
|
`;
|
|
17
17
|
|
|
18
|
+
const testHTMLWithQueryParams = `
|
|
19
|
+
<!DOCTYPE html>
|
|
20
|
+
<html>
|
|
21
|
+
<head>
|
|
22
|
+
<link href="https://hyperclay.com/tailwindcss/myApp.css?v=123&t=456" rel="stylesheet">
|
|
23
|
+
</head>
|
|
24
|
+
<body></body>
|
|
25
|
+
</html>
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
const testHTMLWithFragment = `
|
|
29
|
+
<!DOCTYPE html>
|
|
30
|
+
<html>
|
|
31
|
+
<head>
|
|
32
|
+
<link href="https://hyperclay.com/tailwindcss/myApp.css#section" rel="stylesheet">
|
|
33
|
+
</head>
|
|
34
|
+
<body></body>
|
|
35
|
+
</html>
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
function test(name, actual, expected) {
|
|
39
|
+
const pass = actual === expected;
|
|
40
|
+
console.log(` ${pass ? '✓' : '✗'} ${name}: ${actual} (expected ${expected})`);
|
|
41
|
+
if (!pass) process.exitCode = 1;
|
|
42
|
+
}
|
|
43
|
+
|
|
18
44
|
async function runTests() {
|
|
19
45
|
console.log('Testing hasTailwindLink...');
|
|
20
|
-
|
|
21
|
-
|
|
46
|
+
test('myApp found', hasTailwindLink(testHTML, 'myApp'), true);
|
|
47
|
+
test('other not found', hasTailwindLink(testHTML, 'other'), false);
|
|
48
|
+
test('myApp with query params', hasTailwindLink(testHTMLWithQueryParams, 'myApp'), true);
|
|
49
|
+
test('myApp with fragment', hasTailwindLink(testHTMLWithFragment, 'myApp'), true);
|
|
50
|
+
|
|
51
|
+
console.log('\nTesting hasAnyTailwindLink...');
|
|
52
|
+
test('finds link', hasAnyTailwindLink(testHTML), true);
|
|
53
|
+
test('finds link with query params', hasAnyTailwindLink(testHTMLWithQueryParams), true);
|
|
54
|
+
test('no link', hasAnyTailwindLink('<html><body></body></html>'), false);
|
|
55
|
+
|
|
56
|
+
console.log('\nTesting replaceTailwindLink...');
|
|
57
|
+
const replaced = replaceTailwindLink(testHTML, 'newApp');
|
|
58
|
+
test('replaces app name', replaced.includes('https://hyperclay.com/tailwindcss/newApp.css'), true);
|
|
59
|
+
test('removes old app name', !replaced.includes('myApp'), true);
|
|
60
|
+
|
|
61
|
+
const replacedWithParams = replaceTailwindLink(testHTMLWithQueryParams, 'newApp');
|
|
62
|
+
test('replaces and strips query params', replacedWithParams.includes('https://hyperclay.com/tailwindcss/newApp.css"'), true);
|
|
63
|
+
test('query params removed', !replacedWithParams.includes('?v=123'), true);
|
|
22
64
|
|
|
23
65
|
console.log('\nTesting compileTailwind...');
|
|
24
66
|
const css = await compileTailwind(testHTML);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
console.log('\nSample output (first 500 chars):');
|
|
31
|
-
console.log(css.slice(0, 500));
|
|
67
|
+
test('generates CSS', css.length > 0, true);
|
|
68
|
+
test('contains .prose', css.includes('.prose'), true);
|
|
69
|
+
test('contains .form-input', css.includes('.form-input'), true);
|
|
70
|
+
test('contains .text-2xl', css.includes('.text-2xl'), true);
|
|
32
71
|
}
|
|
33
72
|
|
|
34
73
|
runTests().catch(console.error);
|