asset_sync 2.18.1 → 2.19.0

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: 1fb2743cc1cc656c27c392c0a4f6cd5cc07e57ed8dad28fc1ed9f01b268d6d42
4
- data.tar.gz: 13067af05b7e16f1a12c62db2583f56ec5e995414d86e193110339efde7f8e16
3
+ metadata.gz: 9cdf3c86a21ba63d0de80b07420b5c4f1833f25dbbcefbc92a740599d2d166da
4
+ data.tar.gz: a4c394ecc38feadf42e70643c7485a9dc68d6cccb9e86d8c9d00b99f41e5064f
5
5
  SHA512:
6
- metadata.gz: 57189c1fb4dbd6edab1f5cc262f6ef420f144631adf69d03fc504218018de8765ce15e9d8e38e19eacf4eb825d3ec46b1311cf492939fc537c30554ba26dbd99
7
- data.tar.gz: 56eba25178ac8ee2a51222bfbd46342dc8836e67d52ea255000a710a341b158bee5043969574d111779c589f9223137a2c9a4ed9a1a259adb595ddaa9fd87b40
6
+ metadata.gz: 1cf38f1aa03aa20864cd1b6afadffff78bb032cfe7f15bea92c3f196c034c603d2a1d79e4393ace6f9fda35b8759b2ac5108efb86c9fdf260b898478fc0c3a2f
7
+ data.tar.gz: b26de287f9164b653e7404723672bd746cf899c57df8ed2b7100ba5a1470f0ca6619d6e7ed9b3bbb1c12f6af358e30665e449f4cfc235ff9db55b2b52c179c1a
data/CHANGELOG.md CHANGED
@@ -18,6 +18,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
18
18
  - Nothing
19
19
 
20
20
 
21
+ ## [2.19.0] - 2023-08-15
22
+
23
+ ### Added
24
+
25
+ - Add brotli support (new option `compression` which supports both gzip/brotli to replace now deprecated `gzip_compression`)
26
+ (https://github.com/AssetSync/asset_sync/pull/435)
27
+
28
+
21
29
  ## [2.18.1] - 2023-08-02
22
30
 
23
31
  ### Changed
@@ -1086,7 +1094,8 @@ Changes:
1086
1094
  * Merge branch 'sinatra'
1087
1095
 
1088
1096
 
1089
- [Unreleased]: https://github.com/AssetSync/asset_sync/compare/v2.18.1...HEAD
1097
+ [Unreleased]: https://github.com/AssetSync/asset_sync/compare/v2.19.0...HEAD
1098
+ [2.19.0]: https://github.com/AssetSync/asset_sync/compare/v2.18.1...v2.19.0
1090
1099
  [2.18.1]: https://github.com/AssetSync/asset_sync/compare/v2.18.0...v2.18.1
1091
1100
  [2.18.0]: https://github.com/AssetSync/asset_sync/compare/v2.17.0...v2.18.0
1092
1101
  [2.17.0]: https://github.com/AssetSync/asset_sync/compare/v2.16.0...v2.17.0
data/README.md CHANGED
@@ -165,7 +165,7 @@ heroku config:add FOG_DIRECTORY=xxxx
165
165
  heroku config:add FOG_PROVIDER=AWS
166
166
  # and optionally:
167
167
  heroku config:add FOG_REGION=eu-west-1
168
- heroku config:add ASSET_SYNC_GZIP_COMPRESSION=true
168
+ heroku config:add ASSET_SYNC_COMPRESSION=gz
169
169
  heroku config:add ASSET_SYNC_MANIFEST=true
170
170
  heroku config:add ASSET_SYNC_EXISTING_REMOTE_FILES=keep
171
171
  ```
@@ -260,8 +260,8 @@ AssetSync.configure do |config|
260
260
  # Overrides any existing value (even those set by AssetSync)
261
261
  # config.fog_options = {}
262
262
  #
263
- # Automatically replace files with their equivalent gzip compressed version
264
- # config.gzip_compression = true
263
+ # Automatically replace files with their equivalent gzip/brotli compressed version
264
+ # config.compression = 'gz'
265
265
  #
266
266
  # Use the Rails generated 'manifest.yml' file to produce the list of files to
267
267
  # upload instead of searching the assets directory.
@@ -340,8 +340,8 @@ defaults: &defaults
340
340
  # existing_remote_files: delete
341
341
  # To ignore existing remote files and overwrite.
342
342
  # existing_remote_files: ignore
343
- # Automatically replace files with their equivalent gzip compressed version
344
- # gzip_compression: true
343
+ # Automatically replace files with their equivalent gzip/brotli compressed version
344
+ # compression: "gz"
345
345
  # Fail silently. Useful for environments such as Heroku
346
346
  # fail_silently: true
347
347
  # Always upload. Useful if you want to overwrite specific remote assets regardless of their existence
@@ -379,13 +379,14 @@ AssetSync.config.fog_provider == ENV['FOG_PROVIDER']
379
379
  Simply **upcase** the ruby attribute names to get the equivalent environment variable to set. The only exception to that rule are the internal **AssetSync** config variables, they must be prepended with `ASSET_SYNC_*` e.g.
380
380
 
381
381
  ```ruby
382
- AssetSync.config.gzip_compression == ENV['ASSET_SYNC_GZIP_COMPRESSION']
382
+ AssetSync.config.compression == ENV['ASSET_SYNC_COMPRESSION']
383
383
  ```
384
384
 
385
385
  #### AssetSync (optional)
386
386
 
387
387
  * **existing_remote_files**: (`'keep', 'delete', 'ignore'`) what to do with previously precompiled files. **default:** `'keep'`
388
- * **gzip\_compression**: (`true, false`) when enabled, will automatically replace files that have a gzip compressed equivalent with the compressed version. **default:** `'false'`
388
+ * **gzip\_compression**: (deprecated, can still be used but use `compression` when possible)
389
+ * **compression**: (`'gz', 'br'`) when enabled (non `nil` value set), will automatically replace files that have a gzip/brotli compressed equivalent with the compressed version. **default:** `nil`
389
390
  * **manifest**: (`true, false`) when enabled, will use the `manifest.yml` generated by Rails to get the list of local files to upload. **experimental**. **default:** `'false'`
390
391
  * **include_manifest**: (`true, false`) when enabled, will upload the `manifest.yml` generated by Rails. **default:** `'false'`
391
392
  * **concurrent_uploads**: (`true, false`) when enabled, will upload the files in different Threads, this greatly improves the upload speed. **default:** `'false'`
@@ -540,12 +541,17 @@ end
540
541
  ```
541
542
 
542
543
 
543
- ## Automatic gzip compression
544
+ ## Automatic gzip/brotli compression
544
545
 
545
- With the `gzip_compression` option enabled, when uploading your assets. If a file has a gzip compressed equivalent we will replace that asset with the compressed version and sets the correct headers for S3 to serve it. For example, if you have a file **master.css** and it was compressed to **master.css.gz** we will upload the **.gz** file to S3 in place of the uncompressed file.
546
+ With the `compression` option enabled, when uploading your assets. If a file has a gzip/brotli (only 1 of them, depending on the option value set) compressed equivalent we will replace that asset with the compressed version and sets the correct headers for S3 to serve it. For example, if you have a file **master.css** and it was compressed to **master.css.gz** we will upload the **.gz** file to S3 in place of the uncompressed file.
546
547
 
547
548
  If the compressed file is actually larger than the uncompressed file we will ignore this rule and upload the standard uncompressed version.
548
549
 
550
+ Option `compression` supported values:
551
+ - `nil` => Disabled
552
+ - `'gz'` => Only consider gzip compressed one
553
+ - `'br'` => Only consider brotli compressed one
554
+
549
555
  ## Fail Silently
550
556
 
551
557
  With the `fail_silently` option enabled, when running `rake assets:precompile` AssetSync will never throw an error due to missing configuration variables.
@@ -11,7 +11,7 @@ module AssetSync
11
11
 
12
12
  # AssetSync
13
13
  attr_accessor :existing_remote_files # What to do with your existing remote files? (keep or delete)
14
- attr_accessor :gzip_compression
14
+ attr_accessor :compression
15
15
  attr_accessor :manifest
16
16
  attr_accessor :fail_silently
17
17
  attr_accessor :log_silently
@@ -94,7 +94,7 @@ module AssetSync
94
94
  self.fog_region = nil
95
95
  self.fog_public = true
96
96
  self.existing_remote_files = 'keep'
97
- self.gzip_compression = false
97
+ self.compression = nil
98
98
  self.manifest = false
99
99
  self.fail_silently = false
100
100
  self.log_silently = true
@@ -126,8 +126,12 @@ module AssetSync
126
126
  end
127
127
  end
128
128
 
129
- def gzip?
130
- self.gzip_compression
129
+ def gzip_compression= bool
130
+ if bool
131
+ self.compression = 'gz'
132
+ else
133
+ self.compression = nil
134
+ end
131
135
  end
132
136
 
133
137
  def existing_remote_files?
@@ -246,7 +250,8 @@ module AssetSync
246
250
  self.google_storage_access_key_id = yml["google_storage_access_key_id"] if yml.has_key?("google_storage_access_key_id")
247
251
  self.google_json_key_string = yml["google_json_key_string"] if yml.has_key?("google_json_key_string")
248
252
  self.existing_remote_files = yml["existing_remote_files"] if yml.has_key?("existing_remote_files")
249
- self.gzip_compression = yml["gzip_compression"] if yml.has_key?("gzip_compression")
253
+ self.compression = 'gz' if yml.has_key?("gzip_compression")
254
+ self.compression = yml["compression"] if yml.has_key?("compression")
250
255
  self.manifest = yml["manifest"] if yml.has_key?("manifest")
251
256
  self.fail_silently = yml["fail_silently"] if yml.has_key?("fail_silently")
252
257
  self.log_silently = yml["log_silently"] if yml.has_key?("log_silently")
@@ -44,7 +44,8 @@ module AssetSync
44
44
  config.enabled = (ENV['ASSET_SYNC_ENABLED'] == 'true') if ENV.has_key?('ASSET_SYNC_ENABLED')
45
45
 
46
46
  config.existing_remote_files = ENV['ASSET_SYNC_EXISTING_REMOTE_FILES'] || "keep"
47
- config.gzip_compression = (ENV['ASSET_SYNC_GZIP_COMPRESSION'] == 'true') if ENV.has_key?('ASSET_SYNC_GZIP_COMPRESSION')
47
+ config.compression = 'gz' if ENV.has_key?('ASSET_SYNC_GZIP_COMPRESSION') && ENV['ASSET_SYNC_GZIP_COMPRESSION'] == 'true'
48
+ config.compression = ENV['ASSET_SYNC_COMPRESSION'] if ENV.has_key?('ASSET_SYNC_COMPRESSION')
48
49
  config.manifest = (ENV['ASSET_SYNC_MANIFEST'] == 'true') if ENV.has_key?('ASSET_SYNC_MANIFEST')
49
50
  config.prefix = ENV['ASSET_SYNC_PREFIX'] if ENV.has_key?('ASSET_SYNC_PREFIX')
50
51
  config.include_manifest = (ENV['ASSET_SYNC_INCLUDE_MANIFEST'] == 'true') if ENV.has_key?('ASSET_SYNC_INCLUDE_MANIFEST')
@@ -7,6 +7,11 @@ module AssetSync
7
7
  REGEXP_FINGERPRINTED_FILES = /\A(.*)\/(.+)-[^\.]+\.([^\.]+)\z/m
8
8
  REGEXP_ASSETS_TO_CACHE_CONTROL = /-[0-9a-fA-F]{32,}$/
9
9
 
10
+ CONTENT_ENCODING = {
11
+ 'gz' => 'gzip',
12
+ 'br' => 'br',
13
+ }.freeze
14
+
10
15
  class BucketNotFound < StandardError;
11
16
  end
12
17
 
@@ -211,7 +216,7 @@ module AssetSync
211
216
  one_year = 31557600
212
217
  ext = File.extname(f)[1..-1]
213
218
  mime = MultiMime.lookup(ext)
214
- gzip_file_handle = nil
219
+ compressed_file_handle = nil
215
220
  file_handle = File.open("#{path}/#{f}")
216
221
  file = {
217
222
  :key => f,
@@ -255,41 +260,44 @@ module AssetSync
255
260
  end
256
261
 
257
262
 
258
- gzipped = "#{path}/#{f}.gz"
259
263
  ignore = false
260
-
261
- if config.gzip? && File.extname(f) == ".gz"
262
- # Don't bother uploading gzipped assets if we are in gzip_compression mode
263
- # as we will overwrite file.css with file.css.gz if it exists.
264
- log "Ignoring: #{f}"
265
- ignore = true
266
- elsif config.gzip? && File.exist?(gzipped)
267
- original_size = File.size("#{path}/#{f}")
268
- gzipped_size = File.size(gzipped)
269
-
270
- if gzipped_size < original_size
271
- percentage = ((gzipped_size.to_f/original_size.to_f)*100).round(2)
272
- gzip_file_handle = File.open(gzipped)
273
- file.merge!({
274
- :key => f,
275
- :body => gzip_file_handle,
276
- :content_encoding => 'gzip'
277
- })
278
- log "Uploading: #{gzipped} in place of #{f} saving #{percentage}%"
279
- else
280
- percentage = ((original_size.to_f/gzipped_size.to_f)*100).round(2)
281
- log "Uploading: #{f} instead of #{gzipped} (compression increases this file by #{percentage}%)"
264
+ if config.compression
265
+ compressed_name = "#{path}/#{f}.#{config.compression}"
266
+
267
+ if File.extname(f) == config.compression
268
+ # Don't bother uploading compressed assets if we are in compression mode
269
+ # as we will overwrite file.css with file.css.gz if it exists.
270
+ log "Ignoring: #{f}"
271
+ ignore = true
272
+ elsif File.exist?(compressed)
273
+ original_size = File.size("#{path}/#{f}")
274
+ compressed_size = File.size(compressed_name)
275
+
276
+ if compressed_size < original_size
277
+ percentage = ((compressed_size.to_f/original_size.to_f)*100).round(2)
278
+ compressed_file_handle = File.open(compressed_name)
279
+ file.merge!({
280
+ :key => f,
281
+ :body => compressed_file_handle,
282
+ :content_encoding => CONTENT_ENCODING[config.compression]
283
+ })
284
+ log "Uploading: #{compressed_name} in place of #{f} saving #{percentage}%"
285
+ else
286
+ percentage = ((original_size.to_f/compressed_size.to_f)*100).round(2)
287
+ log "Uploading: #{f} instead of #{compressed_name} (compression increases this file by #{percentage}%)"
288
+ end
282
289
  end
283
290
  else
284
- if !config.gzip? && File.extname(f) == ".gz"
285
- # set content encoding for gzipped files this allows cloudfront to properly handle requests with Accept-Encoding
291
+ compressed_encoding = CONTENT_ENCODING[File.extname(f).delete('.')]
292
+ if compressed_encoding
293
+ # set content encoding for compressed files this allows cloudfront to properly handle requests with Accept-Encoding
286
294
  # http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html
287
295
  uncompressed_filename = f[0..-4]
288
296
  ext = File.extname(uncompressed_filename)[1..-1]
289
297
  mime = MultiMime.lookup(ext)
290
298
  file.merge!({
291
299
  :content_type => mime,
292
- :content_encoding => 'gzip'
300
+ :content_encoding => compressed_encoding
293
301
  })
294
302
  end
295
303
  log "Uploading: #{f}"
@@ -303,7 +311,7 @@ module AssetSync
303
311
 
304
312
  bucket.files.create( file ) unless ignore
305
313
  file_handle.close
306
- gzip_file_handle.close if gzip_file_handle
314
+ compressed_file_handle.close if compressed_file_handle
307
315
  end
308
316
 
309
317
  def upload_files
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AssetSync
4
- VERSION = "2.18.1"
4
+ VERSION = "2.19.0"
5
5
  end
@@ -59,8 +59,8 @@ describe AssetSync do
59
59
  expect(AssetSync.config.existing_remote_files).to eq("keep")
60
60
  end
61
61
 
62
- it "should default gzip_compression to false" do
63
- expect(AssetSync.config.gzip_compression).to be_falsey
62
+ it "should default compression to nil" do
63
+ expect(AssetSync.config.compression).to be_nil
64
64
  end
65
65
 
66
66
  it "should default manifest to false" do
@@ -139,8 +139,8 @@ describe AssetSync do
139
139
  expect(AssetSync.config.existing_remote_files).to eq("keep")
140
140
  end
141
141
 
142
- it "should default gzip_compression to false" do
143
- expect(AssetSync.config.gzip_compression).to be_falsey
142
+ it "should default compression to nil" do
143
+ expect(AssetSync.config.compression).to be_nil
144
144
  end
145
145
 
146
146
  it "should default manifest to false" do
@@ -230,8 +230,8 @@ describe AssetSync do
230
230
  AssetSync.config.gzip_compression = true
231
231
  end
232
232
 
233
- it "config.gzip? should be true" do
234
- expect(AssetSync.config.gzip?).to be_truthy
233
+ it "config.compression should be 'gz'" do
234
+ expect(AssetSync.config.compression).to eq("gz")
235
235
  end
236
236
  end
237
237
 
@@ -40,8 +40,8 @@ describe AssetSync do
40
40
  expect(AssetSync.config.existing_remote_files).to eq("keep")
41
41
  end
42
42
 
43
- it "should default gzip_compression to false" do
44
- expect(AssetSync.config.gzip_compression).to be_falsey
43
+ it "should default compression to nil" do
44
+ expect(AssetSync.config.compression).to be_nil
45
45
  end
46
46
 
47
47
  it "should default manifest to false" do
@@ -71,8 +71,8 @@ describe AssetSync do
71
71
  expect(AssetSync.config.existing_remote_files).to eq("keep")
72
72
  end
73
73
 
74
- it "should default gzip_compression to false" do
75
- expect(AssetSync.config.gzip_compression).to be_falsey
74
+ it "should default compression to nil" do
75
+ expect(AssetSync.config.compression).to be_nil
76
76
  end
77
77
 
78
78
  it "should default manifest to false" do
@@ -110,8 +110,8 @@ describe AssetSync do
110
110
  AssetSync.config.gzip_compression = true
111
111
  end
112
112
 
113
- it "config.gzip? should be true" do
114
- expect(AssetSync.config.gzip?).to be_truthy
113
+ it "config.compression should be 'gz'" do
114
+ expect(AssetSync.config.compression).to eq("gz")
115
115
  end
116
116
  end
117
117
 
@@ -44,8 +44,8 @@ describe AssetSync do
44
44
  expect(AssetSync.config.existing_remote_files).to eq("keep")
45
45
  end
46
46
 
47
- it "should default gzip_compression to false" do
48
- expect(AssetSync.config.gzip_compression).to be_falsey
47
+ it "should default compression to nil" do
48
+ expect(AssetSync.config.compression).to be_nil
49
49
  end
50
50
 
51
51
  it "should default manifest to false" do
@@ -79,8 +79,8 @@ describe AssetSync do
79
79
  expect(AssetSync.config.existing_remote_files).to eq("keep")
80
80
  end
81
81
 
82
- it "should default gzip_compression to false" do
83
- expect(AssetSync.config.gzip_compression).to be_falsey
82
+ it "should default compression to nil" do
83
+ expect(AssetSync.config.compression).to be_nil
84
84
  end
85
85
 
86
86
  it "should default manifest to false" do
@@ -118,8 +118,8 @@ describe AssetSync do
118
118
  AssetSync.config.gzip_compression = true
119
119
  end
120
120
 
121
- it "config.gzip? should be true" do
122
- expect(AssetSync.config.gzip?).to be_truthy
121
+ it "config.compression should be 'gz'" do
122
+ expect(AssetSync.config.compression).to eq("gz")
123
123
  end
124
124
  end
125
125
 
@@ -30,8 +30,8 @@ describe AssetSync do
30
30
  expect(AssetSync.config.existing_remote_files).to eq("keep")
31
31
  end
32
32
 
33
- it "should default gzip_compression to false" do
34
- expect(AssetSync.config.gzip_compression).to be_falsey
33
+ it "should default compression to nil" do
34
+ expect(AssetSync.config.compression).to be_nil
35
35
  end
36
36
 
37
37
  it "should default manifest to false" do
@@ -174,8 +174,8 @@ describe AssetSync do
174
174
  expect(AssetSync.config.existing_remote_files).to eq("keep")
175
175
  end
176
176
 
177
- it "should default gzip_compression to false" do
178
- expect(AssetSync.config.gzip_compression).to be_falsey
177
+ it "should default compression to nil" do
178
+ expect(AssetSync.config.compression).to be_nil
179
179
  end
180
180
 
181
181
  it "should default manifest to false" do
@@ -229,8 +229,8 @@ describe AssetSync do
229
229
  AssetSync.config.gzip_compression = true
230
230
  end
231
231
 
232
- it "config.gzip? should be true" do
233
- expect(AssetSync.config.gzip?).to be_truthy
232
+ it "config.compression should be 'gz'" do
233
+ expect(AssetSync.config.compression).to eq("gz")
234
234
  end
235
235
  end
236
236
 
@@ -61,8 +61,8 @@ describe AssetSync do
61
61
  expect(AssetSync.config.existing_remote_files).to eq("keep")
62
62
  end
63
63
 
64
- it "should default gzip_compression to false" do
65
- expect(AssetSync.config.gzip_compression).to be_falsey
64
+ it "should default compression to nil" do
65
+ expect(AssetSync.config.compression).to be_nil
66
66
  end
67
67
 
68
68
  it "should default manifest to false" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asset_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.18.1
4
+ version: 2.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Hamilton
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2023-08-02 00:00:00.000000000 Z
14
+ date: 2023-08-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: fog-core
@@ -288,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
288
288
  - !ruby/object:Gem::Version
289
289
  version: '0'
290
290
  requirements: []
291
- rubygems_version: 3.4.17
291
+ rubygems_version: 3.4.18
292
292
  signing_key:
293
293
  specification_version: 4
294
294
  summary: Synchronises Assets in a Rails 3 application and Amazon S3/Cloudfront and