sprockets_uglifier_with_source_maps 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 93335675b385d5414755b625b2243a1af4aa6a81
4
- data.tar.gz: 0c4532f47fdc81881b4e9a80bb3af018d370942d
3
+ metadata.gz: fe966a556721536fa55d4695e1bcd024c71bdde3
4
+ data.tar.gz: d23d9deecbbf9c2fcea3fd7543a44928425bd0e9
5
5
  SHA512:
6
- metadata.gz: b3228b0eebf8f657de32befc52e6944ef61f86098562db05ade4fff1d57f1433dc1ccabbdc5d64e86a19a5a3a43a03e3ac252c7a8b0e2fac6c595707e6cede4a
7
- data.tar.gz: 23eb2fbeaad91ca8491afba04fe585dc67d9d6c326fb279e29ee31c747e8fb258339068c621bd54aa728ee12bf47eab31b60f72bf31f73f3d7860902b122b30c
6
+ metadata.gz: 3fc0f191b883413078db8d1bc66dfd0f1d76db53873282175185e23e9936dc045ff97eb6547b7ef977905192d94f9b25755d6075026db66538aa683385a08168
7
+ data.tar.gz: d46c8f28bb7a3cba1c4ca04d05c5a47809ca3c88e1226a2329b870158033348ed3c4dd576c7a104dded37b233b33613314e052ecc36ed1d9b479d2a837ecaf52
data/README.md CHANGED
@@ -25,7 +25,6 @@ Or install it yourself as:
25
25
 
26
26
  $ gem install sprockets_uglifier_with_source_maps
27
27
 
28
-
29
28
  ## Usage
30
29
 
31
30
  In your Rails applications environment configuration:
@@ -42,9 +41,13 @@ These subdirs may be configured:
42
41
  config.assets.sourcemaps_prefix = 'my_maps'
43
42
  config.assets.uncompressed_prefix = 'my_sources'
44
43
 
45
- You can optionally gzip your maps and sources as well (since these files live outside of the assets pipeline this won't happen automatically):
44
+ Alternatively, sources can be embedded into sourcemaps' `sourcesContent` field:
45
+
46
+ config.assets.sourcemaps_embed_source = true
46
47
 
47
- config.assets.sourcemaps_gzip = true
48
+ You can optionally skip gzipping your maps and sources:
49
+
50
+ config.assets.sourcemaps_gzip = false
48
51
 
49
52
  By default maps and sources are defined relatively and will be fetched from the same domain your js file is served from. If you are using a CDN you may not want this - instead you might want to use a direct link to your site so you can more easily implement IP or Basic Auth protection:
50
53
 
@@ -75,6 +78,9 @@ If you use CloudFront you might want to generate a signed url for these files th
75
78
  $ head -c115 public/assets/maps/application-a3aff92c860f3876615c2d158f724865.js.map
76
79
  {"version":3,"file":"application.js","sources":["/assets/sources/application-73a007cf2d51c423a4420b649344b52e.js"],
77
80
 
81
+ ## Troubleshooting
82
+
83
+ If sourcemaps are not generated, try `rm -rf tmp/cache`.
78
84
 
79
85
  ## Contributing
80
86
 
@@ -7,9 +7,7 @@ module SprocketsUglifierWithSM
7
7
  DEFAULTS = { comments: false }
8
8
 
9
9
  def initialize(options = {})
10
- # merge in any options passed in from our rails configuration - i wish
11
- # rails actually did this by default :/
12
- @options = options.merge(DEFAULTS).merge!(Rails.application.config.assets.uglifier.to_h)
10
+ @options = DEFAULTS.merge(Rails.application.config.assets.uglifier.to_h).merge!(options)
13
11
  super @options
14
12
  end
15
13
 
@@ -18,41 +16,53 @@ module SprocketsUglifierWithSM
18
16
  name = input.fetch(:name)
19
17
 
20
18
  uglifier = Sprockets::Autoload::Uglifier.new(@options)
21
- compressed_data, sourcemap = uglifier.compile_with_map(data)
22
19
 
23
- uncompressed_filename = File.join(Rails.application.config.assets.prefix, Rails.application.config.assets.uncompressed_prefix, "#{name}-#{digest(data)}.js")
24
- uncompressed_url = filename_to_url uncompressed_filename
20
+ compressed_data, sourcemap_json = uglifier.compile_with_map(data)
25
21
 
26
- sourcemap = JSON.parse(sourcemap)
27
- sourcemap['file'] = "#{name}.js"
28
- sourcemap['sources'] = [uncompressed_url]
22
+ sourcemap = JSON.parse(sourcemap_json)
29
23
 
30
- sourcemap = sourcemap.to_json
31
-
32
- sourcemap_filename = File.join(Rails.application.config.assets.prefix, Rails.application.config.assets.sourcemaps_prefix, "#{name}-#{digest(sourcemap)}.js.map")
24
+ if Rails.application.config.assets.sourcemaps_embed_source
25
+ sourcemap['sourcesContent'] = [data]
26
+ else
27
+ uncompressed_filename = File.join(Rails.application.config.assets.prefix, Rails.application.config.assets.uncompressed_prefix, "#{name}-#{digest(data)}.js")
28
+ uncompressed_path = File.join(Rails.public_path, uncompressed_filename)
29
+ uncompressed_url = filename_to_url(uncompressed_filename)
33
30
 
34
- sourcemap_path = File.join(Rails.public_path, sourcemap_filename)
35
- uncompressed_path = File.join(Rails.public_path, uncompressed_filename)
36
- FileUtils.mkdir_p [File.dirname(sourcemap_path), File.dirname(uncompressed_path)]
37
- File.open(sourcemap_path, 'w') { |f| f.write sourcemap }
38
- File.open(uncompressed_path, 'w') { |f| f.write data }
31
+ FileUtils.mkdir_p File.dirname(uncompressed_path)
32
+ File.open(uncompressed_path, 'w') { |f| f.write data }
33
+ gzip_file(uncompressed_path) if gzip?
39
34
 
40
- if Rails.application.config.assets.sourcemaps_gzip
41
- [sourcemap_path, uncompressed_path].each do |f|
42
- Zlib::GzipWriter.open("#{f}.gz") do |gz|
43
- gz.mtime = File.mtime(f)
44
- gz.orig_name = f
45
- gz.write IO.binread(f)
46
- end
47
- end
35
+ sourcemap['sources'] = [uncompressed_url]
48
36
  end
37
+ sourcemap['file'] = "#{name}.js"
38
+
39
+ sourcemap_json = sourcemap.to_json
40
+ sourcemap_filename = File.join(Rails.application.config.assets.prefix, Rails.application.config.assets.sourcemaps_prefix, "#{name}-#{digest(sourcemap_json)}.js.map")
41
+ sourcemap_path = File.join(Rails.public_path, sourcemap_filename)
42
+ sourcemap_url = filename_to_url(sourcemap_filename)
43
+
44
+ FileUtils.mkdir_p File.dirname(sourcemap_path)
45
+ File.open(sourcemap_path, 'w') { |f| f.write sourcemap_json }
46
+ gzip_file(sourcemap_path) if gzip?
49
47
 
50
- sourcemap_url = filename_to_url sourcemap_filename
51
48
  compressed_data.concat "\n//# sourceMappingURL=#{sourcemap_url}\n"
52
49
  end
53
50
 
54
51
  private
55
52
 
53
+ def gzip?
54
+ config = Rails.application.config.assets
55
+ config.sourcemaps_gzip || (config.sourcemaps_gzip.nil? && config.gzip)
56
+ end
57
+
58
+ def gzip_file(path)
59
+ Zlib::GzipWriter.open("#{path}.gz") do |gz|
60
+ gz.mtime = File.mtime(path)
61
+ gz.orig_name = path
62
+ gz.write IO.binread(path)
63
+ end
64
+ end
65
+
56
66
  def filename_to_url(filename)
57
67
  url_root = Rails.application.config.assets.sourcemaps_url_root
58
68
  case url_root
@@ -7,7 +7,6 @@ module SprocketsUglifierWithSM
7
7
  config = app.config
8
8
  config.assets.sourcemaps_prefix ||= 'maps'
9
9
  config.assets.uncompressed_prefix ||= 'sources'
10
- config.assets.sourcemaps_gzip ||= false
11
10
  config.assets.sourcemaps_url_root ||= false
12
11
  end
13
12
  end
@@ -1,3 +1,3 @@
1
1
  module SprocketsUglifierWithSM
2
- VERSION = '2.0.1'
2
+ VERSION = '2.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets_uglifier_with_source_maps
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Pavlenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-28 00:00:00.000000000 Z
11
+ date: 2017-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sprockets-rails