ElMassimo / vite-plugin-full-reload

♻️ Automatically reload the page when files are modified
MIT License
147 stars 8 forks source link

Normalise windows paths #7

Closed timacdonald closed 2 years ago

timacdonald commented 2 years ago

(hopefully) Fixes #6

My (possibly flawed) understanding of the problem is that the path.resolve function is converting POSIX paths to Windows paths on Windows machines.

So specifying...

FullReload(['path/to/files/**'])

results in...

["path\\to\\files\\**"]

after calling...

const files = Array.from(paths).map(path => resolve(root, path)).map(normalizePath)

chokidar.watch is then expecting to receive POSIX paths. From the docs...

Screen Shot 2022-07-21 at 1 23 12 pm

So it all breaks down.

This PR proposes that we pipe all paths through Vite's normalizePath function before passing to chokidar. I believe this is the recommended way of doing things:

Screen Shot 2022-07-21 at 1 06 53 pm

The normalizePath function is available in Vite 2 and Vite 3.

Warning: I do not have a windows machine to verify the bug, but also to verify this fix. This solutions needs some real-world testing to be done. I'm just taking a stab in the dark at the fix here 🤠

ElMassimo commented 2 years ago

Thanks Tim! We'll need to add vite as a peer dependency now, I'll do that on a separate PR.

timacdonald commented 2 years ago

@ElMassimo were you able to test this fix to validate it? I finally got a Windows virtual machine setup so I can test it if you didn't yourself?

edit: oh, I see that @guasam tested it for us! Thank you!

timacdonald commented 2 years ago

p.s. my bad on the peer dependency! thanks for adding that in.