tailwind-hyperclay 0.1.4 → 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 +23 -14
  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";
@@ -51,11 +48,13 @@ export async function compileTailwind(html) {
51
48
  return { content, base: path.dirname(resolved) };
52
49
  },
53
50
  loadModule: async (id, base) => {
51
+ const { pathToFileURL } = await import('url');
54
52
  const resolved = require.resolve(id, { paths: [base || process.cwd()] });
55
53
  const mod = await import(pathToFileURL(resolved).href);
56
54
  return { module: mod.default, base: path.dirname(resolved) };
57
55
  },
58
56
  loadPlugin: async (plugin) => {
57
+ const { pathToFileURL } = await import('url');
59
58
  const resolved = require.resolve(plugin);
60
59
  const mod = await import(pathToFileURL(resolved).href);
61
60
  return mod.default;
@@ -68,7 +67,7 @@ export async function compileTailwind(html) {
68
67
  return css;
69
68
  }
70
69
 
71
- export function extractCandidates(html) {
70
+ function extractCandidates(html) {
72
71
  const candidates = new Set();
73
72
 
74
73
  // Extract class attribute values
@@ -102,7 +101,7 @@ function extractHrefs(html) {
102
101
  return hrefs;
103
102
  }
104
103
 
105
- export function getTailwindCssName(html) {
104
+ function getTailwindCssName(html) {
106
105
  for (const href of extractHrefs(html)) {
107
106
  const name = getTailwindName(href);
108
107
  if (name) return name;
@@ -110,15 +109,15 @@ export function getTailwindCssName(html) {
110
109
  return null;
111
110
  }
112
111
 
113
- export function hasTailwindLink(html, appName) {
112
+ function hasTailwindLink(html, appName) {
114
113
  return extractHrefs(html).some(url => getTailwindName(url) === appName);
115
114
  }
116
115
 
117
- export function hasAnyTailwindLink(html) {
116
+ function hasAnyTailwindLink(html) {
118
117
  return extractHrefs(html).some(url => getTailwindName(url) !== null);
119
118
  }
120
119
 
121
- export function replaceTailwindLink(html, newName) {
120
+ function replaceTailwindLink(html, newName) {
122
121
  return html.replace(
123
122
  /(href\s*=\s*["'])([^"']+)(["'])/gi,
124
123
  (match, prefix, url, suffix) => {
@@ -129,3 +128,13 @@ export function replaceTailwindLink(html, newName) {
129
128
  }
130
129
  );
131
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.4",
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>