Skip to content

Commit

Permalink
Use best guess for spotlight-frontend package
Browse files Browse the repository at this point in the history
  • Loading branch information
taylor-steve committed Oct 31, 2024
1 parent da8d0c1 commit d1d1808
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions lib/generators/spotlight/assets/generator_common_utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/spotlight/assets/importmap_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/generators/spotlight/assets/propshaft_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d1d1808

Please sign in to comment.