···11#!/usr/bin/env bash
2233-result=$(pnpx turbo run build --affected --dry-run=json)
33+result=$(pnpx turbo run build --affected --dry-run=json 2>&1)
44+55+# turbo may emit warnings or other text before the JSON output. Extract the
66+# first JSON object/array found in the output so `jq` can parse it safely.
77+json=$(printf '%s\n' "$result" | awk '/^{/ {flag=1} flag {print}')
88+99+if [ -z "$json" ]; then
1010+ echo "Error: no JSON output from turbo; aborting." >&2
1111+ exit 1
1212+fi
41355-packages=$(echo "$result" | jq -r '.tasks[].directory' | grep '^packages/' | while read -r dir; do
1414+packages=$(echo "$json" | jq -r '.tasks[].directory' | grep '^packages/' | while read -r dir; do
615 if [ "$(jq -r '.private' "$dir/package.json")" != "true" ]; then
716 echo "./$dir"
817 fi