Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Add an option to skip caching node_modules #165

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions run-build-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ install_dependencies() {
local defaultYarnVersion=$3
local defaultPHPVersion=$4
local installGoVersion=$5
local cacheNodeModules=$6

# Python Version
if [ -f runtime.txt ]
Expand Down Expand Up @@ -187,7 +188,7 @@ install_dependencies() {
fi

if nvm install $NODE_VERSION
then
then
NODE_VERSION=$(nvm current)
# no echo needed because nvm does that for us
export NODE_VERSION=$NODE_VERSION
Expand Down Expand Up @@ -261,7 +262,7 @@ install_dependencies() {
exit 1
fi
fi

if ! gem list -i "^bundler$" > /dev/null 2>&1
then
if ! gem install bundler
Expand Down Expand Up @@ -330,7 +331,11 @@ install_dependencies() {

if [ -f package.json ]
then
restore_cwd_cache node_modules "node modules"
if [ "$cacheNodeModules" = true ]
then
restore_cwd_cache node_modules "node modules"
fi

if [ -f yarn.lock ]
then
run_yarn $YARN_VERSION
Expand Down Expand Up @@ -491,9 +496,15 @@ install_dependencies() {
# Take things installed during the build and cache them
#
cache_artifacts() {
local cacheNodeModules=$1

cache_cwd_directory ".bundle" "ruby gems"
cache_cwd_directory "bower_components" "bower components"
cache_cwd_directory "node_modules" "node modules"

if [ "$cacheNodeModules" = true ]
then
cache_cwd_directory "node_modules" "node modules"
fi

cache_home_directory ".yarn_cache" "yarn cache"
cache_home_directory ".cache" "pip cache"
Expand Down
5 changes: 3 additions & 2 deletions run-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ cd $NETLIFY_REPO_DIR
: ${YARN_VERSION="1.3.2"}
: ${PHP_VERSION="5.6"}
: ${GO_VERSION="1.10"}
: ${CACHE_NODE_MODULES=true}

echo "Installing dependencies: node=$NODE_VERSION ruby=$RUBY_VERSION yarn=$YARN_VERSION php=$PHP_VERSION go=$GO_VERSION"
install_dependencies $NODE_VERSION $RUBY_VERSION $YARN_VERSION $PHP_VERSION $GO_VERSION
install_dependencies $NODE_VERSION $RUBY_VERSION $YARN_VERSION $PHP_VERSION $GO_VERSION $CACHE_NODE_MODULES

echo "Installing missing commands"
install_missing_commands
Expand All @@ -49,6 +50,6 @@ $cmd
CODE=$?

echo "Caching artifacts"
cache_artifacts
cache_artifacts $CACHE_NODE_MODULES

exit $CODE
2 changes: 2 additions & 0 deletions test-tools/test-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set -e
: ${HUGO_VERSION="0.20"}
: ${PHP_VERSION="5.6"}
: ${GO_VERSION="1.10"}
: ${CACHE_NODE_MODULES=true}

REPO_URL=$1

Expand Down Expand Up @@ -57,6 +58,7 @@ docker run --rm \
-e "NETLIFY_VERBOSE=$NETLIFY_VERBOSE" \
-e "GO_VERSION=$GO_VERSION" \
-e "GO_IMPORT_PATH=$GO_IMPORT_PATH" \
-e "CACHE_NODE_MODULES=$CACHE_NODE_MODULES" \
-v $PWD/$T/scripts:/opt/buildhome/scripts \
-v $PWD/$T/repo:/opt/buildhome/repo \
-v $PWD/$T/cache:/opt/buildhome/cache \
Expand Down