@@ -195,14 +195,15 @@ type ProjectConfig = {
195
195
documentSelector ?: Array < DocumentSelector >
196
196
}
197
197
198
- type DocumentSelector = { pattern : string ; priority : number }
199
198
enum DocumentSelectorPriority {
200
199
CONFIG_FILE = 0 ,
201
200
CSS_FILE = 0 ,
202
201
CONTENT_FILE = 1 ,
203
202
CSS_DIRECTORY = 2 ,
204
203
CONFIG_DIRECTORY = 3 ,
204
+ ROOT_DIRECTORY = 4 ,
205
205
}
206
+ type DocumentSelector = { pattern : string ; priority : DocumentSelectorPriority }
206
207
207
208
function getMode ( config : any ) : unknown {
208
209
if ( typeof config . mode !== 'undefined' ) {
@@ -1403,6 +1404,26 @@ async function getConfigFileFromCssFile(cssFile: string): Promise<string | null>
1403
1404
return path . resolve ( path . dirname ( cssFile ) , match . groups . config . slice ( 1 , - 1 ) )
1404
1405
}
1405
1406
1407
+ function getPackageRoot ( cwd : string , rootDir : string ) {
1408
+ try {
1409
+ let pkgJsonPath = findUp . sync (
1410
+ ( dir ) => {
1411
+ let pkgJson = path . join ( dir , 'package.json' )
1412
+ if ( findUp . sync . exists ( pkgJson ) ) {
1413
+ return pkgJson
1414
+ }
1415
+ if ( dir === rootDir ) {
1416
+ return findUp . stop
1417
+ }
1418
+ } ,
1419
+ { cwd }
1420
+ )
1421
+ return pkgJsonPath ? path . dirname ( pkgJsonPath ) : rootDir
1422
+ } catch {
1423
+ return rootDir
1424
+ }
1425
+ }
1426
+
1406
1427
function getContentDocumentSelectorFromConfigFile (
1407
1428
configPath : string ,
1408
1429
tailwindVersion : string ,
@@ -1419,19 +1440,7 @@ function getContentDocumentSelectorFromConfigFile(
1419
1440
if ( relativeEnabled ) {
1420
1441
contentBase = path . dirname ( configPath )
1421
1442
} else {
1422
- let pkgJsonPath = findUp . sync (
1423
- ( dir ) => {
1424
- let pkgJson = path . join ( dir , 'package.json' )
1425
- if ( findUp . sync . exists ( pkgJson ) ) {
1426
- return pkgJson
1427
- }
1428
- if ( dir === rootDir ) {
1429
- return findUp . stop
1430
- }
1431
- } ,
1432
- { cwd : path . dirname ( configPath ) }
1433
- )
1434
- contentBase = pkgJsonPath ? path . dirname ( pkgJsonPath ) : rootDir
1443
+ contentBase = getPackageRoot ( path . dirname ( configPath ) , rootDir )
1435
1444
}
1436
1445
return content
1437
1446
. filter ( ( item ) : item is string => typeof item === 'string' )
@@ -1587,6 +1596,10 @@ class TW {
1587
1596
}
1588
1597
: [ ]
1589
1598
)
1599
+ . concat ( {
1600
+ pattern : normalizePath ( path . join ( getPackageRoot ( path . dirname ( configPath ) , base ) , '**' ) ) ,
1601
+ priority : DocumentSelectorPriority . ROOT_DIRECTORY ,
1602
+ } )
1590
1603
projects [ configPath ] = [ ...( projects [ configPath ] ?? [ ] ) , ...documentSelector ]
1591
1604
if ( isCssFile ) {
1592
1605
cssFileConfigMap . set ( normalizedFilename , configPath )
0 commit comments