Script 'mail_helper' called by obssrc
Hello community,
here is the log from the commit of package rubygem-propshaft for
openSUSE:Factory checked in at 2026-07-15 16:33:58
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/rubygem-propshaft (Old)
and /work/SRC/openSUSE:Factory/.rubygem-propshaft.new.1991 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-propshaft"
Wed Jul 15 16:33:58 2026 rev:2 rq:1365328 version:1.3.2
Changes:
--------
--- /work/SRC/openSUSE:Factory/rubygem-propshaft/rubygem-propshaft.changes
2024-12-11 21:10:23.880147204 +0100
+++
/work/SRC/openSUSE:Factory/.rubygem-propshaft.new.1991/rubygem-propshaft.changes
2026-07-15 16:50:53.741413305 +0200
@@ -1,0 +2,6 @@
+Mon Jul 13 10:40:34 UTC 2026 - Aleksei Burlakov <[email protected]>
+
+- New upstream release version 1.3.2:
+ * Add charset=utf-8 to Content-Type for CSS and HTML assets by @flavorjones
in #264
+
+-------------------------------------------------------------------
Old:
----
propshaft-1.1.0.gem
New:
----
propshaft-1.3.2.gem
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ rubygem-propshaft.spec ++++++
--- /var/tmp/diff_new_pack.TlnF5J/_old 2026-07-15 16:50:56.301500290 +0200
+++ /var/tmp/diff_new_pack.TlnF5J/_new 2026-07-15 16:50:56.301500290 +0200
@@ -1,7 +1,7 @@
#
# spec file for package rubygem-propshaft
#
-# Copyright (c) 2024 SUSE LLC
+# Copyright (c) 2026 SUSE LLC and contributors
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -24,13 +24,13 @@
#
Name: rubygem-propshaft
-Version: 1.1.0
+Version: 1.3.2
Release: 0
%define mod_name propshaft
%define mod_full_name %{mod_name}-%{version}
-BuildRequires: ruby-macros >= 5
BuildRequires: %{ruby >= 2.7.0}
BuildRequires: %{rubygem gem2rpm}
+BuildRequires: ruby-macros >= 5
URL: https://github.com/rails/propshaft
Source: https://rubygems.org/gems/%{mod_full_name}.gem
Source1: gem2rpm.yml
++++++ propshaft-1.1.0.gem -> propshaft-1.3.2.gem ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/README.md new/README.md
--- old/README.md 2024-09-30 23:22:18.000000000 +0200
+++ new/README.md 1980-01-02 01:00:00.000000000 +0100
@@ -16,7 +16,7 @@
## Usage
-Propshaft makes all the assets from all the paths it's been configured with
through `config.assets.paths` available for serving and will copy all of them
into `public/assets` when precompiling. This is unlike Sprockets, which did not
copy over assets that hadn't been explicitly included in one of the bundled
assets.
+Propshaft makes all the assets from all the paths it's been configured with
through `config.assets.paths` available for serving and will copy all of them
into `public/assets` when precompiling. This is unlike Sprockets, which did not
copy over assets that hadn't been explicitly included in one of the bundled
assets.
You can however exempt directories that have been added through the
`config.assets.excluded_paths`. This is useful if you're for example using
`app/assets/stylesheets` exclusively as a set of inputs to a compiler like Dart
Sass for Rails, and you don't want these input files to be part of the load
path. (Remember you need to add full paths, like
`Rails.root.join("app/assets/stylesheets")`).
@@ -50,9 +50,55 @@
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.
+## Subresource Integrity (SRI)
+
+Propshaft supports Subresource Integrity (SRI) to help protect against
malicious modifications of assets. SRI allows browsers to verify that resources
fetched from CDNs or other sources haven't been tampered with by checking
cryptographic hashes.
+
+### Enabling SRI
+
+To enable SRI support, configure the hash algorithm in your Rails application:
+
+```ruby
+config.assets.integrity_hash_algorithm = "sha384"
+```
+
+Valid hash algorithms include:
+- `"sha256"` - SHA-256 (most common)
+- `"sha384"` - SHA-384 (recommended for enhanced security)
+- `"sha512"` - SHA-512 (strongest)
+
+### Using SRI in your views
+
+Once configured, you can enable SRI by passing the `integrity: true` option to
asset helpers:
+
+```erb
+<%= stylesheet_link_tag "application", integrity: true %>
+<%= javascript_include_tag "application", integrity: true %>
+```
+
+This generates HTML with integrity hashes:
+
+```html
+<link rel="stylesheet" href="/assets/application-abc123.css"
+ integrity="sha384-xyz789...">
+<script src="/assets/application-def456.js"
+ integrity="sha384-uvw012..."></script>
+```
+
+**Important**: SRI only works in secure contexts (HTTPS) or during local
development. The integrity hashes are automatically omitted when serving over
HTTP in production for security reasons.
+
+### Bulk stylesheet inclusion with SRI
+
+Propshaft extends `stylesheet_link_tag` with special symbols for bulk
inclusion:
+
+```erb
+<%= stylesheet_link_tag :all, integrity: true %> <!-- All stylesheets -->
+<%= stylesheet_link_tag :app, integrity: true %> <!-- Only app/assets
stylesheets -->
+```
+
## Improving performance in development
-Before every request Propshaft checks if any asset was updated to decide if a
cache sweep is needed. This verification is done using the application's
configured file watcher which, by default, is
`ActiveSupport::FileUpdateChecker`.
+Before every request Propshaft checks if any asset was updated to decide if a
cache sweep is needed. This verification is done using the application's
configured file watcher which, by default, is
`ActiveSupport::FileUpdateChecker`.
If you have a lot of assets in your project, you can improve performance by
adding the `listen` gem to the development group in your Gemfile, and this line
to the `development.rb` environment file:
Binary files old/checksums.yaml.gz and new/checksums.yaml.gz differ
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/propshaft/assembly.rb
new/lib/propshaft/assembly.rb
--- old/lib/propshaft/assembly.rb 2024-09-30 23:22:18.000000000 +0200
+++ new/lib/propshaft/assembly.rb 1980-01-02 01:00:00.000000000 +0100
@@ -1,3 +1,4 @@
+require "propshaft/manifest"
require "propshaft/load_path"
require "propshaft/resolver/dynamic"
require "propshaft/resolver/static"
@@ -16,7 +17,13 @@
end
def load_path
- @load_path ||= Propshaft::LoadPath.new(config.paths, compilers: compilers,
version: config.version)
+ @load_path ||= Propshaft::LoadPath.new(
+ config.paths,
+ compilers: compilers,
+ version: config.version,
+ file_watcher: config.file_watcher,
+ integrity_hash_algorithm: config.integrity_hash_algorithm
+ )
end
def resolver
@@ -27,8 +34,11 @@
end
end
- def server
- Propshaft::Server.new(self)
+ def prefix
+ @prefix ||= begin
+ prefix = config.prefix || "/"
+ prefix.end_with?("/") ? prefix : "#{prefix}/"
+ end
end
def processor
@@ -47,7 +57,7 @@
def reveal(path_type = :logical_path)
path_type = path_type.presence_in(%i[ logical_path path ]) ||
raise(ArgumentError, "Unknown path_type: #{path_type}")
-
+
load_path.assets.collect do |asset|
asset.send(path_type)
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/propshaft/asset.rb new/lib/propshaft/asset.rb
--- old/lib/propshaft/asset.rb 2024-09-30 23:22:18.000000000 +0200
+++ new/lib/propshaft/asset.rb 1980-01-02 01:00:00.000000000 +0100
@@ -1,9 +1,12 @@
require "digest/sha1"
+require "digest/sha2"
require "action_dispatch/http/mime_type"
class Propshaft::Asset
attr_reader :path, :logical_path, :load_path
+ CONTENT_TYPES_WITH_UTF8_CHARSET = [ Mime::Type.lookup("text/html"),
Mime::Type.lookup("text/css") ]
+
class << self
def extract_path_and_digest(digested_path)
digest =
digested_path[/-([0-9a-zA-Z]{7,128})\.(?!digested)([^.]|.map)+\z/, 1]
@@ -17,12 +20,24 @@
@path, @logical_path, @load_path = path, Pathname.new(logical_path),
load_path
end
+ def compiled_content
+ @compiled_content ||= load_path.compilers.compile(self)
+ end
+
def content(encoding: "ASCII-8BIT")
- File.read(path, encoding: encoding)
+ File.read(path, encoding: encoding, mode: "rb")
end
def content_type
- Mime::Type.lookup_by_extension(logical_path.extname.from(1))
+ @content_type ||=
Mime::Type.lookup_by_extension(logical_path.extname.from(1))
+ end
+
+ def content_type_with_charset
+ if content_type.in? CONTENT_TYPES_WITH_UTF8_CHARSET
+ "#{content_type}; charset=utf-8"
+ else
+ content_type
+ end
end
def length
@@ -33,6 +48,24 @@
@digest ||=
Digest::SHA1.hexdigest("#{content_with_compile_references}#{load_path.version}").first(8)
end
+ def integrity(hash_algorithm:)
+ # Following the Subresource Integrity spec draft
+ # https://w3c.github.io/webappsec-subresource-integrity/
+ # allowing only sha256, sha384, and sha512
+ bitlen = case hash_algorithm
+ when "sha256"
+ 256
+ when "sha384"
+ 384
+ when "sha512"
+ 512
+ else
+ raise(StandardError.new("Subresource Integrity hash algorithm must be
one of SHA2 family (sha256, sha384, sha512)"))
+ end
+
+ [hash_algorithm,
Digest::SHA2.new(bitlen).base64digest(compiled_content)].join("-")
+ end
+
def digested_path
if already_digested?
logical_path
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/propshaft/compiler/css_asset_urls.rb
new/lib/propshaft/compiler/css_asset_urls.rb
--- old/lib/propshaft/compiler/css_asset_urls.rb 2024-09-30
23:22:18.000000000 +0200
+++ new/lib/propshaft/compiler/css_asset_urls.rb 1980-01-02
01:00:00.000000000 +0100
@@ -3,7 +3,7 @@
require "propshaft/compiler"
class Propshaft::Compiler::CssAssetUrls < Propshaft::Compiler
- ASSET_URL_PATTERN =
/url\(\s*["']?(?!(?:\#|%23|data|http|\/\/))([^"'\s?#)]+)([#?][^"')]+)?\s*["']?\)/
+ ASSET_URL_PATTERN =
/url\(\s*["']?(?!(?:\#|%23|data:|http:|https:|\/\/))([^"'\s?#)]+)([#?][^"')]+)?\s*["']?\)/
def compile(asset, input)
input.gsub(ASSET_URL_PATTERN) { asset_url
resolve_path(asset.logical_path.dirname, $1), asset.logical_path, $2, $1 }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/propshaft/helper.rb new/lib/propshaft/helper.rb
--- old/lib/propshaft/helper.rb 2024-09-30 23:22:18.000000000 +0200
+++ new/lib/propshaft/helper.rb 1980-01-02 01:00:00.000000000 +0100
@@ -1,20 +1,106 @@
module Propshaft
+ # Helper module that provides asset path resolution and integrity support
for Rails applications.
+ #
+ # This module extends Rails' built-in asset helpers with additional
functionality:
+ # - Subresource Integrity (SRI) support for enhanced security
+ # - Bulk stylesheet inclusion with :all and :app options
+ # - Asset path resolution with proper error handling
+ #
+ # == Subresource Integrity (SRI) Support
+ #
+ # SRI helps protect against malicious modifications of assets by ensuring
that
+ # resources fetched from CDNs or other sources haven't been tampered with.
+ #
+ # SRI is automatically enabled in secure contexts (HTTPS or local
development)
+ # when the 'integrity' option is set to true:
+ #
+ # <%= stylesheet_link_tag "application", integrity: true %>
+ # <%= javascript_include_tag "application", integrity: true %>
+ #
+ # This will generate integrity hashes and include them in the HTML:
+ #
+ # <link rel="stylesheet" href="/assets/application-abc123.css"
+ # integrity="sha256-xyz789...">
+ # <script src="/assets/application-def456.js"
+ # integrity="sha256-uvw012..."></script>
+ #
+ # == Bulk Stylesheet Inclusion
+ #
+ # The stylesheet_link_tag helper supports special symbols for bulk inclusion:
+ # - :all - includes all CSS files found in the load path
+ # - :app - includes only CSS files from app/assets/**/*.css
+ #
+ # <%= stylesheet_link_tag :all %> # All stylesheets
+ # <%= stylesheet_link_tag :app %> # Only app stylesheets
module Helper
+ # Computes the Subresource Integrity (SRI) hash for the given asset path.
+ #
+ # This method generates a cryptographic hash of the asset content that can
be used
+ # to verify the integrity of the resource when it's loaded by the browser.
+ #
+ # asset_integrity("application.css")
+ # # => "sha256-xyz789abcdef..."
+ def asset_integrity(path, options = {})
+ path = _path_with_extname(path, options)
+ Rails.application.assets.resolver.integrity(path)
+ end
+
+ # Resolves the full path for an asset, raising an error if not found.
def compute_asset_path(path, options = {})
Rails.application.assets.resolver.resolve(path) ||
raise(MissingAssetError.new(path))
end
- # Add an option to call `stylesheet_link_tag` with `:all` to include every
css file found on the load path
- # or `:app` to include css files found in
`Rails.root("app/assets/**/*.css")`, which will exclude lib/ and plugins.
- def stylesheet_link_tag(*sources, **options)
+ # Enhanced +stylesheet_link_tag+ with integrity support and bulk inclusion
options.
+ #
+ # In addition to the standard Rails functionality, this method supports:
+ # * Automatic SRI (Subresource Integrity) hash generation in secure
contexts
+ # * Add an option to call +stylesheet_link_tag+ with +:all+ to include
every css
+ # file found on the load path or +:app+ to include css files found in
+ # <tt>Rails.root("app/assets/**/*.css")</tt>, which will exclude lib/
and plugins.
+ #
+ # ==== Options
+ #
+ # * <tt>:integrity</tt> - Enable SRI hash generation
+ #
+ # ==== Examples
+ #
+ # stylesheet_link_tag "application", integrity: true
+ # # => <link rel="stylesheet" href="/assets/application-abc123.css"
+ # # integrity="sha256-xyz789...">
+ #
+ # stylesheet_link_tag :all # All stylesheets in load path
+ # stylesheet_link_tag :app # Only app/assets stylesheets
+ def stylesheet_link_tag(*sources)
+ options = sources.extract_options!
+
case sources.first
when :all
- super(*all_stylesheets_paths , **options)
+ sources = all_stylesheets_paths
when :app
- super(*app_stylesheets_paths , **options)
- else
- super
+ sources = app_stylesheets_paths
end
+
+ _build_asset_tags(sources, options, :stylesheet) { |source, opts|
super(source, opts) }
+ end
+
+ # Enhanced +javascript_include_tag+ with automatic SRI (Subresource
Integrity) support.
+ #
+ # This method extends Rails' built-in +javascript_include_tag+ to
automatically
+ # generate and include integrity hashes when running in secure contexts.
+ #
+ # ==== Options
+ #
+ # * <tt>:integrity</tt> - Enable SRI hash generation
+ #
+ # ==== Examples
+ #
+ # javascript_include_tag "application", integrity: true
+ # # => <script src="/assets/application-abc123.js"
+ # # integrity="sha256-xyz789..."></script>
+ def javascript_include_tag(*sources)
+ options = sources.extract_options!
+
+ _build_asset_tags(sources, options, :javascript) { |source, opts|
super(source, opts) }
end
# Returns a sorted and unique array of logical paths for all stylesheets
in the load path.
@@ -26,5 +112,50 @@
def app_stylesheets_paths
Rails.application.assets.load_path.asset_paths_by_glob("#{Rails.root.join("app/assets")}/**/*.css")
end
+
+ private
+ # Core method that builds asset tags with optional integrity support.
+ #
+ # This method handles the common logic for both +stylesheet_link_tag+ and
+ # +javascript_include_tag+, including SRI hash generation and HTML tag
creation.
+ def _build_asset_tags(sources, options, asset_type)
+ options = options.stringify_keys
+ integrity = _compute_integrity?(options)
+
+ sources.map { |source|
+ opts = integrity ? options.merge!('integrity' =>
asset_integrity(source, type: asset_type)) : options
+ yield(source, opts)
+ }.join("\n").html_safe
+ end
+
+ # Determines whether integrity hashes should be computed for assets.
+ #
+ # Integrity is only computed in secure contexts (HTTPS or local
development)
+ # and when explicitly requested via the +integrity+ option.
+ def _compute_integrity?(options)
+ if _secure_subresource_integrity_context?
+ case options['integrity']
+ when nil, false, true
+ options.delete('integrity') == true
+ end
+ else
+ options.delete 'integrity'
+ false
+ end
+ end
+
+ # Checks if the current context is secure enough for Subresource
Integrity.
+ #
+ # SRI is only beneficial in secure contexts. Returns true when:
+ # * The request is made over HTTPS (SSL), OR
+ # * The request is local (development environment)
+ def _secure_subresource_integrity_context?
+ respond_to?(:request) && self.request && (self.request.local? ||
self.request.ssl?)
+ end
+
+ # Ensures the asset path includes the appropriate file extension.
+ def _path_with_extname(path, options)
+ "#{path}#{compute_asset_extname(path, options)}"
+ end
end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/propshaft/load_path.rb
new/lib/propshaft/load_path.rb
--- old/lib/propshaft/load_path.rb 2024-09-30 23:22:18.000000000 +0200
+++ new/lib/propshaft/load_path.rb 1980-01-02 01:00:00.000000000 +0100
@@ -1,10 +1,22 @@
+require "propshaft/manifest"
require "propshaft/asset"
class Propshaft::LoadPath
- attr_reader :paths, :compilers, :version
+ class NullFileWatcher # :nodoc:
+ def initialize(paths, files_to_watch, &block)
+ @block = block
+ end
+
+ def execute_if_updated
+ @block.call
+ end
+ end
+
+ attr_reader :paths, :compilers, :version, :integrity_hash_algorithm
- def initialize(paths = [], compilers:, version: nil)
- @paths, @compilers, @version = dedup(paths), compilers, version
+ def initialize(paths = [], compilers:, version: nil, file_watcher: nil,
integrity_hash_algorithm: nil)
+ @paths, @compilers, @version, @integrity_hash_algorithm = dedup(paths),
compilers, version, integrity_hash_algorithm
+ @file_watcher = file_watcher || NullFileWatcher
end
def find(asset_name)
@@ -30,10 +42,8 @@
end
def manifest
- Hash.new.tap do |manifest|
- assets.each do |asset|
- manifest[asset.logical_path.to_s] = asset.digested_path.to_s
- end
+ Propshaft::Manifest.new(integrity_hash_algorithm:
integrity_hash_algorithm).tap do |manifest|
+ assets.each { |asset| manifest.push_asset(asset) }
end
end
@@ -46,7 +56,7 @@
files_to_watch = Array(paths).collect { |dir| [ dir.to_s, exts_to_watch
] }.to_h
mutex = Mutex.new
- Rails.application.config.file_watcher.new([], files_to_watch) do
+ @file_watcher.new([], files_to_watch) do
mutex.synchronize do
clear_cache
seed_cache
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/propshaft/manifest.rb
new/lib/propshaft/manifest.rb
--- old/lib/propshaft/manifest.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/lib/propshaft/manifest.rb 1980-01-02 01:00:00.000000000 +0100
@@ -0,0 +1,183 @@
+module Propshaft
+ # Manages the manifest file that maps logical asset paths to their digested
counterparts.
+ #
+ # The manifest is used to track assets that have been processed and
digested, storing
+ # their logical paths, digested paths, and optional integrity hashes.
+ class Manifest
+ # Represents a single entry in the asset manifest.
+ #
+ # Each entry contains information about an asset including its logical path
+ # (the original path), digested path (the path with content hash), and
+ # optional integrity hash for security verification.
+ class ManifestEntry
+ attr_reader :logical_path, :digested_path, :integrity
+
+ # Creates a new manifest entry.
+ #
+ # ==== Parameters
+ #
+ # * +logical_path+ - The logical path of the asset
+ # * +digested_path+ - The digested path of the asset
+ # * +integrity+ - The integrity hash of the asset (optional)
+ def initialize(logical_path:, digested_path:, integrity:) # :nodoc:
+ @logical_path = logical_path
+ @digested_path = digested_path
+ @integrity = integrity
+ end
+
+ # Converts the manifest entry to a hash representation.
+ #
+ # Returns a hash containing the +digested_path+ and +integrity+ keys.
+ def to_h
+ { digested_path: digested_path, integrity: integrity}
+ end
+ end
+
+ class << self
+ # Creates a new Manifest instance from a manifest file.
+ #
+ # Reads and parses a manifest file, supporting both the current format
+ # (with +digested_path+ and +integrity+ keys) and the legacy format
+ # (simple string values for backwards compatibility).
+ #
+ # ==== Parameters
+ #
+ # * +manifest_path+ - The path to the manifest file
+ #
+ # ==== Returns
+ #
+ # A new manifest instance populated with entries from the file.
+ def from_path(manifest_path)
+ manifest = Manifest.new
+
+ serialized_manifest = JSON.parse(manifest_path.read, symbolize_names:
false)
+
+ serialized_manifest.each_pair do |key, value|
+ # Compatibility mode to be able to
+ # read the old "simple manifest" format
+ digested_path, integrity = if value.is_a?(String)
+ [value, nil]
+ else
+ [value["digested_path"], value["integrity"]]
+ end
+
+ entry = ManifestEntry.new(
+ logical_path: key, digested_path: digested_path, integrity:
integrity
+ )
+
+ manifest.push(entry)
+ end
+
+ manifest
+ end
+ end
+
+ # Creates a new Manifest instance.
+ #
+ # ==== Parameters
+ #
+ # * +integrity_hash_algorithm+ - The algorithm to use for generating
+ # integrity hashes (e.g., 'sha256', 'sha384', 'sha512'). If +nil+,
integrity hashes
+ # will not be generated.
+ def initialize(integrity_hash_algorithm: nil)
+ @integrity_hash_algorithm = integrity_hash_algorithm
+ @entries = {}
+ end
+
+ # Adds an asset to the manifest.
+ #
+ # Creates a manifest entry from the given asset and adds it to the
manifest.
+ # The entry will include the asset's logical path, digested path, and
optionally
+ # an integrity hash if an integrity hash algorithm is configured.
+ #
+ # ==== Parameters
+ #
+ # * +asset+ - The asset to add to the manifest
+ #
+ # ==== Returns
+ #
+ # The manifest entry that was added.
+ def push_asset(asset)
+ entry = ManifestEntry.new(
+ logical_path: asset.logical_path.to_s,
+ digested_path: asset.digested_path.to_s,
+ integrity: integrity_hash_algorithm && asset.integrity(hash_algorithm:
integrity_hash_algorithm)
+ )
+
+ push(entry)
+ end
+
+ # Adds a manifest entry to the manifest.
+ #
+ # ==== Parameters
+ #
+ # * +entry+ - The manifest entry to add
+ #
+ # ==== Returns
+ #
+ # The entry that was added.
+ def push(entry)
+ @entries[entry.logical_path] = entry
+ end
+ alias_method :<<, :push
+
+ # Retrieves a manifest entry by its logical path.
+ #
+ # ==== Parameters
+ #
+ # * +logical_path+ - The logical path of the asset to retrieve
+ #
+ # ==== Returns
+ #
+ # The manifest entry, or +nil+ if not found.
+ def [](logical_path)
+ @entries[logical_path]
+ end
+
+ # Removes a manifest entry by its logical path.
+ #
+ # ==== Parameters
+ #
+ # * +logical_path+ - The logical path of the asset to remove
+ #
+ # ==== Returns
+ #
+ # The removed manifest entry, or +nil+ if not found.
+ def delete(logical_path)
+ @entries.delete(logical_path)
+ end
+
+ # Converts the manifest to JSON format.
+ #
+ # The JSON representation maps logical paths to hash representations of
+ # manifest entries, containing +digested_path+ and +integrity+ information.
+ #
+ # ==== Returns
+ #
+ # The JSON representation of the manifest.
+ def to_json
+ @entries.transform_values do |manifest_entry|
+ manifest_entry.to_h
+ end.to_json
+ end
+
+ # Transforms the values of all manifest entries using the given block.
+ #
+ # This method is useful for applying transformations to all manifest
entries
+ # while preserving the logical path keys.
+ #
+ # ==== Parameters
+ #
+ # * +block+ - A block that will receive each manifest entry
+ #
+ # ==== Returns
+ #
+ # A new hash with the same keys but transformed values.
+ def transform_values(&block)
+ @entries.transform_values(&block)
+ end
+
+ private
+ attr_reader :integrity_hash_algorithm
+ end
+end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/propshaft/processor.rb
new/lib/propshaft/processor.rb
--- old/lib/propshaft/processor.rb 2024-09-30 23:22:18.000000000 +0200
+++ new/lib/propshaft/processor.rb 1980-01-02 01:00:00.000000000 +0100
@@ -54,10 +54,10 @@
def compile_asset(asset)
File.open(output_path.join(asset.digested_path), "w+") do |file|
begin
- file.write compilers.compile(asset)
+ file.write asset.compiled_content
rescue Encoding::UndefinedConversionError
# FIXME: Not sure if there's a better way here?
- file.write compilers.compile(asset).force_encoding("UTF-8")
+ file.write asset.compiled_content.force_encoding("UTF-8")
end
end if compilers.compilable?(asset)
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/propshaft/railtie.rb new/lib/propshaft/railtie.rb
--- old/lib/propshaft/railtie.rb 2024-09-30 23:22:18.000000000 +0200
+++ new/lib/propshaft/railtie.rb 1980-01-02 01:00:00.000000000 +0100
@@ -35,19 +35,13 @@
# Prioritize assets from within the application over assets of the same
path from engines/gems.
config.assets.paths.sort_by!.with_index { |path, i|
[path.to_s.start_with?(Rails.root.to_s) ? 0 : 1, i] }
+ config.assets.file_watcher ||= app.config.file_watcher
+
config.assets.relative_url_root ||= app.config.relative_url_root
config.assets.output_path ||=
Pathname.new(File.join(app.config.paths["public"].first,
app.config.assets.prefix))
config.assets.manifest_path ||=
config.assets.output_path.join(".manifest.json")
- app.assets = Propshaft::Assembly.new(app.config.assets)
-
- if config.assets.server
- app.routes.prepend do
- mount app.assets.server, at: app.assets.config.prefix
- end
- end
-
ActiveSupport.on_load(:action_view) do
include Propshaft::Helper
end
@@ -69,6 +63,13 @@
end
end
+ initializer "propshaft.assets_middleware", group: :all do |app|
+ app.assets = Propshaft::Assembly.new(app.config.assets)
+ if config.assets.server
+ app.middleware.insert_before ::ActionDispatch::Executor,
Propshaft::Server, app.assets
+ end
+ end
+
rake_tasks do
load "propshaft/railties/assets.rake"
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/propshaft/resolver/dynamic.rb
new/lib/propshaft/resolver/dynamic.rb
--- old/lib/propshaft/resolver/dynamic.rb 2024-09-30 23:22:18.000000000
+0200
+++ new/lib/propshaft/resolver/dynamic.rb 1980-01-02 01:00:00.000000000
+0100
@@ -7,15 +7,28 @@
end
def resolve(logical_path)
- if asset = load_path.find(logical_path)
+ if asset = find_asset(logical_path)
File.join prefix, asset.digested_path
end
end
+ def integrity(logical_path)
+ hash_algorithm = load_path.integrity_hash_algorithm
+
+ if hash_algorithm && (asset = find_asset(logical_path))
+ asset.integrity(hash_algorithm: hash_algorithm)
+ end
+ end
+
def read(logical_path, options = {})
if asset = load_path.find(logical_path)
asset.content(**options)
end
end
+
+ private
+ def find_asset(logical_path)
+ load_path.find(logical_path)
+ end
end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/propshaft/resolver/static.rb
new/lib/propshaft/resolver/static.rb
--- old/lib/propshaft/resolver/static.rb 2024-09-30 23:22:18.000000000
+0200
+++ new/lib/propshaft/resolver/static.rb 1980-01-02 01:00:00.000000000
+0100
@@ -7,20 +7,32 @@
end
def resolve(logical_path)
- if asset_path = parsed_manifest[logical_path]
+ if asset_path = digested_path(logical_path)
File.join prefix, asset_path
end
end
+ def integrity(logical_path)
+ entry = manifest[logical_path]
+
+ entry&.integrity
+ end
+
def read(logical_path, encoding: "ASCII-8BIT")
- if asset_path = parsed_manifest[logical_path]
+ if asset_path = digested_path(logical_path)
File.read(manifest_path.dirname.join(asset_path), encoding: encoding)
end
end
private
- def parsed_manifest
- @parsed_manifest ||= JSON.parse(manifest_path.read, symbolize_names:
false)
+ def manifest
+ @manifest ||= Propshaft::Manifest.from_path(manifest_path)
+ end
+
+ def digested_path(logical_path)
+ entry = manifest[logical_path]
+
+ entry&.digested_path
end
end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/propshaft/server.rb new/lib/propshaft/server.rb
--- old/lib/propshaft/server.rb 2024-09-30 23:22:18.000000000 +0200
+++ new/lib/propshaft/server.rb 1980-01-02 01:00:00.000000000 +0100
@@ -2,29 +2,39 @@
require "rack/version"
class Propshaft::Server
- def initialize(assembly)
+ def initialize(app, assembly)
+ @app = app
@assembly = assembly
end
def call(env)
- path, digest = extract_path_and_digest(env)
+ execute_cache_sweeper_if_updated
- if (asset = @assembly.load_path.find(path)) && asset.fresh?(digest)
- compiled_content = @assembly.compilers.compile(asset)
+ path = env["PATH_INFO"]
+ method = env["REQUEST_METHOD"]
- [
- 200,
- {
- Rack::CONTENT_LENGTH => compiled_content.length.to_s,
- Rack::CONTENT_TYPE => asset.content_type.to_s,
- VARY => "Accept-Encoding",
- Rack::ETAG => asset.digest,
- Rack::CACHE_CONTROL => "public, max-age=31536000, immutable"
- },
- [ compiled_content ]
- ]
+ if (method == "GET" || method == "HEAD") &&
path.start_with?(@assembly.prefix)
+ path, digest = extract_path_and_digest(path)
+
+ if (asset = @assembly.load_path.find(path)) && asset.fresh?(digest)
+ compiled_content = asset.compiled_content
+
+ [
+ 200,
+ {
+ Rack::CONTENT_LENGTH => compiled_content.length.to_s,
+ Rack::CONTENT_TYPE => asset.content_type_with_charset.to_s,
+ VARY => "Accept-Encoding",
+ Rack::ETAG => "\"#{asset.digest}\"",
+ Rack::CACHE_CONTROL => "public, max-age=31536000, immutable"
+ },
+ method == "HEAD" ? [] : [ compiled_content ]
+ ]
+ else
+ [ 404, { Rack::CONTENT_TYPE => "text/plain", Rack::CONTENT_LENGTH =>
"9" }, [ "Not found" ] ]
+ end
else
- [ 404, { Rack::CONTENT_TYPE => "text/plain", Rack::CONTENT_LENGTH => "9"
}, [ "Not found" ] ]
+ @app.call(env)
end
end
@@ -33,10 +43,11 @@
end
private
- def extract_path_and_digest(env)
- full_path = Rack::Utils.unescape(env["PATH_INFO"].to_s.sub(/^\//, ""))
+ def extract_path_and_digest(path)
+ path = path.delete_prefix(@assembly.prefix)
+ path = Rack::Utils.unescape(path)
- Propshaft::Asset.extract_path_and_digest(full_path)
+ Propshaft::Asset.extract_path_and_digest(path)
end
if Gem::Version.new(Rack::RELEASE) < Gem::Version.new("3")
@@ -44,4 +55,10 @@
else
VARY = "vary"
end
+
+ def execute_cache_sweeper_if_updated
+ if @assembly.config.sweep_cache
+ @assembly.load_path.cache_sweeper.execute_if_updated
+ end
+ end
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/propshaft/version.rb new/lib/propshaft/version.rb
--- old/lib/propshaft/version.rb 2024-09-30 23:22:18.000000000 +0200
+++ new/lib/propshaft/version.rb 1980-01-02 01:00:00.000000000 +0100
@@ -1,3 +1,3 @@
module Propshaft
- VERSION = "1.1.0"
+ VERSION = "1.3.2"
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/propshaft.rb new/lib/propshaft.rb
--- old/lib/propshaft.rb 2024-09-30 23:22:18.000000000 +0200
+++ new/lib/propshaft.rb 1980-01-02 01:00:00.000000000 +0100
@@ -10,4 +10,4 @@
require "propshaft/assembly"
require "propshaft/errors"
require "propshaft/helper"
-require "propshaft/railtie"
+require "propshaft/railtie" if defined?(Rails::Railtie)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/metadata new/metadata
--- old/metadata 2024-09-30 23:22:18.000000000 +0200
+++ new/metadata 1980-01-02 01:00:00.000000000 +0100
@@ -1,14 +1,13 @@
--- !ruby/object:Gem::Specification
name: propshaft
version: !ruby/object:Gem::Version
- version: 1.1.0
+ version: 1.3.2
platform: ruby
authors:
- David Heinemeier Hansson
-autorequire:
bindir: bin
cert_chain: []
-date: 2024-09-30 00:00:00.000000000 Z
+date: 1980-01-02 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: actionpack
@@ -39,20 +38,6 @@
- !ruby/object:Gem::Version
version: 7.0.0
- !ruby/object:Gem::Dependency
- name: railties
- requirement: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: 7.0.0
- type: :runtime
- prerelease: false
- version_requirements: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- version: 7.0.0
-- !ruby/object:Gem::Dependency
name: rack
requirement: !ruby/object:Gem::Requirement
requirements:
@@ -66,7 +51,6 @@
- - ">="
- !ruby/object:Gem::Version
version: '0'
-description:
email: [email protected]
executables: []
extensions: []
@@ -86,6 +70,7 @@
- lib/propshaft/errors.rb
- lib/propshaft/helper.rb
- lib/propshaft/load_path.rb
+- lib/propshaft/manifest.rb
- lib/propshaft/output_path.rb
- lib/propshaft/processor.rb
- lib/propshaft/quiet_assets.rb
@@ -100,7 +85,6 @@
- MIT
metadata:
rubygems_mfa_required: 'true'
-post_install_message:
rdoc_options: []
require_paths:
- lib
@@ -115,8 +99,7 @@
- !ruby/object:Gem::Version
version: '0'
requirements: []
-rubygems_version: 3.5.16
-signing_key:
+rubygems_version: 4.0.3
specification_version: 4
summary: Deliver assets for Rails.
test_files: []