Commit 6cb3786a authored by zeke's avatar zeke

cache node too

parent 29427c56
#!/usr/bin/env bash #!/usr/bin/env bash
build_dir=$1 build_dir=$1
cache_dir=$2 cache_basedir=$2
bp_dir=$(cd $(dirname $0); cd ..; pwd) bp_dir=$(cd $(dirname $0); cd ..; pwd)
stable_version="0.10.18" stable_version="0.10.18"
...@@ -51,10 +51,8 @@ else ...@@ -51,10 +51,8 @@ else
# Use the latest one. # Use the latest one.
node_version=$(echo "$satisfying_versions" | tail -n 1) node_version=$(echo "$satisfying_versions" | tail -n 1)
if test $node_version; then # Bail if no matching version was found
status "Downloading and installing node v$version" if ! test $node_version; then
download_and_install_node $node_version
else
error "node ${requested_version} not found among available versions on nodejs.org/dist" error "node ${requested_version} not found among available versions on nodejs.org/dist"
fi fi
fi fi
...@@ -63,35 +61,35 @@ fi ...@@ -63,35 +61,35 @@ fi
# Run subsequent node/npm commands from the build path # Run subsequent node/npm commands from the build path
cd $build_dir cd $build_dir
# Configure cache directories # Configure cache directory
package_checksum=$(cat $build_dir/package.json | md5sum | awk '{print $1}') package_checksum=$(cat $build_dir/package.json | md5sum | awk '{print $1}')
cache_store_dir="$cache_dir/node_modules/$node_version/$package_checksum" cache_dir="$cache_basedir/$node_version/$package_checksum"
cache_target_dir="$build_dir/node_modules"
# Restore node_modules from cache if resolved node version and # Restore from cache if node and package.json haven't changed
# package.json match the previous build if test -d $cache_dir; then
if test -d $cache_store_dir; then
status "package.json and node version unchanged since last build" status "package.json and node version unchanged since last build"
status "Restoring node_modules from cache" status "Restoring node v$node_version and node_modules from cache"
if test -d $cache_target_dir; then test -d $cache_dir/node_modules && cp -r $cache_dir/node_modules $build_dir/
cp -r $cache_store_dir/* $cache_target_dir/ cp -r $cache_dir/vendor/node $build_dir/vendor/
else
cp -r $cache_store_dir $cache_target_dir
fi
else else
# Install dependencies anew
if [ $stable_version != $node_version ]; then
status "Downloading and installing node v$version"
download_and_install_node $node_version
fi
status "Installing dependencies" status "Installing dependencies"
npm install --production | indent npm install --production | indent
status "Rebuilding dependencies" status "Rebuilding dependencies"
npm rebuild | indent npm rebuild | indent
fi
# Cache node_modules for future builds status "Caching node and node_modules for future builds"
if test -d $cache_target_dir; then rm -rf $cache_dir
status "Caching node_modules for future builds" mkdir -p $cache_dir
rm -rf $cache_store_dir mkdir -p $cache_dir/vendor
mkdir -p $(dirname $cache_store_dir) test -d $build_dir/node_modules && cp -r $build_dir/node_modules $cache_dir/
cp -r $cache_target_dir $cache_store_dir cp -r $build_dir/vendor/node $cache_dir/vendor/
fi fi
# Update the PATH # Update the PATH
......
...@@ -47,8 +47,8 @@ testProfileCreated() { ...@@ -47,8 +47,8 @@ testProfileCreated() {
testNodeModulesCached() { testNodeModulesCached() {
cache=$(mktmpdir) cache=$(mktmpdir)
compile "node-modules-caching" $cache compile "node-modules-caching" $cache
assertCaptured "Caching node_modules for future builds" assertCaptured "Caching node"
assertEquals "1" "$(ls -1 $cache/node_modules/0.10.18 | wc -l)" assertEquals "1" "$(ls -1 $cache/0.10.18 | wc -l)"
} }
# Pending # Pending
......
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