Site Name: air-dev
Since Netlify doesn’t seem to support node_modules caching for monorepos out of the box, we are trying to take the clever approach over at https://github.com/slawekkolodziej/netlify-lerna-caching-demo to make this work.
The approach is to save the sub-packages node_modules
in the root node_modules
after the build has completed so you can read from them on the next build (via preinstall
) and copy them into their respective packages.
However, we are running into a permission issue when we try to mv
the sub-package node_modules
to their respective packages. Why are permissions disabled for moving, copying, editing the node_modules
folder?
Here is our preinstall
script:
# https://github.com/slawekkolodziej/netlify-lerna-caching-demo
#!/bin/sh
NODE_MODULES_CACHE=node_modules
PACKAGES_CACHE="$NODE_MODULES_CACHE/packages-cache"
mkdir -p "$PACKAGES_CACHE"
restore_deps() {
PACKAGES=$(ls -1 $1)
for PKG in $PACKAGES
do
PKG_CACHE="$PACKAGES_CACHE/$PKG"
ls $PKG_NODE_MODULES
if [ -d $PKG_CACHE ];
then
mv $PKG_CACHE $1/$PKG/node_modules
echo "Restored node modules for $PKG"
else
echo "Unable to restore cache for $PKG"
fi
done
}
restore_deps packages