diff --git a/buildpack/buildpacks/node/bin/common.sh b/buildpack/buildpacks/node/bin/common.sh index 49b790a5..689f66f4 100644 --- a/buildpack/buildpacks/node/bin/common.sh +++ b/buildpack/buildpacks/node/bin/common.sh @@ -28,3 +28,11 @@ indent() { cat_npm_debug_log() { test -f $build_dir/npm-debug.log && cat $build_dir/npm-debug.log } + +cp_keep_links() { + if [ "$(uname)" == "Darwin" ]; then + cp -p "$@" + else + cp --preserve=links "$@" + fi +} diff --git a/buildpack/buildpacks/node/bin/compile b/buildpack/buildpacks/node/bin/compile index 9b40dcc3..a364caba 100755 --- a/buildpack/buildpacks/node/bin/compile +++ b/buildpack/buildpacks/node/bin/compile @@ -32,7 +32,7 @@ if test -d $build_dir/node_modules; then npm rebuild 2>&1 | indent elif test -d $cache_dir/node/node_modules; then status "Restoring node_modules directory from cache" - cp -r $cache_dir/node/node_modules $build_dir/ + cp_keep_links -R $cache_dir/node/node_modules $build_dir/ status "Pruning cached dependencies not specified in package.json" npm prune 2>&1 | indent @@ -70,7 +70,7 @@ 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 + cp_keep_links -R $build_dir/node_modules $cache_dir/node fi # Copy goodies to the cache