Skip to content
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

fix(resolveAlias): handle aliases ending with trailing slash #155

Merged
merged 8 commits into from
Jan 10, 2024

Conversation

huang-julien
Copy link
Contributor

πŸ”— Linked issue

resolve #154

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Hi πŸ‘‹ this PR fix resolveAlias's pathSeperator check by verifying if the alias ends with / or \

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@pi0 pi0 requested a review from danielroe December 27, 2023 13:36
Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

What about alternatively stripping trailing-slashes in normalizeAliases?

@pi0
Copy link
Member

pi0 commented Jan 2, 2024

The only possible downside I can think with stripping trailing slash is then made npm-package (main import) and npm-package/ (all subpath exports) for when normalizeAliases util will be used. Would only normalizing backslash in aliases also worked? (haven't tried PR locally yet)

Copy link

codecov bot commented Jan 2, 2024

Codecov Report

All modified and coverable lines are covered by tests βœ…

Comparison is base (dffa918) 99.42% compared to head (9aeeee2) 99.44%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #155      +/-   ##
==========================================
+ Coverage   99.42%   99.44%   +0.02%     
==========================================
  Files           4        4              
  Lines         346      359      +13     
  Branches      106      111       +5     
==========================================
+ Hits          344      357      +13     
  Misses          2        2              

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

@danielroe
Copy link
Member

I think we already handle that via ordering of aliases (we sort them).

@pi0
Copy link
Member

pi0 commented Jan 2, 2024

What if one wants to only alias main package or it's subpaths? By removing there is no longer a way to distinguish even if sorted.

@danielroe
Copy link
Member

you're right that we no longer have a way to alias only subpaths, though I think aliasing only main package would work same way either way.

@huang-julien
Copy link
Contributor Author

should we leave it like that ?

@pi0
Copy link
Member

pi0 commented Jan 10, 2024

I have added a few more tests for mixed situations (aliases provided both for with trailing slash and without) and also did some refactors to resolveAlias mainly to make logic readable (impl change is same as original PR).

With these changes, could quickly check if we remove the trailing slash of the alias while slicing in L54 (simply change alias to _alias without trailing, and it fails), while the current fix only checks alias prefix without trailing slash for condition and uses original alias preserving this.

@pi0 pi0 changed the title fix: resolve alias ending with / or \ fix(resolveAlias): handle aliases ending with trailing slash Jan 10, 2024
@pi0 pi0 merged commit 2fa8aaa into unjs:main Jan 10, 2024
3 checks passed
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.

Cannot resolve alias with /
3 participants