-
Notifications
You must be signed in to change notification settings - Fork 3
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
PNP tsconfig references resolution fix #10
Conversation
cc @andreialecu as the author of that patch |
@andreialecu your review on this would be much appreciated. This is trying to address breaking scenarios for monorepos where tsconfig files and references are deep within the root of the workspace. Thank you. |
Interesting. I'm using yarn 3 and project references but I don't remember noticing anything wrong. How does the problem manifest exactly? |
Hey @sushruth I just took this for a test spin. Unfortunately all it does is to essentially undo #4 because all paths going through that function are absolute. You can verify in my original repro at: https://github.com/andreialecu/repro-yarn-pnp-composite which I just updated to yarn 3. Run But with this patch, the behavior above happens. To clarify, when did you first see this problem occuring? Did the behavior or |
The problem appears to be that the current patch resolves the root of the locator but in the repro provided in yarnpkg/berry#3231 the reference isn't pointing to a folder (workspace root) so we're effectively turning the reference |
@andreialecu Those errors seem to be expected behavior in yarn 2 with TS 4.3.5 - https://github.com/sushruth/repro-yarn-pnp-composite. Edit 1: P.S. - This behavior (Cannot find module "lib") is also observed when running
I may be wrong here but seems to me like being able to reference types in Edit 2: This makes me think if the |
Not sure I understand what you mean. The behavior is not expected, because it works properly without PnP, or when virtuals are not involved, so it should definitely work. It's the most idiomatic way to use project references as well. The patch I made in #4 fixed that. The change made by this PR simply undoes it which incidentally makes your scenario work.
I'm a bit confused by how the setup in your repro translates into a real world scenario because I'm not sure why your tsconfig would look like that in practice. It seems a bit odd. :) Even so though, I see that your repro works properly with |
Can you clarify if this is a regression and when did it start appearing? Did yarn 3 introduce it or TS 4.3.5? What's the last combo of versions when it was working? |
@andreialecu Turns out I was wrong. I just realized that I had completely ignored the fact that your repro repo is a yarn workspace monorepo. Now I realize what might be the actual issue that was breaking my scenario (mostly for all nx repos for reference) I think it might actually be that the current typescript-patch is not considering the scenario when references are files without a workspace and not workspace folders with
basically upgrading to the latest typescript-patch broke all nx monorepos due to this issue. It was not necessarily introduced in TS or Yarn3. I am now working on a different solution for this issue. Thanks @andreialecu. Reverting this PR to draft. EDIT: The new proposed solution seems to work for all these repro repos -
@andreialecu I am opening this PR up for review once again. Please take a look. Thank you. |
Alternative fix
Exactly, that's what I was hinting at in #10 (comment). The patch needs to be changed to preserve the part of the path that comes after the |
@merceyz that sounds right. One way I though about this is - any path that directly resolved to be from the root workspace would mean PnP may not need to handle the virtual directory. I made a change to reflect that. What do you think about the current diff of this PR? |
@andreialecu pinging for your attention on latest update to this PR. |
@merceyz @andreialecu @arcanis pinging to bring attention to this |
Hey! I'm sorry I'm a little lost 😅 can you make a quick summary of why this is needed? I'm worried about adding a special case just for |
What I said in #10 (comment) and #10 (comment) still stands, I pushed the generic fix here merceyz@3f4e151, will update yarnpkg/berry#3297 to include it |
Fixes yarnpkg/berry#3231
Also slightly makes it easier for nx repositories to adopt yarn 3 (nrwl/nx#2386)
CC: @arcanis