Skip to content

fix: resolve real path for case insensitive systems#4935

Merged
zkochan merged 4 commits into
pnpm:mainfrom
mdogadailo:bugfix/fwd-case-insensitive-systems
Jun 26, 2022
Merged

fix: resolve real path for case insensitive systems#4935
zkochan merged 4 commits into
pnpm:mainfrom
mdogadailo:bugfix/fwd-case-insensitive-systems

Conversation

@mdogadailo

Copy link
Copy Markdown
Contributor

For case insensitive systems (Windows) findWorkspaceDir will return the path to the module as it was called (because of cwd) not the real path.

It leads to an issue when getImporters can't find the the manifest (#4904).

Can be reproduces if pnpm was called from "c:\code\project" but the real path is "C:\Code\Project".
getImporters will find all manifestsByPath as "C:\Code\Project...", but prefixes will use workspace root "c:\code\project...", and it can't match them.

It is possible to try true-case-path but has some vulnerable deps.

@mdogadailo mdogadailo requested a review from zkochan as a code owner June 25, 2022 23:32
@welcome

welcome Bot commented Jun 25, 2022

Copy link
Copy Markdown

💖 Thanks for opening this pull request! 💖
Please be patient and we will get back to you as soon as we can.


async function getRealPath (path: string) {
return new Promise<string>((resolve) => {
fs.realpath.native(path, function (err, resolvedPath) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why shoud fs.realpath.native be used instead of fs.realpath?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fs.realpath.native return the actual casing of a path as it is on disk https://github.com/nodejs/node/pull/15776/files#diff-05bc37150ff4e7aa51dc7a28c71164a9e715f45e323ac9a5c67e061821aad3d2R8, fs.realpath is resolving .., . and sym links

@zkochan zkochan Jun 26, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in that case it is better to add a comment about it because in the Node.js docs this information is not present.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zkochan I've added comments on getRealPath

@mdogadailo

mdogadailo commented Jun 26, 2022

Copy link
Copy Markdown
Contributor Author

@zkochan I fixed test for case-sensitive system. I skipped them, because it is not possible to open the path process.cwd().toUpperCase()

@mdogadailo mdogadailo force-pushed the bugfix/fwd-case-insensitive-systems branch from e58ccd4 to c5e930e Compare June 26, 2022 08:48
@zkochan

zkochan commented Jun 26, 2022

Copy link
Copy Markdown
Member

Run pnpm changeset in the root of the repository and describe your changes. The resulting files should be committed as they will be used during release.

@zkochan zkochan merged commit 6434a82 into pnpm:main Jun 26, 2022
@welcome

welcome Bot commented Jun 26, 2022

Copy link
Copy Markdown

Congrats on merging your first pull request! 🎉🎉🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants