From 93568ec0243e3c2b36bb2f006b9bb816f9af725c Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Fri, 12 Apr 2024 20:02:05 +0300 Subject: [PATCH] Process PEP440 versions --- dictionary | 2 +- package.json | 3 ++ typescript/base/.eslintrc.cjs | 1 + typescript/base/package.json | 1 + typescript/base/src/instance.ts | 51 +++++++++++++++++-- .../projects/ima/schain/SchainImaInstance.ts | 3 ++ typescript/base/yarn.lock | 8 +++ yarn.lock | 12 +++++ 8 files changed, 77 insertions(+), 4 deletions(-) diff --git a/dictionary b/dictionary index 1187fd7..76852fd 160000 --- a/dictionary +++ b/dictionary @@ -1 +1 @@ -Subproject commit 1187fd7c0a2665788895da215a56906ed697bb0f +Subproject commit 76852fd21bdb6afb52820d8fac31fd8dcdb4755c diff --git a/package.json b/package.json index 8d55210..4377e62 100644 --- a/package.json +++ b/package.json @@ -15,5 +15,8 @@ "hooks": "git config core.hooksPath .githooks || true", "no-hooks": "git config core.hooksPath .git/hooks", "prepare": "yarn hooks" + }, + "dependencies": { + "semver": "^7.6.0" } } diff --git a/typescript/base/.eslintrc.cjs b/typescript/base/.eslintrc.cjs index 70a084c..896c99a 100644 --- a/typescript/base/.eslintrc.cjs +++ b/typescript/base/.eslintrc.cjs @@ -24,6 +24,7 @@ module.exports = { "error", "separate-lines" ], + "no-warning-comments": ["warn"], "object-curly-spacing": [ "error", "always" diff --git a/typescript/base/package.json b/typescript/base/package.json index 9a5d4c8..812f9fa 100644 --- a/typescript/base/package.json +++ b/typescript/base/package.json @@ -25,6 +25,7 @@ "types": "lib/index.d.ts", "version": "1.0.1", "dependencies": { + "@renovatebot/pep440": "^3.0.19", "axios": "^1.4.0" } } diff --git a/typescript/base/src/instance.ts b/typescript/base/src/instance.ts index 9e22f59..8b95402 100644 --- a/typescript/base/src/instance.ts +++ b/typescript/base/src/instance.ts @@ -1,9 +1,12 @@ +import * as semver from "semver"; import { ContractAddress, ContractName, MainContractAddress, SkaleABIFile } from "./domain/types"; +import { parse, stringify } from "@renovatebot/pep440/lib/version"; +import { Pep440Version } from "@renovatebot/pep440"; import { Project } from "./project"; export type InstanceData = { @@ -27,6 +30,40 @@ const defaultVersionAbi = [ } ]; +const processSemver = (semVersion: semver.SemVer) => { + if (!semVersion.prerelease.length) { + const defaultPrerelease = 0; + semVersion.prerelease = [ + "stable", + defaultPrerelease + ]; + } + return semVersion.format(); +}; + +const processPep440 = (pyVersion: Pep440Version) => { + const replaceMap = new Map([ + [ + "a", + "develop" + ], + [ + "b", + "beta" + ] + ]); + pyVersion.pre = pyVersion.pre.map((value: string | number) => { + if (typeof value === "string" && replaceMap.has(value)) { + return `-${replaceMap.get(value)!}.`; + } + return value; + }); + // TODO: remove any after the fix in the @renovatebot/pep440 library + // https://github.com/renovatebot/pep440/pull/555 + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return stringify(pyVersion as any)!; +}; + export abstract class Instance { protected project: Project; @@ -87,9 +124,17 @@ export abstract class Instance { private async getVersion () { if (typeof this.version === "undefined") { - this.version = await this.queryVersion(); - if (!this.version.includes("-")) { - this.version = `${this.version}-stable.0`; + const rawVersion = await this.queryVersion(); + const semVersion = semver.parse(rawVersion); + if (semVersion) { + this.version = processSemver(semVersion); + } else { + const pyVersion = parse(rawVersion); + if (pyVersion) { + this.version = processPep440(pyVersion); + } else { + throw new Error(`Can't parse version ${rawVersion}`); + } } } return this.version; diff --git a/typescript/base/src/projects/ima/schain/SchainImaInstance.ts b/typescript/base/src/projects/ima/schain/SchainImaInstance.ts index 5e4d3d4..b130074 100644 --- a/typescript/base/src/projects/ima/schain/SchainImaInstance.ts +++ b/typescript/base/src/projects/ima/schain/SchainImaInstance.ts @@ -47,6 +47,9 @@ export class SchainImaInstance extends ]); getContractAddress (name: string): Promise { + if (name === "MessageProxyForSchain") { + return Promise.resolve(this.address); + } if (SchainImaInstance.PREDEPLOYED.has(name)) { return Promise.resolve(SchainImaInstance.PREDEPLOYED. get(name) as string); diff --git a/typescript/base/yarn.lock b/typescript/base/yarn.lock index 4882374..946abac 100644 --- a/typescript/base/yarn.lock +++ b/typescript/base/yarn.lock @@ -106,10 +106,18 @@ __metadata: languageName: node linkType: hard +"@renovatebot/pep440@npm:^3.0.19": + version: 3.0.19 + resolution: "@renovatebot/pep440@npm:3.0.19" + checksum: d4465f4bec8fe231ac5428c6ed1b9844508b0e0357eeb69818ce24a373faf41dbc2d2b60b2af474bf997aea918aaadb4d75ea005bfa6358deef9a5652f53d141 + languageName: node + linkType: hard + "@skalenetwork/skale-contracts@workspace:.": version: 0.0.0-use.local resolution: "@skalenetwork/skale-contracts@workspace:." dependencies: + "@renovatebot/pep440": ^3.0.19 "@tsconfig/recommended": ^1.0.2 "@types/node": ^20.2.5 "@typescript-eslint/eslint-plugin": ^6.0.0 diff --git a/yarn.lock b/yarn.lock index e652921..e7ca455 100644 --- a/yarn.lock +++ b/yarn.lock @@ -811,6 +811,7 @@ __metadata: resolution: "development@workspace:." dependencies: cspell: ^6.31.1 + semver: ^7.6.0 languageName: unknown linkType: soft @@ -1371,6 +1372,17 @@ __metadata: languageName: node linkType: hard +"semver@npm:^7.6.0": + version: 7.6.0 + resolution: "semver@npm:7.6.0" + dependencies: + lru-cache: ^6.0.0 + bin: + semver: bin/semver.js + checksum: 7427f05b70786c696640edc29fdd4bc33b2acf3bbe1740b955029044f80575fc664e1a512e4113c3af21e767154a94b4aa214bf6cd6e42a1f6dba5914e0b208c + languageName: node + linkType: hard + "signal-exit@npm:^3.0.2": version: 3.0.7 resolution: "signal-exit@npm:3.0.7"