From f4e7ee29e24ca9712675f49076474dc1f2241fc3 Mon Sep 17 00:00:00 2001 From: Josh W Lewis Date: Wed, 16 Feb 2022 11:33:32 -0600 Subject: [PATCH] Fix additional occurrence of yarn cache nesting (#987) * Fix additional occurrence of yarn cache nesting * Delete any nested caches * Add changelog note about cache restoration * Fix comment typo --- CHANGELOG.md | 1 + lib/cache.sh | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d73b7ffc6..0d425e68c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## main +- Fix issue with nested yarn cache during cache restoration ([987](https://github.com/heroku/heroku-buildpack-nodejs/pull/987) - Fix issue with nested yarn caches and cache growth ([#985](https://github.com/heroku/heroku-buildpack-nodejs/pull/985)) ## v191 (2022-02-14) diff --git a/lib/cache.sh b/lib/cache.sh index 1b100f3ad..d2f0d4fbb 100644 --- a/lib/cache.sh +++ b/lib/cache.sh @@ -53,7 +53,15 @@ restore_default_cache_directories() { if has_yarn_cache "$build_dir"; then echo "- yarn cache is checked into source control and cannot be cached" elif [[ -e "$cache_dir/node/cache/yarn" ]]; then + rm -rf "$yarn_cache_dir" mv "$cache_dir/node/cache/yarn" "$yarn_cache_dir" + if [[ -d "$yarn_cache_dir/yarn" ]]; then + # Older versions of the buildpack may have created nested yarn caches. + # This will remove the nested cache. This correction may be removed in + # the near future. + meta_set "yarn_nested_cache" "true" + rm -rf "$yarn_cache_dir/yarn" + fi echo "- yarn cache" else echo "- yarn cache (not cached - skipping)"