Skip to content

Commit

Permalink
pnp: more hacks to allow absolute paths to /nix/store in .pnp.cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-gierakowski committed Jan 31, 2022
1 parent 22a8142 commit e50ebaa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
11 changes: 7 additions & 4 deletions packages/yarnpkg-pnp/sources/loader/hydrateRuntimeState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
},
}];
}))];
Expand Down
16 changes: 12 additions & 4 deletions packages/yarnpkg-pnp/sources/loader/makeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -508,7 +516,7 @@ export function makeApi(runtimeState: RuntimeState, opts: MakeApiOptions): PnpAp
}

return entry.locator;
} while (relativeLocation !== ``);
} while (relativeLocation !== boundryValue);

return null;
}
Expand Down

0 comments on commit e50ebaa

Please sign in to comment.