Skip to content

Commit 2c1dea4

Browse files
Fix handling of absolute config files in upgrade tool (#15927)
Closes #15220 This PR fixes an issue where the upgrade tool would not be able to load some JavaScript config files across different drive letters on Windows. The issue in detail is that `path.relative(…)` tries to build a relative path but if the file is inside the same folder, it won't start the relative path with a `./` so we manually appended it in case that it isn't there. The issue on Windows specifically is that `file.relative(…)` can also return a legit absolute path, e.g. when the file is on a different drive. In this case we obviously don't want to prefix a path with `./`. ## Test plan To reproduce this issue, I checked out a Tailwind v3 project _on a different drive letter than my Windows installation_. In that case, I was adding a repo inside `D:` while `npm` was installed in `C:`. I then run `npx @tailwindcss/upgrade` to reproduce the issue. The fix was validated with a local `bun` run of the upgrade tool: ![telegram-cloud-photo-size-4-5818901845756725194-y](https://github.com/user-attachments/assets/d32b21e3-a08d-4608-b65a-93dddc04f890)
1 parent f1221b3 commit 2c1dea4

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Ensure CSS variable shorthand uses valid CSS variables ([#15738](https://github.com/tailwindlabs/tailwindcss/pull/15738))
1818
- Ensure font-size utilities with `none` modifier have a line-height set e.g.: `text-sm/none` ([#15921](https://github.com/tailwindlabs/tailwindcss/pull/15921))
1919
- Ensure font-size utilities with unknown modifier don't generate CSS ([#15921](https://github.com/tailwindlabs/tailwindcss/pull/15921))
20+
- _Upgrade_: Ensure JavaScript config files on different drives are correctly migrated ([#15927](https://github.com/tailwindlabs/tailwindcss/pull/15927))
2021

2122
## [4.0.0] - 2025-01-21
2223

packages/@tailwindcss-upgrade/src/migrate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ export async function linkConfigs(
435435
// If the path points to a file in the same directory, `path.relative` will
436436
// remove the leading `./` and we need to add it back in order to still
437437
// consider the path relative
438-
if (!relative.startsWith('.')) {
438+
if (!relative.startsWith('.') && !path.isAbsolute(relative)) {
439439
relative = './' + relative
440440
}
441441

packages/@tailwindcss-upgrade/src/template/prepare-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export async function prepareConfig(
4040
// If the path points to a file in the same directory, `path.relative` will
4141
// remove the leading `./` and we need to add it back in order to still
4242
// consider the path relative
43-
if (!relative.startsWith('.')) {
43+
if (!relative.startsWith('.') && !path.isAbsolute(relative)) {
4444
relative = './' + relative
4545
}
4646

@@ -49,7 +49,7 @@ export async function prepareConfig(
4949
let newPrefix = userConfig.prefix ? migratePrefix(userConfig.prefix) : null
5050
let input = css`
5151
@import 'tailwindcss' ${newPrefix ? `prefix(${newPrefix})` : ''};
52-
@config './${relative}';
52+
@config '${relative}';
5353
`
5454
5555
let [compiler, designSystem] = await Promise.all([

0 commit comments

Comments
 (0)