sass-embedded 0.7.28 → 0.9.0

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: 207fb46d3fc8d7e4fab04175f2703c72e02bfa95d36c540a59009d868ac23750
4
- data.tar.gz: b3da3862145c65095de4d7a6dabbce534a42d7fe45d038f6add1ffe3f2cee54a
3
+ metadata.gz: c5bcaee2299b4f0b9d4d1d23b25773fdad87d1a294a4a34eeec0028d1f89a25c
4
+ data.tar.gz: 75ce2615300b0d59e73f715ae43007baf09a9818ea56d80b8be4d54b1f561c69
5
5
  SHA512:
6
- metadata.gz: 1c85b0bbaae870e2869d494ac32fdf395cdb190cd5d19629d41bb0c2cc5186de40a4c3b4f6a66dc1fe4dcb5d1b13837f88e22b3c96836645d883d1e9db152f20
7
- data.tar.gz: c23a80f42bd9f7a02f6627d73bb5e7813b6489749f6e3cc09f8ebba6ea6f1e9c1f00fef44c504064a92e494e690fdcaacef4162903b915f2414a3fbb11237eee
6
+ metadata.gz: 93cf20b2df8d4c363797df90e459f52c6dedf5e540cb5b6eb1cd110dded76477adf82f6c0bc0652f1b5201f535265053f7838654952a4bcc7f338bcc69c9464a
7
+ data.tar.gz: c4190c8fc8e60a37fa834dfdac6fe1842e66d39ac8d0ad9bc1c15ea5c18c16766f19e194be746fc963a5604c740f438c6371aa59c10dd59d452a526fea6cbf0d
data/ext/sass/Makefile CHANGED
@@ -44,7 +44,7 @@ else
44
44
  unzip -od $@ $<
45
45
  endif
46
46
 
47
- embedded_sass.proto:
47
+ embedded_sass.proto: sass_embedded
48
48
  $(EXTCONF) --with-sass-embedded-protocol
49
49
 
50
50
  %_pb.rb: %.proto protoc
data/ext/sass/extconf.rb CHANGED
@@ -1,202 +1,224 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'mkmf'
4
+ require 'fileutils'
5
5
  require 'json'
6
+ require 'mkmf'
6
7
  require 'open-uri'
7
- require 'fileutils'
8
- require_relative './dependencies'
9
- require_relative '../../lib/sass/platform'
8
+ require_relative '../../lib/sass/embedded/compiler/path'
9
+ require_relative '../../lib/sass/embedded/compiler/requirements'
10
+ require_relative '../../lib/sass/embedded/platform'
10
11
 
11
12
  module Sass
12
- # The dependency downloader. This downloads all the dependencies during gem
13
- # installation. The companion Makefile then unpacks all downloaded
14
- # dependencies. By default it downloads the release of each dependency
15
- # from GitHub releases.
16
- #
17
- # It is possible to specify an alternative source or version of each
18
- # dependency. Local sources can be used for offline installation.
19
- #
20
- # @example
21
- # gem install sass-embedded -- \
22
- # --with-protoc=file:///path/to/protoc-*.zip \
23
- # --with-sass-embedded=file:///path/to/sass_embedded-*.(tar.gz|zip) \
24
- # --with-sass-embedded-protocol=file:///path/to/embedded_sass.proto
25
- # @example
26
- # bundle config build.sass-embedded \
27
- # --with-protoc=file:///path/to/protoc-*.zip \
28
- # --with-sass-embedded=file:///path/to/sass_embedded-*.(tar.gz|zip) \
29
- # --with-sass-embedded-protocol=file:///path/to/embedded_sass.proto
30
- class Extconf
31
- def initialize
32
- fetch_with_config('protoc', false) { default_protoc }
33
- fetch_with_config('sass-embedded', false) { default_sass_embedded }
34
- fetch_with_config('sass-embedded-protocol', false) { default_sass_embedded_protocol }
35
- end
13
+ class Embedded
14
+ # The dependency downloader. This downloads all the dependencies during gem
15
+ # installation. The companion Makefile then unpacks all downloaded
16
+ # dependencies. By default it downloads the release of each dependency
17
+ # from GitHub releases.
18
+ #
19
+ # It is possible to specify an alternative source or version of each
20
+ # dependency. Local sources can be used for offline installation.
21
+ #
22
+ # @example
23
+ # gem install sass-embedded -- \
24
+ # --with-protoc=file:///path/to/protoc-*.zip \
25
+ # --with-sass-embedded=file:///path/to/sass_embedded-*.(tar.gz|zip) \
26
+ # --with-sass-embedded-protocol=file:///path/to/embedded_sass.proto
27
+ # @example
28
+ # bundle config build.sass-embedded \
29
+ # --with-protoc=file:///path/to/protoc-*.zip \
30
+ # --with-sass-embedded=file:///path/to/sass_embedded-*.(tar.gz|zip) \
31
+ # --with-sass-embedded-protocol=file:///path/to/embedded_sass.proto
32
+ class Extconf
33
+ def initialize
34
+ fetch_with_config('protoc', false) { default_protoc }
35
+ fetch_with_config('sass-embedded', false) { default_sass_embedded }
36
+ fetch_with_config('sass-embedded-protocol', false) { default_sass_embedded_protocol }
37
+ end
36
38
 
37
- private
39
+ private
38
40
 
39
- def fetch_with_config(config, default)
40
- val = with_config(config, default)
41
- case val
42
- when true
43
- if block_given?
44
- fetch yield
41
+ def fetch_with_config(config, default)
42
+ val = with_config(config, default)
43
+ case val
44
+ when true
45
+ if block_given?
46
+ fetch yield
47
+ else
48
+ fetch default
49
+ end
50
+ when false
51
+ nil
45
52
  else
46
- fetch default
53
+ fetch val
47
54
  end
48
- when false
49
- nil
50
- else
51
- fetch val
52
55
  end
53
- end
54
56
 
55
- def fetch(uri_s)
56
- uri = URI.parse(uri_s)
57
- path = File.absolute_path(File.basename(uri.path), __dir__)
58
- if uri.is_a?(URI::File) || uri.instance_of?(URI::Generic)
59
- FileUtils.copy_file uri.path, path
60
- elsif uri.respond_to? :open
61
- puts "curl -fsSLo #{path} -- #{uri}"
62
- uri.open do |source|
63
- File.open(path, 'wb') do |destination|
64
- destination.write source.read
57
+ def fetch(uri_s)
58
+ uri = URI.parse(uri_s)
59
+ path = File.absolute_path(File.basename(uri.path), __dir__)
60
+ if uri.is_a?(URI::File) || uri.instance_of?(URI::Generic)
61
+ FileUtils.copy_file uri.path, path
62
+ elsif uri.respond_to? :open
63
+ puts "curl -fsSLo #{path} -- #{uri}"
64
+ uri.open do |source|
65
+ File.open(path, 'wb') do |destination|
66
+ destination.write source.read
67
+ end
65
68
  end
69
+ else
70
+ raise
66
71
  end
67
- else
72
+ rescue StandardError
73
+ warn "ERROR: Error fetching #{uri_s}:"
68
74
  raise
69
75
  end
70
- rescue StandardError
71
- warn "ERROR: Error fetching #{uri_s}:"
72
- raise
73
- end
74
76
 
75
- def resolve_tag_name(repo, *requirements, gh_release: true)
76
- requirements = Gem::Requirement.create(*requirements)
77
+ def resolve_tag_name(repo, *requirements, gh_release: true)
78
+ requirements = Gem::Requirement.create(*requirements)
79
+
80
+ satisfied = lambda { |version|
81
+ Gem::Version.correct?(version) && requirements.satisfied_by?(Gem::Version.new(version))
82
+ }
83
+
84
+ headers = {}
85
+ headers['Authorization'] = "token #{ENV['GITHUB_TOKEN']}" if ENV['GITHUB_TOKEN']
77
86
 
78
- if requirements == Gem::Requirement.default && gh_release
79
- URI.parse("https://github.com/#{repo}/releases/latest").open do |file|
80
- File.basename file.base_uri.to_s
81
- end
82
- else
83
87
  begin
84
- headers = {}
85
- headers['Authorization'] = "token #{ENV['GITHUB_TOKEN']}" if ENV['GITHUB_TOKEN']
86
88
  if gh_release
87
- URI.parse("https://api.github.com/repos/#{repo}/releases?per_page=100").open(headers) do |file|
89
+ releases_uri = "https://github.com/#{repo}/releases"
90
+ uri = "#{releases_uri}/latest"
91
+ tag_name = URI.parse(uri).open do |file|
92
+ return nil if file.base_uri == releases_uri
93
+
94
+ latest = File.basename file.base_uri.to_s
95
+ latest if satisfied.call latest
96
+ end
97
+
98
+ return tag_name unless tag_name.nil?
99
+
100
+ uri = "https://api.github.com/repos/#{repo}/releases?per_page=100"
101
+ tag_name = URI.parse(uri).open(headers) do |file|
88
102
  JSON.parse(file.read).map { |release| release['tag_name'] }
89
103
  end
104
+ .find(satisfied)&.peek
90
105
  else
91
- URI.parse("https://api.github.com/repos/#{repo}/tags?per_page=100").open(headers) do |file|
106
+ uri = "https://api.github.com/repos/#{repo}/tags?per_page=100"
107
+ tag_name = URI.parse(uri).open(headers) do |file|
92
108
  JSON.parse(file.read).map { |tag| tag['name'] }
93
109
  end
110
+ .find(satisfied)&.peek
94
111
  end
95
- rescue OpenURI::HTTPError
96
- requirements.requirements
97
- .map { |requirement| requirement.last.to_s.gsub('.pre.', '-') }
112
+
113
+ return tag_name unless tag_name.nil?
114
+ rescue OpenURI::HTTPError => e
115
+ warn "WARNING: Error fetching #{uri}: #{e}"
98
116
  end
99
- .find { |version| Gem::Version.correct?(version) && requirements.satisfied_by?(Gem::Version.new(version)) }
100
- &.to_s
117
+
118
+ requirements.requirements
119
+ .map { |requirement| requirement.last.to_s.gsub('.pre.', '-') }
120
+ .find(satisfied)&.peek
101
121
  end
102
- end
103
122
 
104
- def default_sass_embedded
105
- repo = 'sass/dart-sass-embedded'
106
-
107
- tag_name = resolve_tag_name(repo, Sass::Dependencies::REQUIREMENTS[repo])
108
-
109
- os = case Platform::OS
110
- when 'darwin'
111
- 'macos'
112
- when 'linux'
113
- 'linux'
114
- when 'windows'
115
- 'windows'
116
- else
117
- raise "Unsupported OS: #{Platform::OS}"
118
- end
119
-
120
- arch = case Platform::ARCH
121
- when 'x86_64'
122
- 'x64'
123
- when 'i386'
124
- 'ia32'
125
- when 'aarch64'
126
- raise "Unsupported Arch: #{Platform::ARCH}" unless Platform::OS == 'darwin'
127
-
128
- 'x64'
123
+ def default_sass_embedded
124
+ repo = 'sass/dart-sass-embedded'
125
+
126
+ tag_name = resolve_tag_name(repo, Compiler::REQUIREMENTS)
127
+
128
+ os = case Platform::OS
129
+ when 'darwin'
130
+ 'macos'
131
+ when 'linux'
132
+ 'linux'
133
+ when 'windows'
134
+ 'windows'
129
135
  else
130
- raise "Unsupported Arch: #{Platform::ARCH}"
136
+ raise "Unsupported OS: #{Platform::OS}"
131
137
  end
132
138
 
133
- ext = case os
134
- when 'windows'
135
- 'zip'
136
- else
137
- 'tar.gz'
138
- end
139
+ arch = case Platform::ARCH
140
+ when 'x86_64'
141
+ 'x64'
142
+ when 'i386'
143
+ 'ia32'
144
+ when 'aarch64'
145
+ raise "Unsupported Arch: #{Platform::ARCH}" unless Platform::OS == 'darwin'
139
146
 
140
- "https://github.com/#{repo}/releases/download/#{tag_name}/sass_embedded-#{tag_name}-#{os}-#{arch}.#{ext}"
141
- end
147
+ 'x64'
148
+ else
149
+ raise "Unsupported Arch: #{Platform::ARCH}"
150
+ end
142
151
 
143
- def default_protoc
144
- repo = 'protocolbuffers/protobuf'
152
+ ext = case os
153
+ when 'windows'
154
+ 'zip'
155
+ else
156
+ 'tar.gz'
157
+ end
158
+
159
+ "https://github.com/#{repo}/releases/download/#{tag_name}/sass_embedded-#{tag_name}-#{os}-#{arch}.#{ext}"
160
+ end
145
161
 
146
- spec = Gem::Dependency.new('google-protobuf', Sass::Dependencies::REQUIREMENTS[repo]).to_spec
162
+ def default_protoc
163
+ repo = 'protocolbuffers/protobuf'
147
164
 
148
- tag_name = "v#{spec.version}"
165
+ spec = Gem::Dependency.new('google-protobuf').to_spec
149
166
 
150
- os = case Platform::OS
151
- when 'darwin'
152
- 'osx'
153
- when 'linux'
154
- 'linux'
155
- when 'windows'
156
- 'win'
157
- else
158
- raise "Unsupported OS: #{Platform::OS}"
159
- end
167
+ tag_name = "v#{spec.version}"
160
168
 
161
- arch = case Platform::ARCH
162
- when 'aarch64'
163
- if Platform::OS == 'darwin'
169
+ os = case Platform::OS
170
+ when 'darwin'
171
+ 'osx'
172
+ when 'linux'
173
+ 'linux'
174
+ when 'windows'
175
+ 'win'
176
+ else
177
+ raise "Unsupported OS: #{Platform::OS}"
178
+ end
179
+
180
+ arch = case Platform::ARCH
181
+ when 'aarch64'
182
+ if Platform::OS == 'darwin'
183
+ 'x86_64'
184
+ else
185
+ 'aarch_64'
186
+ end
187
+ when 'sparcv9'
188
+ 's390'
189
+ when 'i386'
190
+ 'x86_32'
191
+ when 'x86_64'
164
192
  'x86_64'
193
+ when 'powerpc64'
194
+ 'ppcle_64'
165
195
  else
166
- 'aarch_64'
196
+ raise "Unsupported Arch: #{Platform::ARCH}"
167
197
  end
168
- when 'sparcv9'
169
- 's390'
170
- when 'i386'
171
- 'x86_32'
172
- when 'x86_64'
173
- 'x86_64'
174
- when 'powerpc64'
175
- 'ppcle_64'
176
- else
177
- raise "Unsupported Arch: #{Platform::ARCH}"
178
- end
179
198
 
180
- os_arch = case os
181
- when 'win'
182
- os + arch.split('_').last
183
- else
184
- "#{os}-#{arch}"
185
- end
199
+ os_arch = case os
200
+ when 'win'
201
+ os + arch.split('_').last
202
+ else
203
+ "#{os}-#{arch}"
204
+ end
186
205
 
187
- ext = 'zip'
206
+ ext = 'zip'
188
207
 
189
- "https://github.com/#{repo}/releases/download/#{tag_name}/protoc-#{tag_name[1..]}-#{os_arch}.#{ext}"
190
- end
208
+ "https://github.com/#{repo}/releases/download/#{tag_name}/protoc-#{tag_name[1..]}-#{os_arch}.#{ext}"
209
+ end
191
210
 
192
- def default_sass_embedded_protocol
193
- repo = 'sass/embedded-protocol'
211
+ def default_sass_embedded_protocol
212
+ repo = 'sass/embedded-protocol'
194
213
 
195
- tag_name = resolve_tag_name(repo, Sass::Dependencies::REQUIREMENTS[repo], gh_release: false)
214
+ tag_name = IO.popen([Compiler::PATH, '--version']) do |file|
215
+ JSON.parse(file.read)['protocolVersion']
216
+ end
196
217
 
197
- "https://raw.githubusercontent.com/#{repo}/#{tag_name}/embedded_sass.proto"
218
+ "https://raw.githubusercontent.com/#{repo}/#{tag_name}/embedded_sass.proto"
219
+ end
198
220
  end
199
221
  end
200
222
  end
201
223
 
202
- Sass::Extconf.new
224
+ Sass::Embedded::Extconf.new
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'compiler'
4
+
5
+ module Sass
6
+ class Embedded
7
+ # The {Channel} for {Compiler} calls. Each instance creates its own
8
+ # {Compiler}. A new {Compiler} is automatically created when the existing
9
+ # {Compiler} runs out of unique request id.
10
+ class Channel
11
+ def initialize
12
+ @mutex = Mutex.new
13
+ @compiler = Compiler.new
14
+ end
15
+
16
+ def close
17
+ @mutex.synchronize do
18
+ @compiler.close
19
+ end
20
+ end
21
+
22
+ def closed?
23
+ @mutex.synchronize do
24
+ @compiler.closed?
25
+ end
26
+ end
27
+
28
+ def subscribe(observer)
29
+ @mutex.synchronize do
30
+ begin
31
+ id = @compiler.add_observer(observer)
32
+ rescue IOError
33
+ @compiler = Compiler.new
34
+ id = @compiler.add_observer(observer)
35
+ end
36
+ Subscription.new @compiler, observer, id
37
+ end
38
+ end
39
+
40
+ # The {Subscription} between {Compiler} and {Observer}.
41
+ class Subscription
42
+ attr_reader :id
43
+
44
+ def initialize(compiler, observer, id)
45
+ @compiler = compiler
46
+ @observer = observer
47
+ @id = id
48
+ end
49
+
50
+ def unsubscribe
51
+ @compiler.delete_observer(@observer)
52
+ end
53
+
54
+ def send_message(*args)
55
+ @compiler.send_message(*args)
56
+ end
57
+ end
58
+
59
+ private_constant :Subscription
60
+ end
61
+ end
62
+ end