Skip to content

Commit 27a7557

Browse files
committed
Warn instead of raising on missing manifest.js
With a pristine (`rails new`) Rails 8.0 app, the `app/assets/config/manifest.js` file is no longer automatically generated. For engines still using sprockets, that is not a huge issue, because they have and add their own manifest files for their assets to the list of precompiled assets. However, scripts like the Solidus bin/sandbox script[1] first run `rails new`, then add the needed engines to the sandbox's `Gemfile`, then run `rails db:migrate` and their respective install generators. With Rails 8, these scripts now fail before anything is possible in Ruby, because the initializer of `Sprockets::Railtie` will raise an error on startup. This commit changes the behavior of the Railtie to issue a deprecation warning instead of raising an Exception. [1] https://github.com/solidusio/solidus/blob/main/bin/sandbox#L44-L99
1 parent 266ec49 commit 27a7557

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

lib/sprockets/railtie.rb

+14-17
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,6 @@ module Sprockets
6060
class Railtie < ::Rails::Railtie
6161
include Sprockets::Rails::Utils
6262

63-
class ManifestNeededError < StandardError
64-
def initialize
65-
msg = "Expected to find a manifest file in `app/assets/config/manifest.js`\n" +
66-
"But did not, please create this file and use it to link any assets that need\n" +
67-
"to be rendered by your app:\n\n" +
68-
"Example:\n" +
69-
" //= link_tree ../images\n" +
70-
" //= link_directory ../javascripts .js\n" +
71-
" //= link_directory ../stylesheets .css\n" +
72-
"and restart your server\n\n" +
73-
"For more information see: https://github.com/rails/sprockets/blob/070fc01947c111d35bb4c836e9bb71962a8e0595/UPGRADING.md#manifestjs"
74-
super msg
75-
end
76-
end
77-
7863
LOOSE_APP_ASSETS = lambda do |logical_path, filename|
7964
filename.start_with?(::Rails.root.join("app/assets").to_s) &&
8065
!['.js', '.css', ''].include?(File.extname(logical_path))
@@ -103,8 +88,20 @@ def configure(&block)
10388

10489
initializer :set_default_precompile do |app|
10590
if using_sprockets4?
106-
raise ManifestNeededError unless ::Rails.root.join("app/assets/config/manifest.js").exist?
107-
app.config.assets.precompile += %w( manifest.js )
91+
if ::Rails.root.join("app/assets/config/manifest.js").exist?
92+
app.config.assets.precompile += %w( manifest.js )
93+
else
94+
msg = "Expected to find a manifest file in `app/assets/config/manifest.js`\n" +
95+
"But did not, please create this file and use it to link any assets that need\n" +
96+
"to be rendered by your app:\n\n" +
97+
"Example:\n" +
98+
" //= link_tree ../images\n" +
99+
" //= link_directory ../javascripts .js\n" +
100+
" //= link_directory ../stylesheets .css\n" +
101+
"and restart your server\n\n" +
102+
"For more information see: https://github.com/rails/sprockets/blob/070fc01947c111d35bb4c836e9bb71962a8e0595/UPGRADING.md#manifestjs"
103+
Sprockets::Rails.deprecator.warn msg
104+
end
108105
else
109106
app.config.assets.precompile += [LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/]
110107
end

0 commit comments

Comments
 (0)