sass-embedded 1.107.0-aarch64-mswin64
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +48 -0
- data/exe/sass +13 -0
- data/lib/sass/calculation_value/calculation_operation.rb +49 -0
- data/lib/sass/calculation_value.rb +22 -0
- data/lib/sass/canonicalize_context.rb +25 -0
- data/lib/sass/cli.rb +12 -0
- data/lib/sass/compile_result.rb +24 -0
- data/lib/sass/compiler/channel.rb +70 -0
- data/lib/sass/compiler/connection.rb +109 -0
- data/lib/sass/compiler/dispatcher.rb +142 -0
- data/lib/sass/compiler/session/function_registry.rb +88 -0
- data/lib/sass/compiler/session/importer_registry.rb +190 -0
- data/lib/sass/compiler/session/logger_registry.rb +99 -0
- data/lib/sass/compiler/session/path.rb +23 -0
- data/lib/sass/compiler/session/protofier.rb +384 -0
- data/lib/sass/compiler/session/stack_trace.rb +46 -0
- data/lib/sass/compiler/session.rb +242 -0
- data/lib/sass/compiler/varint.rb +39 -0
- data/lib/sass/compiler.rb +214 -0
- data/lib/sass/dart-sass/sass.bat +7 -0
- data/lib/sass/dart-sass/src/LICENSE +1659 -0
- data/lib/sass/dart-sass/src/dart.exe +0 -0
- data/lib/sass/dart-sass/src/sass.snapshot +0 -0
- data/lib/sass/elf.rb +386 -0
- data/lib/sass/embedded/version.rb +7 -0
- data/lib/sass/embedded.rb +67 -0
- data/lib/sass/embedded_protocol.rb +10 -0
- data/lib/sass/embedded_sass_pb.rb +62 -0
- data/lib/sass/exception.rb +73 -0
- data/lib/sass/fork_tracker.rb +56 -0
- data/lib/sass/gem_package_importer.rb +28 -0
- data/lib/sass/logger/silent.rb +28 -0
- data/lib/sass/logger/source_location.rb +22 -0
- data/lib/sass/logger/source_span.rb +28 -0
- data/lib/sass/node_package_importer.rb +17 -0
- data/lib/sass/serializer.rb +30 -0
- data/lib/sass/uri.rb +56 -0
- data/lib/sass/value/argument_list.rb +29 -0
- data/lib/sass/value/boolean.rb +59 -0
- data/lib/sass/value/calculation.rb +90 -0
- data/lib/sass/value/color/channel.rb +79 -0
- data/lib/sass/value/color/conversions.rb +473 -0
- data/lib/sass/value/color/gamut_map_method/clip.rb +45 -0
- data/lib/sass/value/color/gamut_map_method/local_minde.rb +94 -0
- data/lib/sass/value/color/gamut_map_method.rb +45 -0
- data/lib/sass/value/color/interpolation_method.rb +51 -0
- data/lib/sass/value/color/space/a98_rgb.rb +57 -0
- data/lib/sass/value/color/space/display_p3.rb +72 -0
- data/lib/sass/value/color/space/display_p3_linear.rb +72 -0
- data/lib/sass/value/color/space/hsl.rb +65 -0
- data/lib/sass/value/color/space/hwb.rb +94 -0
- data/lib/sass/value/color/space/lab.rb +85 -0
- data/lib/sass/value/color/space/lch.rb +53 -0
- data/lib/sass/value/color/space/lms.rb +146 -0
- data/lib/sass/value/color/space/oklab.rb +71 -0
- data/lib/sass/value/color/space/oklch.rb +54 -0
- data/lib/sass/value/color/space/prophoto_rgb.rb +59 -0
- data/lib/sass/value/color/space/rec2020.rb +57 -0
- data/lib/sass/value/color/space/rgb.rb +52 -0
- data/lib/sass/value/color/space/srgb.rb +145 -0
- data/lib/sass/value/color/space/srgb_linear.rb +72 -0
- data/lib/sass/value/color/space/utils.rb +89 -0
- data/lib/sass/value/color/space/xyz_d50.rb +113 -0
- data/lib/sass/value/color/space/xyz_d65.rb +57 -0
- data/lib/sass/value/color/space.rb +218 -0
- data/lib/sass/value/color.rb +631 -0
- data/lib/sass/value/function.rb +66 -0
- data/lib/sass/value/fuzzy_math.rb +84 -0
- data/lib/sass/value/list.rb +89 -0
- data/lib/sass/value/map.rb +77 -0
- data/lib/sass/value/mixin.rb +47 -0
- data/lib/sass/value/module.rb +47 -0
- data/lib/sass/value/null.rb +58 -0
- data/lib/sass/value/number/unit.rb +187 -0
- data/lib/sass/value/number.rb +364 -0
- data/lib/sass/value/string.rb +78 -0
- data/lib/sass/value.rb +174 -0
- data/lib/sass-embedded.rb +4 -0
- metadata +140 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: fe0eb3c3c513974ba191cdbd9696fdad3ebc2f8e40b9f7cf9b924f2e210e498a
|
|
4
|
+
data.tar.gz: b0be1f7ca34b28c9b15dbb7805e80576201853fc43acf1d394b3c4910fdab359
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 377a083279fb6738f2c8d889bd86c5ce95c6f18b3559acd474e1e27ae759071102ecd223efc8dc13c827c12cf39869555bc27bc73269df184ac610d050897203
|
|
7
|
+
data.tar.gz: 3676848b91b1274f79937bf7c552bbb7b9d3010ed81b5effa4e5863a782773ca68c027b03f8ea508eeb25978ceee26623aa54f3425c91efaadf3ecf089f36412
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 なつき
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Embedded Sass Host for Ruby
|
|
2
|
+
|
|
3
|
+
[](https://github.com/sass-contrib/sass-embedded-host-ruby/actions/workflows/build.yml)
|
|
4
|
+
[](https://rubygems.org/gems/sass-embedded)
|
|
5
|
+
|
|
6
|
+
This is a Ruby library that implements the host side of the [Embedded Sass protocol](https://github.com/sass/sass/blob/HEAD/spec/embedded-protocol.md).
|
|
7
|
+
|
|
8
|
+
It exposes a Ruby API for Sass that's backed by a native [Dart Sass](https://sass-lang.com/dart-sass) executable on [supported hardware architectures and platforms](https://dart.dev/get-dart#system-requirements) or a Node.js Dart Sass executable everywhere else.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
``` sh
|
|
13
|
+
gem install sass-embedded
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
The Ruby API provides two entrypoints for compiling Sass to CSS.
|
|
19
|
+
|
|
20
|
+
- `Sass.compile` takes a path to a Sass file and return the result of compiling that file to CSS.
|
|
21
|
+
|
|
22
|
+
``` ruby
|
|
23
|
+
require 'sass-embedded'
|
|
24
|
+
|
|
25
|
+
result = Sass.compile('style.scss')
|
|
26
|
+
puts result.css
|
|
27
|
+
|
|
28
|
+
compressed = Sass.compile('style.scss', style: :compressed)
|
|
29
|
+
puts compressed.css
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
- `Sass.compile_string` takes a string that represents the contents of a Sass file and return the result of compiling that file to CSS.
|
|
33
|
+
|
|
34
|
+
``` ruby
|
|
35
|
+
require 'sass-embedded'
|
|
36
|
+
|
|
37
|
+
result = Sass.compile_string('h1 { font-size: 40px; }')
|
|
38
|
+
puts result.css
|
|
39
|
+
|
|
40
|
+
compressed = Sass.compile_string('h1 { font-size: 40px; }', style: :compressed)
|
|
41
|
+
puts compressed.css
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
See [rubydoc.info/gems/sass-embedded/Sass](https://rubydoc.info/gems/sass-embedded/Sass) for full API documentation.
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
Disclaimer: this is not an official Google product.
|
data/exe/sass
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sass
|
|
4
|
+
module CalculationValue
|
|
5
|
+
# A binary operation that can appear in a SassCalculation.
|
|
6
|
+
#
|
|
7
|
+
# @see https://sass-lang.com/documentation/js-api/classes/calculationoperation/
|
|
8
|
+
class CalculationOperation
|
|
9
|
+
include CalculationValue
|
|
10
|
+
|
|
11
|
+
OPERATORS = %w[+ - * /].freeze
|
|
12
|
+
|
|
13
|
+
private_constant :OPERATORS
|
|
14
|
+
|
|
15
|
+
# @param operator [::String]
|
|
16
|
+
# @param left [CalculationValue]
|
|
17
|
+
# @param right [CalculationValue]
|
|
18
|
+
def initialize(operator, left, right)
|
|
19
|
+
raise Sass::ScriptError, "Invalid operator: #{operator}" unless OPERATORS.include?(operator)
|
|
20
|
+
|
|
21
|
+
@operator = operator.freeze
|
|
22
|
+
@left = assert_calculation_value(left, 'left')
|
|
23
|
+
@right = assert_calculation_value(right, 'right')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @return [::String]
|
|
27
|
+
attr_reader :operator
|
|
28
|
+
|
|
29
|
+
# @return [CalculationValue]
|
|
30
|
+
attr_reader :left
|
|
31
|
+
|
|
32
|
+
# @return [CalculationValue]
|
|
33
|
+
attr_reader :right
|
|
34
|
+
|
|
35
|
+
# @return [::Boolean]
|
|
36
|
+
def ==(other)
|
|
37
|
+
other.is_a?(Sass::CalculationValue::CalculationOperation) &&
|
|
38
|
+
other.operator == operator &&
|
|
39
|
+
other.left == left &&
|
|
40
|
+
other.right == right
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# @return [Integer]
|
|
44
|
+
def hash
|
|
45
|
+
@hash ||= [operator, left, right].hash
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sass
|
|
4
|
+
# The type of values that can be arguments to a SassCalculation.
|
|
5
|
+
#
|
|
6
|
+
# @see https://sass-lang.com/documentation/js-api/types/calculationvalue/
|
|
7
|
+
module CalculationValue
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
def assert_calculation_value(value, name = nil)
|
|
11
|
+
if !value.is_a?(Sass::CalculationValue) || (value.is_a?(Sass::Value::String) && value.quoted?)
|
|
12
|
+
raise Sass::ScriptError.new(
|
|
13
|
+
"#{value} must be one of SassNumber, unquoted SassString, SassCalculation, CalculationOperation", name
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
value
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
require_relative 'calculation_value/calculation_operation'
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sass
|
|
4
|
+
# Contextual information passed to `canonicalize` and `find_file_url`.
|
|
5
|
+
# Not all importers will need this information to resolve loads, but some may find it useful.
|
|
6
|
+
#
|
|
7
|
+
# @see https://sass-lang.com/documentation/js-api/interfaces/canonicalizecontext/
|
|
8
|
+
class CanonicalizeContext
|
|
9
|
+
# @return [String, nil]
|
|
10
|
+
def containing_url
|
|
11
|
+
@containing_url_unused = false
|
|
12
|
+
@containing_url
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# @return [Boolean]
|
|
16
|
+
attr_reader :from_import
|
|
17
|
+
|
|
18
|
+
# @!visibility private
|
|
19
|
+
def initialize(canonicalize_request)
|
|
20
|
+
@containing_url_unused = true
|
|
21
|
+
@containing_url = canonicalize_request.containing_url == '' ? nil : canonicalize_request.containing_url
|
|
22
|
+
@from_import = canonicalize_request.from_import
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/sass/cli.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sass
|
|
4
|
+
# The result of compiling Sass to CSS. Returned by {Sass.compile} and {Sass.compile_string}.
|
|
5
|
+
#
|
|
6
|
+
# @see https://sass-lang.com/documentation/js-api/interfaces/compileresult/
|
|
7
|
+
class CompileResult
|
|
8
|
+
# @return [String]
|
|
9
|
+
attr_reader :css
|
|
10
|
+
|
|
11
|
+
# @return [String, nil]
|
|
12
|
+
attr_reader :source_map
|
|
13
|
+
|
|
14
|
+
# @return [Array<String>]
|
|
15
|
+
attr_reader :loaded_urls
|
|
16
|
+
|
|
17
|
+
# @!visibility private
|
|
18
|
+
def initialize(css, source_map, loaded_urls)
|
|
19
|
+
@css = css
|
|
20
|
+
@source_map = source_map
|
|
21
|
+
@loaded_urls = loaded_urls
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sass
|
|
4
|
+
class Compiler
|
|
5
|
+
# The {Channel} class.
|
|
6
|
+
#
|
|
7
|
+
# It manages the lifecycle of {Dispatcher}.
|
|
8
|
+
class Channel
|
|
9
|
+
def initialize(*args, **kwargs, &block)
|
|
10
|
+
@args = args
|
|
11
|
+
@kwargs = kwargs
|
|
12
|
+
@block = block
|
|
13
|
+
@dispatcher = Dispatcher.new(*@args, **@kwargs, &@block)
|
|
14
|
+
@mutex = Mutex.new
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def close
|
|
18
|
+
@mutex.synchronize do
|
|
19
|
+
unless @dispatcher.nil?
|
|
20
|
+
@dispatcher.close
|
|
21
|
+
@dispatcher = nil
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def closed?
|
|
27
|
+
@mutex.synchronize do
|
|
28
|
+
@dispatcher.nil?
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def stream(session)
|
|
33
|
+
@mutex.synchronize do
|
|
34
|
+
raise IOError, 'closed compiler' if @dispatcher.nil?
|
|
35
|
+
|
|
36
|
+
Stream.new(@dispatcher, session)
|
|
37
|
+
rescue Errno::EBUSY
|
|
38
|
+
@dispatcher = Dispatcher.new(*@args, **@kwargs, &@block)
|
|
39
|
+
Stream.new(@dispatcher, session)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# The {Stream} between {Dispatcher} and {Session}.
|
|
44
|
+
class Stream
|
|
45
|
+
attr_reader :id
|
|
46
|
+
|
|
47
|
+
def initialize(dispatcher, session)
|
|
48
|
+
@dispatcher = dispatcher
|
|
49
|
+
@id = @dispatcher.subscribe(session)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def close
|
|
53
|
+
@dispatcher.unsubscribe(@id)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def error(...)
|
|
57
|
+
@dispatcher.error(...)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def send_proto(...)
|
|
61
|
+
@dispatcher.send_proto(...)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private_constant :Stream
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private_constant :Channel
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'open3'
|
|
4
|
+
|
|
5
|
+
require 'sass/cli'
|
|
6
|
+
|
|
7
|
+
module Sass
|
|
8
|
+
class Compiler
|
|
9
|
+
# The stdio based {Connection} between the {Dispatcher} and the compiler.
|
|
10
|
+
#
|
|
11
|
+
# It runs the `sass --embedded` command.
|
|
12
|
+
class Connection
|
|
13
|
+
def initialize
|
|
14
|
+
@mutex = Mutex.new
|
|
15
|
+
@stdin, @stdout, @stderr, @wait_thread = Open3.popen3(*CLI::COMMAND, '--embedded', chdir: __dir__)
|
|
16
|
+
|
|
17
|
+
@stdin.binmode
|
|
18
|
+
|
|
19
|
+
# # https://dart.dev/tools/dart-devtools
|
|
20
|
+
# if %w[dart dartvm].include?(File.basename(CLI::COMMAND.first, '.exe')) &&
|
|
21
|
+
# %w[--enable-vm-service --observe].intersect?(CLI::COMMAND.map { |argument| argument.partition('=').first })
|
|
22
|
+
# Kernel.warn(@stdout.readline, uplevel: 0)
|
|
23
|
+
# Kernel.warn(@stdout.readline, uplevel: 0)
|
|
24
|
+
# end
|
|
25
|
+
|
|
26
|
+
@stdout.binmode
|
|
27
|
+
|
|
28
|
+
@wait_thread.name = "sass-embedded-process-waiter-#{id}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def id
|
|
32
|
+
@wait_thread.pid
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def listen(dispatcher)
|
|
36
|
+
Thread.new do
|
|
37
|
+
Thread.current.name = "sass-embedded-process-stdout-poller-#{id}"
|
|
38
|
+
loop do
|
|
39
|
+
length = Varint.read(@stdout)
|
|
40
|
+
id = Varint.read(@stdout)
|
|
41
|
+
proto = @stdout.read(length - Varint.length(id))
|
|
42
|
+
dispatcher.receive_proto(id, proto)
|
|
43
|
+
end
|
|
44
|
+
rescue IOError, Errno::EBADF, Errno::EPROTO => e
|
|
45
|
+
dispatcher.error(e)
|
|
46
|
+
@mutex.synchronize do
|
|
47
|
+
@stdout.close
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
Thread.new do
|
|
52
|
+
Thread.current.name = "sass-embedded-process-stderr-poller-#{id}"
|
|
53
|
+
loop do
|
|
54
|
+
Kernel.warn(@stderr.readline, uplevel: 0)
|
|
55
|
+
end
|
|
56
|
+
rescue IOError, Errno::EBADF
|
|
57
|
+
@mutex.synchronize do
|
|
58
|
+
@stderr.close
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def close
|
|
64
|
+
@mutex.synchronize do
|
|
65
|
+
@stdin.close
|
|
66
|
+
@wait_thread.join
|
|
67
|
+
@stdout.close
|
|
68
|
+
@stderr.close
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def closed?
|
|
73
|
+
@mutex.synchronize do
|
|
74
|
+
@stdin.closed? && !@wait_thread.alive?
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
respond_to_pack_r = begin
|
|
79
|
+
old_verbose = $VERBOSE
|
|
80
|
+
$VERBOSE = nil
|
|
81
|
+
[0].pack('R') == "\0"
|
|
82
|
+
rescue ArgumentError
|
|
83
|
+
false
|
|
84
|
+
ensure
|
|
85
|
+
$VERBOSE = old_verbose
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
if respond_to_pack_r
|
|
89
|
+
def write(id, proto)
|
|
90
|
+
buffer = [Varint.length(id) + proto.length, id].pack('R*')
|
|
91
|
+
@mutex.synchronize do
|
|
92
|
+
@stdin.write(buffer, proto)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
else
|
|
96
|
+
def write(id, proto)
|
|
97
|
+
buffer = []
|
|
98
|
+
Varint.write(buffer, Varint.length(id) + proto.length)
|
|
99
|
+
Varint.write(buffer, id)
|
|
100
|
+
@mutex.synchronize do
|
|
101
|
+
@stdin.write(buffer.pack('C*'), proto)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
private_constant :Connection
|
|
108
|
+
end
|
|
109
|
+
end
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sass
|
|
4
|
+
class Compiler
|
|
5
|
+
# The {Dispatcher} class.
|
|
6
|
+
#
|
|
7
|
+
# It dispatches messages between multiple instances of {Session} and a single {Connection} to the compiler.
|
|
8
|
+
class Dispatcher
|
|
9
|
+
def initialize(idle_timeout: 0)
|
|
10
|
+
@id = 1
|
|
11
|
+
@observers = {}.compare_by_identity
|
|
12
|
+
@mutex = Mutex.new
|
|
13
|
+
@connection = Connection.new
|
|
14
|
+
@connection.listen(self)
|
|
15
|
+
ForkTracker.add(self)
|
|
16
|
+
|
|
17
|
+
return unless idle_timeout.positive?
|
|
18
|
+
|
|
19
|
+
@last_accessed_time = current_time
|
|
20
|
+
Thread.new do
|
|
21
|
+
Thread.current.name = "sass-embedded-connection-reaper-#{@connection.id}"
|
|
22
|
+
duration = idle_timeout
|
|
23
|
+
loop do
|
|
24
|
+
sleep(duration.negative? ? idle_timeout : duration)
|
|
25
|
+
break if @mutex.synchronize do
|
|
26
|
+
raise Errno::EBUSY if _closed?
|
|
27
|
+
|
|
28
|
+
duration = idle_timeout - (current_time - @last_accessed_time)
|
|
29
|
+
duration.negative? && _idle? && _close
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
close
|
|
33
|
+
rescue Errno::EBUSY
|
|
34
|
+
# do nothing
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def subscribe(observer)
|
|
39
|
+
@mutex.synchronize do
|
|
40
|
+
raise Errno::EBUSY if _closed?
|
|
41
|
+
|
|
42
|
+
id = @id
|
|
43
|
+
@id = id.next
|
|
44
|
+
@observers[id] = observer
|
|
45
|
+
id
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def unsubscribe(id)
|
|
50
|
+
@mutex.synchronize do
|
|
51
|
+
@observers.delete(id)
|
|
52
|
+
|
|
53
|
+
return unless @observers.empty?
|
|
54
|
+
|
|
55
|
+
if _closed?
|
|
56
|
+
Thread.new do
|
|
57
|
+
close
|
|
58
|
+
end
|
|
59
|
+
else
|
|
60
|
+
_idle
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def close
|
|
66
|
+
@mutex.synchronize do
|
|
67
|
+
_close
|
|
68
|
+
end
|
|
69
|
+
@connection.close
|
|
70
|
+
ForkTracker.delete(self)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def closed?
|
|
74
|
+
@connection.closed?
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def error(error)
|
|
78
|
+
observers = @mutex.synchronize do
|
|
79
|
+
_close
|
|
80
|
+
@observers.values
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
if observers.empty?
|
|
84
|
+
close
|
|
85
|
+
else
|
|
86
|
+
observers.each do |observer|
|
|
87
|
+
observer.error(error)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def receive_proto(id, proto)
|
|
93
|
+
case id
|
|
94
|
+
when 1...0xffffffff
|
|
95
|
+
@mutex.synchronize { @observers[id] }&.receive_proto(proto)
|
|
96
|
+
when 0
|
|
97
|
+
outbound_message = EmbeddedProtocol::OutboundMessage.decode(proto)
|
|
98
|
+
oneof = outbound_message.message
|
|
99
|
+
message = outbound_message.public_send(oneof)
|
|
100
|
+
@mutex.synchronize { @observers[message.id] }&.public_send(oneof, message)
|
|
101
|
+
when 0xffffffff
|
|
102
|
+
outbound_message = EmbeddedProtocol::OutboundMessage.decode(proto)
|
|
103
|
+
oneof = outbound_message.message
|
|
104
|
+
message = outbound_message.public_send(oneof)
|
|
105
|
+
raise Errno::EPROTO, message.message
|
|
106
|
+
else
|
|
107
|
+
raise Errno::EPROTO
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def send_proto(...)
|
|
112
|
+
@connection.write(...)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
private
|
|
116
|
+
|
|
117
|
+
def current_time
|
|
118
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def _close
|
|
122
|
+
@id = 0xffffffff
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def _closed?
|
|
126
|
+
@id == 0xffffffff
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def _idle
|
|
130
|
+
@last_accessed_time = current_time if defined?(@last_accessed_time)
|
|
131
|
+
|
|
132
|
+
@id = 1
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def _idle?
|
|
136
|
+
@id == 1
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
private_constant :Dispatcher
|
|
141
|
+
end
|
|
142
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Sass
|
|
4
|
+
class Compiler
|
|
5
|
+
class Session
|
|
6
|
+
# The {FunctionRegistry} class.
|
|
7
|
+
#
|
|
8
|
+
# It stores sass custom functions and handles function calls.
|
|
9
|
+
class FunctionRegistry
|
|
10
|
+
attr_reader :compile_context, :global_functions
|
|
11
|
+
|
|
12
|
+
def initialize(functions, session:)
|
|
13
|
+
@compile_context = Object.new
|
|
14
|
+
@global_functions = functions.keys.map!(&:to_s)
|
|
15
|
+
@functions_by_name = functions.transform_keys do |signature|
|
|
16
|
+
signature = signature.to_s
|
|
17
|
+
index = signature.index('(')
|
|
18
|
+
if index
|
|
19
|
+
signature.slice(0, index)
|
|
20
|
+
else
|
|
21
|
+
signature
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
@id = 0
|
|
26
|
+
@functions_by_id = {}.compare_by_identity
|
|
27
|
+
@ids_by_function = {}.compare_by_identity
|
|
28
|
+
|
|
29
|
+
@session = session
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def register(function)
|
|
33
|
+
@ids_by_function.fetch(function) do |fn|
|
|
34
|
+
id = @id
|
|
35
|
+
@id = id.next
|
|
36
|
+
|
|
37
|
+
@functions_by_id[id] = fn
|
|
38
|
+
@ids_by_function[fn] = id
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def function_call(function_call_request)
|
|
43
|
+
oneof = function_call_request.identifier
|
|
44
|
+
identifier = function_call_request.public_send(oneof)
|
|
45
|
+
function = case oneof
|
|
46
|
+
when :name
|
|
47
|
+
@functions_by_name[identifier]
|
|
48
|
+
when :function_id
|
|
49
|
+
@functions_by_id[identifier]
|
|
50
|
+
else
|
|
51
|
+
raise ArgumentError, "Unknown FunctionCallRequest.identifier #{identifier}"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
arguments = function_call_request.arguments.map do |argument|
|
|
55
|
+
protofier.from_proto(argument)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
success = protofier.to_proto(function.call(arguments))
|
|
59
|
+
accessed_argument_lists = arguments.filter_map do |argument|
|
|
60
|
+
if argument.is_a?(Sass::Value::ArgumentList) && argument.instance_variable_get(:@keywords_accessed)
|
|
61
|
+
argument.instance_variable_get(:@id)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
EmbeddedProtocol::InboundMessage::FunctionCallResponse.new(
|
|
66
|
+
id: function_call_request.id,
|
|
67
|
+
success:,
|
|
68
|
+
accessed_argument_lists:
|
|
69
|
+
)
|
|
70
|
+
rescue StandardError => e
|
|
71
|
+
@session.backtrace = e.backtrace
|
|
72
|
+
EmbeddedProtocol::InboundMessage::FunctionCallResponse.new(
|
|
73
|
+
id: function_call_request.id,
|
|
74
|
+
error: e.detailed_message(highlight: false)
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
def protofier
|
|
81
|
+
@protofier ||= Protofier.new(self)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
private_constant :FunctionRegistry
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|