fix(dev-server): invalidate WRN cache by content
This commit is contained in:
@@ -119,17 +119,21 @@ function compileWireToTs(file: string, version = 0): string {
|
||||
const cacheDir = compileCacheDir ?? join(dirname(file), ".wrnexus");
|
||||
const name = basename(file).replace(/\.wrn$/, "");
|
||||
const suffix = version ? `-hmr-${version}` : "";
|
||||
const out = join(cacheDir, `${name}-${hashPath(file)}${suffix}.wrn.ts`);
|
||||
const source = readFileSync(file, "utf8");
|
||||
// Include the source contents in the cache identity. Package managers, git
|
||||
// checkouts, archive extraction, and linked dependencies can all replace a
|
||||
// file while preserving (or moving backwards) its mtime. An mtime-only cache
|
||||
// then serves an older compiled component even across a clean build.
|
||||
const out = join(cacheDir, `${name}-${hashPath(file)}-${hashPath(source)}${suffix}.wrn.ts`);
|
||||
|
||||
// Skip recompiling when the on-disk cache is already newer than the source
|
||||
// (e.g. reused across dev restarts) — avoids a read + compile + write.
|
||||
// The content hash makes this safe even when source timestamps are preserved.
|
||||
try {
|
||||
if (statSync(out).mtimeMs >= statSync(file).mtimeMs) return out;
|
||||
if (statSync(out).isFile()) return out;
|
||||
} catch {
|
||||
/* cache missing → compile below */
|
||||
}
|
||||
|
||||
const code = compileWireFile(readFileSync(file, "utf8"), file);
|
||||
const code = compileWireFile(source, file);
|
||||
mkdirSync(cacheDir, { recursive: true });
|
||||
writeFileSync(out, code, "utf8");
|
||||
return out;
|
||||
|
||||
Reference in New Issue
Block a user