tailwind-hyperclay 0.1.14 → 0.1.16
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/CHANGELOG.md +7 -0
- package/index.js +12 -9
- package/package.json +1 -1
- package/test/test.js +6 -6
package/CHANGELOG.md
CHANGED
package/index.js
CHANGED
|
@@ -129,12 +129,18 @@ function extractCandidates(html) {
|
|
|
129
129
|
|
|
130
130
|
function getTailwindName(urlString) {
|
|
131
131
|
// Match relative path: /tailwindcss/name.css
|
|
132
|
-
// Or full URL: https://
|
|
132
|
+
// Or full URL with any domain: https://example.com/tailwindcss/name.css
|
|
133
133
|
// With optional query params (?v=123) or fragments (#section)
|
|
134
|
-
const match = urlString.match(/^(?:https
|
|
134
|
+
const match = urlString.match(/^(?:https?:\/\/[^/]+)?\/tailwindcss\/([^?#]+)\.css(?:[?#].*)?$/);
|
|
135
135
|
return match ? match[1] : null;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
function getTailwindPrefix(urlString) {
|
|
139
|
+
// Extract the domain prefix (e.g. "https://hyperclay.com") or empty string for relative URLs
|
|
140
|
+
const match = urlString.match(/^(https?:\/\/[^/]+)?\/tailwindcss\//);
|
|
141
|
+
return match?.[1] || '';
|
|
142
|
+
}
|
|
143
|
+
|
|
138
144
|
function extractHrefs(html) {
|
|
139
145
|
const hrefs = [];
|
|
140
146
|
const regex = /href\s*=\s*["']([^"']+)["']/gi;
|
|
@@ -153,20 +159,18 @@ function getTailwindCssName(html) {
|
|
|
153
159
|
return null;
|
|
154
160
|
}
|
|
155
161
|
|
|
156
|
-
function hasTailwindLink(html, appName) {
|
|
157
|
-
return extractHrefs(html).some(url => getTailwindName(url) === appName);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
162
|
function hasAnyTailwindLink(html) {
|
|
161
163
|
return extractHrefs(html).some(url => getTailwindName(url) !== null);
|
|
162
164
|
}
|
|
163
165
|
|
|
164
|
-
function replaceTailwindLink(html, newName) {
|
|
166
|
+
function replaceTailwindLink(html, newName, sitePath) {
|
|
167
|
+
const scopedName = sitePath ? `${sitePath}/${newName}` : newName;
|
|
165
168
|
return html.replace(
|
|
166
169
|
/(href\s*=\s*["'])([^"']+)(["'])/gi,
|
|
167
170
|
(match, prefix, url, suffix) => {
|
|
168
171
|
if (getTailwindName(url) !== null) {
|
|
169
|
-
|
|
172
|
+
const domainPrefix = getTailwindPrefix(url);
|
|
173
|
+
return `${prefix}${domainPrefix}/tailwindcss/${scopedName}.css${suffix}`;
|
|
170
174
|
}
|
|
171
175
|
return match;
|
|
172
176
|
}
|
|
@@ -178,7 +182,6 @@ module.exports = {
|
|
|
178
182
|
compileTailwind,
|
|
179
183
|
extractCandidates,
|
|
180
184
|
getTailwindCssName,
|
|
181
|
-
hasTailwindLink,
|
|
182
185
|
hasAnyTailwindLink,
|
|
183
186
|
replaceTailwindLink
|
|
184
187
|
};
|
package/package.json
CHANGED
package/test/test.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { compileTailwind,
|
|
1
|
+
const { compileTailwind, hasAnyTailwindLink, replaceTailwindLink, getTailwindCssName } = require('../index.js');
|
|
2
2
|
|
|
3
3
|
const testHTML = `
|
|
4
4
|
<!DOCTYPE html>
|
|
@@ -42,11 +42,11 @@ function test(name, actual, expected) {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
async function runTests() {
|
|
45
|
-
console.log('Testing
|
|
46
|
-
test('myApp found',
|
|
47
|
-
test('
|
|
48
|
-
test('myApp with
|
|
49
|
-
test('
|
|
45
|
+
console.log('Testing getTailwindCssName...');
|
|
46
|
+
test('myApp found', getTailwindCssName(testHTML), 'myApp');
|
|
47
|
+
test('myApp with query params', getTailwindCssName(testHTMLWithQueryParams), 'myApp');
|
|
48
|
+
test('myApp with fragment', getTailwindCssName(testHTMLWithFragment), 'myApp');
|
|
49
|
+
test('no link returns null', getTailwindCssName('<html></html>'), null);
|
|
50
50
|
|
|
51
51
|
console.log('\nTesting hasAnyTailwindLink...');
|
|
52
52
|
test('finds link', hasAnyTailwindLink(testHTML), true);
|