Skip to content

Commit

Permalink
Fix for Windows Git Bash w/ pnpm (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack1323 authored Dec 17, 2024
1 parent 97efce9 commit 8a36324
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/lib/lockfile/helpers/generate-pnpm-lockfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,17 @@ export async function generatePnpmLockfile({
* importer ids in the context of a lockfile.
*/
...Object.values(directoryByPackageName),
];
/**
* Split the path by the OS separator and join it back with the POSIX
* separator.
*
* The importerIds are built from directory names, so Windows Git Bash
* environments will have double backslashes in their ids:
* "packages\common" vs. "packages/common". Without this split & join, any
* packages not on the top-level will have ill-formatted importerIds and
* their entries will be missing from the lockfile.importers list.
*/
].map((x) => x.split(path.sep).join(path.posix.sep));

log.debug("Relevant importer ids:", relevantImporterIds);

Expand Down
8 changes: 4 additions & 4 deletions src/lib/lockfile/helpers/pnpm-map-importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ function pnpmMapDependenciesLinks(
return value;
}

const relativePath = path.relative(
importerPath,
directoryByPackageName[key]
);
// Replace backslashes with forward slashes to support Windows Git Bash
const relativePath = path
.relative(importerPath, directoryByPackageName[key])
.replace(path.sep, path.posix.sep);

return relativePath.startsWith(".")
? `link:${relativePath}`
Expand Down

0 comments on commit 8a36324

Please sign in to comment.