Skip to content
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 pnp indexing #262

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Fix pnp indexing #262

wants to merge 6 commits into from

Conversation

keynmol
Copy link

@keynmol keynmol commented Jun 14, 2023

Closes #259

We're switching this build itself to Yarn Berry, which will automatically apply the TypeScript patch to support PnP: https://github.com/yarnpkg/berry/blob/master/packages/plugin-compat/extra/typescript/gen-typescript-patch.js#L123-L129

This seemed to be the easiest way of doing this.

Test plan

  • Existing tests
  • New integration tests

keynmol added 6 commits June 14, 2023 12:37
Yarn patches Typescript (certain versions) to support PnP dependency
management strategy.

The easiest thing we can do is to move our own build to Yarn Berry
so that the patch is applied automatically, and we can support both
node_modules and PnP approach
@keynmol
Copy link
Author

keynmol commented Jun 14, 2023

The tests are broken in a non-trivial way. There are some basic things like version of typescript that got bumped, but more importantly we seem to have lost package information for symbols imported from dependencies.

@@ -0,0 +1,3 @@
nodeLinker: pnp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious, what makes it harder to use the patch package without migrating the repo to yarn berry with PnP enabled? (maybe it's impossible, but it's clear from the outside why 🙂)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are several things going on:

  1. I switched this projecto pnp to have a reliable integration test (run indexer on its own codebase)
  2. The compat plugin is only present in the Berry lineage of Yarn it seems - https://github.com/yarnpkg/berry/blob/master/packages/plugin-compat/sources/index.ts#L15C22-L15C31 which likely means it won't work with older Yarn. Just adding the plugin to devDependencies (or dependencies) did nothing
  3. On the Yarn 1.x the TS is not patched - only ts-loader for Webpack is: https://classic.yarnpkg.com/en/docs/pnp/getting-started#search

All this hairball means that in order to apply the typescript patch I had to switch to Yarn 3.x in this project (so that TS patch is applied automatically), but that led ot other issues needing fixing.

I'm currently stuck at what appears to be that something with regards to module resolution is still broken - but it no longer happens in tsconfig.json (which was the original problem), but it happens when analysing the code itself - imports from modules just become local definitions, which is wrong.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll just use this thread as a brain dump

I have a hunch that current issue with missing imports is related to PnP in the following way:

  1. We associate packages with filenames when we process node_modules as part of the indexing: https://github.com/sourcegraph/scip-typescript/blob/main/src/Packages.ts#L10
  2. Because there are no node_modules, the imported files are never processed, and therefore never associated with a package name
  3. Because it's not a normal package resolution made by TS, the patch doesn't apply to it

As a stop gap solution, we could just change nodeLinker to node-modules before yarn install.

Yarn docs warn against it, and we will be operating on a dirty codebase, but IMO this will be so much quicker to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support PnP strategy in Yarn Berry
2 participants