Skip to content

Commit

Permalink
Merge pull request #195 from fabiormoura/manifest_path_configuration
Browse files Browse the repository at this point in the history
Add support to override manifest_path as a configuration
  • Loading branch information
rafaelfranca authored Sep 4, 2024
2 parents e7b4c17 + be1deec commit f06b3f9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
11 changes: 3 additions & 8 deletions lib/propshaft/assembly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
10 changes: 5 additions & 5 deletions lib/propshaft/processor.rb
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/propshaft/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions test/propshaft/assembly_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
})

Expand All @@ -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"
})

Expand All @@ -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"
})

Expand Down
5 changes: 3 additions & 2 deletions test/propshaft/processor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f06b3f9

Please sign in to comment.