oxlint-tailwindcss 0.1.6 → 0.1.7

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 CHANGED
@@ -98,10 +98,7 @@ You can also override per rule if needed:
98
98
  ```jsonc
99
99
  {
100
100
  "rules": {
101
- "tailwindcss/no-unknown-classes": [
102
- "error",
103
- { "entryPoint": "src/app.css" },
104
- ],
101
+ "tailwindcss/no-unknown-classes": ["error", { "entryPoint": "src/app.css" }],
105
102
  },
106
103
  }
107
104
  ```
package/dist/index.cjs CHANGED
@@ -4,6 +4,7 @@ let node_crypto = require("node:crypto");
4
4
  let node_fs = require("node:fs");
5
5
  let node_path = require("node:path");
6
6
  let node_os = require("node:os");
7
+ let node_worker_threads = require("node:worker_threads");
7
8
  //#region src/utils/extractors.ts
8
9
  /**
9
10
  * Preserves leading/trailing spaces in fixed class strings for template literals.
@@ -1482,51 +1483,60 @@ const enforceCanonical = (0, _oxlint_plugins.defineRule)({
1482
1483
  //#endregion
1483
1484
  //#region src/design-system/sort-service.ts
1484
1485
  /**
1485
- * Persistent sort service using named pipes (FIFOs) for synchronous IPC.
1486
+ * Persistent sort service using worker_threads + SharedArrayBuffer.
1486
1487
  *
1487
1488
  * The problem: `ds.getClassOrder()` is the only way to get the exact official
1488
1489
  * Tailwind CSS sort order (matching oxfmt/prettier-plugin-tailwindcss), but the
1489
1490
  * design system is async to load and the oxlint plugin API is sync.
1490
1491
  *
1491
- * The solution: spawn a persistent child process that loads the DS once, then
1492
- * accepts sort requests via FIFOs. File descriptors are opened ONCE and kept
1493
- * open for the entire lint session, using newline-delimited JSON framing.
1492
+ * The solution: spawn a Worker thread that loads the DS once, then accepts sort
1493
+ * requests via SharedArrayBuffer + Atomics. The parent uses `Atomics.wait()`
1494
+ * (with timeout) for synchronous blocking without risk of infinite hangs.
1494
1495
  *
1495
- * Falls back gracefully on platforms without FIFO support (Windows).
1496
+ * Falls back gracefully if the worker fails to initialize within the timeout.
1496
1497
  */
1497
- const SORT_WORKER_SCRIPT = `
1498
- const { openSync, readSync, writeSync, closeSync } = require('fs');
1499
- const { dirname } = require('path');
1498
+ const BUFFER_SIZE = 4 * 1024 * 1024;
1499
+ const HEADER_INTS = 4;
1500
+ const DATA_OFFSET = HEADER_INTS * 4 + 4;
1501
+ const INIT_TIMEOUT = 3e4;
1502
+ const REQUEST_TIMEOUT = 1e4;
1503
+ const WORKER_SCRIPT = `
1504
+ const { workerData } = require('worker_threads');
1500
1505
 
1501
- function readLine(fd) {
1502
- let line = '';
1503
- const buf = Buffer.alloc(1);
1504
- while (true) {
1505
- const n = readSync(fd, buf, 0, 1);
1506
- if (n === 0) return null;
1507
- if (buf[0] === 10) return line;
1508
- line += String.fromCharCode(buf[0]);
1506
+ async function main() {
1507
+ const { sharedBuffer, cssPath } = workerData;
1508
+ const control = new Int32Array(sharedBuffer, 0, ${HEADER_INTS});
1509
+ const lengthView = new DataView(sharedBuffer, ${HEADER_INTS * 4}, 4);
1510
+ const dataArea = new Uint8Array(sharedBuffer, ${DATA_OFFSET});
1511
+
1512
+ let ds;
1513
+ try {
1514
+ const { __unstable__loadDesignSystem } = require('@tailwindcss/node');
1515
+ const { readFileSync } = require('fs');
1516
+ const { dirname } = require('path');
1517
+ const css = readFileSync(cssPath, 'utf-8');
1518
+ ds = await __unstable__loadDesignSystem(css, { base: dirname(cssPath) });
1519
+ } catch {
1520
+ Atomics.store(control, 2, -1);
1521
+ Atomics.notify(control, 2);
1522
+ return;
1509
1523
  }
1510
- }
1511
1524
 
1512
- async function main() {
1513
- const cssPath = process.env.TAILWIND_CSS_PATH;
1514
- const reqPipe = process.env.REQ_PIPE;
1515
- const resPipe = process.env.RES_PIPE;
1525
+ // Signal ready
1526
+ Atomics.store(control, 2, 1);
1527
+ Atomics.notify(control, 2);
1516
1528
 
1517
- const { __unstable__loadDesignSystem } = require('@tailwindcss/node');
1518
- const { readFileSync } = require('fs');
1519
- const css = readFileSync(cssPath, 'utf-8');
1520
- const ds = await __unstable__loadDesignSystem(css, { base: dirname(cssPath) });
1529
+ // Request loop
1530
+ while (true) {
1531
+ Atomics.wait(control, 0, 0); // wait for requestSignal !== 0
1521
1532
 
1522
- const reqFd = openSync(reqPipe, 'r');
1523
- const resFd = openSync(resPipe, 'w');
1533
+ const len = lengthView.getUint32(0);
1534
+ const requestStr = Buffer.from(dataArea.slice(0, len)).toString('utf-8');
1535
+ Atomics.store(control, 0, 0); // consume request
1524
1536
 
1525
- let req;
1526
- while ((req = readLine(reqFd)) !== null) {
1527
- if (!req) continue;
1537
+ let response;
1528
1538
  try {
1529
- const classes = JSON.parse(req);
1539
+ const classes = JSON.parse(requestStr);
1530
1540
  const ordered = ds.getClassOrder(classes);
1531
1541
  const sorted = [...ordered]
1532
1542
  .sort((a, b) => {
@@ -1536,72 +1546,54 @@ async function main() {
1536
1546
  return a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0;
1537
1547
  })
1538
1548
  .map(([name]) => name);
1539
- const out = Buffer.from(JSON.stringify(sorted) + '\\n', 'utf-8');
1540
- writeSync(resFd, out, 0, out.length);
1549
+ response = Buffer.from(JSON.stringify(sorted), 'utf-8');
1541
1550
  } catch {
1542
- const out = Buffer.from('null\\n', 'utf-8');
1543
- writeSync(resFd, out, 0, out.length);
1551
+ response = Buffer.from('null', 'utf-8');
1544
1552
  }
1545
- }
1546
1553
 
1547
- closeSync(reqFd);
1548
- closeSync(resFd);
1554
+ dataArea.set(response, 0);
1555
+ lengthView.setUint32(0, response.length);
1556
+
1557
+ Atomics.store(control, 1, 1); // signal response
1558
+ Atomics.notify(control, 1);
1559
+ }
1549
1560
  }
1550
- main().catch(() => process.exit(1));
1561
+ main();
1551
1562
  `;
1552
- let child = null;
1553
- let reqPipe = null;
1554
- let resPipe = null;
1555
- let reqFd = null;
1556
- let resFd = null;
1563
+ let worker = null;
1564
+ let controlArray = null;
1565
+ let lengthView = null;
1566
+ let dataArea = null;
1557
1567
  let initialized = false;
1558
1568
  let available = true;
1559
- let readBuffer = "";
1560
- /** Read a newline-delimited line from an open file descriptor (blocking). */
1561
- function readLineSync(fd) {
1562
- while (true) {
1563
- const nlIdx = readBuffer.indexOf("\n");
1564
- if (nlIdx >= 0) {
1565
- const line = readBuffer.slice(0, nlIdx);
1566
- readBuffer = readBuffer.slice(nlIdx + 1);
1567
- return line;
1568
- }
1569
- const buf = Buffer.alloc(65536);
1570
- const n = (0, node_fs.readSync)(fd, buf, 0, buf.length, null);
1571
- if (n === 0) throw new Error("EOF");
1572
- readBuffer += buf.toString("utf-8", 0, n);
1573
- }
1574
- }
1575
1569
  function ensureService(cssPath) {
1576
1570
  if (initialized) return available;
1577
1571
  initialized = true;
1578
1572
  try {
1579
- const id = `${process.pid}-${Date.now()}`;
1580
- reqPipe = (0, node_path.join)((0, node_os.tmpdir)(), `oxlint-tw-req-${id}`);
1581
- resPipe = (0, node_path.join)((0, node_os.tmpdir)(), `oxlint-tw-res-${id}`);
1582
- (0, node_child_process.execFileSync)("mkfifo", [reqPipe]);
1583
- (0, node_child_process.execFileSync)("mkfifo", [resPipe]);
1584
- child = (0, node_child_process.spawn)(process.execPath, ["-e", SORT_WORKER_SCRIPT], {
1585
- env: {
1586
- ...process.env,
1587
- TAILWIND_CSS_PATH: cssPath,
1588
- REQ_PIPE: reqPipe,
1589
- RES_PIPE: resPipe
1590
- },
1591
- cwd: (0, node_path.dirname)(cssPath),
1592
- stdio: "ignore",
1593
- detached: false
1573
+ const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE);
1574
+ controlArray = new Int32Array(sharedBuffer, 0, HEADER_INTS);
1575
+ lengthView = new DataView(sharedBuffer, HEADER_INTS * 4, 4);
1576
+ dataArea = new Uint8Array(sharedBuffer, DATA_OFFSET);
1577
+ worker = new node_worker_threads.Worker(WORKER_SCRIPT, {
1578
+ eval: true,
1579
+ workerData: {
1580
+ sharedBuffer,
1581
+ cssPath
1582
+ }
1594
1583
  });
1595
- child.unref();
1596
- child.on("error", () => {
1597
- child = null;
1584
+ worker.unref();
1585
+ worker.on("error", () => {
1598
1586
  available = false;
1587
+ worker = null;
1599
1588
  });
1600
- child.on("exit", () => {
1601
- child = null;
1589
+ worker.on("exit", () => {
1590
+ worker = null;
1602
1591
  });
1603
- reqFd = (0, node_fs.openSync)(reqPipe, "w");
1604
- resFd = (0, node_fs.openSync)(resPipe, "r");
1592
+ if (Atomics.wait(controlArray, 2, 0, INIT_TIMEOUT) === "timed-out" || controlArray[2] === -1) {
1593
+ available = false;
1594
+ cleanup();
1595
+ return false;
1596
+ }
1605
1597
  process.on("exit", cleanup);
1606
1598
  return true;
1607
1599
  } catch {
@@ -1611,49 +1603,36 @@ function ensureService(cssPath) {
1611
1603
  }
1612
1604
  }
1613
1605
  function cleanup() {
1614
- if (reqFd !== null) {
1615
- try {
1616
- (0, node_fs.closeSync)(reqFd);
1617
- } catch {}
1618
- reqFd = null;
1619
- }
1620
- if (resFd !== null) {
1606
+ if (worker) {
1621
1607
  try {
1622
- (0, node_fs.closeSync)(resFd);
1608
+ worker.terminate();
1623
1609
  } catch {}
1624
- resFd = null;
1625
- }
1626
- if (child) {
1627
- try {
1628
- child.kill();
1629
- } catch {}
1630
- child = null;
1631
- }
1632
- if (reqPipe) {
1633
- try {
1634
- (0, node_fs.unlinkSync)(reqPipe);
1635
- } catch {}
1636
- reqPipe = null;
1637
- }
1638
- if (resPipe) {
1639
- try {
1640
- (0, node_fs.unlinkSync)(resPipe);
1641
- } catch {}
1642
- resPipe = null;
1610
+ worker = null;
1643
1611
  }
1644
1612
  }
1645
1613
  /**
1646
- * Sort classes using the official Tailwind CSS sort order via persistent child process.
1614
+ * Sort classes using the official Tailwind CSS sort order via worker thread.
1647
1615
  * Returns the sorted class array, or null if the service is unavailable.
1648
1616
  */
1649
1617
  function sortClassesSync(cssPath, classes) {
1650
1618
  if (!ensureService(cssPath)) return null;
1651
- if (reqFd === null || resFd === null) return null;
1619
+ if (!controlArray || !dataArea || !lengthView) return null;
1652
1620
  try {
1653
- const payload = Buffer.from(JSON.stringify(classes) + "\n", "utf-8");
1654
- (0, node_fs.writeSync)(reqFd, payload, 0, payload.length);
1655
- const line = readLineSync(resFd);
1656
- return JSON.parse(line);
1621
+ const request = Buffer.from(JSON.stringify(classes), "utf-8");
1622
+ if (request.length > BUFFER_SIZE - DATA_OFFSET) return null;
1623
+ dataArea.set(request, 0);
1624
+ lengthView.setUint32(0, request.length);
1625
+ Atomics.store(controlArray, 0, 1);
1626
+ Atomics.notify(controlArray, 0);
1627
+ if (Atomics.wait(controlArray, 1, 0, REQUEST_TIMEOUT) === "timed-out") {
1628
+ available = false;
1629
+ cleanup();
1630
+ return null;
1631
+ }
1632
+ const responseLen = lengthView.getUint32(0);
1633
+ const responseStr = Buffer.from(dataArea.slice(0, responseLen)).toString("utf-8");
1634
+ Atomics.store(controlArray, 1, 0);
1635
+ return JSON.parse(responseStr);
1657
1636
  } catch {
1658
1637
  available = false;
1659
1638
  cleanup();
package/dist/index.mjs CHANGED
@@ -1,9 +1,10 @@
1
1
  import { definePlugin, defineRule } from "@oxlint/plugins";
2
- import { execFileSync, spawn } from "node:child_process";
2
+ import { execFileSync } from "node:child_process";
3
3
  import { createHash } from "node:crypto";
4
- import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
4
+ import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
5
5
  import { dirname, join, resolve } from "node:path";
6
6
  import { tmpdir } from "node:os";
7
+ import { Worker } from "node:worker_threads";
7
8
  //#region src/utils/extractors.ts
8
9
  /**
9
10
  * Preserves leading/trailing spaces in fixed class strings for template literals.
@@ -1482,51 +1483,60 @@ const enforceCanonical = defineRule({
1482
1483
  //#endregion
1483
1484
  //#region src/design-system/sort-service.ts
1484
1485
  /**
1485
- * Persistent sort service using named pipes (FIFOs) for synchronous IPC.
1486
+ * Persistent sort service using worker_threads + SharedArrayBuffer.
1486
1487
  *
1487
1488
  * The problem: `ds.getClassOrder()` is the only way to get the exact official
1488
1489
  * Tailwind CSS sort order (matching oxfmt/prettier-plugin-tailwindcss), but the
1489
1490
  * design system is async to load and the oxlint plugin API is sync.
1490
1491
  *
1491
- * The solution: spawn a persistent child process that loads the DS once, then
1492
- * accepts sort requests via FIFOs. File descriptors are opened ONCE and kept
1493
- * open for the entire lint session, using newline-delimited JSON framing.
1492
+ * The solution: spawn a Worker thread that loads the DS once, then accepts sort
1493
+ * requests via SharedArrayBuffer + Atomics. The parent uses `Atomics.wait()`
1494
+ * (with timeout) for synchronous blocking without risk of infinite hangs.
1494
1495
  *
1495
- * Falls back gracefully on platforms without FIFO support (Windows).
1496
+ * Falls back gracefully if the worker fails to initialize within the timeout.
1496
1497
  */
1497
- const SORT_WORKER_SCRIPT = `
1498
- const { openSync, readSync, writeSync, closeSync } = require('fs');
1499
- const { dirname } = require('path');
1498
+ const BUFFER_SIZE = 4 * 1024 * 1024;
1499
+ const HEADER_INTS = 4;
1500
+ const DATA_OFFSET = HEADER_INTS * 4 + 4;
1501
+ const INIT_TIMEOUT = 3e4;
1502
+ const REQUEST_TIMEOUT = 1e4;
1503
+ const WORKER_SCRIPT = `
1504
+ const { workerData } = require('worker_threads');
1500
1505
 
1501
- function readLine(fd) {
1502
- let line = '';
1503
- const buf = Buffer.alloc(1);
1504
- while (true) {
1505
- const n = readSync(fd, buf, 0, 1);
1506
- if (n === 0) return null;
1507
- if (buf[0] === 10) return line;
1508
- line += String.fromCharCode(buf[0]);
1506
+ async function main() {
1507
+ const { sharedBuffer, cssPath } = workerData;
1508
+ const control = new Int32Array(sharedBuffer, 0, ${HEADER_INTS});
1509
+ const lengthView = new DataView(sharedBuffer, ${HEADER_INTS * 4}, 4);
1510
+ const dataArea = new Uint8Array(sharedBuffer, ${DATA_OFFSET});
1511
+
1512
+ let ds;
1513
+ try {
1514
+ const { __unstable__loadDesignSystem } = require('@tailwindcss/node');
1515
+ const { readFileSync } = require('fs');
1516
+ const { dirname } = require('path');
1517
+ const css = readFileSync(cssPath, 'utf-8');
1518
+ ds = await __unstable__loadDesignSystem(css, { base: dirname(cssPath) });
1519
+ } catch {
1520
+ Atomics.store(control, 2, -1);
1521
+ Atomics.notify(control, 2);
1522
+ return;
1509
1523
  }
1510
- }
1511
1524
 
1512
- async function main() {
1513
- const cssPath = process.env.TAILWIND_CSS_PATH;
1514
- const reqPipe = process.env.REQ_PIPE;
1515
- const resPipe = process.env.RES_PIPE;
1525
+ // Signal ready
1526
+ Atomics.store(control, 2, 1);
1527
+ Atomics.notify(control, 2);
1516
1528
 
1517
- const { __unstable__loadDesignSystem } = require('@tailwindcss/node');
1518
- const { readFileSync } = require('fs');
1519
- const css = readFileSync(cssPath, 'utf-8');
1520
- const ds = await __unstable__loadDesignSystem(css, { base: dirname(cssPath) });
1529
+ // Request loop
1530
+ while (true) {
1531
+ Atomics.wait(control, 0, 0); // wait for requestSignal !== 0
1521
1532
 
1522
- const reqFd = openSync(reqPipe, 'r');
1523
- const resFd = openSync(resPipe, 'w');
1533
+ const len = lengthView.getUint32(0);
1534
+ const requestStr = Buffer.from(dataArea.slice(0, len)).toString('utf-8');
1535
+ Atomics.store(control, 0, 0); // consume request
1524
1536
 
1525
- let req;
1526
- while ((req = readLine(reqFd)) !== null) {
1527
- if (!req) continue;
1537
+ let response;
1528
1538
  try {
1529
- const classes = JSON.parse(req);
1539
+ const classes = JSON.parse(requestStr);
1530
1540
  const ordered = ds.getClassOrder(classes);
1531
1541
  const sorted = [...ordered]
1532
1542
  .sort((a, b) => {
@@ -1536,72 +1546,54 @@ async function main() {
1536
1546
  return a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0;
1537
1547
  })
1538
1548
  .map(([name]) => name);
1539
- const out = Buffer.from(JSON.stringify(sorted) + '\\n', 'utf-8');
1540
- writeSync(resFd, out, 0, out.length);
1549
+ response = Buffer.from(JSON.stringify(sorted), 'utf-8');
1541
1550
  } catch {
1542
- const out = Buffer.from('null\\n', 'utf-8');
1543
- writeSync(resFd, out, 0, out.length);
1551
+ response = Buffer.from('null', 'utf-8');
1544
1552
  }
1545
- }
1546
1553
 
1547
- closeSync(reqFd);
1548
- closeSync(resFd);
1554
+ dataArea.set(response, 0);
1555
+ lengthView.setUint32(0, response.length);
1556
+
1557
+ Atomics.store(control, 1, 1); // signal response
1558
+ Atomics.notify(control, 1);
1559
+ }
1549
1560
  }
1550
- main().catch(() => process.exit(1));
1561
+ main();
1551
1562
  `;
1552
- let child = null;
1553
- let reqPipe = null;
1554
- let resPipe = null;
1555
- let reqFd = null;
1556
- let resFd = null;
1563
+ let worker = null;
1564
+ let controlArray = null;
1565
+ let lengthView = null;
1566
+ let dataArea = null;
1557
1567
  let initialized = false;
1558
1568
  let available = true;
1559
- let readBuffer = "";
1560
- /** Read a newline-delimited line from an open file descriptor (blocking). */
1561
- function readLineSync(fd) {
1562
- while (true) {
1563
- const nlIdx = readBuffer.indexOf("\n");
1564
- if (nlIdx >= 0) {
1565
- const line = readBuffer.slice(0, nlIdx);
1566
- readBuffer = readBuffer.slice(nlIdx + 1);
1567
- return line;
1568
- }
1569
- const buf = Buffer.alloc(65536);
1570
- const n = readSync(fd, buf, 0, buf.length, null);
1571
- if (n === 0) throw new Error("EOF");
1572
- readBuffer += buf.toString("utf-8", 0, n);
1573
- }
1574
- }
1575
1569
  function ensureService(cssPath) {
1576
1570
  if (initialized) return available;
1577
1571
  initialized = true;
1578
1572
  try {
1579
- const id = `${process.pid}-${Date.now()}`;
1580
- reqPipe = join(tmpdir(), `oxlint-tw-req-${id}`);
1581
- resPipe = join(tmpdir(), `oxlint-tw-res-${id}`);
1582
- execFileSync("mkfifo", [reqPipe]);
1583
- execFileSync("mkfifo", [resPipe]);
1584
- child = spawn(process.execPath, ["-e", SORT_WORKER_SCRIPT], {
1585
- env: {
1586
- ...process.env,
1587
- TAILWIND_CSS_PATH: cssPath,
1588
- REQ_PIPE: reqPipe,
1589
- RES_PIPE: resPipe
1590
- },
1591
- cwd: dirname(cssPath),
1592
- stdio: "ignore",
1593
- detached: false
1573
+ const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE);
1574
+ controlArray = new Int32Array(sharedBuffer, 0, HEADER_INTS);
1575
+ lengthView = new DataView(sharedBuffer, HEADER_INTS * 4, 4);
1576
+ dataArea = new Uint8Array(sharedBuffer, DATA_OFFSET);
1577
+ worker = new Worker(WORKER_SCRIPT, {
1578
+ eval: true,
1579
+ workerData: {
1580
+ sharedBuffer,
1581
+ cssPath
1582
+ }
1594
1583
  });
1595
- child.unref();
1596
- child.on("error", () => {
1597
- child = null;
1584
+ worker.unref();
1585
+ worker.on("error", () => {
1598
1586
  available = false;
1587
+ worker = null;
1599
1588
  });
1600
- child.on("exit", () => {
1601
- child = null;
1589
+ worker.on("exit", () => {
1590
+ worker = null;
1602
1591
  });
1603
- reqFd = openSync(reqPipe, "w");
1604
- resFd = openSync(resPipe, "r");
1592
+ if (Atomics.wait(controlArray, 2, 0, INIT_TIMEOUT) === "timed-out" || controlArray[2] === -1) {
1593
+ available = false;
1594
+ cleanup();
1595
+ return false;
1596
+ }
1605
1597
  process.on("exit", cleanup);
1606
1598
  return true;
1607
1599
  } catch {
@@ -1611,49 +1603,36 @@ function ensureService(cssPath) {
1611
1603
  }
1612
1604
  }
1613
1605
  function cleanup() {
1614
- if (reqFd !== null) {
1615
- try {
1616
- closeSync(reqFd);
1617
- } catch {}
1618
- reqFd = null;
1619
- }
1620
- if (resFd !== null) {
1606
+ if (worker) {
1621
1607
  try {
1622
- closeSync(resFd);
1608
+ worker.terminate();
1623
1609
  } catch {}
1624
- resFd = null;
1625
- }
1626
- if (child) {
1627
- try {
1628
- child.kill();
1629
- } catch {}
1630
- child = null;
1631
- }
1632
- if (reqPipe) {
1633
- try {
1634
- unlinkSync(reqPipe);
1635
- } catch {}
1636
- reqPipe = null;
1637
- }
1638
- if (resPipe) {
1639
- try {
1640
- unlinkSync(resPipe);
1641
- } catch {}
1642
- resPipe = null;
1610
+ worker = null;
1643
1611
  }
1644
1612
  }
1645
1613
  /**
1646
- * Sort classes using the official Tailwind CSS sort order via persistent child process.
1614
+ * Sort classes using the official Tailwind CSS sort order via worker thread.
1647
1615
  * Returns the sorted class array, or null if the service is unavailable.
1648
1616
  */
1649
1617
  function sortClassesSync(cssPath, classes) {
1650
1618
  if (!ensureService(cssPath)) return null;
1651
- if (reqFd === null || resFd === null) return null;
1619
+ if (!controlArray || !dataArea || !lengthView) return null;
1652
1620
  try {
1653
- const payload = Buffer.from(JSON.stringify(classes) + "\n", "utf-8");
1654
- writeSync(reqFd, payload, 0, payload.length);
1655
- const line = readLineSync(resFd);
1656
- return JSON.parse(line);
1621
+ const request = Buffer.from(JSON.stringify(classes), "utf-8");
1622
+ if (request.length > BUFFER_SIZE - DATA_OFFSET) return null;
1623
+ dataArea.set(request, 0);
1624
+ lengthView.setUint32(0, request.length);
1625
+ Atomics.store(controlArray, 0, 1);
1626
+ Atomics.notify(controlArray, 0);
1627
+ if (Atomics.wait(controlArray, 1, 0, REQUEST_TIMEOUT) === "timed-out") {
1628
+ available = false;
1629
+ cleanup();
1630
+ return null;
1631
+ }
1632
+ const responseLen = lengthView.getUint32(0);
1633
+ const responseStr = Buffer.from(dataArea.slice(0, responseLen)).toString("utf-8");
1634
+ Atomics.store(controlArray, 1, 0);
1635
+ return JSON.parse(responseStr);
1657
1636
  } catch {
1658
1637
  available = false;
1659
1638
  cleanup();