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 downgrade to npm 5.x when using version 10.x or greater #1141

Merged
merged 4 commits into from
Sep 25, 2023

Conversation

colincasey
Copy link
Contributor

Several checks of the major version of npm being used were only accounting for the first character of the version string. E.g.; version 10.1.0 would be treated as major=1 instead of major=10.

This PR changes those checks to split on . characters using cut and read the major version as the first field and adds a test to verify.

Fixes #1140

Several checks of the `major` version of npm being used were only accounting for the first character of the version string. E.g.; version `10.1.0` would be treated as `major=1` instead of `major=10`.

This PR changes those checks to split on `.` characters using `cut` and read the `major` version as the first field and adds a test to verify.

Fixes #1140
@colincasey colincasey requested a review from a team as a code owner September 20, 2023 19:42
@colincasey colincasey self-assigned this Sep 20, 2023
Copy link
Contributor

@schneems schneems left a comment

Choose a reason for hiding this comment

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

I validate it does what is says on the tin. I verified the logic locally:

Before:

$ major_string=10.0 && echo "${major_string:0:1}"
1
$ echo "10.0" | cut -d "." -f 1
10

The only thing I might recommend would be centralizing this logic to a single point of truth like a function that's also more descriptive of the logic we're after. If we want to make that refactor later we could, but it's not necessary for now.

@colincasey
Copy link
Contributor Author

@schneems I refactored the logic into a helper function as you suggested.

@colincasey colincasey merged commit 8761de0 into main Sep 25, 2023
@colincasey colincasey deleted the fix_issue_1140 branch September 25, 2023 13:11
@colincasey colincasey mentioned this pull request Sep 25, 2023
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.

npm downgraded to 5.x if default version is 10.x
4 participants