diff --git a/npm_and_yarn/lib/dependabot/npm_and_yarn/file_fetcher.rb b/npm_and_yarn/lib/dependabot/npm_and_yarn/file_fetcher.rb index 3539503ac4..d73c28c8e0 100644 --- a/npm_and_yarn/lib/dependabot/npm_and_yarn/file_fetcher.rb +++ b/npm_and_yarn/lib/dependabot/npm_and_yarn/file_fetcher.rb @@ -107,6 +107,7 @@ def yarn_files fetched_yarn_files << yarn_lock if yarn_lock fetched_yarn_files << yarnrc if yarnrc fetched_yarn_files << yarnrc_yml if yarnrc_yml + create_yarn_cache fetched_yarn_files end @@ -655,6 +656,19 @@ def parsed_lerna_json rescue JSON::ParserError raise Dependabot::DependencyFileNotParseable, T.must(lerna_json).path end + + sig { void } + def create_yarn_cache + if repo_contents_path.nil? + Dependabot.logger.info("Repository contents path is nil") + elsif Dir.exist?(T.must(repo_contents_path)) + Dir.chdir(T.must(repo_contents_path)) do + FileUtils.mkdir_p(".yarn/cache") + end + else + Dependabot.logger.info("Repository contents path does not exist") + end + end end end end diff --git a/npm_and_yarn/spec/dependabot/npm_and_yarn/file_fetcher_spec.rb b/npm_and_yarn/spec/dependabot/npm_and_yarn/file_fetcher_spec.rb index 05409f7977..ffeddf1814 100644 --- a/npm_and_yarn/spec/dependabot/npm_and_yarn/file_fetcher_spec.rb +++ b/npm_and_yarn/spec/dependabot/npm_and_yarn/file_fetcher_spec.rb @@ -90,6 +90,9 @@ File.join(repo_contents_path, ".pnp.cjs") ) ).to start_with("version https://git-lfs.github.com/spec/v1") + + # Ensure .yarn directory contains .cache directory + expect(Dir.exist?(File.join(repo_contents_path, ".yarn", "cache"))).to be true end end