From bdc0ba26801f6092ed80719d4b0ed794cb9a9a2e Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro Date: Wed, 14 Aug 2019 15:54:06 +0200 Subject: [PATCH] nix: Reset node_modules when Yarn deps change Signed-off-by: Pedro Pombeiro --- nix/mobile/reset-node_modules.sh | 34 +++++++++++++++++++------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/nix/mobile/reset-node_modules.sh b/nix/mobile/reset-node_modules.sh index aee86deab5..d64691436e 100755 --- a/nix/mobile/reset-node_modules.sh +++ b/nix/mobile/reset-node_modules.sh @@ -22,25 +22,31 @@ deps="$1" nodeModulesDir="$STATUS_REACT_HOME/node_modules" needCopyModules=1 +sentinelFilePath="$nodeModulesDir/.copied~" # Check if node_modules exists and is valid if [ -d "$nodeModulesDir" ]; then - if [ -f "$nodeModulesDir/.copied~" ]; then - echo "Checking for modifications in node_modules..." - modifiedFiles=( $(find $nodeModulesDir -writable -type f -newer $nodeModulesDir/.copied~ \ - -not \( -path "$nodeModulesDir/react-native/third-party/*" -prune \ - -o -path "$nodeModulesDir/react-native/ReactAndroid/build/*" -prune \ - -o -path "$nodeModulesDir/*/android/build/*" -prune \ - -o -path "$nodeModulesDir/realm/src/*" -prune \ - -o -path './resources/icons/*' -prune \) -print) ) - if [ ${#modifiedFiles[@]} -eq 0 ]; then - needCopyModules=0 - echo "No modifications detected." + if [ -f "$sentinelFilePath" ]; then + existingPath="$(cat $sentinelFilePath)" + if [ "${existingPath}" != "${deps}" ]; then + echo "Yarn modules changed, copying over new version" else - echo "Modifications detected in ${#modifiedFiles[@]} files:\n${modifiedFiles[@]}" + echo "Checking for modifications in node_modules..." + modifiedFiles=( $(find $nodeModulesDir -writable -type f -newer $sentinelFilePath \ + -not \( -path "$nodeModulesDir/react-native/third-party/*" -prune \ + -o -path "$nodeModulesDir/react-native/ReactAndroid/build/*" -prune \ + -o -path "$nodeModulesDir/*/android/build/*" -prune \ + -o -path "$nodeModulesDir/realm/src/*" -prune \ + -o -path './resources/icons/*' -prune \) -print) ) + if [ ${#modifiedFiles[@]} -eq 0 ]; then + needCopyModules=0 + echo "No modifications detected." + else + echo "Modifications detected in ${#modifiedFiles[@]} files:\n${modifiedFiles[@]}" + fi fi fi - if [ $needCopyModules -eq 1 ]; then + if [ $needCopyModules -eq 1 ] && [ -d $nodeModulesDir ]; then chmod u+w -R $nodeModulesDir rm -rf $nodeModulesDir fi @@ -69,7 +75,7 @@ if [ ! -d "$nodeModulesDir" ]; then time cp -HRf --preserve=all ${deps}/node_modules/. "$nodeModulesDir.tmp" chmod -R u+w "$nodeModulesDir.tmp" mv -f "$nodeModulesDir.tmp" $nodeModulesDir - touch $nodeModulesDir/.copied~ + echo -n "${deps}" > $sentinelFilePath trap - ERR INT HUP echo "Done" fi