Skip to content

Commit a499e52

Browse files
Avoid two-pass resolution for some cases
1 parent 3631fae commit a499e52

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

packages/@tailwindcss-node/src/compile.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import EnhancedResolve from 'enhanced-resolve'
22
import { createJiti, type Jiti } from 'jiti'
33
import fs from 'node:fs'
44
import fsPromises from 'node:fs/promises'
5-
import path, { dirname } from 'node:path'
5+
import path, { dirname, extname } from 'node:path'
66
import { pathToFileURL } from 'node:url'
77
import { compile as _compile } from 'tailwindcss'
88
import { getModuleDependencies } from './get-module-dependencies'
@@ -100,13 +100,22 @@ async function resolveCssId(id: string, base: string): Promise<string | false |
100100
}
101101
}
102102

103-
try {
104-
let dotResolved = await runResolver(cssResolver, `./${id}`, base)
105-
if (!dotResolved) throw new Error()
106-
return dotResolved
107-
} catch {
108-
return runResolver(cssResolver, id, base)
103+
// CSS imports that do not have a dir prefix are considered relative. Since
104+
// the resolver does not account for this, we need to do a first pass with an
105+
// assumed relative import by prefixing `./${path}`. We don't have to do this
106+
// when the path starts with a `.` or when the path has no extension (at which
107+
// case it's likely an npm package and not a relative stylesheet).
108+
let skipRelativeCheck = extname(id) === '' || id.startsWith('.')
109+
110+
if (!skipRelativeCheck) {
111+
try {
112+
let dotResolved = await runResolver(cssResolver, `./${id}`, base)
113+
if (!dotResolved) throw new Error()
114+
return dotResolved
115+
} catch {}
109116
}
117+
118+
return runResolver(cssResolver, id, base)
110119
}
111120

112121
const jsResolver = EnhancedResolve.ResolverFactory.createResolver({

0 commit comments

Comments
 (0)