oxc-project / oxc-resolver

Rust version of webpack/enhanced-resolve
https://oxc.rs/docs/guide/usage/resolver.html
MIT License
133 stars 20 forks source link

Resolving symlinked long path on Windows returns a DOS device path #295

Open sapphi-red opened 1 day ago

sapphi-red commented 1 day ago

When resolving a symlinked file that has a long path, oxc-resolver returns a DOS device path (a path starting with \\?\) on Windows. I expect a normal path to be returned (a path without \\?\).

Reproduction

  1. Clone https://github.com/sapphi-red-repros/oxc-resolver-windows-long-path-dos-device-path-reproduction on Windows
  2. run pnpm i
  3. run node index.js
  4. the output is something like result \\?\D:\documents\GitHub\oxc-resolver-windows-long-path-dos-device-path-reproduction\node_modules\.pnpm\@vitejs+longfilename-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_pdxfg5khqstn67ymcqlkhhhflu\node_modules\@vitejs\longfilename-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\index.js
Boshen commented 1 day ago

https://github.com/oxc-project/oxc-resolver/blob/a6a9b0bcd1a068bb228c1ab011144a2055a9b644/src/file_system.rs#L173-L174

If you are on windows, can you try and use the example https://github.com/oxc-project/oxc-resolver/blob/main/examples/resolver.rs and see what's happening here.

I'm not on windows and I don't understand windows path at all :-/

sapphi-red commented 1 day ago

dunce::canonicalize seems to only trim \\?\ when the path is shorter than 260 chars. https://gitlab.com/kornelski/dunce/-/blob/1ee29a83526c9f4c3618e1335f0454c878a54dcf/src/lib.rs#L176-180 On the other hand, libuv always strips \\?\ regardless of the char length. https://github.com/libuv/libuv/blob/d4ab6fbba4669935a6bc23645372dfe4ac29ab39/src/win/fs.c#L2780-L2785

sapphi-red commented 1 day ago

When using the path from Node.js side, it would be easier to use if \\?\ is always stripped. But I'm not sure if that is easier to use for the Rust side.

Boshen commented 1 day ago

When using the path from Node.js side, it would be easier to use if \\?\ is always stripped. But I'm not sure if that is easier to use for the Rust side.

Rust side has no preference, we can strip it if things still work.