Skip to content

Resolver: Observe the package.json files a resolution reads - #2291

Open
robhogan wants to merge 1 commit into
mainfrom
pr2291
Open

robhogan wants to merge 1 commit into
mainfrom
pr2291

Conversation

@robhogan

@robhogan robhogan commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Context: The first three PRs of this stack fix some gaps in the Observations API before we start consuming it for unstable_incrementalResolution at the end of the stack.

Resolutions record where they found a package.json, but not that they read it, so a consumer can't tell that an edit to main, browser or exports changes the resolution. (We currently reset the whole graph anyway on any package.json change, but this will allow us to replace that blunt instrument.)

Under resolver.unstable_incrementalResolution, this records the manifests a resolution reads in content, and getPackage reads through the file map. With the flag off, getPackage is unchanged.

Changelog: Internal

Test plan:
Updated observation tests, and tests of a custom resolver reading manifests with the flag on and off. The watch-mode tests in #2289 change a package's main directly and through a symlinked workspace, and fail without this.

@robhogan
robhogan added this pull request to stack #2293 November 25, 2026 16:17
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 25, 2026
@robhogan
robhogan removed this pull request from stack #2293 November 25, 2026 17:18
@robhogan
robhogan changed the base branch from pr2290 to pr2295 November 25, 2026 17:42
@robhogan
robhogan added this pull request to stack #2296 November 25, 2026 17:42
@robhogan
robhogan marked this pull request as ready for review November 26, 2026 14:01
@robhogan
robhogan requested review from huntie and vzaidman November 26, 2026 14:01
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Metro review: Looks good

Risk: low · Commit: 6c756ec · 5 commands run

With resolver.unstable_incrementalResolution on, the resolver now records in content the package.json files a resolution reads, both the closest package found for a module and any manifest read through context.getPackage. getPackage also reads through the file map, so a blocklisted manifest counts as missing. Since my last review the head was only rebased, the one change being an expected-existence entry in a test. The change is still correct. With the flag on, every resolution, the empty module's included, gets an observations record, so the unwrapped getPackage never reaches a resolver. With the flag off, nothing changes.

No findings.

Verified
  • ✅ git range-diff c760fa0a6527~1..c760fa0a6527 HEAD~1..HEAD — Since the previous review, only a rebase. The one change is an existence expectation in the browser-map observation test.
  • ✅ yarn jest --no-watchman packages/metro/src/DeltaBundler/__tests__/resolver-test.js packages/metro/src/node-haste — 6 suites, 311 tests pass at the head.
  • ✅ (base checkout) yarn jest --no-watchman packages/metro/src/DeltaBundler/__tests__/resolver-test.js, using the head's test file (failed as expected) — 6 of 298 fail without the source change: the manifest content observations and the read-through-file-map test, under both configurations. The flag-off test passes, which shows that path is unchanged.
  • ✅ yarn flow check
  • ✅ yarn eslint on the changed files

Not run: No benchmark. The extra file-map lookups in getPackage and _getClosestPackage only happen under the experimental unstable_incrementalResolution flag, and with the flag off getPackage is unchanged. I didn't check Windows behavior; the new code builds no paths by hand and uses the file map's own lookups. I also didn't run the watch-mode tests from the follow-up PR that the description mentions.

Automated review by Claude. Advisory only: it never approves or blocks, and a maintainer makes the call.

@robhogan
robhogan removed this pull request from stack #2296 November 26, 2026 15:35
@robhogan
robhogan added this pull request to stack #2303 November 26, 2026 15:42
Base automatically changed from pr2295 to main November 26, 2026 15:46
Resolutions record where they found a `package.json`, but not that they read it, so a consumer can't tell that an edit to `main`, `browser` or `exports` changes the resolution. With `unstable_enablePackageExports` on, `DeltaCalculator` resets on any `package.json` change, which hides this - but not with it off, or once that reset is retired.

Under `resolver.unstable_incrementalResolution`, this records the manifests a resolution reads in `content`, and `getPackage` reads through the file map: a manifest the file map doesn't have (outside every root, or blocklisted) is missing rather than read from disk unobserved, and `PackageCache` is keyed by its real path, so an edit to a manifest reached through a symlink evicts it. With the flag off, `getPackage` is unchanged.

Changelog: Internal

Test plan:
Updated observation tests, and tests of a custom resolver reading manifests with the flag on and off. The watch-mode tests in #2289 change a package's `main` directly and through a symlinked workspace, and fail without this.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants