fix: @/ alias resolution in monorepo reference scanning and optimization apply#1
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for monorepos by resolving @/ aliases relative to the nearest src/ ancestor and updating referenceMayPointTo to handle @/ and ~/ prefixes. The review feedback suggests two key optimizations: first, using the platform-independent path package in findSrcAncestor to avoid OS-specific separator issues and string splitting; second, replacing slice allocations in the hot path of referenceMayPointTo with direct prefix checks to eliminate unnecessary GC overhead.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
In monorepo projects the importer lives deep inside e.g. apps/mobile/src/views/, but Resolve() hardcoded @/ → src/, producing src/assets/… which never matched the real repo path apps/mobile/src/assets/…. The fuzzy fallback also failed because the short specifier could not suffix-match the long repo path. Fix Resolve to walk up from the importer and find the nearest src/ directory, and add @/ and ~/ prefix stripping to referenceMayPointTo as a safety net. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
334afcd to
9f6ed5e
Compare
…rences referenceChanges always used relativeSpecifier, converting @/assets/... imports to ../../assets/... when applying optimizations. New rewriteSpecifier detects alias prefixes and rewrites only the path suffix and extension, preserving the original import style. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
referenceMayPointTo produced a double-slash when checking absolute-path specifiers like /src/landing/assets/design.webp, causing the suffix match to always fail in monorepo layouts.
Summary
@/alias resolution in monorepo reference scanning —Resolve()now walks up from the importer to find the nearestsrc/ancestor instead of hardcodingsrc/@/and~/alias format when rewriting references during optimization apply — no longer converts to relative../../paths/to prevent double-slash suffix mismatchTest plan
TestResolveReferenceKinds— existing behavior preservedTestBuildMapResolvesProjectReferences— standard project referencesTestBuildMapResolvesAbsolutePublicReferences— public directory resolutionTestBuildMapResolvesMonorepoAtAliasImports— monorepo@/detectionTestBuildMapResolvesAbsolutePathInMonorepo—/src/...absolute path detectionTestReferenceHelperFunctions—@/,~/alias stripping in fuzzy matchTestPathAndSpecifierHelpers—rewriteSpecifieralias preservation + query string