Skip to content

Commit

Permalink
fix(compiler): handle file rename in watch mode (#5968)
Browse files Browse the repository at this point in the history
Fixes: #3443

STENCIL-1104
  • Loading branch information
tanner-reits authored Sep 5, 2024
1 parent 8ad326c commit b25a981
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/compiler/build/watch-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ export const createWatchBuild = async (
);
}

// Make sure all files in the module map are still in the fs
// Otherwise, we can run into build errors because the compiler can think
// there are two component files with the same tag name
Array.from(compilerCtx.moduleMap.keys()).forEach((key) => {
if (filesUpdated.has(key) || filesDeleted.has(key)) {
// Check if the file exists in the fs
const fileExists = compilerCtx.fs.accessSync(key);
if (!fileExists) {
compilerCtx.moduleMap.delete(key);
}
}
});

// Make sure all added/updated files are watched
// We need to check both added/updates since the TS watch program behaves kinda weird
// and doesn't always handle file renames the same way
new Set([...filesUpdated, ...filesAdded]).forEach((filePath) => {
compilerCtx.addWatchFile(filePath);
});

dirsAdded.clear();
dirsDeleted.clear();
filesAdded.clear();
Expand Down

0 comments on commit b25a981

Please sign in to comment.