Ensure @source globs ending in **/* preserve dynamic path segments to avoid scanning too many files#20217
Conversation
Noticed this while debugging, but let's say you have the following: ```css @source './blog/*/foo/bar/baz/**/*'; ``` We would check wether this ends with `**/*`, and if it does, we convert it to an auto source: ```rs SourceEntry::Auto { base = "/Users/projects/project/blog" } ``` Notice that we lose all the information related to `/*/foo/bar/baz/` If the `*` wasn't there, then this would be correct, because then we would've moved the `/blog/foo/bar/baz` part to the `base` ahead of time, and the pattern would just be `/**/*`. That would result in: ```rs SourceEntry::Auto { base = "/Users/projects/project/blog/foo/bar/baz" } ```
Confidence Score: 5/5Safe to merge — the change is a well-scoped, single-line fix backed by a clear test that demonstrates the before/after behavior. The old ends_with check incorrectly collapsed any glob ending in / into an auto-source, throwing away intermediate wildcard segments. After optimize() runs, the only pattern value that legitimately means scan everything under base is exactly /*/* , so the new equality check is the correct discriminant. The fix is minimal, the new test directly reproduces the over-scanning scenario, and the real-world log diff in the PR description confirms the expected reduction in file reads. No files require special attention. Reviews (2): Last reviewed commit: "update changelog" | Re-trigger Greptile |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThis PR refines auto-source detection logic in the Tailwind CSS scanner. The 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
@source instead of pattern@source globs ending in **/* preserve dynamic path segments to avoid scanning too many files
This PR fixes an issue where we were over-scanning because we lost pattern information when a
@sourceended in**/*and contained other dynamic parts in the glob pattern.Noticed this while debugging and working on #20214. Let's say you have the following:
We make sure that folders or patterns ending in
**/*are converted to "auto sources", meaning that auto content detection should be used in these folders.However, when doing so, we would only take the
basepath of the glob. And since we have "dynamic" parts (the*) in the pattern, that should not be the case.So the
@sourcefrom above, would be turned into:Notice that we lose all the information related to
/*/foo/bar/baz/. While this would technically still work, it also means that we are scanning too many files and folders because we're only interested in folders in theblogfolder that also containfoo/bar/baz.If the
*wasn't there, then this would be correct, because then we would've moved the/blog/foo/bar/bazpart to thebaseahead of time, and the pattern would just be/**/*. That would result in:This PR fixes that, by not converting it to an auto-source, and instead convert it to a pattern:
Notice that the static part
blogis still moved to the base path. But the rest stays in thepatternpart as expected.Test plan
@source "../blog/tailwindcss*/**/*";Notice now that a lot of files are skipped as expected since we-re not accidentally over-scanning now.
[ci-all]