Skip to content

Commit 25f1d48

Browse files
committed
Implement ShopifyRubyDefinitions
1 parent 18910a1 commit 25f1d48

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1686
-0
lines changed

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require:
66
- rubocop-sorbet
77

88
AllCops:
9+
NewCops: enable
910
SuggestExtensions: false
1011
TargetRubyVersion: 2.6
1112

lib/shopify_ruby_definitions.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# typed: strong
22
# frozen_string_literal: true
33

4+
require "sorbet-runtime"
5+
6+
require_relative "shopify_ruby_definitions/ruby_build"
7+
require_relative "shopify_ruby_definitions/ruby_versions"
48
require_relative "shopify_ruby_definitions/version"
59

610
module ShopifyRubyDefinitions
11+
extend RubyVersions
712
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# typed: strong
2+
# frozen_string_literal: true
3+
4+
module ShopifyRubyDefinitions
5+
module RubyBuild
6+
extend T::Sig
7+
8+
RUBY_BUILD_DIRECTORY = T.let(File.expand_path("../../../vendor/ruby-build", __FILE__), String)
9+
end
10+
end
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# typed: strong
2+
# frozen_string_literal: true
3+
4+
module ShopifyRubyDefinitions
5+
module RubyVersions
6+
extend T::Sig
7+
8+
VERSIONS_DIRECTORY = T.let(File.join(RubyBuild::RUBY_BUILD_DIRECTORY, "share/ruby-build"), String)
9+
ALL_VERSIONS = T.let(Dir["#{VERSIONS_DIRECTORY}/*"].map { |f| File.basename(f) }, T::Array[String])
10+
11+
sig { returns(T::Hash[String, String]) }
12+
def version_overrides
13+
{
14+
"head" => ruby_head_version,
15+
"ruby-head" => ruby_head_version,
16+
"3.0.0" => "3.0.0-pshopify9",
17+
"3.0.1" => "3.0.1-pshopify2",
18+
"3.0.2" => "3.0.2-pshopify3",
19+
"3.1.0" => "3.1.0-pshopify1",
20+
"3.1.1" => "3.1.1-pshopify2",
21+
"3.1.2" => "3.1.2-pshopify2",
22+
"3.1.3" => "3.1.3-pshopify1",
23+
"3.1.4" => "3.1.4-pshopify1",
24+
"3.2.0" => "3.2.0-pshopify2",
25+
"3.2.1" => "3.2.1-pshopify5",
26+
"3.2.2" => "3.2.2-pshopify3",
27+
}.freeze
28+
end
29+
30+
sig { params(version: String).returns(String) }
31+
def resolve_version(version)
32+
if version.match?(/\A\d+\.\d+\z/)
33+
pattern = /\A#{Regexp.escape(version)}\.(\d+)\z/
34+
versions = ALL_VERSIONS.grep(pattern)
35+
unless versions.empty?
36+
version = T.must(versions.max_by { |v| T.must(v.match(pattern))[1].to_i })
37+
end
38+
end
39+
version_overrides.fetch(version, version)
40+
end
41+
42+
private
43+
44+
sig { returns(String) }
45+
def ruby_head_version
46+
T.must(ALL_VERSIONS.grep(/\A[\d\.]+-dev\z/).max)
47+
end
48+
end
49+
end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# typed: true
2+
# frozen_string_literal: true
3+
4+
require "test_helper"
5+
6+
module ShopifyRubyDefinitions
7+
class TestRubyVersions < Minitest::Test
8+
def test_ALL_VERSIONS
9+
assert_operator(RubyVersions::ALL_VERSIONS.length, :>, 0)
10+
11+
valid_pattern = Regexp.union(
12+
/\A(?:yjit\-)?\d+\.\d+\.\d+(?:\-[\w\-]+)?\z/, # MRI
13+
/\Atruffleruby\-(dev|[\d\.]+(?:-preview\d+)?)\z/, # TruffleRuby
14+
)
15+
16+
RubyVersions::ALL_VERSIONS.each do |v|
17+
assert_match(valid_pattern, v)
18+
end
19+
end
20+
21+
def test_version_overrides
22+
assert_match(/\A3.2.2-pshopify\d\z/, ShopifyRubyDefinitions.version_overrides["3.2.2"])
23+
end
24+
25+
def test_resolve_version
26+
assert_equal("2.6.10", ShopifyRubyDefinitions.resolve_version("2.6"))
27+
assert_equal("3.3.0-dev", ShopifyRubyDefinitions.resolve_version("ruby-head"))
28+
end
29+
end
30+
end

vendor/ruby-build/LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2012-2013 Sam Stephenson
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the "Software"), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7+
of the Software, and to permit persons to whom the Software is furnished to do
8+
so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

0 commit comments

Comments
 (0)