diff --git a/.rlx.yml b/.rlx.yml new file mode 100644 index 00000000..3dd6185e --- /dev/null +++ b/.rlx.yml @@ -0,0 +1 @@ +workspace_path: packages diff --git a/CHANGELOG.md b/CHANGELOG.md index b5f48902..3ea37559 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,15 @@ -## Changelog +# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed +- `root` - `scripts/release-sanity-check.js` and `scripts/version.js` replaced with `rlx` package + +### Fixed +- `root` - CHANGLOG.md according to the Keep a Changelog format ## [1.0.0-rc.15] - 2024-04-08 ### Fixed @@ -29,14 +34,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Output ESM files with `.mjs` extension - Updated `swc` dependencies versions to the latest -### Fixed -- `@distributedlab/w3p` - Tree-shaking issues related to sub-dependencies - ### Removed - `all` - Creating extra `package.json` files in the dist folder for resolving ESM and CommonJS modules - `all,root` - postbuild script - `all` - CDN distributives support +### Fixed +- `@distributedlab/w3p` - Tree-shaking issues related to sub-dependencies + ## [1.0.0-rc.10] - 2024-01-18 ### Fixed - `@distributedlab/jac` - possibility to throw custom error on request @@ -233,12 +238,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `@distributedlab/tools` - `EventEmitter` Make emit second parameter optional ## [0.2.0-rc.5] - 2023-04-24 -### Fixed -- `@distributedlab/fetcher` - `clone` method - ### Removed - `@distributedlab/jac` - Dependency `@distributedlab/jsona` +### Fixed +- `@distributedlab/fetcher` - `clone` method + ## [0.2.0-rc.4] - 2023-04-24 ### Added - `@distributedlab/jac` - `deserialize` helper to deserialize JSON API structures @@ -248,7 +253,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `@distributedlab/jac` - Dependency `@distributedlab/jsona` ## [0.2.0-rc.3] - 2023-04-24 -## Added +### Added - `root`: Package `@distributedlab/w3p` - wrapper for web3 providers - `EVN based`: - `MetamaskProvider` @@ -259,7 +264,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Near based`: - `NearProvider` -## Removed +### Removed - `root` - Unused `tsconfig.eslint.json` ## [0.2.0-rc.2] - 2023-04-24 @@ -277,8 +282,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `all` - Set "browser": to "./dist/esm/index.js" to correctly resolve the package by the Webpack - `all` - Moved exclude tests to the `tsconfig.build.json` file to make ESLint work in the tests -[SWC tsc migration guide]: https://swc.rs/docs/migrating-from-tsc - ## [0.2.0-rc.1] - 2023-04-17 ### Added - `@distributedlab/jac` - `@distributedlab/fetcher` dependency @@ -374,9 +377,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `@distributedlab/tools`: Handling big numbers - `@distributedlab/tools`: Add tests for time.ts and duration.ts -### Changed**** +### Changed - `root`: Updated `README.md` + +[SWC tsc migration guide]: https://swc.rs/docs/migrating-from-tsc [old repo]: https://github.com/distributed-lab/web-kit-old [Unreleased]: https://github.com/distributed-lab/web-kit/compare/1.0.0-rc.15...HEAD diff --git a/package.json b/package.json index 56520ba7..1df01cf6 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ ], "gitHooks": { "pre-commit": "yarn lint", - "pre-push": "yarn test && yarn rsc" + "pre-push": "yarn test && npx rlx rsc" }, "scripts": { "build": "yarn workspaces foreach -pv --topological-dev run build", @@ -36,10 +36,11 @@ "test:watch": "jest --watch", "publish-next": "yarn build && yarn workspaces foreach --no-private exec yarn npm publish --tag next", "publish-latest": "yarn build && yarn workspaces foreach --no-private exec yarn npm publish", - "rsc": "node scripts/release-sanity-check.js", - "apply-version": "node scripts/version.js" + "apply-version": "npx rlx version apply", + "change-log:format": "npx rlx change-log format" }, "devDependencies": { + "@napalmpapalam/rlx": "^0.3.2", "@swc/cli": "^0.3.9", "@swc/core": "^1.4.2", "@swc/jest": "^0.2.36", diff --git a/scripts/release-sanity-check.js b/scripts/release-sanity-check.js deleted file mode 100644 index 1dc8bc02..00000000 --- a/scripts/release-sanity-check.js +++ /dev/null @@ -1,143 +0,0 @@ -const fs = require('fs') -const path = require('path') -const chalk = require('chalk') -const childProcess = require('child_process') - -const VERSION = getVersion() -const PACKAGE_JSON_MAP = getWorkspacePackageJsons() -const CHANGELOG_MD_CONTENT = readFile('../CHANGELOG.md') - -const issuesFound = [] - -function runAllValidations () { - if (!VERSION) { - return reportCheckSkipped() - } - - validateSemverCompatibility() - validatePackageJsonVersion() - validateChangelogHasVersion() - validateChangelogHasVersionOnTop() - validateChangelogAnchorsLegend() - report() -} - -function validateSemverCompatibility () { - const semverRe = /^\d+\.\d+\.\d+((-rc|-x)\.\d+)?$/i - - if (!semverRe.test(VERSION)) { - issuesFound.push(`Version ${VERSION} is not semver compatible`) - } -} - -function validatePackageJsonVersion () { - Object.entries(PACKAGE_JSON_MAP).forEach(([pack, packageJSON]) => { - if (packageJSON.version !== VERSION) { - issuesFound - .push(`@distributedlab/${pack} package.json version should equal ${VERSION}, got ${packageJSON.version}`) - } - }) -} - -function validateChangelogHasVersion () { - const todayYmd = new Date().toISOString().split('T')[0] // YYYY-MM-DD - const releaseTagRe = - new RegExp(`^## \\[${escapeRe(VERSION)}\\] - ${todayYmd}$`, 'm') - - if (!releaseTagRe.test(CHANGELOG_MD_CONTENT)) { - issuesFound - .push(`"## [${VERSION}] - ${todayYmd}" is absent in CHANGELOG.md`) - } -} - -function validateChangelogHasVersionOnTop () { - const todayYmd = new Date().toISOString().split('T')[0] // YYYY-MM-DD - const releaseTagIsNotTopRe = new RegExp( - '## \\[\\d+\\.\\d+\\.\\d+((-rc|-x)\\.\\d+)?\\][\\s\\S]*' + // any other tag - `## \\[${escapeRe(VERSION)}\\] - ${todayYmd}`, // the new - 'i' - ) - - if (releaseTagIsNotTopRe.test(CHANGELOG_MD_CONTENT)) { - issuesFound.push(`The ${VERSION} is not the top tag in CHANGELOG.md`) - } -} - -function validateChangelogAnchorsLegend () { - const baseRepoUrl = 'https://github.com/distributed-lab/web-kit' - const anyReleaseTagRe = - /## \[\d+\.\d+\.\d+((-rc|-x)\.\d+)?\] - \d{4}-\d{2}-\d{2}/gi - - const expectedAnchorsLegend = - `[Unreleased]: ${baseRepoUrl}/compare/${VERSION}...HEAD\n` + - CHANGELOG_MD_CONTENT - .match(anyReleaseTagRe) - ?.map(tag => tag.match(/\[(.*)\]/)[1]) - ?.map((cur, curId, arr) => { - return curId === arr.length - 1 - ? `[${cur}]: ${baseRepoUrl}/releases/tag/${cur}` - : `[${cur}]: ${baseRepoUrl}/compare/${arr[curId + 1]}...${cur}` - }) - ?.join('\n') - - if (!CHANGELOG_MD_CONTENT.includes(expectedAnchorsLegend)) { - issuesFound.push(`The anchors legend is invalid, should be:\n${expectedAnchorsLegend}`) - } -} - -function report () { - /* eslint-disable no-console */ - if (issuesFound.length) { - console.error(chalk`{red Release sanity check for {yellow ${VERSION}} failed!}`) - - for (const issue of issuesFound) { - console.error(chalk`{red ${issue}}`) - } - - process.exitCode = 1 - } else { - console.log(chalk`{green Release sanity check for {yellow ${VERSION}} passed}`) - } - /* eslint-enable no-console */ -} - -function reportCheckSkipped () { - /* eslint-disable-next-line no-console */ - console.log(chalk.gray('No version tag found, skipping release sanity check...')) -} - -function getVersion () { - if (process.argv[2]) { - return process.argv[2] - } - - const refsReport = exec('git log -1 --format="%D"').toString() - const versionMatch = refsReport.match(/tag: ([\w\d\-_.]+)/i) - return versionMatch ? versionMatch[1] : '' -} - -function getWorkspacePackageJsons () { - const dirs = fs.readdirSync(path.resolve(__dirname, '../packages')) - - return dirs.reduce((acc, dir) => { - acc[dir] = require(path.resolve(__dirname, `../packages/${dir}/package.json`)) - return acc - }, {}) -} - -function readFile (relativePath) { - const resolvedPath = path.resolve(__dirname, relativePath) - return fs.readFileSync(resolvedPath, 'utf8') -} - -function escapeRe (string) { - return string.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') -} - -function exec (command) { - return childProcess.execSync(command, { - cwd: path.resolve(__dirname, '..') - }) -} - -runAllValidations() diff --git a/scripts/version.js b/scripts/version.js deleted file mode 100644 index 2bdf2f13..00000000 --- a/scripts/version.js +++ /dev/null @@ -1,68 +0,0 @@ -const fs = require("fs") -const path = require("path") -const chalk = require("chalk") - -const ORGANIZATION_NAME = "@distributedlab" -const VERSION_REGEX = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ -const VERSION = process.argv[2] - -const issuesFound = [] -const packages = fs.readdirSync(path.resolve(__dirname, "../packages")) - - -const run = () => { - validateSemverCompatibility(); - - if (!issuesFound.length) applyVersion() - report() -} - -function validateSemverCompatibility() { - if (process.argv.length !== 3) { - issuesFound.push("No version provided") - } - - if (!VERSION_REGEX.test(VERSION)) { - issuesFound.push(`Version ${VERSION} not semver compatible, should match https://semver.org/ specification`) - } -} - - -function applyVersion() { - for (const pkg of packages) { - const packageJsonPath = path.resolve(__dirname, `../packages/${pkg}/package.json`) - const packageJson = require(packageJsonPath) - - if (packageJson.version === VERSION) { - continue - } - - packageJson.version = VERSION - - fs.writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`, (err) => { - if (err) issuesFound.push(`[${ORGANIZATION_NAME}/${pkg}]: Version apply failed: ${err.toString()}`) - }) - - if (issuesFound.length) break - } -} - - -function report() { - if (issuesFound.length) { - console.error(chalk`{red Version {yellow ${VERSION}} apply failed!}`) - issuesFound.forEach((issue) => { - console.error(chalk`{red ${issue}}`) - }) - process.exitCode = 1 - } else { - console.log(chalk`{green Version {yellow ${VERSION}} apply passed}`) - packages.forEach((pkg) => { - console.error(chalk`{yellow [${ORGANIZATION_NAME}/${pkg}]}: {green ${VERSION}}`) - }); - process.exitCode = 0 - } -} - -run() - diff --git a/yarn.lock b/yarn.lock index 3d260821..fd26e5fb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1283,6 +1283,18 @@ __metadata: languageName: node linkType: hard +"@napalmpapalam/rlx@npm:^0.3.2": + version: 0.3.2 + resolution: "@napalmpapalam/rlx@npm:0.3.2" + dependencies: + binary-install: ^1.1.0 + console.table: ^0.10.0 + bin: + rlx: run.js + checksum: 48bdfd192fb756639266e09f2ae850dddee5f5227496603f0489d4e991b59bd80d1c3618b2c120ca0552857ec1380bc0a3236bc45b5531441bdbedd6e9efd130 + languageName: node + linkType: hard + "@near-wallet-selector/core@npm:7.9.3, @near-wallet-selector/core@npm:^7.8.2": version: 7.9.3 resolution: "@near-wallet-selector/core@npm:7.9.3" @@ -2871,6 +2883,15 @@ __metadata: languageName: node linkType: hard +"axios@npm:^0.26.1": + version: 0.26.1 + resolution: "axios@npm:0.26.1" + dependencies: + follow-redirects: ^1.14.8 + checksum: d9eb58ff4bc0b36a04783fc9ff760e9245c829a5a1052ee7ca6013410d427036b1d10d04e7380c02f3508c5eaf3485b1ae67bd2adbfec3683704745c8d7a6e1a + languageName: node + linkType: hard + "babel-jest@npm:^29.7.0": version: 29.7.0 resolution: "babel-jest@npm:29.7.0" @@ -3039,6 +3060,17 @@ __metadata: languageName: node linkType: hard +"binary-install@npm:^1.1.0": + version: 1.1.0 + resolution: "binary-install@npm:1.1.0" + dependencies: + axios: ^0.26.1 + rimraf: ^3.0.2 + tar: ^6.1.11 + checksum: 271344b49f42460f5e3ec29d681cd4b749aaf9592040d49f6ae86d267b997b5fd094fd7a710df4d477fc299a51833b8cb94206595db6c46edea3f1603266a0d2 + languageName: node + linkType: hard + "bindings@npm:^1.3.0": version: 1.5.0 resolution: "bindings@npm:1.5.0" @@ -3388,6 +3420,13 @@ __metadata: languageName: node linkType: hard +"clone@npm:^1.0.2": + version: 1.0.4 + resolution: "clone@npm:1.0.4" + checksum: d06418b7335897209e77bdd430d04f882189582e67bd1f75a04565f3f07f5b3f119a9d670c943b6697d0afb100f03b866b3b8a1f91d4d02d72c4ecf2bb64b5dd + languageName: node + linkType: hard + "co@npm:^4.6.0": version: 4.6.0 resolution: "co@npm:4.6.0" @@ -3469,6 +3508,15 @@ __metadata: languageName: node linkType: hard +"console.table@npm:^0.10.0": + version: 0.10.0 + resolution: "console.table@npm:0.10.0" + dependencies: + easy-table: 1.1.0 + checksum: 4c1460e3105a5f7df5bfa372844104a20e487fc0fccc5821c169a39def3249759554fc132621074ad6695664a1a8d558dd385c0e7f290acb2eaca51466474bb9 + languageName: node + linkType: hard + "content-disposition@npm:^0.5.4": version: 0.5.4 resolution: "content-disposition@npm:0.5.4" @@ -3655,6 +3703,15 @@ __metadata: languageName: node linkType: hard +"defaults@npm:^1.0.3": + version: 1.0.4 + resolution: "defaults@npm:1.0.4" + dependencies: + clone: ^1.0.2 + checksum: 3a88b7a587fc076b84e60affad8b85245c01f60f38fc1d259e7ac1d89eb9ce6abb19e27215de46b98568dd5bc48471730b327637e6f20b0f1bc85cf00440c80a + languageName: node + linkType: hard + "defer-to-connect@npm:^2.0.0": version: 2.0.1 resolution: "defer-to-connect@npm:2.0.1" @@ -3795,6 +3852,18 @@ __metadata: languageName: node linkType: hard +"easy-table@npm:1.1.0": + version: 1.1.0 + resolution: "easy-table@npm:1.1.0" + dependencies: + wcwidth: ">=1.0.1" + dependenciesMeta: + wcwidth: + optional: true + checksum: 49b960fefe5670076773824386f22070dce185ebc0a99542035496700cc39a0b9346f65fd4307f5fe3dbbe7e6d9c4b59966e77e32f915e0fe71de71c3d0efcf7 + languageName: node + linkType: hard + "electron-to-chromium@npm:^1.4.668": version: 1.4.729 resolution: "electron-to-chromium@npm:1.4.729" @@ -4630,6 +4699,16 @@ __metadata: languageName: node linkType: hard +"follow-redirects@npm:^1.14.8": + version: 1.15.6 + resolution: "follow-redirects@npm:1.15.6" + peerDependenciesMeta: + debug: + optional: true + checksum: a62c378dfc8c00f60b9c80cab158ba54e99ba0239a5dd7c81245e5a5b39d10f0c35e249c3379eae719ff0285fff88c365dd446fab19dee771f1d76252df1bbf5 + languageName: node + linkType: hard + "for-each@npm:^0.3.3": version: 0.3.3 resolution: "for-each@npm:0.3.3" @@ -8786,10 +8865,20 @@ __metadata: languageName: node linkType: hard +"wcwidth@npm:>=1.0.1": + version: 1.0.1 + resolution: "wcwidth@npm:1.0.1" + dependencies: + defaults: ^1.0.3 + checksum: 814e9d1ddcc9798f7377ffa448a5a3892232b9275ebb30a41b529607691c0491de47cba426e917a4d08ded3ee7e9ba2f3fe32e62ee3cd9c7d3bafb7754bd553c + languageName: node + linkType: hard + "web-kit-monorepo-root@workspace:.": version: 0.0.0-use.local resolution: "web-kit-monorepo-root@workspace:." dependencies: + "@napalmpapalam/rlx": ^0.3.2 "@swc/cli": ^0.3.9 "@swc/core": ^1.4.2 "@swc/jest": ^0.2.36