From 4049e9e9b43f697c26b61e19effef1fd4f079ce6 Mon Sep 17 00:00:00 2001 From: Pierre-Marie Dartus Date: Thu, 19 Jul 2018 10:23:51 -0700 Subject: [PATCH] build: Add validation script for peer dependencies versions (#522) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Details This PR adds a validation step in the CI to ensure the validity of the peer-dependencies versions. This would prevent in the future issues where `peerDependencies` and `devDependencies` gets out of sync. screen shot 2018-07-19 at 6 55 06 am **🗒 Note:** Since lerna doesn't update the `peerDependencies` when doing a version bump and push automatically the generated commit, the next major version bump will cause a CI breakage on the branch we will be releasing. #523 ## Does this PR introduce a breaking change? * [ ] Yes * [X] No --- .circleci/config.yml | 4 ++++ package.json | 2 ++ scripts/tasks/version-check.js | 40 ++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 scripts/tasks/version-check.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 94713d1860..dac1e30a6d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,6 +22,10 @@ jobs: - packages/*/node_modules key: yarn-v4-{{ checksum "yarn.lock" }} + - run: + name: Validation package versions + command: node ./scripts/tasks/version-check.js + - run: name: Run Linting command: yarn lint diff --git a/package.json b/package.json index 914dc61949..cb67530b5d 100644 --- a/package.json +++ b/package.json @@ -40,10 +40,12 @@ "commitizen": "~2.9.6", "conventional-changelog-cli": "~1.3.5", "cz-conventional-changelog": "~2.1.0", + "glob": "^7.1.2", "husky": "^1.0.0-rc.4", "jest": "~23.1.0", "lerna": "2.9.0", "prettier": "~1.10.2", + "semver": "^5.5.0", "ts-jest": "~22.0.4", "tslint": "~5.9.1", "typescript": "2.7.2" diff --git a/scripts/tasks/version-check.js b/scripts/tasks/version-check.js new file mode 100644 index 0000000000..934cbeb18d --- /dev/null +++ b/scripts/tasks/version-check.js @@ -0,0 +1,40 @@ +'use strict'; + +const path = require('path'); +const glob = require('glob'); +const semver = require('semver'); + +const PACKAGES_DIR = path.resolve(__dirname, '../../packages'); +const PACKAGES = glob.sync('*/package.json', { + absolute: true, + cwd: PACKAGES_DIR, +}); + +let areVersionsInSync = true; +for (const location of PACKAGES) { + const { + name, + peerDependencies = {}, + devDependencies = {}, + } = require(location); + + for (const dep of Object.keys(peerDependencies)) { + if ( + devDependencies.hasOwnProperty(dep) && + !semver.satisfies(devDependencies[dep], peerDependencies[dep]) + ) { + const error = [ + `Peer and dev versions of ${dep} in ${name} are out of sync.`, + `(Expected: ${peerDependencies[dep]}, Actual: ${devDependencies[dep]})`, + `Please update the peer dependency version.`, + ].join(' '); + + console.error(error); + areVersionsInSync = false; + } + } +} + +if (!areVersionsInSync) { + process.exit(1); +}