From 35edafa437fe610d1beaefbac34d1f5c55a50926 Mon Sep 17 00:00:00 2001 From: Salakar Date: Wed, 13 May 2020 14:22:08 +0100 Subject: [PATCH] fix: peer dependency versions [publish] --- .github/workflows/publish.yml | 3 +- .gitignore | 2 +- scripts/version.js | 53 +++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 scripts/version.js diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0ce865ed1d..9fce21e585 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -34,7 +34,8 @@ jobs: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc npm whoami git diff --exit-code - yarn lerna publish --yes + yarn lerna version --yes + yarn lerna publish from-package --yes env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} GH_TOKEN: ${{ secrets.GH_TOKEN }} diff --git a/.gitignore b/.gitignore index 1bc72ae01e..55b847e6c7 100644 --- a/.gitignore +++ b/.gitignore @@ -540,7 +540,7 @@ Pods/* .idea/**/* **/Pods/** **/dist/ -**/version.js +packages/**/version.js typedoc.raw.json tests/ios/Firebase tests/ios/resetXcode.sh diff --git a/scripts/version.js b/scripts/version.js new file mode 100644 index 0000000000..a7c35a92d1 --- /dev/null +++ b/scripts/version.js @@ -0,0 +1,53 @@ +const { sep } = require('path'); +const { execSync } = require('child_process'); +const { readFileSync, writeFileSync } = require('fs'); + +const packages = JSON.parse(execSync('lerna ls --json').toString('utf-8')); + +const firebaseAppPackageName = '@react-native-firebase/app'; +const firebaseAppPackageVersion = packages.find(package => package.name == firebaseAppPackageName) + .version; + +packages.forEach(package => { + if (package.name == firebaseAppPackageName) return; + const { name, version, location } = package; + + // --------------------------- + // Fix Changelog Links + // --------------------------- + // Links to commits/PRs are broken on conventional-commits-changelog + const changelogPath = `${location}${sep}/CHANGELOG.md`; + let changelogContents = readFileSync(changelogPath).toString('utf-8'); + changelogContents = changelogContents.replace( + /github\.com\/invertase\/react-native-firebase\/(tree\/master\/packages\/[a-z-]*\/)/gm, + 'github.com/invertase/react-native-firebase/', + ); + writeFileSync(changelogPath, changelogContents); + + // --------------------------- + // Format Changelog + // --------------------------- + execSync(`prettier --write ${changelogPath}`); + + // --------------------------- + // Update Peer Dependencies + // --------------------------- + const packageJsonPath = `${location}${sep}/package.json`; + const packageJsonContents = JSON.parse(readFileSync(packageJsonPath).toString('utf-8')); + if (!packageJsonContents.peerDependencies) return; + if (!packageJsonContents.peerDependencies[firebaseAppPackageName]) return; + if (packageJsonContents.peerDependencies[firebaseAppPackageName] === firebaseAppPackageVersion) { + return; + } + + packageJsonContents.peerDependencies[firebaseAppPackageName] = firebaseAppPackageVersion; + + writeFileSync(packageJsonPath, JSON.stringify(packageJsonContents, null, 2) + '\n'); + + console.log( + `Updated '${firebaseAppPackageName}' peer dependency on package`, + packageJsonContents.name, + 'to', + packageJsonContents.peerDependencies[firebaseAppPackageName], + ); +});