rails-assets-manifest 1.0.0 → 2.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: 20fbdae0fd6c2a519e249839ea5d49d59cf397de3381b34554473a932abddc71
4
- data.tar.gz: 40652e5ad01c108a0be622b689175c9f9a05c6b94042c88d89645e0a41881e70
3
+ metadata.gz: 4486b5a02b2aea1cfdcc7afbd89a0748b6f746476175335a9af1d22afb0d4ffa
4
+ data.tar.gz: e2007d8ac77c1183d5d5f598b1b6442ec09abe36b139c93c5a693330ffc41001
5
5
  SHA512:
6
- metadata.gz: 44179030578e024114a95376ee277b130d4e6998d497eb96c7616a319a008d38ec33cf24dce8bd55410e3a687c0ad848ee5c20a9adfbf79b41384258d6b53311
7
- data.tar.gz: 598b10ec984f8c488df4d3b7ed48409c06db220b2e85a86babcc7e42187e9380835f0140a57af523dd7d35848205a3c232e2721519783ac3d9343b8f69cb5720
6
+ metadata.gz: db93bb819d42cbb4771404d560d50c37c4cd97fe4cfabdf764a5b0efc49ccfc0bf6a1f644bc46204a4cabfb2bdbf6d77ddf100105a0231f796f41f0b940b1bf2
7
+ data.tar.gz: be4ebdfe6625038294029a2bf2916dff4488184716a69fcb8e7f18fc4db9375953ab501bdea59f933b4d6e1ca3357235b71544b4a236ebe239956a4ec07793f6
@@ -0,0 +1,61 @@
1
+ ---
2
+ name: test
3
+ on: push
4
+ jobs:
5
+ rspec:
6
+ name: "Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}"
7
+ runs-on: ubuntu-20.04
8
+
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ ruby:
13
+ - "3.0"
14
+ - "2.7"
15
+ - "2.6"
16
+ - "2.5"
17
+ rails:
18
+ - "6.1"
19
+ - "6.0"
20
+ - "5.2"
21
+ - master
22
+ exclude:
23
+ - ruby: "3.0"
24
+ rails: "5.2"
25
+ - ruby: "2.6"
26
+ rails: master
27
+ - ruby: "2.5"
28
+ rails: master
29
+
30
+ env:
31
+ BUNDLE_GEMFILE: gemfiles/rails_${{ matrix.rails }}.gemfile
32
+
33
+ steps:
34
+ - uses: actions/checkout@master
35
+ - uses: ruby/setup-ruby@v1
36
+ with:
37
+ ruby-version: ${{ matrix.ruby }}
38
+ bundler-cache: true
39
+ env:
40
+ BUNDLE_WITHOUT: development
41
+ BUNDLE_JOBS: 4
42
+ BUNDLE_RETRY: 3
43
+
44
+ - run: bundle exec rspec --color
45
+
46
+ rubocop:
47
+ name: rubocop
48
+ runs-on: ubuntu-20.04
49
+
50
+ steps:
51
+ - uses: actions/checkout@master
52
+ - uses: ruby/setup-ruby@v1
53
+ with:
54
+ ruby-version: 3.0
55
+ bundler-cache: true
56
+ env:
57
+ BUNDLE_WITHOUT: development
58
+ BUNDLE_JOBS: 4
59
+ BUNDLE_RETRY: 3
60
+
61
+ - run: bundle exec rubocop --parallel --fail-level E
data/.gitignore CHANGED
@@ -3,6 +3,8 @@
3
3
  /coverage
4
4
  /doc
5
5
  /pkg
6
+ /spec/dummy/log
7
+ /spec/dummy/tmp
6
8
  /spec/examples.txt
7
9
  /tmp
8
10
  /vendor/bundle
data/.rspec CHANGED
@@ -1,3 +1,4 @@
1
- --format documentation
1
+ --backtrace
2
2
  --color
3
+ --format documentation
3
4
  --require spec_helper
data/.rubocop.yml CHANGED
@@ -1,106 +1,18 @@
1
- require:
2
- - rubocop-rspec
3
-
4
1
  AllCops:
5
- Exclude:
6
- - 'bin/**'
7
- - 'config/initializers/integration*'
8
- - 'db/schema.rb'
9
- - 'vendor/**'
10
- TargetRubyVersion: 2.5
11
- TargetRailsVersion: 5.2
12
-
13
-
14
-
15
- # -----------------------------------------------------------------------------
16
- # RAILS
17
-
18
- Rails:
19
- Enabled: true
20
-
21
- #
22
- # False positives:
23
- # * On Acfs::Resource#update_attriubutes!
24
- #
25
- Rails/ActiveRecordAliases:
26
- Exclude:
27
- - spec/**/*_spec.rb
28
-
29
- #
30
- # False positives:
31
- # * On embedded models in migrations.
32
- #
33
- Rails/ApplicationRecord:
34
- Exclude:
35
- - 'db/**/*'
36
-
37
- #
38
- # Often when triggered it just wants to pass joined paths as separate
39
- # arguments but that can hurt readability.
40
- #
41
- Rails/FilePath:
42
- Enabled: false
43
-
44
- #
45
- # False positives:
46
- # * Specs and migrations often need to update things without validations.
47
- #
48
- Rails/SkipsModelValidations:
49
- Exclude:
50
- - 'db/migrations/**.rb'
51
- - 'spec/**/*_spec.rb'
52
-
53
-
54
-
55
- # -----------------------------------------------------------------------------
56
- # RSPEC
57
-
58
- RSpec:
59
2
  Include:
60
- - 'spec/**/*_spec.rb'
61
- - 'spec/spec_helper.rb'
62
- - 'spec/rails_helper.rb'
63
-
64
- RSpec/ContextWording:
65
- Enabled: false
66
-
67
- RSpec/ExampleLength:
68
- Enabled: false
69
-
70
- RSpec/ExpectInHook:
71
- Enabled: false
72
-
73
- RSpec/FilePath:
74
- Exclude:
75
- - 'spec/client/**/*_spec.rb'
76
-
77
- RSpec/MessageSpies:
78
- Enabled: false
79
-
80
- RSpec/MissingExampleGroupArgument:
81
- Enabled: false
82
-
83
- RSpec/MultipleExpectations:
84
- Enabled: false
85
-
86
- RSpec/NestedGroups:
87
- Max: 5
88
-
89
- # -----------------------------------------------------------------------------
90
- # Layout
91
-
92
- Layout/AlignParameters:
93
- EnforcedStyle: with_fixed_indentation
3
+ - '**/*.rb'
4
+ TargetRubyVersion: 2.5
5
+ NewCops: enable
94
6
 
95
7
  Layout/CaseIndentation:
96
8
  EnforcedStyle: end
9
+ IndentOneStep: true
97
10
  SupportedStyles:
98
11
  - case
99
12
  - end
100
- IndentOneStep: true
101
13
 
102
- Layout/MultilineMethodCallIndentation:
103
- EnforcedStyle: indented
14
+ Layout/ArgumentAlignment:
15
+ EnforcedStyle: with_fixed_indentation
104
16
 
105
17
  Layout/SpaceInsideBlockBraces:
106
18
  EnforcedStyle: space
@@ -111,101 +23,26 @@ Layout/SpaceInsideHashLiteralBraces:
111
23
  EnforcedStyle: no_space
112
24
 
113
25
 
114
-
115
- # -----------------------------------------------------------------------------
116
- # Lint
117
-
118
- #
119
- # False positives:
120
- # * expect { something }.to change { something } often triggers this
121
- #
122
- Lint/AmbiguousBlockAssociation:
123
- Exclude:
124
- - 'spec/**/*_spec.rb'
125
-
126
-
127
-
128
- # -----------------------------------------------------------------------------
129
- # Metrics
130
-
131
26
  Metrics/BlockLength:
132
27
  Exclude:
133
- - 'db/**/*'
134
- - 'spec/**/*'
135
- - 'config/**/*'
136
- - '**/*.rake'
137
-
138
- Metrics/ClassLength:
139
- Max: 200
28
+ - spec/**/*_spec.rb
140
29
 
141
30
  Metrics/LineLength:
142
31
  Exclude:
143
- - 'db/**/*'
144
- - 'spec/**/*'
145
- - 'config/**/*'
146
-
147
- Metrics/MethodLength:
148
- Exclude:
149
- - 'db/**/*'
150
-
151
-
152
-
153
- # -----------------------------------------------------------------------------
154
- # Style
32
+ - spec/**/*_spec.rb
155
33
 
156
- Style/BracesAroundHashParameters:
157
- EnforcedStyle: context_dependent
158
34
 
159
- #
160
- # Both styles or mixtures are reasonable
161
- #
162
35
  Style/ClassAndModuleChildren:
163
- EnforcedStyle: compact
164
36
  Enabled: false
165
37
 
166
- #
167
- # Would be better but unlikely...
168
- #
169
38
  Style/Documentation:
170
39
  Enabled: false
171
40
 
172
- #
173
- # Scripts might include on top-level
174
- #
175
- Style/MixinUsage:
176
- Exclude:
177
- - 'scripts/**/*'
178
-
179
41
  Style/RaiseArgs:
180
42
  EnforcedStyle: compact
181
43
 
182
- #
183
- # Quick single line rescues in specs
184
- #
185
- Style/RescueModifier:
186
- Exclude:
187
- - 'spec/**/*_spec.rb'
188
-
189
- #
190
- # Quick single line rescues in specs
191
- #
192
- Style/RescueStandardError:
193
- Exclude:
194
- - 'spec/**/*_spec.rb'
195
-
196
- #
197
- # Often used pattern in chaining subjects in specs
198
- #
199
- Style/Semicolon:
200
- Exclude:
201
- - 'spec/**/*_spec.rb'
202
-
203
44
  Style/SignalException:
204
45
  EnforcedStyle: only_raise
205
46
 
206
- Style/TrailingCommaInArrayLiteral:
207
- EnforcedStyleForMultiline: comma
208
-
209
- Style/TrailingCommaInHashLiteral:
210
- EnforcedStyleForMultiline: comma
211
-
47
+ Style/TrivialAccessors:
48
+ AllowPredicates: true
data/Appraisals ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ appraise 'rails-6.1' do
4
+ gem 'rails', '~> 6.1.0'
5
+ end
6
+
7
+ appraise 'rails-6.0' do
8
+ gem 'rails', '~> 6.0.0'
9
+ end
10
+
11
+ appraise 'rails-5.2' do
12
+ gem 'rails', '~> 5.2.0'
13
+ end
14
+
15
+ appraise 'rails-master' do
16
+ gem 'rails', github: 'rails/rails'
17
+ end
data/CHANGELOG.md CHANGED
@@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Changelog](http://keepachangelog.com/).
5
5
 
6
6
 
7
+
7
8
  ## Unreleased
8
9
  ---
9
10
 
@@ -16,6 +17,52 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch
16
17
  ### Breaks
17
18
 
18
19
 
20
+ ## 2.1.1 - (2021-06-20)
21
+ ---
22
+
23
+ ### Fixes
24
+ * Super method signature for keyword arguments
25
+
26
+
27
+ ## 2.1.0 - (2019-09-11)
28
+ ---
29
+
30
+ ### New
31
+ * Automatically add `crossorigin="anonymous"` for SRI resources
32
+ * Separate manifest caching and eager loading
33
+
34
+ ### Changes
35
+ * Remove defunct onboot manifest validation (f3fe8f57)
36
+
37
+
38
+ ## 2.0.1 - (2019-08-09)
39
+ ---
40
+
41
+ ### Fixes
42
+ * Fix check if assets option node already exists
43
+
44
+
45
+ ## 2.0.0 - (2019-08-08)
46
+ ---
47
+
48
+ ### New
49
+ * Accept glob patterns for `manifests` option
50
+
51
+
52
+ ### Breaks
53
+ * Change `manifest` configuration option into `manifests` to support multiple files
54
+
55
+
56
+ ## 1.1.0 - (2019-08-08)
57
+ ---
58
+
59
+ ### New
60
+ * Add passthrough option to load assets from other plugins (e.g. sprockets)
61
+
62
+ ### Changes
63
+ * Only default to add available integrity if asset is from the manifest
64
+
65
+
19
66
  ## 1.0.0 - (2019-08-07)
20
67
  ---
21
68
 
data/Gemfile CHANGED
@@ -5,5 +5,15 @@ source 'https://rubygems.org'
5
5
  # Load gem's dependencies
6
6
  gemspec
7
7
 
8
- gem 'rake', '~> 12.0'
8
+ gem 'rails'
9
+
10
+ gem 'rake', '~> 13.0'
9
11
  gem 'rspec', '~> 3.0'
12
+ gem 'rspec-rails', '~> 5.0'
13
+ gem 'rubocop', '~> 1.14'
14
+
15
+ gem 'pry'
16
+
17
+ group :development do
18
+ gem 'appraisal'
19
+ end
data/README.md CHANGED
@@ -17,7 +17,7 @@ This gem does not make any assumption on which tool to use to make your assets n
17
17
  }
18
18
  ```
19
19
 
20
- This gem does not add new helper methods but extends the existing helpers. SRI is automatically added if available and within a secure context:
20
+ This gem does not add new helper methods but extends the existing helpers. SRI is automatically added if available and within a secure context. A `crossorigin="anonymous"` attribute is automatically added if non is present.
21
21
 
22
22
  ```slim
23
23
  html
@@ -27,8 +27,8 @@ html
27
27
  ```
28
28
 
29
29
  ```html
30
- <link rel="stylesheet" media="all" href="2b16adf6f756625a0194.css" integrity="sha384-/oreyvcV6U6htGZD0fDWR8/Txezke8KhD0QNgHb660hSaW7M+ZzxxuB4Vo+PuAC9">
31
- <script src="2b16adf6f756625a0194.js" integrity="sha384-iJ55fQQApbQGxWEWSbWStBabi+yNGxZSQy/010+1Dhxl+rymyhGF4NtjUkOsYv7B"></script>
30
+ <link rel="stylesheet" media="all" href="2b16adf6f756625a0194.css" integrity="sha384-/oreyvcV6U6htGZD0fDWR8/Txezke8KhD0QNgHb660hSaW7M+ZzxxuB4Vo+PuAC9" crossorigin="anonymous">
31
+ <script src="2b16adf6f756625a0194.js" integrity="sha384-iJ55fQQApbQGxWEWSbWStBabi+yNGxZSQy/010+1Dhxl+rymyhGF4NtjUkOsYv7B" crossorigin="anonymous"></script>
32
32
  ```
33
33
 
34
34
  ## Installation
@@ -44,13 +44,19 @@ gem 'rails-assets-manifest'
44
44
  The manifest path can be configured e.g. in an environment:
45
45
 
46
46
  ```ruby
47
- config.assets.manifest = "public/.asset-manifest.json"
47
+ config.assets.manifests = %w(public/.asset-manifest.json)
48
48
  ```
49
49
 
50
- If `config.cache_classes` is set to `true` the manifest file be loaded once on boot and raise errors if missing or invalid.
50
+ If `config.cache_classes` is set to `true` the manifest file be loaded once on boot.
51
51
 
52
52
  Assets included with `integrity: true` will raise an error if the integrity option is missing in the manifest.
53
53
 
54
+ Multiple manifests can be loaded by specifying multiple files. Glob patterns are supported:
55
+
56
+ ```ruby
57
+ config.assets.manifests = %w(public/.manifest.*.json lib/manifest.json)
58
+ ```
59
+
54
60
  ## TODO
55
61
 
56
62
  * Override/Join with `asset_host` URL?
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'rails/assets/manifest'
@@ -0,0 +1,16 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.2.0"
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "rspec-rails", "~> 5.0"
9
+ gem "rubocop", "~> 1.14"
10
+ gem "pry"
11
+
12
+ group :development do
13
+ gem "appraisal"
14
+ end
15
+
16
+ gemspec path: "../"
@@ -0,0 +1,16 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 6.0.0"
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "rspec-rails", "~> 5.0"
9
+ gem "rubocop", "~> 1.14"
10
+ gem "pry"
11
+
12
+ group :development do
13
+ gem "appraisal"
14
+ end
15
+
16
+ gemspec path: "../"
@@ -0,0 +1,16 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 6.1.0"
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "rspec-rails", "~> 5.0"
9
+ gem "rubocop", "~> 1.14"
10
+ gem "pry"
11
+
12
+ group :development do
13
+ gem "appraisal"
14
+ end
15
+
16
+ gemspec path: "../"
@@ -0,0 +1,16 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", github: "rails/rails"
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "rspec-rails", "~> 5.0"
9
+ gem "rubocop", "~> 1.14"
10
+ gem "pry"
11
+
12
+ group :development do
13
+ gem "appraisal"
14
+ end
15
+
16
+ gemspec path: "../"
@@ -13,22 +13,37 @@ module Rails
13
13
  require 'rails/assets/manifest/railtie' if defined?(Rails::Railtie)
14
14
 
15
15
  class ManifestMissing < StandardError; end
16
+
16
17
  class ManifestInvalid < StandardError; end
18
+
17
19
  class EntryMissing < StandardError; end
20
+
18
21
  class IntegrityMissing < StandardError; end
19
22
 
20
23
  class << self
21
24
  delegate :lookup, :lookup!, to: :instance
22
25
 
23
- def instance
24
- @instance ||= begin
26
+ attr_reader :instance
27
+
28
+ def prepare!
29
+ @instance = begin
25
30
  config = Rails.application.config
26
31
 
27
32
  Manifest.new \
28
- path: config.assets.manifest,
33
+ files: config.assets.manifests.map {|path| Rails.root.join(path) },
29
34
  cache: config.cache_classes
30
35
  end
31
36
  end
37
+
38
+ def eager_load!
39
+ return unless @instance
40
+
41
+ @instance.eager_load!
42
+ end
43
+
44
+ def passthrough?
45
+ Rails.application.config.assets.passthrough
46
+ end
32
47
  end
33
48
  end
34
49
  end
@@ -2,16 +2,24 @@
2
2
 
3
3
  module Rails::Assets::Manifest
4
4
  module Helper
5
- def compute_asset_path(name, **_kwargs)
5
+ def compute_asset_path(name, _options)
6
6
  ::Rails::Assets::Manifest.lookup!(name).src
7
+ rescue EntryMissing
8
+ return super if Rails::Assets::Manifest.passthrough?
9
+
10
+ raise
7
11
  end
8
12
 
9
- def asset_integrity(name, **kwargs)
10
- ::Rails::Assets::Manifest.lookup!(path_with_extname(name, **kwargs)).integrity
13
+ def asset_integrity(name, options)
14
+ ::Rails::Assets::Manifest.lookup!(path_with_extname(name, options)).integrity
15
+ rescue EntryMissing
16
+ return super if Rails::Assets::Manifest.passthrough?
17
+
18
+ raise
11
19
  end
12
20
 
13
21
  def javascript_include_tag(*sources, integrity: nil, **kwargs)
14
- return super(*sources, **kwargs) unless compute_integrity?(integrity)
22
+ return super(*sources, **kwargs) unless manifest_use_integrity?(integrity)
15
23
 
16
24
  with_integrity(sources, integrity, :javascript, **kwargs) do |source, options|
17
25
  super(source, options)
@@ -19,7 +27,7 @@ module Rails::Assets::Manifest
19
27
  end
20
28
 
21
29
  def stylesheet_link_tag(*sources, integrity: nil, **kwargs)
22
- return super(*sources, **kwargs) unless compute_integrity?(integrity)
30
+ return super(*sources, **kwargs) unless manifest_use_integrity?(integrity)
23
31
 
24
32
  with_integrity(sources, integrity, :stylesheet, **kwargs) do |source, options|
25
33
  super(source, options)
@@ -28,29 +36,57 @@ module Rails::Assets::Manifest
28
36
 
29
37
  private
30
38
 
31
- def compute_integrity?(option)
32
- return false unless secure_subresource_integrity_context?
39
+ def manifest_use_integrity?(option)
40
+ return false unless secure_request_context?
33
41
 
34
42
  option || option.nil?
35
43
  end
36
44
 
45
+ # http://www.w3.org/TR/SRI/#non-secure-contexts-remain-non-secure
46
+ def secure_request_context?
47
+ respond_to?(:request) && request && (request.local? || request.ssl?)
48
+ end
49
+
50
+ # rubocop:disable Metrics/AbcSize
51
+ # rubocop:disable Metrics/CyclomaticComplexity
52
+ # rubocop:disable Metrics/MethodLength
53
+ # rubocop:disable Style/IfUnlessModifier
37
54
  def with_integrity(sources, required, type, **kwargs)
38
55
  sources.map do |source|
39
- integrity = asset_integrity(source, type: type, **kwargs)
56
+ path = path_with_extname(source, type: type, **kwargs)
40
57
 
41
- if required && !integrity
42
- raise IntegrityMissing.new <<~ERROR
43
- SRI missing for #{path_with_extname(source, kwargs)}
44
- ERROR
58
+ # integrity hash passed directly
59
+ if required.is_a?(String)
60
+ next yield(source, integrity: required, crossorigin: 'anonymous', **kwargs)
45
61
  end
46
62
 
47
- yield(source, integrity: integrity, **kwargs)
48
- end.join.html_safe
49
- end
63
+ # Explicit passed `true` option
64
+ if required
65
+ integrity = asset_integrity(source, type: type, **kwargs)
66
+
67
+ raise IntegrityMissing.new "SRI missing for #{path}" unless integrity
50
68
 
51
- def secure_subresource_integrity_context?
52
- respond_to?(:request) && (request&.local? || request&.ssl?)
69
+ next yield(source, integrity: integrity, crossorigin: 'anonymous', **kwargs)
70
+ end
71
+
72
+ # No integrity option passed or `nil` default from above
73
+ if required.nil?
74
+ entry = ::Rails::Assets::Manifest.lookup(path)
75
+
76
+ # Only if it is an asset from our manifest and there is an integrity
77
+ # we default to adding one
78
+ if entry && entry.integrity
79
+ next yield(source, integrity: entry.integrity, crossorigin: 'anonymous', **kwargs)
80
+ end
81
+ end
82
+
83
+ yield(source, **kwargs)
84
+ end.join.html_safe
53
85
  end
86
+ # rubocop:enable Style/IfUnlessModifier
87
+ # rubocop:enable Metrics/MethodLength
88
+ # rubocop:enable Metrics/CyclomaticComplexity
89
+ # rubocop:enable Metrics/AbcSize
54
90
 
55
91
  def path_with_extname(path, options)
56
92
  path = path.to_s
@@ -4,11 +4,9 @@ module Rails::Assets::Manifest
4
4
  class Manifest
5
5
  attr_reader :path
6
6
 
7
- def initialize(path:, cache: true)
8
- @path = path.to_s.freeze
7
+ def initialize(files:, cache: true)
8
+ @files = Array(files).flatten.each(&:freeze).freeze
9
9
  @cache = cache
10
-
11
- data if cache?
12
10
  end
13
11
 
14
12
  def cache?
@@ -22,12 +20,20 @@ module Rails::Assets::Manifest
22
20
  def lookup!(name)
23
21
  lookup(name) || begin
24
22
  raise EntryMissing.new <<~ERROR
25
- Can't find #{name} in #{path}. Your manifest contains:
23
+ Can't find #{name} in #{path}. Your manifests contain:
26
24
  #{JSON.pretty_generate(data.keys)}
27
25
  ERROR
28
26
  end
29
27
  end
30
28
 
29
+ def key?(name)
30
+ data.key?(name.to_s)
31
+ end
32
+
33
+ def eager_load!
34
+ data
35
+ end
36
+
31
37
  private
32
38
 
33
39
  Entry = Struct.new(:src, :integrity) do
@@ -44,21 +50,27 @@ module Rails::Assets::Manifest
44
50
  end
45
51
  end
46
52
 
53
+ def files
54
+ @files.map {|path| Dir.glob(path) }.flatten
55
+ end
56
+
47
57
  def load
48
- JSON.parse(File.read(path)).transform_values do |entry|
49
- if entry.is_a?(String)
50
- Entry.new(entry, nil)
51
- elsif entry.is_a?(Hash)
52
- Entry.new(entry.fetch('src'), entry['integrity'])
53
- else
54
- raise "Invalid entry: #{entry.inspect}"
58
+ files.each_with_object({}) do |file, entries|
59
+ JSON.parse(File.read(file)).each_pair do |key, entry|
60
+ if entry.is_a?(String)
61
+ entries[key] = Entry.new(entry, nil)
62
+ elsif entry.is_a?(Hash) && entry.key?('src')
63
+ entries[key] = Entry.new(entry['src'], entry['integrity'])
64
+ else
65
+ raise "Invalid manifest entry: #{entry.inspect}"
66
+ end
55
67
  end
56
68
  end
57
69
  rescue Errno::ENOENT => e
58
70
  raise ManifestMissing.new <<~ERROR
59
71
  Asset manifest does not exist: #{e}
60
72
  ERROR
61
- rescue => e
73
+ rescue StandardError => e
62
74
  raise ManifestInvalid.new <<~ERROR
63
75
  Asset manifest could not be loaded: #{e}
64
76
  ERROR
@@ -4,8 +4,19 @@ module Rails
4
4
  module Assets
5
5
  module Manifest
6
6
  class Railtie < ::Rails::Railtie
7
- config.assets = ::ActiveSupport::OrderedOptions.new
8
- config.assets.manifest = 'public/assets/manifest.json'
7
+ # If this plugin is used with sprockets this option
8
+ # already exists and must not be overriden. Otherwise
9
+ # all sprockets default options are removed breaking
10
+ # sprockets.
11
+ config.assets = ::ActiveSupport::OrderedOptions.new unless config.respond_to?(:assets)
12
+
13
+ # Path where the manifest files are loaded from.
14
+ config.assets.manifests = ['public/assets/manifest.json']
15
+
16
+ # If set to true missing assets will not raise an
17
+ # exception but are passed through to sprockets
18
+ # or rails own asset methods.
19
+ config.assets.passthrough = false
9
20
 
10
21
  config.after_initialize do |_|
11
22
  ActiveSupport.on_load(:action_view) do
@@ -13,26 +24,12 @@ module Rails
13
24
  end
14
25
  end
15
26
 
16
- initializer 'rails-assets-manifest' do |app|
17
- ::Rails::Assets::Manifest.instance if server?
18
- end
19
-
20
- private
21
-
22
- def server?
23
- !(console? || generator? || rake?)
24
- end
25
-
26
- def console?
27
- defined?(Rails::Console)
28
- end
29
-
30
- def generator?
31
- defined?(Rails::Generators)
27
+ config.to_prepare do
28
+ ::Rails::Assets::Manifest.prepare!
32
29
  end
33
30
 
34
- def rake?
35
- File.basename($0) == "rake"
31
+ config.before_eager_load do
32
+ ::Rails::Assets::Manifest.eager_load!
36
33
  end
37
34
  end
38
35
  end
@@ -4,9 +4,9 @@ module Rails
4
4
  module Assets
5
5
  module Manifest
6
6
  module VERSION
7
- MAJOR = 1
8
- MINOR = 0
9
- PATCH = 0
7
+ MAJOR = 2
8
+ MINOR = 1
9
+ PATCH = 1
10
10
  STAGE = nil
11
11
 
12
12
  STRING = [MAJOR, MINOR, PATCH, STAGE].reject(&:nil?).join('.')
data/renovate.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": ["config:base", "schedule:earlyMondays"]
3
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-assets-manifest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Graichen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-07 00:00:00.000000000 Z
11
+ date: 2021-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -60,10 +60,11 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - ".editorconfig"
63
+ - ".github/workflows/test.yml"
63
64
  - ".gitignore"
64
65
  - ".rspec"
65
66
  - ".rubocop.yml"
66
- - ".travis.yml"
67
+ - Appraisals
67
68
  - CHANGELOG.md
68
69
  - Gemfile
69
70
  - LICENSE
@@ -71,17 +72,17 @@ files:
71
72
  - Rakefile
72
73
  - bin/console
73
74
  - bin/setup
74
- - gemfiles/rails-4-2.gemfile
75
- - gemfiles/rails-5-0.gemfile
76
- - gemfiles/rails-5-1.gemfile
77
- - gemfiles/rails-5-2.gemfile
78
- - gemfiles/rails-master.gemfile
75
+ - gemfiles/rails_5.2.gemfile
76
+ - gemfiles/rails_6.0.gemfile
77
+ - gemfiles/rails_6.1.gemfile
78
+ - gemfiles/rails_master.gemfile
79
79
  - lib/rails/assets/manifest.rb
80
80
  - lib/rails/assets/manifest/helper.rb
81
81
  - lib/rails/assets/manifest/manifest.rb
82
82
  - lib/rails/assets/manifest/railtie.rb
83
83
  - lib/rails/assets/manifest/version.rb
84
84
  - rails-assets-manifest.gemspec
85
+ - renovate.json
85
86
  homepage: https://github.com/jgraichen/rails-assets-manifest
86
87
  licenses: []
87
88
  metadata:
@@ -103,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
104
  - !ruby/object:Gem::Version
104
105
  version: '0'
105
106
  requirements: []
106
- rubygems_version: 3.0.3
107
+ rubygems_version: 3.2.15
107
108
  signing_key:
108
109
  specification_version: 4
109
110
  summary: Load all rails assets from an external manifest.
data/.travis.yml DELETED
@@ -1,37 +0,0 @@
1
- dist: xenial
2
- language: ruby
3
- cache: bundler
4
-
5
- rvm:
6
- - 2.6.3
7
- - 2.5.5
8
-
9
- gemfile:
10
- - gemfiles/rails-5-2.gemfile
11
- - gemfiles/rails-master.gemfile
12
-
13
- before_install:
14
- - gem update --system
15
- - gem install bundler
16
-
17
- script:
18
- - bundle exec rspec spec
19
-
20
- jobs:
21
- allow_failures:
22
- - gemfile: gemfiles/rails-master.gemfile
23
-
24
- include:
25
- - stage: Release
26
- rvm: 2.6.3
27
- env: []
28
- script: skip
29
- install: skip
30
- deploy:
31
- provider: rubygems
32
- api_key:
33
- secure: m5gUzb8J40lo4EJ2xE8XwoeHq4S3ZEDE+AyikDHzGKc5NEQQcCRoc469UlDO7fYfBHGKLh2eEe6+e/T+dyRE/C0qE/tfd6pVWf8xdyzt9+rB0zM3k7pR2Aud2hZ8NFF4bAQ28OvQ2y9pWWLVS9Bn/C0Xou951yZM+vufPVZpX7+08Aw+ZdPQrmg+v9SxsvWElm/is0CMjsHxpEy1vpyyBlF/DhNpHgd+69nupyTuZP8bg3lirZexek0xNaccNpflmrUeRwE7yofVGMfrRhvm5kOniYI+sQl/Zwru9+hK2WaSzfX/ou4ENihiLDGo5gdWeYcyLbS61yQARsRn21cN6SA0iYVuVnAruHC3uoxRh7ty1H8s3aUJnPTnnBj5cnfP9pqOyZI8zFi54CujkEFbRVLlWfGjKtCScgFBwkpXS5aB6CBplulMrX3kz/jYXFgodXLsV10WD725WGJ2Jkb52PoT5i2GyA/Ao746s7+wPIEV/l8NAurcroSHOzr9PcAUG/CwdzgidSnLfwl+qplMCGaUHtdHkPaRHqJL9j4BmcqoGVMaU0a4mAXsrlJG/drT2PMMrREKChtnQPtWg3L9HHDHBIKuXZCIQ7G9n2Dz7lpWnyKZKjJTcFyZWbbnKHLXlE1KDBUiG9qqrYbpky+IEPUt4jZ1W8hx4tKGjNlNwjU=
34
- gem: rails-assets-manifest
35
- on:
36
- tags: true
37
- repo: jgraichen/rails-assets-manifest
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Load root Gemfile
6
- eval_gemfile '../Gemfile'
7
-
8
- gem 'activesupport', '~> 4.2.0'
9
- gem 'railties', '~> 4.2.0'
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Load root Gemfile
6
- eval_gemfile '../Gemfile'
7
-
8
- gem 'activesupport', '~> 5.0.0'
9
- gem 'railties', '~> 5.0.0'
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Load root Gemfile
6
- eval_gemfile '../Gemfile'
7
-
8
- gem 'activesupport', '~> 5.1.0'
9
- gem 'railties', '~> 5.1.0'
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Load root Gemfile
6
- eval_gemfile '../Gemfile'
7
-
8
- gem 'activesupport', '~> 5.2.0'
9
- gem 'railties', '~> 5.2.0'
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Load root Gemfile
6
- eval_gemfile '../Gemfile'
7
-
8
- gem 'activesupport', git: 'https://github.com/rails/rails'
9
- gem 'railties', git: 'https://github.com/rails/rails'