Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix symlinked packages not respecting package.json redirections
TreeFS.hierarchicalLookup is a recently introduced function for finding closest package.json for an input path. It works by traversing to the input path while "collecting ancestors" - i.e. all of the directory nodes on route to the input path, and then checking each of them in reverse order for package.json. This gets a bit complicated when traversal includes symlinks. For the test case in this commit: - `n_m/workspace/link-to-pkg` is a symlink to '../workspace-pkg'. - When resolving the package scope of `n_m/workspace/link-to-pkg/subpath`, we should check: - `n_m/workspace/link-to-pkg` (realpath: `../workspace-pkg`) - `n_m/workspace` (realpath: `n_m/workspace`) In particular, when traversing to `../workspace-pkg`, we should *not* collect `..` but we *should* collect `../workspace-pkg`. We attempt to do this by keeping track of an `unseenPathFromIdx`, which lets us skip ancestor collection when we're traversing from the root to the symlink target. The logic here was effectively off-by-one - we were correctly skipping segments before the symlink target, and correctly collecting segments after, but we missed the symlink target itself. By setting `unseenPathFromIdx` to the index of the start of the target's basename, we include it correctly. Fixes #1347 ``` - **[Fix]**: Fix #1347, failure during resolution to read package.json of symlinked workspace packages for exports or redirects. ``` Test plan: - New unit test - Verified e2e by patching metro-file-map in user's repro
- Loading branch information