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.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: correctly resolve dependencies for CT onboarding when using Yarn Plug n Play #26452
fix: correctly resolve dependencies for CT onboarding when using Yarn Plug n Play #26452
Changes from 5 commits
58e44ea
a3e438e
c02d49d
18c6d0e
35079a6
8194140
21762b2
01e94a7
775314a
47b41bd
948de1b
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very minor, but we could simplify this map to just be a
Map<string, boolean>
. Do you foresee any other fields being tracked that would require an object value?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had this thought too, my reasoning was the property
usesYarnPnP
makes it more obvious what this is used for. Could go either way, I wish TS had a feature where you could label the value, egMap<string, usesPnP as boolean>
or something...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth reading https://yarnpkg.com/features/pnp for more context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm missing an edge case, but couldn't we just use the
require(require.resolve(packageFilePath))
logic in both cases? PnP handles if the module is zipped, and if we aren't in PnP it will be a flat file that should be normally require-ableThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there was an edge case where this doesn't work, let me double check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.pnp.cjs
is regenerated by Yarn every time you install a module. We only want to require it once, since the trick Yarn PnP uses is to dynamically monkeypatchmodule
and do some other weird hacks to facilitate the various features of PnP. That is whatsetup()
does.It's a bit of a hack (Yarn 3, I mean, not what I'm doing here - this is how they recommend you load the
.pnp.cjs
if you are doing it manually). Yarn 3 does run really fast, though, because of this... although Yarn 1 -> Yarn 2.x + PnP is a heck of a lift for a lot of code bases and projects, which is why many people are stuck on v1 (including FB, the (original) authors of Yarn).It wouldn't matter if we executed this block it every time - it would just be a bit of pointless overhead. It would be next to negligible, since Node.js caches
require
calls anyway, but this is cleaner. We do need to execute it once for each new project (think global mode - you can switch projects, each having a different.pnp.cjs
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about a scenario where a Cypress project is nested into a subdirectory of a yarn project? Do we need to traverse upwards to find the first
.pnp.cjs
we encounter?Theres a method on the
module
module that seems to do this for us in a PnP context (find.pnp.cjs
, load, and returnpnpapi
(which we can ignore))There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, forgot the nested edge case, I will verify what happens and address using this if required. Yarn has a ton of APIs for this, as you pointed out, we can probably use one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Painful, but for this API to exist you need to be in a PnP context... which you get by requiring the file in the first place 🤦
I think we need to manually traverse up, lucky we've already got some code that does that,
isRepositoryRoot
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omg, never would have figured this one out. Very nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sent the author a patch stefanpenner/resolve-package-path#62
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem is the module is installed in the same directory as the project, which in our case it isn't - the module is in the binary.