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