Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't follow recursive symlinks during project discovery #1270

Merged
merged 3 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/tailwindcss-language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"dset": "3.1.4",
"enhanced-resolve": "^5.16.1",
"esbuild": "^0.25.0",
"fast-glob": "3.2.4",
"find-up": "5.0.0",
"jiti": "^2.3.3",
"klona": "2.0.4",
Expand All @@ -85,6 +84,7 @@
"stack-trace": "0.0.10",
"tailwindcss": "3.4.17",
"tailwindcss-v4": "npm:[email protected]",
"tinyglobby": "^0.2.12",
"tsconfck": "^3.1.4",
"tsconfig-paths": "^4.2.0",
"typescript": "5.3.3",
Expand Down
34 changes: 34 additions & 0 deletions packages/tailwindcss-language-server/src/project-locator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,40 @@ testLocator({
],
})

testLocator({
name: 'Recursive symlinks do not cause infinite traversal loops',
fs: {
'src/a/b/c/index.css': css`
@import 'tailwindcss';
`,
'src/a/b/c/z': symlinkTo('src', 'dir'),
'src/a/b/x': symlinkTo('src', 'dir'),
'src/a/b/y': symlinkTo('src', 'dir'),
'src/a/b/z': symlinkTo('src', 'dir'),
'src/a/x': symlinkTo('src', 'dir'),

'src/b/c/d/z': symlinkTo('src', 'dir'),
'src/b/c/d/index.css': css``,
'src/b/c/x': symlinkTo('src', 'dir'),
'src/b/c/y': symlinkTo('src', 'dir'),
'src/b/c/z': symlinkTo('src', 'dir'),
'src/b/x': symlinkTo('src', 'dir'),

'src/c/d/e/z': symlinkTo('src', 'dir'),
'src/c/d/x': symlinkTo('src', 'dir'),
'src/c/d/y': symlinkTo('src', 'dir'),
'src/c/d/z': symlinkTo('src', 'dir'),
'src/c/x': symlinkTo('src', 'dir'),
},
expected: [
{
version: '4.1.1 (bundled)',
config: '/src/a/b/c/index.css',
content: [],
},
],
})

// ---

function testLocator({
Expand Down
9 changes: 4 additions & 5 deletions packages/tailwindcss-language-server/src/project-locator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as os from 'node:os'
import * as path from 'node:path'
import * as fs from 'node:fs/promises'
import glob from 'fast-glob'
import { glob } from 'tinyglobby'
import picomatch from 'picomatch'
import type { Settings } from '@tailwindcss/language-service/src/util/state'
import { CONFIG_GLOB, CSS_GLOB } from './lib/constants'
Expand Down Expand Up @@ -276,14 +275,14 @@ export class ProjectLocator {

private async findConfigs(): Promise<ConfigEntry[]> {
// Look for config files and CSS files
let files = await glob([`**/${CONFIG_GLOB}`, `**/${CSS_GLOB}`], {
let files = await glob({
patterns: [`**/${CONFIG_GLOB}`, `**/${CSS_GLOB}`],
cwd: this.base,
ignore: this.settings.tailwindCSS.files.exclude,
onlyFiles: true,
absolute: true,
suppressErrors: true,
followSymbolicLinks: true,
dot: true,
concurrency: Math.max(os.cpus().length, 1),
})

let realpaths = await Promise.all(files.map((file) => fs.realpath(file)))
Expand Down
12 changes: 8 additions & 4 deletions packages/tailwindcss-language-server/tests/prepare.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ import { exec } from 'node:child_process'
import * as path from 'node:path'
import { fileURLToPath } from 'node:url'
import { promisify } from 'node:util'
import glob from 'fast-glob'
import { glob } from 'tinyglobby'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

const fixtures = glob.sync(['tests/fixtures/*/package.json', 'tests/fixtures/v4/*/package.json'], {
cwd: path.resolve(__dirname, '..'),
const root = path.resolve(__dirname, '..')

const fixtures = await glob({
cwd: root,
patterns: ['tests/fixtures/*/package.json', 'tests/fixtures/v4/*/package.json'],
absolute: true,
})

const execAsync = promisify(exec)

await Promise.all(
fixtures.map(async (fixture) => {
console.log(`Installing dependencies for ${fixture}`)
console.log(`Installing dependencies for ${path.relative(root, fixture)}`)

await execAsync('npm install', { cwd: path.dirname(fixture) })
}),
Expand Down
1 change: 1 addition & 0 deletions packages/vscode-tailwindcss/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Prerelease

- Only scan the file system once when needed ([#1287](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1287))
- Don't follow recursive symlinks when searching for projects ([#1270](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1270))

# 0.14.13

Expand Down
49 changes: 24 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.