Skip to content

[node-core-library] Fix semantics of RealNodeModulePath #5042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

dmichon-msft
Copy link
Contributor

@dmichon-msft dmichon-msft commented Dec 13, 2024

Summary

Updates RealNodeModulePath to match the behavior of fs.realpathSync.native with respect to relative paths and trailing slashes.

Details

Relative paths go through path.resolve, which will join them with the current working directory.
If the path has one or more trailing path separators, they will be removed, unless the path is a root, at which point it will be normalized to one trailing path separator.

Switched to using path.join to ensure that empty path segments get pruned.

This will somewhat slow the performance, since path.parse and path.format are a bit more work that previous API calls, but it will produce correct results on Windows when link targets are absolute paths with trailing path separators.

How it was tested

Additional unit tests.

Impacted documentation

None. Semantics of fs.realpathSync.native are matched, as is the purpose of the API.

@dmichon-msft dmichon-msft enabled auto-merge (squash) December 13, 2024 23:55
@dmichon-msft dmichon-msft merged commit 2e2ac57 into microsoft:main Dec 14, 2024
5 checks passed
@dmichon-msft dmichon-msft deleted the user/dmichon/trim-trailing-slash branch December 14, 2024 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

3 participants