diff --git a/lib/propshaft/assembly.rb b/lib/propshaft/assembly.rb index 2deebfa..b3fa22a 100644 --- a/lib/propshaft/assembly.rb +++ b/lib/propshaft/assembly.rb @@ -19,8 +19,8 @@ def load_path end def resolver - @resolver ||= if manifest_path.exist? - Propshaft::Resolver::Static.new manifest_path: manifest_path, prefix: config.prefix + @resolver ||= if config.manifest_path.exist? + Propshaft::Resolver::Static.new manifest_path: config.manifest_path, prefix: config.prefix else Propshaft::Resolver::Dynamic.new load_path: load_path, prefix: config.prefix end @@ -32,7 +32,7 @@ def server def processor Propshaft::Processor.new \ - load_path: load_path, output_path: config.output_path, compilers: compilers + load_path: load_path, output_path: config.output_path, compilers: compilers, manifest_path: config.manifest_path.manifest_path end def compilers @@ -51,9 +51,4 @@ def reveal(path_type = :logical_path) asset.send(path_type) end end - - private - def manifest_path - config.output_path.join(Propshaft::Processor::MANIFEST_FILENAME) - end end diff --git a/lib/propshaft/processor.rb b/lib/propshaft/processor.rb index c4f8560..23d981b 100644 --- a/lib/propshaft/processor.rb +++ b/lib/propshaft/processor.rb @@ -1,12 +1,11 @@ require "propshaft/output_path" class Propshaft::Processor - MANIFEST_FILENAME = ".manifest.json" + attr_reader :load_path, :output_path, :compilers, :manifest_path - attr_reader :load_path, :output_path, :compilers - - def initialize(load_path:, output_path:, compilers:) + def initialize(load_path:, output_path:, compilers:, manifest_path:) @load_path, @output_path = load_path, output_path + @manifest_path = manifest_path @compilers = compilers end @@ -31,7 +30,8 @@ def ensure_output_path_exists def write_manifest - File.open(output_path.join(MANIFEST_FILENAME), "wb+") do |manifest| + FileUtils.mkdir_p(File.dirname(manifest_path)) + File.open(manifest_path, "wb+") do |manifest| manifest.write load_path.manifest.to_json end end diff --git a/lib/propshaft/railtie.rb b/lib/propshaft/railtie.rb index 63433d8..8d53bfd 100644 --- a/lib/propshaft/railtie.rb +++ b/lib/propshaft/railtie.rb @@ -34,6 +34,7 @@ class Railtie < ::Rails::Railtie config.assets.relative_url_root ||= app.config.relative_url_root config.assets.output_path ||= Pathname.new(File.join(app.config.paths["public"].first, app.config.assets.prefix)) + config.assets.manifest_path ||= config.assets.output_path.join(".manifest.json") app.assets = Propshaft::Assembly.new(app.config.assets) diff --git a/test/propshaft/assembly_test.rb b/test/propshaft/assembly_test.rb index 732eada..418feee 100644 --- a/test/propshaft/assembly_test.rb +++ b/test/propshaft/assembly_test.rb @@ -6,6 +6,7 @@ class Propshaft::AssemblyTest < ActiveSupport::TestCase test "uses static resolver when manifest is present" do assembly = Propshaft::Assembly.new(ActiveSupport::OrderedOptions.new.tap { |config| config.output_path = Pathname.new("#{__dir__}/../fixtures/output") + config.manifest_path = config.output_path.join(".manifest.json") config.prefix = "/assets" }) @@ -15,6 +16,7 @@ class Propshaft::AssemblyTest < ActiveSupport::TestCase test "uses dynamic resolver when manifest is missing" do assembly = Propshaft::Assembly.new(ActiveSupport::OrderedOptions.new.tap { |config| config.output_path = Pathname.new("#{__dir__}/../fixtures/assets") + config.manifest_path = config.output_path.join(".manifest.json") config.prefix = "/assets" }) @@ -24,6 +26,7 @@ class Propshaft::AssemblyTest < ActiveSupport::TestCase test "costly methods are memoized" do assembly = Propshaft::Assembly.new(ActiveSupport::OrderedOptions.new.tap { |config| config.output_path = Pathname.new("#{__dir__}/../fixtures/assets") + config.manifest_path = config.output_path.join(".manifest.json") config.prefix = "/assets" }) diff --git a/test/propshaft/processor_test.rb b/test/propshaft/processor_test.rb index d1c5985..12bd802 100644 --- a/test/propshaft/processor_test.rb +++ b/test/propshaft/processor_test.rb @@ -42,9 +42,10 @@ class Propshaft::ProcessorTest < ActiveSupport::TestCase private def processed Dir.mktmpdir do |output_path| + output_path = Pathname.new(output_path) processor = Propshaft::Processor.new( - load_path: @assembly.load_path, output_path: Pathname.new(output_path), - compilers: @assembly.compilers + load_path: @assembly.load_path, output_path: output_path, + compilers: @assembly.compilers, manifest_path: output_path.join(".manifest.json") ) processor.process