-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Resolve errors blocking usage in a mountable Rails engine #1694
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0b33594
Run binstubs based on Rails.root
kevindew abb8c87
Allow dependant tasks to run under a prefix
kevindew 00071d8
Explicitly require Rails::Engine
kevindew 5d374ca
Run yarn tasks within the Rails root directory
kevindew b8e414c
Update the gitignore within the rails root
kevindew f65be8f
Run webpacker:info in Rails.root
kevindew 8726813
Show a relative path when describing configuration missing
kevindew 32a7749
Basic tests for a mounted application
kevindew 46d3e6c
Merge branch 'master' into engine-tasks
gauravtiwari bfa84c5
Update railtie.rb
gauravtiwari cf3a17f
Update railtie.rb
gauravtiwari 6e9fa63
Update railtie.rb
gauravtiwari 8c2b477
Use additional_paths
gauravtiwari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/.bundle | ||
/pkg | ||
/test/mounted_app/test/dummy/log | ||
/test/test_app/log | ||
node_modules | ||
.byebug_history | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,9 @@ | |
copy_file "#{__dir__}/examples/coffee/hello_coffee.coffee", | ||
"#{Webpacker.config.source_entry_path}/hello_coffee.coffee" | ||
|
||
say "Installing all Coffeescript dependencies" | ||
run "yarn add [email protected] coffee-loader" | ||
Dir.chdir(Rails.root) do | ||
say "Installing all Coffeescript dependencies" | ||
run "yarn add [email protected] coffee-loader" | ||
end | ||
|
||
say "Webpacker now supports Coffeescript 🎉", :green |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
binstubs_template_path = File.expand_path("../../install/binstubs.rb", __dir__).freeze | ||
bin_path = ENV["BUNDLE_BIN"] || "./bin" | ||
bin_path = ENV["BUNDLE_BIN"] || Rails.root.join("bin") | ||
|
||
namespace :webpacker do | ||
desc "Installs Webpacker binstubs in this application" | ||
task binstubs: [:check_node, :check_yarn] do | ||
task binstubs: [:check_node, :check_yarn] do |task| | ||
prefix = task.name.split(/#|webpacker:binstubs/).first | ||
|
||
if Rails::VERSION::MAJOR >= 5 | ||
exec "#{RbConfig.ruby} #{bin_path}/rails app:template LOCATION=#{binstubs_template_path}" | ||
exec "#{RbConfig.ruby} #{bin_path}/rails #{prefix}app:template LOCATION=#{binstubs_template_path}" | ||
else | ||
exec "#{RbConfig.ruby} #{bin_path}/rake rails:template LOCATION=#{binstubs_template_path}" | ||
exec "#{RbConfig.ruby} #{bin_path}/rake #{prefix}rails:template LOCATION=#{binstubs_template_path}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
install_template_path = File.expand_path("../../install/template.rb", __dir__).freeze | ||
bin_path = ENV["BUNDLE_BIN"] || "./bin" | ||
bin_path = ENV["BUNDLE_BIN"] || Rails.root.join("bin") | ||
|
||
namespace :webpacker do | ||
desc "Install Webpacker in this application" | ||
task install: [:check_node, :check_yarn] do | ||
task install: [:check_node, :check_yarn] do |task| | ||
prefix = task.name.split(/#|webpacker:install/).first | ||
|
||
if Rails::VERSION::MAJOR >= 5 | ||
exec "#{RbConfig.ruby} #{bin_path}/rails app:template LOCATION=#{install_template_path}" | ||
exec "#{RbConfig.ruby} #{bin_path}/rails #{prefix}app:template LOCATION=#{install_template_path}" | ||
else | ||
exec "#{RbConfig.ruby} #{bin_path}/rake rails:template LOCATION=#{install_template_path}" | ||
exec "#{RbConfig.ruby} #{bin_path}/rake #{prefix}rails:template LOCATION=#{install_template_path}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require "test_helper" | ||
|
||
class EngineRakeTasksTest < Minitest::Test | ||
def setup | ||
remove_webpack_binstubs | ||
end | ||
|
||
def teardown | ||
remove_webpack_binstubs | ||
end | ||
|
||
def test_task_mounted | ||
output = Dir.chdir(mounted_app_path) { `rake -T` } | ||
assert_includes output, "app:webpacker" | ||
end | ||
|
||
def test_binstubs | ||
Dir.chdir(mounted_app_path) { `bundle exec rake app:webpacker:binstubs` } | ||
webpack_binstub_paths.each { |path| assert File.exist?(path) } | ||
end | ||
|
||
private | ||
def mounted_app_path | ||
File.expand_path("mounted_app", __dir__) | ||
end | ||
|
||
def webpack_binstub_paths | ||
[ | ||
"#{mounted_app_path}/test/dummy/bin/webpack", | ||
"#{mounted_app_path}/test/dummy/bin/webpack-dev-server", | ||
] | ||
end | ||
|
||
def remove_webpack_binstubs | ||
webpack_binstub_paths.each do |path| | ||
File.delete(path) if File.exist?(path) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require "bundler/setup" | ||
|
||
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__) | ||
load "rails/tasks/engine.rake" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require_relative "config/application" | ||
|
||
Rails.application.load_tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env ruby | ||
APP_PATH = File.expand_path("../config/application", __dir__) | ||
require "rails/commands" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env ruby | ||
require "rake" | ||
Rake.application.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# This file allows the `Rails.root` to be correctly determined. | ||
|
||
require_relative "config/environment" | ||
|
||
run Rails.application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require "action_controller/railtie" | ||
require "action_view/railtie" | ||
require "webpacker" | ||
|
||
module TestDummyApp | ||
class Application < Rails::Application | ||
config.secret_key_base = "abcdef" | ||
config.eager_load = true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require_relative "application" | ||
|
||
Rails.application.initialize! |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kevindew Do we need to do this? Is it not possible to use root package.json and yarn as a source of truth? But I see, what you mentioned in the description, in case someone wants to publish an engine package to npm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest it's preferable to do this as it keeps the installation consistent to the Rails root (this would be a piece in a different place) and also if you have just a single package.json for both the Rails engine itself and the dummy app then they need to share dependencies when this may not makes sense (e.g. you wouldn't want to have a dependency on webpacker for your distributed engine JS files).
A nice thing though is that if you don't have a package.json in your Rails root then this will just use the global one for your application. So this dir change only prefers a package.json in your mounted app and will fallback to the root one if it doesn't exist.