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

Revert "process: add version constants and compare" #19587 #20062

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 3 additions & 31 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
setupGlobalVariables();

const _process = NativeModule.require('internal/process');
_process.setupCompareVersion();
_process.setupConfig(NativeModule._source);
_process.setupSignalHandlers();
_process.setupUncaughtExceptionCapture(exceptionHandlerState);
Expand Down
44 changes: 1 addition & 43 deletions lib/internal/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -334,6 +293,5 @@ module.exports = {
setupSignalHandlers,
setupChannel,
setupRawDebug,
setupUncaughtExceptionCapture,
setupCompareVersion,
setupUncaughtExceptionCapture
};
11 changes: 0 additions & 11 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3015,17 +3015,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));
Expand Down
39 changes: 1 addition & 38 deletions test/parallel/test-process-release.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const common = require('../common');
require('../common');

const assert = require('assert');
const versionParts = process.versions.node.split('.');
Expand All @@ -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',
});
}