@@ -3,7 +3,11 @@ import os from "node:os";
33import path from "node:path" ;
44import { afterEach , beforeEach , describe , expect , it } from "vitest" ;
55import { TAILWIND_V4_IMPORT_REGEX } from "../src/constants" ;
6- import { extractSourcePatterns } from "../src/linter" ;
6+ import {
7+ extractImportSourceDirectives ,
8+ extractSourcePatterns ,
9+ } from "../src/linter" ;
10+ import { findTailwindConfigPath } from "../src/utils/config" ;
711import { readGitignorePatterns } from "../src/utils/fs" ;
812
913describe ( "extractSourcePatterns" , ( ) => {
@@ -97,6 +101,28 @@ describe("extractSourcePatterns", () => {
97101 } ) ;
98102} ) ;
99103
104+ describe ( "extractImportSourceDirectives" , ( ) => {
105+ it ( "should extract source roots from @import directives" , ( ) => {
106+ const css = `
107+ @import "tailwindcss" source("../src");
108+ @import "tailwindcss" source("./components");
109+ ` ;
110+
111+ expect ( extractImportSourceDirectives ( css ) ) . toEqual ( {
112+ roots : [ "../src" , "./components" ] ,
113+ disableAutoSource : false ,
114+ } ) ;
115+ } ) ;
116+
117+ it ( "should detect source(none)" , ( ) => {
118+ const css = `@import "tailwindcss" source(none);` ;
119+ expect ( extractImportSourceDirectives ( css ) ) . toEqual ( {
120+ roots : [ ] ,
121+ disableAutoSource : true ,
122+ } ) ;
123+ } ) ;
124+ } ) ;
125+
100126describe ( "TAILWIND_V4_IMPORT_REGEX" , ( ) => {
101127 it ( "should match standard @import tailwindcss" , ( ) => {
102128 expect ( TAILWIND_V4_IMPORT_REGEX . test ( '@import "tailwindcss"' ) ) . toBe ( true ) ;
@@ -222,3 +248,39 @@ describe("readGitignorePatterns", () => {
222248 expect ( patterns ) . toEqual ( [ "vendor/**" ] ) ;
223249 } ) ;
224250} ) ;
251+
252+ describe ( "findTailwindConfigPath" , ( ) => {
253+ let tmpDir : string ;
254+
255+ beforeEach ( ( ) => {
256+ tmpDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "tailwind-config-test-" ) ) ;
257+ } ) ;
258+
259+ afterEach ( ( ) => {
260+ fs . rmSync ( tmpDir , { recursive : true , force : true } ) ;
261+ } ) ;
262+
263+ it ( "should discover nested v3 config files recursively" , async ( ) => {
264+ const nestedDir = path . join ( tmpDir , "packages" , "web" ) ;
265+ fs . mkdirSync ( nestedDir , { recursive : true } ) ;
266+ fs . writeFileSync (
267+ path . join ( nestedDir , "tailwind.config.js" ) ,
268+ "module.exports = { content: ['./src/**/*.tsx'] }" ,
269+ ) ;
270+
271+ const discovered = await findTailwindConfigPath ( tmpDir ) ;
272+ expect ( discovered ) . toBe ( path . join ( nestedDir , "tailwind.config.js" ) ) ;
273+ } ) ;
274+
275+ it ( "should discover nested v4 css configs recursively" , async ( ) => {
276+ const nestedDir = path . join ( tmpDir , "apps" , "site" , "styles" ) ;
277+ fs . mkdirSync ( nestedDir , { recursive : true } ) ;
278+ fs . writeFileSync (
279+ path . join ( nestedDir , "theme.css" ) ,
280+ '@import "tailwindcss";' ,
281+ ) ;
282+
283+ const discovered = await findTailwindConfigPath ( tmpDir ) ;
284+ expect ( discovered ) . toBe ( path . join ( nestedDir , "theme.css" ) ) ;
285+ } ) ;
286+ } ) ;
0 commit comments