From 539bc6ecc505d48d188d9646e8d8796839d561e8 Mon Sep 17 00:00:00 2001 From: Clay Risser Date: Thu, 13 Aug 2026 14:40:46 +0100 Subject: [PATCH] fix(compiler): include compiler version in persistent cache fingerprint The transform cache in node_modules/.vxrn/compiler-cache validates entries against input file mtime/content and a fingerprint of the config toggles only. Transform output also depends on the compiler implementation itself, so entries written by an older @vxrn/compiler survive an upgrade (inputs and config unchanged) and keep serving stale transforms. Fold the compiler's own package version into getConfigFingerprint() so the cache invalidates whenever the compiler changes. Version discovery mirrors getPackageVersion() in packages/one/src/cli.ts (CJS/ESM dual dirname, works from dist/{esm,cjs} and from src for tests), with a static fallback marker if package.json cannot be found. Co-authored-by: Cursor --- packages/compiler/src/cache.ts | 39 ++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/packages/compiler/src/cache.ts b/packages/compiler/src/cache.ts index 2aa73d6b0b..d0cbf8c564 100644 --- a/packages/compiler/src/cache.ts +++ b/packages/compiler/src/cache.ts @@ -1,6 +1,7 @@ import { createHash } from 'node:crypto' import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs' -import { join } from 'node:path' +import { dirname, join } from 'node:path' +import { fileURLToPath } from 'node:url' import { configuration } from './configure' /** @@ -36,11 +37,45 @@ function getCacheDir(): string { return cacheDir } -// hash config state so cache invalidates when compiler/reanimated/nativewind toggles change +// the cache persists in node_modules/.vxrn/compiler-cache and entries are +// validated only against input file mtime/content + the config fingerprint. +// transform output also depends on the compiler implementation itself, so the +// fingerprint must include the compiler version - otherwise entries written by +// an older @vxrn/compiler survive an upgrade and serve stale transforms. +function getOwnVersion(): string { + try { + const dir = + typeof __dirname !== 'undefined' + ? // CommonJS + __dirname + : // ESM + dirname(fileURLToPath(import.meta.url)) + // compiled output runs from dist/{esm,cjs}, two levels below the package + // root; straight from src (tests) it's one level below + for (const relativeRoot of ['..', join('..', '..')]) { + const candidate = join(dir, relativeRoot, 'package.json') + if (existsSync(candidate)) { + const packageJson = JSON.parse(readFileSync(candidate, 'utf-8')) + if (packageJson.name === '@vxrn/compiler' && packageJson.version) { + return packageJson.version + } + } + } + } catch { + // fall through to the static fallback marker + } + return 'unknown' +} + +const compilerVersion = getOwnVersion() + +// hash compiler version + config state so cache invalidates when the compiler +// is upgraded or the compiler/reanimated/nativewind toggles change function getConfigFingerprint(): string { return createHash('sha1') .update( JSON.stringify({ + version: compilerVersion, compiler: configuration.enableCompiler, reanimated: configuration.enableReanimated, nativewind: configuration.enableNativewind,