nix: Reset node_modules when Yarn deps change
Signed-off-by: Pedro Pombeiro <pombeirp@users.noreply.github.com>
This commit is contained in:
parent
44bc306823
commit
bdc0ba2680
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue