From 3ab11f2b1a45e948e90f2b5c01a72857a0c7ab04 Mon Sep 17 00:00:00 2001 From: scripthunter7 Date: Wed, 30 Aug 2023 13:44:17 +0200 Subject: [PATCH] Automatic synchronization of local packages if `package.json` or `yarn.lock` changes (#160386) * Update pre-commit * Create post-merge --- .husky/post-merge | 20 ++++++++++++++++++++ .husky/pre-commit | 2 ++ 2 files changed, 22 insertions(+) create mode 100644 .husky/post-merge diff --git a/.husky/post-merge b/.husky/post-merge new file mode 100644 index 00000000000..59d9c1feb96 --- /dev/null +++ b/.husky/post-merge @@ -0,0 +1,20 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +# See https://git-scm.com/docs/githooks#_post_merge + +# This function checks if a file has changed between the current HEAD and the previous HEAD +# Source: https://jshakespeare.com/use-git-hooks-and-husky-to-tell-your-teammates-when-to-run-npm-install +function changed { + # HEAD@{1} is the original position of HEAD before the merge + # HEAD is the new merge commit + # --name-only only shows the names of the changed files + # grep "^$1" only shows the files that match the first argument + git diff --name-only HEAD@{1} HEAD | grep "^$1" > /dev/null 2>&1 +} + +# If package.json or yarn.lock is changed, we should sync local dependencies +if changed "package.json" || changed "yarn.lock"; then + echo "package.json or yarn.lock changed, running yarn install to sync dependencies" + yarn install --force +fi diff --git a/.husky/pre-commit b/.husky/pre-commit index 99dec5d4553..414575091d1 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,6 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" +# See https://git-scm.com/docs/githooks#_pre_commit + yarn run lint