-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: Add validation script for peer dependencies versions (#522)
## 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
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |