Skip to content

fix: skip a move home whose package cannot load the code's npm packages - #42

Merged
alecf merged 1 commit into
mainfrom
fix/home-deps
Nov 13, 2026
Merged

alecf merged 1 commit into
mainfrom
fix/home-deps

Conversation

@alecf

@alecf alecf commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

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). stamp lives in package core and calls left-pad. Only core lists left-pad. The file app/view.ts uses stamp, and it sits in package app, which does not have left-pad.

Before:

- **suggested move:** `stamp` out of `core/owner.ts` — 3 lines
- **move to:** `app/view.ts`, which uses it
- **leaves:** nothing — this breaks the cycle completely.

After:

- **suggested move:** `stamp` out of `core/owner.ts` — 3 lines
- **move to:** `core/base.ts`, which every user already imports
- **leaves:** nothing — this breaks the cycle completely.

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.

  • symbolsOf records each import that names an npm package and resolves to no analyzed file. It skips relative paths and Node built-ins such as fs and node:path.
  • Packages.canUse(pkg, name) is true when the package's package.json lists name. It is also true when a file of the package already imports name. The second rule covers hoisted workspaces, the way canImport already does for workspace packages.
  • A home whose package fails canUse for 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

  • On the four public repositories, none of 109 move homes changed.
  • Run time did not change measurably. The branch was faster on both repositories timed, which is run-order noise.
  • The round 6 miss does not change. The judge wrote that the package "does not depend on zod". Three of its files import zod, so the package can load it. The judge's other objection was that the home is a stub, and no structural signal says so. The plan doc records this.

Tests

  • A fixture in tests/fixtures/moves/src/ext/ sets up two packages. The user file wins as home today, but its package cannot load left-pad. The test expects a shared file in the owner's package.
  • A symbolsOf test pins the package name and the skipped built-ins.
  • A buildPackages test covers both ways a package can use an npm package.
  • Deleting the reachability check fails the fixture test. Deleting the built-in skip fails the symbolsOf test.
  • 839 tests pass. Typecheck and check:boundary are clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01S7cyneSpBhH5XCwE3t8w1Y

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
@alecf
alecf merged commit f57f51a into main Nov 13, 2026
10 checks passed
@alecf
alecf deleted the fix/home-deps branch November 13, 2026 18:52
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.

1 participant