Revert "process: add version constants and compare"
This reverts commit 91e0f8db118b125e805a77ce31dc21af57ee7abf. PR-URL: https://github.com/nodejs/node/pull/20062 Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
parent
53822f605d
commit
287ec1e8f4
@ -1482,9 +1482,6 @@ 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}
|
||||
@ -1513,10 +1510,6 @@ 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.
|
||||
|
||||
<!-- eslint-skip -->
|
||||
```js
|
||||
@ -1525,34 +1518,13 @@ 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',
|
||||
majorVersion: 4,
|
||||
minorVersion: 4,
|
||||
patchVersion: 5,
|
||||
prereleaseTag: '',
|
||||
compareVersion: [Function: compareVersion]
|
||||
libUrl: 'https://nodejs.org/download/release/v4.4.5/win-x64/node.lib'
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
In custom builds from non-release versions of the source tree, only the
|
||||
`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])
|
||||
<!-- YAML
|
||||
added: REPLACEME
|
||||
-->
|
||||
|
||||
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.
|
||||
`name` property may be present. The additional properties should not be
|
||||
relied upon to exist.
|
||||
|
||||
## process.send(message[, sendHandle[, options]][, callback])
|
||||
<!-- YAML
|
||||
|
@ -35,7 +35,6 @@
|
||||
setupGlobalVariables();
|
||||
|
||||
const _process = NativeModule.require('internal/process');
|
||||
_process.setupCompareVersion();
|
||||
_process.setupConfig(NativeModule._source);
|
||||
_process.setupSignalHandlers();
|
||||
_process.setupUncaughtExceptionCapture(exceptionHandlerState);
|
||||
|
@ -283,47 +283,6 @@ function setupUncaughtExceptionCapture(exceptionHandlerState) {
|
||||
};
|
||||
}
|
||||
|
||||
function setupCompareVersion() {
|
||||
const {
|
||||
majorVersion,
|
||||
minorVersion,
|
||||
patchVersion,
|
||||
prereleaseTag,
|
||||
} = process.release;
|
||||
|
||||
process.release.compareVersion = (major, minor, patch, tag) => {
|
||||
if (typeof major !== 'number')
|
||||
throw new ERR_INVALID_ARG_TYPE('major', 'number', major);
|
||||
if (typeof minor !== 'number')
|
||||
throw new ERR_INVALID_ARG_TYPE('minor', 'number', minor);
|
||||
if (typeof patch !== 'number')
|
||||
throw new ERR_INVALID_ARG_TYPE('patch', 'number', patch);
|
||||
if (tag !== undefined && typeof tag !== 'string')
|
||||
throw new ERR_INVALID_ARG_TYPE('tag', 'string', tag);
|
||||
|
||||
if (major > majorVersion)
|
||||
return -1;
|
||||
if (major < majorVersion)
|
||||
return 1;
|
||||
|
||||
if (minor > minorVersion)
|
||||
return -1;
|
||||
if (minor < minorVersion)
|
||||
return 1;
|
||||
|
||||
if (patch > patchVersion)
|
||||
return -1;
|
||||
if (patch < patchVersion)
|
||||
return 1;
|
||||
if (prereleaseTag)
|
||||
return prereleaseTag === tag ? 0 : 1;
|
||||
if (tag)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
setup_performance,
|
||||
setup_cpuUsage,
|
||||
@ -334,6 +293,5 @@ module.exports = {
|
||||
setupSignalHandlers,
|
||||
setupChannel,
|
||||
setupRawDebug,
|
||||
setupUncaughtExceptionCapture,
|
||||
setupCompareVersion,
|
||||
setupUncaughtExceptionCapture
|
||||
};
|
||||
|
11
src/node.cc
11
src/node.cc
@ -3017,17 +3017,6 @@ void SetupProcessObject(Environment* env,
|
||||
READONLY_PROPERTY(release, "name",
|
||||
OneByteString(env->isolate(), NODE_RELEASE));
|
||||
|
||||
READONLY_PROPERTY(release, "majorVersion",
|
||||
Integer::New(env->isolate(), NODE_MAJOR_VERSION));
|
||||
READONLY_PROPERTY(release, "minorVersion",
|
||||
Integer::New(env->isolate(), NODE_MINOR_VERSION));
|
||||
READONLY_PROPERTY(release, "patchVersion",
|
||||
Integer::New(env->isolate(), NODE_PATCH_VERSION));
|
||||
std::string node_tag(NODE_TAG);
|
||||
READONLY_PROPERTY(release, "prereleaseTag",
|
||||
OneByteString(env->isolate(), node_tag.size() > 0 ?
|
||||
node_tag.substr(1).c_str() : ""));
|
||||
|
||||
#if NODE_VERSION_IS_LTS
|
||||
READONLY_PROPERTY(release, "lts",
|
||||
OneByteString(env->isolate(), NODE_VERSION_LTS_CODENAME));
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
require('../common');
|
||||
|
||||
const assert = require('assert');
|
||||
const versionParts = process.versions.node.split('.');
|
||||
@ -18,40 +18,3 @@ if (versionParts[0] === '4' && versionParts[1] >= 2) {
|
||||
} else {
|
||||
assert.strictEqual(process.release.lts, undefined);
|
||||
}
|
||||
|
||||
const {
|
||||
majorVersion: major,
|
||||
minorVersion: minor,
|
||||
patchVersion: patch,
|
||||
prereleaseTag: tag,
|
||||
compareVersion,
|
||||
} = process.release;
|
||||
|
||||
assert.strictEqual(compareVersion(major, minor, patch, tag), 0);
|
||||
|
||||
assert.strictEqual(compareVersion(major + 1, minor, patch, tag), -1);
|
||||
assert.strictEqual(compareVersion(major - 1, minor, patch, tag), 1);
|
||||
|
||||
assert.strictEqual(compareVersion(major, minor + 1, patch, tag), -1);
|
||||
assert.strictEqual(compareVersion(major, minor - 1, patch, tag), 1);
|
||||
|
||||
assert.strictEqual(compareVersion(major, minor, patch + 1, tag), -1);
|
||||
assert.strictEqual(compareVersion(major, minor, patch - 1, tag), 1);
|
||||
|
||||
if (tag)
|
||||
assert.strictEqual(compareVersion(major, minor, patch), 1);
|
||||
else
|
||||
assert.strictEqual(compareVersion(major, minor, patch, 'notrealtag'), -1);
|
||||
|
||||
for (const args of [
|
||||
['', 0, 0, ''],
|
||||
[0, '', 0, ''],
|
||||
[0, 0, '', ''],
|
||||
[0, 0, 0, 0],
|
||||
]) {
|
||||
common.expectsError(() => {
|
||||
compareVersion(...args);
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user