Repository navigation
fix: skip a move home whose package cannot load the code's npm packages - #42
Merged
Merged
Conversation
The home check asked whether a home's package can import the repo files the moved code imports. It now asks the same about npm packages. - symbolsOf records each import that names an npm package and resolves to no analyzed file. Relative paths and Node built-ins are skipped. - Packages.canUse is true when the package.json lists the package, or when a file of the package already imports it. The second covers hoisted workspaces. - A home that fails canUse is unreachable. On the four public repositories this changed none of 109 move homes, and run time did not change measurably. A fixture pins the rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S7cyneSpBhH5XCwE3t8w1Y
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.
What changes for the reader
When a tangle of files can be broken by moving code, the report says where to put it (
move to:). Until now it could name a file in a package that cannot load an npm package the moved code needs. Following that advice breaks the build, or forces a new dependency on that package.Now the report picks a home whose package can already load what the code imports.
Example (from the test fixture).
stamplives in packagecoreand callsleft-pad. Onlycorelistsleft-pad. The fileapp/view.tsusesstamp, and it sits in packageapp, which does not haveleft-pad.Before:
After:
The move itself is the same. Only the home changes, to a file that can import
left-pad.How often this happens. On the four public repositories, no printed home changed. Hoisted workspaces let most packages load most npm packages. This rule matters for repositories where each package installs its own dependencies.
How it works
The home check for a suggested move asked whether the home's package can import the repo files the moved code imports. It did not ask about npm packages. Now it does.
symbolsOfrecords each import that names an npm package and resolves to no analyzed file. It skips relative paths and Node built-ins such asfsandnode:path.Packages.canUse(pkg, name)is true when the package's package.json listsname. It is also true when a file of the package already importsname. The second rule covers hoisted workspaces, the waycanImportalready does for workspace packages.canUsefor any of the moved code's npm packages is unreachable.No text in comments is read. The rule uses package.json and import specifiers only.
Measured
Tests
tests/fixtures/moves/src/ext/sets up two packages. The user file wins as home today, but its package cannot loadleft-pad. The test expects a shared file in the owner's package.symbolsOftest pins the package name and the skipped built-ins.buildPackagestest covers both ways a package can use an npm package.symbolsOftest.check:boundaryare clean.🤖 Generated with Claude Code
https://claude.ai/code/session_01S7cyneSpBhH5XCwE3t8w1Y