Skip to content

Commit

Permalink
fix: return . as dirname fallback for non-absolute paths (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Jun 27, 2022
1 parent 69696c4 commit e15d5da
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export const relative: typeof path.relative = function (from, to) {

// dirname
export const dirname: typeof path.dirname = function (p) {
return normalizeWindowsPath(p).replace(/\/$/, '').split('/').slice(0, -1).join('/') || '/'
return normalizeWindowsPath(p).replace(/\/$/, '').split('/').slice(0, -1).join('/') || (isAbsolute(p) ? '/' : '.')
}

// format
Expand Down
1 change: 1 addition & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ runTest('basename', basename, [

runTest('dirname', dirname, {
// POSIX
'test.html': '.',
'/temp/': '/',
'/temp/myfile.html': '/temp',
'./myfile.html': '.',
Expand Down

0 comments on commit e15d5da

Please sign in to comment.