Skip to content

Commit aaa3b70

Browse files
Normalize Windows drive letters in more places (#1001)
* Normalize dynamically loaded content paths These were not being handled properly * Normalize module dependency paths These are likely to be uppercase but just in case they’re not * Normalize CSS config file path * Normalize changed file paths in watcher * Normalize custom config file paths
1 parent cb62a7f commit aaa3b70

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import {
7272
pathToFileURL,
7373
changeAffectsFile,
7474
normalizePath,
75+
normalizeDriveLetter,
7576
} from './utils'
7677
import type { DocumentService } from './documents'
7778
import type { ProjectConfig } from './project-locator'
@@ -266,7 +267,7 @@ export async function createProjectService(
266267
let isPackageMatcher = picomatch(`**/${PACKAGE_LOCK_GLOB}`, { dot: true })
267268

268269
for (let change of changes) {
269-
let file = normalizePath(change.file)
270+
let file = normalizeDriveLetter(normalizePath(change.file))
270271

271272
let isConfigFile = changeAffectsFile(file, [projectConfig.configPath])
272273
let isDependency = changeAffectsFile(file, state.dependencies ?? [])
@@ -1552,7 +1553,7 @@ function getContentDocumentSelectorFromConfigFile(
15521553
: path.resolve(contentBase, item),
15531554
)
15541555
.map((item) => ({
1555-
pattern: normalizePath(item),
1556+
pattern: normalizeDriveLetter(normalizePath(item)),
15561557
priority: DocumentSelectorPriority.CONTENT_FILE,
15571558
}))
15581559
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ async function getConfigFileFromCssFile(cssFile: string): Promise<string | null>
7777
if (!match) {
7878
return null
7979
}
80-
return normalizePath(path.resolve(path.dirname(cssFile), match.groups.config.slice(1, -1)))
80+
return normalizeDriveLetter(
81+
normalizePath(path.resolve(path.dirname(cssFile), match.groups.config.slice(1, -1))),
82+
)
8183
}
8284

8385
export class TW {
@@ -191,7 +193,7 @@ export class TW {
191193

192194
function getExplicitConfigFiles(settings: TailwindCssSettings) {
193195
function resolvePathForConfig(filepath: string) {
194-
return normalizePath(path.resolve(userDefinedConfigBase, filepath))
196+
return normalizeDriveLetter(normalizePath(path.resolve(userDefinedConfigBase, filepath)))
195197
}
196198

197199
let configFileOrFiles = settings.experimental.configFile
@@ -334,7 +336,11 @@ export class TW {
334336

335337
let isCssFile = isCssMatcher(`**/${CSS_GLOB}`)
336338
if (isCssFile && change.type !== FileChangeType.Deleted) {
337-
let configPath = await getConfigFileFromCssFile(change.file)
339+
// TODO: Determine if we can only use `normalizedFilename`
340+
let configPath =
341+
(await getConfigFileFromCssFile(normalizedFilename)) ||
342+
(await getConfigFileFromCssFile(change.file))
343+
338344
if (
339345
cssFileConfigMap.has(normalizedFilename) &&
340346
cssFileConfigMap.get(normalizedFilename) !== configPath

packages/tailwindcss-language-server/src/util/getModuleDependencies.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// https://github.com/tailwindlabs/tailwindcss/blob/bac5ecf0040aa9a788d1b22d706506146ee831ff/src/lib/getModuleDependencies.js
22
import fs from 'fs'
33
import path from 'path'
4-
import { normalizePath } from '../utils'
4+
import { normalizeDriveLetter, normalizePath } from '../utils'
55

66
let jsExtensions = ['.js', '.cjs', '.mjs']
77

@@ -83,5 +83,5 @@ export function getModuleDependencies(absoluteFilePath: string): string[] {
8383
_getModuleDependencies(absoluteFilePath, path.dirname(absoluteFilePath), new Set()),
8484
)
8585
.filter((file) => file !== absoluteFilePath)
86-
.map((file) => normalizePath(file))
86+
.map((file) => normalizeDriveLetter(normalizePath(file)))
8787
}

0 commit comments

Comments
 (0)