Skip to content

Commit

Permalink
build: fix-peers and --skip-tests (aws#1155)
Browse files Browse the repository at this point in the history
The fix-peer-deps script first needs to align existing peer-dependencies
to their new bumped version and only then can add new peer-dependencies.

Also, add support for "--skip-tests" in build.sh
  • Loading branch information
Elad Ben-Israel authored Nov 13, 2018
1 parent 0cb1adf commit 65821ac
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
14 changes: 10 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
set -euo pipefail

bail="--bail"
run_tests="true"
while [[ "${1:-}" != "" ]]; do
case $1 in
-h|--help)
echo "Usage: build.sh [--no-bail] [--force|-f]"
echo "Usage: build.sh [--no-bail] [--force|-f] [--skip-test]"
exit 1
;;
--no-bail)
Expand All @@ -14,6 +15,9 @@ while [[ "${1:-}" != "" ]]; do
-f|--force)
export CDK_BUILD="--force"
;;
--skip-test|--skip-tests)
run_tests="false"
;;
*)
echo "Unrecognized parameter: $1"
exit 1
Expand Down Expand Up @@ -47,8 +51,10 @@ echo "==========================================================================
echo "building..."
time lerna run $bail --stream build || fail

echo "============================================================================================="
echo "testing..."
lerna run $bail --stream test || fail
if $run_tests; then
echo "============================================================================================="
echo "testing..."
lerna run $bail --stream test || fail
fi

touch $BUILD_INDICATOR
15 changes: 14 additions & 1 deletion scripts/fix-peer-deps.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
#!/bin/bash
set -euo pipefail
lerna exec "$PWD/tools/cdk-build-tools/node_modules/.bin/jsii-fix-peers 2>/dev/null || true"

if [ ! -f lerna.json ]; then
echo "This script should be run from the root of the repo."
exit 1
fi

# first, we need to make sure that all existing peer dependencies are aligned to the "dependency" version
find . -name package.json | grep -v node_modules | xargs node scripts/sync-peer-deps.js

# must build first so .jsii is aligned
/bin/bash ./build.sh --skip-tests

# now, run jsii-fix-peers to add all missing peers based on the jsii spec
lerna exec "$PWD/tools/cdk-build-tools/node_modules/.bin/jsii-fix-peers 2>/dev/null || true"
25 changes: 25 additions & 0 deletions scripts/sync-peer-deps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// align versions of "peerDependencies" and "dependencies" for a given set of package.json files
// usage: node sync-peer-deps.js package.json pacakge.json ...
//
const fs = require('fs');

for (const file of process.argv.splice(2)) {
const pkg = JSON.parse(fs.readFileSync(file).toString());
const deps = pkg.dependencies || { };
let updated = false;
if (pkg.peerDependencies) {
for (const dep of Object.keys(pkg.peerDependencies)) {
const version = deps[dep];
const peerVersion = pkg.peerDependencies[dep];
if (version && version !== peerVersion) {
pkg.peerDependencies[dep] = version;
updated = true;
}
}
}
if (updated) {
console.log('updated:', file);
fs.writeFileSync(file, JSON.stringify(pkg, undefined, 2));
}
}

0 comments on commit 65821ac

Please sign in to comment.