source_maps_fixer 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +29 -0
- data/lib/source_maps_fixer/railtie.rb +11 -0
- data/lib/source_maps_fixer/version.rb +5 -0
- data/lib/source_maps_fixer.rb +49 -0
- data/lib/tasks/fix_source_maps.rake +17 -0
- data/lib/tasks/prepare.rake +11 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 24f639d3f394a3b22527fc373755c2c1f9c53142c56aab9004afa627919bffb2
|
4
|
+
data.tar.gz: 516d9b63e74c54b4128e0ec226991d1902c52ab5392d003a6c8745a63b5191a1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 76a633404431de1c4e31625f734cfc504f902841a462105587f4c0efa1d31de132ae96d15af13f6a86f82a685767d4d20ffff9370909f0f372b9c25ff127f351
|
7
|
+
data.tar.gz: e43942056afb5de02c5ba1cb06719bf404b22a0bab9e5ed9cd8c6ecfb218c648d8c425da227eea059f9ac1c81295cd0f96aeecb4252521a87d8f8c716168013b
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2018 Zbigniew Humeniuk
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# SourceMapsFixer
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'source_maps_fixer'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install source_maps_fixer
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rdoc/task'
|
10
|
+
|
11
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
12
|
+
rdoc.rdoc_dir = 'rdoc'
|
13
|
+
rdoc.title = 'SourceMapsFixer'
|
14
|
+
rdoc.options << '--line-numbers'
|
15
|
+
rdoc.rdoc_files.include('README.md')
|
16
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'bundler/gem_tasks'
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
|
23
|
+
Rake::TestTask.new(:test) do |t|
|
24
|
+
t.libs << 'test'
|
25
|
+
t.pattern = 'test/**/*_test.rb'
|
26
|
+
t.verbose = false
|
27
|
+
end
|
28
|
+
|
29
|
+
task default: :test
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'source_maps_fixer/railtie'
|
4
|
+
|
5
|
+
module SourceMapsFixer
|
6
|
+
class Path
|
7
|
+
def self.files_with_source_maps
|
8
|
+
Dir.glob("#{Rails.root.join 'app', 'assets'}/**/*")
|
9
|
+
.find_all { |name| name =~ /\.map\Z/ }
|
10
|
+
.map { |name| [name.sub('.map', ''), name] }
|
11
|
+
.to_h
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.digest_path file_name
|
15
|
+
Rails.application.assets.find_asset(file_name).digest_path
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.source_mapping_url file_name
|
19
|
+
case file_name.match?(/\.css/) ? :css : :js
|
20
|
+
when :css
|
21
|
+
"/*# sourceMappingURL=#{file_name}*/"
|
22
|
+
when :js
|
23
|
+
"//# sourceMappingURL=#{file_name}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Executor
|
29
|
+
def self.call
|
30
|
+
Path.files_with_source_maps.each do |file_name, sm_name|
|
31
|
+
new_content = File.read(file_name).sub(
|
32
|
+
Path.source_mapping_url(File.basename(sm_name)),
|
33
|
+
Path.source_mapping_url(Path.digest_path(sm_name))
|
34
|
+
)
|
35
|
+
File.open(file_name, 'w') { |file| file.write new_content }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.undo
|
40
|
+
Path.files_with_source_maps.each do |file_name, sm_name|
|
41
|
+
new_content = File.read(file_name).sub(
|
42
|
+
Path.source_mapping_url(Path.digest_path(sm_name)),
|
43
|
+
Path.source_mapping_url(File.basename(sm_name))
|
44
|
+
)
|
45
|
+
File.open(file_name, 'w') { |file| file.write new_content }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :assets do
|
4
|
+
desc 'Fix URLs to source maps'
|
5
|
+
task fix_source_maps: [:environment] do
|
6
|
+
puts 'Fixing URLs to source maps...'
|
7
|
+
SourceMapsFixer::Executor.call
|
8
|
+
puts 'URLs to source maps have been fixed!'
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'Revert fixed URLs to source maps'
|
12
|
+
task undo_fix_source_maps: [:environment] do
|
13
|
+
puts 'Reverting fixed URLs to source maps...'
|
14
|
+
SourceMapsFixer::Executor.undo
|
15
|
+
puts 'URLs to source maps have been reverted!'
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :assets do
|
4
|
+
desc 'Fix URLs to source maps and compile assets'
|
5
|
+
task :prepare do
|
6
|
+
SourceMapsFixer::Executor.call
|
7
|
+
Rake::Task['assets:precompile'].invoke
|
8
|
+
SourceMapsFixer::Executor.undo
|
9
|
+
puts 'Assets have been prepared!'
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: source_maps_fixer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zbigniew Humeniuk
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6.0'
|
33
|
+
description: Rake tasks that fix sourceMappingURL in JavaScript and CSS bundles generated
|
34
|
+
by webpack to match the final fingerprinted names generated by Sprockets after assets'
|
35
|
+
precompilation
|
36
|
+
email:
|
37
|
+
- hello@artofcode.co
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- MIT-LICENSE
|
43
|
+
- README.md
|
44
|
+
- Rakefile
|
45
|
+
- lib/source_maps_fixer.rb
|
46
|
+
- lib/source_maps_fixer/railtie.rb
|
47
|
+
- lib/source_maps_fixer/version.rb
|
48
|
+
- lib/tasks/fix_source_maps.rake
|
49
|
+
- lib/tasks/prepare.rake
|
50
|
+
homepage: https://artofcode.co
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata: {}
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubygems_version: 3.0.1
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Rake tasks for fixing URLs to source maps
|
73
|
+
test_files: []
|