Skip to content

Commit 70394fb

Browse files
Fail the build when a generated client dependency is not declared
The generated clients load their dependencies from our package.json, and the set they need changes with the Smithy codegen version. A codegen bump that adds a dependency would otherwise only break consumers at runtime. The build now checks every dependency of the generated package.json files is declared at the root, and prints the `yarn add` line to fix it. Issue: CLDSRVCLT-19
1 parent 9e857c3 commit 70394fb

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ yarn build
1515
```
1616

1717
The generated clients are shipped inside this package and load their dependencies from the root
18-
`package.json`, so any runtime dependency of a generated client must be declared there as well.
18+
`package.json`, so any runtime dependency of a generated client must be declared there as well
19+
(`yarn build` fails otherwise).
1920
`yarn check:package` packs the build and verifies it installs and loads in a clean consumer.
2021

2122
### Local testing

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
},
2828
"scripts": {
2929
"clean:build": "rm -rf build dist",
30-
"build:smithy": "smithy build && yarn clean:codegen-gitignore",
30+
"build:smithy": "smithy build && yarn clean:codegen-gitignore && yarn check:deps",
31+
"check:deps": "bash tests/packaging/check-deps.sh",
3132
"clean:codegen-gitignore": "rm -f build/smithy/*/typescript-codegen/.gitignore",
3233
"clean:codegen-node-modules": "rm -rf build/smithy/*/typescript-codegen/node_modules",
3334
"build:generated:backbeatRoutes": "cd build/smithy/cloudserverBackbeatRoutes/typescript-codegen && yarn install && yarn build",

‎tests/packaging/check-deps.sh‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
# The generated clients are shipped inside this package, so their runtime
3+
# dependencies must be declared in the root package.json too.
4+
set -euo pipefail
5+
6+
cd "$(dirname "$0")/../.."
7+
8+
generated=(build/smithy/*/typescript-codegen/package.json)
9+
10+
missing=$(comm -23 \
11+
<(jq -r '.dependencies // {} | keys[]' "${generated[@]}" | sort -u) \
12+
<(jq -r '.dependencies // {} | keys[]' package.json | sort -u))
13+
14+
if [ -n "$missing" ]; then
15+
echo "ERROR: dependencies of the generated clients missing from package.json, add them with:" >&2
16+
echo " yarn add $(for name in $missing; do
17+
jq -r --arg n "$name" '.dependencies[$n] // empty | "\($n)@\(.)"' "${generated[@]}" | head -1
18+
done | tr '\n' ' ')" >&2
19+
exit 1
20+
fi

0 commit comments

Comments
 (0)