Skip to content

Commit

Permalink
chore: reapply arcanis#4
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed Mar 29, 2021
1 parent 448f2bb commit e762616
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2201,6 +2201,40 @@ namespace ts.server {
}

updateReferences(refs: readonly ProjectReference[] | undefined) {
// @ts-ignore
if (process.versions.pnp) {
// With Plug'n'Play, dependencies that list peer dependencies
// are "virtualized": they are resolved to a unique (virtual)
// path that the underlying filesystem layer then resolve back
// to the original location.
//
// When a workspace depends on another workspace with peer
// dependencies, this other workspace will thus be resolved to
// a unique path that won't match what the initial project has
// listed in its `references` field, and TS thus won't leverage
// the reference at all.
//
// To avoid that, we compute here the virtualized paths for the
// user-provided references in our references by directly querying
// the PnP API. This way users don't have to know the virtual paths,
// but we still support them just fine even through references.

const pnpApi = require("pnpapi");
const basePath = this.getCurrentDirectory();

const getPnpPath = (path: string) => {
try {
const targetLocator = pnpApi.findPackageLocator(`${path}/`);
return pnpApi.resolveToUnqualified(targetLocator.name, `${basePath}/`);
} catch {
// something went wrong with the resolution, try not to fail
return path;
}
};

refs = refs?.map(r => ({...r, path: getPnpPath(r.path)}));
}

this.projectReferences = refs;
this.potentialProjectReferences = undefined;
}
Expand Down

0 comments on commit e762616

Please sign in to comment.