File tree Expand file tree Collapse file tree 2 files changed +53
-4
lines changed
packages/tailwindcss-language-server/src Expand file tree Collapse file tree 2 files changed +53
-4
lines changed Original file line number Diff line number Diff line change @@ -279,6 +279,48 @@ testLocator({
279
279
] ,
280
280
} )
281
281
282
+ testLocator ( {
283
+ name : 'Roots are detected when they indirectly use Tailwind features' ,
284
+ fs : {
285
+ 'package.json' : json `
286
+ {
287
+ "dependencies": {
288
+ "tailwindcss": "4.0.6"
289
+ }
290
+ }
291
+ ` ,
292
+ // TODO: This is marked as the root which is… maybe fine but not sure
293
+ // The intention in this example is that src/globals.css is the real root
294
+ // but if src/articles.css suddenly gained `@theme` blocks then maybe it'd
295
+ // need to be the root instead.
296
+ 'src/articles/articles.css' : css `
297
+ @reference "../globals.css";
298
+ .article-title {
299
+ @apply text-primary;
300
+ }
301
+ ` ,
302
+ 'src/articles/layout.js' : js `
303
+ import "./articles.css";
304
+ export default function Layout(children) {
305
+ return children;
306
+ }
307
+ ` ,
308
+ 'src/globals.css' : scss `
309
+ @import "tailwindcss";
310
+ @theme {
311
+ --color-primary: #3490dc;
312
+ }
313
+ ` ,
314
+ } ,
315
+ expected : [
316
+ {
317
+ version : '4.0.6' ,
318
+ config : '/src/articles/articles.css' ,
319
+ content : [ ] ,
320
+ } ,
321
+ ] ,
322
+ } )
323
+
282
324
// ---
283
325
284
326
function testLocator ( {
Original file line number Diff line number Diff line change @@ -427,11 +427,18 @@ export class ProjectLocator {
427
427
if ( indexPath && themePath ) graph . connect ( indexPath , themePath )
428
428
if ( indexPath && utilitiesPath ) graph . connect ( indexPath , utilitiesPath )
429
429
430
- for ( let root of graph . roots ( ) ) {
431
- if ( ! root . meta ) continue
430
+ // Sort the graph so potential "roots" appear first
431
+ // The entire concept of roots needs to be rethought because it's not always
432
+ // clear what the root of a project is. Even when imports are present a file
433
+ // may import a file that is the actual "root" of the project.
434
+ let roots = Array . from ( graph . roots ( ) )
435
+
436
+ roots . sort ( ( a , b ) => {
437
+ return a . meta . root === b . meta . root ? 0 : a . meta . root ? - 1 : 1
438
+ } )
432
439
433
- // This file is not eligible to act as a root of the CSS graph
434
- if ( root . meta . root === false ) continue
440
+ for ( let root of roots ) {
441
+ if ( ! root . meta ) continue
435
442
436
443
let config : ConfigEntry = configs . remember ( root . path , ( ) => ( {
437
444
source : 'css' ,
You can’t perform that action at this time.
0 commit comments