sass-embedded 0.13.4 → 0.16.1
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 +4 -4
- data/ext/sass/extconf.rb +52 -1
- data/lib/sass/compile_error.rb +1 -10
- data/lib/sass/compile_result.rb +1 -5
- data/lib/sass/embedded/channel.rb +2 -2
- data/lib/sass/embedded/compile_context/function_registry.rb +83 -0
- data/lib/sass/embedded/compile_context/importer_registry.rb +97 -0
- data/lib/sass/embedded/compile_context.rb +21 -176
- data/lib/sass/embedded/compiler/path.rb +1 -3
- data/lib/sass/embedded/compiler/requirements.rb +1 -1
- data/lib/sass/embedded/compiler.rb +7 -19
- data/lib/sass/embedded/{render.rb → legacy.rb} +79 -3
- data/lib/sass/embedded/observer.rb +2 -0
- data/lib/sass/embedded/protofier.rb +329 -0
- data/lib/sass/embedded/version.rb +1 -1
- data/lib/sass/embedded/version_context.rb +2 -3
- data/lib/sass/embedded.rb +39 -54
- data/lib/sass/embedded_protocol.rb +0 -6
- data/lib/sass/logger/source_location.rb +3 -9
- data/lib/sass/logger/source_span.rb +1 -13
- data/lib/sass/logger.rb +3 -3
- data/lib/sass/script_error.rb +5 -0
- data/lib/sass/value/argument_list.rb +24 -0
- data/lib/sass/value/boolean.rb +42 -0
- data/lib/sass/value/color.rb +213 -0
- data/lib/sass/value/function.rb +35 -0
- data/lib/sass/value/fuzzy_math.rb +81 -0
- data/lib/sass/value/list.rb +60 -0
- data/lib/sass/value/map.rb +57 -0
- data/lib/sass/value/null.rb +39 -0
- data/lib/sass/value/number/unit.rb +186 -0
- data/lib/sass/value/number.rb +272 -0
- data/lib/sass/value/string.rb +43 -0
- data/lib/sass/value.rb +92 -0
- data/lib/sass.rb +47 -48
- metadata +26 -57
- data/lib/sass/embedded/platform.rb +0 -55
- data/lib/sass/embedded/url.rb +0 -36
- data/lib/sass/file_importer.rb +0 -10
- data/lib/sass/importer.rb +0 -14
- data/lib/sass/importer_result.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ecdaedc0510249bc9b8e7da46e0b786a607153db705b5224214d5a2ef407f2a
|
4
|
+
data.tar.gz: 91ea0069f066bad0693367290eee7242f10b2514ba6502b3682bdfccfd3fe9d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1549a6a67863a7d3f3604a3f084fea4721540cbe9ffc9919505b0e71e6eac751eb5e6fa096673234307c6930962cef79ab5ba796c9c9c690fe157a8a3c580857
|
7
|
+
data.tar.gz: d98d4678e005203209feb31d1af90b842aef964dc7771cfd3ebc22a2e7558a9929cb014d750c8b9bfb9b8725c3d9764ac3da93bab0695ea9a46c32879f93ff77
|
data/ext/sass/extconf.rb
CHANGED
@@ -7,10 +7,61 @@ require 'mkmf'
|
|
7
7
|
require 'open-uri'
|
8
8
|
require_relative '../../lib/sass/embedded/compiler/path'
|
9
9
|
require_relative '../../lib/sass/embedded/compiler/requirements'
|
10
|
-
require_relative '../../lib/sass/embedded/platform'
|
11
10
|
|
12
11
|
module Sass
|
13
12
|
class Embedded
|
13
|
+
module Platform
|
14
|
+
OS = case RbConfig::CONFIG['host_os'].downcase
|
15
|
+
when /linux/
|
16
|
+
'linux'
|
17
|
+
when /darwin/
|
18
|
+
'darwin'
|
19
|
+
when /freebsd/
|
20
|
+
'freebsd'
|
21
|
+
when /netbsd/
|
22
|
+
'netbsd'
|
23
|
+
when /openbsd/
|
24
|
+
'openbsd'
|
25
|
+
when /dragonfly/
|
26
|
+
'dragonflybsd'
|
27
|
+
when /sunos|solaris/
|
28
|
+
'solaris'
|
29
|
+
when *Gem::WIN_PATTERNS
|
30
|
+
'windows'
|
31
|
+
else
|
32
|
+
RbConfig::CONFIG['host_os'].downcase
|
33
|
+
end
|
34
|
+
|
35
|
+
OSVERSION = RbConfig::CONFIG['host_os'].gsub(/[^\d]/, '').to_i
|
36
|
+
|
37
|
+
CPU = RbConfig::CONFIG['host_cpu']
|
38
|
+
|
39
|
+
ARCH = case CPU.downcase
|
40
|
+
when /amd64|x86_64|x64/
|
41
|
+
'x86_64'
|
42
|
+
when /i\d86|x86|i86pc/
|
43
|
+
'i386'
|
44
|
+
when /ppc64|powerpc64/
|
45
|
+
'powerpc64'
|
46
|
+
when /ppc|powerpc/
|
47
|
+
'powerpc'
|
48
|
+
when /sparcv9|sparc64/
|
49
|
+
'sparcv9'
|
50
|
+
when /arm64|aarch64/ # MacOS calls it "arm64", other operating systems "aarch64"
|
51
|
+
'aarch64'
|
52
|
+
when /^arm/
|
53
|
+
if OS == 'darwin' # Ruby before 3.0 reports "arm" instead of "arm64" as host_cpu on darwin
|
54
|
+
'aarch64'
|
55
|
+
else
|
56
|
+
'arm'
|
57
|
+
end
|
58
|
+
else
|
59
|
+
RbConfig::CONFIG['host_cpu']
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private_constant :Platform
|
64
|
+
|
14
65
|
# The dependency downloader. This downloads all the dependencies during gem
|
15
66
|
# installation. The companion Makefile then unpacks all downloaded
|
16
67
|
# dependencies. By default it downloads the release of each dependency
|
data/lib/sass/compile_error.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'logger/source_span'
|
4
|
-
|
5
3
|
module Sass
|
6
|
-
#
|
4
|
+
# An exception thrown because a Sass compilation failed.
|
7
5
|
class CompileError < StandardError
|
8
6
|
attr_accessor :sass_message, :sass_stack, :span
|
9
7
|
|
@@ -13,12 +11,5 @@ module Sass
|
|
13
11
|
@sass_stack = sass_stack
|
14
12
|
@span = span
|
15
13
|
end
|
16
|
-
|
17
|
-
def self.from_proto(compile_failure)
|
18
|
-
CompileError.new(compile_failure.formatted,
|
19
|
-
compile_failure.message,
|
20
|
-
compile_failure.stack_trace,
|
21
|
-
Logger::SourceSpan.from_proto(compile_failure.span))
|
22
|
-
end
|
23
14
|
end
|
24
15
|
end
|
data/lib/sass/compile_result.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Sass
|
4
|
-
# The
|
4
|
+
# The result of compiling Sass to CSS. Returned by {Sass.compile} and {Sass.compile_string}.
|
5
5
|
class CompileResult
|
6
6
|
attr_reader :css, :source_map, :loaded_urls
|
7
7
|
|
@@ -10,9 +10,5 @@ module Sass
|
|
10
10
|
@source_map = source_map == '' ? nil : source_map
|
11
11
|
@loaded_urls = loaded_urls
|
12
12
|
end
|
13
|
-
|
14
|
-
def self.from_proto(compile_success)
|
15
|
-
CompileResult.new(compile_success.css, compile_success.source_map, compile_success.loaded_urls)
|
16
|
-
end
|
17
13
|
end
|
18
14
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'compiler'
|
4
|
-
|
5
3
|
module Sass
|
6
4
|
class Embedded
|
7
5
|
# The {Channel} for {Compiler} calls. Each instance creates its own
|
@@ -58,5 +56,7 @@ module Sass
|
|
58
56
|
|
59
57
|
private_constant :Subscription
|
60
58
|
end
|
59
|
+
|
60
|
+
private_constant :Channel
|
61
61
|
end
|
62
62
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
class Embedded
|
5
|
+
class CompileContext
|
6
|
+
# The {FunctionRegistry} for {CompileContext}.
|
7
|
+
class FunctionRegistry
|
8
|
+
attr_reader :global_functions
|
9
|
+
|
10
|
+
def initialize(functions)
|
11
|
+
@global_functions = functions.keys
|
12
|
+
@functions_by_name = functions.transform_keys do |signature|
|
13
|
+
signature = signature.chomp
|
14
|
+
index = signature.index('(')
|
15
|
+
if index
|
16
|
+
signature.slice(0, index)
|
17
|
+
else
|
18
|
+
signature
|
19
|
+
end
|
20
|
+
end
|
21
|
+
@functions_by_id = {}
|
22
|
+
@ids_by_function = {}
|
23
|
+
@id = 0
|
24
|
+
end
|
25
|
+
|
26
|
+
def register(function)
|
27
|
+
return if @ids_by_function.key?(function)
|
28
|
+
|
29
|
+
id = @id
|
30
|
+
@id = @id.next
|
31
|
+
|
32
|
+
@ids_by_function[function] = id
|
33
|
+
@functions_by_id[id] = function
|
34
|
+
|
35
|
+
id
|
36
|
+
end
|
37
|
+
|
38
|
+
def function_call(function_call_request)
|
39
|
+
arguments = function_call_request.arguments.map do |argument|
|
40
|
+
protofier.from_proto_value(argument)
|
41
|
+
end
|
42
|
+
|
43
|
+
success = protofier.to_proto_value(get(function_call_request).call(arguments))
|
44
|
+
accessed_argument_lists = arguments
|
45
|
+
.filter do |argument|
|
46
|
+
argument.is_a?(Sass::Value::ArgumentList) && argument.instance_eval do
|
47
|
+
@keywords_accessed
|
48
|
+
end
|
49
|
+
end
|
50
|
+
.map { |argument| argument.instance_eval { @id } }
|
51
|
+
|
52
|
+
EmbeddedProtocol::InboundMessage::FunctionCallResponse.new(
|
53
|
+
id: function_call_request.id,
|
54
|
+
success: success,
|
55
|
+
accessed_argument_lists: accessed_argument_lists
|
56
|
+
)
|
57
|
+
rescue StandardError => e
|
58
|
+
EmbeddedProtocol::InboundMessage::FunctionCallResponse.new(
|
59
|
+
id: function_call_request.id,
|
60
|
+
error: e.message
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def get(function_call_request)
|
67
|
+
case function_call_request.identifier
|
68
|
+
when :name
|
69
|
+
@functions_by_name[function_call_request.name]
|
70
|
+
when :function_id
|
71
|
+
@functions_by_id[function_call_request.function_id]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def protofier
|
76
|
+
@protofier ||= Protofier.new(self)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
private_constant :FunctionRegistry
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sass
|
4
|
+
class Embedded
|
5
|
+
class CompileContext
|
6
|
+
# The {ImporterRegistry} for {CompileContext}.
|
7
|
+
class ImporterRegistry
|
8
|
+
attr_reader :importers
|
9
|
+
|
10
|
+
def initialize(importers, load_paths)
|
11
|
+
@id = 0
|
12
|
+
@importers_by_id = {}
|
13
|
+
@importers = importers
|
14
|
+
.map { |importer| register(importer) }
|
15
|
+
.concat(load_paths.map do |load_path|
|
16
|
+
EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
|
17
|
+
path: File.absolute_path(load_path)
|
18
|
+
)
|
19
|
+
end)
|
20
|
+
end
|
21
|
+
|
22
|
+
def register(importer)
|
23
|
+
is_importer = importer.respond_to?(:canonicalize) && importer.respond_to?(:load)
|
24
|
+
is_file_importer = importer.respond_to?(:find_file_url)
|
25
|
+
|
26
|
+
raise ArgumentError, 'importer must be an Importer or a FileImporter' if is_importer == is_file_importer
|
27
|
+
|
28
|
+
proto = if is_importer
|
29
|
+
EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
|
30
|
+
importer_id: @id
|
31
|
+
)
|
32
|
+
else
|
33
|
+
EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
|
34
|
+
file_importer_id: @id
|
35
|
+
)
|
36
|
+
end
|
37
|
+
@importers_by_id[@id] = importer
|
38
|
+
@id = @id.next
|
39
|
+
proto
|
40
|
+
end
|
41
|
+
|
42
|
+
def canonicalize(canonicalize_request)
|
43
|
+
importer = @importers_by_id[canonicalize_request.importer_id]
|
44
|
+
url = importer.canonicalize(canonicalize_request.url, from_import: canonicalize_request.from_import)&.to_s
|
45
|
+
|
46
|
+
EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
|
47
|
+
id: canonicalize_request.id,
|
48
|
+
url: url
|
49
|
+
)
|
50
|
+
rescue StandardError => e
|
51
|
+
EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
|
52
|
+
id: canonicalize_request.id,
|
53
|
+
error: e.message
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def import(import_request)
|
58
|
+
importer = @importers_by_id[import_request.importer_id]
|
59
|
+
importer_result = Protofier.to_struct importer.load(import_request.url)
|
60
|
+
|
61
|
+
EmbeddedProtocol::InboundMessage::ImportResponse.new(
|
62
|
+
id: import_request.id,
|
63
|
+
success: EmbeddedProtocol::InboundMessage::ImportResponse::ImportSuccess.new(
|
64
|
+
contents: importer_result.contents,
|
65
|
+
syntax: Protofier.to_proto_syntax(importer_result.syntax),
|
66
|
+
source_map_url: importer_result.respond_to?(:source_map_url) ? importer_result.source_map_url&.to_s : nil
|
67
|
+
)
|
68
|
+
)
|
69
|
+
rescue StandardError => e
|
70
|
+
EmbeddedProtocol::InboundMessage::ImportResponse.new(
|
71
|
+
id: import_request.id,
|
72
|
+
error: e.message
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
def file_import(file_import_request)
|
77
|
+
importer = @importers_by_id[file_import_request.importer_id]
|
78
|
+
file_url = importer.find_file_url(file_import_request.url, from_import: file_import_request.from_import)&.to_s
|
79
|
+
|
80
|
+
raise "file_url must be a file: URL, was \"#{file_url}\"" if !file_url.nil? && !file_url.start_with?('file:')
|
81
|
+
|
82
|
+
EmbeddedProtocol::InboundMessage::FileImportResponse.new(
|
83
|
+
id: file_import_request.id,
|
84
|
+
file_url: file_url
|
85
|
+
)
|
86
|
+
rescue StandardError => e
|
87
|
+
EmbeddedProtocol::InboundMessage::FileImportResponse.new(
|
88
|
+
id: file_import_request.id,
|
89
|
+
error: e.message
|
90
|
+
)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
private_constant :ImporterRegistry
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -1,9 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '../embedded_protocol'
|
4
|
-
require_relative '../logger/source_span'
|
5
|
-
require_relative 'observer'
|
6
|
-
|
7
3
|
module Sass
|
8
4
|
class Embedded
|
9
5
|
# The {Observer} for {Embedded#compile}.
|
@@ -34,7 +30,6 @@ module Sass
|
|
34
30
|
@path = path
|
35
31
|
@source = source
|
36
32
|
|
37
|
-
@importer = to_struct(importer)
|
38
33
|
@load_paths = load_paths
|
39
34
|
@syntax = syntax
|
40
35
|
@url = url
|
@@ -43,19 +38,16 @@ module Sass
|
|
43
38
|
@source_map_include_sources = source_map_include_sources
|
44
39
|
@style = style
|
45
40
|
|
46
|
-
@
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
@importers = importers.map do |obj|
|
52
|
-
to_struct(obj)
|
53
|
-
end
|
41
|
+
@function_registery = FunctionRegistry.new(functions.transform_keys(&:to_s))
|
42
|
+
@importer_registery = ImporterRegistry.new(importers.map do |obj|
|
43
|
+
Protofier.to_struct(obj)
|
44
|
+
end, load_paths)
|
45
|
+
@importer = importer.nil? ? nil : @importer_registery.register(Protofier.to_struct(importer))
|
54
46
|
|
55
47
|
@alert_ascii = alert_ascii
|
56
48
|
@alert_color = alert_color
|
57
49
|
|
58
|
-
@logger = to_struct(logger)
|
50
|
+
@logger = Protofier.to_struct(logger)
|
59
51
|
|
60
52
|
@quiet_deps = quiet_deps
|
61
53
|
@verbose = verbose
|
@@ -83,25 +75,25 @@ module Sass
|
|
83
75
|
return unless message.compilation_id == id
|
84
76
|
|
85
77
|
Thread.new do
|
86
|
-
send_message
|
78
|
+
send_message @importer_registery.canonicalize message
|
87
79
|
end
|
88
80
|
when EmbeddedProtocol::OutboundMessage::ImportRequest
|
89
81
|
return unless message.compilation_id == id
|
90
82
|
|
91
83
|
Thread.new do
|
92
|
-
send_message
|
84
|
+
send_message @importer_registery.import message
|
93
85
|
end
|
94
86
|
when EmbeddedProtocol::OutboundMessage::FileImportRequest
|
95
87
|
return unless message.compilation_id == id
|
96
88
|
|
97
89
|
Thread.new do
|
98
|
-
send_message
|
90
|
+
send_message @importer_registery.file_import message
|
99
91
|
end
|
100
92
|
when EmbeddedProtocol::OutboundMessage::FunctionCallRequest
|
101
93
|
return unless message.compilation_id == id
|
102
94
|
|
103
95
|
Thread.new do
|
104
|
-
send_message
|
96
|
+
send_message @function_registery.function_call message
|
105
97
|
end
|
106
98
|
end
|
107
99
|
rescue StandardError => e
|
@@ -116,14 +108,14 @@ module Sass
|
|
116
108
|
case event.type
|
117
109
|
when :DEBUG
|
118
110
|
if @logger.respond_to? :debug
|
119
|
-
@logger.debug(event.message, span:
|
111
|
+
@logger.debug(event.message, span: Protofier.from_proto_source_span(event.span))
|
120
112
|
else
|
121
113
|
Kernel.warn(event.formatted)
|
122
114
|
end
|
123
115
|
when :DEPRECATION_WARNING
|
124
116
|
if @logger.respond_to? :warn
|
125
117
|
@logger.warn(event.message, deprecation: true,
|
126
|
-
span:
|
118
|
+
span: Protofier.from_proto_source_span(event.span),
|
127
119
|
stack: event.stack_trace)
|
128
120
|
else
|
129
121
|
Kernel.warn(event.formatted)
|
@@ -131,7 +123,7 @@ module Sass
|
|
131
123
|
when :WARNING
|
132
124
|
if @logger.respond_to? :warn
|
133
125
|
@logger.warn(event.message, deprecation: false,
|
134
|
-
span:
|
126
|
+
span: Protofier.from_proto_source_span(event.span),
|
135
127
|
stack: event.stack_trace)
|
136
128
|
else
|
137
129
|
Kernel.warn(event.formatted)
|
@@ -145,170 +137,23 @@ module Sass
|
|
145
137
|
string: unless @source.nil?
|
146
138
|
EmbeddedProtocol::InboundMessage::CompileRequest::StringInput.new(
|
147
139
|
source: @source,
|
148
|
-
url: @url,
|
149
|
-
syntax: to_proto_syntax(@syntax),
|
150
|
-
importer: @importer
|
140
|
+
url: @url&.to_s,
|
141
|
+
syntax: Protofier.to_proto_syntax(@syntax),
|
142
|
+
importer: @importer
|
151
143
|
)
|
152
144
|
end,
|
153
145
|
path: @path,
|
154
|
-
style: to_proto_output_style(@style),
|
146
|
+
style: Protofier.to_proto_output_style(@style),
|
155
147
|
source_map: @source_map,
|
156
148
|
source_map_include_sources: @source_map_include_sources,
|
157
|
-
importers:
|
158
|
-
global_functions: @global_functions,
|
149
|
+
importers: @importer_registery.importers,
|
150
|
+
global_functions: @function_registery.global_functions,
|
159
151
|
alert_ascii: @alert_ascii,
|
160
152
|
alert_color: @alert_color
|
161
153
|
)
|
162
154
|
end
|
163
|
-
|
164
|
-
def canonicalize_response(canonicalize_request)
|
165
|
-
importer = importer_of_id canonicalize_request.importer_id
|
166
|
-
url = importer.canonicalize canonicalize_request.url,
|
167
|
-
from_import: canonicalize_request.from_import
|
168
|
-
|
169
|
-
EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
|
170
|
-
id: canonicalize_request.id,
|
171
|
-
url: url
|
172
|
-
)
|
173
|
-
rescue StandardError => e
|
174
|
-
EmbeddedProtocol::InboundMessage::CanonicalizeResponse.new(
|
175
|
-
id: canonicalize_request.id,
|
176
|
-
error: e.message
|
177
|
-
)
|
178
|
-
end
|
179
|
-
|
180
|
-
def import_response(import_request)
|
181
|
-
importer = importer_of_id import_request.importer_id
|
182
|
-
importer_result = to_struct importer.load(import_request.url)
|
183
|
-
|
184
|
-
EmbeddedProtocol::InboundMessage::ImportResponse.new(
|
185
|
-
id: import_request.id,
|
186
|
-
success: EmbeddedProtocol::InboundMessage::ImportResponse::ImportSuccess.new(
|
187
|
-
contents: importer_result.contents,
|
188
|
-
syntax: to_proto_syntax(importer_result.syntax),
|
189
|
-
source_map_url: importer_result.respond_to?(:source_map_url) ? importer_result.source_map_url : nil
|
190
|
-
)
|
191
|
-
)
|
192
|
-
rescue StandardError => e
|
193
|
-
EmbeddedProtocol::InboundMessage::ImportResponse.new(
|
194
|
-
id: import_request.id,
|
195
|
-
error: e.message
|
196
|
-
)
|
197
|
-
end
|
198
|
-
|
199
|
-
def file_import_response(file_import_request)
|
200
|
-
importer = importer_of_id file_import_request.importer_id
|
201
|
-
file_url = importer.find_file_url file_import_request.url,
|
202
|
-
from_import: file_import_request.from_import
|
203
|
-
|
204
|
-
raise "file_url must be a file: URL, was \"#{file_url}\"" if !file_url.nil? && !file_url.start_with?('file:')
|
205
|
-
|
206
|
-
EmbeddedProtocol::InboundMessage::FileImportResponse.new(
|
207
|
-
id: file_import_request.id,
|
208
|
-
file_url: file_url
|
209
|
-
)
|
210
|
-
rescue StandardError => e
|
211
|
-
EmbeddedProtocol::InboundMessage::FileImportResponse.new(
|
212
|
-
id: file_import_request.id,
|
213
|
-
error: e.message
|
214
|
-
)
|
215
|
-
end
|
216
|
-
|
217
|
-
def function_call_response(function_call_request)
|
218
|
-
EmbeddedProtocol::InboundMessage::FunctionCallResponse.new(
|
219
|
-
id: function_call_request.id,
|
220
|
-
success: @functions[function_call_request.name].call(*function_call_request.arguments),
|
221
|
-
accessed_argument_lists: function_call_request.arguments
|
222
|
-
.filter { |argument| argument.value == :argument_list }
|
223
|
-
.map { |argument| argument.argument_list.id }
|
224
|
-
)
|
225
|
-
rescue StandardError => e
|
226
|
-
EmbeddedProtocol::InboundMessage::FunctionCallResponse.new(
|
227
|
-
id: function_call_request.id,
|
228
|
-
error: e.message
|
229
|
-
)
|
230
|
-
end
|
231
|
-
|
232
|
-
def to_proto_syntax(syntax)
|
233
|
-
case syntax&.to_sym
|
234
|
-
when :scss
|
235
|
-
EmbeddedProtocol::Syntax::SCSS
|
236
|
-
when :indented
|
237
|
-
EmbeddedProtocol::Syntax::INDENTED
|
238
|
-
when :css
|
239
|
-
EmbeddedProtocol::Syntax::CSS
|
240
|
-
else
|
241
|
-
raise ArgumentError, 'syntax must be one of :scss, :indented, :css'
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
def to_proto_output_style(style)
|
246
|
-
case style&.to_sym
|
247
|
-
when :expanded
|
248
|
-
EmbeddedProtocol::OutputStyle::EXPANDED
|
249
|
-
when :compressed
|
250
|
-
EmbeddedProtocol::OutputStyle::COMPRESSED
|
251
|
-
else
|
252
|
-
raise ArgumentError, 'style must be one of :expanded, :compressed'
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
def to_proto_importer(importer, id)
|
257
|
-
is_importer = importer.respond_to?(:canonicalize) && importer.respond_to?(:load)
|
258
|
-
is_file_importer = importer.respond_to?(:find_file_url)
|
259
|
-
|
260
|
-
if is_importer && !is_file_importer
|
261
|
-
EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
|
262
|
-
importer_id: id
|
263
|
-
)
|
264
|
-
elsif is_file_importer && !is_importer
|
265
|
-
EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
|
266
|
-
file_importer_id: id
|
267
|
-
)
|
268
|
-
else
|
269
|
-
raise ArgumentError, 'importer must be an Importer or a FileImporter'
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
def to_proto_importers(importers, load_paths)
|
274
|
-
proto_importers = importers.map.with_index do |importer, id|
|
275
|
-
to_proto_importer(importer, id)
|
276
|
-
end
|
277
|
-
|
278
|
-
load_paths.each do |load_path|
|
279
|
-
proto_importers << EmbeddedProtocol::InboundMessage::CompileRequest::Importer.new(
|
280
|
-
path: File.absolute_path(load_path)
|
281
|
-
)
|
282
|
-
end
|
283
|
-
|
284
|
-
proto_importers
|
285
|
-
end
|
286
|
-
|
287
|
-
def importer_of_id(id)
|
288
|
-
if id == @importers.length
|
289
|
-
@importer
|
290
|
-
else
|
291
|
-
@importers[id]
|
292
|
-
end
|
293
|
-
end
|
294
|
-
|
295
|
-
def to_struct(obj)
|
296
|
-
return obj unless obj.is_a? Hash
|
297
|
-
|
298
|
-
struct = Object.new
|
299
|
-
obj.each do |key, value|
|
300
|
-
if value.respond_to? :call
|
301
|
-
struct.define_singleton_method key.to_sym do |*args, **kwargs|
|
302
|
-
value.call(*args, **kwargs)
|
303
|
-
end
|
304
|
-
else
|
305
|
-
struct.define_singleton_method key.to_sym do
|
306
|
-
value
|
307
|
-
end
|
308
|
-
end
|
309
|
-
end
|
310
|
-
struct
|
311
|
-
end
|
312
155
|
end
|
156
|
+
|
157
|
+
private_constant :CompileContext
|
313
158
|
end
|
314
159
|
end
|
@@ -1,12 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '../platform'
|
4
|
-
|
5
3
|
module Sass
|
6
4
|
class Embedded
|
7
5
|
class Compiler
|
8
6
|
PATH = File.absolute_path(
|
9
|
-
"../../../../ext/sass/sass_embedded/dart-sass-embedded#{
|
7
|
+
"../../../../ext/sass/sass_embedded/dart-sass-embedded#{Gem.win_platform? ? '.bat' : ''}", __dir__
|
10
8
|
)
|
11
9
|
end
|
12
10
|
end
|
@@ -2,9 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'observer'
|
4
4
|
require 'open3'
|
5
|
-
require_relative '../embedded_protocol'
|
6
|
-
require_relative 'compiler/path'
|
7
|
-
require_relative 'protocol_error'
|
8
5
|
|
9
6
|
module Sass
|
10
7
|
class Embedded
|
@@ -14,14 +11,7 @@ module Sass
|
|
14
11
|
class Compiler
|
15
12
|
include Observable
|
16
13
|
|
17
|
-
|
18
|
-
.descriptor
|
19
|
-
.lookup_oneof('message')
|
20
|
-
.to_h do |field_descriptor|
|
21
|
-
[field_descriptor.subtype, field_descriptor.name]
|
22
|
-
end
|
23
|
-
|
24
|
-
private_constant :ONEOF_MESSAGE
|
14
|
+
PROTOCOL_ERROR_ID = 4_294_967_295
|
25
15
|
|
26
16
|
def initialize
|
27
17
|
@observerable_mutex = Mutex.new
|
@@ -35,7 +25,7 @@ module Sass
|
|
35
25
|
warn(@stderr.readline, uplevel: 1)
|
36
26
|
end
|
37
27
|
poll do
|
38
|
-
|
28
|
+
receive_message Protofier.from_proto_message read
|
39
29
|
end
|
40
30
|
end
|
41
31
|
|
@@ -60,9 +50,7 @@ module Sass
|
|
60
50
|
end
|
61
51
|
|
62
52
|
def send_message(message)
|
63
|
-
write
|
64
|
-
ONEOF_MESSAGE[message.class.descriptor] => message
|
65
|
-
).to_proto
|
53
|
+
write Protofier.to_proto_message message
|
66
54
|
end
|
67
55
|
|
68
56
|
def close
|
@@ -86,7 +74,7 @@ module Sass
|
|
86
74
|
private
|
87
75
|
|
88
76
|
def half_closed?
|
89
|
-
@id ==
|
77
|
+
@id == PROTOCOL_ERROR_ID
|
90
78
|
end
|
91
79
|
|
92
80
|
def poll
|
@@ -108,9 +96,7 @@ module Sass
|
|
108
96
|
end
|
109
97
|
end
|
110
98
|
|
111
|
-
def
|
112
|
-
payload = EmbeddedProtocol::OutboundMessage.decode(proto)
|
113
|
-
message = payload[payload.message.to_s]
|
99
|
+
def receive_message(message)
|
114
100
|
case message
|
115
101
|
when EmbeddedProtocol::ProtocolError
|
116
102
|
raise ProtocolError, message.message
|
@@ -152,5 +138,7 @@ module Sass
|
|
152
138
|
writeable.write bytes.pack('C*')
|
153
139
|
end
|
154
140
|
end
|
141
|
+
|
142
|
+
private_constant :Compiler
|
155
143
|
end
|
156
144
|
end
|