Skip to content
This repository was archived by the owner on Aug 6, 2024. It is now read-only.

Commit 84212b2

Browse files
committed
Update replace semver with new version compare module
1 parent 95c67f7 commit 84212b2

File tree

7 files changed

+28
-24
lines changed

7 files changed

+28
-24
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## NEXT PATCH RELEASE
2+
3+
### Bug fixes
4+
5+
* Fixes version check does not support composer version ranges.
6+
17
## 4.0.0
28

39
### Breaking changes

lib/commands/compatibility.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const Chalk = require('chalk');
44
const Program = require('commander');
5-
const semver = require('semver');
5+
const { compareVersions, compareVersionsWithComperator } = require('composer-version-constraint-evaluator');
66
const { promisify } = require('util');
77

88
const ShopwareStoreCommander = require('../shopwareStoreCommander');
@@ -65,7 +65,7 @@ async function main() {
6565
let minCompatibleVersion;
6666
if (binary.compatibleSoftwareVersions.length > 0) {
6767
binary.compatibleSoftwareVersions.sort(
68-
(lhs, rhs) => semver.compare(lhs.name, rhs.name),
68+
(lhs, rhs) => compareVersions(lhs.name, rhs.name),
6969
);
7070
minCompatibleVersion = binary.compatibleSoftwareVersions[0].name;
7171
} else {
@@ -74,19 +74,19 @@ async function main() {
7474
).shift().name;
7575
}
7676

77-
if (semver.lt(Program.opts().minVersion, minCompatibleVersion)) {
77+
if (compareVersionsWithComperator(Program.opts().minVersion, minCompatibleVersion, '<')) {
7878
// Add new version compatibility entries to lower the minimum compatibility
7979
console.log(`Lowering minimum compatible Shopware version of binary ${binary.version} to ${Program.opts().minVersion}...`);
8080
binary.compatibleSoftwareVersions = binary.compatibleSoftwareVersions.concat(shopwareVersions.filter(
8181
version => version.selectable
82-
&& semver.gte(version.name, Program.opts().minVersion)
83-
&& semver.lt(version.name, minCompatibleVersion),
82+
&& compareVersionsWithComperator(version.name, Program.opts().minVersion, '>=')
83+
&& compareVersionsWithComperator(version.name, minCompatibleVersion, '<'),
8484
));
85-
} else if (semver.gt(Program.opts().minVersion, minCompatibleVersion)) {
85+
} else if (compareVersionsWithComperator(Program.opts().minVersion, minCompatibleVersion, '>')) {
8686
// Remove some version compatibilities to raise the minimum compatibility
8787
console.log(`Raising minimum compatible Shopware version of binary ${binary.version} to ${Program.opts().minVersion}...`);
8888
binary.compatibleSoftwareVersions = binary.compatibleSoftwareVersions.filter(
89-
version => version.selectable && semver.gte(version.name, Program.opts().minVersion),
89+
version => version.selectable && compareVersionsWithComperator(version.name, Program.opts().minVersion, '>='),
9090
);
9191
} else {
9292
console.log(`Minimum compatible Shopware version of binary ${binary.version} already matches ${Program.opts().minVersion}`);
@@ -97,7 +97,7 @@ async function main() {
9797
if (binary.compatibleSoftwareVersions.length === 0) {
9898
// Add at least the minimum compatible shopware version
9999
binary.compatibleSoftwareVersions = [
100-
shopwareVersions.find(version => version.selectable && semver.eq(version.name, Program.opts().minVersion)),
100+
shopwareVersions.find(version => version.selectable && compareVersionsWithComperator(version.name, Program.opts().minVersion, '=')),
101101
];
102102
}
103103

lib/commands/list.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const Chalk = require('chalk');
44
const Program = require('commander');
5-
const semver = require('semver');
5+
const { compareVersions } = require('composer-version-constraint-evaluator');
66
const Table = require('cli-table');
77
const ShopwareStoreCommander = require('../shopwareStoreCommander');
88
const programVersion = require('../version');
@@ -16,7 +16,7 @@ const getShopwareCompatibility = (plugin, reverse) => {
1616

1717
const sortedVersions = plugin.latestBinary.compatibleSoftwareVersions
1818
.map(shopwareVersion => shopwareVersion.name)
19-
.sort(semver.compare);
19+
.sort(compareVersions);
2020

2121
return (reverse) ? sortedVersions.pop() : sortedVersions.shift();
2222
};
@@ -27,7 +27,7 @@ const pluginComparators = {
2727
const vA = (a.latestBinary) ? a.latestBinary.version : '0.0.0';
2828
const vB = (b.latestBinary) ? b.latestBinary.version : '0.0.0';
2929

30-
return semver.compare(vA, vB);
30+
return compareVersions(vA, vB);
3131
},
3232
active: (a, b) => a.activationStatus.name.localeCompare(b.activationStatus.name),
3333
reviewStatus: (a, b) => {
@@ -46,13 +46,13 @@ const pluginComparators = {
4646
const vA = getShopwareCompatibility(a, false) || '10000.0.0';
4747
const vB = getShopwareCompatibility(b, false) || '10000.0.0';
4848

49-
return semver.compare(vA, vB);
49+
return compareVersions(vA, vB);
5050
},
5151
maxShopwareCompatibility: (a, b) => {
5252
const vA = getShopwareCompatibility(a, true) || '10000.0.0';
5353
const vB = getShopwareCompatibility(b, true) || '10000.0.0';
5454

55-
return semver.compare(vA, vB);
55+
return compareVersions(vA, vB);
5656
},
5757
};
5858

lib/commands/upload.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const Chalk = require('chalk');
44
const path = require('path');
55
const Program = require('commander');
6-
const semver = require('semver');
6+
const { compareVersionsReverse } = require('composer-version-constraint-evaluator');
77
const ShopwareStoreCommander = require('../shopwareStoreCommander');
88
const publishPluginReleaseEvent = require('../publishPluginReleaseEvent');
99
const util = require('../util');
@@ -22,9 +22,8 @@ function parseOnOffAutoOption(suppliedValue) {
2222
return suppliedValue;
2323
default:
2424
console.error(Chalk.white.bgRed.bold(`Invalid value '${suppliedValue}' for option --license-check-required.`));
25-
process.exit(-1);
2625

27-
return undefined;
26+
return process.exit(-1);
2827
}
2928
}
3029

@@ -99,7 +98,7 @@ async function main() {
9998
return newBinary;
10099
}).sort(
101100
// Sort by version (semver) and release date (from new to old)
102-
(lhs, rhs) => semver.rcompare(lhs.version, rhs.version) || (-1 * lhs.creationDate.localeCompare(rhs.creationDate)),
101+
(lhs, rhs) => compareVersionsReverse(lhs.version, rhs.version) || (-1 * lhs.creationDate.localeCompare(rhs.creationDate)),
103102
);
104103
const latestReleasedBinary = (releasedBinaries.length > 0) ? releasedBinaries[0] : null;
105104

lib/plugin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fs = require('mz/fs');
22
const JSZip = require('jszip');
33
const path = require('path');
4-
const semver = require('semver');
4+
const { versionSatisfiesConstraint } = require('composer-version-constraint-evaluator');
55
const { parseChangelogMarkdown } = require('./changelogMarkdownParser');
66

77
function readInfoFromComposerJson(composerJsonString) {
@@ -82,15 +82,15 @@ module.exports = class Plugin {
8282
const shopwareVersion = this.getShopware6Semver(shopwareMarketingVersion);
8383
const pluginShopwareCompatibility = this.getShopware6Semver(this.shopwareCompatibility);
8484

85-
return semver.satisfies(shopwareVersion, pluginShopwareCompatibility);
85+
return versionSatisfiesConstraint(shopwareVersion, pluginShopwareCompatibility);
8686
}
8787

8888
if (this.shopwareMajorVersion === 5) {
8989
if (!shopwareMarketingVersion.startsWith('5.')) {
9090
return false;
9191
}
9292

93-
return semver.satisfies(shopwareMarketingVersion, this.shopwareCompatibility);
93+
return versionSatisfiesConstraint(shopwareMarketingVersion, this.shopwareCompatibility);
9494
}
9595

9696
throw new Error(

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"marked": "^2.0.3",
4949
"mz": "^2.4.0",
5050
"node-notifier": "^9.0.1",
51-
"semver": "^7.3.5"
51+
"composer-version-constraint-evaluator": "^1.0.0"
5252
},
5353
"devDependencies": {
5454
"cspell": "^5.4.0",
@@ -59,4 +59,4 @@
5959
"node": ">=18.0.0"
6060
},
6161
"preferGlobal": true
62-
}
62+
}

0 commit comments

Comments
 (0)