Commit 08c6c96
Improve multi-root
This PR improves the discoverability of Tailwind config files when we
are trying to link them to your CSS files.
When you have multiple "root" CSS files in your project, and if they
don't include an `@config` directive, then we tried to find the Tailwind
config file in your current working directory.
This means that if you run the upgrade command from the root of your
project, and you have a nested folder with a separate Tailwind setup,
then the nested CSS file would link to the root Tailwind config file.
Visually, you can think of it like this:
```
.
├── admin
│ ├── src
│ │ └── styles
│ │ └── index.css <-- This will be linked to (1)
│ └── tailwind.config.js (2)
├── src
│ └── styles
│ └── index.css <-- This will be linked to (1)
└── tailwind.config.js (1)
```
If you run the upgrade command from the root of your project, then the
`/src/styles/index.css` will be linked to `/tailwind.config.js` which is
what we expect.
But `/admin/src/styles/index.css` will _also_ be linked to
`/tailwind.config.js`
With this PR we improve this behavior by looking at the CSS file, and
crawling up the parent tree. This mens that the new behavior looks like
this:
```
.
├── admin
│ ├── src
│ │ └── styles
│ │ └── index.css <-- This will be linked to (2)
│ └── tailwind.config.js (2)
├── src
│ └── styles
│ └── index.css <-- This will be linked to (1)
└── tailwind.config.js (1)
```
Now `/src/styles/index.css` will be linked to `/tailwind.config.js`, and
`/admin/src/styles/index.css` will be linked to
`/admin/tailwind.config.js`.
When we discover the Tailwind config file, we will also print a message
to the user to let them know which CSS file is linked to which Tailwind
config file.
This should be a safe improvement because if your Tailwind config file
had a different name, or if it lived in a sibling folder then Tailwind
wouldn't find it either and you already required a `@config "…";`
directive in your CSS file to point to the correct file.
In the unlikely event that it turns out that 2 (or more) CSS files
resolve to the same to the same Tailwind config file, then an upgrade
might not be safe and some manual intervention might be needed. In this
case, we will show a warning about this.
<img width="1552" alt="image"
src="https://github.com/user-attachments/assets/7a1ad11d-18c5-4b7d-9a02-14f0116ae955">
Test plan:
---
- Added an integration test that properly links the nearest Tailwind
config file by looking up the tree
- Added an integration test that resolves 2 or more CSS files to the
same config file, resulting in an error where manual intervention is
needed
- Ran it on the Tailwind UI codebase
Running this on Tailwind UI's codebase it looks like this:
<img width="1552" alt="image"
src="https://github.com/user-attachments/assets/21785428-5e0d-47f7-80ec-dab497f58784">
---------
Co-authored-by: Jordan Pittman <jordan@cryptica.me>@config linking (#15001)1 parent dd3441b commit 08c6c96
File tree
9 files changed
+287
-104
lines changed- integrations
- upgrade
- packages/@tailwindcss-upgrade/src
- template
9 files changed
+287
-104
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1385 | 1385 | | |
1386 | 1386 | | |
1387 | 1387 | | |
1388 | | - | |
1389 | | - | |
1390 | | - | |
| 1388 | + | |
1391 | 1389 | | |
1392 | 1390 | | |
1393 | 1391 | | |
| |||
1396 | 1394 | | |
1397 | 1395 | | |
1398 | 1396 | | |
1399 | | - | |
| 1397 | + | |
1400 | 1398 | | |
1401 | 1399 | | |
1402 | 1400 | | |
1403 | 1401 | | |
1404 | 1402 | | |
1405 | | - | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
1406 | 1412 | | |
1407 | 1413 | | |
1408 | 1414 | | |
1409 | 1415 | | |
1410 | | - | |
| 1416 | + | |
1411 | 1417 | | |
1412 | | - | |
| 1418 | + | |
1413 | 1419 | | |
1414 | 1420 | | |
1415 | 1421 | | |
| |||
1425 | 1431 | | |
1426 | 1432 | | |
1427 | 1433 | | |
1428 | | - | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
1429 | 1443 | | |
1430 | | - | |
1431 | | - | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
1432 | 1454 | | |
1433 | 1455 | | |
1434 | 1456 | | |
1435 | 1457 | | |
1436 | | - | |
| 1458 | + | |
1437 | 1459 | | |
1438 | 1460 | | |
1439 | | - | |
| 1461 | + | |
| 1462 | + | |
1440 | 1463 | | |
1441 | 1464 | | |
1442 | 1465 | | |
| |||
1450 | 1473 | | |
1451 | 1474 | | |
1452 | 1475 | | |
1453 | | - | |
| 1476 | + | |
1454 | 1477 | | |
1455 | 1478 | | |
1456 | 1479 | | |
1457 | | - | |
| 1480 | + | |
1458 | 1481 | | |
1459 | 1482 | | |
1460 | 1483 | | |
| |||
1474 | 1497 | | |
1475 | 1498 | | |
1476 | 1499 | | |
1477 | | - | |
| 1500 | + | |
1478 | 1501 | | |
1479 | 1502 | | |
1480 | 1503 | | |
1481 | | - | |
| 1504 | + | |
1482 | 1505 | | |
1483 | 1506 | | |
1484 | 1507 | | |
| |||
1498 | 1521 | | |
1499 | 1522 | | |
1500 | 1523 | | |
1501 | | - | |
| 1524 | + | |
1502 | 1525 | | |
1503 | 1526 | | |
1504 | 1527 | | |
1505 | | - | |
| 1528 | + | |
1506 | 1529 | | |
1507 | 1530 | | |
1508 | 1531 | | |
| |||
1532 | 1555 | | |
1533 | 1556 | | |
1534 | 1557 | | |
1535 | | - | |
| 1558 | + | |
1536 | 1559 | | |
1537 | | - | |
1538 | | - | |
1539 | | - | |
1540 | | - | |
| 1560 | + | |
| 1561 | + | |
1541 | 1562 | | |
1542 | | - | |
1543 | | - | |
| 1563 | + | |
1544 | 1564 | | |
1545 | 1565 | | |
1546 | 1566 | | |
| |||
1567 | 1587 | | |
1568 | 1588 | | |
1569 | 1589 | | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
1570 | 1593 | | |
1571 | 1594 | | |
| 1595 | + | |
1572 | 1596 | | |
1573 | 1597 | | |
1574 | 1598 | | |
| |||
1595 | 1619 | | |
1596 | 1620 | | |
1597 | 1621 | | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
1598 | 1700 | | |
1599 | 1701 | | |
1600 | 1702 | | |
1601 | 1703 | | |
1602 | 1704 | | |
1603 | 1705 | | |
1604 | 1706 | | |
| 1707 | + | |
1605 | 1708 | | |
1606 | 1709 | | |
1607 | 1710 | | |
| |||
1662 | 1765 | | |
1663 | 1766 | | |
1664 | 1767 | | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
1665 | 1771 | | |
1666 | 1772 | | |
1667 | 1773 | | |
1668 | 1774 | | |
1669 | 1775 | | |
1670 | | - | |
1671 | | - | |
1672 | | - | |
1673 | 1776 | | |
1674 | 1777 | | |
1675 | 1778 | | |
| |||
1735 | 1838 | | |
1736 | 1839 | | |
1737 | 1840 | | |
| 1841 | + | |
1738 | 1842 | | |
1739 | 1843 | | |
1740 | 1844 | | |
| |||
1797 | 1901 | | |
1798 | 1902 | | |
1799 | 1903 | | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
1800 | 1907 | | |
1801 | 1908 | | |
1802 | 1909 | | |
1803 | 1910 | | |
1804 | 1911 | | |
1805 | | - | |
1806 | | - | |
1807 | | - | |
1808 | 1912 | | |
1809 | 1913 | | |
1810 | 1914 | | |
| |||
2105 | 2209 | | |
2106 | 2210 | | |
2107 | 2211 | | |
2108 | | - | |
2109 | | - | |
2110 | | - | |
2111 | | - | |
2112 | | - | |
2113 | | - | |
2114 | | - | |
2115 | 2212 | | |
2116 | 2213 | | |
2117 | 2214 | | |
| |||
2141 | 2238 | | |
2142 | 2239 | | |
2143 | 2240 | | |
| 2241 | + | |
| 2242 | + | |
| 2243 | + | |
| 2244 | + | |
| 2245 | + | |
| 2246 | + | |
| 2247 | + | |
2144 | 2248 | | |
2145 | 2249 | | |
2146 | 2250 | | |
| |||
2196 | 2300 | | |
2197 | 2301 | | |
2198 | 2302 | | |
2199 | | - | |
2200 | | - | |
2201 | | - | |
2202 | 2303 | | |
2203 | 2304 | | |
2204 | 2305 | | |
| |||
2220 | 2321 | | |
2221 | 2322 | | |
2222 | 2323 | | |
| 2324 | + | |
| 2325 | + | |
| 2326 | + | |
2223 | 2327 | | |
2224 | 2328 | | |
2225 | 2329 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
349 | | - | |
| 349 | + | |
350 | 350 | | |
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
354 | 354 | | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
355 | 361 | | |
356 | | - | |
357 | | - | |
| 362 | + | |
| 363 | + | |
358 | 364 | | |
359 | 365 | | |
360 | 366 | | |
| |||
0 commit comments