Skip to content

Commit 02c924a

Browse files
committed
Fix resolution of paths that contain a #
1 parent 899e734 commit 02c924a

File tree

1 file changed

+16
-1
lines changed
  • packages/tailwindcss-language-server/src/resolver

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export async function createResolver(opts: ResolverOptions): Promise<Resolver> {
196196
id = normalizeYarnPnPDriveLetter(id)
197197
base = normalizeYarnPnPDriveLetter(base)
198198

199-
return new Promise((resolve, reject) => {
199+
let result = await new Promise<string | false>((resolve, reject) => {
200200
resolver.resolve({}, base, id, {}, (err, res) => {
201201
if (err) {
202202
reject(err)
@@ -205,6 +205,21 @@ export async function createResolver(opts: ResolverOptions): Promise<Resolver> {
205205
}
206206
})
207207
})
208+
209+
if (!result) return false
210+
211+
// The `enhanced-resolve` package supports resolving paths with fragment
212+
// identifiers. For example, it can resolve `foo/bar#baz` to `foo/bar.js`
213+
// However, it's also possible that a path contains a `#` character as part
214+
// of the path itself. For example, `foo#bar` might point to a file named
215+
// `foo#bar.js`. The resolver distinguishes between these two cases by
216+
// escaping the `#` character with a NUL byte when it's part of the path.
217+
//
218+
// Since the real path doesn't actually contain NUL bytes, we need to remove
219+
// them to get the correct path otherwise readFileSync will throw an error.
220+
result = result.replace(/\0(.)/g, '$1')
221+
222+
return result
208223
}
209224

210225
async function resolveJsId(id: string, base: string): Promise<string> {

0 commit comments

Comments
 (0)