Skip to content

Commit 086ffff

Browse files
Fix v4 theme reloading on Windows (tailwindlabs#960)
We now normalize case of windows drive letters of watched files because we may recieve a path that has `C:` at the start of a path in some places and `c:` in others because they’re coming from different sources (filesystem vs VS Code file watching notifications).
1 parent 9d7006d commit 086ffff

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/tailwindcss-language-server/src/tw.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import resolveFrom from './util/resolveFrom'
4040
import * as parcel from './watcher/index.js'
4141
import { equal } from '@tailwindcss/language-service/src/util/array'
4242
import { CONFIG_GLOB, CSS_GLOB, PACKAGE_LOCK_GLOB } from './lib/constants'
43-
import { clearRequireCache, isObject, changeAffectsFile } from './utils'
43+
import { clearRequireCache, isObject, changeAffectsFile, normalizeDriveLetter } from './utils'
4444
import { DocumentService } from './documents'
4545
import { createProjectService, type ProjectService } from './projects'
4646
import { type SettingsCache, createSettingsCache } from './config'
@@ -273,6 +273,7 @@ export class TW {
273273

274274
changeLoop: for (let change of changes) {
275275
let normalizedFilename = normalizePath(change.file)
276+
normalizedFilename = normalizeDriveLetter(normalizedFilename)
276277

277278
for (let ignorePattern of ignore) {
278279
let isIgnored = picomatch(ignorePattern, { dot: true })
@@ -312,6 +313,8 @@ export class TW {
312313
...project.projectConfig.config.entries.map((entry) => entry.path),
313314
]
314315

316+
reloadableFiles = reloadableFiles.map(normalizeDriveLetter)
317+
315318
if (!changeAffectsFile(normalizedFilename, reloadableFiles)) continue
316319

317320
needsSoftRestart = true

packages/tailwindcss-language-server/src/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ export function dirContains(dir: string, file: string): boolean {
7070
return !!relative && !relative.startsWith('..') && !path.isAbsolute(relative)
7171
}
7272

73+
const WIN_DRIVE_LETTER = /^([a-zA-Z]):/
74+
75+
/**
76+
* Windows drive letters are case-insensitive and we may get them as either
77+
* lower or upper case. This function normalizes the drive letter to uppercase
78+
* to be consistent with the rest of the codebase.
79+
*/
80+
export function normalizeDriveLetter(filepath: string) {
81+
return filepath.replace(WIN_DRIVE_LETTER, (_, letter) => letter.toUpperCase() + ':')
82+
}
83+
7384
export function changeAffectsFile(change: string, files: string[]): boolean {
7485
for (let file of files) {
7586
if (change === file || dirContains(change, file)) {

0 commit comments

Comments
 (0)