@@ -15,44 +15,20 @@ if ! git show-ref --verify --quiet refs/remotes/origin/"$BASE_BRANCH"; then
1515 exit 1
1616fi
1717
18- echo " Detecting changed packages compared to $BASE_BRANCH ..."
18+ echo " Detecting changed packages and their dependents compared to $BASE_BRANCH ..."
1919
20- # Get changes from all relevant directories
21- CHANGED_PATHS=$( git diff --name-only origin/" $BASE_BRANCH " ...HEAD | grep -E ' ^(config|core|extensions/|integrations/|packages/)' | sort -u)
20+ # Use Yarn's built-in workspace dependency graph to find changed packages + all transitive dependents
21+ PUBLISH_PATHS=$( yarn workspaces list --since=origin/" $BASE_BRANCH " --recursive --no-private --json | node -e "
22+ const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim();
23+ if (!lines) process.exit(0);
24+ const paths = lines.split('\n').map(l => './' + JSON.parse(l).location);
25+ console.log(paths.join(' '));
26+ " )
2227
23- if [ -z " $CHANGED_PATHS " ]; then
28+ if [ -z " $PUBLISH_PATHS " ]; then
2429 echo " No changed packages detected."
2530 exit 0
2631fi
2732
28- # Process each changed path and format it for publishing
29- PUBLISH_PATHS=" "
30- while IFS= read -r path; do
31- case " $path " in
32- config/* |core/* )
33- # For config and core, include the first directory
34- dir=$( echo " $path " | cut -d ' /' -f 1)
35- if [[ ! " $PUBLISH_PATHS " =~ " ./$dir " ]]; then
36- PUBLISH_PATHS+=" ./$dir "
37- fi
38- ;;
39- extensions/* |integrations/* |packages/* )
40- # For extensions, integrations, and packages, include the full path up to the second level
41- dir=$( echo " $path " | cut -d ' /' -f 1-2)
42- if [[ ! " $PUBLISH_PATHS " =~ " ./$dir " ]]; then
43- PUBLISH_PATHS+=" ./$dir "
44- fi
45- ;;
46- esac
47- done <<< " $CHANGED_PATHS"
48-
49- # Remove trailing space
50- PUBLISH_PATHS=" ${PUBLISH_PATHS% } "
51-
52- if [ -n " $PUBLISH_PATHS " ]; then
53- echo " Publishing changed packages: $PUBLISH_PATHS "
54- yarn dlx pkg-pr-new publish --compact $PUBLISH_PATHS --packageManager yarn --template ' ./demo'
55- else
56- echo " No publishable packages found."
57- exit 0
58- fi
33+ echo " Publishing packages: $PUBLISH_PATHS "
34+ yarn dlx pkg-pr-new publish --compact $PUBLISH_PATHS --packageManager yarn --template ' ./demo'
0 commit comments