oxlint-tailwindcss 1.8.0 → 1.9.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 +12 -9
- package/dist/index.cjs +354 -45
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +355 -46
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -18,8 +18,11 @@ Read the story behind this plugin:
|
|
|
18
18
|
per package. Both fully deterministic.
|
|
19
19
|
- **Coexists with oxfmt and Prettier** — Point all tools at the same CSS and they agree
|
|
20
20
|
byte-for-byte. See the [interop guide](https://oxlint-tailwindcss.pages.dev/interop).
|
|
21
|
-
- **Tailwind CSS v4
|
|
22
|
-
your shadcn variables, your typography plugin.
|
|
21
|
+
- **Tailwind CSS v4.1+** — Designed for v4 from day one. Reads your `@theme { ... }` custom tokens,
|
|
22
|
+
your shadcn variables, your typography plugin. It loads _your_ project's Tailwind engine, resolved
|
|
23
|
+
per entry point, so the linter and your build agree; an engine older than v4.1, a future major, or
|
|
24
|
+
a major-version drift from your build fails loud (opt back in with
|
|
25
|
+
`settings.tailwindcss.allowUntestedEngine`).
|
|
23
26
|
- **Fail loud** — Misconfiguration surfaces as a single `designSystemUnavailable` diagnostic with an
|
|
24
27
|
actionable hint. Never silently skipped rules.
|
|
25
28
|
- **Fast** — Native oxlint plugin with per-entry-point caching and content-hash disk cache for
|
|
@@ -987,15 +990,15 @@ the box. If you find one that doesn't, open an issue.
|
|
|
987
990
|
## Requirements
|
|
988
991
|
|
|
989
992
|
- Node.js >= 20
|
|
990
|
-
- Tailwind CSS v4
|
|
993
|
+
- Tailwind CSS v4.1 or newer (4.0.x is not supported — it predates a design-system API the plugin
|
|
994
|
+
needs, and is reported with a clear diagnostic)
|
|
991
995
|
- oxlint >= 1.43.0
|
|
992
996
|
|
|
993
|
-
> **oxlint 1.77.0
|
|
994
|
-
>
|
|
995
|
-
>
|
|
996
|
-
>
|
|
997
|
-
> (
|
|
998
|
-
> unaffected, so CI is fine; if you use the editor extension, pin `oxlint@1.76.0` for now.
|
|
997
|
+
> **Avoid oxlint 1.77.0 with the editor extension.** 1.77.0 panics the oxlint **language server** on
|
|
998
|
+
> any diagnostic from any JS plugin (`disable_fix.rs:52`, then SIGABRT and a restart loop). It's an
|
|
999
|
+
> oxlint bug, not a plugin one, and the CLI is unaffected (CI is fine). It's **fixed in oxlint
|
|
1000
|
+
> 1.78.0** ([oxc#25280](https://github.com/oxc-project/oxc/pull/25280)) — upgrade to `oxlint@1.78.0`
|
|
1001
|
+
> or newer (or stay on `1.76.0`) if you use the editor extension.
|
|
999
1002
|
|
|
1000
1003
|
## License
|
|
1001
1004
|
|
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@ let node_crypto = require("node:crypto");
|
|
|
3
3
|
let node_fs = require("node:fs");
|
|
4
4
|
let node_path = require("node:path");
|
|
5
5
|
let node_os = require("node:os");
|
|
6
|
-
//#region ../../node_modules/.pnpm/@oxlint+plugins@1.
|
|
6
|
+
//#region ../../node_modules/.pnpm/@oxlint+plugins@1.78.0/node_modules/@oxlint/plugins/index.js
|
|
7
7
|
/**
|
|
8
8
|
* Define a plugin.
|
|
9
9
|
*
|
|
@@ -1577,6 +1577,14 @@ var DeprecatedEntryPointShapeError = class extends OxlintTailwindError {};
|
|
|
1577
1577
|
var DesignSystemLoadError = class extends OxlintTailwindError {};
|
|
1578
1578
|
/** The sort or canonicalize worker thread failed to initialize or timed out. */
|
|
1579
1579
|
var SortServiceError = class extends OxlintTailwindError {};
|
|
1580
|
+
/**
|
|
1581
|
+
* The resolved Tailwind engine version is outside the range this plugin
|
|
1582
|
+
* supports: older than v4, a future major (v5+) the plugin was not built for,
|
|
1583
|
+
* or a major-version drift from the version the consumer's build compiles
|
|
1584
|
+
* with. Fail-loud rather than lint against semantics that don't match the
|
|
1585
|
+
* build. See `design-system/engine-guard.ts` for the decision table.
|
|
1586
|
+
*/
|
|
1587
|
+
var UnsupportedEngineError = class extends OxlintTailwindError {};
|
|
1580
1588
|
/** Type-guard: did this error originate from the plugin's fail-loud infrastructure? */
|
|
1581
1589
|
function isFatalError(err) {
|
|
1582
1590
|
return err instanceof OxlintTailwindError;
|
|
@@ -1647,28 +1655,54 @@ function softGetDS(getDS) {
|
|
|
1647
1655
|
//#endregion
|
|
1648
1656
|
//#region src/design-system/tailwind-node.ts
|
|
1649
1657
|
/**
|
|
1650
|
-
*
|
|
1651
|
-
*
|
|
1652
|
-
*
|
|
1653
|
-
* — this module resolves once at load and exposes the results.
|
|
1658
|
+
* Resolves the Tailwind engine (`@tailwindcss/node`) the plugin runs against.
|
|
1659
|
+
*
|
|
1660
|
+
* Two layers:
|
|
1654
1661
|
*
|
|
1655
|
-
*
|
|
1656
|
-
*
|
|
1662
|
+
* 1. **Bundled fallback** — `TAILWIND_NODE_PATH` / `TAILWIND_NODE_VERSION`,
|
|
1663
|
+
* resolved ONCE at module load from the plugin's own location. This is the
|
|
1664
|
+
* copy shipped as a dependency; used only when the consumer's engine can't
|
|
1665
|
+
* be found.
|
|
1666
|
+
* 2. **Per-entry-point resolution** — `resolveTailwindNodeFor(cssPath)`
|
|
1667
|
+
* resolves the engine from the CONSUMER's project (the `node_modules` around
|
|
1668
|
+
* the resolved CSS entry point), so the linter analyzes with the same
|
|
1669
|
+
* Tailwind the build compiles with (issue #114). Memoized per CSS directory;
|
|
1670
|
+
* a pure function of the on-disk module topology, so every layer
|
|
1671
|
+
* (precompute, live worker services, disk-cache key) that is handed the same
|
|
1672
|
+
* `cssPath` independently agrees on the same engine — no cross-layer
|
|
1673
|
+
* threading required.
|
|
1674
|
+
*
|
|
1675
|
+
* Versions are read from the resolved entry's `package.json` (walk-up
|
|
1676
|
+
* fallback for unconventional layouts).
|
|
1657
1677
|
*/
|
|
1658
|
-
function
|
|
1678
|
+
function tryResolveFrom(specifier, fromDir) {
|
|
1659
1679
|
try {
|
|
1660
|
-
return require.resolve(
|
|
1680
|
+
return require.resolve(specifier, { paths: [fromDir] });
|
|
1661
1681
|
} catch {
|
|
1662
1682
|
return null;
|
|
1663
1683
|
}
|
|
1664
1684
|
}
|
|
1665
|
-
function
|
|
1685
|
+
function realpathOr(p) {
|
|
1686
|
+
try {
|
|
1687
|
+
return (0, node_fs.realpathSync)(p);
|
|
1688
|
+
} catch {
|
|
1689
|
+
return p;
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
/**
|
|
1693
|
+
* Read the `version` from the `package.json` for `name`, starting at
|
|
1694
|
+
* `dirname(entryPath)` and walking up a few levels (packages ship their entry
|
|
1695
|
+
* as `dist/index.{cjs,mjs}` next to the `package.json`, but layouts vary).
|
|
1696
|
+
* The `pkg.name === name` guard backstops a wrong `package.json` found mid-walk
|
|
1697
|
+
* (e.g. through a pnpm symlink). Returns `'unknown'` if nothing matches.
|
|
1698
|
+
*/
|
|
1699
|
+
function readVersionFromEntry(entryPath, name) {
|
|
1666
1700
|
let dir = (0, node_path.dirname)(entryPath);
|
|
1667
1701
|
for (let i = 0; i < 5; i++) {
|
|
1668
1702
|
const pkgJson = (0, node_path.join)(dir, "package.json");
|
|
1669
1703
|
if ((0, node_fs.existsSync)(pkgJson)) try {
|
|
1670
1704
|
const pkg = JSON.parse((0, node_fs.readFileSync)(pkgJson, "utf-8"));
|
|
1671
|
-
if (pkg.name ===
|
|
1705
|
+
if (pkg.name === name && pkg.version) return pkg.version;
|
|
1672
1706
|
} catch {}
|
|
1673
1707
|
const parent = (0, node_path.dirname)(dir);
|
|
1674
1708
|
if (parent === dir) break;
|
|
@@ -1676,21 +1710,93 @@ function readVersionFromEntry(entryPath) {
|
|
|
1676
1710
|
}
|
|
1677
1711
|
return "unknown";
|
|
1678
1712
|
}
|
|
1679
|
-
const
|
|
1713
|
+
const bundledEntry = resolveBundledEntry();
|
|
1714
|
+
function resolveBundledEntry() {
|
|
1715
|
+
try {
|
|
1716
|
+
return require.resolve("@tailwindcss/node");
|
|
1717
|
+
} catch {
|
|
1718
|
+
return null;
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
/**
|
|
1722
|
+
* Absolute entry of the plugin's own bundled `@tailwindcss/node`, or `null`
|
|
1723
|
+
* if not installed. Used as the last-resort fallback by
|
|
1724
|
+
* `resolveTailwindNodeFor` and passed to workers, which resolve the bare
|
|
1725
|
+
* specifier from a tmp-dir `eval` context (where it would otherwise fail).
|
|
1726
|
+
*/
|
|
1727
|
+
const TAILWIND_NODE_PATH = bundledEntry;
|
|
1680
1728
|
/**
|
|
1681
|
-
*
|
|
1682
|
-
*
|
|
1683
|
-
*
|
|
1684
|
-
* context (with cwd inside a tmp dir or under pnpm strict workspaces) can
|
|
1685
|
-
* fail to find the bare specifier.
|
|
1729
|
+
* Installed version of the plugin's bundled `@tailwindcss/node`, or
|
|
1730
|
+
* `'unknown'`. This is the version the plugin was built and tested against;
|
|
1731
|
+
* `engine-guard` uses it as the "tested ceiling".
|
|
1686
1732
|
*/
|
|
1687
|
-
const
|
|
1733
|
+
const TAILWIND_NODE_VERSION = bundledEntry !== null ? readVersionFromEntry(bundledEntry, "@tailwindcss/node") : "unknown";
|
|
1734
|
+
const BUILD_TOOL_SPECIFIERS = [
|
|
1735
|
+
"@tailwindcss/postcss",
|
|
1736
|
+
"@tailwindcss/vite",
|
|
1737
|
+
"@tailwindcss/cli"
|
|
1738
|
+
];
|
|
1739
|
+
/**
|
|
1740
|
+
* The real directories of the consumer's Tailwind build tools, resolved from
|
|
1741
|
+
* the CSS dir. Under pnpm's strict layout `@tailwindcss/node` is only a
|
|
1742
|
+
* transitive dep (not symlinked into the package's `node_modules`), so it is
|
|
1743
|
+
* unreachable from the CSS dir directly — but it IS reachable from the build
|
|
1744
|
+
* tool's own real directory. `realpathSync` follows the pnpm symlink to the
|
|
1745
|
+
* virtual store before we resolve `@tailwindcss/node` relative to it.
|
|
1746
|
+
*/
|
|
1747
|
+
function buildToolAnchorDirs(cssDir) {
|
|
1748
|
+
const dirs = [];
|
|
1749
|
+
for (const spec of BUILD_TOOL_SPECIFIERS) {
|
|
1750
|
+
const entry = tryResolveFrom(spec, cssDir);
|
|
1751
|
+
if (entry) dirs.push((0, node_path.dirname)(realpathOr(entry)));
|
|
1752
|
+
}
|
|
1753
|
+
return dirs;
|
|
1754
|
+
}
|
|
1755
|
+
const resolutionCache = /* @__PURE__ */ new Map();
|
|
1688
1756
|
/**
|
|
1689
|
-
*
|
|
1690
|
-
*
|
|
1691
|
-
*
|
|
1757
|
+
* Resolve the Tailwind engine to run for a given resolved CSS entry point,
|
|
1758
|
+
* anchored on the consumer's project. Memoized per CSS directory.
|
|
1759
|
+
*
|
|
1760
|
+
* Cascade:
|
|
1761
|
+
* 1. `buildVersion` (B) — the consumer's `tailwindcss` resolved from the CSS
|
|
1762
|
+
* dir. Always a direct dep, so it resolves under npm (hoisted) and pnpm
|
|
1763
|
+
* (symlinked into the package). `'unknown'` if the project has no Tailwind.
|
|
1764
|
+
* 2. `nodePath` (E) — the first `@tailwindcss/node` resolvable from
|
|
1765
|
+
* `[cssDir, ...buildToolAnchorDirs]`, preferring the copy whose version
|
|
1766
|
+
* equals `buildVersion` so a hoisted plugin copy can't shadow the
|
|
1767
|
+
* consumer's engine (R2). Falls back to the bundled copy.
|
|
1768
|
+
*
|
|
1769
|
+
* Never throws; degrades to `'unknown'` / bundled so the version guard (not
|
|
1770
|
+
* this function) owns the fail-loud decision.
|
|
1692
1771
|
*/
|
|
1693
|
-
|
|
1772
|
+
function resolveTailwindNodeFor(cssPath) {
|
|
1773
|
+
const cssDir = (0, node_path.dirname)((0, node_path.resolve)(cssPath));
|
|
1774
|
+
const cached = resolutionCache.get(cssDir);
|
|
1775
|
+
if (cached) return cached;
|
|
1776
|
+
const twEntry = tryResolveFrom("tailwindcss", cssDir);
|
|
1777
|
+
const buildVersion = twEntry ? readVersionFromEntry(twEntry, "tailwindcss") : "unknown";
|
|
1778
|
+
const candidates = [];
|
|
1779
|
+
for (const dir of [cssDir, ...buildToolAnchorDirs(cssDir)]) {
|
|
1780
|
+
const found = tryResolveFrom("@tailwindcss/node", dir);
|
|
1781
|
+
if (!found) continue;
|
|
1782
|
+
const real = realpathOr(found);
|
|
1783
|
+
if (!candidates.includes(real)) candidates.push(real);
|
|
1784
|
+
}
|
|
1785
|
+
let nodePath = null;
|
|
1786
|
+
if (buildVersion !== "unknown") nodePath = candidates.find((c) => readVersionFromEntry(c, "@tailwindcss/node") === buildVersion) ?? null;
|
|
1787
|
+
if (nodePath === null) nodePath = candidates[0] ?? null;
|
|
1788
|
+
if (nodePath === null) nodePath = TAILWIND_NODE_PATH;
|
|
1789
|
+
const usedBundled = nodePath !== null && TAILWIND_NODE_PATH !== null && realpathOr(nodePath) === realpathOr(TAILWIND_NODE_PATH);
|
|
1790
|
+
const nodeVersion = nodePath !== null ? readVersionFromEntry(realpathOr(nodePath), "@tailwindcss/node") : "unknown";
|
|
1791
|
+
const result = {
|
|
1792
|
+
nodePath,
|
|
1793
|
+
nodeVersion,
|
|
1794
|
+
buildVersion,
|
|
1795
|
+
usedBundled
|
|
1796
|
+
};
|
|
1797
|
+
resolutionCache.set(cssDir, result);
|
|
1798
|
+
return result;
|
|
1799
|
+
}
|
|
1694
1800
|
//#endregion
|
|
1695
1801
|
//#region src/design-system/sync-loader.ts
|
|
1696
1802
|
/**
|
|
@@ -1718,7 +1824,7 @@ const TAILWIND_NODE_VERSION = entryPath !== null ? readVersionFromEntry(entryPat
|
|
|
1718
1824
|
* `tests/benchmarks/precompute-phases.test.ts` used to keep a hand-copied
|
|
1719
1825
|
* duplicate of the extractor that silently drifted from the real one, and it is
|
|
1720
1826
|
* interpolated (not concatenated at runtime), so its text still feeds the
|
|
1721
|
-
* `
|
|
1827
|
+
* `SCRIPT_HASH` md5 and any edit here invalidates the disk cache automatically.
|
|
1722
1828
|
*
|
|
1723
1829
|
* Exports (in the worker scope): `walkDeclarations`, `scanVarReads`,
|
|
1724
1830
|
* `isPureVarRead`.
|
|
@@ -2621,23 +2727,20 @@ function cacheDirName() {
|
|
|
2621
2727
|
}
|
|
2622
2728
|
}
|
|
2623
2729
|
const CACHE_DIR = (0, node_path.join)((0, node_os.tmpdir)(), cacheDirName());
|
|
2730
|
+
/** md5 of the precompute script (no version) — the version is folded in per entry point. */
|
|
2731
|
+
const SCRIPT_HASH = (0, node_crypto.createHash)("md5").update(PRECOMPUTE_SCRIPT).digest("hex").slice(0, 8);
|
|
2624
2732
|
/**
|
|
2625
|
-
*
|
|
2626
|
-
*
|
|
2627
|
-
*
|
|
2628
|
-
*
|
|
2629
|
-
*
|
|
2630
|
-
* tailwindcss (e.g. 4.2 → 4.3 adding `zoom-*`, `tab-*`, `scrollbar-*` etc.),
|
|
2631
|
-
* so `validClasses`, `cssProps`, `canonical`, and `arbitraryEquivalents`
|
|
2632
|
-
* reflect the installed version. @tailwindcss/node and tailwindcss are
|
|
2633
|
-
* published together, so their versions match.
|
|
2733
|
+
* The engine identifier folded into the content hash. Normally the resolved
|
|
2734
|
+
* `@tailwindcss/node` version; when that is `'unknown'` (unreadable
|
|
2735
|
+
* `package.json`) two genuinely different engines would both hash as `unknown`,
|
|
2736
|
+
* so tiebreak on the resolved path (machine-local, but the disk cache is
|
|
2737
|
+
* per-uid/per-machine anyway, and under pnpm the path encodes the version).
|
|
2634
2738
|
*/
|
|
2635
|
-
function
|
|
2636
|
-
return
|
|
2739
|
+
function engineCacheKey(res) {
|
|
2740
|
+
return res.nodeVersion === "unknown" && res.nodePath !== null ? `unknown@${res.nodePath}` : res.nodeVersion;
|
|
2637
2741
|
}
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
return (0, node_crypto.createHash)("md5").update(`${CACHE_KEY}:${content}`).digest("hex");
|
|
2742
|
+
function computeContentHash(content, engineVersion) {
|
|
2743
|
+
return (0, node_crypto.createHash)("md5").update(`${SCRIPT_HASH}:${engineVersion}:${content}`).digest("hex");
|
|
2641
2744
|
}
|
|
2642
2745
|
const IMPORT_RE = /@import\s+(?:url\(\s*)?['"]([^'"]+)['"]/g;
|
|
2643
2746
|
/**
|
|
@@ -2649,7 +2752,7 @@ const IMPORT_RE = /@import\s+(?:url\(\s*)?['"]([^'"]+)['"]/g;
|
|
|
2649
2752
|
*
|
|
2650
2753
|
* Resolves RELATIVE imports (`./`, `../`) recursively up to a small depth;
|
|
2651
2754
|
* package imports (`@import "tailwindcss"`, `tw-animate-css`) are already
|
|
2652
|
-
* covered by the
|
|
2755
|
+
* covered by the engine version folded into the content hash. Best-effort:
|
|
2653
2756
|
* an unreadable import contributes nothing (it can't affect the DS either).
|
|
2654
2757
|
*/
|
|
2655
2758
|
function hashableContent(entryPath, entryContent) {
|
|
@@ -2689,7 +2792,9 @@ function getContentCachePath(contentHash) {
|
|
|
2689
2792
|
*/
|
|
2690
2793
|
function cacheArtifactPaths(cssPath) {
|
|
2691
2794
|
const resolved = (0, node_path.resolve)(cssPath);
|
|
2692
|
-
const
|
|
2795
|
+
const content = (0, node_fs.readFileSync)(resolved, "utf-8");
|
|
2796
|
+
const res = resolveTailwindNodeFor(resolved);
|
|
2797
|
+
const hash = computeContentHash(hashableContent(resolved, content), engineCacheKey(res));
|
|
2693
2798
|
return {
|
|
2694
2799
|
json: getContentCachePath(hash),
|
|
2695
2800
|
lock: (0, node_path.join)(CACHE_DIR, `${hash}.lock`)
|
|
@@ -2899,12 +3004,13 @@ function loadDesignSystemSync(cssPath, timeout) {
|
|
|
2899
3004
|
} catch (cause) {
|
|
2900
3005
|
throw new DesignSystemLoadError(`Could not read CSS entry point: ${resolvedPath}`, "Verify the path resolves from the oxlint working directory and the file is readable.", { cause: cause instanceof Error ? cause : void 0 });
|
|
2901
3006
|
}
|
|
2902
|
-
const
|
|
3007
|
+
const engine = resolveTailwindNodeFor(resolvedPath);
|
|
3008
|
+
const contentHash = computeContentHash(hashableContent(resolvedPath, content), engineCacheKey(engine));
|
|
2903
3009
|
const contentCachePath = getContentCachePath(contentHash);
|
|
2904
3010
|
const cached = tryReadCache(contentCachePath);
|
|
2905
3011
|
if (cached) return cached;
|
|
2906
|
-
if (
|
|
2907
|
-
return computeWithLock(resolvedPath,
|
|
3012
|
+
if (engine.nodePath === null) throw new DesignSystemLoadError(`Could not resolve '@tailwindcss/node' while loading "${resolvedPath}".`, "Install '@tailwindcss/node' (or upgrade oxlint-tailwindcss) and re-run.");
|
|
3013
|
+
return computeWithLock(resolvedPath, engine.nodePath, contentHash, contentCachePath, timeout ?? 6e4);
|
|
2908
3014
|
}
|
|
2909
3015
|
//#endregion
|
|
2910
3016
|
//#region src/design-system/debug.ts
|
|
@@ -2935,6 +3041,207 @@ function debugLog(message) {
|
|
|
2935
3041
|
if (_enabled || process.env.DEBUG === "oxlint-tailwindcss") console.error(`${PREFIX} ${message}`);
|
|
2936
3042
|
}
|
|
2937
3043
|
//#endregion
|
|
3044
|
+
//#region src/design-system/engine-guard.ts
|
|
3045
|
+
/**
|
|
3046
|
+
* Version safeguards for the consumer-resolved Tailwind engine.
|
|
3047
|
+
*
|
|
3048
|
+
* Once the plugin loads the CONSUMER's Tailwind (`resolveTailwindNodeFor`),
|
|
3049
|
+
* two version facts matter per entry point:
|
|
3050
|
+
*
|
|
3051
|
+
* - `E` — the `@tailwindcss/node` version the plugin will actually run.
|
|
3052
|
+
* - `B` — the `tailwindcss` version the consumer's build compiles with.
|
|
3053
|
+
*
|
|
3054
|
+
* `assessEngine` grades `(E, B)` against the plugin's supported range and the
|
|
3055
|
+
* drift between the two, returning `ok` / `warn` / `fatal`. `emitEngineVerdict`
|
|
3056
|
+
* turns a `fatal` into an `UnsupportedEngineError` (which the fatal-reporter
|
|
3057
|
+
* routes to `designSystemUnavailable` with no per-rule `meta` change) and a
|
|
3058
|
+
* `warn` into a one-time stderr notice.
|
|
3059
|
+
*
|
|
3060
|
+
* The comparator is a hand-rolled subset of semver (no `semver` dependency —
|
|
3061
|
+
* runtime deps stay `@tailwindcss/node` + `tailwindcss` only). It is total and
|
|
3062
|
+
* never throws; unparseable input reads as "unknown".
|
|
3063
|
+
*/
|
|
3064
|
+
const WARN_PREFIX = "[oxlint-tailwindcss]";
|
|
3065
|
+
/** The lowest Tailwind major this plugin supports. */
|
|
3066
|
+
const SUPPORTED_MAJOR = 4;
|
|
3067
|
+
/**
|
|
3068
|
+
* `4.1.0`, the minimum engine version. The precompute calls
|
|
3069
|
+
* `ds.canonicalizeCandidates`, which the design system only exposes from
|
|
3070
|
+
* Tailwind 4.1 onward — on 4.0.x it throws `is not a function`, so we fail loud
|
|
3071
|
+
* with a clear message before spawning the worker. A `4.1.0-*` prerelease sorts
|
|
3072
|
+
* below it.
|
|
3073
|
+
*/
|
|
3074
|
+
const MIN_ENGINE = {
|
|
3075
|
+
major: 4,
|
|
3076
|
+
minor: 1,
|
|
3077
|
+
patch: 0,
|
|
3078
|
+
prerelease: null
|
|
3079
|
+
};
|
|
3080
|
+
/**
|
|
3081
|
+
* Parse a version string into `{ major, minor, patch, prerelease }`, or `null`
|
|
3082
|
+
* for anything unparseable (`''`, `'unknown'`, a range like `'^4.3.3'`, a dist
|
|
3083
|
+
* tag like `'next'`, non-strings). Total — never throws.
|
|
3084
|
+
*/
|
|
3085
|
+
function parseVersion(v) {
|
|
3086
|
+
if (typeof v !== "string") return null;
|
|
3087
|
+
let s = v.trim();
|
|
3088
|
+
if (s === "" || s === "unknown") return null;
|
|
3089
|
+
if (s[0] === "v" || s[0] === "V") s = s.slice(1);
|
|
3090
|
+
const plus = s.indexOf("+");
|
|
3091
|
+
if (plus !== -1) s = s.slice(0, plus);
|
|
3092
|
+
let prerelease = null;
|
|
3093
|
+
const dash = s.indexOf("-");
|
|
3094
|
+
if (dash !== -1) {
|
|
3095
|
+
prerelease = s.slice(dash + 1) || null;
|
|
3096
|
+
s = s.slice(0, dash);
|
|
3097
|
+
}
|
|
3098
|
+
const parts = s.split(".");
|
|
3099
|
+
const major = Number.parseInt(parts[0], 10);
|
|
3100
|
+
if (Number.isNaN(major)) return null;
|
|
3101
|
+
const minor = Number.parseInt(parts[1] ?? "0", 10);
|
|
3102
|
+
const patch = Number.parseInt(parts[2] ?? "0", 10);
|
|
3103
|
+
return {
|
|
3104
|
+
major,
|
|
3105
|
+
minor: Number.isNaN(minor) ? 0 : minor,
|
|
3106
|
+
patch: Number.isNaN(patch) ? 0 : patch,
|
|
3107
|
+
prerelease
|
|
3108
|
+
};
|
|
3109
|
+
}
|
|
3110
|
+
/** Compare by major, minor, patch; at equal core, a release outranks a prerelease. */
|
|
3111
|
+
function compareVersions(a, b) {
|
|
3112
|
+
if (a.major !== b.major) return a.major < b.major ? -1 : 1;
|
|
3113
|
+
if (a.minor !== b.minor) return a.minor < b.minor ? -1 : 1;
|
|
3114
|
+
if (a.patch !== b.patch) return a.patch < b.patch ? -1 : 1;
|
|
3115
|
+
if (a.prerelease === b.prerelease) return 0;
|
|
3116
|
+
if (a.prerelease === null) return 1;
|
|
3117
|
+
if (b.prerelease === null) return -1;
|
|
3118
|
+
return a.prerelease < b.prerelease ? -1 : a.prerelease > b.prerelease ? 1 : 0;
|
|
3119
|
+
}
|
|
3120
|
+
function sameMajor(a, b) {
|
|
3121
|
+
return a.major === b.major;
|
|
3122
|
+
}
|
|
3123
|
+
function sameMinor(a, b) {
|
|
3124
|
+
return a.major === b.major && a.minor === b.minor;
|
|
3125
|
+
}
|
|
3126
|
+
/**
|
|
3127
|
+
* Grade `(E, B)` against the supported range and build drift. First matching
|
|
3128
|
+
* row wins (see the decision table in the PR / plan). Pure and total: safe to
|
|
3129
|
+
* unit-test with literal version strings.
|
|
3130
|
+
*/
|
|
3131
|
+
function assessEngine(E, B, opts) {
|
|
3132
|
+
const pe = parseVersion(E);
|
|
3133
|
+
const pb = parseVersion(B);
|
|
3134
|
+
const bundled = opts.bundledVersion;
|
|
3135
|
+
if (pe === null) return {
|
|
3136
|
+
verdict: "ok",
|
|
3137
|
+
kind: "engine-version-unknown",
|
|
3138
|
+
message: "Could not determine the resolved Tailwind engine version; skipping the version guard."
|
|
3139
|
+
};
|
|
3140
|
+
if (pe.major < SUPPORTED_MAJOR || compareVersions(pe, MIN_ENGINE) < 0) return {
|
|
3141
|
+
verdict: "fatal",
|
|
3142
|
+
kind: "engine-too-old",
|
|
3143
|
+
message: `oxlint-tailwindcss requires Tailwind CSS v4.1 or newer, but the resolved engine is ${E}.`,
|
|
3144
|
+
hint: "Upgrade tailwindcss / @tailwindcss/node to v4.1+, or pin an older oxlint-tailwindcss."
|
|
3145
|
+
};
|
|
3146
|
+
if (pe.major > SUPPORTED_MAJOR) {
|
|
3147
|
+
if (opts.allowUntested) return {
|
|
3148
|
+
verdict: "warn",
|
|
3149
|
+
kind: "engine-future-major-allowed",
|
|
3150
|
+
message: `Running against untested Tailwind engine ${E} (a major newer than the tested ${bundled}) because allowUntestedEngine is set — results may be inaccurate.`
|
|
3151
|
+
};
|
|
3152
|
+
return {
|
|
3153
|
+
verdict: "fatal",
|
|
3154
|
+
kind: "engine-future-major",
|
|
3155
|
+
message: `The resolved Tailwind engine ${E} is a major version newer than this plugin was built for (tested against ${bundled}); its behavior is unverified.`,
|
|
3156
|
+
hint: "Set settings.tailwindcss.allowUntestedEngine: true to run anyway (results may be inaccurate), or upgrade oxlint-tailwindcss."
|
|
3157
|
+
};
|
|
3158
|
+
}
|
|
3159
|
+
if (pb !== null && !sameMajor(pe, pb)) {
|
|
3160
|
+
if (opts.allowUntested) return {
|
|
3161
|
+
verdict: "warn",
|
|
3162
|
+
kind: "engine-build-drift-major-allowed",
|
|
3163
|
+
message: `Linting with Tailwind engine ${E} while your build uses tailwindcss@${B} (a different major) because allowUntestedEngine is set — the plugin enforces different semantics than your build produces.`
|
|
3164
|
+
};
|
|
3165
|
+
return {
|
|
3166
|
+
verdict: "fatal",
|
|
3167
|
+
kind: "engine-build-drift-major",
|
|
3168
|
+
message: `Linting with Tailwind engine ${E} but your build uses tailwindcss@${B} (a different major); the plugin would enforce different Tailwind semantics than your build produces.`,
|
|
3169
|
+
hint: "Align the versions, or set settings.tailwindcss.allowUntestedEngine: true to override."
|
|
3170
|
+
};
|
|
3171
|
+
}
|
|
3172
|
+
if (pb !== null && !sameMinor(pe, pb)) return {
|
|
3173
|
+
verdict: "warn",
|
|
3174
|
+
kind: "engine-build-drift-minor",
|
|
3175
|
+
message: `Linting with Tailwind engine ${E} but your build uses tailwindcss@${B}; lint results may differ from your compiled CSS.`,
|
|
3176
|
+
hint: "Align the versions, or ignore if intentional."
|
|
3177
|
+
};
|
|
3178
|
+
const pBundled = parseVersion(bundled);
|
|
3179
|
+
if (pBundled !== null && compareVersions(pe, pBundled) > 0) return {
|
|
3180
|
+
verdict: "warn",
|
|
3181
|
+
kind: "engine-newer-minor",
|
|
3182
|
+
message: `The resolved Tailwind engine ${E} is newer than the version this plugin was tested against (${bundled}); newly added utilities may be reported as unknown.`,
|
|
3183
|
+
hint: "Usually safe; upgrade oxlint-tailwindcss if you see false positives."
|
|
3184
|
+
};
|
|
3185
|
+
return {
|
|
3186
|
+
verdict: "ok",
|
|
3187
|
+
kind: "ok",
|
|
3188
|
+
message: ""
|
|
3189
|
+
};
|
|
3190
|
+
}
|
|
3191
|
+
const warnedEngineKeys = /* @__PURE__ */ new Set();
|
|
3192
|
+
/**
|
|
3193
|
+
* Act on a verdict: `fatal` throws `UnsupportedEngineError` (routed to
|
|
3194
|
+
* `designSystemUnavailable`), `warn` emits a one-time stderr notice keyed by
|
|
3195
|
+
* `(entryPoint, kind, E, B)`, `ok` is silent. `debugLog` (self-gated) always
|
|
3196
|
+
* records the structured detail when debug is on.
|
|
3197
|
+
*/
|
|
3198
|
+
function emitEngineVerdict(v, ctx) {
|
|
3199
|
+
if (v.verdict === "fatal") throw new UnsupportedEngineError(v.message, v.hint);
|
|
3200
|
+
if (v.verdict === "warn") {
|
|
3201
|
+
const key = `${ctx.resolvedPath}\0${v.kind}\0${ctx.E}\0${ctx.B}`;
|
|
3202
|
+
if (!warnedEngineKeys.has(key)) {
|
|
3203
|
+
warnedEngineKeys.add(key);
|
|
3204
|
+
console.warn(`${WARN_PREFIX} ${v.message}`);
|
|
3205
|
+
}
|
|
3206
|
+
}
|
|
3207
|
+
debugLog(`engine E=${ctx.E} B=${ctx.B} → ${v.kind}`);
|
|
3208
|
+
}
|
|
3209
|
+
/**
|
|
3210
|
+
* Resolve the engine for `resolvedPath` (or use injected facts), assess it, and
|
|
3211
|
+
* emit the verdict. Throws `UnsupportedEngineError` on a fatal verdict. Called
|
|
3212
|
+
* once per entry point from `getLoadedDesignSystem`, inside its fatal-caching
|
|
3213
|
+
* `try`.
|
|
3214
|
+
*/
|
|
3215
|
+
function guardEngine(resolvedPath, allowUntested, override) {
|
|
3216
|
+
let E;
|
|
3217
|
+
let B;
|
|
3218
|
+
let bundledVersion;
|
|
3219
|
+
if (override) {
|
|
3220
|
+
E = override.E;
|
|
3221
|
+
B = override.B;
|
|
3222
|
+
bundledVersion = override.bundledVersion ?? TAILWIND_NODE_VERSION;
|
|
3223
|
+
} else {
|
|
3224
|
+
const res = resolveTailwindNodeFor(resolvedPath);
|
|
3225
|
+
E = res.nodeVersion;
|
|
3226
|
+
B = res.buildVersion;
|
|
3227
|
+
bundledVersion = TAILWIND_NODE_VERSION;
|
|
3228
|
+
}
|
|
3229
|
+
emitEngineVerdict(assessEngine(E, B, {
|
|
3230
|
+
allowUntested,
|
|
3231
|
+
bundledVersion
|
|
3232
|
+
}), {
|
|
3233
|
+
resolvedPath,
|
|
3234
|
+
E,
|
|
3235
|
+
B
|
|
3236
|
+
});
|
|
3237
|
+
}
|
|
3238
|
+
/** Read `settings.tailwindcss.allowUntestedEngine` (default `false`). */
|
|
3239
|
+
function allowUntestedEngineFromSettings(settings) {
|
|
3240
|
+
const tw = settings?.tailwindcss;
|
|
3241
|
+
if (tw && typeof tw === "object" && "allowUntestedEngine" in tw) return tw.allowUntestedEngine === true;
|
|
3242
|
+
return false;
|
|
3243
|
+
}
|
|
3244
|
+
//#endregion
|
|
2938
3245
|
//#region src/utils/context.ts
|
|
2939
3246
|
/**
|
|
2940
3247
|
* Safely read `context.options[0]`. Returns `undefined` if the getter throws
|
|
@@ -3208,7 +3515,7 @@ function timeoutFromSettings(settings) {
|
|
|
3208
3515
|
* Cached per absolute entry-point path, keyed by mtime. In monorepos each
|
|
3209
3516
|
* unique CSS gets its own cache entry.
|
|
3210
3517
|
*/
|
|
3211
|
-
function getLoadedDesignSystem(cssPath, settings) {
|
|
3518
|
+
function getLoadedDesignSystem(cssPath, settings, engineInfo) {
|
|
3212
3519
|
const resolvedPath = (0, node_path.resolve)(cssPath);
|
|
3213
3520
|
let mtime;
|
|
3214
3521
|
try {
|
|
@@ -3225,6 +3532,7 @@ function getLoadedDesignSystem(cssPath, settings) {
|
|
|
3225
3532
|
if (failed && failed.mtime === mtime) throw failed.error;
|
|
3226
3533
|
let data;
|
|
3227
3534
|
try {
|
|
3535
|
+
guardEngine(resolvedPath, allowUntestedEngineFromSettings(settings), engineInfo);
|
|
3228
3536
|
data = loadDesignSystemSync(resolvedPath, timeoutFromSettings(settings));
|
|
3229
3537
|
} catch (err) {
|
|
3230
3538
|
if (isFatalError(err)) dsFailureCache.set(resolvedPath, {
|
|
@@ -3450,7 +3758,8 @@ var DesignSystemWorker = class {
|
|
|
3450
3758
|
this.workers.set(cssPath, existing);
|
|
3451
3759
|
return existing;
|
|
3452
3760
|
}
|
|
3453
|
-
|
|
3761
|
+
const { nodePath: tailwindNodePath } = resolveTailwindNodeFor(cssPath);
|
|
3762
|
+
if (tailwindNodePath === null) throw this.remember(cssPath, new SortServiceError(`Could not resolve '@tailwindcss/node' for the ${this.opts.serviceName} worker.`, "Install '@tailwindcss/node' (or upgrade oxlint-tailwindcss) and re-run."));
|
|
3454
3763
|
const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE);
|
|
3455
3764
|
const controlArray = new Int32Array(sharedBuffer, 0, HEADER_INTS);
|
|
3456
3765
|
const lengthView = new DataView(sharedBuffer, HEADER_INTS * 4, 4);
|
|
@@ -3462,7 +3771,7 @@ var DesignSystemWorker = class {
|
|
|
3462
3771
|
workerData: {
|
|
3463
3772
|
sharedBuffer,
|
|
3464
3773
|
cssPath,
|
|
3465
|
-
tailwindNodePath
|
|
3774
|
+
tailwindNodePath
|
|
3466
3775
|
}
|
|
3467
3776
|
});
|
|
3468
3777
|
} catch (cause) {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/@oxlint+plugins@1.
|
|
1
|
+
//#region ../../node_modules/.pnpm/@oxlint+plugins@1.78.0/node_modules/@oxlint/plugins/index.d.ts
|
|
2
2
|
//#endregion
|
|
3
3
|
//#region src-js/plugins/tokens.d.ts
|
|
4
4
|
/**
|
|
@@ -1599,6 +1599,7 @@ interface TSTypePredicate extends Span {
|
|
|
1599
1599
|
parent: Node$1;
|
|
1600
1600
|
}
|
|
1601
1601
|
type TSTypePredicateName = IdentifierName | TSThisType;
|
|
1602
|
+
type TSModuleDeclarationKind = "module" | "namespace";
|
|
1602
1603
|
interface TSModuleDeclaration extends Span {
|
|
1603
1604
|
type: "TSModuleDeclaration";
|
|
1604
1605
|
id: BindingIdentifier | StringLiteral | TSQualifiedName;
|
|
@@ -1608,7 +1609,6 @@ interface TSModuleDeclaration extends Span {
|
|
|
1608
1609
|
global: false;
|
|
1609
1610
|
parent: Node$1;
|
|
1610
1611
|
}
|
|
1611
|
-
type TSModuleDeclarationKind = "module" | "namespace";
|
|
1612
1612
|
interface TSGlobalDeclaration extends Span {
|
|
1613
1613
|
type: "TSModuleDeclaration";
|
|
1614
1614
|
id: IdentifierName;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/@oxlint+plugins@1.
|
|
1
|
+
//#region ../../node_modules/.pnpm/@oxlint+plugins@1.78.0/node_modules/@oxlint/plugins/index.d.ts
|
|
2
2
|
//#endregion
|
|
3
3
|
//#region src-js/plugins/tokens.d.ts
|
|
4
4
|
/**
|
|
@@ -1599,6 +1599,7 @@ interface TSTypePredicate extends Span {
|
|
|
1599
1599
|
parent: Node$1;
|
|
1600
1600
|
}
|
|
1601
1601
|
type TSTypePredicateName = IdentifierName | TSThisType;
|
|
1602
|
+
type TSModuleDeclarationKind = "module" | "namespace";
|
|
1602
1603
|
interface TSModuleDeclaration extends Span {
|
|
1603
1604
|
type: "TSModuleDeclaration";
|
|
1604
1605
|
id: BindingIdentifier | StringLiteral | TSQualifiedName;
|
|
@@ -1608,7 +1609,6 @@ interface TSModuleDeclaration extends Span {
|
|
|
1608
1609
|
global: false;
|
|
1609
1610
|
parent: Node$1;
|
|
1610
1611
|
}
|
|
1611
|
-
type TSModuleDeclarationKind = "module" | "namespace";
|
|
1612
1612
|
interface TSGlobalDeclaration extends Span {
|
|
1613
1613
|
type: "TSModuleDeclaration";
|
|
1614
1614
|
id: IdentifierName;
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
2
|
import { Worker, threadId } from "node:worker_threads";
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
|
-
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
6
6
|
import { tmpdir, userInfo } from "node:os";
|
|
7
7
|
//#region \0rolldown/runtime.js
|
|
8
8
|
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
9
9
|
//#endregion
|
|
10
|
-
//#region ../../node_modules/.pnpm/@oxlint+plugins@1.
|
|
10
|
+
//#region ../../node_modules/.pnpm/@oxlint+plugins@1.78.0/node_modules/@oxlint/plugins/index.js
|
|
11
11
|
/**
|
|
12
12
|
* Define a plugin.
|
|
13
13
|
*
|
|
@@ -1581,6 +1581,14 @@ var DeprecatedEntryPointShapeError = class extends OxlintTailwindError {};
|
|
|
1581
1581
|
var DesignSystemLoadError = class extends OxlintTailwindError {};
|
|
1582
1582
|
/** The sort or canonicalize worker thread failed to initialize or timed out. */
|
|
1583
1583
|
var SortServiceError = class extends OxlintTailwindError {};
|
|
1584
|
+
/**
|
|
1585
|
+
* The resolved Tailwind engine version is outside the range this plugin
|
|
1586
|
+
* supports: older than v4, a future major (v5+) the plugin was not built for,
|
|
1587
|
+
* or a major-version drift from the version the consumer's build compiles
|
|
1588
|
+
* with. Fail-loud rather than lint against semantics that don't match the
|
|
1589
|
+
* build. See `design-system/engine-guard.ts` for the decision table.
|
|
1590
|
+
*/
|
|
1591
|
+
var UnsupportedEngineError = class extends OxlintTailwindError {};
|
|
1584
1592
|
/** Type-guard: did this error originate from the plugin's fail-loud infrastructure? */
|
|
1585
1593
|
function isFatalError(err) {
|
|
1586
1594
|
return err instanceof OxlintTailwindError;
|
|
@@ -1651,28 +1659,54 @@ function softGetDS(getDS) {
|
|
|
1651
1659
|
//#endregion
|
|
1652
1660
|
//#region src/design-system/tailwind-node.ts
|
|
1653
1661
|
/**
|
|
1654
|
-
*
|
|
1655
|
-
*
|
|
1656
|
-
*
|
|
1657
|
-
* — this module resolves once at load and exposes the results.
|
|
1662
|
+
* Resolves the Tailwind engine (`@tailwindcss/node`) the plugin runs against.
|
|
1663
|
+
*
|
|
1664
|
+
* Two layers:
|
|
1658
1665
|
*
|
|
1659
|
-
*
|
|
1660
|
-
*
|
|
1666
|
+
* 1. **Bundled fallback** — `TAILWIND_NODE_PATH` / `TAILWIND_NODE_VERSION`,
|
|
1667
|
+
* resolved ONCE at module load from the plugin's own location. This is the
|
|
1668
|
+
* copy shipped as a dependency; used only when the consumer's engine can't
|
|
1669
|
+
* be found.
|
|
1670
|
+
* 2. **Per-entry-point resolution** — `resolveTailwindNodeFor(cssPath)`
|
|
1671
|
+
* resolves the engine from the CONSUMER's project (the `node_modules` around
|
|
1672
|
+
* the resolved CSS entry point), so the linter analyzes with the same
|
|
1673
|
+
* Tailwind the build compiles with (issue #114). Memoized per CSS directory;
|
|
1674
|
+
* a pure function of the on-disk module topology, so every layer
|
|
1675
|
+
* (precompute, live worker services, disk-cache key) that is handed the same
|
|
1676
|
+
* `cssPath` independently agrees on the same engine — no cross-layer
|
|
1677
|
+
* threading required.
|
|
1678
|
+
*
|
|
1679
|
+
* Versions are read from the resolved entry's `package.json` (walk-up
|
|
1680
|
+
* fallback for unconventional layouts).
|
|
1661
1681
|
*/
|
|
1662
|
-
function
|
|
1682
|
+
function tryResolveFrom(specifier, fromDir) {
|
|
1663
1683
|
try {
|
|
1664
|
-
return __require.resolve(
|
|
1684
|
+
return __require.resolve(specifier, { paths: [fromDir] });
|
|
1665
1685
|
} catch {
|
|
1666
1686
|
return null;
|
|
1667
1687
|
}
|
|
1668
1688
|
}
|
|
1669
|
-
function
|
|
1689
|
+
function realpathOr(p) {
|
|
1690
|
+
try {
|
|
1691
|
+
return realpathSync(p);
|
|
1692
|
+
} catch {
|
|
1693
|
+
return p;
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
/**
|
|
1697
|
+
* Read the `version` from the `package.json` for `name`, starting at
|
|
1698
|
+
* `dirname(entryPath)` and walking up a few levels (packages ship their entry
|
|
1699
|
+
* as `dist/index.{cjs,mjs}` next to the `package.json`, but layouts vary).
|
|
1700
|
+
* The `pkg.name === name` guard backstops a wrong `package.json` found mid-walk
|
|
1701
|
+
* (e.g. through a pnpm symlink). Returns `'unknown'` if nothing matches.
|
|
1702
|
+
*/
|
|
1703
|
+
function readVersionFromEntry(entryPath, name) {
|
|
1670
1704
|
let dir = dirname(entryPath);
|
|
1671
1705
|
for (let i = 0; i < 5; i++) {
|
|
1672
1706
|
const pkgJson = join(dir, "package.json");
|
|
1673
1707
|
if (existsSync(pkgJson)) try {
|
|
1674
1708
|
const pkg = JSON.parse(readFileSync(pkgJson, "utf-8"));
|
|
1675
|
-
if (pkg.name ===
|
|
1709
|
+
if (pkg.name === name && pkg.version) return pkg.version;
|
|
1676
1710
|
} catch {}
|
|
1677
1711
|
const parent = dirname(dir);
|
|
1678
1712
|
if (parent === dir) break;
|
|
@@ -1680,21 +1714,93 @@ function readVersionFromEntry(entryPath) {
|
|
|
1680
1714
|
}
|
|
1681
1715
|
return "unknown";
|
|
1682
1716
|
}
|
|
1683
|
-
const
|
|
1717
|
+
const bundledEntry = resolveBundledEntry();
|
|
1718
|
+
function resolveBundledEntry() {
|
|
1719
|
+
try {
|
|
1720
|
+
return __require.resolve("@tailwindcss/node");
|
|
1721
|
+
} catch {
|
|
1722
|
+
return null;
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
/**
|
|
1726
|
+
* Absolute entry of the plugin's own bundled `@tailwindcss/node`, or `null`
|
|
1727
|
+
* if not installed. Used as the last-resort fallback by
|
|
1728
|
+
* `resolveTailwindNodeFor` and passed to workers, which resolve the bare
|
|
1729
|
+
* specifier from a tmp-dir `eval` context (where it would otherwise fail).
|
|
1730
|
+
*/
|
|
1731
|
+
const TAILWIND_NODE_PATH = bundledEntry;
|
|
1684
1732
|
/**
|
|
1685
|
-
*
|
|
1686
|
-
*
|
|
1687
|
-
*
|
|
1688
|
-
* context (with cwd inside a tmp dir or under pnpm strict workspaces) can
|
|
1689
|
-
* fail to find the bare specifier.
|
|
1733
|
+
* Installed version of the plugin's bundled `@tailwindcss/node`, or
|
|
1734
|
+
* `'unknown'`. This is the version the plugin was built and tested against;
|
|
1735
|
+
* `engine-guard` uses it as the "tested ceiling".
|
|
1690
1736
|
*/
|
|
1691
|
-
const
|
|
1737
|
+
const TAILWIND_NODE_VERSION = bundledEntry !== null ? readVersionFromEntry(bundledEntry, "@tailwindcss/node") : "unknown";
|
|
1738
|
+
const BUILD_TOOL_SPECIFIERS = [
|
|
1739
|
+
"@tailwindcss/postcss",
|
|
1740
|
+
"@tailwindcss/vite",
|
|
1741
|
+
"@tailwindcss/cli"
|
|
1742
|
+
];
|
|
1743
|
+
/**
|
|
1744
|
+
* The real directories of the consumer's Tailwind build tools, resolved from
|
|
1745
|
+
* the CSS dir. Under pnpm's strict layout `@tailwindcss/node` is only a
|
|
1746
|
+
* transitive dep (not symlinked into the package's `node_modules`), so it is
|
|
1747
|
+
* unreachable from the CSS dir directly — but it IS reachable from the build
|
|
1748
|
+
* tool's own real directory. `realpathSync` follows the pnpm symlink to the
|
|
1749
|
+
* virtual store before we resolve `@tailwindcss/node` relative to it.
|
|
1750
|
+
*/
|
|
1751
|
+
function buildToolAnchorDirs(cssDir) {
|
|
1752
|
+
const dirs = [];
|
|
1753
|
+
for (const spec of BUILD_TOOL_SPECIFIERS) {
|
|
1754
|
+
const entry = tryResolveFrom(spec, cssDir);
|
|
1755
|
+
if (entry) dirs.push(dirname(realpathOr(entry)));
|
|
1756
|
+
}
|
|
1757
|
+
return dirs;
|
|
1758
|
+
}
|
|
1759
|
+
const resolutionCache = /* @__PURE__ */ new Map();
|
|
1692
1760
|
/**
|
|
1693
|
-
*
|
|
1694
|
-
*
|
|
1695
|
-
*
|
|
1761
|
+
* Resolve the Tailwind engine to run for a given resolved CSS entry point,
|
|
1762
|
+
* anchored on the consumer's project. Memoized per CSS directory.
|
|
1763
|
+
*
|
|
1764
|
+
* Cascade:
|
|
1765
|
+
* 1. `buildVersion` (B) — the consumer's `tailwindcss` resolved from the CSS
|
|
1766
|
+
* dir. Always a direct dep, so it resolves under npm (hoisted) and pnpm
|
|
1767
|
+
* (symlinked into the package). `'unknown'` if the project has no Tailwind.
|
|
1768
|
+
* 2. `nodePath` (E) — the first `@tailwindcss/node` resolvable from
|
|
1769
|
+
* `[cssDir, ...buildToolAnchorDirs]`, preferring the copy whose version
|
|
1770
|
+
* equals `buildVersion` so a hoisted plugin copy can't shadow the
|
|
1771
|
+
* consumer's engine (R2). Falls back to the bundled copy.
|
|
1772
|
+
*
|
|
1773
|
+
* Never throws; degrades to `'unknown'` / bundled so the version guard (not
|
|
1774
|
+
* this function) owns the fail-loud decision.
|
|
1696
1775
|
*/
|
|
1697
|
-
|
|
1776
|
+
function resolveTailwindNodeFor(cssPath) {
|
|
1777
|
+
const cssDir = dirname(resolve(cssPath));
|
|
1778
|
+
const cached = resolutionCache.get(cssDir);
|
|
1779
|
+
if (cached) return cached;
|
|
1780
|
+
const twEntry = tryResolveFrom("tailwindcss", cssDir);
|
|
1781
|
+
const buildVersion = twEntry ? readVersionFromEntry(twEntry, "tailwindcss") : "unknown";
|
|
1782
|
+
const candidates = [];
|
|
1783
|
+
for (const dir of [cssDir, ...buildToolAnchorDirs(cssDir)]) {
|
|
1784
|
+
const found = tryResolveFrom("@tailwindcss/node", dir);
|
|
1785
|
+
if (!found) continue;
|
|
1786
|
+
const real = realpathOr(found);
|
|
1787
|
+
if (!candidates.includes(real)) candidates.push(real);
|
|
1788
|
+
}
|
|
1789
|
+
let nodePath = null;
|
|
1790
|
+
if (buildVersion !== "unknown") nodePath = candidates.find((c) => readVersionFromEntry(c, "@tailwindcss/node") === buildVersion) ?? null;
|
|
1791
|
+
if (nodePath === null) nodePath = candidates[0] ?? null;
|
|
1792
|
+
if (nodePath === null) nodePath = TAILWIND_NODE_PATH;
|
|
1793
|
+
const usedBundled = nodePath !== null && TAILWIND_NODE_PATH !== null && realpathOr(nodePath) === realpathOr(TAILWIND_NODE_PATH);
|
|
1794
|
+
const nodeVersion = nodePath !== null ? readVersionFromEntry(realpathOr(nodePath), "@tailwindcss/node") : "unknown";
|
|
1795
|
+
const result = {
|
|
1796
|
+
nodePath,
|
|
1797
|
+
nodeVersion,
|
|
1798
|
+
buildVersion,
|
|
1799
|
+
usedBundled
|
|
1800
|
+
};
|
|
1801
|
+
resolutionCache.set(cssDir, result);
|
|
1802
|
+
return result;
|
|
1803
|
+
}
|
|
1698
1804
|
//#endregion
|
|
1699
1805
|
//#region src/design-system/sync-loader.ts
|
|
1700
1806
|
/**
|
|
@@ -1722,7 +1828,7 @@ const TAILWIND_NODE_VERSION = entryPath !== null ? readVersionFromEntry(entryPat
|
|
|
1722
1828
|
* `tests/benchmarks/precompute-phases.test.ts` used to keep a hand-copied
|
|
1723
1829
|
* duplicate of the extractor that silently drifted from the real one, and it is
|
|
1724
1830
|
* interpolated (not concatenated at runtime), so its text still feeds the
|
|
1725
|
-
* `
|
|
1831
|
+
* `SCRIPT_HASH` md5 and any edit here invalidates the disk cache automatically.
|
|
1726
1832
|
*
|
|
1727
1833
|
* Exports (in the worker scope): `walkDeclarations`, `scanVarReads`,
|
|
1728
1834
|
* `isPureVarRead`.
|
|
@@ -2625,23 +2731,20 @@ function cacheDirName() {
|
|
|
2625
2731
|
}
|
|
2626
2732
|
}
|
|
2627
2733
|
const CACHE_DIR = join(tmpdir(), cacheDirName());
|
|
2734
|
+
/** md5 of the precompute script (no version) — the version is folded in per entry point. */
|
|
2735
|
+
const SCRIPT_HASH = createHash("md5").update(PRECOMPUTE_SCRIPT).digest("hex").slice(0, 8);
|
|
2628
2736
|
/**
|
|
2629
|
-
*
|
|
2630
|
-
*
|
|
2631
|
-
*
|
|
2632
|
-
*
|
|
2633
|
-
*
|
|
2634
|
-
* tailwindcss (e.g. 4.2 → 4.3 adding `zoom-*`, `tab-*`, `scrollbar-*` etc.),
|
|
2635
|
-
* so `validClasses`, `cssProps`, `canonical`, and `arbitraryEquivalents`
|
|
2636
|
-
* reflect the installed version. @tailwindcss/node and tailwindcss are
|
|
2637
|
-
* published together, so their versions match.
|
|
2737
|
+
* The engine identifier folded into the content hash. Normally the resolved
|
|
2738
|
+
* `@tailwindcss/node` version; when that is `'unknown'` (unreadable
|
|
2739
|
+
* `package.json`) two genuinely different engines would both hash as `unknown`,
|
|
2740
|
+
* so tiebreak on the resolved path (machine-local, but the disk cache is
|
|
2741
|
+
* per-uid/per-machine anyway, and under pnpm the path encodes the version).
|
|
2638
2742
|
*/
|
|
2639
|
-
function
|
|
2640
|
-
return
|
|
2743
|
+
function engineCacheKey(res) {
|
|
2744
|
+
return res.nodeVersion === "unknown" && res.nodePath !== null ? `unknown@${res.nodePath}` : res.nodeVersion;
|
|
2641
2745
|
}
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
return createHash("md5").update(`${CACHE_KEY}:${content}`).digest("hex");
|
|
2746
|
+
function computeContentHash(content, engineVersion) {
|
|
2747
|
+
return createHash("md5").update(`${SCRIPT_HASH}:${engineVersion}:${content}`).digest("hex");
|
|
2645
2748
|
}
|
|
2646
2749
|
const IMPORT_RE = /@import\s+(?:url\(\s*)?['"]([^'"]+)['"]/g;
|
|
2647
2750
|
/**
|
|
@@ -2653,7 +2756,7 @@ const IMPORT_RE = /@import\s+(?:url\(\s*)?['"]([^'"]+)['"]/g;
|
|
|
2653
2756
|
*
|
|
2654
2757
|
* Resolves RELATIVE imports (`./`, `../`) recursively up to a small depth;
|
|
2655
2758
|
* package imports (`@import "tailwindcss"`, `tw-animate-css`) are already
|
|
2656
|
-
* covered by the
|
|
2759
|
+
* covered by the engine version folded into the content hash. Best-effort:
|
|
2657
2760
|
* an unreadable import contributes nothing (it can't affect the DS either).
|
|
2658
2761
|
*/
|
|
2659
2762
|
function hashableContent(entryPath, entryContent) {
|
|
@@ -2693,7 +2796,9 @@ function getContentCachePath(contentHash) {
|
|
|
2693
2796
|
*/
|
|
2694
2797
|
function cacheArtifactPaths(cssPath) {
|
|
2695
2798
|
const resolved = resolve(cssPath);
|
|
2696
|
-
const
|
|
2799
|
+
const content = readFileSync(resolved, "utf-8");
|
|
2800
|
+
const res = resolveTailwindNodeFor(resolved);
|
|
2801
|
+
const hash = computeContentHash(hashableContent(resolved, content), engineCacheKey(res));
|
|
2697
2802
|
return {
|
|
2698
2803
|
json: getContentCachePath(hash),
|
|
2699
2804
|
lock: join(CACHE_DIR, `${hash}.lock`)
|
|
@@ -2903,12 +3008,13 @@ function loadDesignSystemSync(cssPath, timeout) {
|
|
|
2903
3008
|
} catch (cause) {
|
|
2904
3009
|
throw new DesignSystemLoadError(`Could not read CSS entry point: ${resolvedPath}`, "Verify the path resolves from the oxlint working directory and the file is readable.", { cause: cause instanceof Error ? cause : void 0 });
|
|
2905
3010
|
}
|
|
2906
|
-
const
|
|
3011
|
+
const engine = resolveTailwindNodeFor(resolvedPath);
|
|
3012
|
+
const contentHash = computeContentHash(hashableContent(resolvedPath, content), engineCacheKey(engine));
|
|
2907
3013
|
const contentCachePath = getContentCachePath(contentHash);
|
|
2908
3014
|
const cached = tryReadCache(contentCachePath);
|
|
2909
3015
|
if (cached) return cached;
|
|
2910
|
-
if (
|
|
2911
|
-
return computeWithLock(resolvedPath,
|
|
3016
|
+
if (engine.nodePath === null) throw new DesignSystemLoadError(`Could not resolve '@tailwindcss/node' while loading "${resolvedPath}".`, "Install '@tailwindcss/node' (or upgrade oxlint-tailwindcss) and re-run.");
|
|
3017
|
+
return computeWithLock(resolvedPath, engine.nodePath, contentHash, contentCachePath, timeout ?? 6e4);
|
|
2912
3018
|
}
|
|
2913
3019
|
//#endregion
|
|
2914
3020
|
//#region src/design-system/debug.ts
|
|
@@ -2939,6 +3045,207 @@ function debugLog(message) {
|
|
|
2939
3045
|
if (_enabled || process.env.DEBUG === "oxlint-tailwindcss") console.error(`${PREFIX} ${message}`);
|
|
2940
3046
|
}
|
|
2941
3047
|
//#endregion
|
|
3048
|
+
//#region src/design-system/engine-guard.ts
|
|
3049
|
+
/**
|
|
3050
|
+
* Version safeguards for the consumer-resolved Tailwind engine.
|
|
3051
|
+
*
|
|
3052
|
+
* Once the plugin loads the CONSUMER's Tailwind (`resolveTailwindNodeFor`),
|
|
3053
|
+
* two version facts matter per entry point:
|
|
3054
|
+
*
|
|
3055
|
+
* - `E` — the `@tailwindcss/node` version the plugin will actually run.
|
|
3056
|
+
* - `B` — the `tailwindcss` version the consumer's build compiles with.
|
|
3057
|
+
*
|
|
3058
|
+
* `assessEngine` grades `(E, B)` against the plugin's supported range and the
|
|
3059
|
+
* drift between the two, returning `ok` / `warn` / `fatal`. `emitEngineVerdict`
|
|
3060
|
+
* turns a `fatal` into an `UnsupportedEngineError` (which the fatal-reporter
|
|
3061
|
+
* routes to `designSystemUnavailable` with no per-rule `meta` change) and a
|
|
3062
|
+
* `warn` into a one-time stderr notice.
|
|
3063
|
+
*
|
|
3064
|
+
* The comparator is a hand-rolled subset of semver (no `semver` dependency —
|
|
3065
|
+
* runtime deps stay `@tailwindcss/node` + `tailwindcss` only). It is total and
|
|
3066
|
+
* never throws; unparseable input reads as "unknown".
|
|
3067
|
+
*/
|
|
3068
|
+
const WARN_PREFIX = "[oxlint-tailwindcss]";
|
|
3069
|
+
/** The lowest Tailwind major this plugin supports. */
|
|
3070
|
+
const SUPPORTED_MAJOR = 4;
|
|
3071
|
+
/**
|
|
3072
|
+
* `4.1.0`, the minimum engine version. The precompute calls
|
|
3073
|
+
* `ds.canonicalizeCandidates`, which the design system only exposes from
|
|
3074
|
+
* Tailwind 4.1 onward — on 4.0.x it throws `is not a function`, so we fail loud
|
|
3075
|
+
* with a clear message before spawning the worker. A `4.1.0-*` prerelease sorts
|
|
3076
|
+
* below it.
|
|
3077
|
+
*/
|
|
3078
|
+
const MIN_ENGINE = {
|
|
3079
|
+
major: 4,
|
|
3080
|
+
minor: 1,
|
|
3081
|
+
patch: 0,
|
|
3082
|
+
prerelease: null
|
|
3083
|
+
};
|
|
3084
|
+
/**
|
|
3085
|
+
* Parse a version string into `{ major, minor, patch, prerelease }`, or `null`
|
|
3086
|
+
* for anything unparseable (`''`, `'unknown'`, a range like `'^4.3.3'`, a dist
|
|
3087
|
+
* tag like `'next'`, non-strings). Total — never throws.
|
|
3088
|
+
*/
|
|
3089
|
+
function parseVersion(v) {
|
|
3090
|
+
if (typeof v !== "string") return null;
|
|
3091
|
+
let s = v.trim();
|
|
3092
|
+
if (s === "" || s === "unknown") return null;
|
|
3093
|
+
if (s[0] === "v" || s[0] === "V") s = s.slice(1);
|
|
3094
|
+
const plus = s.indexOf("+");
|
|
3095
|
+
if (plus !== -1) s = s.slice(0, plus);
|
|
3096
|
+
let prerelease = null;
|
|
3097
|
+
const dash = s.indexOf("-");
|
|
3098
|
+
if (dash !== -1) {
|
|
3099
|
+
prerelease = s.slice(dash + 1) || null;
|
|
3100
|
+
s = s.slice(0, dash);
|
|
3101
|
+
}
|
|
3102
|
+
const parts = s.split(".");
|
|
3103
|
+
const major = Number.parseInt(parts[0], 10);
|
|
3104
|
+
if (Number.isNaN(major)) return null;
|
|
3105
|
+
const minor = Number.parseInt(parts[1] ?? "0", 10);
|
|
3106
|
+
const patch = Number.parseInt(parts[2] ?? "0", 10);
|
|
3107
|
+
return {
|
|
3108
|
+
major,
|
|
3109
|
+
minor: Number.isNaN(minor) ? 0 : minor,
|
|
3110
|
+
patch: Number.isNaN(patch) ? 0 : patch,
|
|
3111
|
+
prerelease
|
|
3112
|
+
};
|
|
3113
|
+
}
|
|
3114
|
+
/** Compare by major, minor, patch; at equal core, a release outranks a prerelease. */
|
|
3115
|
+
function compareVersions(a, b) {
|
|
3116
|
+
if (a.major !== b.major) return a.major < b.major ? -1 : 1;
|
|
3117
|
+
if (a.minor !== b.minor) return a.minor < b.minor ? -1 : 1;
|
|
3118
|
+
if (a.patch !== b.patch) return a.patch < b.patch ? -1 : 1;
|
|
3119
|
+
if (a.prerelease === b.prerelease) return 0;
|
|
3120
|
+
if (a.prerelease === null) return 1;
|
|
3121
|
+
if (b.prerelease === null) return -1;
|
|
3122
|
+
return a.prerelease < b.prerelease ? -1 : a.prerelease > b.prerelease ? 1 : 0;
|
|
3123
|
+
}
|
|
3124
|
+
function sameMajor(a, b) {
|
|
3125
|
+
return a.major === b.major;
|
|
3126
|
+
}
|
|
3127
|
+
function sameMinor(a, b) {
|
|
3128
|
+
return a.major === b.major && a.minor === b.minor;
|
|
3129
|
+
}
|
|
3130
|
+
/**
|
|
3131
|
+
* Grade `(E, B)` against the supported range and build drift. First matching
|
|
3132
|
+
* row wins (see the decision table in the PR / plan). Pure and total: safe to
|
|
3133
|
+
* unit-test with literal version strings.
|
|
3134
|
+
*/
|
|
3135
|
+
function assessEngine(E, B, opts) {
|
|
3136
|
+
const pe = parseVersion(E);
|
|
3137
|
+
const pb = parseVersion(B);
|
|
3138
|
+
const bundled = opts.bundledVersion;
|
|
3139
|
+
if (pe === null) return {
|
|
3140
|
+
verdict: "ok",
|
|
3141
|
+
kind: "engine-version-unknown",
|
|
3142
|
+
message: "Could not determine the resolved Tailwind engine version; skipping the version guard."
|
|
3143
|
+
};
|
|
3144
|
+
if (pe.major < SUPPORTED_MAJOR || compareVersions(pe, MIN_ENGINE) < 0) return {
|
|
3145
|
+
verdict: "fatal",
|
|
3146
|
+
kind: "engine-too-old",
|
|
3147
|
+
message: `oxlint-tailwindcss requires Tailwind CSS v4.1 or newer, but the resolved engine is ${E}.`,
|
|
3148
|
+
hint: "Upgrade tailwindcss / @tailwindcss/node to v4.1+, or pin an older oxlint-tailwindcss."
|
|
3149
|
+
};
|
|
3150
|
+
if (pe.major > SUPPORTED_MAJOR) {
|
|
3151
|
+
if (opts.allowUntested) return {
|
|
3152
|
+
verdict: "warn",
|
|
3153
|
+
kind: "engine-future-major-allowed",
|
|
3154
|
+
message: `Running against untested Tailwind engine ${E} (a major newer than the tested ${bundled}) because allowUntestedEngine is set — results may be inaccurate.`
|
|
3155
|
+
};
|
|
3156
|
+
return {
|
|
3157
|
+
verdict: "fatal",
|
|
3158
|
+
kind: "engine-future-major",
|
|
3159
|
+
message: `The resolved Tailwind engine ${E} is a major version newer than this plugin was built for (tested against ${bundled}); its behavior is unverified.`,
|
|
3160
|
+
hint: "Set settings.tailwindcss.allowUntestedEngine: true to run anyway (results may be inaccurate), or upgrade oxlint-tailwindcss."
|
|
3161
|
+
};
|
|
3162
|
+
}
|
|
3163
|
+
if (pb !== null && !sameMajor(pe, pb)) {
|
|
3164
|
+
if (opts.allowUntested) return {
|
|
3165
|
+
verdict: "warn",
|
|
3166
|
+
kind: "engine-build-drift-major-allowed",
|
|
3167
|
+
message: `Linting with Tailwind engine ${E} while your build uses tailwindcss@${B} (a different major) because allowUntestedEngine is set — the plugin enforces different semantics than your build produces.`
|
|
3168
|
+
};
|
|
3169
|
+
return {
|
|
3170
|
+
verdict: "fatal",
|
|
3171
|
+
kind: "engine-build-drift-major",
|
|
3172
|
+
message: `Linting with Tailwind engine ${E} but your build uses tailwindcss@${B} (a different major); the plugin would enforce different Tailwind semantics than your build produces.`,
|
|
3173
|
+
hint: "Align the versions, or set settings.tailwindcss.allowUntestedEngine: true to override."
|
|
3174
|
+
};
|
|
3175
|
+
}
|
|
3176
|
+
if (pb !== null && !sameMinor(pe, pb)) return {
|
|
3177
|
+
verdict: "warn",
|
|
3178
|
+
kind: "engine-build-drift-minor",
|
|
3179
|
+
message: `Linting with Tailwind engine ${E} but your build uses tailwindcss@${B}; lint results may differ from your compiled CSS.`,
|
|
3180
|
+
hint: "Align the versions, or ignore if intentional."
|
|
3181
|
+
};
|
|
3182
|
+
const pBundled = parseVersion(bundled);
|
|
3183
|
+
if (pBundled !== null && compareVersions(pe, pBundled) > 0) return {
|
|
3184
|
+
verdict: "warn",
|
|
3185
|
+
kind: "engine-newer-minor",
|
|
3186
|
+
message: `The resolved Tailwind engine ${E} is newer than the version this plugin was tested against (${bundled}); newly added utilities may be reported as unknown.`,
|
|
3187
|
+
hint: "Usually safe; upgrade oxlint-tailwindcss if you see false positives."
|
|
3188
|
+
};
|
|
3189
|
+
return {
|
|
3190
|
+
verdict: "ok",
|
|
3191
|
+
kind: "ok",
|
|
3192
|
+
message: ""
|
|
3193
|
+
};
|
|
3194
|
+
}
|
|
3195
|
+
const warnedEngineKeys = /* @__PURE__ */ new Set();
|
|
3196
|
+
/**
|
|
3197
|
+
* Act on a verdict: `fatal` throws `UnsupportedEngineError` (routed to
|
|
3198
|
+
* `designSystemUnavailable`), `warn` emits a one-time stderr notice keyed by
|
|
3199
|
+
* `(entryPoint, kind, E, B)`, `ok` is silent. `debugLog` (self-gated) always
|
|
3200
|
+
* records the structured detail when debug is on.
|
|
3201
|
+
*/
|
|
3202
|
+
function emitEngineVerdict(v, ctx) {
|
|
3203
|
+
if (v.verdict === "fatal") throw new UnsupportedEngineError(v.message, v.hint);
|
|
3204
|
+
if (v.verdict === "warn") {
|
|
3205
|
+
const key = `${ctx.resolvedPath}\0${v.kind}\0${ctx.E}\0${ctx.B}`;
|
|
3206
|
+
if (!warnedEngineKeys.has(key)) {
|
|
3207
|
+
warnedEngineKeys.add(key);
|
|
3208
|
+
console.warn(`${WARN_PREFIX} ${v.message}`);
|
|
3209
|
+
}
|
|
3210
|
+
}
|
|
3211
|
+
debugLog(`engine E=${ctx.E} B=${ctx.B} → ${v.kind}`);
|
|
3212
|
+
}
|
|
3213
|
+
/**
|
|
3214
|
+
* Resolve the engine for `resolvedPath` (or use injected facts), assess it, and
|
|
3215
|
+
* emit the verdict. Throws `UnsupportedEngineError` on a fatal verdict. Called
|
|
3216
|
+
* once per entry point from `getLoadedDesignSystem`, inside its fatal-caching
|
|
3217
|
+
* `try`.
|
|
3218
|
+
*/
|
|
3219
|
+
function guardEngine(resolvedPath, allowUntested, override) {
|
|
3220
|
+
let E;
|
|
3221
|
+
let B;
|
|
3222
|
+
let bundledVersion;
|
|
3223
|
+
if (override) {
|
|
3224
|
+
E = override.E;
|
|
3225
|
+
B = override.B;
|
|
3226
|
+
bundledVersion = override.bundledVersion ?? TAILWIND_NODE_VERSION;
|
|
3227
|
+
} else {
|
|
3228
|
+
const res = resolveTailwindNodeFor(resolvedPath);
|
|
3229
|
+
E = res.nodeVersion;
|
|
3230
|
+
B = res.buildVersion;
|
|
3231
|
+
bundledVersion = TAILWIND_NODE_VERSION;
|
|
3232
|
+
}
|
|
3233
|
+
emitEngineVerdict(assessEngine(E, B, {
|
|
3234
|
+
allowUntested,
|
|
3235
|
+
bundledVersion
|
|
3236
|
+
}), {
|
|
3237
|
+
resolvedPath,
|
|
3238
|
+
E,
|
|
3239
|
+
B
|
|
3240
|
+
});
|
|
3241
|
+
}
|
|
3242
|
+
/** Read `settings.tailwindcss.allowUntestedEngine` (default `false`). */
|
|
3243
|
+
function allowUntestedEngineFromSettings(settings) {
|
|
3244
|
+
const tw = settings?.tailwindcss;
|
|
3245
|
+
if (tw && typeof tw === "object" && "allowUntestedEngine" in tw) return tw.allowUntestedEngine === true;
|
|
3246
|
+
return false;
|
|
3247
|
+
}
|
|
3248
|
+
//#endregion
|
|
2942
3249
|
//#region src/utils/context.ts
|
|
2943
3250
|
/**
|
|
2944
3251
|
* Safely read `context.options[0]`. Returns `undefined` if the getter throws
|
|
@@ -3212,7 +3519,7 @@ function timeoutFromSettings(settings) {
|
|
|
3212
3519
|
* Cached per absolute entry-point path, keyed by mtime. In monorepos each
|
|
3213
3520
|
* unique CSS gets its own cache entry.
|
|
3214
3521
|
*/
|
|
3215
|
-
function getLoadedDesignSystem(cssPath, settings) {
|
|
3522
|
+
function getLoadedDesignSystem(cssPath, settings, engineInfo) {
|
|
3216
3523
|
const resolvedPath = resolve(cssPath);
|
|
3217
3524
|
let mtime;
|
|
3218
3525
|
try {
|
|
@@ -3229,6 +3536,7 @@ function getLoadedDesignSystem(cssPath, settings) {
|
|
|
3229
3536
|
if (failed && failed.mtime === mtime) throw failed.error;
|
|
3230
3537
|
let data;
|
|
3231
3538
|
try {
|
|
3539
|
+
guardEngine(resolvedPath, allowUntestedEngineFromSettings(settings), engineInfo);
|
|
3232
3540
|
data = loadDesignSystemSync(resolvedPath, timeoutFromSettings(settings));
|
|
3233
3541
|
} catch (err) {
|
|
3234
3542
|
if (isFatalError(err)) dsFailureCache.set(resolvedPath, {
|
|
@@ -3454,7 +3762,8 @@ var DesignSystemWorker = class {
|
|
|
3454
3762
|
this.workers.set(cssPath, existing);
|
|
3455
3763
|
return existing;
|
|
3456
3764
|
}
|
|
3457
|
-
|
|
3765
|
+
const { nodePath: tailwindNodePath } = resolveTailwindNodeFor(cssPath);
|
|
3766
|
+
if (tailwindNodePath === null) throw this.remember(cssPath, new SortServiceError(`Could not resolve '@tailwindcss/node' for the ${this.opts.serviceName} worker.`, "Install '@tailwindcss/node' (or upgrade oxlint-tailwindcss) and re-run."));
|
|
3458
3767
|
const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE);
|
|
3459
3768
|
const controlArray = new Int32Array(sharedBuffer, 0, HEADER_INTS);
|
|
3460
3769
|
const lengthView = new DataView(sharedBuffer, HEADER_INTS * 4, 4);
|
|
@@ -3466,7 +3775,7 @@ var DesignSystemWorker = class {
|
|
|
3466
3775
|
workerData: {
|
|
3467
3776
|
sharedBuffer,
|
|
3468
3777
|
cssPath,
|
|
3469
|
-
tailwindNodePath
|
|
3778
|
+
tailwindNodePath
|
|
3470
3779
|
}
|
|
3471
3780
|
});
|
|
3472
3781
|
} catch (cause) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oxlint-tailwindcss",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Tailwind CSS linting rules for oxlint",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"css",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@oxlint/plugins": "catalog:",
|
|
59
59
|
"@tailwindcss/typography": "^0.5.20",
|
|
60
|
-
"@types/node": "^26.
|
|
60
|
+
"@types/node": "^26.2.0",
|
|
61
61
|
"oxlint": "catalog:",
|
|
62
62
|
"tailwindcss-animate": "^1.0.7",
|
|
63
63
|
"tsdown": "^0.22.14",
|