Skip to content

Warn instead of raising on missing manifest.js #546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,43 @@ jobs:
include:
- ruby: 2.5
gemfile: "gemfiles/Gemfile.rails-6.1-sprockets-3"
bundler: "2.3.0"
- ruby: 2.5
gemfile: "gemfiles/Gemfile.rails-6.1-sprockets-4"

bundler: "2.3.0"
- ruby: 2.7
gemfile: "gemfiles/Gemfile.rails-7.0-sprockets-3"
bundler: "2.4.8"
- ruby: 2.7
gemfile: "gemfiles/Gemfile.rails-7.0-sprockets-4"

bundler: "2.4.8"
- ruby: 2.7
gemfile: "gemfiles/Gemfile.rails-7.1-sprockets-3"
bundler: "2.4.8"
- ruby: 2.7
gemfile: "gemfiles/Gemfile.rails-7.1-sprockets-4"

bundler: "2.4.8"
- ruby: 3.1
gemfile: "gemfiles/Gemfile.rails-7.2-sprockets-3"
bundler: default
- ruby: 3.1
gemfile: "gemfiles/Gemfile.rails-7.2-sprockets-4"

bundler: default
- ruby: 3.2
gemfile: "gemfiles/Gemfile.rails-8.0-sprockets-3"
bundler: default
- ruby: 3.2
gemfile: "gemfiles/Gemfile.rails-8.0-sprockets-4"

bundler: default
- ruby: 3.2
gemfile: Gemfile
bundler: default
- ruby: 3.3
gemfile: Gemfile
bundler: default
- ruby: head
gemfile: Gemfile
bundler: default

env:
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
Expand All @@ -49,6 +57,8 @@ jobs:
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
cache-version: ${{ matrix.ruby }}-${{ matrix.ruby }}-${{ matrix.gemfile }}
bundler: ${{ matrix.bundler }}
- name: Run tests
run: bundle exec rake
continue-on-error: ${{ matrix.gemfile == 'Gemfile' }}
2 changes: 2 additions & 0 deletions gemfiles/Gemfile.rails-6.1-sprockets-3
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ gemspec path: '..'
gem 'actionpack', '~> 6.1.0'
gem 'railties', '~> 6.1.0'
gem 'sprockets', '~> 3.0'

gem 'concurrent-ruby', '< 1.3.5'
2 changes: 2 additions & 0 deletions gemfiles/Gemfile.rails-6.1-sprockets-4
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ gemspec path: '..'
gem 'actionpack', '~> 6.1.0'
gem 'railties', '~> 6.1.0'
gem 'sprockets', '~> 4.0'

gem 'concurrent-ruby', '< 1.3.5'
2 changes: 2 additions & 0 deletions gemfiles/Gemfile.rails-7.0-sprockets-3
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ gemspec path: '..'
gem 'actionpack', '~> 7.0.0'
gem 'railties', '~> 7.0.0'
gem 'sprockets', '~> 3.0'

gem 'concurrent-ruby', '< 1.3.5'
2 changes: 2 additions & 0 deletions gemfiles/Gemfile.rails-7.0-sprockets-4
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ gemspec path: '..'
gem 'actionpack', '~> 7.0.0'
gem 'railties', '~> 7.0.0'
gem 'sprockets', '~> 4.0'

gem 'concurrent-ruby', '< 1.3.5'
31 changes: 14 additions & 17 deletions lib/sprockets/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,6 @@ module Sprockets
class Railtie < ::Rails::Railtie
include Sprockets::Rails::Utils

class ManifestNeededError < StandardError
def initialize
msg = "Expected to find a manifest file in `app/assets/config/manifest.js`\n" +
"But did not, please create this file and use it to link any assets that need\n" +
"to be rendered by your app:\n\n" +
"Example:\n" +
" //= link_tree ../images\n" +
" //= link_directory ../javascripts .js\n" +
" //= link_directory ../stylesheets .css\n" +
"and restart your server\n\n" +
"For more information see: https://github.com/rails/sprockets/blob/070fc01947c111d35bb4c836e9bb71962a8e0595/UPGRADING.md#manifestjs"
super msg
end
end

LOOSE_APP_ASSETS = lambda do |logical_path, filename|
filename.start_with?(::Rails.root.join("app/assets").to_s) &&
!['.js', '.css', ''].include?(File.extname(logical_path))
Expand Down Expand Up @@ -103,8 +88,20 @@ def configure(&block)

initializer :set_default_precompile do |app|
if using_sprockets4?
raise ManifestNeededError unless ::Rails.root.join("app/assets/config/manifest.js").exist?
app.config.assets.precompile += %w( manifest.js )
if ::Rails.root.join("app/assets/config/manifest.js").exist?
app.config.assets.precompile += %w( manifest.js )
else
msg = "Expected to find a manifest file in `app/assets/config/manifest.js`\n" +
"But did not, please create this file and use it to link any assets that need\n" +
"to be rendered by your app:\n\n" +
"Example:\n" +
" //= link_tree ../images\n" +
" //= link_directory ../javascripts .js\n" +
" //= link_directory ../stylesheets .css\n" +
"and restart your server\n\n" +
"For more information see: https://github.com/rails/sprockets/blob/070fc01947c111d35bb4c836e9bb71962a8e0595/UPGRADING.md#manifestjs"
Sprockets::Rails.deprecator.warn msg
end
else
app.config.assets.precompile += [LOOSE_APP_ASSETS, /(?:\/|\\|\A)application\.(css|js)$/]
end
Expand Down
Loading