diff --git a/packages/yarnpkg-pnp/sources/loader/hydrateRuntimeState.ts b/packages/yarnpkg-pnp/sources/loader/hydrateRuntimeState.ts index 240eeaa8521a..3a3817f8eb0c 100644 --- a/packages/yarnpkg-pnp/sources/loader/hydrateRuntimeState.ts +++ b/packages/yarnpkg-pnp/sources/loader/hydrateRuntimeState.ts @@ -45,10 +45,13 @@ export function hydrateRuntimeState(data: SerializedState, {basePath}: HydrateRu // we only need this for packages that are used by the currently running script // this is a lazy getter because `ppath.join` has some overhead get packageLocation() { - // We use ppath.join instead of ppath.resolve because: - // 1) packageInformationData.packageLocation is a relative path when part of the SerializedState - // 2) ppath.join preserves trailing slashes - return resolvedPackageLocation || (resolvedPackageLocation = ppath.join(absolutePortablePath, packageInformationData.packageLocation)); + // We keep /nix/store paths as they are + return resolvedPackageLocation || (packageInformationData.packageLocation.match('^/nix/store/') + ? (resolvedPackageLocation = packageInformationData.packageLocation) + // We use ppath.join instead of ppath.resolve because: + // 1) packageInformationData.packageLocation is a relative path when part of the SerializedState + // 2) ppath.join preserves trailing slashes + : (resolvedPackageLocation = ppath.join(absolutePortablePath, packageInformationData.packageLocation))); }, }]; }))]; diff --git a/packages/yarnpkg-pnp/sources/loader/makeApi.ts b/packages/yarnpkg-pnp/sources/loader/makeApi.ts index 2a7fad67482f..685f54ce778c 100644 --- a/packages/yarnpkg-pnp/sources/loader/makeApi.ts +++ b/packages/yarnpkg-pnp/sources/loader/makeApi.ts @@ -491,10 +491,18 @@ export function makeApi(runtimeState: RuntimeState, opts: MakeApiOptions): PnpAp if (isPathIgnored(location) && !resolveIgnored) return null; - let relativeLocation = ppath.relative(runtimeState.basePath, location); + let relativeLocation - if (!relativeLocation.match(isStrictRegExp)) - relativeLocation = `./${relativeLocation}` as PortablePath; + + let boundryValue = `` + if (location.match('^/nix/store/')) { + relativeLocation = location + boundryValue = `/` + } else { + relativeLocation = ppath.relative(runtimeState.basePath, location); + if (!relativeLocation.match(isStrictRegExp)) + relativeLocation = `./${relativeLocation}` as PortablePath; + } if (!relativeLocation.endsWith(`/`)) relativeLocation = `${relativeLocation}/` as PortablePath; @@ -508,7 +516,7 @@ export function makeApi(runtimeState: RuntimeState, opts: MakeApiOptions): PnpAp } return entry.locator; - } while (relativeLocation !== ``); + } while (relativeLocation !== boundryValue); return null; }