sprockets 4.0.0 → 4.0.3

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: cbc5f0a881069d09632a087bb32f43c8e5d01a631f2ff6fbc6e776e3695bd51c
4
- data.tar.gz: 580922aaccc4defd65fdf239b441f7e8e96216d98dae8fdfe0a64afc3b40a4bc
3
+ metadata.gz: f59adc73cec32bd913421523e00e2615eb6557cce967d6b59b8244a9f969051d
4
+ data.tar.gz: d970c5ed6ba67c58afd8c3529634f450d9ed1357000cb5952916efa9dca77d4e
5
5
  SHA512:
6
- metadata.gz: f474ef02d068783020ae4a3833bded8783d1a1bfa1ee5ae106dd7e8dfbcf12723c8582155cb44c0594b0c36bcad476b7139814f2577fa2e25a82ad6675763dc4
7
- data.tar.gz: 853bbac33f50b2097126190c01bdc182306b7aa7132d50b91248efd1dcc1b7a35863fa1a5e529eacc8d967ee9d2de8083ae68b72e02889e01a821d794d0ad147
6
+ metadata.gz: 3fb439abcba98f893e88ee2bc75af8e3b59760c82f510fd4de510706e49a4fb28fbc84d9c0eefcc172dd981aec04bcaec2f5afc572d03081d6600249b3eb9632
7
+ data.tar.gz: f28698f721422b64b05de921d7e91ff8972415ba3a82e47d196095f4e6a487103078d69dfcd54b9027341c7852b079d6ef35d6626b68508a63627e44a75c0891
data/CHANGELOG.md CHANGED
@@ -2,7 +2,23 @@
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
- ## Master
5
+ ## 4.0.3
6
+
7
+ - Fix `Manifest#find` yielding from a Promise causing issue on Ruby 3.1.0-dev. [#720](https://github.com/rails/sprockets/pull/720)
8
+ - Better detect the ERB version to avoid deprecation warnings. [#719](https://github.com/rails/sprockets/pull/719)
9
+ - Allow assets already fingerprinted to be served through `Sprockets::Server`
10
+ - Do not fingerprint files that already contain a valid digest in their name
11
+ - Remove remaining support for Ruby < 2.4.[#672](https://github.com/rails/sprockets/pull/672)
12
+
13
+ ## 4.0.2
14
+
15
+ - Fix `etag` and digest path compilation that were generating string with invalid digest since 4.0.1.
16
+
17
+ ## 4.0.1
18
+
19
+ - Fix for Ruby 2.7 keyword arguments warning in `base.rb`. [#660](https://github.com/rails/sprockets/pull/660)
20
+ - Fix for when `x_sprockets_linecount` is missing from a source map.
21
+ - Fix subresource integrity to match the digest of the asset.
6
22
 
7
23
  ## 4.0.0
8
24
 
@@ -15,7 +31,7 @@ Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprocket
15
31
 
16
32
  ## 4.0.0.beta9
17
33
 
18
- - Minimum Ruby version for Sprockets 4 is now 2.5+ which matches minimum ruby verision of Rails [#604]
34
+ - Minimum Ruby version for Sprockets 4 is now 2.5+ which matches minimum ruby version of Rails [#604]
19
35
  - Fix threading bug introduced in Sprockets 4 [#603]
20
36
  - Warn when two potential manifest files exist. [#560]
21
37
 
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
@@ -115,9 +115,9 @@ Here is a list of the available directives:
115
115
  - [`require_self`](#require_self) - Change order of where current contents are concatenated to current
116
116
  - [`require_directory`](#require_directory) - Add contents of each file in a folder to current
117
117
  - [`require_tree`](#require_tree) - Add contents of all files in all directories in a path to current
118
- - [`link`](#link) - Make target file compile and be publically available without adding contents to current
119
- - [`link_directory`](#link_directory) - Make target directory compile and be publically available without adding contents to current
120
- - [`link_tree`](#link_tree) - Make target tree compile and be publically available without adding contents to current
118
+ - [`link`](#link) - Make target file compile and be publicly available without adding contents to current
119
+ - [`link_directory`](#link_directory) - Make target directory compile and be publicly available without adding contents to current
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
122
  - [`stub`](#stub) - Ignore target file
123
123
 
@@ -363,37 +363,70 @@ directory specified by *path*.
363
363
  ### link
364
364
 
365
365
  `link` *path* declares a dependency on the target *path* and adds it to a list
366
- of subdependencies to automatically be compiled when the asset is written out to
366
+ of subdependencies to be compiled when the asset is written out to
367
367
  disk.
368
368
 
369
369
  Example:
370
370
 
371
- If you've got a `manifest.js` file and you want to explicitly make sure an `admin.js` file is
372
- generated and made available to the public you can link it like this:
371
+ If you've got a `manifest.js` file and you want to specify that a `admin.js` source file should be
372
+ generated and made available to the public you can link it by including this in the `manifest.js` file:
373
373
 
374
374
  ```
375
375
  //= link admin.js
376
376
  ```
377
377
 
378
+ The argument to `link` is a _logical path_, that is it will be resolved according to the
379
+ configured asset load paths. See [Accessing Assets](#accessing-assets) above. A path relative to
380
+ the current file won't work, it must be a logical path.
381
+
382
+ **Caution**: the "link" directive should always have an explicit extension on the end.
383
+
378
384
  ### link_directory
379
385
 
380
- `link_directory` *path* links all the files inside the directory specified by the *path*
386
+ `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.
387
+
388
+ Files in subdirectories will not be linked (Compare to [link_tree](#link_tree)).
389
+
390
+ The *path* argument to `link_directory` is _not_ a logical path (it does not use the asset load paths), but is a path relative to the file the `link_directory` directive is found in, and can use `..` to . For instance, you might want:
391
+
392
+ ```js
393
+ //= link_directory ../stylesheets
394
+ ```
395
+
396
+ `link_directory` can take an optional second argument with an extension or content-type, with the
397
+ two arguments separated by a space:
398
+
399
+ ```js
400
+ //= link_directory ../stylesheets text/css
401
+ //= link_directory ../more_stylesheets .css
402
+ ```
403
+
404
+ This will limit the matching files to link to only files recognized as that type. An extension is
405
+ just a shortcut for the type referenced, it does not need to match the source file exactly, but
406
+ instead identifies the content-type the source file must be recognized as.
381
407
 
382
408
  ### link_tree
383
409
 
384
- `link_tree` *path* works like `link_directory`, but operates
410
+ `link_tree` *path* works like [link_directory](#link_directory), but operates
385
411
  recursively to link all files in all subdirectories of the
386
412
  directory specified by *path*.
387
413
 
388
414
  Example:
389
415
 
390
- You can specify a file extension so any extra files will be ignored:
416
+ ```js
417
+ //= link_tree ./path/to/folder
418
+ ```
419
+
420
+ Like `link_directory`, the argument is path relative to the current file, it is *not* a 'logical path' tresolved against load paths.
421
+
422
+
423
+ As with `link_directory`, you can also specify a second argument -- separated by a space -- so any extra files not matching the content-type specified will be ignored:
391
424
 
392
425
  ```js
393
- //= link_tree ./path/to/folder .js
426
+ //= link_tree ./path/to/folder text/javascript
427
+ //= link_tree ./path/to/other_folder .js
394
428
  ```
395
429
 
396
- > Note: There is an intentional space between the path and the extension
397
430
 
398
431
  ### depend_on
399
432
 
@@ -573,19 +606,19 @@ Several JavaScript and CSS minifiers are available through shorthand.
573
606
  In Rails you will specify them with:
574
607
 
575
608
  ```ruby
576
- config.assets.js_compressor = :uglify
609
+ config.assets.js_compressor = :terser
577
610
  config.assets.css_compressor = :scss
578
611
  ```
579
612
 
580
613
  If you're not using Rails, configure this directly on the "environment".
581
614
 
582
615
  ``` ruby
583
- environment.js_compressor = :uglify
616
+ environment.js_compressor = :terser
584
617
  environment.css_compressor = :scss
585
618
  ```
586
619
 
587
620
  If you are using Sprockets directly with a Rack app, don't forget to add
588
- the `uglifier` and `sass` gems to your Gemfile when using above options.
621
+ the `terser` and `sass` gems to your Gemfile when using above options.
589
622
 
590
623
  ### Gzip
591
624
 
@@ -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.
@@ -123,13 +127,26 @@ module Sprockets
123
127
  metadata[:digest]
124
128
  end
125
129
 
130
+ # Private: Return the version of the environment where the asset was generated.
131
+ def environment_version
132
+ metadata[:environment_version]
133
+ end
134
+
126
135
  # Public: Returns String hexdigest of source.
127
136
  def hexdigest
128
137
  DigestUtils.pack_hexdigest(digest)
129
138
  end
130
139
 
131
140
  # Pubic: ETag String of Asset.
132
- alias_method :etag, :hexdigest
141
+ def etag
142
+ version = environment_version
143
+
144
+ if version && version != ""
145
+ DigestUtils.hexdigest(version + digest)
146
+ else
147
+ DigestUtils.pack_hexdigest(digest)
148
+ end
149
+ end
133
150
 
134
151
  # Public: Returns String base64 digest of source.
135
152
  def base64digest
@@ -138,7 +155,7 @@ module Sprockets
138
155
 
139
156
  # Public: A "named information" URL for subresource integrity.
140
157
  def integrity
141
- DigestUtils.integrity_uri(metadata[:digest])
158
+ DigestUtils.integrity_uri(digest)
142
159
  end
143
160
 
144
161
  # Public: Add enumerator to allow `Asset` instances to be used as Rack
@@ -115,8 +115,8 @@ module Sprockets
115
115
  #
116
116
  # environment['application.js']
117
117
  #
118
- def [](*args)
119
- find_asset(*args)
118
+ def [](*args, **options)
119
+ find_asset(*args, **options)
120
120
  end
121
121
 
122
122
  # Find asset by logical path or expanded path.
@@ -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.
@@ -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
  #
@@ -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-f]{7,128})\.digested/
187
+ end
188
+
192
189
  private
193
190
  def build_digest(obj)
194
191
  digest = digest_class.new
@@ -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.
@@ -69,4 +69,3 @@ module Sprockets
69
69
  end
70
70
  end
71
71
  end
72
-
@@ -195,14 +195,16 @@ module Sprockets
195
195
  source = result.delete(:data)
196
196
  metadata = result
197
197
  metadata[:charset] = source.encoding.name.downcase unless metadata.key?(:charset)
198
- metadata[:digest] = digest(self.version + source)
198
+ metadata[:digest] = digest(source)
199
199
  metadata[:length] = source.bytesize
200
+ metadata[:environment_version] = version
200
201
  else
201
202
  dependencies << build_file_digest_uri(unloaded.filename)
202
203
  metadata = {
203
204
  digest: file_digest(unloaded.filename),
204
205
  length: self.stat(unloaded.filename).size,
205
- dependencies: dependencies
206
+ dependencies: dependencies,
207
+ environment_version: version,
206
208
  }
207
209
  end
208
210
 
@@ -289,7 +291,7 @@ module Sprockets
289
291
  # Internal: Retrieves an asset based on its digest
290
292
  #
291
293
  # unloaded - An UnloadedAsset
292
- # 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"
293
295
  # stored in the cache
294
296
  #
295
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
 
@@ -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
@@ -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
  #
@@ -78,7 +78,7 @@ module Sprockets
78
78
  offset = 0
79
79
  if a["sections"].count != 0 && !a["sections"].last["map"]["mappings"].empty?
80
80
  last_line_count = a["sections"].last["map"].delete("x_sprockets_linecount")
81
- offset += last_line_count
81
+ offset += last_line_count || 1
82
82
 
83
83
  last_offset = a["sections"].last["offset"]["line"]
84
84
  offset += last_offset
@@ -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
@@ -436,7 +436,7 @@ module Sprockets
436
436
  digit = BASE64_VALUES[str[i]]
437
437
  raise ArgumentError unless digit
438
438
  continuation = (digit & VLQ_CONTINUATION_BIT) != 0
439
- digit &= VLQ_CONTINUATION_BIT - 1
439
+ digit &= VLQ_BASE_MASK
440
440
  value += digit << shift
441
441
  if continuation
442
442
  shift += VLQ_BASE_SHIFT
@@ -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.0"
3
+ VERSION = "4.0.3"
4
4
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sprockets
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Stephenson
8
8
  - Joshua Peek
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-10-08 00:00:00.000000000 Z
12
+ date: 2022-03-02 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
@@ -422,7 +423,7 @@ homepage: https://github.com/rails/sprockets
422
423
  licenses:
423
424
  - MIT
424
425
  metadata: {}
425
- post_install_message:
426
+ post_install_message:
426
427
  rdoc_options: []
427
428
  require_paths:
428
429
  - lib
@@ -437,8 +438,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
437
438
  - !ruby/object:Gem::Version
438
439
  version: '0'
439
440
  requirements: []
440
- rubygems_version: 3.0.3
441
- signing_key:
441
+ rubygems_version: 3.2.32
442
+ signing_key:
442
443
  specification_version: 4
443
444
  summary: Rack-based asset packaging system
444
445
  test_files: []