Commit 1e46a9b9 authored by zeke's avatar zeke

Cache everything one level deeper (inside $cache_dir/node) to avoid clobbering...

Cache everything one level deeper (inside $cache_dir/node) to avoid clobbering cached artifacts from other buildpacks.
Store node-version textfile in new .heroku directory, in the slug _and_ the cache.
parent 26c18bce
...@@ -61,12 +61,18 @@ if test -d $build_dir/node_modules; then ...@@ -61,12 +61,18 @@ if test -d $build_dir/node_modules; then
status "Found existing node_modules directory; skipping cache" status "Found existing node_modules directory; skipping cache"
status "Rebuilding any native dependencies" status "Rebuilding any native dependencies"
npm rebuild 2>&1 | indent npm rebuild 2>&1 | indent
elif test -d $cache_dir/node_modules; then elif test -d $cache_dir/node/node_modules; then
status "Restoring node_modules directory from cache" status "Restoring node_modules directory from cache"
cp -r $cache_dir/node_modules $build_dir/ cp -r $cache_dir/node/node_modules $build_dir/
status "Pruning cached dependencies not specified in package.json" status "Pruning cached dependencies not specified in package.json"
npm prune 2>&1 | indent npm prune 2>&1 | indent
if test -f $cache_dir/node/.heroku/node-version && [ $(cat $cache_dir/node/.heroku/node-version) != "$node_version" ]; then
status "Node version changed since last build; rebuilding dependencies"
npm rebuild 2>&1 | indent
fi
fi fi
# Scope config var availability only to `npm install` # Scope config var availability only to `npm install`
...@@ -81,10 +87,26 @@ fi ...@@ -81,10 +87,26 @@ fi
npm install --userconfig $build_dir/.npmrc --production 2>&1 | indent npm install --userconfig $build_dir/.npmrc --production 2>&1 | indent
) )
status "Caching node_modules directory for future builds" # Persist goodies like node-version in the slug
rm -rf $cache_dir/node_modules mkdir -p $build_dir/.heroku
mkdir -p $cache_dir
test -d $build_dir/node_modules && cp -r $build_dir/node_modules $cache_dir/ # Save resolved node version in the slug for later reference
echo $node_version > $build_dir/.heroku/node-version
# Purge node-related cached content, being careful not to purge the top-level
# cache, for the sake of heroku-buildpack-multi apps.
rm -rf $cache_dir/node_modules # (for apps still on the older caching strategy)
rm -rf $cache_dir/node
mkdir -p $cache_dir/node
# If app has a node_modules directory, cache it.
if test -d $build_dir/node_modules; then
status "Caching node_modules directory for future builds"
cp -r $build_dir/node_modules $cache_dir/node
fi
# Copy goodies to the cache
cp -r $build_dir/.heroku $cache_dir/node
status "Cleaning up node-gyp and npm artifacts" status "Cleaning up node-gyp and npm artifacts"
rm -rf "$build_dir/.node-gyp" rm -rf "$build_dir/.node-gyp"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment