@devflow-tools/plugin-tailwind 0.9.0 → 0.11.0
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optimize-classes.d.ts","sourceRoot":"","sources":["../../src/analyzers/optimize-classes.ts"],"names":[],"mappings":"AAAA,wBAAsB,eAAe,CAAC,MAAM,EAAE;IAC5C,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"optimize-classes.d.ts","sourceRoot":"","sources":["../../src/analyzers/optimize-classes.ts"],"names":[],"mappings":"AAAA,wBAAsB,eAAe,CAAC,MAAM,EAAE;IAC5C,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC,CA4F9D"}
|
|
@@ -1,18 +1,81 @@
|
|
|
1
1
|
export async function optimizeClasses(params) {
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
const { existsSync, readFileSync } = await import('fs');
|
|
3
|
+
const { extname, join } = await import('path');
|
|
4
|
+
const targetFile = params.filePath.startsWith('/') ? params.filePath : join(process.cwd(), params.filePath);
|
|
5
|
+
if (!existsSync(targetFile)) {
|
|
6
|
+
return {
|
|
7
|
+
content: [{
|
|
8
|
+
type: "text",
|
|
9
|
+
text: JSON.stringify({ file: params.filePath, error: "File not found", suggestions: [], classCount: 0 }, null, 2),
|
|
10
|
+
}],
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const content = readFileSync(targetFile, 'utf-8');
|
|
14
|
+
const classNames = [];
|
|
15
|
+
// Extract from className="..." (static)
|
|
16
|
+
const stringMatches = content.match(/className="([^"]*)"/g) || [];
|
|
17
|
+
for (const m of stringMatches) {
|
|
18
|
+
const inner = m.match(/"([^"]*)"/)?.[1];
|
|
19
|
+
if (inner) {
|
|
20
|
+
const classes = inner.split(/\s+/).filter(Boolean);
|
|
21
|
+
classNames.push(...classes);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// Extract from className={'...'} or className={`...`} (dynamic)
|
|
25
|
+
const exprMatches = content.match(/className=\{['`]([^'`]+)['`]\}/g) || [];
|
|
26
|
+
for (const m of exprMatches) {
|
|
27
|
+
const inner = m.match(/\{['`](.+?)['`]\}/)?.[1];
|
|
28
|
+
if (inner) {
|
|
29
|
+
const classes = inner.split(/\s+/).filter(Boolean);
|
|
30
|
+
classNames.push(...classes);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const suggestions = [];
|
|
34
|
+
const classCount = classNames.length;
|
|
35
|
+
if (classCount === 0) {
|
|
36
|
+
suggestions.push("No Tailwind classes detected in className attributes");
|
|
37
|
+
return {
|
|
38
|
+
content: [{
|
|
39
|
+
type: "text",
|
|
40
|
+
text: JSON.stringify({ file: params.filePath, suggestions, classCount: 0, status: "no classes found" }, null, 2),
|
|
41
|
+
}],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// Detect repeated class combinations
|
|
45
|
+
const comboStr = classNames.join('|');
|
|
46
|
+
const combos = new Map();
|
|
47
|
+
for (let i = 0; i < classNames.length - 2; i++) {
|
|
48
|
+
const combo = classNames.slice(i, i + 3).join(' ');
|
|
49
|
+
if (combo.length > 5) {
|
|
50
|
+
combos.set(combo, (combos.get(combo) ?? 0) + 1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const repeated = [...combos.entries()].filter(([, count]) => count >= 2);
|
|
54
|
+
if (repeated.length > 0) {
|
|
55
|
+
suggestions.push(`Found ${repeated.length} repeated class combos — use @apply in CSS for reuse`);
|
|
56
|
+
}
|
|
57
|
+
// Detect long class strings (>10 classes)
|
|
58
|
+
const longLines = classNames.filter(c => c.split(/\s+/).length > 10);
|
|
59
|
+
if (classNames.length > 0 && classNames.filter(c => c.includes(':')).length > classNames.length * 0.5) {
|
|
60
|
+
suggestions.push("High ratio of responsive/variant classes — consider extracting to component variants");
|
|
61
|
+
}
|
|
62
|
+
// Detect arbitrary values
|
|
63
|
+
const arbitraryCount = classNames.filter(c => /\[.*\]/.test(c)).length;
|
|
64
|
+
if (arbitraryCount > 0) {
|
|
65
|
+
suggestions.push(`${arbitraryCount} arbitrary value(s) detected — prefer config tokens when possible`);
|
|
66
|
+
}
|
|
67
|
+
if (suggestions.length === 0) {
|
|
68
|
+
suggestions.push("Classes look clean — no issues detected");
|
|
69
|
+
}
|
|
8
70
|
return {
|
|
9
71
|
content: [{
|
|
10
72
|
type: "text",
|
|
11
73
|
text: JSON.stringify({
|
|
12
74
|
file: params.filePath,
|
|
13
75
|
suggestions,
|
|
14
|
-
classCount
|
|
15
|
-
|
|
76
|
+
classCount,
|
|
77
|
+
classList: classNames.slice(0, 50),
|
|
78
|
+
status: suggestions.length === 1 && suggestions[0]?.includes('clean') ? 'clean' : 'needs review',
|
|
16
79
|
}, null, 2),
|
|
17
80
|
}],
|
|
18
81
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optimize-classes.js","sourceRoot":"","sources":["../../src/analyzers/optimize-classes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAErC;IACC,MAAM,WAAW,GAAG;
|
|
1
|
+
{"version":3,"file":"optimize-classes.js","sourceRoot":"","sources":["../../src/analyzers/optimize-classes.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAErC;IACC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM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AAC;QAC7B,WAAW,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO;QACL,OAAO,EAAE,CAAC;gBACR,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACnB,IAAI,EAAE,MAAM,CAAC,QAAQ;oBACrB,WAAW;oBACX,UAAU;oBACV,SAAS,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;oBAClC,MAAM,EAAE,WAAW,CAAC,MAAM,KAAK,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc;iBACjG,EAAE,IAAI,EAAE,CAAC,CAAC;aACZ,CAAC;KACH,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devflow-tools/plugin-tailwind",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"files": [
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "ff6ac69b0f3cc95cb32ffe8bcbf21b24767aa914"
|
|
30
30
|
}
|