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

fix(doctor, watchman): accept new date-based watchman versions #1550

Merged

Conversation

mikehardy
Copy link
Contributor

@mikehardy mikehardy commented Feb 10, 2022

Summary:

fix(doctor, watchman): accept new date-based watchman versions

doctor was giving false-negatives with the new watchman versions

they use date-based versions now that violate semver with leading-zeros in numeric parts:

loose mode correctly pasrses them though, so add optional parameter to install check that
allows loose version range coercion

Should be compatible as watchman project is on record as being permanently backwards-compatible:
https://facebook.github.io/watchman/docs/compatibility.html

Test Plan:

I wrote a test that covers watchman completely before modifying it, then modified it and added a chunk of test to check the modification - so, best reviewed one commit at a time

this verifies existing functionality prior to changes
doctor was giving false-negatives with the new watchman versions

they use date-based versions now that violate semver with leading-zeros in numeric parts:
- npm/node-semver#232

loose mode correctly pasrses them though, so add optional parameter to install check that
allows loose version range coercion

Should be compatible as watchman project is on record as being permanently backwards-compatible:
https://facebook.github.io/watchman/docs/compatibility.html
@mikehardy mikehardy changed the title Watchman modern versions fix(doctor, watchman): accept new date-based watchman versions Feb 10, 2022
@mikehardy
Copy link
Contributor Author

This was needed so that yarn react-native doctor ran all green on my local (functioning! fully installed!) local dev environments

@@ -19,11 +19,13 @@ const isSoftwareNotInstalled = async (command: string): Promise<boolean> => {
const doesSoftwareNeedToBeFixed = ({
version,
versionRange,
looseRange = false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

default value so no other code has to change, and follows the semver package historical precedent of all semver APIs taking loose as a final argument, with false being the default

@@ -3,7 +3,7 @@ export default {
NODE_JS: '>= 8.3',
YARN: '>= 1.10.x',
NPM: '>= 4.x',
WATCHMAN: '4.x',
WATCHMAN: '>= 4.x',
Copy link
Contributor Author

@mikehardy mikehardy Feb 10, 2022

Choose a reason for hiding this comment

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

4.9.0 was released something like 2 years ago then they transitioned to date ranges that have leading zeros in the semver parts, which is technically a semver violation but still easily parsed. This let's the range slip up to the new versions, which do work

@liamjones
Copy link
Contributor

FYI this resolves #1485 - sort of... It doesn't directly implement support for CalVer but negates the need to do that.

}): boolean => {
const coercedVersion = semver.coerce(version);
const coercedVersion = semver.coerce(version, {loose: looseRange});
Copy link
Member

Choose a reason for hiding this comment

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

Does the check for version ranges just work as-is when comparing semver vs date version?

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 I fully understand the question so let me state what I think I understand, then please correct if I'm wrong - I think that if you compare a semver vs a "semver except it has leading zeros in some parts because it is YYYY.MM.DD.ZZ.etc" it will coerce and compare and work as is. The coercion takes the leading three parts and the loose allows leading zeros to still go through and be treated as integers during coercion

Which is...sort of some detail and not an answer. I was worried personally about the impact here which is why I went with an optional parameter you can opt-in too when you know a version series "style" (that is: it has changed to date, and it has changed in a way that it's previous semver-compatible will work with it's current date form) and thus can make more assumptions / tests about correct behavior vs hoping that the full loose backus-naur form works well with the semver BNF

Hopefully that's what you were curious about?

@grabbou
Copy link
Member

grabbou commented Feb 14, 2022

#1485

Well, I guess it sort of fixes that issue. Alternative would be to enable looseMode for all the version checks. I think at this point, since we have support for CalVer, we are good to close that issue and just keep support in mind when other dependencies switch to it in the future.

What you think?

@grabbou
Copy link
Member

grabbou commented Feb 14, 2022

@mikehardy great work and thanks for adding tests. My question is - where I can look up details on what exactly is loose mode doing that makes this code work?

Copy link
Member

@grabbou grabbou left a comment

Choose a reason for hiding this comment

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

LGTM!

@grabbou grabbou merged commit 0f29b26 into react-native-community:master Feb 14, 2022
@mikehardy
Copy link
Contributor Author

@mikehardy great work and thanks for adding tests. My question is - where I can look up details on what exactly is loose mode doing that makes this code work?

It appears undocumented, I had to read the regexes in source 😂

@mikehardy mikehardy deleted the watchman-modern-versions branch April 10, 2022 15:17
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.

4 participants