fix(components): do not filter custom components in workspaces named ui/#3
Merged
Merged
Conversation
`isUIPrimitive` had a `filePath.includes("/ui/")` check intended to filter
shadcn primitives. That check is too broad: it matches every file under a
monorepo workspace literally named `ui/` (e.g. `ui/src/components/*.tsx`),
so every custom component in such a repo was wrongly dropped.
The real shadcn case (`components/ui/<primitive>.tsx`) is still caught by
the more specific `/components/ui/` check, and lowercase primitive file
names are still caught by the `UI_PRIMITIVES` set. Vendor path checks
(`@radix-ui`, `@shadcn`) are unchanged.
Repro: morgan monorepo (`packages: shared, server, ui`) reported 0
components. After the fix, 130 components are detected with prop
signatures extracted via AST. Includes a regression test fixture that
asserts a workspace-level `ui/src/components/AppShell.tsx` is detected
while a sibling `ui/src/components/ui/button.tsx` is still filtered.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes an over-broad shadcn/ui primitive filter in the component detector that was incorrectly excluding all components in monorepos with a workspace literally named ui/, restoring correct React component detection in those repos.
Changes:
- Removed the
filePath.includes("/ui/")heuristic fromisUIPrimitive()to avoid colliding withui/workspace paths. - Added a regression test fixture covering a
ui/workspace containing both a real app component and a shadcn-style primitive path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/detectors/components.ts |
Narrows the UI-primitive filter to avoid excluding components solely due to a /ui/ path segment. |
tests/detectors.test.ts |
Adds regression coverage for monorepos with a ui/ workspace and expected component detection behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
64
to
75
| function isUIPrimitive(filePath: string): boolean { | ||
| const name = basename(filePath, extname(filePath)).toLowerCase(); | ||
| // Note: do NOT match a bare `/ui/` segment here. That collides with monorepo | ||
| // workspaces literally named `ui/` (e.g. `ui/src/components/*.tsx`), where | ||
| // every custom component would be wrongly filtered. The real shadcn case is | ||
| // `components/ui/` (caught below) or lowercase primitive filenames (caught | ||
| // via UI_PRIMITIVES). Vendor paths (`@radix-ui`, `@shadcn`) are kept. | ||
| return ( | ||
| UI_PRIMITIVES.has(name) || | ||
| filePath.includes("/ui/") || | ||
| filePath.includes("/components/ui/") || | ||
| filePath.includes("@radix-ui") || | ||
| filePath.includes("@shadcn") |
Comment on lines
+395
to
+409
| // shadcn primitive at the canonical path. Must still be filtered. | ||
| "ui/src/components/ui/button.tsx": `export const Button = ({ label }: { label: string }) => <button>{label}</button>;`, | ||
| }); | ||
| const project = await mods.detectProject(dir); | ||
| assert.equal(project.componentFramework, "react", "react workspace dep should be aggregated"); | ||
| const files = await mods.collectFiles(dir); | ||
| const components = await mods.detectComponents(files, project); | ||
| assert.ok( | ||
| components.some((c: any) => c.name === "AppShell"), | ||
| `expected AppShell to be detected, got: ${components.map((c: any) => c.name).join(", ") || "<none>"}`, | ||
| ); | ||
| assert.ok( | ||
| !components.some((c: any) => c.name === "Button"), | ||
| "shadcn primitive at components/ui/button.tsx should still be filtered", | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
isUIPrimitiveinsrc/detectors/components.tshad afilePath.includes(\"/ui/\")check intended to filter shadcn primitives. It is too broad: it matches every file under a monorepo workspace literally named `ui/` (e.g. `ui/src/components/*.tsx`), so every custom component in such a repo was wrongly dropped.The real shadcn case (`components/ui/.tsx`) is still caught by the more specific `/components/ui/` check; lowercase primitive file names are still caught by the `UI_PRIMITIVES` set; vendor path checks (`@radix-ui`, `@shadcn`) are unchanged.
Why we want this in the fork right now
Surfaced while validating MGN-853 (cross-repo wiki ingestion into Talas brain). Running
npx codesight --wikiagainst `morgan` (pnpm workspace `packages: shared, server, ui`) reported `0 components`. After the fix, 130 components are detected with prop signatures extracted via AST. The new `ui.md` article alone (~3.3K tokens) is the single biggest UI-context gain for triage and dev agents working on morgan.Change
function isUIPrimitive(filePath: string): boolean { const name = basename(filePath, extname(filePath)).toLowerCase(); return ( UI_PRIMITIVES.has(name) || - filePath.includes(\"/ui/\") || filePath.includes(\"/components/ui/\") || filePath.includes(\"@radix-ui\") || filePath.includes(\"@shadcn\") ); }Test plan
tests/detectors.test.ts. Fixture has bothui/src/components/AppShell.tsx(must be detected) andui/src/components/ui/button.tsx(must still be filtered).detects React components with propstest still passes.tests/monorepo.test.ts:312also fails onmain(verified via stash + re-run).morgan-- components 0 -> 130, wiki tokens 15,736 -> 19,077,ui.mdarticle generated.Upstream
Also filed at Houseofmvps#43 as a contribution. This PR lets us land internally without waiting on upstream review.
🤖 Generated with Claude Code