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

Replace semver with version compare module that supports composer ranges #68

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
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 plugin binary version checks to support composer version constraints.

## 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, compareVersionsWithComparator } = require('@pickware/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 (compareVersionsWithComparator(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),
&& compareVersionsWithComparator(version.name, Program.opts().minVersion, '>=')
&& compareVersionsWithComparator(version.name, minCompatibleVersion, '<'),
));
} else if (semver.gt(Program.opts().minVersion, minCompatibleVersion)) {
} else if (compareVersionsWithComparator(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 && compareVersionsWithComparator(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 && compareVersionsWithComparator(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('@pickware/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('@pickware/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('@pickware/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.

2 changes: 1 addition & 1 deletion 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"
"@pickware/composer-version-constraint-evaluator": "^1.0.0"
},
"devDependencies": {
"cspell": "^5.4.0",
Expand Down
Loading