sprockets 4.0.2 → 4.1.1

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: a4743994bc846327ac80bde662aa5a26fd95ce5cca2dd149deafe0fe94b6bf00
4
- data.tar.gz: 454485ef7d2c5aac60c69b7d7042ed1b74245afecfeadc72c7e9bc290dc8b5b8
3
+ metadata.gz: e5f1a2b7d847a15dff3669ec28a2248484ee0831c88017fc67fee6afe7b6a6f1
4
+ data.tar.gz: 2714999cde7d9f9340d0d7f2a98f3e48c9b46d099e36069dd380a12f6c270c54
5
5
  SHA512:
6
- metadata.gz: c6d61894b3f53a76bf1f04c3f2fe74143b33e43d5fbdc3db216bdf0ad88d06f8a73fc61bd12071ee79e8aab49b36cb14685f6bb2d86582387cbc5522cef305a3
7
- data.tar.gz: ca2bff624116f6de55ce4f9c6371be9d71245d2883c4837cf5a1b4969006fbdf8507b358c7986cccb03edb00711367538176ed2701a1e725cde1206163c64e2c
6
+ metadata.gz: db948451245c6a7e6cf20876368d040e6de9b3f178ab5fa0010070b9e834cd08036d449e35f3857a8443ac26fc5318ac20ab5cc16d91a4b65d8fc0f07a796939
7
+ data.tar.gz: 2a6e4b9dbb1f2effa1ef15a4f861c7b5cadb6384713bf3452749f8f0be1405ab319d85b23272b1dbc3bdeda7837d0ce55f0caf62273e197eb6190511f0789097
data/CHANGELOG.md CHANGED
@@ -2,6 +2,26 @@
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
+ - Fix `Sprockets::Server` to return response headers to compatible with with Rack::Lint 2.0.
6
+
7
+ ## 4.1.0
8
+
9
+ - Allow age to be altered in asset:clean rake task.
10
+ - Fix `Sprockets::Server` to return lower-cased response headers to comply with Rack::Lint 3.0. [#744](https://github.com/rails/sprockets/pull/744)
11
+ - Adding new directive `depend_on_directory` [#668](https://github.com/rails/sprockets/pull/668)
12
+ - Fix `application/js-sourcemap+json` charset [#669](https://github.com/rails/sprockets/pull/669)
13
+ - Fix `CachedEnvironment` caching nil values [#723](https://github.com/rails/sprockets/pull/723)
14
+ - Process `*.jst.ejs.erb` files with ERBProcessor [#674](https://github.com/rails/sprockets/pull/674)
15
+ - Fix cache key for coffee script processor to be dependent on the filename [#670](https://github.com/rails/sprockets/pull/670)
16
+
17
+ ## 4.0.3
18
+
19
+ - Fix `Manifest#find` yielding from a Promise causing issue on Ruby 3.1.0-dev. [#720](https://github.com/rails/sprockets/pull/720)
20
+ - Better detect the ERB version to avoid deprecation warnings. [#719](https://github.com/rails/sprockets/pull/719)
21
+ - Allow assets already fingerprinted to be served through `Sprockets::Server`
22
+ - Do not fingerprint files that already contain a valid digest in their name
23
+ - Remove remaining support for Ruby < 2.4.[#672](https://github.com/rails/sprockets/pull/672)
24
+
5
25
  ## 4.0.2
6
26
 
7
27
  - Fix `etag` and digest path compilation that were generating string with invalid digest since 4.0.1.
@@ -23,7 +43,7 @@ Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprocket
23
43
 
24
44
  ## 4.0.0.beta9
25
45
 
26
- - Minimum Ruby version for Sprockets 4 is now 2.5+ which matches minimum ruby verision of Rails [#604]
46
+ - Minimum Ruby version for Sprockets 4 is now 2.5+ which matches minimum ruby version of Rails [#604]
27
47
  - Fix threading bug introduced in Sprockets 4 [#603]
28
48
  - Warn when two potential manifest files exist. [#560]
29
49
 
data/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2014-2019 Sam Stephenson
2
+ Copyright (c) 2014-2019 Joshua Peek
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -119,6 +119,7 @@ Here is a list of the available directives:
119
119
  - [`link_directory`](#link_directory) - Make target directory compile and be publicly available without adding contents to current
120
120
  - [`link_tree`](#link_tree) - Make target tree compile and be publicly available without adding contents to current
121
121
  - [`depend_on`](#depend_on) - Recompile current file if target has changed
122
+ - [`depend_on_directory`](#depend_on_directory) - Recompile current file if any files in target directory has changed
122
123
  - [`stub`](#stub) - Ignore target file
123
124
 
124
125
  You can see what each of these does below.
@@ -239,7 +240,7 @@ The first time this file is compiled the `application.js` output will be written
239
240
 
240
241
  So, if `b.js` changes it will get recompiled. However instead of having to recompile the other files from `a.js` to `z.js` since they did not change, we can use the prior intermediary files stored in the cached values . If these files were expensive to generate, then this "partial" asset cache strategy can save a lot of time.
241
242
 
242
- Directives such as `require`, `link`, and `depend_on` tell Sprockets what assets need to be re-compiled when a file changes. Files are considered "fresh" based on their mtime on disk and a combination of cache keys.
243
+ Directives such as `require`, `link`, `depend_on`, and `depend_on_directory` tell Sprockets what assets need to be re-compiled when a file changes. Files are considered "fresh" based on their mtime on disk and a combination of cache keys.
243
244
 
244
245
  On Rails you can force a "clean" install by clearing the `public/assets` and `tmp/cache/assets` directories.
245
246
 
@@ -376,11 +377,19 @@ generated and made available to the public you can link it by including this in
376
377
  ```
377
378
 
378
379
  The argument to `link` is a _logical path_, that is it will be resolved according to the
379
- configured asset load paths. See [Accesing Assets](#accessing-assets) above. A path relative to
380
+ configured asset load paths. See [Accessing Assets](#accessing-assets) above. A path relative to
380
381
  the current file won't work, it must be a logical path.
381
382
 
382
383
  **Caution**: the "link" directive should always have an explicit extension on the end.
383
384
 
385
+ `link` can also be used to include manifest files from mounted Rails engines:
386
+
387
+ ```
388
+ //= link my_engine
389
+ ```
390
+
391
+ This would find a manifest file at `my_engine/app/assets/config/my_engine.js` and include its directives.
392
+
384
393
  ### link_directory
385
394
 
386
395
  `link_directory` *path* links all the files inside the directory specified by the *path*. By "link", we mean they are specified as compilation targets to be written out to disk, and made available to be served to user-agents.
@@ -445,11 +454,53 @@ you need to tell sprockets that it needs to re-compile the file if `bar.data` ch
445
454
  var bar = '<%= File.read("bar.data") %>'
446
455
  ```
447
456
 
457
+ To depend on an entire directory containing multiple files, use `depend_on_directory`
458
+
448
459
  ### depend_on_asset
449
460
 
450
461
  `depend_on_asset` *path* works like `depend_on`, but operates
451
462
  recursively reading the file and following the directives found. This is automatically implied if you use `link`, so consider if it just makes sense using `link` instead of `depend_on_asset`.
452
463
 
464
+ ### depend_on_directory
465
+
466
+ `depend_on_directory` *path* declares all files in the given *path* without
467
+ including them in the bundle. This is useful when you need to expire an
468
+ asset's cache in response to a change in multiple files in a single directory.
469
+
470
+ All paths are relative to your declaration and must begin with `./`
471
+
472
+ Also, your must include these directories in your [load path](guides/building_an_asset_processing_framework.md#the-load-path).
473
+
474
+ **Example:**
475
+
476
+ If we've got a directory called `data` with files `a.data` and `b.data`
477
+
478
+ ```
479
+ // ./data/a.data
480
+ A
481
+ ```
482
+
483
+ ```
484
+ // ./data/b.data
485
+ B
486
+ ```
487
+
488
+ ```
489
+ // ./file.js.erb
490
+ //= depend_on_directory ./data
491
+ var a = '<% File.read('data/a.data') %>'
492
+ var b = '<% File.read('data/b.data') %>'
493
+ ```
494
+
495
+ Would produce:
496
+
497
+ ```js
498
+ var a = "A";
499
+ var b = "B";
500
+ ```
501
+
502
+ You can also see [Index files are proxies for folders](#index-files-are-proxies-for-folders) for another method of organizing folders that will give you more control.
503
+
453
504
  ### stub
454
505
 
455
506
  `stub` *path* excludes that asset and its dependencies from the asset bundle.
@@ -491,9 +542,9 @@ When you modify the `logo.png` on disk, it will force `application.css` to be
491
542
  recompiled so that the fingerprint will be correct in the generated asset.
492
543
 
493
544
  You can manually make sprockets depend on any other file that is generated
494
- by sprockets by using the `depend_on` directive. Rails implements the above
495
- feature by auto calling `depend_on` on the original asset when the `asset_url`
496
- is used inside of an asset.
545
+ by sprockets by using the `depend_on` or `depend_on_directory` directive. Rails
546
+ implements the above feature by auto calling `depend_on` on the original asset
547
+ when the `asset_url` is used inside of an asset.
497
548
 
498
549
  ### Styling with Sass and SCSS
499
550
 
@@ -606,19 +657,19 @@ Several JavaScript and CSS minifiers are available through shorthand.
606
657
  In Rails you will specify them with:
607
658
 
608
659
  ```ruby
609
- config.assets.js_compressor = :uglify
660
+ config.assets.js_compressor = :terser
610
661
  config.assets.css_compressor = :scss
611
662
  ```
612
663
 
613
664
  If you're not using Rails, configure this directly on the "environment".
614
665
 
615
666
  ``` ruby
616
- environment.js_compressor = :uglify
667
+ environment.js_compressor = :terser
617
668
  environment.css_compressor = :scss
618
669
  ```
619
670
 
620
671
  If you are using Sprockets directly with a Rack app, don't forget to add
621
- the `uglifier` and `sass` gems to your Gemfile when using above options.
672
+ the `terser` and `sass` gems to your Gemfile when using above options.
622
673
 
623
674
  ### Gzip
624
675
 
@@ -69,9 +69,12 @@ module Rake
69
69
  #
70
70
  attr_accessor :assets
71
71
 
72
- # Number of old assets to keep.
72
+ # Minimum number of old assets to keep. See Sprockets::Manifest#clean for more information.
73
73
  attr_accessor :keep
74
74
 
75
+ # Assets created within this age will be kept. See Sprockets::Manifest#clean for more information.
76
+ attr_accessor :age
77
+
75
78
  # Logger to use during rake tasks. Defaults to using stderr.
76
79
  #
77
80
  # t.logger = Logger.new($stdout)
@@ -103,6 +106,7 @@ module Rake
103
106
  @logger = Logger.new($stderr)
104
107
  @logger.level = Logger::INFO
105
108
  @keep = 2
109
+ @age = 3600
106
110
 
107
111
  yield self if block_given?
108
112
 
@@ -130,7 +134,7 @@ module Rake
130
134
  desc name == :assets ? "Clean old assets" : "Clean old #{name} assets"
131
135
  task "clean_#{name}" do
132
136
  with_logger do
133
- manifest.clean(keep)
137
+ manifest.clean(keep, age)
134
138
  end
135
139
  end
136
140
 
@@ -14,7 +14,7 @@ module Sprockets
14
14
  # information that is needed to build a source map file.
15
15
  #
16
16
  # To add this comment we must have an asset we can link to.
17
- # To do this we ensure that the original aset is loaded, then
17
+ # To do this we ensure that the original asset is loaded, then
18
18
  # we use a use a special mime type. For example `application/js-sourcemap+json`
19
19
  # for a JS source map.
20
20
  #
@@ -6,7 +6,7 @@ module Sprockets
6
6
  class Asset
7
7
  attr_reader :logical_path
8
8
 
9
- # Private: Intialize Asset wrapper from attributes Hash.
9
+ # Private: Initialize Asset wrapper from attributes Hash.
10
10
  #
11
11
  # Asset wrappers should not be initialized directly, only
12
12
  # Environment#find_asset should vend them.
@@ -38,7 +38,7 @@ module Sprockets
38
38
  #
39
39
  # The API status of the keys is dependent on the pipeline processors
40
40
  # itself. So some values maybe considered public and others internal.
41
- # See the pipeline proccessor documentation itself.
41
+ # See the pipeline processor documentation itself.
42
42
  #
43
43
  # Returns Hash.
44
44
  attr_reader :metadata
@@ -53,7 +53,7 @@ module Sprockets
53
53
 
54
54
  # Public: Internal URI to lookup asset by.
55
55
  #
56
- # NOT a publically accessible URL.
56
+ # NOT a publicly accessible URL.
57
57
  #
58
58
  # Returns URI.
59
59
  attr_reader :uri
@@ -64,7 +64,11 @@ module Sprockets
64
64
  #
65
65
  # Returns String.
66
66
  def digest_path
67
- logical_path.sub(/\.(\w+)$/) { |ext| "-#{etag}#{ext}" }
67
+ if DigestUtils.already_digested?(@name)
68
+ logical_path
69
+ else
70
+ logical_path.sub(/\.(\w+)$/) { |ext| "-#{etag}#{ext}" }
71
+ end
68
72
  end
69
73
 
70
74
  # Public: Return load path + logical path with digest spliced in.
@@ -13,7 +13,7 @@ module Sprockets
13
13
  # load_path - String environment path
14
14
  # logical_path - String path relative to base
15
15
  #
16
- # Returns candiate filenames.
16
+ # Returns candidate filenames.
17
17
  def resolve_alternates(load_path, logical_path)
18
18
  candidates, deps = super
19
19
 
@@ -10,7 +10,7 @@ module Sprockets
10
10
  # Uses pipeline metadata:
11
11
  #
12
12
  # :required - Ordered Set of asset URIs to prepend
13
- # :stubbed - Set of asset URIs to substract from the required set.
13
+ # :stubbed - Set of asset URIs to subtract from the required set.
14
14
  #
15
15
  # Also see DirectiveProcessor.
16
16
  class Bundle
@@ -62,7 +62,7 @@ module Sprockets
62
62
  # Internal: Wrap a backend cache store.
63
63
  #
64
64
  # Always assign a backend cache store instance to Environment#cache= and
65
- # use Environment#cache to retreive a wrapped interface.
65
+ # use Environment#cache to retrieve a wrapped interface.
66
66
  #
67
67
  # cache - A compatible backend cache store instance.
68
68
  def initialize(cache = nil, logger = self.class.default_logger)
@@ -4,7 +4,7 @@ require 'sprockets/base'
4
4
  module Sprockets
5
5
  # `CachedEnvironment` is a special cached version of `Environment`.
6
6
  #
7
- # The expection is that all of its file system methods are cached
7
+ # The exception is that all of its file system methods are cached
8
8
  # for the instances lifetime. This makes `CachedEnvironment` much faster. This
9
9
  # behavior is ideal in production environments where the file system
10
10
  # is immutable.
@@ -31,27 +31,27 @@ module Sprockets
31
31
 
32
32
  # Internal: Cache Environment#entries
33
33
  def entries(path)
34
- @entries[path] ||= super(path)
34
+ @entries.fetch(path){ @entries[path] = super(path) }
35
35
  end
36
36
 
37
37
  # Internal: Cache Environment#stat
38
38
  def stat(path)
39
- @stats[path] ||= super(path)
39
+ @stats.fetch(path){ @stats[path] = super(path) }
40
40
  end
41
41
 
42
42
  # Internal: Cache Environment#load
43
43
  def load(uri)
44
- @uris[uri] ||= super(uri)
44
+ @uris.fetch(uri){ @uris[uri] = super(uri) }
45
45
  end
46
46
 
47
47
  # Internal: Cache Environment#processor_cache_key
48
48
  def processor_cache_key(str)
49
- @processor_cache_keys[str] ||= super(str)
49
+ @processor_cache_keys.fetch(str){ @processor_cache_keys[str] = super(str) }
50
50
  end
51
51
 
52
52
  # Internal: Cache Environment#resolve_dependency
53
53
  def resolve_dependency(str)
54
- @resolved_dependencies[str] ||= super(str)
54
+ @resolved_dependencies.fetch(str){ @resolved_dependencies[str] = super(str) }
55
55
  end
56
56
 
57
57
  private
@@ -6,7 +6,7 @@ module Sprockets
6
6
  # Processor engine class for the CoffeeScript compiler.
7
7
  # Depends on the `coffee-script` and `coffee-script-source` gems.
8
8
  #
9
- # For more infomation see:
9
+ # For more information see:
10
10
  #
11
11
  # https://github.com/rails/ruby-coffee-script
12
12
  #
@@ -20,7 +20,7 @@ module Sprockets
20
20
  def self.call(input)
21
21
  data = input[:data]
22
22
 
23
- js, map = input[:cache].fetch([self.cache_key, data]) do
23
+ js, map = input[:cache].fetch([self.cache_key, data, input[:filename]]) do
24
24
  result = Autoload::CoffeeScript.compile(
25
25
  data,
26
26
  sourceMap: "v3",
@@ -59,9 +59,9 @@ module Sprockets
59
59
 
60
60
  # Deprecated: Assign a `Digest` implementation class. This maybe any Ruby
61
61
  # `Digest::` implementation such as `Digest::SHA256` or
62
- # `Digest::MD5`.
62
+ # `Digest::SHA512`.
63
63
  #
64
- # environment.digest_class = Digest::MD5
64
+ # environment.digest_class = Digest::SHA512
65
65
  #
66
66
  def digest_class=(klass)
67
67
  self.config = config.merge(digest_class: klass).freeze
@@ -2,6 +2,7 @@
2
2
  require 'rack/utils'
3
3
  require 'set'
4
4
  require 'sprockets/errors'
5
+ require 'delegate'
5
6
 
6
7
  module Sprockets
7
8
  # They are typically accessed by ERB templates. You can mix in custom helpers
@@ -210,7 +211,7 @@ module Sprockets
210
211
  #
211
212
  # NOTE: This helper is currently not implemented and should be
212
213
  # customized by the application. Though, in the future, some
213
- # basics implemention may be provided with different methods that
214
+ # basic implementation may be provided with different methods that
214
215
  # are required to be overridden.
215
216
  def asset_path(path, options = {})
216
217
  message = <<-EOS
@@ -40,7 +40,7 @@ module Sprockets
40
40
  end
41
41
  end
42
42
 
43
- # Public: Add environmental dependency inheirted by all assets.
43
+ # Public: Add environmental dependency inherited by all assets.
44
44
  #
45
45
  # uri - String dependency URI
46
46
  #
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
- require 'digest/md5'
3
2
  require 'digest/sha1'
4
3
  require 'digest/sha2'
5
4
  require 'set'
@@ -19,7 +18,6 @@ module Sprockets
19
18
 
20
19
  # Internal: Maps digest bytesize to the digest class.
21
20
  DIGEST_SIZES = {
22
- 16 => Digest::MD5,
23
21
  20 => Digest::SHA1,
24
22
  32 => Digest::SHA256,
25
23
  48 => Digest::SHA384,
@@ -68,18 +66,8 @@ module Sprockets
68
66
  Encoding => ->(val, digest) {
69
67
  digest << 'Encoding'.freeze
70
68
  digest << val.name
71
- },
72
- }
73
- if 0.class != Integer # Ruby < 2.4
74
- ADD_VALUE_TO_DIGEST[Fixnum] = ->(val, digest) {
75
- digest << 'Integer'.freeze
76
- digest << val.to_s
77
- }
78
- ADD_VALUE_TO_DIGEST[Bignum] = ->(val, digest) {
79
- digest << 'Integer'.freeze
80
- digest << val.to_s
81
69
  }
82
- end
70
+ }
83
71
 
84
72
  ADD_VALUE_TO_DIGEST.compare_by_identity.rehash
85
73
 
@@ -189,6 +177,15 @@ module Sprockets
189
177
  integrity_uri(unpack_hexdigest(hexdigest))
190
178
  end
191
179
 
180
+ # Internal: Checks an asset name for a valid digest
181
+ #
182
+ # name - The name of the asset
183
+ #
184
+ # Returns true if the name contains a digest like string and .digested before the extension
185
+ def already_digested?(name)
186
+ return name =~ /-([0-9a-zA-Z]{7,128})\.digested/
187
+ end
188
+
192
189
  private
193
190
  def build_digest(obj)
194
191
  digest = digest_class.new
@@ -285,6 +285,24 @@ module Sprockets
285
285
  to_load(resolve(path))
286
286
  end
287
287
 
288
+ # Allows you to state a dependency on a relative directory
289
+ # without including it.
290
+ #
291
+ # This is used for caching purposes. Any changes made to
292
+ # the dependency directory will invalidate the cache of the
293
+ # source file.
294
+ #
295
+ # This is useful if you are using ERB and File.read to pull
296
+ # in contents from multiple files in a directory.
297
+ #
298
+ # //= depend_on_directory ./data
299
+ #
300
+ def process_depend_on_directory_directive(path = ".", accept = nil)
301
+ path = expand_relative_dirname(:depend_on_directory, path)
302
+ accept = expand_accept_shorthand(accept)
303
+ resolve_paths(*@environment.stat_directory_with_dependencies(path), accept: accept)
304
+ end
305
+
288
306
  # Allows dependency to be excluded from the asset bundle.
289
307
  #
290
308
  # The `path` must be a valid asset and may or may not already
@@ -374,7 +392,7 @@ module Sprockets
374
392
  next if subpath == @filename || stat.directory?
375
393
  uri, deps = @environment.resolve(subpath, **kargs)
376
394
  @dependencies.merge(deps)
377
- yield uri if uri
395
+ yield uri if uri && block_given?
378
396
  end
379
397
  end
380
398
 
@@ -4,7 +4,7 @@ require 'sprockets/autoload'
4
4
  module Sprockets
5
5
  # Processor engine class for the Eco compiler. Depends on the `eco` gem.
6
6
  #
7
- # For more infomation see:
7
+ # For more information see:
8
8
  #
9
9
  # https://github.com/sstephenson/ruby-eco
10
10
  # https://github.com/sstephenson/eco
@@ -4,7 +4,7 @@ require 'sprockets/autoload'
4
4
  module Sprockets
5
5
  # Processor engine class for the EJS compiler. Depends on the `ejs` gem.
6
6
  #
7
- # For more infomation see:
7
+ # For more information see:
8
8
  #
9
9
  # https://github.com/sstephenson/ruby-ejs
10
10
  #
@@ -18,8 +18,7 @@ class Sprockets::ERBProcessor
18
18
  end
19
19
 
20
20
  def call(input)
21
- match = ERB.version.match(/\Aerb\.rb \[(?<version>[^ ]+) /)
22
- if match && match[:version] >= "2.2.0" # Ruby 2.6+
21
+ if keyword_constructor? # Ruby 2.6+
23
22
  engine = ::ERB.new(input[:data], trim_mode: '<>')
24
23
  else
25
24
  engine = ::ERB.new(input[:data], nil, '<>')
@@ -34,4 +33,11 @@ class Sprockets::ERBProcessor
34
33
  data = engine.result(context.instance_eval('binding'))
35
34
  context.metadata.merge(data: data)
36
35
  end
36
+
37
+ private
38
+
39
+ def keyword_constructor?
40
+ return @keyword_constructor if defined? @keyword_constructor
41
+ @keyword_constructor = ::ERB.instance_method(:initialize).parameters.include?([:key, :trim_mode])
42
+ end
37
43
  end
@@ -1,6 +1,6 @@
1
1
  module Sprockets
2
2
  module Exporters
3
- # Convienence class for all exporters to inherit from
3
+ # Convenience class for all exporters to inherit from
4
4
  #
5
5
  # An exporter is responsible for exporting a Sprockets::Asset
6
6
  # to a file system. For example the Exporters::File class
@@ -29,7 +29,7 @@ module Sprockets
29
29
  setup
30
30
  end
31
31
 
32
- # Public: Callback that is executed after intialization
32
+ # Public: Callback that is executed after initialization
33
33
  #
34
34
  # Any setup that needs to be done can be performed in the +setup+
35
35
  # method. It will be called immediately after initialization.
@@ -291,7 +291,7 @@ module Sprockets
291
291
  # Internal: Retrieves an asset based on its digest
292
292
  #
293
293
  # unloaded - An UnloadedAsset
294
- # limit - A Fixnum which sets the maximum number of versions of "histories"
294
+ # limit - An Integer which sets the maximum number of versions of "histories"
295
295
  # stored in the cache
296
296
  #
297
297
  # This method attempts to retrieve the last `limit` number of histories of an asset
@@ -15,7 +15,7 @@ module Sprockets
15
15
  # The JSON is part of the public API and should be considered stable. This
16
16
  # should make it easy to read from other programming languages and processes
17
17
  # that don't have sprockets loaded. See `#assets` and `#files` for more
18
- # infomation about the structure.
18
+ # information about the structure.
19
19
  class Manifest
20
20
  include ManifestUtils
21
21
 
@@ -112,7 +112,7 @@ module Sprockets
112
112
  # Public: Find all assets matching pattern set in environment.
113
113
  #
114
114
  # Returns Enumerator of Assets.
115
- def find(*args)
115
+ def find(*args, &block)
116
116
  unless environment
117
117
  raise Error, "manifest requires environment for compilation"
118
118
  end
@@ -122,12 +122,13 @@ module Sprockets
122
122
  environment = self.environment.cached
123
123
  promises = args.flatten.map do |path|
124
124
  Concurrent::Promise.execute(executor: executor) do
125
- environment.find_all_linked_assets(path) do |asset|
126
- yield asset
127
- end
125
+ environment.find_all_linked_assets(path).to_a
128
126
  end
129
127
  end
130
- promises.each(&:wait!)
128
+
129
+ promises.each do |promise|
130
+ promise.value!.each(&block)
131
+ end
131
132
 
132
133
  nil
133
134
  end
@@ -273,7 +274,7 @@ module Sprockets
273
274
  nil
274
275
  end
275
276
 
276
- # Persist manfiest back to FS
277
+ # Persist manifest back to FS
277
278
  def save
278
279
  data = json_encode(@data)
279
280
  FileUtils.mkdir_p File.dirname(@filename)
data/lib/sprockets/npm.rb CHANGED
@@ -8,7 +8,7 @@ module Sprockets
8
8
  # load_path - String environment path
9
9
  # logical_path - String path relative to base
10
10
  #
11
- # Returns candiate filenames.
11
+ # Returns candidate filenames.
12
12
  def resolve_alternates(load_path, logical_path)
13
13
  candidates, deps = super
14
14
 
@@ -162,7 +162,7 @@ module Sprockets
162
162
  def split_subpath(path, subpath)
163
163
  return "" if path == subpath
164
164
  path = File.join(path, ''.freeze)
165
- if subpath.start_with?(path)
165
+ if subpath&.start_with?(path)
166
166
  subpath[path.length..-1]
167
167
  else
168
168
  nil
@@ -130,7 +130,7 @@ module Sprockets
130
130
  #
131
131
  # mime_type - String MIME Type. Use '*/*' applies to all types.
132
132
  # key - Symbol metadata key
133
- # initial - Initial memo to pass to the reduce funciton (default: nil)
133
+ # initial - Initial memo to pass to the reduce function (default: nil)
134
134
  # block - Proc accepting the memo accumulator and current value
135
135
  #
136
136
  # Returns nothing.
@@ -6,7 +6,7 @@ module Sprockets
6
6
  #
7
7
  # A Processor is a general function that may modify or transform an asset as
8
8
  # part of the pipeline. CoffeeScript to JavaScript conversion, Minification
9
- # or Concatenation are all implemented as seperate Processor steps.
9
+ # or Concatenation are all implemented as separate Processor steps.
10
10
  #
11
11
  # Processors maybe any object that responds to call. So procs or a class that
12
12
  # defines a self.call method.
@@ -118,8 +118,9 @@ module Sprockets
118
118
  Symbol,
119
119
  TrueClass,
120
120
  FalseClass,
121
- NilClass
122
- ] + (0.class == Integer ? [Integer] : [Bignum, Fixnum])).freeze
121
+ NilClass,
122
+ Integer
123
+ ]).freeze
123
124
 
124
125
  # Internal: Set of all nested compound metadata types that can nest values.
125
126
  VALID_METADATA_COMPOUND_TYPES = Set.new([
@@ -7,7 +7,7 @@ require 'uri'
7
7
  module Sprockets
8
8
  # Processor engine class for the SASS/SCSS compiler. Depends on the `sass` gem.
9
9
  #
10
- # For more infomation see:
10
+ # For more information see:
11
11
  #
12
12
  # https://github.com/sass/sass
13
13
  # https://github.com/rails/sass-rails
@@ -7,7 +7,7 @@ require 'uri'
7
7
  module Sprockets
8
8
  # Processor engine class for the SASS/SCSS compiler. Depends on the `sassc` gem.
9
9
  #
10
- # For more infomation see:
10
+ # For more information see:
11
11
  #
12
12
  # https://github.com/sass/sassc-ruby
13
13
  # https://github.com/sass/sassc-rails
@@ -35,7 +35,8 @@ module Sprockets
35
35
  msg = "Served asset #{env['PATH_INFO']} -"
36
36
 
37
37
  # Extract the path from everything after the leading slash
38
- path = Rack::Utils.unescape(env['PATH_INFO'].to_s.sub(/^\//, ''))
38
+ full_path = Rack::Utils.unescape(env['PATH_INFO'].to_s.sub(/^\//, ''))
39
+ path = full_path
39
40
 
40
41
  unless path.valid_encoding?
41
42
  return bad_request_response(env)
@@ -64,6 +65,15 @@ module Sprockets
64
65
  # Look up the asset.
65
66
  asset = find_asset(path)
66
67
 
68
+ # Fallback to looking up the asset with the full path.
69
+ # This will make assets that are hashed with webpack or
70
+ # other js bundlers work consistently between production
71
+ # and development pipelines.
72
+ if asset.nil? && (asset = find_asset(full_path))
73
+ if_match = asset.etag if fingerprint
74
+ fingerprint = asset.etag
75
+ end
76
+
67
77
  if asset.nil?
68
78
  status = :not_found
69
79
  elsif fingerprint && asset.etag != fingerprint
@@ -289,7 +299,7 @@ module Sprockets
289
299
  # # => "0aa2105d29558f3eb790d411d7d8fb66"
290
300
  #
291
301
  def path_fingerprint(path)
292
- path[/-([0-9a-f]{7,128})\.[^.]+\z/, 1]
302
+ path[/-([0-9a-zA-Z]{7,128})\.[^.]+\z/, 1]
293
303
  end
294
304
  end
295
305
  end
@@ -9,7 +9,7 @@ module Sprockets
9
9
  # When a file is passed in it will have a `application/js-sourcemap+json`
10
10
  # or `application/css-sourcemap+json` mime type. The filename will be
11
11
  # match the original asset. The original asset is loaded. As it
12
- # gets processed by Sprockets it will aquire all information
12
+ # gets processed by Sprockets it will acquire all information
13
13
  # needed to build a source map file in the `asset.to_hash[:metadata][:map]`
14
14
  # key.
15
15
  #
@@ -140,7 +140,7 @@ module Sprockets
140
140
  }
141
141
  end
142
142
 
143
- # Public: Combine two seperate source map transformations into a single
143
+ # Public: Combine two separate source map transformations into a single
144
144
  # mapping.
145
145
  #
146
146
  # Source transformations may happen in discrete steps producing separate
@@ -453,7 +453,7 @@ module Sprockets
453
453
  #
454
454
  # ary - Two dimensional Array of Integers.
455
455
  #
456
- # Returns a VLQ encoded String seperated by , and ;.
456
+ # Returns a VLQ encoded String separated by , and ;.
457
457
  def vlq_encode_mappings(ary)
458
458
  ary.map { |group|
459
459
  group.map { |segment|
@@ -25,7 +25,7 @@ module Sprockets
25
25
 
26
26
  # Internal: Duplicate and store key/value on new frozen hash.
27
27
  #
28
- # Seperated for recursive calls, always use hash_reassoc(hash, *keys).
28
+ # Separated for recursive calls, always use hash_reassoc(hash, *keys).
29
29
  #
30
30
  # hash - Hash
31
31
  # key - Object key
@@ -132,6 +132,9 @@ module Sprockets
132
132
 
133
133
  mod.instance_methods.each do |sym|
134
134
  method = mod.instance_method(sym)
135
+ if base.method_defined?(sym)
136
+ base.send(:alias_method, sym, sym)
137
+ end
135
138
  base.send(:define_method, sym, method)
136
139
  end
137
140
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Sprockets
3
- VERSION = "4.0.2"
3
+ VERSION = "4.1.1"
4
4
  end
data/lib/sprockets.rb CHANGED
@@ -51,6 +51,7 @@ module Sprockets
51
51
  register_mime_type 'application/json', extensions: ['.json'], charset: :unicode
52
52
  register_mime_type 'application/ruby', extensions: ['.rb']
53
53
  register_mime_type 'application/xml', extensions: ['.xml']
54
+ register_mime_type 'application/manifest+json', extensions: ['.webmanifest']
54
55
  register_mime_type 'text/css', extensions: ['.css'], charset: :css
55
56
  register_mime_type 'text/html', extensions: ['.html', '.htm'], charset: :html
56
57
  register_mime_type 'text/plain', extensions: ['.txt', '.text']
@@ -89,7 +90,7 @@ module Sprockets
89
90
  register_mime_type 'application/font-woff2', extensions: ['.woff2']
90
91
 
91
92
  require 'sprockets/source_map_processor'
92
- register_mime_type 'application/js-sourcemap+json', extensions: ['.js.map']
93
+ register_mime_type 'application/js-sourcemap+json', extensions: ['.js.map'], charset: :unicode
93
94
  register_mime_type 'application/css-sourcemap+json', extensions: ['.css.map']
94
95
  register_transformer 'application/javascript', 'application/js-sourcemap+json', SourceMapProcessor
95
96
  register_transformer 'text/css', 'application/css-sourcemap+json', SourceMapProcessor
@@ -180,6 +181,7 @@ module Sprockets
180
181
  application/ecmascript-6
181
182
  application/javascript
182
183
  application/json
184
+ application/manifest+json
183
185
  application/xml
184
186
  text/coffeescript
185
187
  text/css
@@ -189,6 +191,7 @@ module Sprockets
189
191
  text/scss
190
192
  text/yaml
191
193
  text/eco
194
+ text/ejs
192
195
  ), 'application/\2+ruby', '.erb', ERBProcessor)
193
196
 
194
197
  register_mime_type 'application/html+ruby', extensions: ['.html.erb', '.erb', '.rhtml'], charset: :html
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.0.2
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Stephenson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-06-05 00:00:00.000000000 Z
12
+ date: 2022-06-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -336,6 +336,7 @@ extensions: []
336
336
  extra_rdoc_files: []
337
337
  files:
338
338
  - CHANGELOG.md
339
+ - MIT-LICENSE
339
340
  - README.md
340
341
  - bin/sprockets
341
342
  - lib/rake/sprocketstask.rb
@@ -437,7 +438,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
437
438
  - !ruby/object:Gem::Version
438
439
  version: '0'
439
440
  requirements: []
440
- rubygems_version: 3.1.2
441
+ rubygems_version: 3.3.7
441
442
  signing_key:
442
443
  specification_version: 4
443
444
  summary: Rack-based asset packaging system