aleclarson / vite-tsconfig-paths

Support for TypeScript's path mapping in Vite
MIT License
1.28k stars 45 forks source link

Paths never get remapped on Windows #5

Closed TrixterTheTux closed 3 years ago

TrixterTheTux commented 3 years ago

Tried using this module on Linux, and it seems to do a great job.

Though on a Windows environment it seems that the resolve for root here breaks the local descendant output due to generating the root in a different format. Originally, the root passed to configResolved is in the format of /Users/..., but the resolve() changes it to the format of C:\Users\....

The resolveId's importer variable follows the root variable's path scheme, so the isLocalDescendant function will never be able to correctly validate that the path starts with root (as it compares format of /Users/... to C:\Users\...). It also additionally uses sep after the resolve, which seems to be always / for importer's paths (instead of sep's value \ on Windows) from my testing.

Changing the mentioned line to root = (opts.root || root) + '/'; seems to fix the issue on both OSes, though I don't know if this is a good fix due to opts.root being configurable by the user and it could follow the C:\Users\... format too due to usage of e.g. process.cwd() or path.join().

aleclarson commented 3 years ago

Fixed in 2.0.0-alpha.4. Thanks for the detailed report!