You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I find the fact that path.relative returns a valid path, except in one corner case when the two arguments are identical, rather inconvenient.
However, this is probably intentional since there is a test for this introduced in #2106. But I haven't found any reasoning for this, and the reasoning of #2106 itself is not (directly) applicable here: it's one thing to defensively treat empty strings as '.', and the other to return an empty string instead of a valid path.
I see what you mean, but '.' means 'current directory' to me, something which does not seem correct for me for arbitrary paths which are equal. It would only be correct when dir equals $PWD.
I see what you mean, but '.' means 'current directory' to me, something which does not seem correct for me for arbitrary paths which are equal. It would only be correct when dir equals $PWD.
That's not actually correct. Every directory has '.' and '..', and they can appear anywhere in the path:
Shouldn't path.relative(dir, dir) just return dir?
No, that would imply there's another sub-directory like /dir/dir when dir = '/dir'.
That's not actually correct. Every directory has '.' and '..', and they can appear anywhere in the path:
Right, I see returning '.' has some uses, like process.chdir(path.relative(process.cwd(), 'dir')). Still, I'm uncomfortable with breaking documented behaviour.
Activity
silverwind commentedon Jan 24, 2016
I see what you mean, but
'.'means 'current directory' to me, something which does not seem correct for me for arbitrary paths which are equal. It would only be correct whendirequals$PWD.eush77 commentedon Jan 24, 2016
That's not actually correct. Every directory has
'.'and'..', and they can appear anywhere in the path:zeusdeux commentedon Jan 24, 2016
Shouldn't
path.relative(dir, dir)just returndir?silverwind commentedon Jan 24, 2016
No, that would imply there's another sub-directory like
/dir/dirwhendir = '/dir'.Right, I see returning
'.'has some uses, likeprocess.chdir(path.relative(process.cwd(), 'dir')). Still, I'm uncomfortable with breaking documented behaviour.evanlucas commentedon Jan 29, 2016
This is documented at https://nodejs.org/dist/latest-v5.x/docs/api/path.html#path_path_relative_from_to.
I'll go ahead and close. Thanks!