@@ -2,16 +2,21 @@ import path from 'node:path'
2
2
import process from 'node:process'
3
3
import postcss from 'postcss'
4
4
import { lilconfig } from 'lilconfig'
5
- import createJiti from 'jiti'
6
- import { requireResolve } from '@/utils'
5
+ import { jiti } from '@/ jiti'
6
+ import { defu , requireResolve } from '@/utils'
7
7
8
- const jiti = createJiti ( __filename )
8
+ export interface ProcessTailwindcssOptions {
9
+ cwd ?: string
10
+ config ?: string
11
+ }
9
12
10
- export async function processTailwindcss ( options : { cwd ?: string , config ?: string } ) {
11
- options . cwd = options . cwd ?? process . cwd ( )
12
- let config = options . config
13
+ export async function processTailwindcss ( options : ProcessTailwindcssOptions ) {
14
+ const { config : userConfig , cwd } = defu < ProcessTailwindcssOptions , ProcessTailwindcssOptions [ ] > ( options , {
15
+ cwd : process . cwd ( ) ,
16
+ } )
17
+ let config = userConfig
13
18
// 没有具体指定的话,就走下面的分支
14
- if ( ! ( typeof options . config === 'string' && path . isAbsolute ( options . config ) ) ) {
19
+ if ( ! ( typeof config === 'string' && path . isAbsolute ( config ) ) ) {
15
20
const moduleName = 'tailwind'
16
21
const result = await lilconfig ( 'tailwindcss' , {
17
22
searchPlaces : [
@@ -31,14 +36,14 @@ export async function processTailwindcss(options: { cwd?: string, config?: strin
31
36
'.cts' : jiti ,
32
37
'.mts' : jiti ,
33
38
} ,
34
- } ) . search ( options . cwd )
39
+ } ) . search ( cwd )
35
40
if ( ! result ) {
36
- throw new Error ( `No TailwindCSS Config found in: ${ options . cwd } ` )
41
+ throw new Error ( `No TailwindCSS Config found in: ${ cwd } ` )
37
42
}
38
43
config = result . filepath
39
44
}
40
45
const id = requireResolve ( 'tailwindcss' , {
41
- basedir : options . cwd ,
46
+ basedir : cwd ,
42
47
} )
43
48
return await postcss ( [
44
49
// eslint-disable-next-line ts/no-var-requires, ts/no-require-imports
0 commit comments