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

process: add release.compareVersion(str) functionality #20055

Closed
wants to merge 3 commits into from

Conversation

BridgeAR
Copy link
Member

This overloads release.compareVersion by also accepting a single
string argument to compare the version. It also fixes a former bug
by comparing the pre-release tags properly.

It also adds a stricter input validation to throw on negative values.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

This overloads `release.compareVersion` by also accepting a single
string argument to compare the version. It also fixes a former bug
by comparing the pre-release tags properly.

It also adds a stricter input validation to throw on negative values.
@BridgeAR BridgeAR added the semver-minor PRs that contain new features and should be released in the next minor version. label Apr 15, 2018
@BridgeAR BridgeAR requested a review from devsnek April 15, 2018 20:12
@nodejs-github-bot nodejs-github-bot added the process Issues and PRs related to the process subsystem. label Apr 15, 2018
@BridgeAR
Copy link
Member Author

added: REPLACEME
-->

Perform a SemVer comparison to the release version.
Copy link
Contributor

@mscdex mscdex Apr 15, 2018

Choose a reason for hiding this comment

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

The description should come after the parameter list (yes, this should've also been fixed in the original PR).

Copy link
Member Author

Choose a reason for hiding this comment

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

Done (including in the original description).

throw new ERR_INVALID_ARG_TYPE('tag', 'string', tag);
process.release.compareVersion = function(major, minor, patch, tag) {
if (arguments.length === 1 && typeof major === 'string') {
const [start, ...end] = major.split('-');
Copy link
Contributor

@mscdex mscdex Apr 15, 2018

Choose a reason for hiding this comment

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

Would it be faster to just use a regexp to parse and validate the string?

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not benchmark this explicitly but I changed it to a reg exp nevertheless because it is also nicer to read.

The return value was not intuitive. It is now exactly the other way
around as it was originally implemented.

This also fixes a bug with the pre-release tag where the former
implementation detected `1.0.0` to be "younger" than `1.0.0-pre`.

Fixes: nodejs#20053
@BridgeAR BridgeAR force-pushed the improve-process-release branch from 54278f4 to 8800470 Compare April 16, 2018 00:27
@BridgeAR
Copy link
Member Author

I pushed two changes: the first to address comments including some stricter checks and the second to fix #20053. That also fixes a minor bug in the former implementation.

CI https://ci.nodejs.org/job/node-test-pull-request/14316/

@devsnek
Copy link
Member

devsnek commented Apr 16, 2018

someone was opposed to accepting a string when i did it in my pr, i think it was @vsemozhetbyt

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Apr 16, 2018

Nope, it was not me) I consider this is above my level of knowledge and experience to make strong suggestions about API design)

@BridgeAR
Copy link
Member Author

That was here #19587 (comment)

@mscdex
Copy link
Contributor

mscdex commented Apr 16, 2018

Right, and I'm still not convinced it's a good idea unless adding support for strings does not slow down the non-string case and parsing the string has very minimal overhead. Even though this kind of check really only needs to be done once for the lifetime of a process, I have a feeling people may use it post-startup and they may expect it to be fast.

@BridgeAR
Copy link
Member Author

@mscdex since I know that the versions read from the RegExp are valid numbers, I do not explicitly coerce them to numbers and it is therefore not monomorphic and I use implicit type coercion in the actual check for strings. If you want, I can change that so it's monomorphic (all cases besides major) if the user does not supply invalid arguments.

@rvagg
Copy link
Member

rvagg commented Apr 16, 2018

proposing reversion of the process.release additions @ #20062

@BridgeAR
Copy link
Member Author

Closing as it seems like #20062 is preferred.

@BridgeAR BridgeAR closed this Apr 16, 2018
@BridgeAR BridgeAR added the invalid Issues and PRs that are invalid. label Apr 16, 2018
@BridgeAR BridgeAR deleted the improve-process-release branch April 1, 2019 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Issues and PRs that are invalid. process Issues and PRs related to the process subsystem. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants