tailwind-hyperclay 0.1.6 → 0.1.10
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 +37 -10
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
const { readFile, writeFile } = require('fs/promises');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
|
+
let compile;
|
|
5
|
+
try {
|
|
6
|
+
const tw = require('tailwindcss');
|
|
7
|
+
compile = tw.compile;
|
|
8
|
+
} catch (e) {
|
|
9
|
+
// Fallback for Electron asarUnpack issue
|
|
10
|
+
if (process.versions.electron) {
|
|
11
|
+
try {
|
|
12
|
+
// Try to look for it in app.asar.unpacked
|
|
13
|
+
// process.resourcesPath usually points to Contents/Resources
|
|
14
|
+
// Point directly to the dist file to bypass package.json exports resolution issues in ASAR
|
|
15
|
+
const unpackedPath = path.join(process.resourcesPath, 'app.asar.unpacked', 'node_modules', 'tailwindcss', 'dist', 'lib.js');
|
|
16
|
+
const tw = require(unpackedPath);
|
|
17
|
+
compile = tw.compile;
|
|
18
|
+
} catch (e2) {
|
|
19
|
+
console.error('Failed to load tailwindcss from unpacked path:', e2);
|
|
20
|
+
throw e;
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
throw e;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
4
27
|
async function generateCSS({ input, output }) {
|
|
5
28
|
const html = await readFile(input, 'utf-8');
|
|
6
29
|
|
|
@@ -14,7 +37,6 @@ async function generateCSS({ input, output }) {
|
|
|
14
37
|
}
|
|
15
38
|
|
|
16
39
|
async function compileTailwind(html) {
|
|
17
|
-
const { compile } = await import('tailwindcss');
|
|
18
40
|
|
|
19
41
|
const inputCSS = `
|
|
20
42
|
@import "tailwindcss";
|
|
@@ -22,10 +44,16 @@ async function compileTailwind(html) {
|
|
|
22
44
|
@plugin "@tailwindcss/forms" { strategy: "class"; }
|
|
23
45
|
`;
|
|
24
46
|
|
|
47
|
+
// Use process.resourcesPath in Electron (production), otherwise __dirname
|
|
48
|
+
// This ensures we don't rely on process.cwd() which is '/' when double-clicking the app
|
|
49
|
+
const defaultBase = process.versions.electron && process.resourcesPath
|
|
50
|
+
? path.join(process.resourcesPath, 'app.asar.unpacked', 'node_modules')
|
|
51
|
+
: __dirname;
|
|
52
|
+
|
|
25
53
|
const compiler = await compile(inputCSS, {
|
|
26
54
|
loadStylesheet: async (id, base) => {
|
|
27
55
|
let resolved;
|
|
28
|
-
const searchPaths = [base ||
|
|
56
|
+
const searchPaths = [base || defaultBase];
|
|
29
57
|
|
|
30
58
|
// Try resolving as-is first (for .css files)
|
|
31
59
|
try {
|
|
@@ -48,16 +76,15 @@ async function compileTailwind(html) {
|
|
|
48
76
|
return { content, base: path.dirname(resolved) };
|
|
49
77
|
},
|
|
50
78
|
loadModule: async (id, base) => {
|
|
51
|
-
const {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
return { module: mod.default, base: path.dirname(resolved) };
|
|
79
|
+
const resolved = require.resolve(id, { paths: [base || defaultBase] });
|
|
80
|
+
const mod = require(resolved);
|
|
81
|
+
return { module: mod.default || mod, base: path.dirname(resolved) };
|
|
55
82
|
},
|
|
56
83
|
loadPlugin: async (plugin) => {
|
|
57
|
-
|
|
58
|
-
const resolved = require.resolve(plugin);
|
|
59
|
-
const mod =
|
|
60
|
-
return mod.default;
|
|
84
|
+
// Plugins need to be found in the app's node_modules
|
|
85
|
+
const resolved = require.resolve(plugin, { paths: [defaultBase] });
|
|
86
|
+
const mod = require(resolved);
|
|
87
|
+
return mod.default || mod;
|
|
61
88
|
}
|
|
62
89
|
});
|
|
63
90
|
|