Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: fix-peers and --skip-tests #1155

Merged
merged 1 commit into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be called "--no-test" instead (to match "--no-bail").

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that's the same thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave --skip-test[s] if that's okay

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));
}
}