- 
        Couldn't load subscription status. 
- Fork 724
Add Yarn PnP support #1966
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
base: main
Are you sure you want to change the base?
Add Yarn PnP support #1966
Conversation
| @microsoft-github-policy-service agree company="Datadog" | 
| I see my tests are not passing in CI, looking into it 🙇 | 
| var ( | ||
| isPnpApiInitialized atomic.Uint32 | ||
| cachedPnpApi *PnpApi | ||
| pnpMu sync.Mutex | ||
| // testPnpCache stores per-goroutine PnP APIs for test isolation | ||
| // Key is goroutine ID (as int) | ||
| testPnpCache sync.Map // map[int]*PnpApi | ||
| ) | ||
|  | ||
| // getGoroutineID returns the current goroutine ID | ||
| // It is usually not recommended to work with goroutine IDs, but it is the most non-intrusive way to setup a parallel testing environment for PnP API | ||
| func getGoroutineID() int { | ||
| var buf [64]byte | ||
| n := runtime.Stack(buf[:], false) | ||
| idField := strings.Fields(strings.TrimPrefix(string(buf[:n]), "goroutine "))[0] | ||
| id, _ := strconv.Atoi(idField) | ||
| return id | ||
| } | ||
|  | 
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.
All of this global / goroutine local storage is something that won't work. If we are storing something, it needs to be attached to a Program, Project, a Host, etc, not global. Parsing out the goroutine ID is definitely a bad idea, especially given our LSP can handle multiple requests at the same time from multiple goroutines and so on.
|  | ||
| pnpApi := &PnpApi{fs: fs, url: filePath} | ||
|  | ||
| manifestData, err := pnpApi.findClosestPnpManifest() | 
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 don't really understand this init. Surely one needs to be able to load multiple projects with differing pnp info at the same time? All of this info really does need to be handled differently.
Motivation
This PR adds Plug'n'Play support natively to Typescript Go, following this issue: #460
It has been reviewed and supported by @arcanis, the lead maintainer of Yarn, and the original author of Yarn PnP.
Datadog has a frontend monorepo using yarn with over 6k packages, and seeing how TS Strada struggles with our current scaling, we decided to invest time in adding a native Yarn PnP support for Typescript Go.
This PnP implementation has been actively used in the IDE of more than 230 engineers at Datadog, and we're committed to fixing all issues reported to us.
Challenges
We did not integrate it in our CI yet as we still have several packages failing on build mode (most errors seem to be reported in the issues section of TS Corsa). Because the TS Corsa API is not available yet, we also couldn't integrate it properly with a fast lage setup unlike with the TS Strada API.
Changes
It's based on the main changes from the original yarn patch (microsoft/TypeScript@99f3e13) that the community has been maintaining for years throughout Typescript Strada updates, except that we implemented the official PnP specification so it doesn't depend on third-party code.
Implemented features:
internal/module/resolver.gointernal/modulespecifiers/specifiers.gointernal/core/compileroptions.goMissing features:
pnpApi.ResolveToUnqualified.pnp.cjschangesTests
internal/fourslash)