Skip to content

Commit

Permalink
Speed up precommit (#6226)
Browse files Browse the repository at this point in the history
I measured which bits of precommit take so long:

![Screenshot 2024-07-08 at 11 04
17](https://github.com/software-mansion/react-native-reanimated/assets/40713406/12d4b237-a6a7-4666-a111-b1c2108196b4)

I decided to simply call it conditionally.
  • Loading branch information
tjzel authored Jul 8, 2024
1 parent a65fcb2 commit 4859c29
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@
REANIMATED_PATH=packages/react-native-reanimated

yarn lint-staged

cd $REANIMATED_PATH
yarn type:check:all
yarn find-unused-code:js
# This step can take several seconds, so we don't want to run it on irrelevant commits.
! git diff-index --name-only HEAD -- | grep "$REANIMATED_PATH/src/.*\.\(ts\|tsx\)$" >/dev/null
if [ $? -eq 1 ]; then
yarn type:check:all
yarn find-unused-code:js
fi

# This automatically builds Reanimated Babel plugin JavaScript files if their
# TypeScript counterparts were changed. It also adds the output file to the commit
# if the built file differs from currently committed one.
! git diff-index HEAD --name-only |\
grep -E '^plugin/' > /dev/null
! git diff-index HEAD --name-only |
grep -E '^plugin/' >/dev/null
if [ $? -eq 1 ]; then
yarn build:plugin
! git status -u |\
grep -E 'plugin/build/plugin\.js' > /dev/null
! git status -u |
grep -E 'plugin/build/plugin\.js' >/dev/null
if [ $? -eq 1 ]; then
git add plugin/build/plugin.js
echo "[Reanimated] Plugin files were automatically built and changes were spotted.\
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-reanimated/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"format:android": "find android/src/ -iname \"*.h\" -o -iname \"*.cpp\" | xargs clang-format -i",
"format:common": "find Common/ -iname \"*.h\" -o -iname \"*.cpp\" | xargs clang-format -i",
"format:docs": "cd docs && yarn format",
"find-unused-code:js": "yarn ts-prune --ignore \"index|.web.\" --error ",
"find-unused-code:js": "yarn ts-prune --ignore \"index|.web.\" --error",
"type:check:src": "yarn tsc --noEmit",
"type:check:plugin": "cd plugin && yarn type:check:src && cd ..",
"type:check:app": "./scripts/test-ts.sh ../../apps/common-app/src/App.tsx",
Expand Down

0 comments on commit 4859c29

Please sign in to comment.