condenser 0.0.10 → 0.0.11
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 +4 -4
- data/lib/condenser.rb +4 -6
- data/lib/condenser/asset.rb +116 -69
- data/lib/condenser/build_cache.rb +107 -0
- data/lib/condenser/cache/file_store.rb +1 -3
- data/lib/condenser/environment.rb +1 -1
- data/lib/condenser/processors/babel_processor.rb +1 -1
- data/lib/condenser/processors/node_modules/@types/estree/LICENSE +21 -21
- data/lib/condenser/processors/node_modules/@types/estree/README.md +16 -16
- data/lib/condenser/processors/node_modules/@types/node/LICENSE +21 -21
- data/lib/condenser/processors/node_modules/@types/node/README.md +16 -16
- data/lib/condenser/processors/node_modules/@types/resolve/README.md +16 -16
- data/lib/condenser/processors/node_modules/babel-plugin-transform-class-extended-hook/test/index.js +107 -107
- data/lib/condenser/processors/node_modules/color-name/.npmignore +106 -106
- data/lib/condenser/processors/node_modules/color-name/LICENSE +7 -7
- data/lib/condenser/processors/node_modules/color-name/README.md +11 -11
- data/lib/condenser/processors/node_modules/color-name/index.js +152 -152
- data/lib/condenser/processors/node_modules/color-name/test.js +7 -7
- data/lib/condenser/processors/node_modules/is-reference/node_modules/@types/estree/LICENSE +21 -21
- data/lib/condenser/processors/node_modules/is-reference/node_modules/@types/estree/README.md +16 -16
- data/lib/condenser/processors/node_modules/is-reference/node_modules/@types/estree/index.d.ts +548 -548
- data/lib/condenser/processors/rollup_processor.rb +0 -8
- data/lib/condenser/resolve.rb +80 -60
- data/lib/condenser/transformers/sass_transformer.rb +1 -1
- data/lib/condenser/transformers/sass_transformer/importer.rb +1 -1
- data/lib/condenser/version.rb +1 -1
- data/test/cache_test.rb +72 -0
- data/test/test_helper.rb +1 -1
- data/test/transformers/scss_test.rb +2 -1
- metadata +17 -2
@@ -4,8 +4,6 @@ require File.expand_path('../node_processor', __FILE__)
|
|
4
4
|
|
5
5
|
class Condenser::RollupProcessor < Condenser::NodeProcessor
|
6
6
|
|
7
|
-
include ActiveSupport::Benchmarkable
|
8
|
-
|
9
7
|
ROLLUP_VERSION = '0.56.1'
|
10
8
|
|
11
9
|
def self.call(environment, input)
|
@@ -15,10 +13,6 @@ class Condenser::RollupProcessor < Condenser::NodeProcessor
|
|
15
13
|
def initialize(options = {})
|
16
14
|
@options = options.merge({}).freeze
|
17
15
|
end
|
18
|
-
|
19
|
-
def logger
|
20
|
-
@environment.logger
|
21
|
-
end
|
22
16
|
|
23
17
|
def call(environment, input)
|
24
18
|
@environment = environment
|
@@ -204,7 +198,6 @@ class Condenser::RollupProcessor < Condenser::NodeProcessor
|
|
204
198
|
messages.each do |message|
|
205
199
|
message = JSON.parse(message)
|
206
200
|
|
207
|
-
benchmark "Rollup #{message['method']}(#{message['args'].map(&:inspect).join(', ')})", level: :info do
|
208
201
|
ret = case message['method']
|
209
202
|
when 'resolve'
|
210
203
|
importee, importer = message['args']
|
@@ -292,7 +285,6 @@ class Condenser::RollupProcessor < Condenser::NodeProcessor
|
|
292
285
|
end
|
293
286
|
|
294
287
|
io.write(JSON.generate({rid: message['rid'], return: ret}))
|
295
|
-
end
|
296
288
|
end
|
297
289
|
end
|
298
290
|
rescue Errno::EPIPE, EOFError
|
data/lib/condenser/resolve.rb
CHANGED
@@ -6,81 +6,92 @@ class Condenser
|
|
6
6
|
super
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
9
|
+
def build_cache
|
10
|
+
return @build_cache if instance_variable_defined?(:@build_cache)
|
11
|
+
@build_cache = BuildCache.new(path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def resolve(filename, base=nil, accept: nil)
|
10
15
|
filename = filename.delete_prefix("/") if path.none? { |p| filename.start_with?(p) }
|
16
|
+
dirname, basename, extensions, mime_types = decompose_path(filename, base)
|
17
|
+
accept ||= mime_types.empty? ? ['*/*'] : mime_types
|
18
|
+
accept = Array(accept)
|
11
19
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
results = []
|
16
|
-
|
17
|
-
accept ||= mime_types.empty? ? ['*/*'] : mime_types
|
18
|
-
accept = Array(accept)
|
20
|
+
cache_key = [dirname, basename].flatten.join('/')
|
21
|
+
cache_key << "@#{accept.join(',')}" if accept
|
19
22
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
build_cache.fetch(cache_key) do
|
24
|
+
build do
|
25
|
+
results = []
|
26
|
+
|
27
|
+
paths = if dirname&.start_with?('/')
|
28
|
+
if pat = path.find { |pa| dirname.start_with?(pa) }
|
29
|
+
dirname.delete_prefix!(pat)
|
30
|
+
dirname.delete_prefix!('/')
|
31
|
+
[pat]
|
32
|
+
else
|
33
|
+
[]
|
34
|
+
end
|
25
35
|
else
|
26
|
-
|
36
|
+
path
|
27
37
|
end
|
28
|
-
|
29
|
-
path
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
glob = File.join(glob, dirname) if dirname
|
35
|
-
glob = File.join(glob, basename)
|
36
|
-
glob << '.*' unless glob.end_with?('*')
|
38
|
+
|
39
|
+
paths.each do |path|
|
40
|
+
glob = path
|
41
|
+
glob = File.join(glob, dirname) if dirname
|
42
|
+
glob = File.join(glob, basename)
|
43
|
+
glob << '.*' unless glob.end_with?('*')
|
37
44
|
|
38
|
-
|
39
|
-
|
45
|
+
Dir.glob(glob).sort.each do |f|
|
46
|
+
next if !File.file?(f)
|
40
47
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
content_types: f_mime_types,
|
50
|
-
source_file: f,
|
51
|
-
source_path: path
|
52
|
-
})
|
53
|
-
results << @build_cache[asset_filename]
|
54
|
-
else
|
55
|
-
reverse_mapping[f_mime_types]&.each do |derivative_mime_types|
|
56
|
-
if accept == ['*/*'] || mime_type_match_accept?(derivative_mime_types, accept)
|
57
|
-
asset_dir = f_dirname.delete_prefix(path).delete_prefix('/')
|
58
|
-
asset_basename = f_basename + derivative_mime_types.map { |t| @mime_types[t][:extensions].first }.join('')
|
59
|
-
asset_filename = asset_dir.empty? ? asset_basename : File.join(asset_dir, asset_basename)
|
60
|
-
@build_cache[asset_filename] ||= Asset.new(self, {
|
48
|
+
f_dirname, f_basename, f_extensions, f_mime_types = decompose_path(f)
|
49
|
+
if (basename == '*' || basename == f_basename)
|
50
|
+
if accept == ['*/*'] || mime_type_match_accept?(f_mime_types, accept)
|
51
|
+
asset_dir = f_dirname.delete_prefix(path).delete_prefix('/')
|
52
|
+
asset_basename = f_basename + f_extensions.join('')
|
53
|
+
asset_filename = asset_dir.empty? ? asset_basename : File.join(asset_dir, asset_basename)
|
54
|
+
results << build_cache.map(asset_filename + f_mime_types.join('')) do
|
55
|
+
Asset.new(self, {
|
61
56
|
filename: asset_filename,
|
62
|
-
content_types:
|
57
|
+
content_types: f_mime_types,
|
63
58
|
source_file: f,
|
64
59
|
source_path: path
|
65
60
|
})
|
66
|
-
|
61
|
+
end
|
62
|
+
else
|
63
|
+
reverse_mapping[f_mime_types]&.each do |derivative_mime_types|
|
64
|
+
if accept == ['*/*'] || mime_type_match_accept?(derivative_mime_types, accept)
|
65
|
+
asset_dir = f_dirname.delete_prefix(path).delete_prefix('/')
|
66
|
+
asset_basename = f_basename + derivative_mime_types.map { |t| @mime_types[t][:extensions].first }.join('')
|
67
|
+
asset_filename = asset_dir.empty? ? asset_basename : File.join(asset_dir, asset_basename)
|
68
|
+
results << build_cache.map(asset_filename + derivative_mime_types.join('')) do
|
69
|
+
Asset.new(self, {
|
70
|
+
filename: asset_filename,
|
71
|
+
content_types: derivative_mime_types,
|
72
|
+
source_file: f,
|
73
|
+
source_path: path
|
74
|
+
})
|
75
|
+
end
|
76
|
+
end
|
67
77
|
end
|
68
78
|
end
|
69
|
-
end
|
70
79
|
|
80
|
+
end
|
71
81
|
end
|
72
82
|
end
|
73
|
-
end
|
74
83
|
|
75
|
-
|
76
|
-
|
77
|
-
|
84
|
+
results = results.group_by do |a|
|
85
|
+
accept.find_index { |m| match_mime_types?(a.content_types, m) }
|
86
|
+
end
|
78
87
|
|
79
|
-
|
80
|
-
|
81
|
-
|
88
|
+
results = results.keys.sort.reduce([]) do |c, key|
|
89
|
+
c += results[key].sort_by(&:filename)
|
90
|
+
end
|
82
91
|
|
83
|
-
|
92
|
+
results.sort_by!(&:filename)
|
93
|
+
results
|
94
|
+
end
|
84
95
|
end
|
85
96
|
end
|
86
97
|
|
@@ -95,9 +106,9 @@ class Condenser
|
|
95
106
|
end
|
96
107
|
end
|
97
108
|
|
98
|
-
def find(filename, base=nil, accept: nil
|
109
|
+
def find(filename, base=nil, accept: nil)
|
99
110
|
build do
|
100
|
-
|
111
|
+
resolve(filename, base, accept: accept).first
|
101
112
|
end
|
102
113
|
end
|
103
114
|
|
@@ -123,13 +134,22 @@ class Condenser
|
|
123
134
|
def build
|
124
135
|
@build_cc += 1
|
125
136
|
if @build_cc == 1
|
126
|
-
|
137
|
+
# if @file_watcher_active
|
138
|
+
# sleep 0.25 #if !@build_cache_polling # Let the Listen gem flush
|
139
|
+
build_cache.semaphore.lock
|
140
|
+
# else
|
141
|
+
# @build_cache = {}
|
142
|
+
# end
|
127
143
|
end
|
128
144
|
yield
|
129
145
|
ensure
|
130
146
|
@build_cc -= 1
|
131
147
|
if @build_cc == 0
|
132
|
-
|
148
|
+
# if @file_watcher_active
|
149
|
+
build_cache.semaphore.unlock
|
150
|
+
# else
|
151
|
+
# @build_cache = nil
|
152
|
+
# end
|
133
153
|
end
|
134
154
|
end
|
135
155
|
|
@@ -6,7 +6,7 @@ class Condenser::SassTransformer
|
|
6
6
|
env = options[:condenser][:environment]
|
7
7
|
accept = extensions.keys.map { |x| options[:condenser][:environment].extensions[x] }
|
8
8
|
|
9
|
-
options[:asset][:
|
9
|
+
options[:asset][:process_dependencies] << [name, accept.map{ |i| [i] }]
|
10
10
|
|
11
11
|
imports = []
|
12
12
|
env.resolve(name, accept: accept).sort_by(&:filename).each do |asset|
|
data/lib/condenser/version.rb
CHANGED
data/test/cache_test.rb
CHANGED
@@ -116,4 +116,76 @@ class CacheTest < ActiveSupport::TestCase
|
|
116
116
|
JS
|
117
117
|
|
118
118
|
end
|
119
|
+
|
120
|
+
test 'a dependency is supurceeded by a new file' do
|
121
|
+
Dir.mkdir(File.join(@path, 'a'))
|
122
|
+
Dir.mkdir(File.join(@path, 'b'))
|
123
|
+
@env.clear_path
|
124
|
+
@env.append_path File.join(@path, 'a')
|
125
|
+
@env.append_path File.join(@path, 'b')
|
126
|
+
|
127
|
+
file 'b/dep.js', <<-JS
|
128
|
+
console.log( 5 );
|
129
|
+
JS
|
130
|
+
|
131
|
+
file 'a/a.js', <<-JS
|
132
|
+
import 'dep';
|
133
|
+
JS
|
134
|
+
|
135
|
+
assert_exported_file 'a.js', 'application/javascript', <<~JS
|
136
|
+
!function(){"use strict";console.log(5)}();
|
137
|
+
JS
|
138
|
+
|
139
|
+
file 'a/dep.js', <<-JS
|
140
|
+
console.log( 10 );
|
141
|
+
JS
|
142
|
+
|
143
|
+
assert_exported_file 'a.js', 'application/javascript', <<~JS
|
144
|
+
!function(){"use strict";console.log(10)}();
|
145
|
+
JS
|
146
|
+
end
|
147
|
+
|
148
|
+
test 'a globed dependency is supurceeded by a new file' do
|
149
|
+
Dir.mkdir(File.join(@path, 'a'))
|
150
|
+
Dir.mkdir(File.join(@path, 'b'))
|
151
|
+
@env.clear_path
|
152
|
+
@env.append_path File.join(@path, 'a')
|
153
|
+
@env.append_path File.join(@path, 'b')
|
154
|
+
|
155
|
+
file 'b/deps/dep.js', <<-JS
|
156
|
+
console.log( 5 );
|
157
|
+
JS
|
158
|
+
|
159
|
+
file 'a/a.js', <<-JS
|
160
|
+
import 'deps/*';
|
161
|
+
JS
|
162
|
+
|
163
|
+
assert_exported_file 'a.js', 'application/javascript', <<~JS
|
164
|
+
!function(){"use strict";console.log(5)}();
|
165
|
+
JS
|
166
|
+
|
167
|
+
file 'a/deps/dep.js', <<-JS
|
168
|
+
console.log( 10 );
|
169
|
+
JS
|
170
|
+
|
171
|
+
assert_exported_file 'a.js', 'application/javascript', <<~JS
|
172
|
+
!function(){"use strict";console.log(10)}();
|
173
|
+
JS
|
174
|
+
end
|
175
|
+
|
176
|
+
test 'a new dependency for a glob call is reflected in the next call' do
|
177
|
+
file "dir/a.scss", "body { color: blue; }"
|
178
|
+
file 'test.scss', '@import "dir/*"'
|
179
|
+
|
180
|
+
assert_exported_file 'test.css', 'text/css', <<~CSS
|
181
|
+
body{color:blue}
|
182
|
+
CSS
|
183
|
+
|
184
|
+
file "dir/b.scss", "body { color: green; }"
|
185
|
+
|
186
|
+
assert_exported_file 'test.css', 'text/css', <<~CSS
|
187
|
+
body{color:blue}body{color:green}
|
188
|
+
CSS
|
189
|
+
end
|
190
|
+
|
119
191
|
end
|
data/test/test_helper.rb
CHANGED
@@ -30,7 +30,7 @@ Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
|
30
30
|
class ActiveSupport::TestCase
|
31
31
|
|
32
32
|
def setup
|
33
|
-
@path = Dir.mktmpdir
|
33
|
+
@path = File.realpath(Dir.mktmpdir)
|
34
34
|
@env = Condenser.new(@path, logger: Logger.new('/dev/null'))
|
35
35
|
@env.context_class.class_eval do
|
36
36
|
def asset_path(path, options = {})
|
@@ -104,7 +104,8 @@ class CondenserSCSSTest < ActiveSupport::TestCase
|
|
104
104
|
SCSS
|
105
105
|
|
106
106
|
asset = @env.find('c.css')
|
107
|
-
assert_equal ["a.scss", "d.scss", "b.scss"], asset.
|
107
|
+
assert_equal ["a.scss", "d.scss", "b.scss"], asset.process_dependencies.map(&:filename)
|
108
|
+
assert_equal ["a.scss", "d.scss", "b.scss"], asset.export_dependencies.map(&:filename)
|
108
109
|
end
|
109
110
|
|
110
111
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: condenser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubi
|
@@ -44,6 +44,20 @@ dependencies:
|
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '3'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: listen
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
47
61
|
- !ruby/object:Gem::Dependency
|
48
62
|
name: ruby-ejs
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -231,6 +245,7 @@ files:
|
|
231
245
|
- README.md
|
232
246
|
- lib/condenser.rb
|
233
247
|
- lib/condenser/asset.rb
|
248
|
+
- lib/condenser/build_cache.rb
|
234
249
|
- lib/condenser/cache/file_store.rb
|
235
250
|
- lib/condenser/cache/memory_store.rb
|
236
251
|
- lib/condenser/cache/null_store.rb
|