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] Fix edge cases where Rush does not update the lockfile #4910

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

L-Qun
Copy link
Contributor

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

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.

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

// eslint-disable-next-line no-fallthrough
Copy link
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
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
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
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.

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
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
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.

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
@L-Qun L-Qun requested a review from iclanton September 11, 2024 01:19
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