From e7e857ac763dd053a8bda4b27d26a2090269f6d8 Mon Sep 17 00:00:00 2001 From: Paul Keen <125715+pftg@users.noreply.github.com> Date: Sun, 28 Aug 2022 15:32:31 +0200 Subject: [PATCH] fix: prevent yarn 2+ error in `assets:precompile` (#241) Yarn's migration guide mentions that selecting which dependencies are installed (dev or prod) requires the workspace-tools plugin. It's now the user's responsibility to ensure any build dependencies are available when vite build is run. --- vite_ruby/lib/tasks/vite.rake | 5 ++++- vite_ruby/lib/vite_ruby/commands.rb | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/vite_ruby/lib/tasks/vite.rake b/vite_ruby/lib/tasks/vite.rake index aedc3e9c..73921968 100644 --- a/vite_ruby/lib/tasks/vite.rake +++ b/vite_ruby/lib/tasks/vite.rake @@ -86,5 +86,8 @@ if ARGV.include?('assets:precompile') else ENV['NPM_CONFIG_INCLUDE'] = 'dev' end - ENV['YARN_PRODUCTION'] = 'false' + + unless ViteRuby.commands.next_yarn? + ENV['YARN_PRODUCTION'] = 'false' + end end diff --git a/vite_ruby/lib/vite_ruby/commands.rb b/vite_ruby/lib/vite_ruby/commands.rb index 0674cd52..c96297d8 100644 --- a/vite_ruby/lib/vite_ruby/commands.rb +++ b/vite_ruby/lib/vite_ruby/commands.rb @@ -71,6 +71,10 @@ def legacy_npm_version? `npm --version`.to_i < 7 rescue false end + def next_yarn? + `yarn --version`.to_i >= 2 rescue false + end + # Internal: Verifies if ViteRuby is properly installed. def verify_install unless File.exist?(config.root.join('bin/vite'))