Skip to content

Commit

Permalink
fix(pnp): fallback to initialApiPath when api can't be located for vi…
Browse files Browse the repository at this point in the history
…rtual path
  • Loading branch information
merceyz committed Sep 23, 2020
1 parent 290c685 commit 47e6452
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
11 changes: 8 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.

13 changes: 8 additions & 5 deletions packages/yarnpkg-pnp/sources/loader/makeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ export function makeManager(pnpapi: PnpApi, opts: MakeManagerOptions) {
}

function findApiPathFor(modulePath: NativePath) {
const start = VirtualFS.resolveVirtual(
ppath.resolve(npath.toPortablePath(modulePath)),
);
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,12 @@ 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 {
return initialApiPath;
}
}

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

0 comments on commit 47e6452

Please sign in to comment.