sprockets 4.3.0 → 4.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ed3bbcd2acf1e69863e6ffbf1906f4c21c9818de0125fab07af7233adb4b896
4
- data.tar.gz: bda5afe84773146933b12ea7c9789671231afa86536f12d82dd2e6df0a951bab
3
+ metadata.gz: fa95962ec0936790685d6cbc86c52ee2a18b64dd53c0fc6d4d4b2768f770c0ff
4
+ data.tar.gz: 02f7be276656a15d0307316d330995d66a020f19b432b307a00da6a0ff30e97f
5
5
  SHA512:
6
- metadata.gz: d6386915d85ef699768c8f59762cbb544e9a06840ccb1780df28ba6313aeb7e54e095c7d0a5567eb874c9e1613d1b01d6745cff747fcfdb53ba4856b99531df1
7
- data.tar.gz: e41508e003694d4500b699dfeaa8254c462d2859a477c46e63c003cf928a01586603f4fa01adf80c9a403b0fb93dfe7f0d97bf1e118ffda6201084bca541a47a
6
+ metadata.gz: 84150daf942284304aad9eba323c15c453fb5d30a9b91b121721f810a938cda9e6c81592c0693e1af8f6538b8b4a167d7c87710b50405757364ee7e4f229722a
7
+ data.tar.gz: bf5083c1c49dcca322bbc66bde199c4f6a6dbbce955d6a0200438f401739ae995147f1acbe42aebb051dd51a324a9c757005e769d48a197c420ee8ac182f2c7e
data/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprockets/blob/master/UPGRADING.md
4
4
 
5
+ # 4.4.1
6
+
7
+ - Fix the `ignore_mtime` option to be shared between environments. [#834](https://github.com/rails/sprockets/pull/834)
8
+
9
+ ## 4.4.0
10
+
11
+ - Implement `ignore_mtime` option. [#832](https://github.com/rails/sprockets/pull/832)
12
+ - Allow disabling cache limits. [#831](https://github.com/rails/sprockets/pull/831)
13
+
5
14
  ## 4.3.0
6
15
 
7
16
  - Fixed compatibility with `json` 3+.
@@ -62,14 +62,18 @@ module Sprockets
62
62
  # Returns a String digest or nil.
63
63
  def file_digest(path)
64
64
  if stat = self.stat(path)
65
- # Caveat: Digests are cached by the path's current mtime. Its possible
66
- # for a files contents to have changed and its mtime to have been
67
- # negligently reset thus appearing as if the file hasn't changed on
68
- # disk. Also, the mtime is only read to the nearest second. It's
69
- # also possible the file was updated more than once in a given second.
70
- key = UnloadedAsset.new(path, self).file_digest_key(stat.mtime.to_i)
71
- cache.fetch(key) do
65
+ if ignore_mtime
72
66
  self.stat_digest(path, stat)
67
+ else
68
+ # Caveat: Digests are cached by the path's current mtime. Its possible
69
+ # for a files contents to have changed and its mtime to have been
70
+ # negligently reset thus appearing as if the file hasn't changed on
71
+ # disk. Also, the mtime is only read to the nearest second. It's
72
+ # also possible the file was updated more than once in a given second.
73
+ key = UnloadedAsset.new(path, self).file_digest_key(stat.mtime.to_i)
74
+ cache.fetch(key) do
75
+ self.stat_digest(path, stat)
76
+ end
73
77
  end
74
78
  end
75
79
  end
@@ -36,13 +36,13 @@ module Sprockets
36
36
  #
37
37
  # root - A String path to a directory to persist cached values to.
38
38
  # max_size - A Integer of the maximum size the store will hold (in bytes).
39
- # (default: 25MB).
39
+ # (default: 25MB). Can be set to +false+ for no limit.
40
40
  # logger - The logger to which some info will be printed.
41
41
  # (default logger level is FATAL and won't output anything).
42
42
  def initialize(root, max_size = DEFAULT_MAX_SIZE, logger = self.class.default_logger)
43
43
  @root = root
44
44
  @max_size = max_size
45
- @gc_size = max_size * 0.75
45
+ @gc_size = max_size * 0.75 if max_size
46
46
  @logger = logger
47
47
  end
48
48
 
@@ -111,11 +111,13 @@ module Sprockets
111
111
  # Write data
112
112
  PathUtils.atomic_write(path) do |f|
113
113
  f.write(raw)
114
- @size = size + f.size unless exists
114
+ if defined?(@size) && !exists
115
+ @size += f.size
116
+ end
115
117
  end
116
118
 
117
119
  # GC if necessary
118
- gc! if size > @max_size
120
+ gc! if @max_size && size > @max_size
119
121
 
120
122
  value
121
123
  end
@@ -18,7 +18,7 @@ module Sprockets
18
18
  # Public: Initialize the cache store.
19
19
  #
20
20
  # max_size - A Integer of the maximum number of keys the store will hold.
21
- # (default: 1000).
21
+ # (default: 1000). Can be set to +false+ for no limit.
22
22
  def initialize(max_size = DEFAULT_MAX_SIZE)
23
23
  @max_size = max_size
24
24
  @cache = {}
@@ -56,7 +56,7 @@ module Sprockets
56
56
  @mutex.synchronize do
57
57
  @cache.delete(key)
58
58
  @cache[key] = value
59
- @cache.shift if @cache.size > @max_size
59
+ @cache.shift if @max_size && @cache.size > @max_size
60
60
  end
61
61
  value
62
62
  end
@@ -67,6 +67,19 @@ module Sprockets
67
67
  self.config = config.merge(digest_class: klass).freeze
68
68
  end
69
69
 
70
+ def ignore_mtime
71
+ config[:ignore_mtime]
72
+ end
73
+
74
+ # By default sprockets tries to quickly revalidate the cache for a source file
75
+ # by comparing its last modified time.
76
+ # This is efficient in development, but in some CI or producton environments
77
+ # where the source files are restored from version control, the last modified time
78
+ # tend to be somewhat random, and checking it is just needless overhead.
79
+ def ignore_mtime=(ignore_mtime)
80
+ self.config = config.merge(ignore_mtime: ignore_mtime).freeze
81
+ end
82
+
70
83
  # This class maybe mutated and mixed in with custom helpers.
71
84
  #
72
85
  # environment.context_class.instance_eval do
@@ -91,6 +91,8 @@ module Sprockets
91
91
  SEPARATOR_PATTERN = "#{Regexp.quote(File::SEPARATOR)}"
92
92
  end
93
93
 
94
+ RELATIVE_PATH_PATTERN = /^\.\.?($|#{SEPARATOR_PATTERN})/
95
+
94
96
  # Public: Check if path is explicitly relative.
95
97
  # Starts with "./" or "../".
96
98
  #
@@ -98,7 +100,7 @@ module Sprockets
98
100
  #
99
101
  # Returns true if path is relative, otherwise false.
100
102
  def relative_path?(path)
101
- path.match?(/^\.\.?($|#{SEPARATOR_PATTERN})/) ? true : false
103
+ path.match?(RELATIVE_PATH_PATTERN) ? true : false
102
104
  end
103
105
 
104
106
  # Public: Get relative path from `start` to `dest`.
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Sprockets
3
- VERSION = "4.3.0"
3
+ VERSION = "4.4.1"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
4
+ version: 4.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Stephenson