uglifier 2.5.3 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of uglifier might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -2
- data/README.md +3 -1
- data/lib/uglifier.rb +36 -21
- data/lib/uglifier/version.rb +2 -1
- data/spec/source_map_spec.rb +34 -10
- data/uglifier.gemspec +1 -1
- metadata +27 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 585ecdc74ace303e7a9ab552441517c2cd455bb7
|
4
|
+
data.tar.gz: b974ac6688e88acbf12928ce84e035f1edab1519
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4ce4b2b9b9bacf055ae287c7c9b290ed9bf0a7cf405a829208e10906d10726ef11815366d2a3572e020d0dd65422605a98fcde2ef2c2c76790a13c9101bd285
|
7
|
+
data.tar.gz: d7c2783bfe8e21e0f11eda932a302f5c60ec8b3361b693ea7a81e1c610e5a5e01234d78c90614207852216dbdc679bac676ddf6e91a219eb1863ef2af5fe90f5
|
data/.travis.yml
CHANGED
@@ -3,7 +3,7 @@ rvm:
|
|
3
3
|
- 1.8.7
|
4
4
|
- 1.9.3
|
5
5
|
- 2.0.0
|
6
|
-
- 2.1.
|
6
|
+
- 2.1.5
|
7
7
|
- jruby
|
8
8
|
#- rbx-2 # Fails on Travis
|
9
9
|
git:
|
@@ -12,7 +12,7 @@ gemfile:
|
|
12
12
|
- Gemfile
|
13
13
|
matrix:
|
14
14
|
include:
|
15
|
-
- rvm: 2.1.
|
15
|
+
- rvm: 2.1.5
|
16
16
|
gemfile: gemfiles/rubyracer
|
17
17
|
- rvm: 2.0.0
|
18
18
|
gemfile: gemfiles/rubyracer
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -95,7 +95,9 @@ Available options and their defaults are
|
|
95
95
|
:source_root => nil, # The URL of the directory which contains :source_filename
|
96
96
|
:output_filename => nil, # The filename or URL where the minified output can be found
|
97
97
|
:input_source_map => nil, # The contents of the source map describing the input
|
98
|
-
:screw_ie8 => false
|
98
|
+
:screw_ie8 => false, # Don't bother to generate safe code for IE8
|
99
|
+
:source_map_url => false, # Url for source mapping to be appended in minified source
|
100
|
+
:source_url => false # Url to original source to be appended in minified source
|
99
101
|
}
|
100
102
|
```
|
101
103
|
|
data/lib/uglifier.rb
CHANGED
@@ -6,7 +6,9 @@ require "uglifier/version"
|
|
6
6
|
|
7
7
|
# A wrapper around the UglifyJS interface
|
8
8
|
class Uglifier
|
9
|
+
# Error class for compilation errors.
|
9
10
|
Error = ExecJS::Error
|
11
|
+
# JavaScript code to call UglifyJS
|
10
12
|
JS = <<-JS
|
11
13
|
function comments(option) {
|
12
14
|
if (Object.prototype.toString.call(option) === '[object Array]') {
|
@@ -55,6 +57,15 @@ class Uglifier
|
|
55
57
|
var stream = UglifyJS.OutputStream(gen_code_options);
|
56
58
|
|
57
59
|
ast.print(stream);
|
60
|
+
|
61
|
+
if (options.source_map_options.map_url) {
|
62
|
+
stream += "\\n//# sourceMappingURL=" + options.source_map_options.map_url;
|
63
|
+
}
|
64
|
+
|
65
|
+
if (options.source_map_options.url) {
|
66
|
+
stream += "\\n//# sourceURL=" + options.source_map_options.url;
|
67
|
+
}
|
68
|
+
|
58
69
|
if (options.generate_map) {
|
59
70
|
return [stream.toString(), source_map.toString()];
|
60
71
|
} else {
|
@@ -62,7 +73,7 @@ class Uglifier
|
|
62
73
|
}
|
63
74
|
JS
|
64
75
|
|
65
|
-
# UglifyJS source
|
76
|
+
# UglifyJS source path
|
66
77
|
SourcePath = File.expand_path("../uglify.js", __FILE__)
|
67
78
|
# ES5 shims source path
|
68
79
|
ES5FallbackPath = File.expand_path("../es5.js", __FILE__)
|
@@ -124,48 +135,45 @@ class Uglifier
|
|
124
135
|
:source_root => nil, # The URL of the directory which contains :source_filename
|
125
136
|
:output_filename => nil, # The filename or URL where the minified output can be found
|
126
137
|
:input_source_map => nil, # The contents of the source map describing the input
|
127
|
-
:screw_ie8 => false # Don't bother to generate safe code for IE8
|
138
|
+
:screw_ie8 => false, # Don't bother to generate safe code for IE8
|
139
|
+
:source_map_url => false, # Url for source mapping to be appended in minified source
|
140
|
+
:source_url => false # Url for original source to be appended in minified source
|
128
141
|
}
|
129
142
|
# rubocop:enable LineLength
|
130
143
|
|
131
144
|
# Minifies JavaScript code using implicit context.
|
132
145
|
#
|
133
|
-
# source
|
134
|
-
# options
|
135
|
-
#
|
136
|
-
# Returns minified code as String
|
146
|
+
# @param source [IO, String] valid JS source code.
|
147
|
+
# @param options [Hash] optional overrides to +Uglifier::DEFAULTS+
|
148
|
+
# @return [String] minified code.
|
137
149
|
def self.compile(source, options = {})
|
138
150
|
new(options).compile(source)
|
139
151
|
end
|
140
152
|
|
141
153
|
# Minifies JavaScript code and generates a source map using implicit context.
|
142
154
|
#
|
143
|
-
# source
|
144
|
-
# options
|
145
|
-
#
|
146
|
-
# Returns a pair of [minified code as String, source map as a String]
|
155
|
+
# @param source [IO, String] valid JS source code.
|
156
|
+
# @param options [Hash] optional overrides to +Uglifier::DEFAULTS+
|
157
|
+
# @return [Array(String, String)] minified code and source map.
|
147
158
|
def self.compile_with_map(source, options = {})
|
148
159
|
new(options).compile_with_map(source)
|
149
160
|
end
|
150
161
|
|
151
162
|
# Initialize new context for Uglifier with given options
|
152
163
|
#
|
153
|
-
# options
|
164
|
+
# @param options [Hash] optional overrides to +Uglifier::DEFAULTS+
|
154
165
|
def initialize(options = {})
|
155
166
|
(options.keys - DEFAULTS.keys - [:comments, :squeeze, :copyright])[0..1].each do |missing|
|
156
167
|
raise ArgumentError, "Invalid option: #{missing}"
|
157
168
|
end
|
158
169
|
@options = options
|
159
|
-
@context = ExecJS.compile(
|
160
|
-
File.open(SplitFallbackPath, "r:UTF-8").read +
|
161
|
-
File.open(SourcePath, "r:UTF-8").read)
|
170
|
+
@context = ExecJS.compile(uglifyjs_source)
|
162
171
|
end
|
163
172
|
|
164
173
|
# Minifies JavaScript code
|
165
174
|
#
|
166
|
-
# source
|
167
|
-
#
|
168
|
-
# Returns minified code as String
|
175
|
+
# @param source [IO, String] valid JS source code.
|
176
|
+
# @return [String] minified code.
|
169
177
|
def compile(source)
|
170
178
|
run_uglifyjs(source, false)
|
171
179
|
end
|
@@ -173,15 +181,20 @@ class Uglifier
|
|
173
181
|
|
174
182
|
# Minifies JavaScript code and generates a source map
|
175
183
|
#
|
176
|
-
# source
|
177
|
-
#
|
178
|
-
# Returns a pair of [minified code as String, source map as a String]
|
184
|
+
# @param source [IO, String] valid JS source code.
|
185
|
+
# @return [Array(String, String)] minified code and source map.
|
179
186
|
def compile_with_map(source)
|
180
187
|
run_uglifyjs(source, true)
|
181
188
|
end
|
182
189
|
|
183
190
|
private
|
184
191
|
|
192
|
+
def uglifyjs_source
|
193
|
+
[ES5FallbackPath, SplitFallbackPath, SourcePath].map do |file|
|
194
|
+
File.open(file, "r:UTF-8") { |f| f.read }
|
195
|
+
end.join("\n")
|
196
|
+
end
|
197
|
+
|
185
198
|
# Run UglifyJS for given source code
|
186
199
|
def run_uglifyjs(source, generate_map)
|
187
200
|
@context.exec(Uglifier::JS % json_encode(
|
@@ -263,7 +276,9 @@ class Uglifier
|
|
263
276
|
{
|
264
277
|
:file => @options[:output_filename],
|
265
278
|
:root => @options[:source_root],
|
266
|
-
:orig => @options[:input_source_map]
|
279
|
+
:orig => @options[:input_source_map],
|
280
|
+
:map_url => @options[:source_map_url],
|
281
|
+
:url => @options[:source_url]
|
267
282
|
}
|
268
283
|
end
|
269
284
|
|
data/lib/uglifier/version.rb
CHANGED
data/spec/source_map_spec.rb
CHANGED
@@ -3,16 +3,8 @@ require 'stringio'
|
|
3
3
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
4
4
|
|
5
5
|
describe "Uglifier" do
|
6
|
-
|
7
|
-
|
8
|
-
minified, map = Uglifier.new.compile_with_map(source)
|
9
|
-
expect(minified.length).to be < source.length
|
10
|
-
expect(map.length).to be > 0
|
11
|
-
expect { JSON.parse(map) }.not_to raise_error
|
12
|
-
end
|
13
|
-
|
14
|
-
it "generates source maps with the correct meta-data" do
|
15
|
-
source = <<-JS
|
6
|
+
let(:source) do
|
7
|
+
<<-JS
|
16
8
|
function hello () {
|
17
9
|
function world () {
|
18
10
|
return 2;
|
@@ -21,7 +13,17 @@ describe "Uglifier" do
|
|
21
13
|
return world() + world();
|
22
14
|
};
|
23
15
|
JS
|
16
|
+
end
|
17
|
+
|
18
|
+
it "generates source maps" do
|
19
|
+
source = File.open("lib/uglify.js", "r:UTF-8").read
|
20
|
+
minified, map = Uglifier.new.compile_with_map(source)
|
21
|
+
expect(minified.length).to be < source.length
|
22
|
+
expect(map.length).to be > 0
|
23
|
+
expect { JSON.parse(map) }.not_to raise_error
|
24
|
+
end
|
24
25
|
|
26
|
+
it "generates source maps with the correct meta-data" do
|
25
27
|
_, map = Uglifier.compile_with_map(source,
|
26
28
|
:source_filename => "ahoy.js",
|
27
29
|
:output_filename => "ahoy.min.js",
|
@@ -83,4 +85,26 @@ describe "Uglifier" do
|
|
83
85
|
expect(map.mappings.first[:source_line]).to eq(1)
|
84
86
|
expect(map.mappings.last[:source_line]).to eq(6)
|
85
87
|
end
|
88
|
+
|
89
|
+
it "appens source map url" do
|
90
|
+
minified, _ = Uglifier.compile_with_map(
|
91
|
+
source,
|
92
|
+
:source_filename => "ahoy.js",
|
93
|
+
:output_filename => "ahoy.min.js",
|
94
|
+
:source_root => "http://localhost/",
|
95
|
+
:source_map_url => "http://example.com/map"
|
96
|
+
)
|
97
|
+
expect(minified).to include("\n//# sourceMappingURL=http://example.com/map")
|
98
|
+
end
|
99
|
+
|
100
|
+
it "appens source url" do
|
101
|
+
minified, _ = Uglifier.compile_with_map(
|
102
|
+
source,
|
103
|
+
:source_filename => "ahoy.js",
|
104
|
+
:output_filename => "ahoy.min.js",
|
105
|
+
:source_root => "http://localhost/",
|
106
|
+
:source_url => "http://example.com/source"
|
107
|
+
)
|
108
|
+
expect(minified).to include("\n//# sourceURL=http://example.com/source")
|
109
|
+
end
|
86
110
|
end
|
data/uglifier.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_runtime_dependency "execjs", ">= 0.3.0"
|
27
27
|
spec.add_runtime_dependency "json", ">= 1.8.0"
|
28
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
-
spec.add_development_dependency "rake", "~> 10.
|
29
|
+
spec.add_development_dependency "rake", "~> 10.4"
|
30
30
|
spec.add_development_dependency "bundler", "~> 1.3"
|
31
31
|
spec.add_development_dependency "rdoc", ">= 3.11"
|
32
32
|
spec.add_development_dependency "source_map", ">= 0"
|
metadata
CHANGED
@@ -1,111 +1,111 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uglifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ville Lautanala
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: execjs
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.3.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.3.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.8.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.8.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 10.
|
61
|
+
version: '10.4'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 10.
|
68
|
+
version: '10.4'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '1.3'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.3'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rdoc
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '3.11'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '3.11'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: source_map
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
description: Uglifier minifies JavaScript files by wrapping UglifyJS to be accessible
|
@@ -118,12 +118,12 @@ extra_rdoc_files:
|
|
118
118
|
- LICENSE.txt
|
119
119
|
- README.md
|
120
120
|
files:
|
121
|
-
- .document
|
122
|
-
- .gitignore
|
123
|
-
- .gitmodules
|
124
|
-
- .rspec
|
125
|
-
- .rubocop.yml
|
126
|
-
- .travis.yml
|
121
|
+
- ".document"
|
122
|
+
- ".gitignore"
|
123
|
+
- ".gitmodules"
|
124
|
+
- ".rspec"
|
125
|
+
- ".rubocop.yml"
|
126
|
+
- ".travis.yml"
|
127
127
|
- CHANGELOG.md
|
128
128
|
- CONTRIBUTING.md
|
129
129
|
- Gemfile
|
@@ -151,17 +151,17 @@ require_paths:
|
|
151
151
|
- lib
|
152
152
|
required_ruby_version: !ruby/object:Gem::Requirement
|
153
153
|
requirements:
|
154
|
-
- -
|
154
|
+
- - ">="
|
155
155
|
- !ruby/object:Gem::Version
|
156
156
|
version: 1.8.7
|
157
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
158
|
requirements:
|
159
|
-
- -
|
159
|
+
- - ">="
|
160
160
|
- !ruby/object:Gem::Version
|
161
161
|
version: '0'
|
162
162
|
requirements: []
|
163
163
|
rubyforge_project:
|
164
|
-
rubygems_version: 2.
|
164
|
+
rubygems_version: 2.2.2
|
165
165
|
signing_key:
|
166
166
|
specification_version: 4
|
167
167
|
summary: Ruby wrapper for UglifyJS JavaScript compressor
|