Skip to content

Commit 3a7f348

Browse files
committed
Relax Font-Awesome dependency to allow Webpacker users to stay on 5.x
Closes #3565
1 parent 0158c81 commit 3a7f348

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

lib/generators/rails_admin/install_generator.rb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def configure_for_webpacker5
6464
run "yarn add rails_admin@#{RailsAdmin::Version.js}"
6565
template 'rails_admin.webpacker.js', 'app/javascript/packs/rails_admin.js'
6666
template 'rails_admin.scss.erb', 'app/javascript/stylesheets/rails_admin.scss'
67+
# To work around https://github.com/railsadminteam/rails_admin/issues/3565
68+
add_package_json_field('resolutions', {'rails_admin/@fortawesome/fontawesome-free' => '^5.15.0'})
6769
end
6870

6971
def configure_for_webpack
@@ -99,28 +101,29 @@ def setup_css(additional_script_entries = {})
99101
else
100102
add_file 'config/initializers/assets.rb', asset_config
101103
end
102-
add_scripts(additional_script_entries.merge({'build:css' => 'sass ./app/assets/stylesheets/rails_admin.scss:./app/assets/builds/rails_admin.css --no-source-map --load-path=node_modules'}))
104+
add_package_json_field('scripts', additional_script_entries.merge({'build:css' => 'sass ./app/assets/stylesheets/rails_admin.scss:./app/assets/builds/rails_admin.css --no-source-map --load-path=node_modules'}), <<~INSTRUCTION)
105+
Taking 'build:css' as an example, if you're already have application.sass.css for the sass build, the resulting script would look like:
106+
sass ./app/assets/stylesheets/application.sass.scss:./app/assets/builds/application.css ./app/assets/stylesheets/rails_admin.scss:./app/assets/builds/rails_admin.css --no-source-map --load-path=node_modules
107+
INSTRUCTION
103108
end
104109

105-
def add_scripts(entries)
106-
display 'Add scripts to package.json'
110+
def add_package_json_field(name, entries, instruction = nil)
111+
display "Add #{name} to package.json"
107112
package = begin
108113
JSON.parse(File.read(File.join(destination_root, 'package.json')))
109114
rescue Errno::ENOENT, JSON::ParserError
110115
{}
111116
end
112-
if package['scripts'] && (package['scripts'].keys & entries.keys).any?
113-
say <<-MESSAGE.gsub(/^ {10}/, ''), :red
114-
You need to merge "scripts": #{JSON.pretty_generate(entries)} into the existing scripts in your package.json .
115-
Taking 'build:css' as an example, if you're already have application.sass.css for the sass build, the resulting script would look like:
116-
sass ./app/assets/stylesheets/application.sass.scss:./app/assets/builds/application.css ./app/assets/stylesheets/rails_admin.scss:./app/assets/builds/rails_admin.css --no-source-map --load-path=node_modules
117+
if package[name] && (package[name].keys & entries.keys).any?
118+
say <<~MESSAGE, :red
119+
You need to merge "#{name}": #{JSON.pretty_generate(entries)} into the existing #{name} in your package.json.#{instruction && "\n#{instruction}"}
117120
MESSAGE
118121
else
119-
package['scripts'] ||= {}
120-
entries.each do |entry, build_script|
121-
package['scripts'][entry] = build_script
122+
package[name] ||= {}
123+
entries.each do |entry, value|
124+
package[name][entry] = value
122125
end
123-
add_file 'package.json', JSON.pretty_generate(package)
126+
add_file 'package.json', "#{JSON.pretty_generate(package)}\n"
124127
end
125128
end
126129
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
import "rails_admin/src/rails_admin/base";
2-
import "../stylesheets/rails_admin.scss";
2+
import "../stylesheets/rails_admin.scss";

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"dependencies": {
1717
"@babel/runtime": "^7.16.7",
18-
"@fortawesome/fontawesome-free": "^6.1.1",
18+
"@fortawesome/fontawesome-free": ">=5.15.0 <7.0.0",
1919
"@hotwired/turbo-rails": "^7.1.0",
2020
"@popperjs/core": "^2.11.0",
2121
"@rails/ujs": "^6.1.4-1",

0 commit comments

Comments
 (0)