Skip to content

Commit

Permalink
build: Add validation script for peer dependencies versions (#522)
Browse files Browse the repository at this point in the history
## 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.

<img width="1107" alt="screen shot 2018-07-19 at 6 55 06 am" src="https://user-images.githubusercontent.com/2567083/42946895-ecbede6c-8b20-11e8-914d-d3a0f05eb4b1.png">

**🗒 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
  • Loading branch information
pmdartus authored Jul 19, 2018
1 parent 186ed43 commit 4049e9e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
40 changes: 40 additions & 0 deletions scripts/tasks/version-check.js
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 4049e9e

Please sign in to comment.