fix: preserve root path in tryWorkspaceByCwd when cwd is /#7203
Open
quinise wants to merge 4 commits into
Open
fix: preserve root path in tryWorkspaceByCwd when cwd is /#7203quinise wants to merge 4 commits into
quinise wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a workspace lookup edge case in Project.tryWorkspaceByCwd where normalizing / and stripping trailing slashes could produce an empty string, causing workspace resolution to fail when the current working directory is the filesystem root (notably in Docker scenarios).
Changes:
- Preserve the filesystem root by falling back to
PortablePath.rootwhen trailing-slash stripping would yield''. - Add a regression test ensuring
tryWorkspaceByCwd('/')can resolve a workspace registered at/. - Add a versions file to release the fix as patch updates across relevant Yarn packages/plugins.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/yarnpkg-core/sources/Project.ts | Ensures normalized root path (/) isn’t converted into an empty string during workspace lookup. |
| packages/yarnpkg-core/tests/Project.test.ts | Adds a regression test covering workspace lookup when cwd is /. |
| .yarn/versions/da7e1fc4.yml | Declares patch releases for packages affected by the core fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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's the problem this PR addresses?
In Project.tryWorkspaceByCwd, the workspaceCwd is normalized and trailing slashes are stripped. However, when cwd is the filesystem root (/), stripping the trailing slash produces an empty string "" instead of "/", causing workspace lookup to fail.
Closes issue #5380
[Bug?]: The nearest package directory (/) doesn't seem to be part of the project declared in /. (docker)
...
How did you fix it?
After stripping trailing slashes, fall back to PortablePath.root if the result is an empty string:
...
Checklist