Skip to content

[rush] Fix edge cases where Rush does not update the lockfile#4910

Closed
L-Qun wants to merge 5 commits into
microsoft:mainfrom
L-Qun:fix/edge-case-rush-does-not-update-lockfile
Closed

[rush] Fix edge cases where Rush does not update the lockfile#4910
L-Qun wants to merge 5 commits into
microsoft:mainfrom
L-Qun:fix/edge-case-rush-does-not-update-lockfile

Conversation

@L-Qun

@L-Qun L-Qun commented Aug 30, 2024

Copy link
Copy Markdown
Contributor

Details

image

If the user moves a package from dependencies to devDependencies, and then runs rush update, Rush should update the lockfile correctly, but it does not. This issue occurs because it triggers case DependencyType.Dev, but Rush cannot find this package in importer.devDependencies. Consequently, Rush deletes it from the importerDependencies set.

Impacted documentation

None.

break;
}

// eslint-disable-next-line no-fallthrough

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// eslint-disable-next-line no-fallthrough

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this explicit rule suppression is here, it seems like there was a reason for this behavior initially. Are you sure unit tests adequately cover all scenarios here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. But I noticed that you added this rule suppression. Is there a specific case for that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe I guess it was just an oversight.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chengcyber and I reviewed this today. It is really a spec change, not a bug:

In the past, whether a package was a devDependency or regular dependency did not affect the node_modules folder. The distinction maybe was reflected in the lockfile, but the installation plan was equivalent.

But now, apparently rush install fails if PNPM finds that the lockfile is inconsistent with package.json with regards to devDependencies-vs-dependencies. We need to modify the spec, such that Rush's analysis now will treat devDependencies vs dependencies as a significant difference.

This PR technically fixes the behavior by inserting a break statement, however the change is a bit confusing, because the code comments and structure are unchanged. The /intent/ of the code appears to be the same, but in fact we have changed it.

Possible improvements:

  1. Add some code comments better explaining the expected behavior
  2. Possibly restructure the code to no longer rely on case statements that fallthrough
  3. Ideally add some unit tests with examples of the edge cases

@@ -1002,6 +1002,7 @@ export class PnpmShrinkwrapFile extends BaseShrinkwrapFile {
}
// If fall through, there is a chance the package declares an inconsistent version, ignore it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be an error case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this an error case would likely mitigate whatever issue the existing code was trying to account for.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this an error case would likely mitigate whatever issue the existing code was trying to account for.

I'm not sure about that. If the inconsistency is in an indirect dependency, and PNPM tolerates it, then Rush probably should as well.

@iclanton iclanton changed the title Fix edge cases where Rush does not update the lockfile [rush] Fix edge cases where Rush does not update the lockfile Sep 9, 2024
L-Qun and others added 2 commits September 10, 2024 11:21
…ate-lockfile_2024-08-30-06-44.json

Co-authored-by: Ian Clanton-Thuon <iclanton@users.noreply.github.com>
Co-authored-by: Ian Clanton-Thuon <iclanton@users.noreply.github.com>
@L-Qun L-Qun requested a review from iclanton September 11, 2024 01:19
@L-Qun L-Qun closed this by deleting the head repository Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants