@@ -12,13 +12,13 @@ import resolveConfigFallback from 'tailwindcss/resolveConfig'
1212import * as recast from 'recast'
1313import * as astTypes from 'ast-types'
1414import * as path from 'path'
15- import * as fs from 'fs'
1615import requireFrom from 'import-from'
1716import requireFresh from 'import-fresh'
1817import objectHash from 'object-hash'
1918import * as svelte from 'prettier-plugin-svelte'
2019import lineColumn from 'line-column'
2120import jsesc from 'jsesc'
21+ import escalade from 'escalade/sync'
2222
2323let contextMap = new Map ( )
2424
@@ -129,23 +129,35 @@ function createParser(original, transform) {
129129 let createContext = createContextFallback
130130 let generateRules = generateRulesFallback
131131
132+ let baseDir
132133 let prettierConfigPath = prettier . resolveConfigFile . sync ( options . filepath )
133- let baseDir = prettierConfigPath
134- ? path . dirname ( prettierConfigPath )
135- : process . env . VSCODE_CWD ?? process . cwd ( )
136134
137135 if ( options . tailwindConfig ) {
136+ baseDir = prettierConfigPath
137+ ? path . dirname ( prettierConfigPath )
138+ : process . cwd ( )
138139 tailwindConfigPath = path . resolve ( baseDir , options . tailwindConfig )
139140 tailwindConfig = requireFresh ( tailwindConfigPath )
140141 } 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 )
149161 }
150162 }
151163
0 commit comments