-
Notifications
You must be signed in to change notification settings - Fork 792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Sourcemaps #515
Fix Sourcemaps #515
Changes from all commits
45f01e0
1d28403
870945b
11217f9
66c2bd7
e146451
ff5b6dd
033c6b6
30b5838
3a0c297
21fb47b
9d808a4
b4f2dfa
8ad78ba
25d1fa8
809ecc9
b238342
f2bbb41
1c8756a
3b13ef8
e59e64d
3e75ea2
b7f530b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ language: ruby | |
cache: bundler | ||
|
||
sudo: false | ||
|
||
before_script: "unset _JAVA_OPTIONS" | ||
rvm: | ||
- 2.2 | ||
- 2.3.4 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,10 +107,6 @@ module Sprockets | |
[SourceMapCommentProcessor] | ||
end | ||
|
||
require 'sprockets/preprocessors/default_source_map' | ||
register_preprocessor 'text/css', Preprocessors::DefaultSourceMap.new | ||
register_preprocessor 'application/javascript', Preprocessors::DefaultSourceMap.new | ||
|
||
require 'sprockets/directive_processor' | ||
register_preprocessor 'text/css', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]]) | ||
register_preprocessor 'application/javascript', DirectiveProcessor.new(comments: ["//", ["/*", "*/"]]) | ||
|
@@ -123,7 +119,6 @@ module Sprockets | |
register_bundle_metadata_reducer 'application/javascript', :data, proc { String.new("") }, Utils.method(:concat_javascript_sources) | ||
register_bundle_metadata_reducer '*/*', :links, :+ | ||
register_bundle_metadata_reducer '*/*', :sources, proc { [] }, :+ | ||
register_bundle_metadata_reducer '*/*', :map, proc { |input| { "version" => 3, "file" => PathUtils.split_subpath(input[:load_path], input[:filename]), "sections" => [] } }, SourceMapUtils.method(:concat_source_maps) | ||
|
||
require 'sprockets/closure_compressor' | ||
require 'sprockets/sass_compressor' | ||
|
@@ -219,4 +214,11 @@ module Sprockets | |
|
||
depend_on 'environment-version' | ||
depend_on 'environment-paths' | ||
|
||
require 'sprockets/preprocessors/default_source_map' | ||
register_preprocessor 'text/css', Preprocessors::DefaultSourceMap.new | ||
register_preprocessor 'application/javascript', Preprocessors::DefaultSourceMap.new | ||
|
||
register_bundle_metadata_reducer 'text/css', :map, proc { |input| { "version" => 3, "file" => PathUtils.split_subpath(input[:load_path], input[:filename]), "sections" => [] } }, SourceMapUtils.method(:concat_source_maps) | ||
register_bundle_metadata_reducer 'application/javascript', :map, proc { |input| { "version" => 3, "file" => PathUtils.split_subpath(input[:load_path], input[:filename]), "sections" => [] } }, SourceMapUtils.method(:concat_source_maps) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ class Cache | |
# Internal: Cache key version for this class. Rarely should have to change | ||
# unless the cache format radically changes. Will be bump on major version | ||
# releases though. | ||
VERSION = '4.0' | ||
VERSION = '4.0.0' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need this because By rev-ing the cache we can ensure the key will be there, since it’s added by |
||
|
||
def self.default_logger | ||
logger = Logger.new($stderr) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
//= require child.js | ||
//= require coffee/main.js | ||
//= require sub/a.js | ||
//= require plain.js |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function plain(input) { | ||
console.log("Plain" + input) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -610,7 +610,7 @@ class SlowExporter2 < SlowExporter | |
@env.register_exporter 'image/png',SlowExporter | ||
@env.register_exporter 'image/png',SlowExporter2 | ||
Sprockets::Manifest.new(@env, @dir).compile('logo.png', 'troll.png') | ||
assert_equal %w(0 0 0 0 1 1 1 1), SlowExporter.seq | ||
refute_equal %w(0 1 0 1 0 1 0 1), SlowExporter.seq | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we asserting what this isn't instead of what it is? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we're exporting things serially then the second exporter will not start until the first one ends. We are guaranteed to get However that test is coupled to a I changed the test to allow for other combinations, as long as they don't perfectly match the "synchronous" case. |
||
end | ||
|
||
test 'sequential exporting' do | ||
|
@@ -642,7 +642,7 @@ def call(_) | |
processor = SlowProcessor.new | ||
@env.register_postprocessor 'image/png', processor | ||
Sprockets::Manifest.new(@env, @dir).compile('logo.png', 'troll.png') | ||
assert_equal %w(0 0 1 1), processor.seq | ||
refute_equal %w(0 1 0 1), processor.seq | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
end | ||
|
||
test 'sequential processing' do | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,10 @@ | |
|
||
class TestSourceMapUtils < MiniTest::Test | ||
|
||
def deep_dup(object) | ||
Marshal.load( Marshal.dump(object) ) | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👹 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😇 |
||
def test_map | ||
source_map = { | ||
'version' => 3, | ||
|
@@ -94,12 +98,15 @@ def test_concat_empty_source_map_returns_original | |
{ source: 'c.js', generated: [rand(1..100), rand(0..100)], original: [rand(1..100), rand(0..100)] } | ||
].freeze | ||
|
||
linecount = abc_mappings.count(";") | ||
linecount += 1 if abc_mappings[-1] == ";" | ||
map = { | ||
"version" => 3, | ||
"file" => "a.js", | ||
"mappings" => Sprockets::SourceMapUtils.encode_vlq_mappings(abc_mappings), | ||
"sources" => ["a.js", "b.js", "c.js"], | ||
"names" => [] | ||
"names" => [], | ||
"x_sprockets_linecount" => linecount | ||
} | ||
empty_map = { "version" => 3, "file" => 'a.js', "sections" => [] } | ||
index_map = { | ||
|
@@ -113,11 +120,14 @@ def test_concat_empty_source_map_returns_original | |
] | ||
} | ||
|
||
assert_equal map, Sprockets::SourceMapUtils.concat_source_maps(nil, map.dup) | ||
assert_equal map, Sprockets::SourceMapUtils.concat_source_maps(map.dup, nil) | ||
assert_equal map, Sprockets::SourceMapUtils.concat_source_maps(nil, deep_dup(map)) | ||
assert_equal map, Sprockets::SourceMapUtils.concat_source_maps(deep_dup(map), nil) | ||
|
||
assert_equal index_map, Sprockets::SourceMapUtils.concat_source_maps(deep_dup(empty_map), map.dup) | ||
|
||
assert_equal index_map, Sprockets::SourceMapUtils.concat_source_maps(empty_map.dup, map.dup) | ||
assert_equal index_map, Sprockets::SourceMapUtils.concat_source_maps(map.dup, empty_map.dup) | ||
expected_index_map = deep_dup(index_map) | ||
expected_index_map["sections"].first["map"].delete("x_sprockets_linecount") | ||
assert_equal expected_index_map, Sprockets::SourceMapUtils.concat_source_maps(deep_dup(map), deep_dup(empty_map)) | ||
end | ||
|
||
def test_concat_source_maps | ||
|
@@ -136,27 +146,29 @@ def test_concat_source_maps | |
"file" => "a.js", | ||
"mappings" => Sprockets::SourceMapUtils.encode_vlq_mappings(abc_mappings), | ||
"sources" => ["a.js", "b.js", "c.js"], | ||
"names" => [] | ||
"names" => [], | ||
"x_sprockets_linecount" => 3 | ||
|
||
} | ||
|
||
d_map = { | ||
"version" => 3, | ||
"file" => "d.js", | ||
"mappings" => Sprockets::SourceMapUtils.encode_vlq_mappings(d_mapping), | ||
"sources" => ["d.js"], | ||
"names" => [] | ||
"names" => [], | ||
"x_sprockets_linecount" => 1 | ||
} | ||
|
||
|
||
combined = Sprockets::SourceMapUtils.concat_source_maps(abc_map.dup, d_map.dup) | ||
combined = Sprockets::SourceMapUtils.concat_source_maps(deep_dup(abc_map), deep_dup(d_map)) | ||
assert_equal [ | ||
{ source: 'a.js', generated: [1, 0], original: [1, 0] }, | ||
{ source: 'b.js', generated: [2, 0], original: [20, 0] }, | ||
{ source: 'c.js', generated: [3, 0], original: [30, 0] }, | ||
{ source: 'd.js', generated: [4, 0], original: [1, 0] } | ||
], Sprockets::SourceMapUtils.decode_source_map(combined)[:mappings] | ||
|
||
combined = Sprockets::SourceMapUtils.concat_source_maps(d_map.dup, abc_map.dup) | ||
combined = Sprockets::SourceMapUtils.concat_source_maps(deep_dup(d_map), deep_dup(abc_map)) | ||
assert_equal [ | ||
{ source: 'd.js', generated: [1, 0], original: [1, 0] }, | ||
{ source: 'a.js', generated: [2, 0], original: [1, 0] }, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leaked in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, causes a failure travis-ci/travis-ci#8408 (comment) and documentcloud/closure-compiler#48