sass-embedded 0.8.1 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36aa31c9cb340c6a95c73c93ea480ab565a9f8f009094ec0f7f7a2239e647f2b
4
- data.tar.gz: 71f325cdb5e5db87b97a931b92749c6e0ebbc91b376945fc5aa7b2fb5590928a
3
+ metadata.gz: 4bb434b577a1d5faadc9e9d9edb6c8ecaa2ded93cb620cd36b219c5b4792236b
4
+ data.tar.gz: 48b8a5013737d1d4a3fd68155f919538acb3d0d7522d85172ca2476b0dfbfc2e
5
5
  SHA512:
6
- metadata.gz: 7f136169a9f697db2cc04c466e2268230d090db81a01e54da74880a5dde4bba1acdafe425cf8b7f35f4030a2ec4d52b56e20dbba82911be974f9c000138f1e67
7
- data.tar.gz: 79507aae38d81b506a0d38ddc312bd12533bbe1d6647e0634a3755ff154c4a0a7be917d9cfbe8f7604ce2196fda9a7eb45f0f77a89c0b23513aec5b43f88abb2
6
+ metadata.gz: 0baea25cfe10f0af7dd6c86415bd7a9c9332e32c238fd68877214cb14432d7868645d35315f28b410168380b8c3f7f35a05a747fb258c0ca781d34d28c3fa9b6
7
+ data.tar.gz: 5eb83255303cd791c51cf86ba1aa49e54d739ee19d045978f5dfd2c46f69d76c27c22f664d845784f226b1ec3a086bc8dc86a7a7c22a091af85df39f50f56147
data/ext/sass/extconf.rb CHANGED
@@ -1,221 +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 '../../lib/sass/platform'
9
- require_relative '../../lib/sass/compiler'
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)
77
79
 
78
- satisfied = lambda { |version|
79
- Gem::Version.correct?(version) && requirements.satisfied_by?(Gem::Version.new(version))
80
- }
80
+ satisfied = lambda { |version|
81
+ Gem::Version.correct?(version) && requirements.satisfied_by?(Gem::Version.new(version))
82
+ }
81
83
 
82
- headers = {}
83
- headers['Authorization'] = "token #{ENV['GITHUB_TOKEN']}" if ENV['GITHUB_TOKEN']
84
+ headers = {}
85
+ headers['Authorization'] = "token #{ENV['GITHUB_TOKEN']}" if ENV['GITHUB_TOKEN']
84
86
 
85
- begin
86
- if gh_release
87
- releases_uri = "https://github.com/#{repo}/releases"
88
- uri = "#{releases_uri}/latest"
89
- tag_name = URI.parse(uri).open do |file|
90
- return nil if file.base_uri == releases_uri
87
+ begin
88
+ if gh_release
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
91
93
 
92
- latest = File.basename file.base_uri.to_s
93
- latest if satisfied.call latest
94
- end
94
+ latest = File.basename file.base_uri.to_s
95
+ latest if satisfied.call latest
96
+ end
95
97
 
96
- return tag_name unless tag_name.nil?
98
+ return tag_name unless tag_name.nil?
97
99
 
98
- uri = "https://api.github.com/repos/#{repo}/releases?per_page=100"
99
- tag_name = URI.parse(uri).open(headers) do |file|
100
- JSON.parse(file.read).map { |release| release['tag_name'] }
101
- end
102
- .find(satisfied)&.peek
103
- else
104
- uri = "https://api.github.com/repos/#{repo}/tags?per_page=100"
105
- tag_name = URI.parse(uri).open(headers) do |file|
106
- JSON.parse(file.read).map { |tag| tag['name'] }
100
+ uri = "https://api.github.com/repos/#{repo}/releases?per_page=100"
101
+ tag_name = URI.parse(uri).open(headers) do |file|
102
+ JSON.parse(file.read).map { |release| release['tag_name'] }
103
+ end
104
+ .find(satisfied)&.peek
105
+ else
106
+ uri = "https://api.github.com/repos/#{repo}/tags?per_page=100"
107
+ tag_name = URI.parse(uri).open(headers) do |file|
108
+ JSON.parse(file.read).map { |tag| tag['name'] }
109
+ end
110
+ .find(satisfied)&.peek
107
111
  end
108
- .find(satisfied)&.peek
112
+
113
+ return tag_name unless tag_name.nil?
114
+ rescue OpenURI::HTTPError => e
115
+ warn "WARNING: Error fetching #{uri}: #{e}"
109
116
  end
110
117
 
111
- return tag_name unless tag_name.nil?
112
- rescue OpenURI::HTTPError => e
113
- warn "WARNING: Error fetching #{uri}: #{e}"
118
+ requirements.requirements
119
+ .map { |requirement| requirement.last.to_s.gsub('.pre.', '-') }
120
+ .find(satisfied)&.peek
114
121
  end
115
122
 
116
- requirements.requirements
117
- .map { |requirement| requirement.last.to_s.gsub('.pre.', '-') }
118
- .find(satisfied)&.peek
119
- end
123
+ def default_sass_embedded
124
+ repo = 'sass/dart-sass-embedded'
125
+
126
+ tag_name = resolve_tag_name(repo, Compiler::REQUIREMENTS)
120
127
 
121
- def default_sass_embedded
122
- repo = 'sass/dart-sass-embedded'
123
-
124
- tag_name = resolve_tag_name(repo, Compiler::REQUIREMENTS)
125
-
126
- os = case Platform::OS
127
- when 'darwin'
128
- 'macos'
129
- when 'linux'
130
- 'linux'
131
- when 'windows'
132
- 'windows'
133
- else
134
- raise "Unsupported OS: #{Platform::OS}"
135
- end
136
-
137
- arch = case Platform::ARCH
138
- when 'x86_64'
139
- 'x64'
140
- when 'i386'
141
- 'ia32'
142
- when 'aarch64'
143
- raise "Unsupported Arch: #{Platform::ARCH}" unless Platform::OS == 'darwin'
144
-
145
- 'x64'
128
+ os = case Platform::OS
129
+ when 'darwin'
130
+ 'macos'
131
+ when 'linux'
132
+ 'linux'
133
+ when 'windows'
134
+ 'windows'
146
135
  else
147
- raise "Unsupported Arch: #{Platform::ARCH}"
136
+ raise "Unsupported OS: #{Platform::OS}"
148
137
  end
149
138
 
150
- ext = case os
151
- when 'windows'
152
- 'zip'
153
- else
154
- 'tar.gz'
155
- 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'
156
146
 
157
- "https://github.com/#{repo}/releases/download/#{tag_name}/sass_embedded-#{tag_name}-#{os}-#{arch}.#{ext}"
158
- end
147
+ 'x64'
148
+ else
149
+ raise "Unsupported Arch: #{Platform::ARCH}"
150
+ end
159
151
 
160
- def default_protoc
161
- repo = 'protocolbuffers/protobuf'
152
+ ext = case os
153
+ when 'windows'
154
+ 'zip'
155
+ else
156
+ 'tar.gz'
157
+ end
162
158
 
163
- spec = Gem::Dependency.new('google-protobuf').to_spec
159
+ "https://github.com/#{repo}/releases/download/#{tag_name}/sass_embedded-#{tag_name}-#{os}-#{arch}.#{ext}"
160
+ end
164
161
 
165
- tag_name = "v#{spec.version}"
162
+ def default_protoc
163
+ repo = 'protocolbuffers/protobuf'
166
164
 
167
- os = case Platform::OS
168
- when 'darwin'
169
- 'osx'
170
- when 'linux'
171
- 'linux'
172
- when 'windows'
173
- 'win'
174
- else
175
- raise "Unsupported OS: #{Platform::OS}"
176
- end
165
+ spec = Gem::Dependency.new('google-protobuf').to_spec
177
166
 
178
- arch = case Platform::ARCH
179
- when 'aarch64'
180
- if Platform::OS == 'darwin'
167
+ tag_name = "v#{spec.version}"
168
+
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'
181
192
  'x86_64'
193
+ when 'powerpc64'
194
+ 'ppcle_64'
182
195
  else
183
- 'aarch_64'
196
+ raise "Unsupported Arch: #{Platform::ARCH}"
184
197
  end
185
- when 'sparcv9'
186
- 's390'
187
- when 'i386'
188
- 'x86_32'
189
- when 'x86_64'
190
- 'x86_64'
191
- when 'powerpc64'
192
- 'ppcle_64'
193
- else
194
- raise "Unsupported Arch: #{Platform::ARCH}"
195
- end
196
198
 
197
- os_arch = case os
198
- when 'win'
199
- os + arch.split('_').last
200
- else
201
- "#{os}-#{arch}"
202
- end
199
+ os_arch = case os
200
+ when 'win'
201
+ os + arch.split('_').last
202
+ else
203
+ "#{os}-#{arch}"
204
+ end
203
205
 
204
- ext = 'zip'
206
+ ext = 'zip'
205
207
 
206
- "https://github.com/#{repo}/releases/download/#{tag_name}/protoc-#{tag_name[1..]}-#{os_arch}.#{ext}"
207
- end
208
+ "https://github.com/#{repo}/releases/download/#{tag_name}/protoc-#{tag_name[1..]}-#{os_arch}.#{ext}"
209
+ end
208
210
 
209
- def default_sass_embedded_protocol
210
- repo = 'sass/embedded-protocol'
211
+ def default_sass_embedded_protocol
212
+ repo = 'sass/embedded-protocol'
211
213
 
212
- tag_name = IO.popen([Compiler::DART_SASS_EMBEDDED, '--version']) do |file|
213
- JSON.parse(file.read)['protocolVersion']
214
- end
214
+ tag_name = IO.popen([Compiler::PATH, '--version']) do |file|
215
+ JSON.parse(file.read)['protocolVersion']
216
+ end
215
217
 
216
- "https://raw.githubusercontent.com/#{repo}/#{tag_name}/embedded_sass.proto"
218
+ "https://raw.githubusercontent.com/#{repo}/#{tag_name}/embedded_sass.proto"
219
+ end
217
220
  end
218
221
  end
219
222
  end
220
223
 
221
- 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 ProtocolError
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