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

Commit

Permalink
Update replace semver with new version compare module
Browse files Browse the repository at this point in the history
  • Loading branch information
magraina committed Jul 29, 2024
1 parent 95c67f7 commit 84212b2
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## NEXT PATCH RELEASE

### Bug fixes

* Fixes version check does not support composer version ranges.

## 4.0.0

### Breaking changes
Expand Down
16 changes: 8 additions & 8 deletions lib/commands/compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

const ShopwareStoreCommander = require('../shopwareStoreCommander');
Expand Down Expand Up @@ -65,7 +65,7 @@ async function main() {
let minCompatibleVersion;
if (binary.compatibleSoftwareVersions.length > 0) {
binary.compatibleSoftwareVersions.sort(
(lhs, rhs) => semver.compare(lhs.name, rhs.name),
(lhs, rhs) => compareVersions(lhs.name, rhs.name),
);
minCompatibleVersion = binary.compatibleSoftwareVersions[0].name;
} else {
Expand All @@ -74,19 +74,19 @@ async function main() {
).shift().name;
}

if (semver.lt(Program.opts().minVersion, minCompatibleVersion)) {
if (compareVersionsWithComperator(Program.opts().minVersion, minCompatibleVersion, '<')) {
// Add new version compatibility entries to lower the minimum compatibility
console.log(`Lowering minimum compatible Shopware version of binary ${binary.version} to ${Program.opts().minVersion}...`);
binary.compatibleSoftwareVersions = binary.compatibleSoftwareVersions.concat(shopwareVersions.filter(
version => version.selectable
&& semver.gte(version.name, Program.opts().minVersion)
&& semver.lt(version.name, minCompatibleVersion),
&& compareVersionsWithComperator(version.name, Program.opts().minVersion, '>=')
&& compareVersionsWithComperator(version.name, minCompatibleVersion, '<'),
));
} else if (semver.gt(Program.opts().minVersion, minCompatibleVersion)) {
} else if (compareVersionsWithComperator(Program.opts().minVersion, minCompatibleVersion, '>')) {
// Remove some version compatibilities to raise the minimum compatibility
console.log(`Raising minimum compatible Shopware version of binary ${binary.version} to ${Program.opts().minVersion}...`);
binary.compatibleSoftwareVersions = binary.compatibleSoftwareVersions.filter(
version => version.selectable && semver.gte(version.name, Program.opts().minVersion),
version => version.selectable && compareVersionsWithComperator(version.name, Program.opts().minVersion, '>='),
);
} else {
console.log(`Minimum compatible Shopware version of binary ${binary.version} already matches ${Program.opts().minVersion}`);
Expand All @@ -97,7 +97,7 @@ async function main() {
if (binary.compatibleSoftwareVersions.length === 0) {
// Add at least the minimum compatible shopware version
binary.compatibleSoftwareVersions = [
shopwareVersions.find(version => version.selectable && semver.eq(version.name, Program.opts().minVersion)),
shopwareVersions.find(version => version.selectable && compareVersionsWithComperator(version.name, Program.opts().minVersion, '=')),
];
}

Expand Down
10 changes: 5 additions & 5 deletions lib/commands/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

const sortedVersions = plugin.latestBinary.compatibleSoftwareVersions
.map(shopwareVersion => shopwareVersion.name)
.sort(semver.compare);
.sort(compareVersions);

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

return semver.compare(vA, vB);
return compareVersions(vA, vB);
},
active: (a, b) => a.activationStatus.name.localeCompare(b.activationStatus.name),
reviewStatus: (a, b) => {
Expand All @@ -46,13 +46,13 @@ const pluginComparators = {
const vA = getShopwareCompatibility(a, false) || '10000.0.0';
const vB = getShopwareCompatibility(b, false) || '10000.0.0';

return semver.compare(vA, vB);
return compareVersions(vA, vB);
},
maxShopwareCompatibility: (a, b) => {
const vA = getShopwareCompatibility(a, true) || '10000.0.0';
const vB = getShopwareCompatibility(b, true) || '10000.0.0';

return semver.compare(vA, vB);
return compareVersions(vA, vB);
},
};

Expand Down
7 changes: 3 additions & 4 deletions lib/commands/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const Chalk = require('chalk');
const path = require('path');
const Program = require('commander');
const semver = require('semver');
const { compareVersionsReverse } = require('composer-version-constraint-evaluator');
const ShopwareStoreCommander = require('../shopwareStoreCommander');
const publishPluginReleaseEvent = require('../publishPluginReleaseEvent');
const util = require('../util');
Expand All @@ -22,9 +22,8 @@ function parseOnOffAutoOption(suppliedValue) {
return suppliedValue;
default:
console.error(Chalk.white.bgRed.bold(`Invalid value '${suppliedValue}' for option --license-check-required.`));
process.exit(-1);

return undefined;
return process.exit(-1);
}
}

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

Expand Down
6 changes: 3 additions & 3 deletions lib/plugin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('mz/fs');
const JSZip = require('jszip');
const path = require('path');
const semver = require('semver');
const { versionSatisfiesConstraint } = require('composer-version-constraint-evaluator');
const { parseChangelogMarkdown } = require('./changelogMarkdownParser');

function readInfoFromComposerJson(composerJsonString) {
Expand Down Expand Up @@ -82,15 +82,15 @@ module.exports = class Plugin {
const shopwareVersion = this.getShopware6Semver(shopwareMarketingVersion);
const pluginShopwareCompatibility = this.getShopware6Semver(this.shopwareCompatibility);

return semver.satisfies(shopwareVersion, pluginShopwareCompatibility);
return versionSatisfiesConstraint(shopwareVersion, pluginShopwareCompatibility);
}

if (this.shopwareMajorVersion === 5) {
if (!shopwareMarketingVersion.startsWith('5.')) {
return false;
}

return semver.satisfies(shopwareMarketingVersion, this.shopwareCompatibility);
return versionSatisfiesConstraint(shopwareMarketingVersion, this.shopwareCompatibility);
}

throw new Error(
Expand Down
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"marked": "^2.0.3",
"mz": "^2.4.0",
"node-notifier": "^9.0.1",
"semver": "^7.3.5"
"composer-version-constraint-evaluator": "^1.0.0"
},
"devDependencies": {
"cspell": "^5.4.0",
Expand All @@ -59,4 +59,4 @@
"node": ">=18.0.0"
},
"preferGlobal": true
}
}

0 comments on commit 84212b2

Please sign in to comment.