@@ -384,23 +384,14 @@ async function createProjectService(
384384
385385 if ( ! enabled ) {
386386 if ( projectConfig . configPath && ( isConfigFile || isDependency ) ) {
387- // update document selector
388- let originalConfig = require ( projectConfig . configPath )
389- let contentConfig : unknown = originalConfig . content ?. files ?? originalConfig . content
390- let content = Array . isArray ( contentConfig ) ? contentConfig : [ ]
391- // TODO `state.version` isn't going to exist here
392- let relativeEnabled = semver . gte ( state . version , '3.2.0' )
393- ? originalConfig . future ?. relativeContentPathsByDefault ||
394- originalConfig . content ?. relative
395- : false
396- let contentBase = relativeEnabled ? path . dirname ( state . configPath ) : projectConfig . folder
397- let contentSelector = content
398- . filter ( ( item ) : item is string => typeof item === 'string' )
399- . map ( ( item ) => path . resolve ( contentBase , item ) )
400- . map ( ( item ) => ( { pattern : normalizePath ( item ) , priority : 1 } ) )
401387 documentSelector = [
402388 ...documentSelector . filter ( ( { priority } ) => priority !== 1 ) ,
403- ...contentSelector ,
389+ // TODO `state.version` isn't going to exist here
390+ ...getContentDocumentSelectorFromConfigFile (
391+ projectConfig . configPath ,
392+ state . version ,
393+ projectConfig . folder
394+ ) ,
404395 ]
405396
406397 checkOpenDocuments ( )
@@ -502,6 +493,8 @@ async function createProjectService(
502493 throw new SilentError ( 'No config file found.' )
503494 }
504495
496+ watchPatterns ( [ configPath ] )
497+
505498 const pnpPath = findUp . sync (
506499 ( dir ) => {
507500 let pnpFile = path . join ( dir , '.pnp.js' )
@@ -916,19 +909,14 @@ async function createProjectService(
916909 }
917910
918911 /////////////////////
919- let contentConfig : unknown = originalConfig . content ?. files ?? originalConfig . content
920- let content = Array . isArray ( contentConfig ) ? contentConfig : [ ]
921- let relativeEnabled = semver . gte ( tailwindcss . version , '3.2.0' )
922- ? originalConfig . future ?. relativeContentPathsByDefault || originalConfig . content ?. relative
923- : false
924- let contentBase = relativeEnabled ? path . dirname ( state . configPath ) : projectConfig . folder
925- let contentSelector = content
926- . filter ( ( item ) : item is string => typeof item === 'string' )
927- . map ( ( item ) => path . resolve ( contentBase , item ) )
928- . map ( ( item ) => ( { pattern : normalizePath ( item ) , priority : 1 } ) )
929912 documentSelector = [
930913 ...documentSelector . filter ( ( { priority } ) => priority !== 1 ) ,
931- ...contentSelector ,
914+ ...getContentDocumentSelectorFromConfigFile (
915+ state . configPath ,
916+ tailwindcss . version ,
917+ projectConfig . folder ,
918+ originalConfig
919+ ) ,
932920 ]
933921 //////////////////////
934922
@@ -992,7 +980,7 @@ async function createProjectService(
992980 // }
993981 state . dependencies = getModuleDependencies ( state . configPath )
994982 // chokidarWatcher?.add(state.dependencies)
995- watchPatterns ( [ state . configPath , ... ( state . dependencies ?? [ ] ) ] )
983+ watchPatterns ( state . dependencies ?? [ ] )
996984
997985 state . configId = getConfigId ( state . configPath , state . dependencies )
998986
@@ -1436,6 +1424,42 @@ async function getConfigFileFromCssFile(cssFile: string): Promise<string | null>
14361424 return path . resolve ( path . dirname ( cssFile ) , match . groups . config . slice ( 1 , - 1 ) )
14371425}
14381426
1427+ function getContentDocumentSelectorFromConfigFile (
1428+ configPath : string ,
1429+ tailwindVersion : string ,
1430+ rootDir : string ,
1431+ actualConfig ?: any
1432+ ) : DocumentSelector [ ] {
1433+ let config = actualConfig ?? require ( configPath )
1434+ let contentConfig : unknown = config . content ?. files ?? config . content
1435+ let content = Array . isArray ( contentConfig ) ? contentConfig : [ ]
1436+ let relativeEnabled = semver . gte ( tailwindVersion , '3.2.0' )
1437+ ? config . future ?. relativeContentPathsByDefault || config . content ?. relative
1438+ : false
1439+ let contentBase : string
1440+ if ( relativeEnabled ) {
1441+ contentBase = path . dirname ( configPath )
1442+ } else {
1443+ let pkgJsonPath = findUp . sync (
1444+ ( dir ) => {
1445+ let pkgJson = path . join ( dir , 'package.json' )
1446+ if ( findUp . sync . exists ( pkgJson ) ) {
1447+ return pkgJson
1448+ }
1449+ if ( dir === rootDir ) {
1450+ return findUp . stop
1451+ }
1452+ } ,
1453+ { cwd : path . dirname ( configPath ) }
1454+ )
1455+ contentBase = pkgJsonPath ? path . dirname ( pkgJsonPath ) : rootDir
1456+ }
1457+ return content
1458+ . filter ( ( item ) : item is string => typeof item === 'string' )
1459+ . map ( ( item ) => path . resolve ( contentBase , item ) )
1460+ . map ( ( item ) => ( { pattern : normalizePath ( item ) , priority : 1 } ) )
1461+ }
1462+
14391463class TW {
14401464 private initialized = false
14411465 private lspHandlersAdded = false
@@ -1547,17 +1571,7 @@ class TW {
15471571
15481572 let contentSelector : Array < DocumentSelector > = [ ]
15491573 try {
1550- let config = require ( configPath )
1551- let contentConfig : unknown = config . content ?. files ?? config . content
1552- let content = Array . isArray ( contentConfig ) ? contentConfig : [ ]
1553- let relativeEnabled = semver . gte ( twVersion , '3.2.0' )
1554- ? config . future ?. relativeContentPathsByDefault || config . content ?. relative
1555- : false
1556- let contentBase = relativeEnabled ? path . dirname ( configPath ) : base
1557- contentSelector = content
1558- . filter ( ( item ) : item is string => typeof item === 'string' )
1559- . map ( ( item ) => path . resolve ( contentBase , item ) )
1560- . map ( ( item ) => ( { pattern : normalizePath ( item ) , priority : 1 } ) )
1574+ contentSelector = getContentDocumentSelectorFromConfigFile ( configPath , twVersion , base )
15611575 } catch { }
15621576
15631577 let documentSelector = contentSelector
0 commit comments