From 20fe1aa05cbb59936e860ee168b583b19186ada3 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 15 Apr 2020 10:26:15 +0000 Subject: [PATCH 1/2] chore(deps): bump semver from 7.2.2 to 7.3.2 Bumps [semver](https://github.com/npm/node-semver) from 7.2.2 to 7.3.2. - [Release notes](https://github.com/npm/node-semver/releases) - [Changelog](https://github.com/npm/node-semver/blob/master/CHANGELOG.md) - [Commits](https://github.com/npm/node-semver/compare/v7.2.2...v7.3.2) Signed-off-by: dependabot-preview[bot] --- packages/@jsii/dotnet-runtime/package.json | 2 +- packages/jsii-pacmak/package.json | 2 +- packages/jsii/package.json | 2 +- yarn.lock | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/@jsii/dotnet-runtime/package.json b/packages/@jsii/dotnet-runtime/package.json index fcc204d1b2..0e5d403300 100644 --- a/packages/@jsii/dotnet-runtime/package.json +++ b/packages/@jsii/dotnet-runtime/package.json @@ -42,7 +42,7 @@ "@types/node": "^10.17.19", "@types/semver": "^7.1.0", "jsii-build-tools": "^0.0.0", - "semver": "^7.2.2", + "semver": "^7.3.2", "typescript": "~3.8.3" } } diff --git a/packages/jsii-pacmak/package.json b/packages/jsii-pacmak/package.json index a82ed91974..a0d0267acc 100644 --- a/packages/jsii-pacmak/package.json +++ b/packages/jsii-pacmak/package.json @@ -42,7 +42,7 @@ "fs-extra": "^9.0.0", "jsii-reflect": "^0.0.0", "jsii-rosetta": "^0.0.0", - "semver": "^7.2.2", + "semver": "^7.3.2", "spdx-license-list": "^6.1.0", "xmlbuilder": "^15.1.1", "yargs": "^15.3.1" diff --git a/packages/jsii/package.json b/packages/jsii/package.json index decd00206c..ce3cb0923a 100644 --- a/packages/jsii/package.json +++ b/packages/jsii/package.json @@ -39,7 +39,7 @@ "deep-equal": "^2.0.2", "fs-extra": "^9.0.0", "log4js": "^6.2.0", - "semver": "^7.2.2", + "semver": "^7.3.2", "semver-intersect": "^1.4.0", "sort-json": "^2.0.0", "spdx-license-list": "^6.1.0", diff --git a/yarn.lock b/yarn.lock index 9c729725c1..b870ed8057 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7931,10 +7931,10 @@ semver@6.3.0, semver@^6.0.0, semver@^6.1.2, semver@^6.2.0, semver@^6.3.0: resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d" integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== -semver@^7.2.2: - version "7.2.2" - resolved "https://registry.yarnpkg.com/semver/-/semver-7.2.2.tgz#d01432d74ed3010a20ffaf909d63a691520521cd" - integrity sha512-Zo84u6o2PebMSK3zjJ6Zp5wi8VnQZnEaCP13Ul/lt1ANsLACxnJxq4EEm1PY94/por1Hm9+7xpIswdS5AkieMA== +semver@^7.3.2: + version "7.3.2" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938" + integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ== serialize-javascript@^2.1.2: version "2.1.2" From a2221e39cda4be39fe3612c11a31a4d4435e1e95 Mon Sep 17 00:00:00 2001 From: Romain Marcadier-Muller Date: Wed, 15 Apr 2020 15:22:41 +0200 Subject: [PATCH 2/2] fix -0 suffix added by semver on '<' comparators --- .../jsii-pacmak/lib/targets/version-utils.ts | 37 +++++++++++++------ ...s.CalculatorPackageId.BasePackageId.csproj | 2 +- ...ts.CalculatorPackageId.LibPackageId.csproj | 4 +- ...azon.JSII.Tests.CalculatorPackageId.csproj | 6 +-- .../test/targets/version-utils.test.ts | 8 ++-- 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/packages/jsii-pacmak/lib/targets/version-utils.ts b/packages/jsii-pacmak/lib/targets/version-utils.ts index 41afa1db02..70d2d632ae 100644 --- a/packages/jsii-pacmak/lib/targets/version-utils.ts +++ b/packages/jsii-pacmak/lib/targets/version-utils.ts @@ -9,7 +9,7 @@ import { Comparator, Range } from 'semver'; * @see https://cwiki.apache.org/confluence/display/MAVENOLD/Dependency+Mediation+and+Conflict+Resolution */ export function toMavenVersionRange(semverRange: string, suffix?: string): string { - return toBracketNotation(semverRange, suffix); + return toBracketNotation(semverRange, suffix, { semver: false }); } /** @@ -34,33 +34,37 @@ export function toPythonVersionRange(semverRange: string): string { return range.set.map( set => set.map( comp => { + const versionId = comp.semver.raw?.replace(/-0$/, '') ?? '0.0.0'; switch (comp.operator) { case '': + // With ^0.0.0, somehow we get a left entry with an empty operator and value, we'll fix this up + return comp.value === '' ? '>=0.0.0' : `==${versionId}`; case '=': - return `==${comp.semver.raw}`; + return `==${versionId}`; default: // >, >=, <, <= are all valid expressions - return `${comp.operator}${comp.semver.raw}`; + return `${comp.operator}${versionId}`; } } ).join(', ') ).join(', '); } -function toBracketNotation(semverRange: string, suffix?: string): string { +function toBracketNotation(semverRange: string, suffix?: string, { semver = true }: { semver?: boolean } = {}): string { const range = new Range(semverRange); return range.set.map(set => { if (set.length === 1) { + const version = set[0].semver.raw; switch (set[0].operator || '=') { // "[version]" => means exactly version - case '=': return `[${addSuffix(set[0].semver.raw)}]`; + case '=': return `[${addSuffix(version)}]`; // "(version,]" => means greater than version - case '>': return `(${addSuffix(set[0].semver.raw)},]`; + case '>': return `(${addSuffix(version)},]`; // "[version,]" => means greater than or equal to that version - case '>=': return `[${addSuffix(set[0].semver.raw)},]`; + case '>=': return `[${addSuffix(version)},]`; // "[,version)" => means less than version - case '<': return `[,${addSuffix(set[0].semver.raw)})`; + case '<': return `[,${addSuffix(version, !semver)})`; // "[,version]" => means less than or equal to version - case '<=': return `[,${addSuffix(set[0].semver.raw)}]`; + case '<=': return `[,${addSuffix(version)}]`; } } else if (set.length === 2) { const nugetRange = toBracketRange(set[0], set[1]); @@ -68,7 +72,7 @@ function toBracketNotation(semverRange: string, suffix?: string): string { return nugetRange; } } - throw new Error(`Unsupported SemVer range set: ${set.map(comp => comp.value).join(', ')}`); + throw new Error(`Unsupported SemVer range set in ${semverRange}: ${set.map(comp => comp.value).join(', ')}`); }).join(', '); function toBracketRange(left: Comparator, right: Comparator): string | undefined { @@ -77,6 +81,11 @@ function toBracketNotation(semverRange: string, suffix?: string): string { [left, right] = [right, left]; } + // With ^0.0.0, somehow we get a left entry with an empty operator and value, we'll fix this up + if (left.operator === '' && left.value === '') { + left = new Comparator('>=0.0.0', left.options); + } + if (!left.operator.startsWith('>') || !right.operator.startsWith('<')) { // We only support ranges defined like "> (or >=) left, < (or <=) right" return undefined; @@ -84,10 +93,14 @@ function toBracketNotation(semverRange: string, suffix?: string): string { const leftBrace = left.operator.endsWith('=') ? '[' : '('; const rightBrace = right.operator.endsWith('=') ? ']' : ')'; - return `${leftBrace}${addSuffix(left.semver.raw)},${addSuffix(right.semver.raw)}${rightBrace}`; + return `${leftBrace}${addSuffix(left.semver.raw)},${addSuffix(right.semver.raw, right.operator === '<' && !semver)}${rightBrace}`; } - function addSuffix(str: string) { + function addSuffix(str: string | undefined, trimDashZero = false) { + if (!str) { return ''; } + if (trimDashZero) { + str = str.replace(/-0$/, ''); + } return suffix ? `${str}${suffix}` : str; } } diff --git a/packages/jsii-pacmak/test/expected.jsii-calc-base/dotnet/Amazon.JSII.Tests.CalculatorPackageId.BasePackageId/Amazon.JSII.Tests.CalculatorPackageId.BasePackageId.csproj b/packages/jsii-pacmak/test/expected.jsii-calc-base/dotnet/Amazon.JSII.Tests.CalculatorPackageId.BasePackageId/Amazon.JSII.Tests.CalculatorPackageId.BasePackageId.csproj index 6df81f8e66..c85c0e3114 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc-base/dotnet/Amazon.JSII.Tests.CalculatorPackageId.BasePackageId/Amazon.JSII.Tests.CalculatorPackageId.BasePackageId.csproj +++ b/packages/jsii-pacmak/test/expected.jsii-calc-base/dotnet/Amazon.JSII.Tests.CalculatorPackageId.BasePackageId/Amazon.JSII.Tests.CalculatorPackageId.BasePackageId.csproj @@ -26,7 +26,7 @@ - + 0612,0618 diff --git a/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId.csproj b/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId.csproj index ab48cbd8c8..f5350812e2 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId.csproj +++ b/packages/jsii-pacmak/test/expected.jsii-calc-lib/dotnet/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId/Amazon.JSII.Tests.CalculatorPackageId.LibPackageId.csproj @@ -26,8 +26,8 @@ - - + + 0612,0618 diff --git a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon.JSII.Tests.CalculatorPackageId.csproj b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon.JSII.Tests.CalculatorPackageId.csproj index 525025ccb2..6a40934b9d 100644 --- a/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon.JSII.Tests.CalculatorPackageId.csproj +++ b/packages/jsii-pacmak/test/expected.jsii-calc/dotnet/Amazon.JSII.Tests.CalculatorPackageId/Amazon.JSII.Tests.CalculatorPackageId.csproj @@ -28,9 +28,9 @@ - - - + + + 0612,0618 diff --git a/packages/jsii-pacmak/test/targets/version-utils.test.ts b/packages/jsii-pacmak/test/targets/version-utils.test.ts index 9b227c7303..99192bcda8 100644 --- a/packages/jsii-pacmak/test/targets/version-utils.test.ts +++ b/packages/jsii-pacmak/test/targets/version-utils.test.ts @@ -9,12 +9,12 @@ const examples: Record }, '~1.2.3': { maven: '[1.2.3,1.3.0)', - nuget: '[1.2.3,1.3.0)', + nuget: '[1.2.3,1.3.0-0)', python: '>=1.2.3, <1.3.0', }, '^1.2.3': { maven: '[1.2.3,2.0.0)', - nuget: '[1.2.3,2.0.0)', + nuget: '[1.2.3,2.0.0-0)', python: '>=1.2.3, <2.0.0', }, @@ -26,12 +26,12 @@ const examples: Record }, '~0.1.2': { maven: '[0.1.2,0.2.0)', - nuget: '[0.1.2,0.2.0)', + nuget: '[0.1.2,0.2.0-0)', python: '>=0.1.2, <0.2.0', }, '^0.1.2': { maven: '[0.1.2,0.2.0)', - nuget: '[0.1.2,0.2.0)', + nuget: '[0.1.2,0.2.0-0)', python: '>=0.1.2, <0.2.0', },