Skip to content

Commit

Permalink
fix(pnp): search virtual path base when api can't be located for virt…
Browse files Browse the repository at this point in the history
…ual path target
  • Loading branch information
merceyz committed Sep 24, 2020
1 parent 290c685 commit 6e30a6e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
12 changes: 9 additions & 3 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 packages/yarnpkg-pnp/sources/hook.js

Large diffs are not rendered by default.

20 changes: 14 additions & 6 deletions packages/yarnpkg-pnp/sources/loader/makeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ export function makeManager(pnpapi: PnpApi, opts: MakeManagerOptions) {
} while (curr !== end);
}

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

let curr: PortablePath;
let next = start;
Expand Down Expand Up @@ -122,8 +121,17 @@ export function makeManager(pnpapi: PnpApi, opts: MakeManagerOptions) {
next = ppath.dirname(curr);
} while (curr !== PortablePath.root);

addToCache(start, curr, null);
return null;
if (pModulePath === start) {
addToCache(start, curr, null);
return null;
} else {
// Can't locate pnpapi from virtual path target, so try from the base
return findApiPathFor(
npath.fromPortablePath(
pModulePath.substr(0, pModulePath.indexOf(`$$virtual`) - 1)
)
);
}
}

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

0 comments on commit 6e30a6e

Please sign in to comment.