-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for relative url root (#138)
* Adds support for relative url root * Creates base compiler class to hold url prefix
- Loading branch information
1 parent
69c285f
commit 26082d0
Showing
13 changed files
with
119 additions
and
84 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
# Base compiler from which other compilers can inherit | ||
class Propshaft::Compiler | ||
attr_reader :assembly | ||
|
||
def initialize(assembly) | ||
@assembly = assembly | ||
end | ||
|
||
# Override this in a specific compiler | ||
def compile(logical_path, input) | ||
raise NotImplementedError | ||
end | ||
|
||
private | ||
def url_prefix | ||
@url_prefix ||= File.join(assembly.config.relative_url_root.to_s, assembly.config.prefix.to_s).chomp("/") | ||
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
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,66 @@ | ||
require "test_helper" | ||
require "minitest/mock" | ||
require "propshaft/asset" | ||
require "propshaft/assembly" | ||
require "propshaft/compilers" | ||
|
||
class Propshaft::Compiler::SourceMappingUrlsTest < ActiveSupport::TestCase | ||
setup do | ||
@options = ActiveSupport::OrderedOptions.new.tap { |config| | ||
config.paths = [ Pathname.new("#{__dir__}/../../fixtures/assets/mapped") ] | ||
config.output_path = Pathname.new("#{__dir__}/../../fixtures/output") | ||
config.prefix = "/assets" | ||
} | ||
end | ||
|
||
test "matching source map" do | ||
assert_match %r{//# sourceMappingURL=/assets/source.js-[a-z0-9]{40}\.map}, | ||
compile_asset(find_asset("source.js", fixture_path: "mapped")) | ||
assert_match %r{/\*# sourceMappingURL=/assets/source.css-[a-z0-9]{40}\.map}, | ||
compile_asset(find_asset("source.css", fixture_path: "mapped")) | ||
end | ||
|
||
test "matching nested source map" do | ||
assert_match %r{//# sourceMappingURL=/assets/nested/another-source.js-[a-z0-9]{40}\.map}, | ||
compile_asset(find_asset("nested/another-source.js", fixture_path: "mapped")) | ||
end | ||
|
||
test "missing source map" do | ||
assert_no_match %r{sourceMappingURL}, | ||
compile_asset(find_asset("sourceless.js", fixture_path: "mapped")) | ||
assert_no_match %r{sourceMappingURL}, | ||
compile_asset(find_asset("sourceless.css", fixture_path: "mapped")) | ||
end | ||
|
||
test "sourceMappingURL removal due to missing map does not damage /* ... */ comments" do | ||
assert_match %r{\A#{Regexp.escape ".failure { color: red; }\n/* */\n"}\Z}, | ||
compile_asset(find_asset("sourceless.css", fixture_path: "mapped")) | ||
end | ||
|
||
test "sourceMappingURL outside of a comment should be left alone" do | ||
assert_match %r{sourceMappingURL=sourceMappingURL-outside-comment.css.map}, | ||
compile_asset(find_asset("sourceMappingURL-outside-comment.css", fixture_path: "mapped")) | ||
end | ||
|
||
test "sourceMappingURL not at the beginning of the line should be left alone" do | ||
assert_match %r{sourceMappingURL=sourceMappingURL-not-at-start.css.map}, | ||
compile_asset(find_asset("sourceMappingURL-not-at-start.css", fixture_path: "mapped")) | ||
end | ||
|
||
test "relative url root" do | ||
@options.relative_url_root = "/url-root" | ||
|
||
assert_match %r{//# sourceMappingURL=/url-root/assets/source.js-[a-z0-9]{40}\.map}, | ||
compile_asset(find_asset("source.js", fixture_path: "mapped")) | ||
end | ||
|
||
private | ||
def compile_asset(asset) | ||
|
||
assembly = Propshaft::Assembly.new(@options) | ||
assembly.compilers.register "text/javascript", Propshaft::Compiler::SourceMappingUrls | ||
assembly.compilers.register "text/css", Propshaft::Compiler::SourceMappingUrls | ||
|
||
assembly.compilers.compile(asset) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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