From 5ead5800bf4bf72cc70a9a1f5e015d4376ddd60b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blaisot?= Date: Tue, 17 Feb 2026 10:27:10 +0100 Subject: [PATCH] fix: invalidate stale dev_bundle cache after git branch switch After switching git branches, .meteor/release changes but .meteor/local/dev_bundle (which is gitignored) keeps pointing to the previous release's dev_bundle. This causes `meteor node` to use the wrong Node.js version until another command like `meteor --version` triggers a full springboard and refreshes the symlink. Store the release string in .meteor/local/dev_bundle_release alongside the dev_bundle symlink. Before trusting the cached symlink, verify it still matches the current .meteor/release content. --- tools/cli/dev-bundle.js | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/tools/cli/dev-bundle.js b/tools/cli/dev-bundle.js index 5a60eff3a8..2be9789140 100644 --- a/tools/cli/dev-bundle.js +++ b/tools/cli/dev-bundle.js @@ -37,12 +37,7 @@ async function getDevBundleDir() { } const devBundleLink = path.join(localDir, "dev_bundle"); - const devBundleStat = statOrNull(devBundleLink); - if (devBundleStat) { - return new Promise(function (resolve) { - resolve(links.readLink(devBundleLink)); - }); - } + const devBundleReleaseFile = path.join(localDir, "dev_bundle_release"); const release = fs.readFileSync( releaseFile, "utf8" @@ -52,10 +47,38 @@ async function getDevBundleDir() { return DEFAULT_DEV_BUNDLE_DIR; } + // Check if the cached dev_bundle link still matches the current release. + // After a git branch switch, .meteor/release changes but + // .meteor/local/dev_bundle (which is gitignored) keeps pointing to + // the old release's dev_bundle. + const devBundleStat = statOrNull(devBundleLink); + if (devBundleStat) { + var cachedRelease = null; + try { + cachedRelease = fs.readFileSync( + devBundleReleaseFile, "utf8" + ).replace(/^\s+|\s+$/g, ""); + } catch (e) { + // If the release cache file doesn't exist, invalidate the cache + // so we re-resolve the dev_bundle for the current release. + } + + if (cachedRelease === release) { + return new Promise(function (resolve) { + resolve(links.readLink(devBundleLink)); + }); + } + } + const devBundleDir = await getDevBundleForRelease(release); if (devBundleDir) { links.makeLink(devBundleDir, devBundleLink); + try { + fs.writeFileSync(devBundleReleaseFile, release, "utf8"); + } catch (e) { + // Non-fatal: the link itself was created successfully. + } return devBundleDir; }