condenser 0.0.12 → 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,7 @@ class Condenser
9
9
 
10
10
  def build_cache
11
11
  return @build_cache if instance_variable_defined?(:@build_cache)
12
- @build_cache = BuildCache.new(path)
12
+ @build_cache = BuildCache.new(path, logger: logger)
13
13
  end
14
14
 
15
15
  def resolve(filename, base=nil, accept: nil)
@@ -20,7 +20,6 @@ class Condenser
20
20
 
21
21
  cache_key = [dirname, basename].flatten.join('/')
22
22
  cache_key << "@#{accept.join(',')}" if accept
23
-
24
23
  build_cache.fetch(cache_key) do
25
24
  build do
26
25
  results = []
@@ -52,7 +51,7 @@ class Condenser
52
51
  asset_dir = f_dirname.delete_prefix(path).delete_prefix('/')
53
52
  asset_basename = f_basename + f_extensions.join('')
54
53
  asset_filename = asset_dir.empty? ? asset_basename : File.join(asset_dir, asset_basename)
55
- results << build_cache.map(asset_filename + f_mime_types.join('')) do
54
+ results << build_cache.map("#{asset_filename}@#{f_mime_types.join('')}") do
56
55
  Asset.new(self, {
57
56
  filename: asset_filename,
58
57
  content_types: f_mime_types,
@@ -66,7 +65,7 @@ class Condenser
66
65
  asset_dir = f_dirname.delete_prefix(path).delete_prefix('/')
67
66
  asset_basename = f_basename + derivative_mime_types.map { |t| @mime_types[t][:extensions].first }.join('')
68
67
  asset_filename = asset_dir.empty? ? asset_basename : File.join(asset_dir, asset_basename)
69
- results << build_cache.map(asset_filename + derivative_mime_types.join('')) do
68
+ results << build_cache.map("#{asset_filename}@#{derivative_mime_types.join('')}") do
70
69
  Asset.new(self, {
71
70
  filename: asset_filename,
72
71
  content_types: derivative_mime_types,
@@ -133,15 +132,20 @@ class Condenser
133
132
  end
134
133
 
135
134
  def build
136
- @build_cc += 1
137
- if @build_cc == 1
138
- build_cache.semaphore.lock if build_cache.listening
135
+ if build_cache.listening && !build_cache.semaphore.owned?
136
+ build_cache.semaphore.lock
137
+ logger.debug { "build cache semaphore locked by #{Thread.current.object_id}" }
139
138
  end
139
+
140
+ @build_cc += 1
140
141
  yield
141
142
  ensure
142
143
  @build_cc -= 1
143
144
  if @build_cc == 0
144
- build_cache.semaphore.unlock if build_cache.listening
145
+ if build_cache.listening && build_cache.semaphore.owned?
146
+ logger.debug { "build cache semaphore unlocked by #{Thread.current.object_id}" }
147
+ build_cache.semaphore.unlock
148
+ end
145
149
  end
146
150
  end
147
151
 
@@ -1,3 +1,3 @@
1
1
  class Condenser
2
- VERSION = '0.0.12'
2
+ VERSION = '0.1'
3
3
  end
@@ -188,4 +188,20 @@ class CacheTest < ActiveSupport::TestCase
188
188
  CSS
189
189
  end
190
190
 
191
+ test 'a dependency is removed for a glob call when one of it dependencies is delted' do
192
+ file "css/a.scss", "body { color: blue; }"
193
+ file "css/b.scss", "body { color: green; }"
194
+ file 'test.scss', '@import "css/*"'
195
+
196
+ assert_exported_file 'test.css', 'text/css', <<~CSS
197
+ body{color:blue}body{color:green}
198
+ CSS
199
+
200
+ rm "css/b.scss"
201
+
202
+ assert_exported_file 'test.css', 'text/css', <<~CSS
203
+ body{color:blue}
204
+ CSS
205
+ end
206
+
191
207
  end
@@ -31,7 +31,7 @@ class ActiveSupport::TestCase
31
31
 
32
32
  def setup
33
33
  @path = File.realpath(Dir.mktmpdir)
34
- @env = Condenser.new(@path, logger: Logger.new('/dev/null'))
34
+ @env = Condenser.new(@path, logger: Logger.new('/dev/null', level: :debug))
35
35
  @env.context_class.class_eval do
36
36
  def asset_path(path, options = {})
37
37
  "/assets/#{path}"
@@ -59,6 +59,10 @@ class ActiveSupport::TestCase
59
59
  File.write(path, source)
60
60
  end
61
61
 
62
+ def rm(name)
63
+ File.delete(File.join(@path, name))
64
+ end
65
+
62
66
  def assert_file(path, mime_types, source=nil)
63
67
  sleep 0.25 if @env.build_cache.listening
64
68
  asset = @env.find(path)
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.12
4
+ version: '0.1'
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-13 00:00:00.000000000 Z
11
+ date: 2020-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubi