From 944ef3807a8da5df566269daf161cc5639810e84 Mon Sep 17 00:00:00 2001 From: Pedro <37028775+pedro-gomes-92@users.noreply.github.com> Date: Thu, 28 Nov 2024 15:24:41 +0800 Subject: [PATCH] [rush] Skip unrelated projects shrinkwrap-deps during state snapshot --- ...-non-existing-hashes_2024-11-28-07-23.json | 10 ++++++++ .../src/logic/ProjectChangeAnalyzer.ts | 24 +++++++++---------- 2 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 common/changes/@microsoft/rush/pedrogomes-fix-non-existing-hashes_2024-11-28-07-23.json 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