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

feat(align-deps) allow exact version within range according to semver… #2984

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

balazsgerlei
Copy link
Contributor

@balazsgerlei balazsgerlei commented Feb 22, 2024

…Satisfies

Description

Add a new option (flag) --diff-mode to allow specifying two modes for diffing:

  • strict: Same as before
  • allow-exact-versions: Allow (don't throw an error) when exact versions are declared in package.json that are within range according to semverSatisfies.

Resolves #2983

Remaining tasks:

  • Change to diff-mode options from a boolean flag
  • Add information about what changed (Changeset)
  • Add unit tests
  • Update documentation

Test plan

  • CI should pass, including updated unit tests
  • Declare a dependency to package.json with an exact version that is within the range of what the built-in capabilities define. Run align-deps with the new --diff-mode set to allow-exact-version and verify that no error is thrown.
  • Declare a dependency to package.json with an exact version that is within the range of what the built-in capabilities define. Run align-deps with the new --diff-mode set to allow-exact-version and --write flag set and verify that nothing changes in package.json.
  • Declare a dependency to package.json with an exact version that is outside of the range of what the built-in capabilities define. Run align-deps with the new --diff-mode set to allow-exact-version and verify that an error is thrown for not correct version.
  • Declare a dependency to package.json with an exact version that is within the range of what the built-in capabilities define. Run align-deps with the new --diff-mode set to strict and verify that an error is thrown for not correct version.
  • Declare a dependency to package.json with an exact version that is within the range of what the built-in capabilities define. Run align-deps with the new --diff-mode set to strict but with --write flag and verify that the versions is overwritten with what is defined in built-in capabilities.
  • Declare a dependency to package.json with an exact version that is outside of the range of what the built-in capabilities define. Run align-deps with the new --diff-mode set to strict and verify that an error is thrown for not correct version.
  • Declare a dependency to package.json with an exact version that is within the range of what the built-in capabilities define. Run align-deps without the new --diff-mode set and verify that an error is thrown for not correct version.
  • Declare a dependency to package.json with an exact version that is within the range of what the built-in capabilities define. Run align-deps without the new --diff-mode set but with --write flag and verify that the versions is overwritten with what is defined in built-in capabilities.
  • Declare a dependency to package.json with an exact version that is outside of the range of what the built-in capabilities define. Run align-deps without the new --diff-mode set and verify that an error is thrown for not correct version.

@balazsgerlei
Copy link
Contributor Author

balazsgerlei commented Feb 22, 2024

I marked the PR as Draft as I haven't finished with the implementation, e.g. I still need to add unit tests but I wanted to ask the project maintainers' opinion (especially @tido64) considering this is my first feature addition to this repo. I appreciate any help and suggestion!

@kelset
Copy link
Member

kelset commented Feb 22, 2024

thanks for sending it over!
Super small thing, can you run yarn change locally to generate the changesets ? that will make CI go green

Comment on lines 73 to 98
"allow-exact-version": {
default: false,
description:
"Determines whether align-deps should allow exact versions in 'package.json' that are within the range and not throw an error for them.",
type: "boolean",
},
};
Copy link
Member

Choose a reason for hiding this comment

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

nit: once everything else is handled and we're good on the implementation, we should add mention of this in the readme: https://github.com/microsoft/rnx-kit/blob/main/packages/align-deps/README.md#usage

@balazsgerlei
Copy link
Contributor Author

thanks for sending it over! Super small thing, can you run yarn change locally to generate the changesets ? that will make CI go green

Sure, that's definitely on my list. You know what, I'll update the PR description with checkboxes for the remaining tasks and if I forgot something you can call that out!

Getting back to changeset, what kind of version bump you think this change warrants?

@kelset
Copy link
Member

kelset commented Feb 22, 2024

Getting back to changeset, what kind of version bump you think this change warrants?

@tido64 any preferences? If we want to be close to the semver definition I'd say we should go with minor:

MINOR version when you add functionality in a backward compatible manner

since it's a new feature

@tido64
Copy link
Member

tido64 commented Mar 12, 2024

@balazsgerlei: Are you unblocked to continue working on this? If you don't have the time, let me know. I wouldn't mind taking over and pushing it over the finish line. 😄

@balazsgerlei
Copy link
Contributor Author

@balazsgerlei: Are you unblocked to continue working on this? If you don't have the time, let me know. I wouldn't mind taking over and pushing it over the finish line. 😄

I've been indeed very occupied with personal stuff so I had little to no free time after work to attend to this. It would be still a nice challenge to finish this so I'll try to allocate some time for it and if I couldn't do it this week I'll let you know, but thanks for offering to take over!

@tido64
Copy link
Member

tido64 commented Mar 12, 2024

I've been indeed very occupied with personal stuff so I had little to no free time after work to attend to this. It would be still a nice challenge to finish this so I'll try to allocate some time for it and if I couldn't do it this week I'll let you know, but thanks for offering to take over!

Take the time you need to finish this. No pressure. Just making sure you're not waiting to hear from us 😉

@balazsgerlei balazsgerlei force-pushed the allow-exact-version branch 2 times, most recently from 94eb7a2 to b424f3e Compare March 25, 2024 10:00
@balazsgerlei
Copy link
Contributor Author

balazsgerlei commented Mar 25, 2024

Okay, it took a while, I've finally had some time to update this.

I implemented the two distinct diff mode options, what I'm not sure about is how and where to handle if the option is not set correctly. It should not happen since the only two valid options are delcared in cli.ts though I feel like it should still be handled in e.g. check.ts. I could add a simple isDiffMode function similarly to isKitType in initialize.ts before diff is called in checkPackageManifest but I don't see any ErrorCode (which is what checkPackageManifest returns) that would be a good fit and I was hesitant to add a new ErrorCode for this, though that might be the best choice.

Can I ask for some guidence on this @tido64 @kelset ? Thank you!

@kelset
Copy link
Member

kelset commented Mar 25, 2024

Hey @balazsgerlei Tommy is currently on a break; I'll throw in my 2C$ in the meantime.

Because we are setting the options via .choices from yargs directly I don't think we necessarily need to handle the error case you are mentioning directly because it should be handled by yargs itself.

What happens currently if you try to run the command and passing an invalid option?

@balazsgerlei
Copy link
Contributor Author

Hey @balazsgerlei Tommy is currently on a break; I'll throw in my 2C$ in the meantime.

Because we are setting the options via .choices from yargs directly I don't think we necessarily need to handle the error case you are mentioning directly because it should be handled by yargs itself.

What happens currently if you try to run the command and passing an invalid option?

The available options are listed and at the end it also tells you what you did wrong:

Invalid values:
Argument: diff-mode, Given: "xyz", Choices: "strict", "allow-exact-version"

That's what I also meant is that when using the script in Terminal you basically cannot pass the wrong argument to the actual logic, just that it would be more precise to handle that case somewhere e.g. in check.ts. That said, I'm more than happy to move forward like this, I would really like if I/we can get to the finish line. 😄

So I think I will continue with the unit tests like this and in the time being, let me know if you have another solution in mind or if @tido64 comes back and has a different opinion!

packages/align-deps/src/cli.ts Outdated Show resolved Hide resolved
packages/cli/src/align-deps.ts Outdated Show resolved Hide resolved
packages/align-deps/src/diff.ts Show resolved Hide resolved
packages/align-deps/src/types.ts Outdated Show resolved Hide resolved
@balazsgerlei balazsgerlei force-pushed the allow-exact-version branch 3 times, most recently from 60f3451 to 650df3d Compare April 10, 2024 07:28
@timostroehlein
Copy link

Thank you for the PR, we also need that feature in our team. I was about to implement that myself until i saw this PR 😄.

I have one small suggestion that would make this ideal for us, currently the diff-mode allow-exact-version only checks for the exact version, as the name suggests. It would be great if there would be another option, e.g. allow-in-range, which would allow all versions which satisfy the version range of the capability.

The following would be valid then:
capability: ^0.73.0
valid: ^0.73.1 ^0.73.9 0.73.2
invalid: ^0.74.0 0.74.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

align-deps: new flag to not throw an error for exact dependencies that are within bounds
4 participants