Skip to content

Commit 70a7aaa

Browse files
committed
Fix drive-letter case-sensitivity on Windows
1 parent e3d6f94 commit 70a7aaa

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

packages/tailwindcss-language-server/src/resolver/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from 'enhanced-resolve'
99
import { loadPnPApi, type PnpApi } from './pnp'
1010
import { loadTsConfig, type TSConfigApi } from './tsconfig'
11+
import { normalizeYarnPnPDriveLetter } from '../utils'
1112

1213
export interface ResolverOptions {
1314
/**
@@ -183,6 +184,10 @@ export async function createResolver(opts: ResolverOptions): Promise<Resolver> {
183184
if (match) id = match
184185
}
185186

187+
// 2. Normalize the drive letters to the case that the PnP API expects
188+
id = normalizeYarnPnPDriveLetter(id)
189+
base = normalizeYarnPnPDriveLetter(base)
190+
186191
return new Promise((resolve, reject) => {
187192
resolver.resolve({}, base, id, {}, (err, res) => {
188193
if (err) {

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,42 @@ export function dirContains(dir: string, file: string): boolean {
7474
}
7575

7676
const WIN_DRIVE_LETTER = /^([a-zA-Z]):/
77+
const POSIX_DRIVE_LETTER = /^\/([a-zA-Z]):/
7778

7879
/**
7980
* Windows drive letters are case-insensitive and we may get them as either
8081
* lower or upper case. This function normalizes the drive letter to uppercase
8182
* to be consistent with the rest of the codebase.
8283
*/
8384
export function normalizeDriveLetter(filepath: string) {
84-
return filepath.replace(WIN_DRIVE_LETTER, (_, letter) => letter.toUpperCase() + ':')
85+
return filepath
86+
.replace(WIN_DRIVE_LETTER, (_, letter) => `${letter.toUpperCase()}:`)
87+
.replace(POSIX_DRIVE_LETTER, (_, letter) => `/${letter.toUpperCase()}:`)
88+
}
89+
90+
/**
91+
* Windows drive letters are case-insensitive and we may get them as either
92+
* lower or upper case.
93+
*
94+
* Yarn PnP only works when requests have the correct case for the drive letter
95+
* that matches the drive letter of the current working directory.
96+
*
97+
* Even using makeApi with a custom base path doesn't work around this.
98+
*/
99+
export function normalizeYarnPnPDriveLetter(filepath: string) {
100+
let cwdDriveLetter = process.cwd().match(WIN_DRIVE_LETTER)?.[1]
101+
102+
return filepath
103+
.replace(WIN_DRIVE_LETTER, (_, letter) => {
104+
return letter.toUpperCase() === cwdDriveLetter.toUpperCase()
105+
? `${cwdDriveLetter}:`
106+
: `${letter.toUpperCase()}:`
107+
})
108+
.replace(POSIX_DRIVE_LETTER, (_, letter) => {
109+
return letter.toUpperCase() === cwdDriveLetter.toUpperCase()
110+
? `/${cwdDriveLetter}:`
111+
: `/${letter.toUpperCase()}:`
112+
})
85113
}
86114

87115
export function changeAffectsFile(change: string, files: Iterable<string>): boolean {

0 commit comments

Comments
 (0)