sass-embedded 1.69.3 → 1.69.4

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: 1509d7ed0fb36b2105b5e4b4c2a9c75329e2235f5b5d3df80bbc6c5453974007
4
- data.tar.gz: 0f85ac7960bab13667c83d084912b9bfdc6026e29027b4cadd426ec40314d154
3
+ metadata.gz: 7b75bdfda99382f0e6be135736c4a395606d1f3c113511a4c678f3d8ad7b9340
4
+ data.tar.gz: 02eb7dc20e74ca76ffd6aae45bf42fcc04a77781a18436cba415f699a4833cb8
5
5
  SHA512:
6
- metadata.gz: 4d8230d785381a7a7f2c73c7d7e34599b1be1357a129e9e218a4560f87ae91868a2f80610102c5c6ada7071c3c163e8ea7c466075b4b1cdf13f588c58c9ae25e
7
- data.tar.gz: 54e6d181394a8767537a8694449bc81664bd3f103f335e1190c2a36b14025443558a304155e3eabdfdd4f28b8e980efd0ec8d411137d008c902b8f0ae5423f72
6
+ metadata.gz: b572dd621a3d86ead89f664b9c0f86d7cc50504816ab61c1c31b0259250796f5ea5d6ceed7ccc5e3f1e695cfdb1dd55660a05c3833b3043a63dbc5aa16d485ff
7
+ data.tar.gz: 77a1fbc37314e99ad0d8e8cb95359c9a7aba9ac3799351b36c495e476db290f48ab920bc4e0f56671e6fd2c2ceaf1acae8324d42d72042fb19966d548ee39ba0
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "dependencies": {
3
- "sass": "1.69.3"
3
+ "sass": "1.69.4"
4
4
  }
5
5
  }
@@ -2,14 +2,16 @@
2
2
 
3
3
  require 'open3'
4
4
 
5
+ require_relative '../../../ext/sass/cli'
6
+
5
7
  module Sass
6
8
  class Embedded
7
9
  # The stdio based {Connection} between the {Dispatcher} and the compiler.
8
10
  #
9
11
  # It runs the `sass --embedded` command.
10
12
  class Connection
11
- def initialize
12
- @stdin, @stdout, @stderr, @wait_thread = begin
13
+ def initialize(dispatcher)
14
+ @stdin, stdout, stderr, @wait_thread = begin
13
15
  Open3.popen3(*CLI::COMMAND, '--embedded', chdir: __dir__)
14
16
  rescue Errno::ENOENT
15
17
  require_relative '../elf'
@@ -18,51 +20,46 @@ module Sass
18
20
 
19
21
  Open3.popen3(ELF::INTERPRETER, *CLI::COMMAND, '--embedded', chdir: __dir__)
20
22
  end
21
-
22
23
  @stdin.binmode
23
- @stdout.binmode
24
- @stdin_mutex = Mutex.new
25
- @stdout_mutex = Mutex.new
24
+
25
+ Thread.new do
26
+ stdout.binmode
27
+ loop do
28
+ length = Varint.read(stdout)
29
+ id = Varint.read(stdout)
30
+ proto = stdout.read(length - Varint.length(id))
31
+ dispatcher.receive_proto(id, proto)
32
+ rescue IOError, Errno::EBADF, Errno::EPROTO => e
33
+ dispatcher.error(e)
34
+ break
35
+ end
36
+ stdout.close
37
+ end
26
38
 
27
39
  Thread.new do
28
40
  loop do
29
- warn(@stderr.readline, uplevel: 1)
41
+ warn(stderr.readline, uplevel: 1)
30
42
  rescue IOError, Errno::EBADF
31
43
  break
32
44
  end
45
+ stderr.close
33
46
  end
34
47
  end
35
48
 
36
49
  def close
37
- @stdin_mutex.synchronize do
38
- @stdin.close
39
- @wait_thread.join
40
- @stdout.close
41
- @stderr.close
42
- end
50
+ @stdin.close
51
+ @wait_thread.join
43
52
  end
44
53
 
45
54
  def closed?
46
- @stdin_mutex.synchronize do
47
- @stdin.closed?
48
- end
55
+ @stdin.closed? && !@wait_thread.alive?
49
56
  end
50
57
 
51
58
  def write(id, proto)
52
- @stdin_mutex.synchronize do
53
- Varint.write(@stdin, Varint.length(id) + proto.length)
54
- Varint.write(@stdin, id)
55
- @stdin.write(proto)
56
- end
57
- end
58
-
59
- def read
60
- @stdout_mutex.synchronize do
61
- length = Varint.read(@stdout)
62
- id = Varint.read(@stdout)
63
- proto = @stdout.read(length - Varint.length(id))
64
- return id, proto
65
- end
59
+ buffer = []
60
+ Varint.write(buffer, Varint.length(id) + proto.length)
61
+ Varint.write(buffer, id)
62
+ @stdin.write(buffer.pack('C*'), proto)
66
63
  end
67
64
  end
68
65
 
@@ -6,33 +6,16 @@ module Sass
6
6
  #
7
7
  # It dispatches messages between mutliple instances of {Host} and a single {Connection} to the compiler.
8
8
  class Dispatcher
9
- UINT_MAX = 0xffffffff
10
-
11
9
  def initialize
12
- @connection = Connection.new
13
- @observers = {}
14
10
  @id = 1
11
+ @observers = {}
15
12
  @mutex = Mutex.new
16
-
17
- Thread.new do
18
- loop do
19
- receive_proto
20
- rescue IOError, Errno::EBADF, Errno::EPROTO => e
21
- values = @mutex.synchronize do
22
- @id = UINT_MAX
23
- @observers.values
24
- end
25
- values.each do |observer|
26
- observer.error(e)
27
- end
28
- break
29
- end
30
- end
13
+ @connection = Connection.new(self)
31
14
  end
32
15
 
33
16
  def subscribe(observer)
34
17
  @mutex.synchronize do
35
- raise Errno::EBUSY if @id == UINT_MAX
18
+ raise Errno::EBUSY if @id == 0xffffffff
36
19
 
37
20
  id = @id
38
21
  @id = id.next
@@ -47,7 +30,7 @@ module Sass
47
30
 
48
31
  return unless @observers.empty?
49
32
 
50
- if @id == UINT_MAX
33
+ if @id == 0xffffffff
51
34
  Thread.new do
52
35
  close
53
36
  end
@@ -69,29 +52,31 @@ module Sass
69
52
  @connection.closed?
70
53
  end
71
54
 
72
- def error
73
- @mutex.synchronize do
74
- @id = UINT_MAX
55
+ def error(error)
56
+ observers = @mutex.synchronize do
57
+ @id = 0xffffffff
58
+ @observers.values
75
59
  end
76
- end
77
60
 
78
- def send_proto(...)
79
- @connection.write(...)
61
+ if observers.empty?
62
+ close
63
+ else
64
+ observers.each do |observer|
65
+ observer.error(error)
66
+ end
67
+ end
80
68
  end
81
69
 
82
- private
83
-
84
- def receive_proto
85
- id, proto = @connection.read
70
+ def receive_proto(id, proto)
86
71
  case id
87
- when 1...UINT_MAX
72
+ when 1...0xffffffff
88
73
  @mutex.synchronize { @observers[id] }.receive_proto(proto)
89
74
  when 0
90
75
  outbound_message = EmbeddedProtocol::OutboundMessage.decode(proto)
91
76
  oneof = outbound_message.message
92
77
  message = outbound_message.public_send(oneof)
93
78
  @mutex.synchronize { @observers[message.id] }.public_send(oneof, message)
94
- when UINT_MAX
79
+ when 0xffffffff
95
80
  outbound_message = EmbeddedProtocol::OutboundMessage.decode(proto)
96
81
  oneof = outbound_message.message
97
82
  message = outbound_message.public_send(oneof)
@@ -101,6 +86,10 @@ module Sass
101
86
  end
102
87
  end
103
88
 
89
+ def send_proto(...)
90
+ @connection.write(...)
91
+ end
92
+
104
93
  # The {Channel} between {Dispatcher} and {Host}.
105
94
  class Channel
106
95
  attr_reader :id
@@ -114,6 +103,12 @@ module Sass
114
103
  @dispatcher.unsubscribe(id)
115
104
  end
116
105
 
106
+ def error(...)
107
+ Thread.new do
108
+ @dispatcher.error(...)
109
+ end
110
+ end
111
+
117
112
  def send_proto(...)
118
113
  @dispatcher.send_proto(...)
119
114
  end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ class Embedded
5
+ class Host
6
+ # The {Protofier} module.
7
+ #
8
+ # It converts Pure Ruby types and Protobuf Ruby types.
9
+ module Protofier
10
+ module_function
11
+
12
+ def from_proto_canonicalize_context(canonicalize_request)
13
+ CanonicalizeContext.new(
14
+ canonicalize_request.containing_url == '' ? nil : canonicalize_request.containing_url,
15
+ canonicalize_request.from_import
16
+ )
17
+ end
18
+
19
+ def from_proto_compile_response(compile_response)
20
+ oneof = compile_response.result
21
+ result = compile_response.public_send(oneof)
22
+ case oneof
23
+ when :failure
24
+ raise CompileError.new(
25
+ result.message,
26
+ result.formatted == '' ? nil : result.formatted,
27
+ result.stack_trace == '' ? nil : result.stack_trace,
28
+ from_proto_source_span(result.span),
29
+ compile_response.loaded_urls
30
+ )
31
+ when :success
32
+ CompileResult.new(
33
+ result.css,
34
+ result.source_map == '' ? nil : result.source_map,
35
+ compile_response.loaded_urls
36
+ )
37
+ else
38
+ raise ArgumentError, "Unknown CompileResponse.result #{result}"
39
+ end
40
+ end
41
+
42
+ def from_proto_source_span(source_span)
43
+ return if source_span.nil?
44
+
45
+ Logger::SourceSpan.new(from_proto_source_location(source_span.start),
46
+ from_proto_source_location(source_span.end),
47
+ source_span.text,
48
+ source_span.url == '' ? nil : source_span.url,
49
+ source_span.context == '' ? nil : source_span.context)
50
+ end
51
+
52
+ def from_proto_source_location(source_location)
53
+ return if source_location.nil?
54
+
55
+ Logger::SourceLocation.new(source_location.offset,
56
+ source_location.line,
57
+ source_location.column)
58
+ end
59
+
60
+ def to_proto_syntax(syntax)
61
+ case syntax&.to_sym
62
+ when :scss
63
+ EmbeddedProtocol::Syntax::SCSS
64
+ when :indented
65
+ EmbeddedProtocol::Syntax::INDENTED
66
+ when :css
67
+ EmbeddedProtocol::Syntax::CSS
68
+ else
69
+ raise ArgumentError, 'syntax must be one of :scss, :indented, :css'
70
+ end
71
+ end
72
+
73
+ def to_proto_output_style(style)
74
+ case style&.to_sym
75
+ when :expanded
76
+ EmbeddedProtocol::OutputStyle::EXPANDED
77
+ when :compressed
78
+ EmbeddedProtocol::OutputStyle::COMPRESSED
79
+ else
80
+ raise ArgumentError, 'style must be one of :expanded, :compressed'
81
+ end
82
+ end
83
+ end
84
+
85
+ private_constant :Protofier
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ class Embedded
5
+ class Host
6
+ # The {Structifier} module.
7
+ #
8
+ # It converts {::Hash} to {Struct}-like objects.
9
+ module Structifier
10
+ module_function
11
+
12
+ def to_struct(obj, *symbols)
13
+ return obj unless obj.is_a? Hash
14
+
15
+ struct = Object.new
16
+ symbols.each do |key|
17
+ next unless obj.key?(key)
18
+
19
+ value = obj[key]
20
+ if value.respond_to? :call
21
+ struct.define_singleton_method key do |*args, **kwargs|
22
+ value.call(*args, **kwargs)
23
+ end
24
+ else
25
+ struct.define_singleton_method key do
26
+ value
27
+ end
28
+ end
29
+ end
30
+ struct
31
+ end
32
+ end
33
+
34
+ private_constant :Structifier
35
+ end
36
+ end
37
+ end
@@ -3,6 +3,8 @@
3
3
  require_relative 'host/function_registry'
4
4
  require_relative 'host/importer_registry'
5
5
  require_relative 'host/logger_registry'
6
+ require_relative 'host/protofier'
7
+ require_relative 'host/structifier'
6
8
  require_relative 'host/value_protofier'
7
9
 
8
10
  module Sass
@@ -88,8 +90,8 @@ module Sass
88
90
  def error(message)
89
91
  case message
90
92
  when EmbeddedProtocol::ProtocolError
91
- @dispatcher.error
92
93
  @error = Errno::EPROTO.new(message.message)
94
+ @channel.error(@error)
93
95
  else
94
96
  @error ||= message
95
97
  end
@@ -33,10 +33,6 @@ module Sass
33
33
  @dispatcher.connect(...)
34
34
  end
35
35
  end
36
-
37
- def error(...)
38
- @dispatcher.error(...)
39
- end
40
36
  end
41
37
 
42
38
  private_constant :ResilientDispatcher
@@ -26,13 +26,11 @@ module Sass
26
26
  end
27
27
 
28
28
  def write(writeable, value)
29
- bytes = []
30
29
  until value < 0x80
31
- bytes << ((value & 0x7f) | 0x80)
30
+ writeable << ((value & 0x7f) | 0x80)
32
31
  value >>= 7
33
32
  end
34
- bytes << value
35
- writeable.write bytes.pack('C*')
33
+ writeable << value
36
34
  end
37
35
  end
38
36
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sass
4
4
  class Embedded
5
- VERSION = '1.69.3'
5
+ VERSION = '1.69.4'
6
6
  end
7
7
  end
data/lib/sass/embedded.rb CHANGED
@@ -1,15 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../ext/sass/cli'
4
3
  require_relative 'canonicalize_context'
5
4
  require_relative 'compile_error'
6
5
  require_relative 'compile_result'
7
6
  require_relative 'embedded/connection'
8
7
  require_relative 'embedded/dispatcher'
9
8
  require_relative 'embedded/host'
10
- require_relative 'embedded/protofier'
11
9
  require_relative 'embedded/resilient_dispatcher'
12
- require_relative 'embedded/structifier'
13
10
  require_relative 'embedded/varint'
14
11
  require_relative 'embedded/version'
15
12
  require_relative 'embedded_protocol'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sass-embedded
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.69.3
4
+ version: 1.69.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - なつき
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-12 00:00:00.000000000 Z
11
+ date: 2023-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-protobuf
@@ -70,10 +70,10 @@ files:
70
70
  - lib/sass/embedded/host/function_registry.rb
71
71
  - lib/sass/embedded/host/importer_registry.rb
72
72
  - lib/sass/embedded/host/logger_registry.rb
73
+ - lib/sass/embedded/host/protofier.rb
74
+ - lib/sass/embedded/host/structifier.rb
73
75
  - lib/sass/embedded/host/value_protofier.rb
74
- - lib/sass/embedded/protofier.rb
75
76
  - lib/sass/embedded/resilient_dispatcher.rb
76
- - lib/sass/embedded/structifier.rb
77
77
  - lib/sass/embedded/varint.rb
78
78
  - lib/sass/embedded/version.rb
79
79
  - lib/sass/embedded_protocol.rb
@@ -99,8 +99,8 @@ homepage: https://github.com/ntkme/sass-embedded-host-ruby
99
99
  licenses:
100
100
  - MIT
101
101
  metadata:
102
- documentation_uri: https://rubydoc.info/gems/sass-embedded/1.69.3
103
- source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v1.69.3
102
+ documentation_uri: https://rubydoc.info/gems/sass-embedded/1.69.4
103
+ source_code_uri: https://github.com/ntkme/sass-embedded-host-ruby/tree/v1.69.4
104
104
  funding_uri: https://github.com/sponsors/ntkme
105
105
  post_install_message:
106
106
  rdoc_options: []
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubygems_version: 3.4.20
120
+ rubygems_version: 3.4.21
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Use dart-sass with Ruby!
@@ -1,86 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Sass
4
- class Embedded
5
- # The {Protofier} module.
6
- #
7
- # It converts Pure Ruby types and Protobuf Ruby types.
8
- module Protofier
9
- module_function
10
-
11
- def from_proto_canonicalize_context(canonicalize_request)
12
- CanonicalizeContext.new(
13
- canonicalize_request.containing_url == '' ? nil : canonicalize_request.containing_url,
14
- canonicalize_request.from_import
15
- )
16
- end
17
-
18
- def from_proto_compile_response(compile_response)
19
- oneof = compile_response.result
20
- result = compile_response.public_send(oneof)
21
- case oneof
22
- when :failure
23
- raise CompileError.new(
24
- result.message,
25
- result.formatted == '' ? nil : result.formatted,
26
- result.stack_trace == '' ? nil : result.stack_trace,
27
- from_proto_source_span(result.span),
28
- compile_response.loaded_urls
29
- )
30
- when :success
31
- CompileResult.new(
32
- result.css,
33
- result.source_map == '' ? nil : result.source_map,
34
- compile_response.loaded_urls
35
- )
36
- else
37
- raise ArgumentError, "Unknown CompileResponse.result #{result}"
38
- end
39
- end
40
-
41
- def from_proto_source_span(source_span)
42
- return if source_span.nil?
43
-
44
- Logger::SourceSpan.new(from_proto_source_location(source_span.start),
45
- from_proto_source_location(source_span.end),
46
- source_span.text,
47
- source_span.url == '' ? nil : source_span.url,
48
- source_span.context == '' ? nil : source_span.context)
49
- end
50
-
51
- def from_proto_source_location(source_location)
52
- return if source_location.nil?
53
-
54
- Logger::SourceLocation.new(source_location.offset,
55
- source_location.line,
56
- source_location.column)
57
- end
58
-
59
- def to_proto_syntax(syntax)
60
- case syntax&.to_sym
61
- when :scss
62
- EmbeddedProtocol::Syntax::SCSS
63
- when :indented
64
- EmbeddedProtocol::Syntax::INDENTED
65
- when :css
66
- EmbeddedProtocol::Syntax::CSS
67
- else
68
- raise ArgumentError, 'syntax must be one of :scss, :indented, :css'
69
- end
70
- end
71
-
72
- def to_proto_output_style(style)
73
- case style&.to_sym
74
- when :expanded
75
- EmbeddedProtocol::OutputStyle::EXPANDED
76
- when :compressed
77
- EmbeddedProtocol::OutputStyle::COMPRESSED
78
- else
79
- raise ArgumentError, 'style must be one of :expanded, :compressed'
80
- end
81
- end
82
- end
83
-
84
- private_constant :Protofier
85
- end
86
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Sass
4
- class Embedded
5
- # The {Structifier} module.
6
- #
7
- # It converts {::Hash} to {Struct}-like objects.
8
- module Structifier
9
- module_function
10
-
11
- def to_struct(obj, *symbols)
12
- return obj unless obj.is_a? Hash
13
-
14
- struct = Object.new
15
- symbols.each do |key|
16
- next unless obj.key?(key)
17
-
18
- value = obj[key]
19
- if value.respond_to? :call
20
- struct.define_singleton_method key do |*args, **kwargs|
21
- value.call(*args, **kwargs)
22
- end
23
- else
24
- struct.define_singleton_method key do
25
- value
26
- end
27
- end
28
- end
29
- struct
30
- end
31
- end
32
-
33
- private_constant :Structifier
34
- end
35
- end