From 91e0f8db118b125e805a77ce31dc21af57ee7abf Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Sat, 24 Mar 2018 23:57:23 -0500 Subject: process: add version constants and compare PR-URL: https://github.com/nodejs/node/pull/19587 Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Anatoli Papirovski --- doc/api/process.md | 34 ++++++++++++++++++++++++--- lib/internal/bootstrap/node.js | 1 + lib/internal/process.js | 44 ++++++++++++++++++++++++++++++++++- src/node.cc | 11 +++++++++ test/parallel/test-process-release.js | 39 ++++++++++++++++++++++++++++++- 5 files changed, 124 insertions(+), 5 deletions(-) diff --git a/doc/api/process.md b/doc/api/process.md index 202725cb51..060d741804 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -1482,6 +1482,9 @@ changes: - version: v4.2.0 pr-url: https://github.com/nodejs/node/pull/3212 description: The `lts` property is now supported. + - version: REPLACEME + pr-url: https://github.com/nodejs/node/pull/19587 + description: Add SemVer properties. --> * {Object} @@ -1510,6 +1513,10 @@ tarball. - `'Argon'` for the 4.x LTS line beginning with 4.2.0. - `'Boron'` for the 6.x LTS line beginning with 6.9.0. - `'Carbon'` for the 8.x LTS line beginning with 8.9.1. +* `majorVersion` {number} The major version of this release. +* `minorVersion` {number} The minor version of this release. +* `patchVersion` {number} The patch version of this release. +* `prereleaseTag` {string} The SemVer pre-release tag for Node.js. ```js @@ -1518,13 +1525,34 @@ tarball. lts: 'Argon', sourceUrl: 'https://nodejs.org/download/release/v4.4.5/node-v4.4.5.tar.gz', headersUrl: 'https://nodejs.org/download/release/v4.4.5/node-v4.4.5-headers.tar.gz', - libUrl: 'https://nodejs.org/download/release/v4.4.5/win-x64/node.lib' + libUrl: 'https://nodejs.org/download/release/v4.4.5/win-x64/node.lib', + majorVersion: 4, + minorVersion: 4, + patchVersion: 5, + prereleaseTag: '', + compareVersion: [Function: compareVersion] } ``` + In custom builds from non-release versions of the source tree, only the -`name` property may be present. The additional properties should not be -relied upon to exist. +`name` property and SemVer properties may be present. The additional properties +should not be relied upon to exist. + +## process.release.compareVersion(major, minor, patch[, tag]) + + +Perform a SemVer comparison to the release version. + +* `major` {number} The major version to compare. +* `minor` {number} The minor version to compare. +* `patch` {number} The patch version to compare. +* `tag` {string} The pre-release tag to compare. +* Returns: {number} `1` if the given version is lower than the current release + version, `0` if the given version matches the process version, and `-1` + if the given version is greater than the release version. ## process.send(message[, sendHandle[, options]][, callback])