propshaft 0.1.6 → 0.1.7

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: 5a482b12e3d939c6286f02d4e6ca66a141b9124527503f64ceb262277366fca6
4
- data.tar.gz: a0d5ad9626de08fbab61cf450d95abab5ea77a1e5b90a162cbdc79ee1e424e07
3
+ metadata.gz: f01db7988c70a623917c5239f4b76cef03e3364b86f3bb1b9850691d1045d3e1
4
+ data.tar.gz: 066dab4410e31551036e8f539cb351b8c4a6d7c53ae9bd02343b228be16fc85f
5
5
  SHA512:
6
- metadata.gz: 3e60fdc05df54c428a898d460f2df85bdaf1d65a39c4a1025e8e70b758b10e1f39453ee7665c052c6d4b090257cac0b34accb896a25f7362dade2e0fc06b5276
7
- data.tar.gz: d501ae6047c543b522f791d23d8cd6856a0d3c9101c5cbf3fdb3d632a942fa995dc0707c6bdc872040efb8c63d859ace32be66a93b51788f57aa452ce0930850
6
+ metadata.gz: 7b09d882ebf32f6afda261a3dbf32ab322e25b1756b802b70e4b6b16f73f3d91404e8b51be6e5c54a1335332744305d3d149712136cbbdabc67b258229178b9f
7
+ data.tar.gz: 65a13d00417ff13f2678660038ebb7f33074e56b0277b7c51e9df170f9e393ec17cd5ff5ddc888b4e24c469df33ba4f5d8acb19ecf5a2b7626d41c22dac0d781
data/README.md CHANGED
@@ -24,6 +24,11 @@ These assets can be referenced through their logical path using the normal helpe
24
24
  Additionally, Propshaft ships with a CSS function called `asset-path("image.svg")` that'll be compiled into `url("/assets/image-f2e1ec14d6856e1958083094170ca6119c529a73.svg")` when doing `assets:precompile`. This function is applied to all `.css` files.
25
25
 
26
26
 
27
+ ## Bypassing the digest step
28
+
29
+ If you need to put multiple files that refer to each other through Propshaft, like a JavaScript file and its source map, you have to digest these files in advance to retain stable file names. Propshaft looks for the specific pattern of `-[digest].digested.js` as the postfix to any asset file as an indication that the file has already been digested.
30
+
31
+
27
32
  ## Migrating from Sprockets
28
33
 
29
34
  Propshaft does a lot less than Sprockets, by design, so it might well be a fair bit of work to migrate if it's even desirable. This is particularly true if you rely on Sprockets to provide any form of transpiling, like CoffeeScript or Sass, or if you rely on any gems that do. You'll need to either stop transpiling or use a Node-based transpiler, like those in `jsbundling-rails` and `cssbundling-rails`.
@@ -14,7 +14,7 @@ class Propshaft::Assembly
14
14
  end
15
15
 
16
16
  def load_path
17
- Propshaft::LoadPath.new(config.paths)
17
+ @load_path ||= Propshaft::LoadPath.new(config.paths)
18
18
  end
19
19
 
20
20
  def resolver
@@ -25,10 +25,19 @@ class Propshaft::Asset
25
25
  end
26
26
 
27
27
  def digested_path
28
- logical_path.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" }
28
+ if already_digested?
29
+ logical_path
30
+ else
31
+ logical_path.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" }
32
+ end
29
33
  end
30
34
 
31
35
  def ==(other_asset)
32
36
  logical_path.hash == other_asset.logical_path.hash
33
37
  end
38
+
39
+ private
40
+ def already_digested?
41
+ logical_path.to_s =~ /-([0-9a-f]{7,128})\.digested\.[^.]+\z/
42
+ end
34
43
  end
@@ -27,9 +27,23 @@ class Propshaft::LoadPath
27
27
  end
28
28
  end
29
29
 
30
+ # Returns a ActiveSupport::FileUpdateChecker object configured to clear the cache of the load_path
31
+ # when the directories passed during its initialization have changes. This is used in development
32
+ # and test to ensure the map caches are reset when javascript files are changed.
33
+ def cache_sweeper
34
+ @cache_sweeper ||= begin
35
+ exts_to_watch = Mime::EXTENSION_LOOKUP.map(&:first)
36
+ files_to_watch = Array(paths).collect { |dir| [ dir.to_s, exts_to_watch ] }.to_h
37
+
38
+ Rails.application.config.file_watcher.new([], files_to_watch) do
39
+ clear_cache
40
+ end
41
+ end
42
+ end
43
+
30
44
  private
31
45
  def assets_by_path
32
- Hash.new.tap do |mapped|
46
+ @cached_assets_by_path ||= Hash.new.tap do |mapped|
33
47
  paths.each do |path|
34
48
  all_files_from_tree(path).each do |file|
35
49
  logical_path = file.relative_path_from(path)
@@ -42,4 +56,8 @@ class Propshaft::LoadPath
42
56
  def all_files_from_tree(path)
43
57
  path.children.flat_map { |child| child.directory? ? all_files_from_tree(child) : child }
44
58
  end
59
+
60
+ def clear_cache
61
+ @cached_assets_by_path = nil
62
+ end
45
63
  end
@@ -14,9 +14,10 @@ end
14
14
  module Propshaft
15
15
  class Railtie < ::Rails::Railtie
16
16
  config.assets = ActiveSupport::OrderedOptions.new
17
- config.assets.paths = []
18
- config.assets.prefix = "/assets"
19
- config.assets.compilers = [ [ "text/css", Propshaft::Compilers::CssAssetUrls ] ]
17
+ config.assets.paths = []
18
+ config.assets.prefix = "/assets"
19
+ config.assets.compilers = [ [ "text/css", Propshaft::Compilers::CssAssetUrls ] ]
20
+ config.assets.sweep_cache = Rails.env.development? || Rails.env.test?
20
21
 
21
22
  config.after_initialize do |app|
22
23
  config.assets.output_path ||=
@@ -31,6 +32,12 @@ module Propshaft
31
32
  ActiveSupport.on_load(:action_view) do
32
33
  include Propshaft::Helper
33
34
  end
35
+
36
+ if config.assets.sweep_cache
37
+ ActiveSupport.on_load(:action_controller_base) do
38
+ before_action { Rails.application.assets.load_path.cache_sweeper.execute_if_updated }
39
+ end
40
+ end
34
41
  end
35
42
 
36
43
  rake_tasks do |app|
@@ -1,3 +1,3 @@
1
1
  module Propshaft
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: propshaft
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-30 00:00:00.000000000 Z
11
+ date: 2021-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails