ITADN

Path resolution fails when changing PWD in contexts, `normalizePath` calls are duplicated.

#263Closedjames-pre 创建于 2025-09-09
J
james-precommented
`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](https://github.com/jeff-hykin/core/blob/5bae834dc21dab5525622ac9f4ff42af590363a2/src/path.ts#L110) 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.
关闭于 2025-11-17 7 条评论