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): resolve the virtual path of the pnpapi instead of the issuer #1851

Merged
merged 2 commits into from
Sep 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 9 additions & 22 deletions .pnp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions .yarn/versions/109cba4d.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/plugin-pnp": patch
"@yarnpkg/pnp": patch
"@yarnpkg/pnpify": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-node-modules"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- vscode-zipfs
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ via `nmHoistingLimits` global setting and `installConfig.hoistingLimits` `packag
- Cyclic peer dependencies inside `node_modules` are hoisted now in all possible cases
- `node-modules` linker is more forgiving now for packages with incorrect assumptions about hoisting layout,
thanks to maximizing package exposure at the top-level first and only after that minimizing package duplicates during hoisting.
- In case of `node_modules` the workspace peer dependencies are no longer ingnored. They are picked up
- In case of `node_modules` the workspace peer dependencies are no longer ignored. They are picked up
from the closest workspace, that is upper in directory hierarchy.

## Bugfixes
Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-pnp/sources/hook.js

Large diffs are not rendered by default.

32 changes: 14 additions & 18 deletions packages/yarnpkg-pnp/sources/loader/makeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ export function makeManager(pnpapi: PnpApi, opts: MakeManagerOptions) {

const findApiPathCache = new Map<PortablePath, PortablePath | null>();

function addToCache(start: PortablePath, end: PortablePath, target: PortablePath | null) {
function addToCacheAndReturn(start: PortablePath, end: PortablePath, target: PortablePath | null) {
if (target !== null)
target = VirtualFS.resolveVirtual(target);

let curr: PortablePath;
let next = start;

Expand All @@ -88,12 +91,12 @@ export function makeManager(pnpapi: PnpApi, opts: MakeManagerOptions) {
findApiPathCache.set(curr, target);
next = ppath.dirname(curr);
} while (curr !== end);

return target;
}

function findApiPathFor(modulePath: NativePath) {
const start = VirtualFS.resolveVirtual(
ppath.resolve(npath.toPortablePath(modulePath)),
);
const start = ppath.resolve(npath.toPortablePath(modulePath));

let curr: PortablePath;
let next = start;
Expand All @@ -102,28 +105,21 @@ export function makeManager(pnpapi: PnpApi, opts: MakeManagerOptions) {
curr = next;

const cached = findApiPathCache.get(curr);
if (cached !== undefined) {
addToCache(start, curr, cached);
return cached;
}
if (cached !== undefined)
return addToCacheAndReturn(start, curr, cached);

const candidate = ppath.join(curr, `.pnp.js` as Filename);
if (xfs.existsSync(candidate) && xfs.statSync(candidate).isFile()) {
addToCache(start, curr, candidate);
return candidate;
}
if (xfs.existsSync(candidate) && xfs.statSync(candidate).isFile())
return addToCacheAndReturn(start, curr, candidate);

const cjsCandidate = ppath.join(curr, `.pnp.cjs` as Filename);
if (xfs.existsSync(cjsCandidate) && xfs.statSync(cjsCandidate).isFile()) {
addToCache(start, curr, cjsCandidate);
return cjsCandidate;
}
if (xfs.existsSync(cjsCandidate) && xfs.statSync(cjsCandidate).isFile())
return addToCacheAndReturn(start, curr, cjsCandidate);

next = ppath.dirname(curr);
} while (curr !== PortablePath.root);

addToCache(start, curr, null);
return null;
return addToCacheAndReturn(start, curr, null);
}

function getApiPathFromParent(parent: Module | null | undefined): PortablePath | null {
Expand Down