oxlint-tailwindcss 0.3.0 → 0.4.1
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/README.md +16 -3
- package/dist/index.cjs +137 -48
- package/dist/index.mjs +137 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -7,7 +7,8 @@ Read the story behind this plugin: [oxlint-tailwindcss: The Linting Plugin Tailw
|
|
|
7
7
|
## Highlights
|
|
8
8
|
|
|
9
9
|
- **Works out of the box** — Auto-detects your Tailwind CSS entry point. Fully configurable when needed.
|
|
10
|
-
- **
|
|
10
|
+
- **Monorepo-ready** — Each package resolves its own design system automatically. Run `oxlint` once from the workspace root.
|
|
11
|
+
- **Fast** — Native oxlint plugin with per-entry-point caching and content-based disk cache for monorepo deduplication.
|
|
11
12
|
- **Tailwind CSS v4** — Designed for v4 from day one.
|
|
12
13
|
- **Typo suggestions** — `itms-center` → "Did you mean `items-center`?"
|
|
13
14
|
- **Conflict detection** — Shows exactly which CSS properties conflict and which class wins.
|
|
@@ -75,7 +76,7 @@ assets/{name}.css assets/css/{name}.css resources/css/{name}.css
|
|
|
75
76
|
|
|
76
77
|
Where `{name}` is one of: `app`, `globals`, `global`, `style`, `styles`, `index`, `main`, `tailwind`, `tailwindcss`.
|
|
77
78
|
|
|
78
|
-
The search is monorepo-aware — it stops at `package.json` boundaries so each package resolves its own Tailwind config. If the signal isn't found directly in the CSS file, the auto-detector follows `@import` statements one level deep — supporting both relative paths and package imports (e.g. `@import '@company/theme/tailwind.config.css'`).
|
|
79
|
+
The search is monorepo-aware — it stops at `package.json` boundaries so each package resolves its own Tailwind config. Packages without a Tailwind CSS file are silently skipped (DS-dependent rules produce no diagnostics). If the signal isn't found directly in the CSS file, the auto-detector follows `@import` statements one level deep — supporting both relative paths and package imports (e.g. `@import '@company/theme/tailwind.config.css'`).
|
|
79
80
|
|
|
80
81
|
If auto-detection doesn't find your CSS file, set `entryPoint` once in `settings`:
|
|
81
82
|
|
|
@@ -94,7 +95,7 @@ If auto-detection doesn't find your CSS file, set `entryPoint` once in `settings
|
|
|
94
95
|
}
|
|
95
96
|
```
|
|
96
97
|
|
|
97
|
-
The design system is loaded once and shared across all rules.
|
|
98
|
+
The design system is loaded once per entry point and shared across all rules. In monorepos, each package resolves its own entry point automatically via `package.json` boundaries.
|
|
98
99
|
|
|
99
100
|
You can also override per rule if needed:
|
|
100
101
|
|
|
@@ -108,6 +109,18 @@ You can also override per rule if needed:
|
|
|
108
109
|
|
|
109
110
|
Resolution order: rule option > `settings.tailwindcss.entryPoint` > auto-detect.
|
|
110
111
|
|
|
112
|
+
For slow environments (large monorepos, CI), you can increase the design system loading timeout:
|
|
113
|
+
|
|
114
|
+
```jsonc
|
|
115
|
+
{
|
|
116
|
+
"settings": {
|
|
117
|
+
"tailwindcss": {
|
|
118
|
+
"timeout": 60000, // milliseconds (default: 30000)
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
111
124
|
If no entry point is found (neither configured nor auto-detected), rules that require the design system (`no-unknown-classes`, `no-conflicting-classes`, `no-deprecated-classes`, `enforce-canonical`, `enforce-sort-order`, `no-unnecessary-arbitrary-value`, `consistent-variant-order`) are silently disabled. All other rules work without it.
|
|
112
125
|
|
|
113
126
|
## Custom class detection
|
package/dist/index.cjs
CHANGED
|
@@ -173,6 +173,10 @@ function extractFromClassedCall(node) {
|
|
|
173
173
|
skippedFirst = true;
|
|
174
174
|
continue;
|
|
175
175
|
}
|
|
176
|
+
if (!skippedFirst && arg.type === "TemplateLiteral") {
|
|
177
|
+
skippedFirst = true;
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
176
180
|
skippedFirst = true;
|
|
177
181
|
if (arg.type === "ObjectExpression") results.push(...extractFromCvaConfig(arg));
|
|
178
182
|
else results.push(...extractFromExpression(arg));
|
|
@@ -872,6 +876,10 @@ async function main() {
|
|
|
872
876
|
const entries = ds.getClassList();
|
|
873
877
|
const classNames = entries.map(e => e[0]);
|
|
874
878
|
|
|
879
|
+
// Index for O(1) lookups by class name (avoids O(N) indexOf/includes in later phases)
|
|
880
|
+
const classNameIndex = new Map();
|
|
881
|
+
for (let i = 0; i < classNames.length; i++) classNameIndex.set(classNames[i], i);
|
|
882
|
+
|
|
875
883
|
// Validity: which classes produce CSS
|
|
876
884
|
const cssResults = ds.candidatesToCss(classNames);
|
|
877
885
|
const validClasses = classNames.filter((_, i) => cssResults[i] != null);
|
|
@@ -933,7 +941,7 @@ async function main() {
|
|
|
933
941
|
// Sort order — include extra candidates so bare utilities (rounded, blur, etc.) get order
|
|
934
942
|
const allForOrder = [...classNames];
|
|
935
943
|
for (const cls of validClasses) {
|
|
936
|
-
if (!
|
|
944
|
+
if (!classNameIndex.has(cls)) allForOrder.push(cls);
|
|
937
945
|
}
|
|
938
946
|
const order = {};
|
|
939
947
|
const orderResults = ds.getClassOrder(allForOrder);
|
|
@@ -1063,7 +1071,8 @@ async function main() {
|
|
|
1063
1071
|
const candidates = [];
|
|
1064
1072
|
for (const cls of validClasses) {
|
|
1065
1073
|
if (cls.includes('[') || cls.includes('/')) continue;
|
|
1066
|
-
const idx =
|
|
1074
|
+
const idx = classNameIndex.get(cls);
|
|
1075
|
+
if (idx === undefined) continue;
|
|
1067
1076
|
const cssText = cssResults[idx];
|
|
1068
1077
|
if (!cssText) continue;
|
|
1069
1078
|
const pvMatch = cssText.match(/^\\s+([\\w-]+)\\s*:\\s*(.+?)\\s*;?\\s*$/m);
|
|
@@ -1096,21 +1105,61 @@ async function main() {
|
|
|
1096
1105
|
main().catch(e => { process.stderr.write(e.message); process.exit(1); });
|
|
1097
1106
|
`;
|
|
1098
1107
|
const CACHE_DIR = (0, node_path.join)((0, node_os.tmpdir)(), "oxlint-tailwindcss");
|
|
1099
|
-
const CACHE_VERSION =
|
|
1100
|
-
|
|
1101
|
-
|
|
1108
|
+
const CACHE_VERSION = 11;
|
|
1109
|
+
/**
|
|
1110
|
+
* Two-level disk cache for monorepo deduplication:
|
|
1111
|
+
*
|
|
1112
|
+
* Level 1 — mtime index (.idx): maps path+mtime → content hash (fast-path, avoids reading CSS)
|
|
1113
|
+
* Level 2 — content cache (.json): maps content hash → precomputed data (shared across packages)
|
|
1114
|
+
*
|
|
1115
|
+
* In monorepos, multiple packages with identical CSS (e.g. `@import 'tailwindcss'`) at different
|
|
1116
|
+
* paths share a single content cache entry, avoiding redundant child process spawns.
|
|
1117
|
+
*/
|
|
1118
|
+
function getMtimeIndexPath(cssPath, mtime) {
|
|
1119
|
+
return (0, node_path.join)(CACHE_DIR, `${(0, node_crypto.createHash)("md5").update(`v${CACHE_VERSION}:${cssPath}:${mtime}`).digest("hex")}.idx`);
|
|
1120
|
+
}
|
|
1121
|
+
function computeContentHash(content) {
|
|
1122
|
+
return (0, node_crypto.createHash)("md5").update(`v${CACHE_VERSION}:${content}`).digest("hex");
|
|
1123
|
+
}
|
|
1124
|
+
function getContentCachePath(contentHash) {
|
|
1125
|
+
return (0, node_path.join)(CACHE_DIR, `${contentHash}.json`);
|
|
1126
|
+
}
|
|
1127
|
+
function tryReadCache(cachePath) {
|
|
1128
|
+
try {
|
|
1129
|
+
return JSON.parse((0, node_fs.readFileSync)(cachePath, "utf-8"));
|
|
1130
|
+
} catch {
|
|
1131
|
+
return null;
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
function writeCacheFiles(contentCachePath, mtimeIndexPath, contentHash, data) {
|
|
1135
|
+
try {
|
|
1136
|
+
(0, node_fs.mkdirSync)(CACHE_DIR, { recursive: true });
|
|
1137
|
+
(0, node_fs.writeFileSync)(contentCachePath, data);
|
|
1138
|
+
(0, node_fs.writeFileSync)(mtimeIndexPath, contentHash);
|
|
1139
|
+
} catch {}
|
|
1102
1140
|
}
|
|
1103
|
-
function loadDesignSystemSync(cssPath) {
|
|
1141
|
+
function loadDesignSystemSync(cssPath, timeout) {
|
|
1104
1142
|
const resolvedPath = (0, node_path.resolve)(cssPath);
|
|
1105
1143
|
try {
|
|
1106
1144
|
const mtime = (0, node_fs.statSync)(resolvedPath).mtimeMs;
|
|
1107
|
-
const
|
|
1108
|
-
if ((0, node_fs.existsSync)(
|
|
1109
|
-
|
|
1145
|
+
const mtimeIndexPath = getMtimeIndexPath(resolvedPath, mtime);
|
|
1146
|
+
if ((0, node_fs.existsSync)(mtimeIndexPath)) try {
|
|
1147
|
+
const cached = tryReadCache(getContentCachePath((0, node_fs.readFileSync)(mtimeIndexPath, "utf-8").trim()));
|
|
1148
|
+
if (cached) return cached;
|
|
1110
1149
|
} catch {}
|
|
1150
|
+
const contentHash = computeContentHash((0, node_fs.readFileSync)(resolvedPath, "utf-8"));
|
|
1151
|
+
const contentCachePath = getContentCachePath(contentHash);
|
|
1152
|
+
const cached = tryReadCache(contentCachePath);
|
|
1153
|
+
if (cached) {
|
|
1154
|
+
try {
|
|
1155
|
+
(0, node_fs.mkdirSync)(CACHE_DIR, { recursive: true });
|
|
1156
|
+
(0, node_fs.writeFileSync)(mtimeIndexPath, contentHash);
|
|
1157
|
+
} catch {}
|
|
1158
|
+
return cached;
|
|
1159
|
+
}
|
|
1111
1160
|
const stdout = (0, node_child_process.execFileSync)(process.execPath, ["-e", PRECOMPUTE_SCRIPT], {
|
|
1112
1161
|
encoding: "utf-8",
|
|
1113
|
-
timeout: 3e4,
|
|
1162
|
+
timeout: timeout ?? 3e4,
|
|
1114
1163
|
maxBuffer: 50 * 1024 * 1024,
|
|
1115
1164
|
env: {
|
|
1116
1165
|
...process.env,
|
|
@@ -1118,10 +1167,7 @@ function loadDesignSystemSync(cssPath) {
|
|
|
1118
1167
|
},
|
|
1119
1168
|
cwd: (0, node_path.dirname)(resolvedPath)
|
|
1120
1169
|
});
|
|
1121
|
-
|
|
1122
|
-
(0, node_fs.mkdirSync)(CACHE_DIR, { recursive: true });
|
|
1123
|
-
(0, node_fs.writeFileSync)(cachePath, stdout);
|
|
1124
|
-
} catch {}
|
|
1170
|
+
writeCacheFiles(contentCachePath, mtimeIndexPath, contentHash, stdout);
|
|
1125
1171
|
return JSON.parse(stdout);
|
|
1126
1172
|
} catch (error) {
|
|
1127
1173
|
console.error(`[oxlint-tailwindcss] Failed to load design system from "${resolvedPath}":`, error instanceof Error ? error.message : error);
|
|
@@ -1215,29 +1261,18 @@ function autoDetectEntryPoint(filePath) {
|
|
|
1215
1261
|
continue;
|
|
1216
1262
|
}
|
|
1217
1263
|
}
|
|
1264
|
+
if ((0, node_fs.existsSync)((0, node_path.join)(currentDir, "package.json"))) break;
|
|
1218
1265
|
const parentDir = (0, node_path.dirname)(currentDir);
|
|
1219
1266
|
if (parentDir === currentDir) break;
|
|
1220
|
-
if (depth > 0 && (0, node_fs.existsSync)((0, node_path.join)(parentDir, "package.json"))) {
|
|
1221
|
-
for (const candidate of CANDIDATE_PATHS) {
|
|
1222
|
-
const fullPath = (0, node_path.join)(parentDir, candidate);
|
|
1223
|
-
if (!(0, node_fs.existsSync)(fullPath)) continue;
|
|
1224
|
-
try {
|
|
1225
|
-
const content = (0, node_fs.readFileSync)(fullPath, "utf-8");
|
|
1226
|
-
if (TAILWIND_SIGNALS.some((signal) => content.includes(signal))) return fullPath;
|
|
1227
|
-
if (hasTailwindSignalInImports(content, (0, node_path.dirname)(fullPath), TAILWIND_SIGNALS)) return fullPath;
|
|
1228
|
-
} catch {
|
|
1229
|
-
continue;
|
|
1230
|
-
}
|
|
1231
|
-
}
|
|
1232
|
-
break;
|
|
1233
|
-
}
|
|
1234
1267
|
currentDir = parentDir;
|
|
1235
1268
|
}
|
|
1236
1269
|
return null;
|
|
1237
1270
|
}
|
|
1238
1271
|
//#endregion
|
|
1239
1272
|
//#region src/design-system/loader.ts
|
|
1240
|
-
|
|
1273
|
+
const dsCache = /* @__PURE__ */ new Map();
|
|
1274
|
+
const autoDetectCache = /* @__PURE__ */ new Map();
|
|
1275
|
+
let lastLoadedPath = null;
|
|
1241
1276
|
/**
|
|
1242
1277
|
* Extracts `entryPoint` from `context.settings.tailwindcss`.
|
|
1243
1278
|
*/
|
|
@@ -1249,30 +1284,62 @@ function entryPointFromSettings(settings) {
|
|
|
1249
1284
|
}
|
|
1250
1285
|
}
|
|
1251
1286
|
/**
|
|
1287
|
+
* Extracts `timeout` from `context.settings.tailwindcss`.
|
|
1288
|
+
*/
|
|
1289
|
+
function timeoutFromSettings(settings) {
|
|
1290
|
+
const tw = settings?.tailwindcss;
|
|
1291
|
+
if (tw && typeof tw === "object" && "timeout" in tw) {
|
|
1292
|
+
const t = tw.timeout;
|
|
1293
|
+
if (typeof t === "number" && t > 0) return t;
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
/**
|
|
1297
|
+
* Cached auto-detect: caches by directory since all files in the same directory
|
|
1298
|
+
* resolve to the same entry point. Avoids repeated filesystem walks.
|
|
1299
|
+
*/
|
|
1300
|
+
function cachedAutoDetect(filePath) {
|
|
1301
|
+
if (!filePath) return autoDetectEntryPoint(filePath);
|
|
1302
|
+
const dir = (0, node_path.dirname)((0, node_path.resolve)(filePath));
|
|
1303
|
+
const cached = autoDetectCache.get(dir);
|
|
1304
|
+
if (cached !== void 0) return cached;
|
|
1305
|
+
const result = autoDetectEntryPoint(filePath);
|
|
1306
|
+
autoDetectCache.set(dir, result);
|
|
1307
|
+
return result;
|
|
1308
|
+
}
|
|
1309
|
+
/**
|
|
1252
1310
|
* Returns the design system cache, loading synchronously on first call.
|
|
1253
1311
|
* Uses execFileSync internally to bridge the async Tailwind API.
|
|
1254
|
-
*
|
|
1312
|
+
*
|
|
1313
|
+
* Supports multiple design systems: each unique CSS entry point gets its own cache.
|
|
1314
|
+
* In monorepos, files in different packages auto-detect to different entry points
|
|
1315
|
+
* and each gets the correct DS.
|
|
1255
1316
|
*
|
|
1256
1317
|
* Resolution order: rule option `entryPoint` > `settings.tailwindcss.entryPoint` > auto-detect.
|
|
1257
1318
|
*/
|
|
1258
1319
|
function getLoadedDesignSystem(entryPoint, settings, filePath) {
|
|
1259
|
-
const
|
|
1320
|
+
const explicitEntry = entryPoint ?? entryPointFromSettings(settings);
|
|
1321
|
+
const cssPath = explicitEntry ?? cachedAutoDetect(filePath) ?? lastLoadedPath;
|
|
1260
1322
|
if (!cssPath) return null;
|
|
1261
1323
|
const resolvedPath = (0, node_path.resolve)(cssPath);
|
|
1262
1324
|
try {
|
|
1263
1325
|
const mtime = (0, node_fs.statSync)(resolvedPath).mtimeMs;
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1326
|
+
const cached = dsCache.get(resolvedPath);
|
|
1327
|
+
if (cached && cached.mtime === mtime) {
|
|
1328
|
+
if (explicitEntry) lastLoadedPath = resolvedPath;
|
|
1329
|
+
return {
|
|
1330
|
+
cache: cached.cache,
|
|
1331
|
+
entryPoint: resolvedPath
|
|
1332
|
+
};
|
|
1333
|
+
}
|
|
1334
|
+
const data = loadDesignSystemSync(resolvedPath, timeoutFromSettings(settings));
|
|
1269
1335
|
if (!data) return null;
|
|
1270
1336
|
const cache = DesignSystemCache.fromPrecomputed(data);
|
|
1271
|
-
|
|
1337
|
+
dsCache.set(resolvedPath, {
|
|
1272
1338
|
cache,
|
|
1273
|
-
path: resolvedPath,
|
|
1274
1339
|
mtime
|
|
1275
|
-
};
|
|
1340
|
+
});
|
|
1341
|
+
console.error(`[oxlint-tailwindcss] Loaded design system from "${resolvedPath}"`);
|
|
1342
|
+
if (explicitEntry) lastLoadedPath = resolvedPath;
|
|
1276
1343
|
return {
|
|
1277
1344
|
cache,
|
|
1278
1345
|
entryPoint: resolvedPath
|
|
@@ -1282,17 +1349,21 @@ function getLoadedDesignSystem(entryPoint, settings, filePath) {
|
|
|
1282
1349
|
}
|
|
1283
1350
|
}
|
|
1284
1351
|
/**
|
|
1285
|
-
* Creates a lazy DS loader that
|
|
1352
|
+
* Creates a lazy DS loader that resolves the correct design system per file.
|
|
1286
1353
|
*
|
|
1287
1354
|
* In `createOnce`, `context.settings` and `context.filename` throw. When visitors
|
|
1288
|
-
* run, they become available.
|
|
1289
|
-
*
|
|
1355
|
+
* run, they become available. The loader re-resolves when the filename changes,
|
|
1356
|
+
* supporting monorepos where different files need different design systems.
|
|
1357
|
+
*
|
|
1358
|
+
* When a fixed entryPoint is provided (rule option or settings), it's used for all
|
|
1359
|
+
* files and cached after first resolution.
|
|
1290
1360
|
*/
|
|
1291
1361
|
function createLazyLoader(context) {
|
|
1292
|
-
let result = null;
|
|
1293
1362
|
let lastFilePath;
|
|
1363
|
+
let lastResult = null;
|
|
1364
|
+
let fixedEntryResolved = false;
|
|
1365
|
+
let fixedResult = null;
|
|
1294
1366
|
return () => {
|
|
1295
|
-
if (result) return result;
|
|
1296
1367
|
let entryPoint;
|
|
1297
1368
|
try {
|
|
1298
1369
|
entryPoint = (context.options?.[0])?.entryPoint;
|
|
@@ -1305,10 +1376,17 @@ function createLazyLoader(context) {
|
|
|
1305
1376
|
try {
|
|
1306
1377
|
filePath = context.filename;
|
|
1307
1378
|
} catch {}
|
|
1308
|
-
|
|
1379
|
+
const fixedEntry = entryPoint ?? entryPointFromSettings(settings);
|
|
1380
|
+
if (fixedEntry) {
|
|
1381
|
+
if (fixedEntryResolved) return fixedResult;
|
|
1382
|
+
fixedEntryResolved = true;
|
|
1383
|
+
fixedResult = getLoadedDesignSystem(fixedEntry, settings, filePath);
|
|
1384
|
+
return fixedResult;
|
|
1385
|
+
}
|
|
1386
|
+
if (filePath && filePath === lastFilePath) return lastResult;
|
|
1309
1387
|
if (filePath) lastFilePath = filePath;
|
|
1310
|
-
|
|
1311
|
-
return
|
|
1388
|
+
lastResult = getLoadedDesignSystem(void 0, settings, filePath);
|
|
1389
|
+
return lastResult;
|
|
1312
1390
|
};
|
|
1313
1391
|
}
|
|
1314
1392
|
//#endregion
|
|
@@ -1544,6 +1622,7 @@ const noConflictingClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1544
1622
|
];
|
|
1545
1623
|
const COMPOSITION_PAIRS = [
|
|
1546
1624
|
[/^text-/, /^leading-/],
|
|
1625
|
+
[/^text-/, /^tracking-/],
|
|
1547
1626
|
[/^border(?:-[0-9]|$)/, /^border-(?:solid|dashed|dotted|double|hidden|none)$/],
|
|
1548
1627
|
[/^divide-/, /^border(?:-[trblxyse])?-/],
|
|
1549
1628
|
[/^prose(?:-|$)/, /^max-w-/]
|
|
@@ -1737,9 +1816,19 @@ let lengthView = null;
|
|
|
1737
1816
|
let dataArea = null;
|
|
1738
1817
|
let initialized = false;
|
|
1739
1818
|
let available = true;
|
|
1819
|
+
let currentCssPath = null;
|
|
1740
1820
|
function ensureService(cssPath) {
|
|
1741
|
-
if (initialized) return available;
|
|
1821
|
+
if (initialized && currentCssPath === cssPath) return available;
|
|
1822
|
+
if (initialized) {
|
|
1823
|
+
cleanup();
|
|
1824
|
+
initialized = false;
|
|
1825
|
+
available = true;
|
|
1826
|
+
controlArray = null;
|
|
1827
|
+
lengthView = null;
|
|
1828
|
+
dataArea = null;
|
|
1829
|
+
}
|
|
1742
1830
|
initialized = true;
|
|
1831
|
+
currentCssPath = cssPath;
|
|
1743
1832
|
try {
|
|
1744
1833
|
const tailwindNodePath = require.resolve("@tailwindcss/node");
|
|
1745
1834
|
const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE);
|
package/dist/index.mjs
CHANGED
|
@@ -177,6 +177,10 @@ function extractFromClassedCall(node) {
|
|
|
177
177
|
skippedFirst = true;
|
|
178
178
|
continue;
|
|
179
179
|
}
|
|
180
|
+
if (!skippedFirst && arg.type === "TemplateLiteral") {
|
|
181
|
+
skippedFirst = true;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
180
184
|
skippedFirst = true;
|
|
181
185
|
if (arg.type === "ObjectExpression") results.push(...extractFromCvaConfig(arg));
|
|
182
186
|
else results.push(...extractFromExpression(arg));
|
|
@@ -876,6 +880,10 @@ async function main() {
|
|
|
876
880
|
const entries = ds.getClassList();
|
|
877
881
|
const classNames = entries.map(e => e[0]);
|
|
878
882
|
|
|
883
|
+
// Index for O(1) lookups by class name (avoids O(N) indexOf/includes in later phases)
|
|
884
|
+
const classNameIndex = new Map();
|
|
885
|
+
for (let i = 0; i < classNames.length; i++) classNameIndex.set(classNames[i], i);
|
|
886
|
+
|
|
879
887
|
// Validity: which classes produce CSS
|
|
880
888
|
const cssResults = ds.candidatesToCss(classNames);
|
|
881
889
|
const validClasses = classNames.filter((_, i) => cssResults[i] != null);
|
|
@@ -937,7 +945,7 @@ async function main() {
|
|
|
937
945
|
// Sort order — include extra candidates so bare utilities (rounded, blur, etc.) get order
|
|
938
946
|
const allForOrder = [...classNames];
|
|
939
947
|
for (const cls of validClasses) {
|
|
940
|
-
if (!
|
|
948
|
+
if (!classNameIndex.has(cls)) allForOrder.push(cls);
|
|
941
949
|
}
|
|
942
950
|
const order = {};
|
|
943
951
|
const orderResults = ds.getClassOrder(allForOrder);
|
|
@@ -1067,7 +1075,8 @@ async function main() {
|
|
|
1067
1075
|
const candidates = [];
|
|
1068
1076
|
for (const cls of validClasses) {
|
|
1069
1077
|
if (cls.includes('[') || cls.includes('/')) continue;
|
|
1070
|
-
const idx =
|
|
1078
|
+
const idx = classNameIndex.get(cls);
|
|
1079
|
+
if (idx === undefined) continue;
|
|
1071
1080
|
const cssText = cssResults[idx];
|
|
1072
1081
|
if (!cssText) continue;
|
|
1073
1082
|
const pvMatch = cssText.match(/^\\s+([\\w-]+)\\s*:\\s*(.+?)\\s*;?\\s*$/m);
|
|
@@ -1100,21 +1109,61 @@ async function main() {
|
|
|
1100
1109
|
main().catch(e => { process.stderr.write(e.message); process.exit(1); });
|
|
1101
1110
|
`;
|
|
1102
1111
|
const CACHE_DIR = join(tmpdir(), "oxlint-tailwindcss");
|
|
1103
|
-
const CACHE_VERSION =
|
|
1104
|
-
|
|
1105
|
-
|
|
1112
|
+
const CACHE_VERSION = 11;
|
|
1113
|
+
/**
|
|
1114
|
+
* Two-level disk cache for monorepo deduplication:
|
|
1115
|
+
*
|
|
1116
|
+
* Level 1 — mtime index (.idx): maps path+mtime → content hash (fast-path, avoids reading CSS)
|
|
1117
|
+
* Level 2 — content cache (.json): maps content hash → precomputed data (shared across packages)
|
|
1118
|
+
*
|
|
1119
|
+
* In monorepos, multiple packages with identical CSS (e.g. `@import 'tailwindcss'`) at different
|
|
1120
|
+
* paths share a single content cache entry, avoiding redundant child process spawns.
|
|
1121
|
+
*/
|
|
1122
|
+
function getMtimeIndexPath(cssPath, mtime) {
|
|
1123
|
+
return join(CACHE_DIR, `${createHash("md5").update(`v${CACHE_VERSION}:${cssPath}:${mtime}`).digest("hex")}.idx`);
|
|
1124
|
+
}
|
|
1125
|
+
function computeContentHash(content) {
|
|
1126
|
+
return createHash("md5").update(`v${CACHE_VERSION}:${content}`).digest("hex");
|
|
1127
|
+
}
|
|
1128
|
+
function getContentCachePath(contentHash) {
|
|
1129
|
+
return join(CACHE_DIR, `${contentHash}.json`);
|
|
1130
|
+
}
|
|
1131
|
+
function tryReadCache(cachePath) {
|
|
1132
|
+
try {
|
|
1133
|
+
return JSON.parse(readFileSync(cachePath, "utf-8"));
|
|
1134
|
+
} catch {
|
|
1135
|
+
return null;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
function writeCacheFiles(contentCachePath, mtimeIndexPath, contentHash, data) {
|
|
1139
|
+
try {
|
|
1140
|
+
mkdirSync(CACHE_DIR, { recursive: true });
|
|
1141
|
+
writeFileSync(contentCachePath, data);
|
|
1142
|
+
writeFileSync(mtimeIndexPath, contentHash);
|
|
1143
|
+
} catch {}
|
|
1106
1144
|
}
|
|
1107
|
-
function loadDesignSystemSync(cssPath) {
|
|
1145
|
+
function loadDesignSystemSync(cssPath, timeout) {
|
|
1108
1146
|
const resolvedPath = resolve(cssPath);
|
|
1109
1147
|
try {
|
|
1110
1148
|
const mtime = statSync(resolvedPath).mtimeMs;
|
|
1111
|
-
const
|
|
1112
|
-
if (existsSync(
|
|
1113
|
-
|
|
1149
|
+
const mtimeIndexPath = getMtimeIndexPath(resolvedPath, mtime);
|
|
1150
|
+
if (existsSync(mtimeIndexPath)) try {
|
|
1151
|
+
const cached = tryReadCache(getContentCachePath(readFileSync(mtimeIndexPath, "utf-8").trim()));
|
|
1152
|
+
if (cached) return cached;
|
|
1114
1153
|
} catch {}
|
|
1154
|
+
const contentHash = computeContentHash(readFileSync(resolvedPath, "utf-8"));
|
|
1155
|
+
const contentCachePath = getContentCachePath(contentHash);
|
|
1156
|
+
const cached = tryReadCache(contentCachePath);
|
|
1157
|
+
if (cached) {
|
|
1158
|
+
try {
|
|
1159
|
+
mkdirSync(CACHE_DIR, { recursive: true });
|
|
1160
|
+
writeFileSync(mtimeIndexPath, contentHash);
|
|
1161
|
+
} catch {}
|
|
1162
|
+
return cached;
|
|
1163
|
+
}
|
|
1115
1164
|
const stdout = execFileSync(process.execPath, ["-e", PRECOMPUTE_SCRIPT], {
|
|
1116
1165
|
encoding: "utf-8",
|
|
1117
|
-
timeout: 3e4,
|
|
1166
|
+
timeout: timeout ?? 3e4,
|
|
1118
1167
|
maxBuffer: 50 * 1024 * 1024,
|
|
1119
1168
|
env: {
|
|
1120
1169
|
...process.env,
|
|
@@ -1122,10 +1171,7 @@ function loadDesignSystemSync(cssPath) {
|
|
|
1122
1171
|
},
|
|
1123
1172
|
cwd: dirname(resolvedPath)
|
|
1124
1173
|
});
|
|
1125
|
-
|
|
1126
|
-
mkdirSync(CACHE_DIR, { recursive: true });
|
|
1127
|
-
writeFileSync(cachePath, stdout);
|
|
1128
|
-
} catch {}
|
|
1174
|
+
writeCacheFiles(contentCachePath, mtimeIndexPath, contentHash, stdout);
|
|
1129
1175
|
return JSON.parse(stdout);
|
|
1130
1176
|
} catch (error) {
|
|
1131
1177
|
console.error(`[oxlint-tailwindcss] Failed to load design system from "${resolvedPath}":`, error instanceof Error ? error.message : error);
|
|
@@ -1219,29 +1265,18 @@ function autoDetectEntryPoint(filePath) {
|
|
|
1219
1265
|
continue;
|
|
1220
1266
|
}
|
|
1221
1267
|
}
|
|
1268
|
+
if (existsSync(join(currentDir, "package.json"))) break;
|
|
1222
1269
|
const parentDir = dirname(currentDir);
|
|
1223
1270
|
if (parentDir === currentDir) break;
|
|
1224
|
-
if (depth > 0 && existsSync(join(parentDir, "package.json"))) {
|
|
1225
|
-
for (const candidate of CANDIDATE_PATHS) {
|
|
1226
|
-
const fullPath = join(parentDir, candidate);
|
|
1227
|
-
if (!existsSync(fullPath)) continue;
|
|
1228
|
-
try {
|
|
1229
|
-
const content = readFileSync(fullPath, "utf-8");
|
|
1230
|
-
if (TAILWIND_SIGNALS.some((signal) => content.includes(signal))) return fullPath;
|
|
1231
|
-
if (hasTailwindSignalInImports(content, dirname(fullPath), TAILWIND_SIGNALS)) return fullPath;
|
|
1232
|
-
} catch {
|
|
1233
|
-
continue;
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
break;
|
|
1237
|
-
}
|
|
1238
1271
|
currentDir = parentDir;
|
|
1239
1272
|
}
|
|
1240
1273
|
return null;
|
|
1241
1274
|
}
|
|
1242
1275
|
//#endregion
|
|
1243
1276
|
//#region src/design-system/loader.ts
|
|
1244
|
-
|
|
1277
|
+
const dsCache = /* @__PURE__ */ new Map();
|
|
1278
|
+
const autoDetectCache = /* @__PURE__ */ new Map();
|
|
1279
|
+
let lastLoadedPath = null;
|
|
1245
1280
|
/**
|
|
1246
1281
|
* Extracts `entryPoint` from `context.settings.tailwindcss`.
|
|
1247
1282
|
*/
|
|
@@ -1253,30 +1288,62 @@ function entryPointFromSettings(settings) {
|
|
|
1253
1288
|
}
|
|
1254
1289
|
}
|
|
1255
1290
|
/**
|
|
1291
|
+
* Extracts `timeout` from `context.settings.tailwindcss`.
|
|
1292
|
+
*/
|
|
1293
|
+
function timeoutFromSettings(settings) {
|
|
1294
|
+
const tw = settings?.tailwindcss;
|
|
1295
|
+
if (tw && typeof tw === "object" && "timeout" in tw) {
|
|
1296
|
+
const t = tw.timeout;
|
|
1297
|
+
if (typeof t === "number" && t > 0) return t;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
/**
|
|
1301
|
+
* Cached auto-detect: caches by directory since all files in the same directory
|
|
1302
|
+
* resolve to the same entry point. Avoids repeated filesystem walks.
|
|
1303
|
+
*/
|
|
1304
|
+
function cachedAutoDetect(filePath) {
|
|
1305
|
+
if (!filePath) return autoDetectEntryPoint(filePath);
|
|
1306
|
+
const dir = dirname(resolve(filePath));
|
|
1307
|
+
const cached = autoDetectCache.get(dir);
|
|
1308
|
+
if (cached !== void 0) return cached;
|
|
1309
|
+
const result = autoDetectEntryPoint(filePath);
|
|
1310
|
+
autoDetectCache.set(dir, result);
|
|
1311
|
+
return result;
|
|
1312
|
+
}
|
|
1313
|
+
/**
|
|
1256
1314
|
* Returns the design system cache, loading synchronously on first call.
|
|
1257
1315
|
* Uses execFileSync internally to bridge the async Tailwind API.
|
|
1258
|
-
*
|
|
1316
|
+
*
|
|
1317
|
+
* Supports multiple design systems: each unique CSS entry point gets its own cache.
|
|
1318
|
+
* In monorepos, files in different packages auto-detect to different entry points
|
|
1319
|
+
* and each gets the correct DS.
|
|
1259
1320
|
*
|
|
1260
1321
|
* Resolution order: rule option `entryPoint` > `settings.tailwindcss.entryPoint` > auto-detect.
|
|
1261
1322
|
*/
|
|
1262
1323
|
function getLoadedDesignSystem(entryPoint, settings, filePath) {
|
|
1263
|
-
const
|
|
1324
|
+
const explicitEntry = entryPoint ?? entryPointFromSettings(settings);
|
|
1325
|
+
const cssPath = explicitEntry ?? cachedAutoDetect(filePath) ?? lastLoadedPath;
|
|
1264
1326
|
if (!cssPath) return null;
|
|
1265
1327
|
const resolvedPath = resolve(cssPath);
|
|
1266
1328
|
try {
|
|
1267
1329
|
const mtime = statSync(resolvedPath).mtimeMs;
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1330
|
+
const cached = dsCache.get(resolvedPath);
|
|
1331
|
+
if (cached && cached.mtime === mtime) {
|
|
1332
|
+
if (explicitEntry) lastLoadedPath = resolvedPath;
|
|
1333
|
+
return {
|
|
1334
|
+
cache: cached.cache,
|
|
1335
|
+
entryPoint: resolvedPath
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
const data = loadDesignSystemSync(resolvedPath, timeoutFromSettings(settings));
|
|
1273
1339
|
if (!data) return null;
|
|
1274
1340
|
const cache = DesignSystemCache.fromPrecomputed(data);
|
|
1275
|
-
|
|
1341
|
+
dsCache.set(resolvedPath, {
|
|
1276
1342
|
cache,
|
|
1277
|
-
path: resolvedPath,
|
|
1278
1343
|
mtime
|
|
1279
|
-
};
|
|
1344
|
+
});
|
|
1345
|
+
console.error(`[oxlint-tailwindcss] Loaded design system from "${resolvedPath}"`);
|
|
1346
|
+
if (explicitEntry) lastLoadedPath = resolvedPath;
|
|
1280
1347
|
return {
|
|
1281
1348
|
cache,
|
|
1282
1349
|
entryPoint: resolvedPath
|
|
@@ -1286,17 +1353,21 @@ function getLoadedDesignSystem(entryPoint, settings, filePath) {
|
|
|
1286
1353
|
}
|
|
1287
1354
|
}
|
|
1288
1355
|
/**
|
|
1289
|
-
* Creates a lazy DS loader that
|
|
1356
|
+
* Creates a lazy DS loader that resolves the correct design system per file.
|
|
1290
1357
|
*
|
|
1291
1358
|
* In `createOnce`, `context.settings` and `context.filename` throw. When visitors
|
|
1292
|
-
* run, they become available.
|
|
1293
|
-
*
|
|
1359
|
+
* run, they become available. The loader re-resolves when the filename changes,
|
|
1360
|
+
* supporting monorepos where different files need different design systems.
|
|
1361
|
+
*
|
|
1362
|
+
* When a fixed entryPoint is provided (rule option or settings), it's used for all
|
|
1363
|
+
* files and cached after first resolution.
|
|
1294
1364
|
*/
|
|
1295
1365
|
function createLazyLoader(context) {
|
|
1296
|
-
let result = null;
|
|
1297
1366
|
let lastFilePath;
|
|
1367
|
+
let lastResult = null;
|
|
1368
|
+
let fixedEntryResolved = false;
|
|
1369
|
+
let fixedResult = null;
|
|
1298
1370
|
return () => {
|
|
1299
|
-
if (result) return result;
|
|
1300
1371
|
let entryPoint;
|
|
1301
1372
|
try {
|
|
1302
1373
|
entryPoint = (context.options?.[0])?.entryPoint;
|
|
@@ -1309,10 +1380,17 @@ function createLazyLoader(context) {
|
|
|
1309
1380
|
try {
|
|
1310
1381
|
filePath = context.filename;
|
|
1311
1382
|
} catch {}
|
|
1312
|
-
|
|
1383
|
+
const fixedEntry = entryPoint ?? entryPointFromSettings(settings);
|
|
1384
|
+
if (fixedEntry) {
|
|
1385
|
+
if (fixedEntryResolved) return fixedResult;
|
|
1386
|
+
fixedEntryResolved = true;
|
|
1387
|
+
fixedResult = getLoadedDesignSystem(fixedEntry, settings, filePath);
|
|
1388
|
+
return fixedResult;
|
|
1389
|
+
}
|
|
1390
|
+
if (filePath && filePath === lastFilePath) return lastResult;
|
|
1313
1391
|
if (filePath) lastFilePath = filePath;
|
|
1314
|
-
|
|
1315
|
-
return
|
|
1392
|
+
lastResult = getLoadedDesignSystem(void 0, settings, filePath);
|
|
1393
|
+
return lastResult;
|
|
1316
1394
|
};
|
|
1317
1395
|
}
|
|
1318
1396
|
//#endregion
|
|
@@ -1548,6 +1626,7 @@ const noConflictingClasses = defineRule({
|
|
|
1548
1626
|
];
|
|
1549
1627
|
const COMPOSITION_PAIRS = [
|
|
1550
1628
|
[/^text-/, /^leading-/],
|
|
1629
|
+
[/^text-/, /^tracking-/],
|
|
1551
1630
|
[/^border(?:-[0-9]|$)/, /^border-(?:solid|dashed|dotted|double|hidden|none)$/],
|
|
1552
1631
|
[/^divide-/, /^border(?:-[trblxyse])?-/],
|
|
1553
1632
|
[/^prose(?:-|$)/, /^max-w-/]
|
|
@@ -1741,9 +1820,19 @@ let lengthView = null;
|
|
|
1741
1820
|
let dataArea = null;
|
|
1742
1821
|
let initialized = false;
|
|
1743
1822
|
let available = true;
|
|
1823
|
+
let currentCssPath = null;
|
|
1744
1824
|
function ensureService(cssPath) {
|
|
1745
|
-
if (initialized) return available;
|
|
1825
|
+
if (initialized && currentCssPath === cssPath) return available;
|
|
1826
|
+
if (initialized) {
|
|
1827
|
+
cleanup();
|
|
1828
|
+
initialized = false;
|
|
1829
|
+
available = true;
|
|
1830
|
+
controlArray = null;
|
|
1831
|
+
lengthView = null;
|
|
1832
|
+
dataArea = null;
|
|
1833
|
+
}
|
|
1746
1834
|
initialized = true;
|
|
1835
|
+
currentCssPath = cssPath;
|
|
1747
1836
|
try {
|
|
1748
1837
|
const tailwindNodePath = __require.resolve("@tailwindcss/node");
|
|
1749
1838
|
const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE);
|