tailwind-hyperclay 0.1.3 → 0.1.6

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 (3) hide show
  1. package/index.js +31 -18
  2. package/package.json +1 -5
  3. package/test/test.js +1 -1
package/index.js CHANGED
@@ -1,12 +1,7 @@
1
- import { compile } from 'tailwindcss';
2
- import { readFile, writeFile } from 'fs/promises';
3
- import { createRequire } from 'module';
4
- import { pathToFileURL } from 'url';
5
- import path from 'path';
1
+ const { readFile, writeFile } = require('fs/promises');
2
+ const path = require('path');
6
3
 
7
- const require = createRequire(import.meta.url);
8
-
9
- export async function generateCSS({ input, output }) {
4
+ async function generateCSS({ input, output }) {
10
5
  const html = await readFile(input, 'utf-8');
11
6
 
12
7
  const css = await compileTailwind(html);
@@ -18,7 +13,9 @@ export async function generateCSS({ input, output }) {
18
13
  return css;
19
14
  }
20
15
 
21
- export async function compileTailwind(html) {
16
+ async function compileTailwind(html) {
17
+ const { compile } = await import('tailwindcss');
18
+
22
19
  const inputCSS = `
23
20
  @import "tailwindcss";
24
21
  @plugin "@tailwindcss/typography";
@@ -34,24 +31,30 @@ export async function compileTailwind(html) {
34
31
  try {
35
32
  resolved = require.resolve(id, { paths: searchPaths });
36
33
  } catch {
37
- // If that fails, try with /index.css suffix (for package imports like "tailwindcss")
38
- resolved = require.resolve(`${id}/index.css`, { paths: searchPaths });
34
+ // If that fails, try resolving the package main entry and construct path to index.css
35
+ // This avoids subpath exports which can fail in Electron asar bundles
36
+ const mainEntry = require.resolve(id, { paths: searchPaths });
37
+ const pkgRoot = path.resolve(path.dirname(mainEntry), '..');
38
+ resolved = path.join(pkgRoot, 'index.css');
39
39
  }
40
40
 
41
- // If resolved to a JS file, try the CSS variant
41
+ // If resolved to a JS file, find package root and use index.css
42
42
  if (resolved.endsWith('.js') || resolved.endsWith('.mjs')) {
43
- resolved = require.resolve(`${id}/index.css`, { paths: searchPaths });
43
+ const pkgRoot = path.resolve(path.dirname(resolved), '..');
44
+ resolved = path.join(pkgRoot, 'index.css');
44
45
  }
45
46
 
46
47
  const content = await readFile(resolved, 'utf-8');
47
48
  return { content, base: path.dirname(resolved) };
48
49
  },
49
50
  loadModule: async (id, base) => {
51
+ const { pathToFileURL } = await import('url');
50
52
  const resolved = require.resolve(id, { paths: [base || process.cwd()] });
51
53
  const mod = await import(pathToFileURL(resolved).href);
52
54
  return { module: mod.default, base: path.dirname(resolved) };
53
55
  },
54
56
  loadPlugin: async (plugin) => {
57
+ const { pathToFileURL } = await import('url');
55
58
  const resolved = require.resolve(plugin);
56
59
  const mod = await import(pathToFileURL(resolved).href);
57
60
  return mod.default;
@@ -64,7 +67,7 @@ export async function compileTailwind(html) {
64
67
  return css;
65
68
  }
66
69
 
67
- export function extractCandidates(html) {
70
+ function extractCandidates(html) {
68
71
  const candidates = new Set();
69
72
 
70
73
  // Extract class attribute values
@@ -98,7 +101,7 @@ function extractHrefs(html) {
98
101
  return hrefs;
99
102
  }
100
103
 
101
- export function getTailwindCssName(html) {
104
+ function getTailwindCssName(html) {
102
105
  for (const href of extractHrefs(html)) {
103
106
  const name = getTailwindName(href);
104
107
  if (name) return name;
@@ -106,15 +109,15 @@ export function getTailwindCssName(html) {
106
109
  return null;
107
110
  }
108
111
 
109
- export function hasTailwindLink(html, appName) {
112
+ function hasTailwindLink(html, appName) {
110
113
  return extractHrefs(html).some(url => getTailwindName(url) === appName);
111
114
  }
112
115
 
113
- export function hasAnyTailwindLink(html) {
116
+ function hasAnyTailwindLink(html) {
114
117
  return extractHrefs(html).some(url => getTailwindName(url) !== null);
115
118
  }
116
119
 
117
- export function replaceTailwindLink(html, newName) {
120
+ function replaceTailwindLink(html, newName) {
118
121
  return html.replace(
119
122
  /(href\s*=\s*["'])([^"']+)(["'])/gi,
120
123
  (match, prefix, url, suffix) => {
@@ -125,3 +128,13 @@ export function replaceTailwindLink(html, newName) {
125
128
  }
126
129
  );
127
130
  }
131
+
132
+ module.exports = {
133
+ generateCSS,
134
+ compileTailwind,
135
+ extractCandidates,
136
+ getTailwindCssName,
137
+ hasTailwindLink,
138
+ hasAnyTailwindLink,
139
+ replaceTailwindLink
140
+ };
package/package.json CHANGED
@@ -1,12 +1,8 @@
1
1
  {
2
2
  "name": "tailwind-hyperclay",
3
- "version": "0.1.3",
3
+ "version": "0.1.6",
4
4
  "description": "On-save Tailwind CSS generator for Hyperclay",
5
- "type": "module",
6
5
  "main": "index.js",
7
- "exports": {
8
- ".": "./index.js"
9
- },
10
6
  "scripts": {
11
7
  "test": "node test/test.js",
12
8
  "release": "./scripts/release.sh"
package/test/test.js CHANGED
@@ -1,4 +1,4 @@
1
- import { compileTailwind, hasTailwindLink, hasAnyTailwindLink, replaceTailwindLink } from '../index.js';
1
+ const { compileTailwind, hasTailwindLink, hasAnyTailwindLink, replaceTailwindLink } = require('../index.js');
2
2
 
3
3
  const testHTML = `
4
4
  <!DOCTYPE html>