Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rush-lib] Fix shrinkwrap-deps.json missing file #5021

Merged

Conversation

pedro-gomes-92
Copy link
Contributor

@pedro-gomes-92 pedro-gomes-92 commented Nov 28, 2024

Summary

Fixes a regression where Rush sometimes incorrectly reports "fatal: could not open 'packages/xxx/.rush/temp/shrinkwrap-deps.json' for reading: No such file or directory" when using subspaces.

Details

What happened?

CleanShot 2024-11-28 at 15 34 37@2x

We have a repository with 3 subspaces: S1, S2 and S3. At the same time, P1 depends on P2 and P3.
We committed changes to the project P1.

When running rush install --from git:origin/master, Rush will install the dependencies for S1 and S2, but NOT S3, which is correct!

BUT, when running rush build --from git:origin/master, Rush fails with the message:

Error calculating the state of the repo. (inner error: Error: git --no-optional-locks exited with code 128:
fatal: could not open 'packages/P5/.rush/temp/shrinkwrap-deps.json' for reading: No such file or directory

shrinkwrap-deps.json wasn't added to P5, because the subspace S3 wasn't installed.

What I expected to happen?

No error message should be printed by Rush and build script should be successfully finished.

The solution

Revert to the previous Rush workspace snapshot logic (version 5.139.0), by skipping the shrinkwrap-deps.json hashing for all unrelated projects.

Current state

for (const project of rushConfiguration.projects) {
  const projectShrinkwrapFilePath: string = BaseProjectShrinkwrapFile.getFilePathForProject(project);
  absoluteFilePathsToCheck.push(projectShrinkwrapFilePath);
  const relativeProjectShrinkwrapFilePath: string = Path.convertToSlashes(
    path.relative(rootDirectory, projectShrinkwrapFilePath)
  );
  
  additionalRelativePathsToHash.push(relativeProjectShrinkwrapFilePath);
  }
  
  await Async.forEachAsync(absoluteFilePathsToCheck, async (filePath: string) => {
  // Non existing srinkwrap-deps.json are NOT skipped, because we are not removing them from additionalRelativePathsToHash!
  if (!rushConfiguration.subspacesFeatureEnabled && !(await FileSystem.existsAsync(filePath))) {
    throw new Error(
      `A project dependency file (${filePath}) is missing. You may need to run ` +
        '"rush install" or "rush update".'
    );
  }
});

Previous working state

await Async.forEachAsync(
  this._rushConfiguration.projects,
  async (project: RushConfigurationProject) => {
    const projectShrinkwrapFilePath: string =
      BaseProjectShrinkwrapFile.getFilePathForProject(project);
    if (!(await FileSystem.existsAsync(projectShrinkwrapFilePath))) {
      if (this._rushConfiguration.subspacesFeatureEnabled) {
        // Non existing srinkwrap-deps.json are skipped, because they are not being added to additionalFilesToHash!
        return;
      }
      throw new Error(
        `A project dependency file (${projectShrinkwrapFilePath}) is missing. You may need to run ` +
          '"rush install" or "rush update".'
      );
    }
    const relativeProjectShrinkwrapFilePath: string = Path.convertToSlashes(
      path.relative(rootDir, projectShrinkwrapFilePath)
    );
    additionalFilesToHash.push(relativeProjectShrinkwrapFilePath);
  }
);

How it was tested

  1. Create a repository with subspaces enabled: https://rushjs.io/pages/advanced/subspaces/
  2. Create 3 subspaces (e.g. default, S1 and S2)
  3. Create a project inside of each subspace, and add S1 project as a local dependency of default
  4. Commit a new change to the project of default (don't need to push)
  5. Run rush install --from git:origin/master (default and S1 will be installed)
  6. Run rush build --from git:origin/master

The message "fatal: could not open 'packages/<project_of_S2>/.rush/temp/shrinkwrap-deps.json' for reading: No such file or directory" will appear and the build script will fail.

@pedro-gomes-92 pedro-gomes-92 marked this pull request as ready for review November 28, 2024 08:20
@iclanton iclanton merged commit dd871b9 into microsoft:main Dec 2, 2024
4 checks passed
@pedro-gomes-92 pedro-gomes-92 deleted the pedrogomes/fix-non-existing-hashes branch December 3, 2024 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

3 participants