tailwind-hyperclay 0.1.2 → 0.1.4

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.
Files changed (2) hide show
  1. package/index.js +25 -17
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -34,13 +34,17 @@ export async function compileTailwind(html) {
34
34
  try {
35
35
  resolved = require.resolve(id, { paths: searchPaths });
36
36
  } catch {
37
- // If that fails, try with /index.css suffix (for package imports like "tailwindcss")
38
- resolved = require.resolve(`${id}/index.css`, { paths: searchPaths });
37
+ // If that fails, try resolving the package main entry and construct path to index.css
38
+ // This avoids subpath exports which can fail in Electron asar bundles
39
+ const mainEntry = require.resolve(id, { paths: searchPaths });
40
+ const pkgRoot = path.resolve(path.dirname(mainEntry), '..');
41
+ resolved = path.join(pkgRoot, 'index.css');
39
42
  }
40
43
 
41
- // If resolved to a JS file, try the CSS variant
44
+ // If resolved to a JS file, find package root and use index.css
42
45
  if (resolved.endsWith('.js') || resolved.endsWith('.mjs')) {
43
- resolved = require.resolve(`${id}/index.css`, { paths: searchPaths });
46
+ const pkgRoot = path.resolve(path.dirname(resolved), '..');
47
+ resolved = path.join(pkgRoot, 'index.css');
44
48
  }
45
49
 
46
50
  const content = await readFile(resolved, 'utf-8');
@@ -80,16 +84,12 @@ export function extractCandidates(html) {
80
84
  return Array.from(candidates);
81
85
  }
82
86
 
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;
87
+ function getTailwindName(urlString) {
88
+ // Match relative path: /tailwindcss/name.css
89
+ // Or full URL: https://hyperclay.com/tailwindcss/name.css
90
+ // With optional query params (?v=123) or fragments (#section)
91
+ const match = urlString.match(/^(?:https:\/\/hyperclay\.com)?\/tailwindcss\/([^?#]+)\.css(?:[?#].*)?$/);
92
+ return match ? match[1] : null;
93
93
  }
94
94
 
95
95
  function extractHrefs(html) {
@@ -102,19 +102,27 @@ function extractHrefs(html) {
102
102
  return hrefs;
103
103
  }
104
104
 
105
+ export function getTailwindCssName(html) {
106
+ for (const href of extractHrefs(html)) {
107
+ const name = getTailwindName(href);
108
+ if (name) return name;
109
+ }
110
+ return null;
111
+ }
112
+
105
113
  export function hasTailwindLink(html, appName) {
106
- return extractHrefs(html).some(url => parseTailwindUrl(url) === appName);
114
+ return extractHrefs(html).some(url => getTailwindName(url) === appName);
107
115
  }
108
116
 
109
117
  export function hasAnyTailwindLink(html) {
110
- return extractHrefs(html).some(url => parseTailwindUrl(url) !== null);
118
+ return extractHrefs(html).some(url => getTailwindName(url) !== null);
111
119
  }
112
120
 
113
121
  export function replaceTailwindLink(html, newName) {
114
122
  return html.replace(
115
123
  /(href\s*=\s*["'])([^"']+)(["'])/gi,
116
124
  (match, prefix, url, suffix) => {
117
- if (parseTailwindUrl(url) !== null) {
125
+ if (getTailwindName(url) !== null) {
118
126
  return `${prefix}https://hyperclay.com/tailwindcss/${newName}.css${suffix}`;
119
127
  }
120
128
  return match;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwind-hyperclay",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "On-save Tailwind CSS generator for Hyperclay",
5
5
  "type": "module",
6
6
  "main": "index.js",