condenser 0.0.11 → 0.0.12
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/build_cache.rb +51 -44
- data/lib/condenser/resolve.rb +4 -12
- data/lib/condenser/version.rb +1 -1
- data/test/manifest_test.rb +1 -2
- data/test/test_helper.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31107c23d48e2044816158df8cc737fdea156e2227763f4ad1409dcc36406388
|
4
|
+
data.tar.gz: 3936450c32a7340a50345cc389351c2894b3263ca7e1c8f54563336a0977a445
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cf137d71f65b067b88e480756b74814e9e88df0342574fc7f466b87aa64515433a9c1dbf827c49aa1d816d20c0c640be6a97d55dba814aeeceade3ed200e37b
|
7
|
+
data.tar.gz: cf154ab552d503a93ce487f1c7f9561faa07391c7e29d7190a66ca7e3bd9c6a842dd574193720484a84bcfba6430be58665f141519c5a4b024621169c4c89fe7
|
@@ -1,71 +1,78 @@
|
|
1
|
-
require 'listen'
|
2
|
-
|
3
1
|
class Condenser
|
4
2
|
class BuildCache
|
5
3
|
|
6
|
-
attr_reader :semaphore
|
4
|
+
attr_reader :semaphore, :listening
|
7
5
|
|
8
|
-
def initialize(path)
|
6
|
+
def initialize(path, listen: {})
|
9
7
|
@path = path
|
10
|
-
@semaphore = Mutex.new
|
11
|
-
@polling = Listen::Adapter.select == Listen::Adapter::Polling
|
12
8
|
@map_cache = {}
|
13
9
|
@lookup_cache = {}
|
14
10
|
@process_dependencies = {}
|
15
11
|
@export_dependencies = {}
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
12
|
+
@listening = if listen
|
13
|
+
require 'listen'
|
14
|
+
Listen::Adapter.select != Listen::Adapter::Polling
|
15
|
+
else
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
if !@listening
|
20
|
+
@polling = false
|
21
|
+
else
|
22
|
+
@semaphore = Mutex.new
|
23
|
+
@listener = Listen.to(*path) do |modified, added, removed|
|
24
|
+
@semaphore.synchronize do
|
25
|
+
added = added.reduce([]) do |rt, added_file|
|
26
|
+
rt << added_file.match(/([^\.]+)(\.|$)/).to_a[1]
|
27
|
+
if path_match = @path.find { |p| added_file.start_with?(p) }
|
28
|
+
a = added_file.delete_prefix(path_match).match(/([^\.]+)(\.|$)/).to_a[1]
|
29
|
+
b = (File.dirname(a) + "/*")
|
24
30
|
|
25
|
-
|
26
|
-
|
31
|
+
rt << a << a.delete_prefix('/')
|
32
|
+
rt << a << b.delete_prefix('/')
|
33
|
+
end
|
27
34
|
end
|
28
|
-
end
|
29
35
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
36
|
+
removed.each do |file|
|
37
|
+
@map_cache&.delete_if do |k,v|
|
38
|
+
v.source_file == file
|
39
|
+
end
|
34
40
|
|
35
|
-
|
36
|
-
|
37
|
-
|
41
|
+
@process_dependencies[file]&.delete_if do |asset|
|
42
|
+
asset.source_file == file
|
43
|
+
end
|
38
44
|
|
39
|
-
|
40
|
-
|
45
|
+
@export_dependencies[file]&.delete_if do |asset|
|
46
|
+
asset.source_file == file
|
47
|
+
end
|
41
48
|
end
|
42
|
-
end
|
43
49
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
50
|
+
@lookup_cache.delete_if do |key, value|
|
51
|
+
if added.any?{ |a| key.starts_with?(a) }
|
52
|
+
value.each do |asset|
|
53
|
+
modified << asset.source_file
|
54
|
+
end
|
55
|
+
true
|
48
56
|
end
|
49
|
-
true
|
50
57
|
end
|
51
|
-
|
52
|
-
|
53
|
-
added.any?{ |a| k.starts_with?(a) }
|
54
|
-
end
|
55
|
-
|
56
|
-
modified.each do |file|
|
57
|
-
@process_dependencies[file]&.each do |asset|
|
58
|
-
asset.needs_reprocessing!
|
58
|
+
@map_cache&.delete_if do |k,v|
|
59
|
+
added.any?{ |a| k.starts_with?(a) }
|
59
60
|
end
|
61
|
+
|
62
|
+
modified.each do |file|
|
63
|
+
@process_dependencies[file]&.each do |asset|
|
64
|
+
asset.needs_reprocessing!
|
65
|
+
end
|
60
66
|
|
61
|
-
|
62
|
-
|
67
|
+
@export_dependencies[file]&.each do |asset|
|
68
|
+
asset.needs_reexporting!
|
69
|
+
end
|
63
70
|
end
|
64
|
-
end
|
65
71
|
|
72
|
+
end
|
66
73
|
end
|
74
|
+
@listener.start
|
67
75
|
end
|
68
|
-
@listener.start
|
69
76
|
end
|
70
77
|
|
71
78
|
def map(key)
|
data/lib/condenser/resolve.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
class Condenser
|
2
2
|
module Resolve
|
3
3
|
|
4
|
-
def initialize(*args)
|
4
|
+
def initialize(*args, **kws, &block)
|
5
5
|
@reverse_mapping = nil
|
6
|
+
@build_cache_options = kws[:listen]
|
6
7
|
super
|
7
8
|
end
|
8
9
|
|
@@ -134,22 +135,13 @@ class Condenser
|
|
134
135
|
def build
|
135
136
|
@build_cc += 1
|
136
137
|
if @build_cc == 1
|
137
|
-
|
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
|
138
|
+
build_cache.semaphore.lock if build_cache.listening
|
143
139
|
end
|
144
140
|
yield
|
145
141
|
ensure
|
146
142
|
@build_cc -= 1
|
147
143
|
if @build_cc == 0
|
148
|
-
|
149
|
-
build_cache.semaphore.unlock
|
150
|
-
# else
|
151
|
-
# @build_cache = nil
|
152
|
-
# end
|
144
|
+
build_cache.semaphore.unlock if build_cache.listening
|
153
145
|
end
|
154
146
|
end
|
155
147
|
|
data/lib/condenser/version.rb
CHANGED
data/test/manifest_test.rb
CHANGED
@@ -262,9 +262,8 @@ class ManifestTest < ActiveSupport::TestCase
|
|
262
262
|
assert_equal digest_path, data['application.js']['path']
|
263
263
|
|
264
264
|
File.write(File.join(@path, 'application.js'), "console.log(2);")
|
265
|
+
sleep 0.25 if @env.build_cache.listening
|
265
266
|
|
266
|
-
# mtime = Time.now + 1
|
267
|
-
# File.utime(mtime, mtime, filename)
|
268
267
|
new_digest_path = @env['application.js'].path
|
269
268
|
assert_not_equal new_digest_path, digest_path
|
270
269
|
|
data/test/test_helper.rb
CHANGED
@@ -60,6 +60,7 @@ class ActiveSupport::TestCase
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def assert_file(path, mime_types, source=nil)
|
63
|
+
sleep 0.25 if @env.build_cache.listening
|
63
64
|
asset = @env.find(path)
|
64
65
|
assert asset, "Couldn't find asset \"#{path}\""
|
65
66
|
asset.process
|
@@ -69,6 +70,7 @@ class ActiveSupport::TestCase
|
|
69
70
|
end
|
70
71
|
|
71
72
|
def assert_exported_file(path, mime_types, source=nil)
|
73
|
+
sleep 0.25 if @env.build_cache.listening
|
72
74
|
asset = @env.find(path)
|
73
75
|
assert asset, "Couldn't find asset \"#{path}\""
|
74
76
|
asset = asset.export
|