sprockets 4.0.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +35 -2
- data/MIT-LICENSE +21 -0
- data/README.md +103 -19
- data/lib/rake/sprocketstask.rb +6 -2
- data/lib/sprockets/add_source_map_comment_to_asset_processor.rb +1 -1
- data/lib/sprockets/asset.rb +23 -6
- data/lib/sprockets/base.rb +2 -2
- data/lib/sprockets/bower.rb +1 -1
- data/lib/sprockets/bundle.rb +1 -1
- data/lib/sprockets/cache/memory_store.rb +20 -11
- data/lib/sprockets/cache.rb +1 -1
- data/lib/sprockets/cached_environment.rb +11 -11
- data/lib/sprockets/coffee_script_processor.rb +2 -2
- data/lib/sprockets/configuration.rb +2 -2
- data/lib/sprockets/context.rb +2 -1
- data/lib/sprockets/dependencies.rb +1 -1
- data/lib/sprockets/digest_utils.rb +10 -13
- data/lib/sprockets/directive_processor.rb +19 -1
- data/lib/sprockets/eco_processor.rb +1 -1
- data/lib/sprockets/ejs_processor.rb +1 -1
- data/lib/sprockets/erb_processor.rb +8 -2
- data/lib/sprockets/exporters/base.rb +2 -3
- data/lib/sprockets/exporting.rb +2 -2
- data/lib/sprockets/loader.rb +5 -3
- data/lib/sprockets/manifest.rb +8 -7
- data/lib/sprockets/npm.rb +1 -1
- data/lib/sprockets/path_utils.rb +1 -1
- data/lib/sprockets/processing.rb +1 -1
- data/lib/sprockets/processor_utils.rb +4 -3
- data/lib/sprockets/sass_processor.rb +1 -1
- data/lib/sprockets/sassc_processor.rb +1 -1
- data/lib/sprockets/server.rb +30 -20
- data/lib/sprockets/source_map_processor.rb +1 -1
- data/lib/sprockets/source_map_utils.rb +4 -4
- data/lib/sprockets/uri_utils.rb +1 -1
- data/lib/sprockets/utils.rb +24 -16
- data/lib/sprockets/version.rb +1 -1
- data/lib/sprockets.rb +4 -1
- metadata +15 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c5995147a647a6d47d625b6cc9f10586506f3832cff0070985ec9560ee3fc0d
|
4
|
+
data.tar.gz: 1befd6f705efbef88f05dc58b38f719f11b445f76c60a95f854a43ef8e84c21d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d47aea08307515c8a0fab29615fbde5f892c91300668afd83b2739032adeb77794d4303e6ecb56c570bc784695d25304f7481fa45c4ab7bbe0727281ee7deab
|
7
|
+
data.tar.gz: 6d0f0b116766053d96402f5d88602374829ef9610160bd8398a093db33ceaafe31a2f2b33a8d0c615769f0bbba7c39d867db90dfded9bc5ff35d0c0ff4482e36
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,40 @@
|
|
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
|
-
##
|
5
|
+
## 4.2.0
|
6
|
+
|
7
|
+
- Rack 3 compatibility. [#758](https://github.com/rails/sprockets/pull/758)
|
8
|
+
- Fix thread safety of `Sprockets::CachedEnvironment` and `Sprockets::Cache::MemoryStore`. [#771](https://github.com/rails/sprockets/pull/771)
|
9
|
+
- Add support for Rack 3.0. Headers set by sprockets will now be lower case. [#758](https://github.com/rails/sprockets/pull/758)
|
10
|
+
- Make `Sprockets::Utils.module_include` thread safe on JRuby. [#759](https://github.com/rails/sprockets/pull/759)
|
11
|
+
|
12
|
+
## 4.1.0
|
13
|
+
|
14
|
+
- Allow age to be altered in asset:clean rake task.
|
15
|
+
- Fix `Sprockets::Server` to return lower-cased response headers to comply with Rack::Lint 3.0. [#744](https://github.com/rails/sprockets/pull/744)
|
16
|
+
- Adding new directive `depend_on_directory` [#668](https://github.com/rails/sprockets/pull/668)
|
17
|
+
- Fix `application/js-sourcemap+json` charset [#669](https://github.com/rails/sprockets/pull/669)
|
18
|
+
- Fix `CachedEnvironment` caching nil values [#723](https://github.com/rails/sprockets/pull/723)
|
19
|
+
- Process `*.jst.ejs.erb` files with ERBProcessor [#674](https://github.com/rails/sprockets/pull/674)
|
20
|
+
- Fix cache key for coffee script processor to be dependent on the filename [#670](https://github.com/rails/sprockets/pull/670)
|
21
|
+
|
22
|
+
## 4.0.3
|
23
|
+
|
24
|
+
- Fix `Manifest#find` yielding from a Promise causing issue on Ruby 3.1.0-dev. [#720](https://github.com/rails/sprockets/pull/720)
|
25
|
+
- Better detect the ERB version to avoid deprecation warnings. [#719](https://github.com/rails/sprockets/pull/719)
|
26
|
+
- Allow assets already fingerprinted to be served through `Sprockets::Server`
|
27
|
+
- Do not fingerprint files that already contain a valid digest in their name
|
28
|
+
- Remove remaining support for Ruby < 2.4.[#672](https://github.com/rails/sprockets/pull/672)
|
29
|
+
|
30
|
+
## 4.0.2
|
31
|
+
|
32
|
+
- Fix `etag` and digest path compilation that were generating string with invalid digest since 4.0.1.
|
33
|
+
|
34
|
+
## 4.0.1
|
35
|
+
|
36
|
+
- Fix for Ruby 2.7 keyword arguments warning in `base.rb`. [#660](https://github.com/rails/sprockets/pull/660)
|
37
|
+
- Fix for when `x_sprockets_linecount` is missing from a source map.
|
38
|
+
- Fix subresource integrity to match the digest of the asset.
|
6
39
|
|
7
40
|
## 4.0.0
|
8
41
|
|
@@ -15,7 +48,7 @@ Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprocket
|
|
15
48
|
|
16
49
|
## 4.0.0.beta9
|
17
50
|
|
18
|
-
- Minimum Ruby version for Sprockets 4 is now 2.5+ which matches minimum ruby
|
51
|
+
- Minimum Ruby version for Sprockets 4 is now 2.5+ which matches minimum ruby version of Rails [#604]
|
19
52
|
- Fix threading bug introduced in Sprockets 4 [#603]
|
20
53
|
- Warn when two potential manifest files exist. [#560]
|
21
54
|
|
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,10 +115,11 @@ 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
|
119
|
-
- [`link_directory`](#link_directory) - Make target directory compile and be
|
120
|
-
- [`link_tree`](#link_tree) - Make target tree compile and be
|
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
|
+
- [`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 `
|
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
|
|
@@ -363,37 +364,78 @@ directory specified by *path*.
|
|
363
364
|
### link
|
364
365
|
|
365
366
|
`link` *path* declares a dependency on the target *path* and adds it to a list
|
366
|
-
of subdependencies to
|
367
|
+
of subdependencies to be compiled when the asset is written out to
|
367
368
|
disk.
|
368
369
|
|
369
370
|
Example:
|
370
371
|
|
371
|
-
If you've got a `manifest.js` file and you want to
|
372
|
-
generated and made available to the public you can link it
|
372
|
+
If you've got a `manifest.js` file and you want to specify that a `admin.js` source file should be
|
373
|
+
generated and made available to the public you can link it by including this in the `manifest.js` file:
|
373
374
|
|
374
375
|
```
|
375
376
|
//= link admin.js
|
376
377
|
```
|
377
378
|
|
379
|
+
The argument to `link` is a _logical path_, that is it will be resolved according to the
|
380
|
+
configured asset load paths. See [Accessing Assets](#accessing-assets) above. A path relative to
|
381
|
+
the current file won't work, it must be a logical path.
|
382
|
+
|
383
|
+
**Caution**: the "link" directive should always have an explicit extension on the end.
|
384
|
+
|
385
|
+
`link` can also be used to include manifest files from mounted Rails engines:
|
386
|
+
|
387
|
+
```
|
388
|
+
//= link my_engine_manifest
|
389
|
+
```
|
390
|
+
|
391
|
+
This would find a manifest file at `my_engine/app/assets/config/my_engine_manifest.js` and include its directives.
|
392
|
+
|
378
393
|
### link_directory
|
379
394
|
|
380
|
-
`link_directory` *path* links all the files inside the directory specified by the *path
|
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.
|
396
|
+
|
397
|
+
Files in subdirectories will not be linked (Compare to [link_tree](#link_tree)).
|
398
|
+
|
399
|
+
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:
|
400
|
+
|
401
|
+
```js
|
402
|
+
//= link_directory ../stylesheets
|
403
|
+
```
|
404
|
+
|
405
|
+
`link_directory` can take an optional second argument with an extension or content-type, with the
|
406
|
+
two arguments separated by a space:
|
407
|
+
|
408
|
+
```js
|
409
|
+
//= link_directory ../stylesheets text/css
|
410
|
+
//= link_directory ../more_stylesheets .css
|
411
|
+
```
|
412
|
+
|
413
|
+
This will limit the matching files to link to only files recognized as that type. An extension is
|
414
|
+
just a shortcut for the type referenced, it does not need to match the source file exactly, but
|
415
|
+
instead identifies the content-type the source file must be recognized as.
|
381
416
|
|
382
417
|
### link_tree
|
383
418
|
|
384
|
-
`link_tree` *path* works like
|
419
|
+
`link_tree` *path* works like [link_directory](#link_directory), but operates
|
385
420
|
recursively to link all files in all subdirectories of the
|
386
421
|
directory specified by *path*.
|
387
422
|
|
388
423
|
Example:
|
389
424
|
|
390
|
-
|
425
|
+
```js
|
426
|
+
//= link_tree ./path/to/folder
|
427
|
+
```
|
428
|
+
|
429
|
+
Like `link_directory`, the argument is path relative to the current file, it is *not* a 'logical path' tresolved against load paths.
|
430
|
+
|
431
|
+
|
432
|
+
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
433
|
|
392
434
|
```js
|
393
|
-
//= link_tree ./path/to/folder
|
435
|
+
//= link_tree ./path/to/folder text/javascript
|
436
|
+
//= link_tree ./path/to/other_folder .js
|
394
437
|
```
|
395
438
|
|
396
|
-
> Note: There is an intentional space between the path and the extension
|
397
439
|
|
398
440
|
### depend_on
|
399
441
|
|
@@ -412,11 +454,53 @@ you need to tell sprockets that it needs to re-compile the file if `bar.data` ch
|
|
412
454
|
var bar = '<%= File.read("bar.data") %>'
|
413
455
|
```
|
414
456
|
|
457
|
+
To depend on an entire directory containing multiple files, use `depend_on_directory`
|
458
|
+
|
415
459
|
### depend_on_asset
|
416
460
|
|
417
461
|
`depend_on_asset` *path* works like `depend_on`, but operates
|
418
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`.
|
419
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
|
+
|
420
504
|
### stub
|
421
505
|
|
422
506
|
`stub` *path* excludes that asset and its dependencies from the asset bundle.
|
@@ -441,7 +525,7 @@ Generated files are cached. If you're using an `ENV` var then
|
|
441
525
|
when you change then ENV var the asset will be forced to
|
442
526
|
recompile. This behavior is only true for environment variables,
|
443
527
|
if you are pulling a value from somewhere else, such as a database,
|
444
|
-
must manually invalidate the cache to see the change.
|
528
|
+
you must manually invalidate the cache to see the change.
|
445
529
|
|
446
530
|
If you're using Rails, there are helpers you can use such as `asset_url`
|
447
531
|
that will cause a recompile if the value changes.
|
@@ -458,9 +542,9 @@ When you modify the `logo.png` on disk, it will force `application.css` to be
|
|
458
542
|
recompiled so that the fingerprint will be correct in the generated asset.
|
459
543
|
|
460
544
|
You can manually make sprockets depend on any other file that is generated
|
461
|
-
by sprockets by using the `depend_on` directive. Rails
|
462
|
-
feature by auto calling `depend_on` on the original asset
|
463
|
-
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.
|
464
548
|
|
465
549
|
### Styling with Sass and SCSS
|
466
550
|
|
@@ -573,19 +657,19 @@ Several JavaScript and CSS minifiers are available through shorthand.
|
|
573
657
|
In Rails you will specify them with:
|
574
658
|
|
575
659
|
```ruby
|
576
|
-
config.assets.js_compressor = :
|
660
|
+
config.assets.js_compressor = :terser
|
577
661
|
config.assets.css_compressor = :scss
|
578
662
|
```
|
579
663
|
|
580
664
|
If you're not using Rails, configure this directly on the "environment".
|
581
665
|
|
582
666
|
``` ruby
|
583
|
-
environment.js_compressor = :
|
667
|
+
environment.js_compressor = :terser
|
584
668
|
environment.css_compressor = :scss
|
585
669
|
```
|
586
670
|
|
587
671
|
If you are using Sprockets directly with a Rack app, don't forget to add
|
588
|
-
the `
|
672
|
+
the `terser` and `sass` gems to your Gemfile when using above options.
|
589
673
|
|
590
674
|
### Gzip
|
591
675
|
|
data/lib/rake/sprocketstask.rb
CHANGED
@@ -69,9 +69,12 @@ module Rake
|
|
69
69
|
#
|
70
70
|
attr_accessor :assets
|
71
71
|
|
72
|
-
#
|
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
|
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
|
#
|
data/lib/sprockets/asset.rb
CHANGED
@@ -6,7 +6,7 @@ module Sprockets
|
|
6
6
|
class Asset
|
7
7
|
attr_reader :logical_path
|
8
8
|
|
9
|
-
# Private:
|
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
|
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
|
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
|
-
|
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
|
-
|
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(
|
158
|
+
DigestUtils.integrity_uri(digest)
|
142
159
|
end
|
143
160
|
|
144
161
|
# Public: Add enumerator to allow `Asset` instances to be used as Rack
|
data/lib/sprockets/base.rb
CHANGED
data/lib/sprockets/bower.rb
CHANGED
@@ -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
|
16
|
+
# Returns candidate filenames.
|
17
17
|
def resolve_alternates(load_path, logical_path)
|
18
18
|
candidates, deps = super
|
19
19
|
|
data/lib/sprockets/bundle.rb
CHANGED
@@ -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
|
13
|
+
# :stubbed - Set of asset URIs to subtract from the required set.
|
14
14
|
#
|
15
15
|
# Also see DirectiveProcessor.
|
16
16
|
class Bundle
|
@@ -22,6 +22,7 @@ module Sprockets
|
|
22
22
|
def initialize(max_size = DEFAULT_MAX_SIZE)
|
23
23
|
@max_size = max_size
|
24
24
|
@cache = {}
|
25
|
+
@mutex = Mutex.new
|
25
26
|
end
|
26
27
|
|
27
28
|
# Public: Retrieve value from cache.
|
@@ -32,12 +33,14 @@ module Sprockets
|
|
32
33
|
#
|
33
34
|
# Returns Object or nil or the value is not set.
|
34
35
|
def get(key)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
@mutex.synchronize do
|
37
|
+
exists = true
|
38
|
+
value = @cache.delete(key) { exists = false }
|
39
|
+
if exists
|
40
|
+
@cache[key] = value
|
41
|
+
else
|
42
|
+
nil
|
43
|
+
end
|
41
44
|
end
|
42
45
|
end
|
43
46
|
|
@@ -50,9 +53,11 @@ module Sprockets
|
|
50
53
|
#
|
51
54
|
# Returns Object value.
|
52
55
|
def set(key, value)
|
53
|
-
@
|
54
|
-
|
55
|
-
|
56
|
+
@mutex.synchronize do
|
57
|
+
@cache.delete(key)
|
58
|
+
@cache[key] = value
|
59
|
+
@cache.shift if @cache.size > @max_size
|
60
|
+
end
|
56
61
|
value
|
57
62
|
end
|
58
63
|
|
@@ -60,14 +65,18 @@ module Sprockets
|
|
60
65
|
#
|
61
66
|
# Returns String.
|
62
67
|
def inspect
|
63
|
-
|
68
|
+
@mutex.synchronize do
|
69
|
+
"#<#{self.class} size=#{@cache.size}/#{@max_size}>"
|
70
|
+
end
|
64
71
|
end
|
65
72
|
|
66
73
|
# Public: Clear the cache
|
67
74
|
#
|
68
75
|
# Returns true
|
69
76
|
def clear(options=nil)
|
70
|
-
@
|
77
|
+
@mutex.synchronize do
|
78
|
+
@cache.clear
|
79
|
+
end
|
71
80
|
true
|
72
81
|
end
|
73
82
|
end
|
data/lib/sprockets/cache.rb
CHANGED
@@ -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
|
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
|
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.
|
@@ -16,11 +16,11 @@ module Sprockets
|
|
16
16
|
initialize_configuration(environment)
|
17
17
|
|
18
18
|
@cache = environment.cache
|
19
|
-
@stats =
|
20
|
-
@entries =
|
21
|
-
@uris =
|
22
|
-
@processor_cache_keys =
|
23
|
-
@resolved_dependencies =
|
19
|
+
@stats = Concurrent::Map.new
|
20
|
+
@entries = Concurrent::Map.new
|
21
|
+
@uris = Concurrent::Map.new
|
22
|
+
@processor_cache_keys = Concurrent::Map.new
|
23
|
+
@resolved_dependencies = Concurrent::Map.new
|
24
24
|
end
|
25
25
|
|
26
26
|
# No-op return self as cached environment.
|
@@ -31,27 +31,27 @@ module Sprockets
|
|
31
31
|
|
32
32
|
# Internal: Cache Environment#entries
|
33
33
|
def entries(path)
|
34
|
-
@entries
|
34
|
+
@entries.fetch_or_store(path) { super(path) }
|
35
35
|
end
|
36
36
|
|
37
37
|
# Internal: Cache Environment#stat
|
38
38
|
def stat(path)
|
39
|
-
@stats
|
39
|
+
@stats.fetch_or_store(path) { super(path) }
|
40
40
|
end
|
41
41
|
|
42
42
|
# Internal: Cache Environment#load
|
43
43
|
def load(uri)
|
44
|
-
@uris
|
44
|
+
@uris.fetch_or_store(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
|
49
|
+
@processor_cache_keys.fetch_or_store(str) { super(str) }
|
50
50
|
end
|
51
51
|
|
52
52
|
# Internal: Cache Environment#resolve_dependency
|
53
53
|
def resolve_dependency(str)
|
54
|
-
@resolved_dependencies
|
54
|
+
@resolved_dependencies.fetch_or_store(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
|
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::
|
62
|
+
# `Digest::SHA512`.
|
63
63
|
#
|
64
|
-
# environment.digest_class = Digest::
|
64
|
+
# environment.digest_class = Digest::SHA512
|
65
65
|
#
|
66
66
|
def digest_class=(klass)
|
67
67
|
self.config = config.merge(digest_class: klass).freeze
|
data/lib/sprockets/context.rb
CHANGED
@@ -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
|
-
#
|
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
|