oxlint-tailwindcss 0.3.0 → 0.4.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.
- package/README.md +15 -2
- package/dist/index.cjs +124 -32
- package/dist/index.mjs +124 -32
- 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.
|
|
@@ -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
|
@@ -872,6 +872,10 @@ async function main() {
|
|
|
872
872
|
const entries = ds.getClassList();
|
|
873
873
|
const classNames = entries.map(e => e[0]);
|
|
874
874
|
|
|
875
|
+
// Index for O(1) lookups by class name (avoids O(N) indexOf/includes in later phases)
|
|
876
|
+
const classNameIndex = new Map();
|
|
877
|
+
for (let i = 0; i < classNames.length; i++) classNameIndex.set(classNames[i], i);
|
|
878
|
+
|
|
875
879
|
// Validity: which classes produce CSS
|
|
876
880
|
const cssResults = ds.candidatesToCss(classNames);
|
|
877
881
|
const validClasses = classNames.filter((_, i) => cssResults[i] != null);
|
|
@@ -933,7 +937,7 @@ async function main() {
|
|
|
933
937
|
// Sort order — include extra candidates so bare utilities (rounded, blur, etc.) get order
|
|
934
938
|
const allForOrder = [...classNames];
|
|
935
939
|
for (const cls of validClasses) {
|
|
936
|
-
if (!
|
|
940
|
+
if (!classNameIndex.has(cls)) allForOrder.push(cls);
|
|
937
941
|
}
|
|
938
942
|
const order = {};
|
|
939
943
|
const orderResults = ds.getClassOrder(allForOrder);
|
|
@@ -1063,7 +1067,8 @@ async function main() {
|
|
|
1063
1067
|
const candidates = [];
|
|
1064
1068
|
for (const cls of validClasses) {
|
|
1065
1069
|
if (cls.includes('[') || cls.includes('/')) continue;
|
|
1066
|
-
const idx =
|
|
1070
|
+
const idx = classNameIndex.get(cls);
|
|
1071
|
+
if (idx === undefined) continue;
|
|
1067
1072
|
const cssText = cssResults[idx];
|
|
1068
1073
|
if (!cssText) continue;
|
|
1069
1074
|
const pvMatch = cssText.match(/^\\s+([\\w-]+)\\s*:\\s*(.+?)\\s*;?\\s*$/m);
|
|
@@ -1096,21 +1101,61 @@ async function main() {
|
|
|
1096
1101
|
main().catch(e => { process.stderr.write(e.message); process.exit(1); });
|
|
1097
1102
|
`;
|
|
1098
1103
|
const CACHE_DIR = (0, node_path.join)((0, node_os.tmpdir)(), "oxlint-tailwindcss");
|
|
1099
|
-
const CACHE_VERSION =
|
|
1100
|
-
|
|
1101
|
-
|
|
1104
|
+
const CACHE_VERSION = 11;
|
|
1105
|
+
/**
|
|
1106
|
+
* Two-level disk cache for monorepo deduplication:
|
|
1107
|
+
*
|
|
1108
|
+
* Level 1 — mtime index (.idx): maps path+mtime → content hash (fast-path, avoids reading CSS)
|
|
1109
|
+
* Level 2 — content cache (.json): maps content hash → precomputed data (shared across packages)
|
|
1110
|
+
*
|
|
1111
|
+
* In monorepos, multiple packages with identical CSS (e.g. `@import 'tailwindcss'`) at different
|
|
1112
|
+
* paths share a single content cache entry, avoiding redundant child process spawns.
|
|
1113
|
+
*/
|
|
1114
|
+
function getMtimeIndexPath(cssPath, mtime) {
|
|
1115
|
+
return (0, node_path.join)(CACHE_DIR, `${(0, node_crypto.createHash)("md5").update(`v${CACHE_VERSION}:${cssPath}:${mtime}`).digest("hex")}.idx`);
|
|
1102
1116
|
}
|
|
1103
|
-
function
|
|
1117
|
+
function computeContentHash(content) {
|
|
1118
|
+
return (0, node_crypto.createHash)("md5").update(`v${CACHE_VERSION}:${content}`).digest("hex");
|
|
1119
|
+
}
|
|
1120
|
+
function getContentCachePath(contentHash) {
|
|
1121
|
+
return (0, node_path.join)(CACHE_DIR, `${contentHash}.json`);
|
|
1122
|
+
}
|
|
1123
|
+
function tryReadCache(cachePath) {
|
|
1124
|
+
try {
|
|
1125
|
+
return JSON.parse((0, node_fs.readFileSync)(cachePath, "utf-8"));
|
|
1126
|
+
} catch {
|
|
1127
|
+
return null;
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
function writeCacheFiles(contentCachePath, mtimeIndexPath, contentHash, data) {
|
|
1131
|
+
try {
|
|
1132
|
+
(0, node_fs.mkdirSync)(CACHE_DIR, { recursive: true });
|
|
1133
|
+
(0, node_fs.writeFileSync)(contentCachePath, data);
|
|
1134
|
+
(0, node_fs.writeFileSync)(mtimeIndexPath, contentHash);
|
|
1135
|
+
} catch {}
|
|
1136
|
+
}
|
|
1137
|
+
function loadDesignSystemSync(cssPath, timeout) {
|
|
1104
1138
|
const resolvedPath = (0, node_path.resolve)(cssPath);
|
|
1105
1139
|
try {
|
|
1106
1140
|
const mtime = (0, node_fs.statSync)(resolvedPath).mtimeMs;
|
|
1107
|
-
const
|
|
1108
|
-
if ((0, node_fs.existsSync)(
|
|
1109
|
-
|
|
1141
|
+
const mtimeIndexPath = getMtimeIndexPath(resolvedPath, mtime);
|
|
1142
|
+
if ((0, node_fs.existsSync)(mtimeIndexPath)) try {
|
|
1143
|
+
const cached = tryReadCache(getContentCachePath((0, node_fs.readFileSync)(mtimeIndexPath, "utf-8").trim()));
|
|
1144
|
+
if (cached) return cached;
|
|
1110
1145
|
} catch {}
|
|
1146
|
+
const contentHash = computeContentHash((0, node_fs.readFileSync)(resolvedPath, "utf-8"));
|
|
1147
|
+
const contentCachePath = getContentCachePath(contentHash);
|
|
1148
|
+
const cached = tryReadCache(contentCachePath);
|
|
1149
|
+
if (cached) {
|
|
1150
|
+
try {
|
|
1151
|
+
(0, node_fs.mkdirSync)(CACHE_DIR, { recursive: true });
|
|
1152
|
+
(0, node_fs.writeFileSync)(mtimeIndexPath, contentHash);
|
|
1153
|
+
} catch {}
|
|
1154
|
+
return cached;
|
|
1155
|
+
}
|
|
1111
1156
|
const stdout = (0, node_child_process.execFileSync)(process.execPath, ["-e", PRECOMPUTE_SCRIPT], {
|
|
1112
1157
|
encoding: "utf-8",
|
|
1113
|
-
timeout: 3e4,
|
|
1158
|
+
timeout: timeout ?? 3e4,
|
|
1114
1159
|
maxBuffer: 50 * 1024 * 1024,
|
|
1115
1160
|
env: {
|
|
1116
1161
|
...process.env,
|
|
@@ -1118,10 +1163,7 @@ function loadDesignSystemSync(cssPath) {
|
|
|
1118
1163
|
},
|
|
1119
1164
|
cwd: (0, node_path.dirname)(resolvedPath)
|
|
1120
1165
|
});
|
|
1121
|
-
|
|
1122
|
-
(0, node_fs.mkdirSync)(CACHE_DIR, { recursive: true });
|
|
1123
|
-
(0, node_fs.writeFileSync)(cachePath, stdout);
|
|
1124
|
-
} catch {}
|
|
1166
|
+
writeCacheFiles(contentCachePath, mtimeIndexPath, contentHash, stdout);
|
|
1125
1167
|
return JSON.parse(stdout);
|
|
1126
1168
|
} catch (error) {
|
|
1127
1169
|
console.error(`[oxlint-tailwindcss] Failed to load design system from "${resolvedPath}":`, error instanceof Error ? error.message : error);
|
|
@@ -1237,7 +1279,9 @@ function autoDetectEntryPoint(filePath) {
|
|
|
1237
1279
|
}
|
|
1238
1280
|
//#endregion
|
|
1239
1281
|
//#region src/design-system/loader.ts
|
|
1240
|
-
|
|
1282
|
+
const dsCache = /* @__PURE__ */ new Map();
|
|
1283
|
+
const autoDetectCache = /* @__PURE__ */ new Map();
|
|
1284
|
+
let lastLoadedPath = null;
|
|
1241
1285
|
/**
|
|
1242
1286
|
* Extracts `entryPoint` from `context.settings.tailwindcss`.
|
|
1243
1287
|
*/
|
|
@@ -1249,30 +1293,57 @@ function entryPointFromSettings(settings) {
|
|
|
1249
1293
|
}
|
|
1250
1294
|
}
|
|
1251
1295
|
/**
|
|
1296
|
+
* Extracts `timeout` from `context.settings.tailwindcss`.
|
|
1297
|
+
*/
|
|
1298
|
+
function timeoutFromSettings(settings) {
|
|
1299
|
+
const tw = settings?.tailwindcss;
|
|
1300
|
+
if (tw && typeof tw === "object" && "timeout" in tw) {
|
|
1301
|
+
const t = tw.timeout;
|
|
1302
|
+
if (typeof t === "number" && t > 0) return t;
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
/**
|
|
1306
|
+
* Cached auto-detect: caches by directory since all files in the same directory
|
|
1307
|
+
* resolve to the same entry point. Avoids repeated filesystem walks.
|
|
1308
|
+
*/
|
|
1309
|
+
function cachedAutoDetect(filePath) {
|
|
1310
|
+
if (!filePath) return autoDetectEntryPoint(filePath);
|
|
1311
|
+
const dir = (0, node_path.dirname)((0, node_path.resolve)(filePath));
|
|
1312
|
+
const cached = autoDetectCache.get(dir);
|
|
1313
|
+
if (cached !== void 0) return cached;
|
|
1314
|
+
const result = autoDetectEntryPoint(filePath);
|
|
1315
|
+
autoDetectCache.set(dir, result);
|
|
1316
|
+
return result;
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1252
1319
|
* Returns the design system cache, loading synchronously on first call.
|
|
1253
1320
|
* Uses execFileSync internally to bridge the async Tailwind API.
|
|
1254
|
-
*
|
|
1321
|
+
*
|
|
1322
|
+
* Supports multiple design systems: each unique CSS entry point gets its own cache.
|
|
1323
|
+
* In monorepos, files in different packages auto-detect to different entry points
|
|
1324
|
+
* and each gets the correct DS.
|
|
1255
1325
|
*
|
|
1256
1326
|
* Resolution order: rule option `entryPoint` > `settings.tailwindcss.entryPoint` > auto-detect.
|
|
1257
1327
|
*/
|
|
1258
1328
|
function getLoadedDesignSystem(entryPoint, settings, filePath) {
|
|
1259
|
-
const cssPath = entryPoint ?? entryPointFromSettings(settings) ??
|
|
1329
|
+
const cssPath = entryPoint ?? entryPointFromSettings(settings) ?? cachedAutoDetect(filePath) ?? lastLoadedPath;
|
|
1260
1330
|
if (!cssPath) return null;
|
|
1261
1331
|
const resolvedPath = (0, node_path.resolve)(cssPath);
|
|
1262
1332
|
try {
|
|
1263
1333
|
const mtime = (0, node_fs.statSync)(resolvedPath).mtimeMs;
|
|
1264
|
-
|
|
1265
|
-
|
|
1334
|
+
const cached = dsCache.get(resolvedPath);
|
|
1335
|
+
if (cached && cached.mtime === mtime) return {
|
|
1336
|
+
cache: cached.cache,
|
|
1266
1337
|
entryPoint: resolvedPath
|
|
1267
1338
|
};
|
|
1268
|
-
const data = loadDesignSystemSync(resolvedPath);
|
|
1339
|
+
const data = loadDesignSystemSync(resolvedPath, timeoutFromSettings(settings));
|
|
1269
1340
|
if (!data) return null;
|
|
1270
1341
|
const cache = DesignSystemCache.fromPrecomputed(data);
|
|
1271
|
-
|
|
1342
|
+
dsCache.set(resolvedPath, {
|
|
1272
1343
|
cache,
|
|
1273
|
-
path: resolvedPath,
|
|
1274
1344
|
mtime
|
|
1275
|
-
};
|
|
1345
|
+
});
|
|
1346
|
+
lastLoadedPath = resolvedPath;
|
|
1276
1347
|
return {
|
|
1277
1348
|
cache,
|
|
1278
1349
|
entryPoint: resolvedPath
|
|
@@ -1282,17 +1353,21 @@ function getLoadedDesignSystem(entryPoint, settings, filePath) {
|
|
|
1282
1353
|
}
|
|
1283
1354
|
}
|
|
1284
1355
|
/**
|
|
1285
|
-
* Creates a lazy DS loader that
|
|
1356
|
+
* Creates a lazy DS loader that resolves the correct design system per file.
|
|
1286
1357
|
*
|
|
1287
1358
|
* In `createOnce`, `context.settings` and `context.filename` throw. When visitors
|
|
1288
|
-
* run, they become available.
|
|
1289
|
-
*
|
|
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.
|
|
1290
1364
|
*/
|
|
1291
1365
|
function createLazyLoader(context) {
|
|
1292
|
-
let result = null;
|
|
1293
1366
|
let lastFilePath;
|
|
1367
|
+
let lastResult = null;
|
|
1368
|
+
let fixedEntryResolved = false;
|
|
1369
|
+
let fixedResult = null;
|
|
1294
1370
|
return () => {
|
|
1295
|
-
if (result) return result;
|
|
1296
1371
|
let entryPoint;
|
|
1297
1372
|
try {
|
|
1298
1373
|
entryPoint = (context.options?.[0])?.entryPoint;
|
|
@@ -1305,10 +1380,17 @@ function createLazyLoader(context) {
|
|
|
1305
1380
|
try {
|
|
1306
1381
|
filePath = context.filename;
|
|
1307
1382
|
} catch {}
|
|
1308
|
-
|
|
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;
|
|
1309
1391
|
if (filePath) lastFilePath = filePath;
|
|
1310
|
-
|
|
1311
|
-
return
|
|
1392
|
+
lastResult = getLoadedDesignSystem(void 0, settings, filePath);
|
|
1393
|
+
return lastResult;
|
|
1312
1394
|
};
|
|
1313
1395
|
}
|
|
1314
1396
|
//#endregion
|
|
@@ -1737,9 +1819,19 @@ let lengthView = null;
|
|
|
1737
1819
|
let dataArea = null;
|
|
1738
1820
|
let initialized = false;
|
|
1739
1821
|
let available = true;
|
|
1822
|
+
let currentCssPath = null;
|
|
1740
1823
|
function ensureService(cssPath) {
|
|
1741
|
-
if (initialized) return available;
|
|
1824
|
+
if (initialized && currentCssPath === cssPath) return available;
|
|
1825
|
+
if (initialized) {
|
|
1826
|
+
cleanup();
|
|
1827
|
+
initialized = false;
|
|
1828
|
+
available = true;
|
|
1829
|
+
controlArray = null;
|
|
1830
|
+
lengthView = null;
|
|
1831
|
+
dataArea = null;
|
|
1832
|
+
}
|
|
1742
1833
|
initialized = true;
|
|
1834
|
+
currentCssPath = cssPath;
|
|
1743
1835
|
try {
|
|
1744
1836
|
const tailwindNodePath = require.resolve("@tailwindcss/node");
|
|
1745
1837
|
const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE);
|
package/dist/index.mjs
CHANGED
|
@@ -876,6 +876,10 @@ async function main() {
|
|
|
876
876
|
const entries = ds.getClassList();
|
|
877
877
|
const classNames = entries.map(e => e[0]);
|
|
878
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
|
+
|
|
879
883
|
// Validity: which classes produce CSS
|
|
880
884
|
const cssResults = ds.candidatesToCss(classNames);
|
|
881
885
|
const validClasses = classNames.filter((_, i) => cssResults[i] != null);
|
|
@@ -937,7 +941,7 @@ async function main() {
|
|
|
937
941
|
// Sort order — include extra candidates so bare utilities (rounded, blur, etc.) get order
|
|
938
942
|
const allForOrder = [...classNames];
|
|
939
943
|
for (const cls of validClasses) {
|
|
940
|
-
if (!
|
|
944
|
+
if (!classNameIndex.has(cls)) allForOrder.push(cls);
|
|
941
945
|
}
|
|
942
946
|
const order = {};
|
|
943
947
|
const orderResults = ds.getClassOrder(allForOrder);
|
|
@@ -1067,7 +1071,8 @@ async function main() {
|
|
|
1067
1071
|
const candidates = [];
|
|
1068
1072
|
for (const cls of validClasses) {
|
|
1069
1073
|
if (cls.includes('[') || cls.includes('/')) continue;
|
|
1070
|
-
const idx =
|
|
1074
|
+
const idx = classNameIndex.get(cls);
|
|
1075
|
+
if (idx === undefined) continue;
|
|
1071
1076
|
const cssText = cssResults[idx];
|
|
1072
1077
|
if (!cssText) continue;
|
|
1073
1078
|
const pvMatch = cssText.match(/^\\s+([\\w-]+)\\s*:\\s*(.+?)\\s*;?\\s*$/m);
|
|
@@ -1100,21 +1105,61 @@ async function main() {
|
|
|
1100
1105
|
main().catch(e => { process.stderr.write(e.message); process.exit(1); });
|
|
1101
1106
|
`;
|
|
1102
1107
|
const CACHE_DIR = join(tmpdir(), "oxlint-tailwindcss");
|
|
1103
|
-
const CACHE_VERSION =
|
|
1104
|
-
|
|
1105
|
-
|
|
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 join(CACHE_DIR, `${createHash("md5").update(`v${CACHE_VERSION}:${cssPath}:${mtime}`).digest("hex")}.idx`);
|
|
1106
1120
|
}
|
|
1107
|
-
function
|
|
1121
|
+
function computeContentHash(content) {
|
|
1122
|
+
return createHash("md5").update(`v${CACHE_VERSION}:${content}`).digest("hex");
|
|
1123
|
+
}
|
|
1124
|
+
function getContentCachePath(contentHash) {
|
|
1125
|
+
return join(CACHE_DIR, `${contentHash}.json`);
|
|
1126
|
+
}
|
|
1127
|
+
function tryReadCache(cachePath) {
|
|
1128
|
+
try {
|
|
1129
|
+
return JSON.parse(readFileSync(cachePath, "utf-8"));
|
|
1130
|
+
} catch {
|
|
1131
|
+
return null;
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
function writeCacheFiles(contentCachePath, mtimeIndexPath, contentHash, data) {
|
|
1135
|
+
try {
|
|
1136
|
+
mkdirSync(CACHE_DIR, { recursive: true });
|
|
1137
|
+
writeFileSync(contentCachePath, data);
|
|
1138
|
+
writeFileSync(mtimeIndexPath, contentHash);
|
|
1139
|
+
} catch {}
|
|
1140
|
+
}
|
|
1141
|
+
function loadDesignSystemSync(cssPath, timeout) {
|
|
1108
1142
|
const resolvedPath = resolve(cssPath);
|
|
1109
1143
|
try {
|
|
1110
1144
|
const mtime = statSync(resolvedPath).mtimeMs;
|
|
1111
|
-
const
|
|
1112
|
-
if (existsSync(
|
|
1113
|
-
|
|
1145
|
+
const mtimeIndexPath = getMtimeIndexPath(resolvedPath, mtime);
|
|
1146
|
+
if (existsSync(mtimeIndexPath)) try {
|
|
1147
|
+
const cached = tryReadCache(getContentCachePath(readFileSync(mtimeIndexPath, "utf-8").trim()));
|
|
1148
|
+
if (cached) return cached;
|
|
1114
1149
|
} catch {}
|
|
1150
|
+
const contentHash = computeContentHash(readFileSync(resolvedPath, "utf-8"));
|
|
1151
|
+
const contentCachePath = getContentCachePath(contentHash);
|
|
1152
|
+
const cached = tryReadCache(contentCachePath);
|
|
1153
|
+
if (cached) {
|
|
1154
|
+
try {
|
|
1155
|
+
mkdirSync(CACHE_DIR, { recursive: true });
|
|
1156
|
+
writeFileSync(mtimeIndexPath, contentHash);
|
|
1157
|
+
} catch {}
|
|
1158
|
+
return cached;
|
|
1159
|
+
}
|
|
1115
1160
|
const stdout = execFileSync(process.execPath, ["-e", PRECOMPUTE_SCRIPT], {
|
|
1116
1161
|
encoding: "utf-8",
|
|
1117
|
-
timeout: 3e4,
|
|
1162
|
+
timeout: timeout ?? 3e4,
|
|
1118
1163
|
maxBuffer: 50 * 1024 * 1024,
|
|
1119
1164
|
env: {
|
|
1120
1165
|
...process.env,
|
|
@@ -1122,10 +1167,7 @@ function loadDesignSystemSync(cssPath) {
|
|
|
1122
1167
|
},
|
|
1123
1168
|
cwd: dirname(resolvedPath)
|
|
1124
1169
|
});
|
|
1125
|
-
|
|
1126
|
-
mkdirSync(CACHE_DIR, { recursive: true });
|
|
1127
|
-
writeFileSync(cachePath, stdout);
|
|
1128
|
-
} catch {}
|
|
1170
|
+
writeCacheFiles(contentCachePath, mtimeIndexPath, contentHash, stdout);
|
|
1129
1171
|
return JSON.parse(stdout);
|
|
1130
1172
|
} catch (error) {
|
|
1131
1173
|
console.error(`[oxlint-tailwindcss] Failed to load design system from "${resolvedPath}":`, error instanceof Error ? error.message : error);
|
|
@@ -1241,7 +1283,9 @@ function autoDetectEntryPoint(filePath) {
|
|
|
1241
1283
|
}
|
|
1242
1284
|
//#endregion
|
|
1243
1285
|
//#region src/design-system/loader.ts
|
|
1244
|
-
|
|
1286
|
+
const dsCache = /* @__PURE__ */ new Map();
|
|
1287
|
+
const autoDetectCache = /* @__PURE__ */ new Map();
|
|
1288
|
+
let lastLoadedPath = null;
|
|
1245
1289
|
/**
|
|
1246
1290
|
* Extracts `entryPoint` from `context.settings.tailwindcss`.
|
|
1247
1291
|
*/
|
|
@@ -1253,30 +1297,57 @@ function entryPointFromSettings(settings) {
|
|
|
1253
1297
|
}
|
|
1254
1298
|
}
|
|
1255
1299
|
/**
|
|
1300
|
+
* Extracts `timeout` from `context.settings.tailwindcss`.
|
|
1301
|
+
*/
|
|
1302
|
+
function timeoutFromSettings(settings) {
|
|
1303
|
+
const tw = settings?.tailwindcss;
|
|
1304
|
+
if (tw && typeof tw === "object" && "timeout" in tw) {
|
|
1305
|
+
const t = tw.timeout;
|
|
1306
|
+
if (typeof t === "number" && t > 0) return t;
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
/**
|
|
1310
|
+
* Cached auto-detect: caches by directory since all files in the same directory
|
|
1311
|
+
* resolve to the same entry point. Avoids repeated filesystem walks.
|
|
1312
|
+
*/
|
|
1313
|
+
function cachedAutoDetect(filePath) {
|
|
1314
|
+
if (!filePath) return autoDetectEntryPoint(filePath);
|
|
1315
|
+
const dir = dirname(resolve(filePath));
|
|
1316
|
+
const cached = autoDetectCache.get(dir);
|
|
1317
|
+
if (cached !== void 0) return cached;
|
|
1318
|
+
const result = autoDetectEntryPoint(filePath);
|
|
1319
|
+
autoDetectCache.set(dir, result);
|
|
1320
|
+
return result;
|
|
1321
|
+
}
|
|
1322
|
+
/**
|
|
1256
1323
|
* Returns the design system cache, loading synchronously on first call.
|
|
1257
1324
|
* Uses execFileSync internally to bridge the async Tailwind API.
|
|
1258
|
-
*
|
|
1325
|
+
*
|
|
1326
|
+
* Supports multiple design systems: each unique CSS entry point gets its own cache.
|
|
1327
|
+
* In monorepos, files in different packages auto-detect to different entry points
|
|
1328
|
+
* and each gets the correct DS.
|
|
1259
1329
|
*
|
|
1260
1330
|
* Resolution order: rule option `entryPoint` > `settings.tailwindcss.entryPoint` > auto-detect.
|
|
1261
1331
|
*/
|
|
1262
1332
|
function getLoadedDesignSystem(entryPoint, settings, filePath) {
|
|
1263
|
-
const cssPath = entryPoint ?? entryPointFromSettings(settings) ??
|
|
1333
|
+
const cssPath = entryPoint ?? entryPointFromSettings(settings) ?? cachedAutoDetect(filePath) ?? lastLoadedPath;
|
|
1264
1334
|
if (!cssPath) return null;
|
|
1265
1335
|
const resolvedPath = resolve(cssPath);
|
|
1266
1336
|
try {
|
|
1267
1337
|
const mtime = statSync(resolvedPath).mtimeMs;
|
|
1268
|
-
|
|
1269
|
-
|
|
1338
|
+
const cached = dsCache.get(resolvedPath);
|
|
1339
|
+
if (cached && cached.mtime === mtime) return {
|
|
1340
|
+
cache: cached.cache,
|
|
1270
1341
|
entryPoint: resolvedPath
|
|
1271
1342
|
};
|
|
1272
|
-
const data = loadDesignSystemSync(resolvedPath);
|
|
1343
|
+
const data = loadDesignSystemSync(resolvedPath, timeoutFromSettings(settings));
|
|
1273
1344
|
if (!data) return null;
|
|
1274
1345
|
const cache = DesignSystemCache.fromPrecomputed(data);
|
|
1275
|
-
|
|
1346
|
+
dsCache.set(resolvedPath, {
|
|
1276
1347
|
cache,
|
|
1277
|
-
path: resolvedPath,
|
|
1278
1348
|
mtime
|
|
1279
|
-
};
|
|
1349
|
+
});
|
|
1350
|
+
lastLoadedPath = resolvedPath;
|
|
1280
1351
|
return {
|
|
1281
1352
|
cache,
|
|
1282
1353
|
entryPoint: resolvedPath
|
|
@@ -1286,17 +1357,21 @@ function getLoadedDesignSystem(entryPoint, settings, filePath) {
|
|
|
1286
1357
|
}
|
|
1287
1358
|
}
|
|
1288
1359
|
/**
|
|
1289
|
-
* Creates a lazy DS loader that
|
|
1360
|
+
* Creates a lazy DS loader that resolves the correct design system per file.
|
|
1290
1361
|
*
|
|
1291
1362
|
* In `createOnce`, `context.settings` and `context.filename` throw. When visitors
|
|
1292
|
-
* run, they become available.
|
|
1293
|
-
*
|
|
1363
|
+
* run, they become available. The loader re-resolves when the filename changes,
|
|
1364
|
+
* supporting monorepos where different files need different design systems.
|
|
1365
|
+
*
|
|
1366
|
+
* When a fixed entryPoint is provided (rule option or settings), it's used for all
|
|
1367
|
+
* files and cached after first resolution.
|
|
1294
1368
|
*/
|
|
1295
1369
|
function createLazyLoader(context) {
|
|
1296
|
-
let result = null;
|
|
1297
1370
|
let lastFilePath;
|
|
1371
|
+
let lastResult = null;
|
|
1372
|
+
let fixedEntryResolved = false;
|
|
1373
|
+
let fixedResult = null;
|
|
1298
1374
|
return () => {
|
|
1299
|
-
if (result) return result;
|
|
1300
1375
|
let entryPoint;
|
|
1301
1376
|
try {
|
|
1302
1377
|
entryPoint = (context.options?.[0])?.entryPoint;
|
|
@@ -1309,10 +1384,17 @@ function createLazyLoader(context) {
|
|
|
1309
1384
|
try {
|
|
1310
1385
|
filePath = context.filename;
|
|
1311
1386
|
} catch {}
|
|
1312
|
-
|
|
1387
|
+
const fixedEntry = entryPoint ?? entryPointFromSettings(settings);
|
|
1388
|
+
if (fixedEntry) {
|
|
1389
|
+
if (fixedEntryResolved) return fixedResult;
|
|
1390
|
+
fixedEntryResolved = true;
|
|
1391
|
+
fixedResult = getLoadedDesignSystem(fixedEntry, settings, filePath);
|
|
1392
|
+
return fixedResult;
|
|
1393
|
+
}
|
|
1394
|
+
if (filePath && filePath === lastFilePath) return lastResult;
|
|
1313
1395
|
if (filePath) lastFilePath = filePath;
|
|
1314
|
-
|
|
1315
|
-
return
|
|
1396
|
+
lastResult = getLoadedDesignSystem(void 0, settings, filePath);
|
|
1397
|
+
return lastResult;
|
|
1316
1398
|
};
|
|
1317
1399
|
}
|
|
1318
1400
|
//#endregion
|
|
@@ -1741,9 +1823,19 @@ let lengthView = null;
|
|
|
1741
1823
|
let dataArea = null;
|
|
1742
1824
|
let initialized = false;
|
|
1743
1825
|
let available = true;
|
|
1826
|
+
let currentCssPath = null;
|
|
1744
1827
|
function ensureService(cssPath) {
|
|
1745
|
-
if (initialized) return available;
|
|
1828
|
+
if (initialized && currentCssPath === cssPath) return available;
|
|
1829
|
+
if (initialized) {
|
|
1830
|
+
cleanup();
|
|
1831
|
+
initialized = false;
|
|
1832
|
+
available = true;
|
|
1833
|
+
controlArray = null;
|
|
1834
|
+
lengthView = null;
|
|
1835
|
+
dataArea = null;
|
|
1836
|
+
}
|
|
1746
1837
|
initialized = true;
|
|
1838
|
+
currentCssPath = cssPath;
|
|
1747
1839
|
try {
|
|
1748
1840
|
const tailwindNodePath = __require.resolve("@tailwindcss/node");
|
|
1749
1841
|
const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE);
|