Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/rspack/prebundle.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ export type WatchOptions = Watchpack.WatchOptions;
packageJson.types = 'index.d.ts';
return `${JSON.stringify(packageJson, null, 2)}\n`;
});

// Windows path separator normalization patch.
// Upstream watchpack's `withoutCase` only lowercases; on Windows the
// `DirectoryWatcher.doScan` initial-missing calculation registers
// watcher keys with whichever separator the caller passed in and then
// tries to delete entries keyed by `path.join()` output (backslash).
// When rspack hands over a mix of forward-slash paths (persistent
// cache rehydrate) and backslash paths (native fs / loader
// addDependency), the delete pass misses every forward-slash-keyed
// watcher and each fires a spurious `initial-missing` on hot start,
// which cascades into `compiler.removedFiles` and a full rebuild.
// Normalizing to forward slashes inside `withoutCase` collapses the
// two flavors to a single map key, matching the behavior POSIX
// already gets for free.
const indexJsPath = join(task.distPath, 'index.js');
replaceFileContent(indexJsPath, (content) =>
content.replace(
'function withoutCase(str) {\n\treturn str.toLowerCase();\n}',
"function withoutCase(str) {\n\t// Normalize backslashes in addition to lowercasing so DirectoryWatcher.doScan's\n\t// missingWatchers map key (registered with the caller's separator) matches\n\t// path.join()'s native-separator output on Windows.\n\treturn str.toLowerCase().replace(/\\\\/g, \"/\");\n}",
),
);
},
},
],
Expand Down