Skip to content

Commit

Permalink
fix(pnp): resolve the virtual path of the pnpapi instead of the issuer (
Browse files Browse the repository at this point in the history
#1851)

* fix(pnp): resolve the virtual path of the pnpapi instead of the issuer

* chore: fix typo in changelog
  • Loading branch information
merceyz authored Sep 27, 2020
1 parent 8e4c097 commit 877cd49
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 42 deletions.
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

0 comments on commit 877cd49

Please sign in to comment.