compare-versions
compare-versions copied to clipboard
compareVersions('~12.1.2', '11.1.2') => 0 ?
Hi,
this test fails:
it('should return 1 for versions ~12.1.2 and 11.1.2', () => { const result: VersionsComparison = compareVersions('~12.1.2', '11.1.2'); expect(result).toBe(1); });
with error:
Expected 0 to be 1.
Is this behaving expected?
I've found some weird things using this library, too:
satisifes('10.0.4', '>=14.0.0') // true
When a dep of 10.x obviously does NOT satisfy a requirement of >=14.x
.
compareVersions('~12.1.2', '11.1.2')
@pawtwa The compareVersions
function tests which of two versions is bigger. This example uses ~
in the first version string which is a range. The function you can use in this case is satisfies('11.1.2', '~12.1.2')
(which in this case would be false
) :)
satisifes('10.0.4', '>=14.0.0') // true
@lmiller1990 I added your example to the unit test suite and it correctly returns false
. Can you share a code pen/snippet of the full example if you are still seeing this problem?
Sure - I just installed the module from rpm
and did the absolute most basic program possible. I'm now using the semver
lib which works as expected, out of the box, but I hope we can get to the bottom of the bug here, too. I must be missing something, this library has millions downloads, there's no way the most basic feature is not working.
I just did:
yarn init -y
yarn add compare-versions
Here's the entire source (shown via cat
and ls
):
$ ls
index.js node_modules package.json yarn.lock
$ cat package.json
{
"name": "anything-node",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"compare-versions": "^4.1.3"
}
}
$ cat yarn.lock
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
compare-versions@^4.1.3:
version "4.1.3"
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-4.1.3.tgz#8f7b8966aef7dc4282b45dfa6be98434fc18a1a4"
integrity sha512-WQfnbDcrYnGr55UwbxKiQKASnTtNnaAWVi8jZyy8NTpVAXWACSne8lMD1iaIo9AiU6mnuLvSVshCzewVuWxHUg==
$ cat index.js
const { satisfies } = require('compare-versions')
console.log(
satisfies('10.0.4', '>=14.0.0') // true
)
$ node index.js
true
$ node --version
v16.14.2
I think you are right, there is a discrepancy between the CJS and MJS version of the package. I will change the build system so they are identical to avoid this happening again in the future. Thanks for the great repro example.
This has now been fixed by v5 which ensures identical behavior between CJS and ESM versions.