diff --git a/lib/generators/spotlight/assets/generator_common_utilities.rb b/lib/generators/spotlight/assets/generator_common_utilities.rb index 5793a39dc..6343ea279 100644 --- a/lib/generators/spotlight/assets/generator_common_utilities.rb +++ b/lib/generators/spotlight/assets/generator_common_utilities.rb @@ -4,17 +4,25 @@ module Spotlight module Assets # Utilities for the Spotlight assets generators module GeneratorCommonUtilities - # Some versions of the blacklight gem do not have a corresponding blacklight-frontend package on npm. + # Some versions of the blacklight/spotlight gem do not have a corresponding package on npm. # Assume we want the most recent version that is compatible with the major version of the gem. - def blacklight_yarn_version - versions = JSON.parse(`yarn info blacklight-frontend versions --json`)['data'] - exact_match = versions.find { |v| v == Blacklight::VERSION } + def package_yarn_version(package_name, requested_version) + versions = JSON.parse(`yarn info #{package_name} versions --json`)['data'] + exact_match = versions.find { |v| v == requested_version } return exact_match if exact_match - major_version = Gem::Version.new(Blacklight::VERSION).segments.first + major_version = Gem::Version.new(requested_version).segments.first "^#{major_version}" end + def blacklight_yarn_version + package_yarn_version('blacklight-frontend', Blacklight::VERSION) + end + + def spotlight_yarn_version + package_yarn_version('spotlight-frontend', Spotlight::VERSION) + end + # Support the gem version format e.g., `~> 5.3` for consistency. def bootstrap_yarn_version options[:'bootstrap-version'].match(/(\d+(\.\d+)*)/)[0] diff --git a/lib/generators/spotlight/assets/importmap_generator.rb b/lib/generators/spotlight/assets/importmap_generator.rb index 5da37dc9c..85e9d777f 100644 --- a/lib/generators/spotlight/assets/importmap_generator.rb +++ b/lib/generators/spotlight/assets/importmap_generator.rb @@ -67,7 +67,7 @@ def add_frontend # Otherwise, pick the version from npm that matches the Spotlight # gem version else - run "yarn add spotlight-frontend@#{Spotlight::VERSION}" + run "yarn add spotlight-frontend@#{spotlight_yarn_version}" end end diff --git a/lib/generators/spotlight/assets/propshaft_generator.rb b/lib/generators/spotlight/assets/propshaft_generator.rb index 611f46f8f..69f971748 100644 --- a/lib/generators/spotlight/assets/propshaft_generator.rb +++ b/lib/generators/spotlight/assets/propshaft_generator.rb @@ -63,7 +63,7 @@ def add_frontend # Otherwise, pick the version from npm that matches the Spotlight # gem version else - run "yarn add spotlight-frontend@#{Spotlight::VERSION}" + run "yarn add spotlight-frontend@#{spotlight_yarn_version}" end end