Skip to content

fix: @/ alias resolution in monorepo reference scanning and optimization apply#1

Merged
runkids merged 3 commits into
runkids:mainfrom
hiro05097952:fix/resolve-path
Jun 9, 2026
Merged

fix: @/ alias resolution in monorepo reference scanning and optimization apply#1
runkids merged 3 commits into
runkids:mainfrom
hiro05097952:fix/resolve-path

Conversation

@hiro05097952

@hiro05097952 hiro05097952 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix @/ alias resolution in monorepo reference scanning — Resolve() now walks up from the importer to find the nearest src/ ancestor instead of hardcoding src/
  • Preserve @/ and ~/ alias format when rewriting references during optimization apply — no longer converts to relative ../../ paths
  • Fix absolute-path fuzzy matching — strip leading / to prevent double-slash suffix mismatch

Test plan

  • TestResolveReferenceKinds — existing behavior preserved
  • TestBuildMapResolvesProjectReferences — standard project references
  • TestBuildMapResolvesAbsolutePublicReferences — public directory resolution
  • TestBuildMapResolvesMonorepoAtAliasImports — monorepo @/ detection
  • TestBuildMapResolvesAbsolutePathInMonorepo/src/... absolute path detection
  • TestReferenceHelperFunctions@/, ~/ alias stripping in fuzzy match
  • TestPathAndSpecifierHelpersrewriteSpecifier alias preservation + query string
  • All 10 existing reference tests and action tests pass

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/references/references.go
Comment thread internal/references/references.go Outdated
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>
…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>
@hiro05097952 hiro05097952 changed the title fix: resolve @/ alias relative to nearest src/ ancestor in monorepos Fix: @/ alias resolution in monorepo reference scanning and optimization apply Jun 8, 2026
@hiro05097952 hiro05097952 changed the title Fix: @/ alias resolution in monorepo reference scanning and optimization apply fix: @/ alias resolution in monorepo reference scanning and optimization apply Jun 8, 2026
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.
@runkids runkids merged commit 1fb1856 into runkids:main Jun 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants