From e15d5da0efba221209190deb2f3f98466f135d78 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 27 Jun 2022 12:24:56 +0100 Subject: [PATCH] fix: return `.` as dirname fallback for non-absolute paths (#19) --- src/path.ts | 2 +- test/index.spec.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/path.ts b/src/path.ts index 99c9c0a..a61bee0 100644 --- a/src/path.ts +++ b/src/path.ts @@ -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 diff --git a/test/index.spec.ts b/test/index.spec.ts index 1e25697..d1e6048 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -44,6 +44,7 @@ runTest('basename', basename, [ runTest('dirname', dirname, { // POSIX + 'test.html': '.', '/temp/': '/', '/temp/myfile.html': '/temp', './myfile.html': '.',