condenser 0.0.11 → 0.0.12

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
  SHA256:
3
- metadata.gz: d330a97b14eba56db0e2404b7b5c8bc95880c5a17ef8886bc0fed653311dcb0f
4
- data.tar.gz: 8b67113289b161903a55be74073ad979580710fd557f5ad97c6c1e65ef903200
3
+ metadata.gz: 31107c23d48e2044816158df8cc737fdea156e2227763f4ad1409dcc36406388
4
+ data.tar.gz: 3936450c32a7340a50345cc389351c2894b3263ca7e1c8f54563336a0977a445
5
5
  SHA512:
6
- metadata.gz: df64dbbbb0ec741c7d4af17d71d4dd0e855fc82f13220775353c361ae4da0254cd233fbeb143bca2536c8331b425c67b3247151fc59214fef5a34b8c1a13880d
7
- data.tar.gz: 563064dd6255fb14cbd7bed0ae7bbc6bd64a1c019e7ed3f2837c449c05041333b5c4aca91391e918fbf8b99d4aa7e0725b120cb30819467f193ddd48347cb607
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
- @listener = Listen.to(*path) do |modified, added, removed|
18
- @semaphore.synchronize do
19
- added = added.reduce([]) do |rt, added_file|
20
- rt << added_file.match(/([^\.]+)(\.|$)/).to_a[1]
21
- if path_match = @path.find { |p| added_file.start_with?(p) }
22
- a = added_file.delete_prefix(path_match).match(/([^\.]+)(\.|$)/).to_a[1]
23
- b = (File.dirname(a) + "/*")
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
- rt << a << a.delete_prefix('/')
26
- rt << a << b.delete_prefix('/')
31
+ rt << a << a.delete_prefix('/')
32
+ rt << a << b.delete_prefix('/')
33
+ end
27
34
  end
28
- end
29
35
 
30
- removed.each do |file|
31
- @map_cache&.delete_if do |k,v|
32
- v.source_file == file
33
- end
36
+ removed.each do |file|
37
+ @map_cache&.delete_if do |k,v|
38
+ v.source_file == file
39
+ end
34
40
 
35
- @process_dependencies[file]&.delete_if do |asset|
36
- asset.source_file == file
37
- end
41
+ @process_dependencies[file]&.delete_if do |asset|
42
+ asset.source_file == file
43
+ end
38
44
 
39
- @export_dependencies[file]&.delete_if do |asset|
40
- asset.source_file == file
45
+ @export_dependencies[file]&.delete_if do |asset|
46
+ asset.source_file == file
47
+ end
41
48
  end
42
- end
43
49
 
44
- @lookup_cache.delete_if do |key, value|
45
- if added.any?{ |a| key.starts_with?(a) }
46
- value.each do |asset|
47
- modified << asset.source_file
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
- end
52
- @map_cache&.delete_if do |k,v|
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
- @export_dependencies[file]&.each do |asset|
62
- asset.needs_reexporting!
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)
@@ -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
- # 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
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
- # if @file_watcher_active
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
 
@@ -1,3 +1,3 @@
1
1
  class Condenser
2
- VERSION = '0.0.11'
2
+ VERSION = '0.0.12'
3
3
  end
@@ -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
 
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: condenser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy