@@ -12,13 +12,13 @@ import resolveConfigFallback from 'tailwindcss/resolveConfig'
12
12
import * as recast from 'recast'
13
13
import * as astTypes from 'ast-types'
14
14
import * as path from 'path'
15
- import * as fs from 'fs'
16
15
import requireFrom from 'import-from'
17
16
import requireFresh from 'import-fresh'
18
17
import objectHash from 'object-hash'
19
18
import * as svelte from 'prettier-plugin-svelte'
20
19
import lineColumn from 'line-column'
21
20
import jsesc from 'jsesc'
21
+ import escalade from 'escalade/sync'
22
22
23
23
let contextMap = new Map ( )
24
24
@@ -129,23 +129,35 @@ function createParser(original, transform) {
129
129
let createContext = createContextFallback
130
130
let generateRules = generateRulesFallback
131
131
132
+ let baseDir
132
133
let prettierConfigPath = prettier . resolveConfigFile . sync ( options . filepath )
133
- let baseDir = prettierConfigPath
134
- ? path . dirname ( prettierConfigPath )
135
- : process . env . VSCODE_CWD ?? process . cwd ( )
136
134
137
135
if ( options . tailwindConfig ) {
136
+ baseDir = prettierConfigPath
137
+ ? path . dirname ( prettierConfigPath )
138
+ : process . cwd ( )
138
139
tailwindConfigPath = path . resolve ( baseDir , options . tailwindConfig )
139
140
tailwindConfig = requireFresh ( tailwindConfigPath )
140
141
} else {
141
- let tailwindConfigPathJs = path . resolve ( baseDir , 'tailwind.config.js' )
142
- let tailwindConfigPathCjs = path . resolve ( baseDir , 'tailwind.config.cjs' )
143
- if ( fs . existsSync ( tailwindConfigPathJs ) ) {
144
- tailwindConfigPath = tailwindConfigPathJs
145
- tailwindConfig = requireFresh ( tailwindConfigPathJs )
146
- } else if ( fs . existsSync ( tailwindConfigPathCjs ) ) {
147
- tailwindConfigPath = tailwindConfigPathCjs
148
- tailwindConfig = requireFresh ( tailwindConfigPathCjs )
142
+ baseDir = prettierConfigPath
143
+ ? path . dirname ( prettierConfigPath )
144
+ : options . filepath
145
+ ? path . dirname ( options . filepath )
146
+ : process . cwd ( )
147
+ let configPath
148
+ try {
149
+ configPath = escalade ( baseDir , ( _dir , names ) => {
150
+ if ( names . includes ( 'tailwind.config.js' ) ) {
151
+ return 'tailwind.config.js'
152
+ }
153
+ if ( names . includes ( 'tailwind.config.cjs' ) ) {
154
+ return 'tailwind.config.cjs'
155
+ }
156
+ } )
157
+ } catch { }
158
+ if ( configPath ) {
159
+ tailwindConfigPath = configPath
160
+ tailwindConfig = requireFresh ( configPath )
149
161
}
150
162
}
151
163
0 commit comments