diff --git a/common/changes/@microsoft/rush/pedrogomes-fix-non-existing-hashes_2024-11-28-07-23.json b/common/changes/@microsoft/rush/pedrogomes-fix-non-existing-hashes_2024-11-28-07-23.json new file mode 100644 index 00000000000..3e05c3638a8 --- /dev/null +++ b/common/changes/@microsoft/rush/pedrogomes-fix-non-existing-hashes_2024-11-28-07-23.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "Fix an issue where Rush sometimes incorrectly reported \"fatal: could not open 'packages/xxx/.rush/temp/shrinkwrap-deps.json' for reading: No such file or directory\" when using subspaces", + "type": "none" + } + ], + "packageName": "@microsoft/rush" +} \ No newline at end of file diff --git a/libraries/rush-lib/src/logic/ProjectChangeAnalyzer.ts b/libraries/rush-lib/src/logic/ProjectChangeAnalyzer.ts index 942cbac6bdd..6c820c9ca78 100644 --- a/libraries/rush-lib/src/logic/ProjectChangeAnalyzer.ts +++ b/libraries/rush-lib/src/logic/ProjectChangeAnalyzer.ts @@ -257,25 +257,23 @@ export class ProjectChangeAnalyzer { const additionalRelativePathsToHash: string[] = []; const globalAdditionalFiles: string[] = []; if (rushConfiguration.packageManager === 'pnpm') { - const absoluteFilePathsToCheck: string[] = []; - - for (const project of rushConfiguration.projects) { + await Async.forEachAsync(rushConfiguration.projects, async (project: RushConfigurationProject) => { const projectShrinkwrapFilePath: string = BaseProjectShrinkwrapFile.getFilePathForProject(project); - absoluteFilePathsToCheck.push(projectShrinkwrapFilePath); - const relativeProjectShrinkwrapFilePath: string = Path.convertToSlashes( - path.relative(rootDirectory, projectShrinkwrapFilePath) - ); - - additionalRelativePathsToHash.push(relativeProjectShrinkwrapFilePath); - } + if (!(await FileSystem.existsAsync(projectShrinkwrapFilePath))) { + if (rushConfiguration.subspacesFeatureEnabled) { + return; + } - await Async.forEachAsync(absoluteFilePathsToCheck, async (filePath: string) => { - if (!rushConfiguration.subspacesFeatureEnabled && !(await FileSystem.existsAsync(filePath))) { throw new Error( - `A project dependency file (${filePath}) is missing. You may need to run ` + + `A project dependency file (${projectShrinkwrapFilePath}) is missing. You may need to run ` + '"rush install" or "rush update".' ); } + + const relativeProjectShrinkwrapFilePath: string = Path.convertToSlashes( + path.relative(rootDirectory, projectShrinkwrapFilePath) + ); + additionalRelativePathsToHash.push(relativeProjectShrinkwrapFilePath); }); } else { // Add the shrinkwrap file to every project's dependencies