1
+ import type * as ts from 'typescript/lib/tsserverlibrary'
2
+
1
3
import * as Path from 'path'
2
4
import Module from 'module'
3
5
4
6
import { buildSync } from 'esbuild'
5
- import findUp from 'find-up'
6
- import locatePath from 'locate-path'
7
7
8
8
import type { Configuration } from 'twind'
9
9
@@ -24,12 +24,18 @@ const TAILWIND_CONFIG_FILES = [
24
24
// TODO use typescript to check files
25
25
// this.typescript.server.toNormalizedPath(fileName)
26
26
// 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
+ }
33
39
34
40
export const loadFile = < T > ( file : string , cwd = process . cwd ( ) ) : T => {
35
41
const result = buildSync ( {
@@ -107,10 +113,11 @@ export const loadConfig = (configFile: string, cwd = process.cwd()): Configurati
107
113
}
108
114
109
115
export const getConfig = (
116
+ project : ts . server . Project ,
110
117
cwd = process . cwd ( ) ,
111
118
configFile ?: string ,
112
119
) : Configuration & { configFile : string | undefined } => {
113
- configFile ??= findConfig ( cwd )
120
+ configFile ??= findConfig ( project , cwd )
114
121
115
122
return {
116
123
...( configFile ? loadConfig ( Path . resolve ( cwd , configFile ) , cwd ) : { } ) ,
0 commit comments