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: trim root folder / when calculating relative paths #142

Merged
merged 8 commits into from Dec 12, 2023
Merged

Conversation

peterroe
Copy link
Contributor

@peterroe peterroe commented Oct 20, 2023

πŸ”— Linked issue

resolves #126

❓ 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

The split method will generate redundant "" when pass a root path

pathe/src/path.ts

Lines 213 to 215 in 055f50a

export const relative: typeof path.relative = function (from, to) {
const _from = resolve(from).split("/");
const _to = resolve(to).split("/");

"/".split("/") //=> ["", ""] 
// But expected [""]

πŸ“ Checklist

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

src/utils.ts Outdated Show resolved Hide resolved
@pi0 pi0 requested a review from danielroe October 21, 2023 20:50
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

LGTM (have to test locally for possible perf improvement tough)

@codecov
Copy link

codecov bot commented Oct 21, 2023

Codecov Report

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

Comparison is base (b7ff533) 99.41% compared to head (a596657) 99.41%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #142   +/-   ##
=======================================
  Coverage   99.41%   99.41%           
=======================================
  Files           4        4           
  Lines         340      342    +2     
  Branches      105      105           
=======================================
+ Hits          338      340    +2     
  Misses          2        2           

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

src/path.ts Outdated Show resolved Hide resolved
@peterroe
Copy link
Contributor Author

All set πŸ‘€

@peterroe
Copy link
Contributor Author

πŸ‘€ Maybe we should fix this in time? cc @danielroe

@danielroe danielroe changed the title fix: relative method when pass root path fix: trim root folder / when calculating relative paths Nov 15, 2023
@danielroe danielroe requested a review from pi0 November 15, 2023 09:00
@danielroe danielroe requested review from pi0 and removed request for pi0 December 11, 2023 11:14
@pi0 pi0 merged commit 5930a85 into unjs:main Dec 12, 2023
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.

Incorrect relative behavior with "/"
3 participants