From ff937737d63baf628830423798856ace06b54969 Mon Sep 17 00:00:00 2001 From: Dylan Piercey Date: Sat, 13 Apr 2024 15:53:13 -0700 Subject: [PATCH] fix: normalize windows paths in vites watcher (#124) --- .changeset/weak-bulldogs-perform.md | 5 +++++ src/index.ts | 15 ++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 .changeset/weak-bulldogs-perform.md diff --git a/.changeset/weak-bulldogs-perform.md b/.changeset/weak-bulldogs-perform.md new file mode 100644 index 0000000..9fb1cf0 --- /dev/null +++ b/.changeset/weak-bulldogs-perform.md @@ -0,0 +1,5 @@ +--- +"@marko/vite": patch +--- + +Fix issue where filename from vites watcher was not in posix which was preventing clearing cached data. diff --git a/src/index.ts b/src/index.ts index fb50b28..1393a6e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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); } }