mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-09-17 23:52:36 +00:00
fix: detect React component paths before lowercasing
Preserve the original filename casing for the React component heuristic so PascalCase files in views/components folders stop being misclassified as non-framework code. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
parent
6222b5be9b
commit
518c481f7a
2 changed files with 8 additions and 7 deletions
|
|
@ -34,10 +34,12 @@ export interface FrameworkHint {
|
|||
*/
|
||||
export function detectFrameworkFromPath(filePath: string): FrameworkHint | null {
|
||||
// Normalize path separators and ensure leading slash for consistent matching
|
||||
let p = filePath.toLowerCase().replace(/\\/g, '/');
|
||||
const originalPath = filePath.replace(/\\/g, '/');
|
||||
let p = originalPath.toLowerCase();
|
||||
if (!p.startsWith('/')) {
|
||||
p = '/' + p; // Add leading slash so patterns like '/app/' match 'app/...'
|
||||
}
|
||||
const originalPathWithLeadingSlash = originalPath.startsWith('/') ? originalPath : `/${originalPath}`;
|
||||
|
||||
// ========== JAVASCRIPT / TYPESCRIPT FRAMEWORKS ==========
|
||||
|
||||
|
|
@ -128,7 +130,7 @@ export function detectFrameworkFromPath(filePath: string): FrameworkHint | null
|
|||
(p.endsWith('.tsx') || p.endsWith('.jsx'))
|
||||
) {
|
||||
// Only boost if PascalCase filename (likely a component, not util)
|
||||
const fileName = p.split('/').pop() || '';
|
||||
const fileName = originalPathWithLeadingSlash.split('/').pop() || '';
|
||||
if (/^[A-Z]/.test(fileName)) {
|
||||
return { framework: 'react', entryPointMultiplier: 1.5, reason: 'react-component' };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,12 +90,11 @@ describe('detectFrameworkFromPath', () => {
|
|||
|
||||
describe('React', () => {
|
||||
it('has React component detection rule for views/components folders', () => {
|
||||
// Note: The current implementation lowercases the path before checking
|
||||
// PascalCase, so PascalCase detection currently can't match.
|
||||
// This test documents the current behavior.
|
||||
const result = detectFrameworkFromPath('views/Button.tsx');
|
||||
// Returns null because path is lowercased before PascalCase regex check
|
||||
expect(result).toBeNull();
|
||||
expect(result).not.toBeNull();
|
||||
expect(result!.framework).toBe('react');
|
||||
expect(result!.entryPointMultiplier).toBe(1.5);
|
||||
expect(result!.reason).toBe('react-component');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue