Skip to content

Commit

Permalink
fix: normalize windows paths in vites watcher (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Apr 13, 2024
1 parent 2cd3fa9 commit ff93773
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/weak-bulldogs-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marko/vite": patch
---

Fix issue where filename from vites watcher was not in posix which was preventing clearing cached data.
15 changes: 8 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,24 +396,25 @@ export default function markoPlugin(opts: Options = {}): vite.Plugin[] {
configureServer(_server) {
ssrConfig.hot = domConfig.hot = true;
devServer = _server;
devServer.watcher.on("all", (type, filename) => {
cachedSources.delete(filename);
devServer.watcher.on("all", (type, originalFileName) => {
const fileName = normalizePath(originalFileName);
cachedSources.delete(fileName);

if (type === "unlink") {
entryIds.delete(filename);
transformWatchFiles.delete(filename);
transformOptionalFiles.delete(filename);
entryIds.delete(fileName);
transformWatchFiles.delete(fileName);
transformOptionalFiles.delete(fileName);
}

for (const [id, files] of transformWatchFiles) {
if (anyMatch(files, filename)) {
if (anyMatch(files, fileName)) {
devServer.watcher.emit("change", id);
}
}

if (type === "add" || type === "unlink") {
for (const [id, files] of transformOptionalFiles) {
if (anyMatch(files, filename)) {
if (anyMatch(files, fileName)) {
devServer.watcher.emit("change", id);
}
}
Expand Down

0 comments on commit ff93773

Please sign in to comment.