Skip to content

Commit

Permalink
Merge pull request #36803 from andrewkress/fix-issue-36799
Browse files Browse the repository at this point in the history
read webpacker config to populate autoload paths
  • Loading branch information
rafaelfranca committed Aug 15, 2019
1 parent 5eaf39b commit 5b327db
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
14 changes: 3 additions & 11 deletions railties/lib/rails/engine/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# frozen_string_literal: true

require "rails/railtie/configuration"
require "yaml"

module Rails
class Engine
class Configuration < ::Rails::Railtie::Configuration
attr_reader :root
attr_accessor :middleware
attr_accessor :middleware, :javascript_path
attr_writer :eager_load_paths, :autoload_once_paths, :autoload_paths

def initialize(root = nil)
super()
@root = root
@generators = app_generators.dup
@middleware = Rails::Configuration::MiddlewareStackProxy.new
@javascript_path = "javascript"
end

# Holds generators configuration:
Expand All @@ -41,7 +41,7 @@ def paths

paths.add "app", eager_load: true,
glob: "{*,*/concerns}",
exclude: ["assets", webpacker_path]
exclude: ["assets", javascript_path]
paths.add "app/assets", glob: "*"
paths.add "app/controllers", eager_load: true
paths.add "app/channels", eager_load: true, glob: "**/*_channel.rb"
Expand Down Expand Up @@ -86,14 +86,6 @@ def autoload_once_paths
def autoload_paths
@autoload_paths ||= paths.autoload_paths
end

def webpacker_path
if File.file?("#{Rails.root}/config/webpacker.yml")
YAML.load_file("#{Rails.root}/config/webpacker.yml")[Rails.env]["source_path"]&.gsub("app/", "")
else
"javascript"
end
end
end
end
end
14 changes: 13 additions & 1 deletion railties/test/application/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,19 @@ def index
app "development"
ActiveSupport::Dependencies.autoload_paths.each do |path|
assert_not_operator path, :ends_with?, "app/assets"
assert_not_operator path, :ends_with?, "app/#{Rails.configuration.webpacker_path}"
assert_not_operator path, :ends_with?, "app/javascript"
end
end

test "autoload paths will exclude the configured javascript_path" do
add_to_config "config.javascript_path = 'webpack'"
app_dir("app/webpack")

app "development"

ActiveSupport::Dependencies.autoload_paths.each do |path|
assert_not_operator path, :ends_with?, "app/assets"
assert_not_operator path, :ends_with?, "app/webpack"
end
end

Expand Down
1 change: 1 addition & 0 deletions railties/test/isolation/assets/config/webpacker.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
default: &default
source_path: app/javascript
check_yarn_integrity: false
development:
<<: *default
Expand Down

0 comments on commit 5b327db

Please sign in to comment.