normalizePath is used to normalize file URLs, buffers, and irregular strings into valid paths.
Part of this normalization is converting the path into an absolute one via path.resolve. Unfortunatly, normalizePath is not aware of contexts, resulting in path.resolve always using the default context's PWD to resolve relative paths. This was originally pointed out by @jeff-hykin in #261:
One thing though, a bug that would be my first actual PR: I think resolve needs to use this to get the pwd. E.g. this bit of code Right now its always using the default context's pwd. Also, similar bug, normalizePath in utils needs this so it can pass it to resolve. Then, because of that, a lot of normalizePath and resolve calls need to be changed to resolve.call(this, x).
Additionally, calls to normalizePath are duplicated acros multiple code paths. For example, take lstat:
lstat
├ normalizePath
├ realpath
│ ├ normalizePath
│ └ _resolve
│ └ resolveMount
│ └ normalizePath
└ resolveMount
└ normalizePath
That's 4 calls to normalizePath in the best case. Resolving parent directories and symlinks in _resolve further increases the number of calls.
In order to properly fix this problem, the path resolution will be cleaned up to handle everything at once without a mess of function calls and properly handle PWDs.
normalizePathis used to normalize file URLs, buffers, and irregular strings into valid paths.Part of this normalization is converting the path into an absolute one via
path.resolve. Unfortunatly,normalizePathis not aware of contexts, resulting inpath.resolvealways using the default context's PWD to resolve relative paths. This was originally pointed out by @jeff-hykin in #261:Additionally, calls to
normalizePathare duplicated acros multiple code paths. For example, takelstat:That's 4 calls to
normalizePathin the best case. Resolving parent directories and symlinks in_resolvefurther increases the number of calls.In order to properly fix this problem, the path resolution will be cleaned up to handle everything at once without a mess of function calls and properly handle PWDs.