Skip to content

Commit 73330db

Browse files
committed
Ignore URL imports when considering roots
1 parent 2f6de10 commit 73330db

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

packages/tailwindcss-language-server/src/project-locator.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,28 @@ testLocator({
531531
],
532532
})
533533

534+
testLocator({
535+
name: 'Stylesheets that only have URL imports are not considered roots',
536+
fs: {
537+
'a/fonts.css': css`
538+
@import 'https://example.com/fonts/some-font.css';
539+
.a {
540+
color: red;
541+
}
542+
`,
543+
'src/app.css': css`
544+
@import 'tailwindcss';
545+
`,
546+
},
547+
expected: [
548+
{
549+
version: '4.1.1 (bundled)',
550+
config: '/src/app.css',
551+
content: [],
552+
},
553+
],
554+
})
555+
534556
// ---
535557

536558
function testLocator({

packages/tailwindcss-language-server/src/version-guesser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ const HAS_TAILWIND = /@tailwind\s*[^;]+;/
4949
const HAS_COMMON_DIRECTIVE = /@(config|apply)\s*[^;{]+[;{]/
5050

5151
// If it's got imports at all it could be either
52-
const HAS_IMPORT = /@import\s*['"]/
52+
// Note: We only care about non-url imports
53+
const HAS_NON_URL_IMPORT = /@import\s*['"](?!([a-z]+:|\/\/))/
5354

5455
/**
5556
* Determine the likely Tailwind version used by the given file
@@ -128,7 +129,7 @@ export function analyzeStylesheet(content: string): TailwindStylesheet {
128129
}
129130

130131
// Files that import other files could be either and are potentially roots
131-
if (HAS_IMPORT.test(content)) {
132+
if (HAS_NON_URL_IMPORT.test(content)) {
132133
return {
133134
root: true,
134135
versions: ['4', '3'],

0 commit comments

Comments
 (0)