Merge pull request #36803 from andrewkress/fix-issue-36799

read webpacker config to populate autoload paths
This commit is contained in:
Rafael França 2019-08-15 18:53:47 -04:00 committed by GitHub
commit 9ad68a4cf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 12 deletions

View File

@ -1,13 +1,12 @@
# 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)
@ -15,6 +14,7 @@ module Rails
@root = root
@generators = app_generators.dup
@middleware = Rails::Configuration::MiddlewareStackProxy.new
@javascript_path = "javascript"
end
# Holds generators configuration:
@ -41,7 +41,7 @@ module Rails
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"
@ -86,14 +86,6 @@ module Rails
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

View File

@ -1708,7 +1708,19 @@ module ApplicationTests
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

View File

@ -1,4 +1,5 @@
default: &default
source_path: app/javascript
check_yarn_integrity: false
development:
<<: *default