Skip to content

Commit 61501e1

Browse files
committed
fix(update-aws-cdk): Keep peerDependencies in sync with devDependencies
As I understand it: - `devDependencies` are what's used when developing a library - `peerDependencies` are requirements for consumers of the library This change ensures the two are kept in sync to make things easier to reason about.
1 parent e52c956 commit 61501e1

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

script/update-aws-cdk

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,34 @@ set -e
88
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
99
ROOT_DIR=$DIR/..
1010

11-
updateAwsCdk() {
11+
updateDependency() {
12+
DEPENDENCY_NAME=$1
13+
14+
echo "Updating $DEPENDENCY_NAME (if available)"
15+
1216
# `npx` to avoid a devDependency (and the Dependabot PRs)
1317
# See https://www.npmjs.com/package/npm-check-updates
14-
npx npm-check-updates@16.3.25 "aws-cdk-lib" "aws-cdk" "constructs" --upgrade --deep --target minor
18+
npx npm-check-updates "$DEPENDENCY_NAME" --upgrade --deep --target minor
19+
20+
# Synchronise the version within peerDependencies in package.json
21+
FILE=package.json
22+
TMP_FILE=package.json.tmp
23+
24+
NEW_VERSION=$(jq -r ".devDependencies.\"${DEPENDENCY_NAME}\"" < "$ROOT_DIR/$FILE")
25+
26+
# Peer dependencies describe the version clients need.
27+
# The ^ allows them to use a matching or higher minor/patch version.
28+
# The means clients can use Dependabot.
29+
NEW_PEER_VERSION="^${NEW_VERSION}"
30+
31+
# As jq doesn't support in-place editing, write to a temp file and move it back.
32+
jq ".peerDependencies.\"${DEPENDENCY_NAME}\" |= \"${NEW_PEER_VERSION}\"" $FILE > $TMP_FILE && mv $TMP_FILE $FILE
33+
}
34+
35+
updateAwsCdk() {
36+
updateDependency aws-cdk
37+
updateDependency aws-cdk-lib
38+
updateDependency constructs
1539

1640
# Deliberately NOT `npm ci` as we're going to raise a PR with the resulting changes to package-lock.json
1741
# --ignore-scripts for speed

0 commit comments

Comments
 (0)