Hash the pnpm patches directory in the rspack cache version (#54478)

The persistent cache version still hashed `.yarn/patches`, which moved to
`patches/` in #54392. The lookup is guarded by `existsSync`, so it failed
silently and patch contents stopped contributing to the version at all.

That hash is the only thing that notices a patch change: a patch alters a
package's files but not its version, which is all rspack's node_modules
snapshot checks. Editing a patch therefore left the cache version
identical and the build reused stale compiled modules.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Bram Kragten
2026-10-01 08:22:39 +03:00
committed by GitHub
co-authored by Claude Opus 5
parent d68a113f4c
commit 8acc456dfd
+5 -5
View File
@@ -54,9 +54,9 @@ const CONFIG_FILES = [
path.join(__dirname, "babel-plugins", "inline-constants-plugin.cjs"),
];
// Yarn patches change a package's files but not its version, which is all the
// Patches change a package's files but not its version, which is all the
// node_modules snapshot checks, so their contents go into the version too.
const YARN_PATCHES_DIR = path.join(paths.root_dir, ".yarn", "patches");
const PATCHES_DIR = path.join(paths.root_dir, "patches");
// Content hash of the toolchain versions and our own build files, used as the
// persistent cache `version`. Everything here is path-independent so the cache
@@ -69,12 +69,12 @@ const cacheVersion = () => {
...CONFIG_FILES.map(
(file) => `${path.basename(file)}:${fs.readFileSync(file, "utf8")}`
),
...(existsSync(YARN_PATCHES_DIR) ? fs.readdirSync(YARN_PATCHES_DIR) : [])
...(existsSync(PATCHES_DIR) ? fs.readdirSync(PATCHES_DIR) : [])
.filter((file) => file.endsWith(".patch"))
.sort()
.map(
(file) =>
`${file}:${fs.readFileSync(path.join(YARN_PATCHES_DIR, file), "utf8")}`
`${file}:${fs.readFileSync(path.join(PATCHES_DIR, file), "utf8")}`
),
];
return require("crypto")
@@ -489,7 +489,7 @@ const createRspackConfig = ({
// `name` is already unique per variant (frontend-modern/-legacy).
name,
// Content-based version (node major + toolchain versions + our own
// build files + Yarn patches). Everything is path-independent, so
// build files + patches). Everything is path-independent, so
// the cache stays valid when reused on another machine/checkout.
// Runtime deps are deliberately absent — rspack's node_modules
// snapshot invalidates their modules per-package, so a single