Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various compatibility fixes for the 3.x branch #804

Merged
merged 11 commits into from Mar 28, 2024
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,34 @@
name: CI
on: [push, pull_request]
jobs:
tests:
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
name: ${{ matrix.ruby }}
strategy:
matrix:
experimental: [false]
ruby:
- "2.5"
- "2.6"
- "2.7"
- "3.0"
- "3.1"
- "3.2"
- "3.3"
rubyopt: [""]
include:
- { ruby: "3.3", rubyopt: "--enable-frozen-string-literal --debug-frozen-string-literal", experimental: false }
- { ruby: head, experimental: true }

steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Run tests ${{ matrix.rubyopt }}
timeout-minutes: 10
run: bundle exec rake RUBYOPT="${{ matrix.rubyopt }}"
20 changes: 20 additions & 0 deletions .github/workflows/isolated.yml
@@ -0,0 +1,20 @@
name: CI isolated tests
on: [push, pull_request]
jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: [2.7]

steps:
- uses: actions/checkout@v3

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Run tests
run: bundle exec rake test_isolated
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion lib/sprockets.rb
Expand Up @@ -105,7 +105,7 @@ module Sprockets
register_bundle_processor 'application/javascript', Bundle
register_bundle_processor 'text/css', Bundle

register_bundle_metadata_reducer '*/*', :data, proc { "" }, :concat
register_bundle_metadata_reducer '*/*', :data, proc { "" }, :+
register_bundle_metadata_reducer 'application/javascript', :data, proc { "" }, Utils.method(:concat_javascript_sources)
register_bundle_metadata_reducer '*/*', :links, :+

Expand Down
2 changes: 2 additions & 0 deletions lib/sprockets/directive_processor.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: false

require 'set'
require 'shellwords'

Expand Down
4 changes: 2 additions & 2 deletions lib/sprockets/server.rb
Expand Up @@ -251,11 +251,11 @@ def cache_headers(env, etag)
# If the request url contains a fingerprint, set a long
# expires on the response
if path_fingerprint(env["PATH_INFO"])
headers["Cache-Control"] << ", max-age=31536000"
headers["Cache-Control"] += ", max-age=31536000"

# Otherwise set `must-revalidate` since the asset could be modified.
else
headers["Cache-Control"] << ", must-revalidate"
headers["Cache-Control"] += ", must-revalidate"
headers["Vary"] = "Accept-Encoding"
end

Expand Down
3 changes: 3 additions & 0 deletions lib/sprockets/uri_utils.rb
Expand Up @@ -50,6 +50,9 @@ def split_file_uri(uri)
# Hack for parsing Windows "file:///C:/Users/IEUser" paths
path.gsub!(/^\/([a-zA-Z]:)/, '\1'.freeze)

host = nil if host && host.empty?
query = nil if query && query.empty?

[scheme, host, path, query]
end

Expand Down
1 change: 1 addition & 0 deletions lib/sprockets/utils.rb
Expand Up @@ -102,6 +102,7 @@ def string_end_with_semicolon?(str)
#
# Returns buf String.
def concat_javascript_sources(buf, source)
buf = +buf
if source.bytesize > 0
buf << source

Expand Down
3 changes: 2 additions & 1 deletion sprockets.gemspec
Expand Up @@ -11,6 +11,7 @@ Gem::Specification.new do |s|
s.files = Dir["README.md", "CHANGELOG.md", "LICENSE", "lib/**/*.rb"]
s.executables = ["sprockets"]

s.add_dependency "base64"
s.add_dependency "rack", "> 1", "< 3"
s.add_dependency "concurrent-ruby", "~> 1.0"

Expand All @@ -23,7 +24,7 @@ Gem::Specification.new do |s|
s.add_development_dependency "minitest", "~> 5.0"
s.add_development_dependency "nokogiri", "~> 1.3"
s.add_development_dependency "rack-test", "~> 0.6"
s.add_development_dependency "rake", "~> 10.0"
s.add_development_dependency "rake"
s.add_development_dependency "sass", "~> 3.1"
s.add_development_dependency "uglifier", "~> 2.3"
s.add_development_dependency "yui-compressor", "~> 0.12"
Expand Down
2 changes: 1 addition & 1 deletion test/sprockets_test.rb
Expand Up @@ -125,7 +125,7 @@ def silence_warnings
Sprockets.register_transformer 'text/css', 'application/css-sourcemap+json', SourceMapTransformer


class Sprockets::TestCase < MiniTest::Test
class Sprockets::TestCase < Minitest::Test
FIXTURE_ROOT = File.expand_path(File.join(File.dirname(__FILE__), "fixtures"))

def self.test(name, &block)
Expand Down
16 changes: 9 additions & 7 deletions test/test_asset.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: false

require "sprockets_test"

module AssetTests
Expand Down Expand Up @@ -117,7 +119,7 @@ def self.test(name, &block)

sandbox filename do
write(filename, "a;")
asset = asset('test.js')
assert asset('test.js')

File.unlink(filename)

Expand All @@ -132,7 +134,7 @@ def self.test(name, &block)
sandbox main, dep do
write(main, "//= depend_on test-dep\n")
write(dep, "a;")
asset = asset('test-main.js')
assert asset('test-main.js')

File.unlink(dep)

Expand Down Expand Up @@ -215,7 +217,7 @@ def setup
end

test "charset is nil" do
assert_equal nil, @asset.charset
assert_nil @asset.charset
end

test "length" do
Expand Down Expand Up @@ -1312,7 +1314,7 @@ def setup
end

test "content type" do
assert_equal nil, content_type("empty")
assert_nil content_type("empty")

assert_equal "application/javascript", content_type("application.js")
assert_equal "text/css", content_type("application.css")
Expand All @@ -1324,7 +1326,7 @@ def setup

assert_equal "text/css", content_type("store.css.erb")
assert_equal "text/plain", content_type("files.erb")
assert_equal nil, content_type("store.foo")
assert_nil content_type("store.foo")

assert_equal "application/javascript", content_type("application.coffee")
assert_equal "text/css", content_type("application.scss")
Expand All @@ -1347,7 +1349,7 @@ def setup
assert_equal "application/javascript", content_type("jquery.ext/form.js")
assert_equal "application/javascript", content_type("jquery-coffee.min.coffee")
assert_equal "application/javascript", content_type("jquery-custom.min.js.erb")
assert_equal nil, content_type("jquery.js.min")
assert_nil content_type("jquery.js.min")

assert_equal "application/javascript", content_type("all.coffee/plain.js")
assert_equal "application/javascript", content_type("all.coffee/hot.coffee")
Expand All @@ -1357,7 +1359,7 @@ def setup
assert_equal "application/javascript", content_type("bar-ng.ngt.haml")
assert_equal "application/javascript", content_type("baz-ng.js.ngt")

assert_equal nil, content_type("sprite.css.embed")
assert_nil content_type("sprite.css.embed")

assert_equal "application/javascript", content_type("traceur.es6")
assert_equal "application/javascript", content_type("traceur.js.es6")
Expand Down
12 changes: 6 additions & 6 deletions test/test_cache_store.rb
Expand Up @@ -62,7 +62,7 @@ def test_delete
@store.set("foo", "bar")
assert_equal "bar", @store.get("foo")
@store.set("foo", nil)
assert_equal nil, @store.get("foo")
assert_nil @store.get("foo")
end

def test_fetch
Expand All @@ -71,7 +71,7 @@ def test_fetch
end
end

class TestNullStore < MiniTest::Test
class TestNullStore < Minitest::Test
def setup
@_store = Sprockets::Cache::NullStore.new
@store = Sprockets::Cache.new(Sprockets::Cache::NullStore.new)
Expand All @@ -85,7 +85,7 @@ def test_inspect
include CacheStoreNullTests
end

class TestMemoryStore < MiniTest::Test
class TestMemoryStore < Minitest::Test
def setup
@_store = Sprockets::Cache::MemoryStore.new
@store = Sprockets::Cache.new(@_store)
Expand Down Expand Up @@ -118,7 +118,7 @@ def test_set_with_lru
end
end

class TestZeroMemoryStore < MiniTest::Test
class TestZeroMemoryStore < Minitest::Test
def setup
@_store = Sprockets::Cache::MemoryStore.new(0)
@store = Sprockets::Cache.new(@_store)
Expand All @@ -131,7 +131,7 @@ def test_inspect
include CacheStoreNullTests
end

class TestFileStore < MiniTest::Test
class TestFileStore < Minitest::Test
def setup
@root = Dir::mktmpdir "sprockets-file-store"
@_store = Sprockets::Cache::FileStore.new(@root)
Expand Down Expand Up @@ -159,7 +159,7 @@ def test_corrupted_read
include CacheStoreTests
end

class TestZeroFileStore < MiniTest::Test
class TestZeroFileStore < Minitest::Test
def setup
@tmpdir = Dir::mktmpdir "sprockets-file-store-zero"
@_store = Sprockets::Cache::FileStore.new(@tmpdir, 0)
Expand Down
2 changes: 1 addition & 1 deletion test/test_closure_compressor.rb
Expand Up @@ -2,7 +2,7 @@
require 'sprockets/cache'
require 'sprockets/closure_compressor'

class TestClosureCompressor < MiniTest::Test
class TestClosureCompressor < Minitest::Test
def test_compress_javascript
input = {
:data => "function foo() {\n return true;\n}",
Expand Down
2 changes: 1 addition & 1 deletion test/test_coffee_script_processor.rb
Expand Up @@ -2,7 +2,7 @@
require 'sprockets/cache'
require 'sprockets/coffee_script_processor'

class TestCoffeeScriptProcessor < MiniTest::Test
class TestCoffeeScriptProcessor < Minitest::Test
def test_compile_coffee_script_template_to_js
input = {
content_type: 'application/javascript',
Expand Down
4 changes: 2 additions & 2 deletions test/test_digest_utils.rb
@@ -1,7 +1,7 @@
require 'minitest/autorun'
require 'sprockets/digest_utils'

class TestDigestUtils < MiniTest::Test
class TestDigestUtils < Minitest::Test
include Sprockets::DigestUtils

def test_detect_digest_class
Expand Down Expand Up @@ -35,7 +35,7 @@ def test_digest
assert_equal "62427aa539a0b78e90fd710dc0e15f2960771ba44214b5d41d4a93a8b2940a38", hexdigest({"foo" => "baz"})
assert_equal "b6054efd9929004bdd0a1c09eb2d12961325396da749143def3e9a4050aa703e", hexdigest([[:foo, 1]])
assert_equal "79a19ffe41ecebd5dc35e95363e0b4aa79b139a22bc650384df57eb09842f099", hexdigest([{:foo => 1}])
assert_equal "94ee40cca7c2c6d2a134033d2f5a31c488cad5d3dcc61a3dbb5e2a858635874b", hexdigest("foo".force_encoding('UTF-8').encoding)
assert_equal "94ee40cca7c2c6d2a134033d2f5a31c488cad5d3dcc61a3dbb5e2a858635874b", hexdigest(Encoding::UTF_8)

assert_raises(TypeError) do
digest(Object.new)
Expand Down
2 changes: 1 addition & 1 deletion test/test_eco_processor.rb
Expand Up @@ -2,7 +2,7 @@
require 'sprockets/cache'
require 'sprockets/eco_processor'

class TestEcoProcessor < MiniTest::Test
class TestEcoProcessor < Minitest::Test
def test_compile_eco_template_to_js
input = {
content_type: 'application/javascript',
Expand Down
2 changes: 1 addition & 1 deletion test/test_ejs_processor.rb
Expand Up @@ -2,7 +2,7 @@
require 'sprockets/cache'
require 'sprockets/ejs_processor'

class TestEjsProcessor < MiniTest::Test
class TestEjsProcessor < Minitest::Test
def test_compile_ejs_template_to_js
input = {
content_type: 'application/javascript',
Expand Down
1 change: 1 addition & 0 deletions test/test_encoding.rb
@@ -1,4 +1,5 @@
# encoding: utf-8
# frozen_string_literal: false
require "sprockets_test"

class AssetEncodingTest < Sprockets::TestCase
Expand Down
2 changes: 1 addition & 1 deletion test/test_encoding_utils.rb
Expand Up @@ -2,7 +2,7 @@
require 'minitest/autorun'
require 'sprockets/encoding_utils'

class TestDigestUtils < MiniTest::Test
class TestDigestUtils < Minitest::Test
include Sprockets::EncodingUtils

def test_deflate
Expand Down
2 changes: 1 addition & 1 deletion test/test_environment.rb
Expand Up @@ -361,7 +361,7 @@ def self.test(name, &block)
end

test "missing asset returns nil" do
assert_equal nil, @env["missing.js"]
assert_nil @env["missing.js"]
end

test "missing asset path returns nil" do
Expand Down
2 changes: 1 addition & 1 deletion test/test_erb_processor.rb
Expand Up @@ -3,7 +3,7 @@
require 'sprockets/cache'
require 'sprockets/erb_processor'

class TestERBProcessor < MiniTest::Test
class TestERBProcessor < Minitest::Test

def uri_path(path)
path = '/' + path if path[1] == ':' # Windows path / drive letter
Expand Down
2 changes: 1 addition & 1 deletion test/test_http_utils.rb
@@ -1,7 +1,7 @@
require 'minitest/autorun'
require 'sprockets/http_utils'

class TestHTTPUtils < MiniTest::Test
class TestHTTPUtils < Minitest::Test
include Sprockets::HTTPUtils

def test_match_mime_type
Expand Down
2 changes: 1 addition & 1 deletion test/test_jst_processor.rb
Expand Up @@ -2,7 +2,7 @@
require 'sprockets/cache'
require 'sprockets/jst_processor'

class TestJstProcessor < MiniTest::Test
class TestJstProcessor < Minitest::Test
def test_export_js_template_in_JST
input = {
name: 'users/show',
Expand Down