1+ import type * as ts from 'typescript/lib/tsserverlibrary'
2+
13import * as Path from 'path'
24import Module from 'module'
35
46import { buildSync } from 'esbuild'
5- import findUp from 'find-up'
6- import locatePath from 'locate-path'
77
88import type { Configuration } from 'twind'
99
@@ -24,12 +24,18 @@ const TAILWIND_CONFIG_FILES = [
2424// TODO use typescript to check files
2525// this.typescript.server.toNormalizedPath(fileName)
2626// info.project.containsFile()
27- export const findConfig = ( cwd = process . cwd ( ) ) : string | undefined =>
28- locatePath . sync ( TWIND_CONFIG_FILES . map ( ( file ) => Path . resolve ( cwd , 'config' , file ) ) ) ||
29- locatePath . sync ( TWIND_CONFIG_FILES . map ( ( file ) => Path . resolve ( cwd , 'src' , file ) ) ) ||
30- locatePath . sync ( TWIND_CONFIG_FILES . map ( ( file ) => Path . resolve ( cwd , 'public' , file ) ) ) ||
31- findUp . sync ( TWIND_CONFIG_FILES , { cwd } ) ||
32- findUp . sync ( TAILWIND_CONFIG_FILES , { cwd } )
27+ export const findConfig = ( project : ts . server . Project , cwd = process . cwd ( ) ) : string | undefined => {
28+ const locatePath = ( files : string [ ] ) =>
29+ files . map ( ( file ) => Path . resolve ( cwd , file ) ) . find ( ( file ) => project . fileExists ( file ) )
30+
31+ return (
32+ locatePath ( TWIND_CONFIG_FILES . map ( ( file ) => Path . join ( 'config' , file ) ) ) ||
33+ locatePath ( TWIND_CONFIG_FILES . map ( ( file ) => Path . join ( 'src' , file ) ) ) ||
34+ locatePath ( TWIND_CONFIG_FILES . map ( ( file ) => Path . join ( 'public' , file ) ) ) ||
35+ locatePath ( TWIND_CONFIG_FILES ) ||
36+ locatePath ( TAILWIND_CONFIG_FILES )
37+ )
38+ }
3339
3440export const loadFile = < T > ( file : string , cwd = process . cwd ( ) ) : T => {
3541 const result = buildSync ( {
@@ -107,10 +113,11 @@ export const loadConfig = (configFile: string, cwd = process.cwd()): Configurati
107113}
108114
109115export const getConfig = (
116+ project : ts . server . Project ,
110117 cwd = process . cwd ( ) ,
111118 configFile ?: string ,
112119) : Configuration & { configFile : string | undefined } => {
113- configFile ??= findConfig ( cwd )
120+ configFile ??= findConfig ( project , cwd )
114121
115122 return {
116123 ...( configFile ? loadConfig ( Path . resolve ( cwd , configFile ) , cwd ) : { } ) ,
0 commit comments