From 15ba5ab9315fff960a93378683bb65de09a06b18 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Wed, 23 Jul 2025 11:48:46 +0200 Subject: [PATCH] fix: rebuild should not fail if an index file is not found in the store (#9788) --- .changeset/modern-windows-smoke.md | 5 +++++ .../src/implementation/index.ts | 19 ++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 .changeset/modern-windows-smoke.md diff --git a/.changeset/modern-windows-smoke.md b/.changeset/modern-windows-smoke.md new file mode 100644 index 0000000000..5e4da816df --- /dev/null +++ b/.changeset/modern-windows-smoke.md @@ -0,0 +1,5 @@ +--- +"@pnpm/plugin-commands-rebuild": patch +--- + +Rebuild should not fail if it cannot find an index file in the store for the built package. diff --git a/exec/plugin-commands-rebuild/src/implementation/index.ts b/exec/plugin-commands-rebuild/src/implementation/index.ts index 5c96c73307..76ea83e073 100644 --- a/exec/plugin-commands-rebuild/src/implementation/index.ts +++ b/exec/plugin-commands-rebuild/src/implementation/index.ts @@ -345,13 +345,18 @@ async function _rebuild ( const pkgId = `${pkgInfo.name}@${pkgInfo.version}` if (opts.skipIfHasSideEffectsCache && resolution.integrity) { const filesIndexFile = getIndexFilePathInCafs(opts.storeDir, resolution.integrity!.toString(), pkgId) - const pkgFilesIndex = await loadJsonFile(filesIndexFile) - sideEffectsCacheKey = calcDepState(depGraph, depsStateCache, depPath, { - includeDepGraphHash: true, - }) - if (pkgFilesIndex.sideEffects?.[sideEffectsCacheKey]) { - pkgsThatWereRebuilt.add(depPath) - return + let pkgFilesIndex: PackageFilesIndex | undefined + try { + pkgFilesIndex = await loadJsonFile(filesIndexFile) + } catch {} + if (pkgFilesIndex) { + sideEffectsCacheKey = calcDepState(depGraph, depsStateCache, depPath, { + includeDepGraphHash: true, + }) + if (pkgFilesIndex.sideEffects?.[sideEffectsCacheKey]) { + pkgsThatWereRebuilt.add(depPath) + return + } } } let requiresBuild = true