sass-embedded 1.69.4-aarch64-linux-gnu → 1.69.6-aarch64-linux-gnu

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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/exe/sass +2 -2
  4. data/ext/sass/dart-sass/src/LICENSE +32 -0
  5. data/ext/sass/dart-sass/src/dart +0 -0
  6. data/ext/sass/dart-sass/src/sass.snapshot +0 -0
  7. data/ext/sass/embedded_sass_pb.rb +1 -1
  8. data/lib/sass/compiler/connection.rb +92 -0
  9. data/lib/sass/{embedded → compiler}/dispatcher.rb +31 -10
  10. data/lib/sass/{embedded → compiler}/host/function_registry.rb +3 -3
  11. data/lib/sass/{embedded → compiler}/host/importer_registry.rb +3 -3
  12. data/lib/sass/{embedded → compiler}/host/logger_registry.rb +1 -1
  13. data/lib/sass/{embedded → compiler}/host/protofier.rb +1 -1
  14. data/lib/sass/{embedded → compiler}/host/structifier.rb +3 -3
  15. data/lib/sass/{embedded → compiler}/host/value_protofier.rb +1 -1
  16. data/lib/sass/{embedded → compiler}/host.rb +15 -13
  17. data/lib/sass/{embedded → compiler}/resilient_dispatcher.rb +5 -4
  18. data/lib/sass/{embedded → compiler}/varint.rb +1 -1
  19. data/lib/sass/compiler.rb +188 -0
  20. data/lib/sass/embedded/version.rb +2 -2
  21. data/lib/sass/embedded.rb +65 -205
  22. data/lib/sass/exception.rb +65 -0
  23. data/lib/sass/fork_tracker.rb +51 -0
  24. data/lib/sass/serializer.rb +73 -0
  25. data/lib/sass/value/argument_list.rb +1 -1
  26. data/lib/sass/value/color.rb +6 -6
  27. data/lib/sass/value/function.rb +1 -1
  28. data/lib/sass/value/map.rb +1 -1
  29. data/lib/sass/value/number.rb +11 -11
  30. data/lib/sass/value.rb +0 -1
  31. metadata +25 -23
  32. data/lib/sass/compile_error.rb +0 -31
  33. data/lib/sass/embedded/connection.rb +0 -68
  34. data/lib/sass/script_error.rb +0 -10
@@ -0,0 +1,188 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'canonicalize_context'
4
+ require_relative 'compile_result'
5
+ require_relative 'compiler/connection'
6
+ require_relative 'compiler/dispatcher'
7
+ require_relative 'compiler/host'
8
+ require_relative 'compiler/resilient_dispatcher'
9
+ require_relative 'compiler/varint'
10
+ require_relative 'embedded_protocol'
11
+ require_relative 'exception'
12
+ require_relative 'fork_tracker'
13
+ require_relative 'logger/silent'
14
+ require_relative 'logger/source_location'
15
+ require_relative 'logger/source_span'
16
+ require_relative 'serializer'
17
+ require_relative 'value'
18
+
19
+ module Sass
20
+ # The {Compiler} for using dart-sass. Each instance creates its own
21
+ # communication {Dispatcher} with a dedicated compiler process.
22
+ #
23
+ # @example
24
+ # sass = Sass::Compiler.new
25
+ # result = sass.compile_string('h1 { font-size: 40px; }')
26
+ # result = sass.compile('style.scss')
27
+ # sass.close
28
+ class Compiler
29
+ def initialize
30
+ @dispatcher = ResilientDispatcher.new(Dispatcher)
31
+ end
32
+
33
+ # Compiles the Sass file at +path+ to CSS.
34
+ # @param path [String]
35
+ # @param load_paths [Array<String>] Paths in which to look for stylesheets loaded by rules like
36
+ # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
37
+ # @param charset [Boolean] By default, if the CSS document contains non-ASCII characters, Sass adds a +@charset+
38
+ # declaration (in expanded output mode) or a byte-order mark (in compressed mode) to indicate its encoding to
39
+ # browsers or other consumers. If +charset+ is +false+, these annotations are omitted.
40
+ # @param source_map [Boolean] Whether or not Sass should generate a source map.
41
+ # @param source_map_include_sources [Boolean] Whether Sass should include the sources in the generated source map.
42
+ # @param style [String, Symbol] The OutputStyle of the compiled CSS.
43
+ # @param functions [Hash<String, Proc>] Additional built-in Sass functions that are available in all stylesheets.
44
+ # @param importers [Array<Object>] Custom importers that control how Sass resolves loads from rules like
45
+ # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
46
+ # @param alert_ascii [Boolean] If this is +true+, the compiler will exclusively use ASCII characters in its error
47
+ # and warning messages. Otherwise, it may use non-ASCII Unicode characters as well.
48
+ # @param alert_color [Boolean] If this is +true+, the compiler will use ANSI color escape codes in its error and
49
+ # warning messages. If it's +false+, it won't use these. If it's +nil+, the compiler will determine whether or
50
+ # not to use colors depending on whether the user is using an interactive terminal.
51
+ # @param logger [Object] An object to use to handle warnings and/or debug messages from Sass.
52
+ # @param quiet_deps [Boolean] If this option is set to +true+, Sass won’t print warnings that are caused by
53
+ # dependencies. A “dependency” is defined as any file that’s loaded through +load_paths+ or +importer+.
54
+ # Stylesheets that are imported relative to the entrypoint are not considered dependencies.
55
+ # @param verbose [Boolean] By default, Dart Sass will print only five instances of the same deprecation warning per
56
+ # compilation to avoid deluging users in console noise. If you set verbose to +true+, it will instead print every
57
+ # deprecation warning it encounters.
58
+ # @return [CompileResult]
59
+ # @raise [ArgumentError, CompileError]
60
+ # @see https://sass-lang.com/documentation/js-api/functions/compile/
61
+ def compile(path,
62
+ load_paths: [],
63
+
64
+ charset: true,
65
+ source_map: false,
66
+ source_map_include_sources: false,
67
+ style: :expanded,
68
+
69
+ functions: {},
70
+ importers: [],
71
+
72
+ alert_ascii: false,
73
+ alert_color: nil,
74
+ logger: nil,
75
+ quiet_deps: false,
76
+ verbose: false)
77
+ raise ArgumentError, 'path must be set' if path.nil?
78
+
79
+ Host.new(@dispatcher).compile_request(
80
+ path:,
81
+ source: nil,
82
+ importer: nil,
83
+ load_paths:,
84
+ syntax: nil,
85
+ url: nil,
86
+ charset:,
87
+ source_map:,
88
+ source_map_include_sources:,
89
+ style:,
90
+ functions:,
91
+ importers:,
92
+ alert_color:,
93
+ alert_ascii:,
94
+ logger:,
95
+ quiet_deps:,
96
+ verbose:
97
+ )
98
+ end
99
+
100
+ # Compiles a stylesheet whose contents is +source+ to CSS.
101
+ # @param source [String]
102
+ # @param importer [Object] The importer to use to handle loads that are relative to the entrypoint stylesheet.
103
+ # @param load_paths [Array<String>] Paths in which to look for stylesheets loaded by rules like
104
+ # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
105
+ # @param syntax [String, Symbol] The Syntax to use to parse the entrypoint stylesheet.
106
+ # @param url [String] The canonical URL of the entrypoint stylesheet. If this is passed along with +importer+, it's
107
+ # used to resolve relative loads in the entrypoint stylesheet.
108
+ # @param charset [Boolean] By default, if the CSS document contains non-ASCII characters, Sass adds a +@charset+
109
+ # declaration (in expanded output mode) or a byte-order mark (in compressed mode) to indicate its encoding to
110
+ # browsers or other consumers. If +charset+ is +false+, these annotations are omitted.
111
+ # @param source_map [Boolean] Whether or not Sass should generate a source map.
112
+ # @param source_map_include_sources [Boolean] Whether Sass should include the sources in the generated source map.
113
+ # @param style [String, Symbol] The OutputStyle of the compiled CSS.
114
+ # @param functions [Hash<String, Proc>] Additional built-in Sass functions that are available in all stylesheets.
115
+ # @param importers [Array<Object>] Custom importers that control how Sass resolves loads from rules like
116
+ # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
117
+ # @param alert_ascii [Boolean] If this is +true+, the compiler will exclusively use ASCII characters in its error
118
+ # and warning messages. Otherwise, it may use non-ASCII Unicode characters as well.
119
+ # @param alert_color [Boolean] If this is +true+, the compiler will use ANSI color escape codes in its error and
120
+ # warning messages. If it's +false+, it won't use these. If it's +nil+, the compiler will determine whether or
121
+ # not to use colors depending on whether the user is using an interactive terminal.
122
+ # @param logger [Object] An object to use to handle warnings and/or debug messages from Sass.
123
+ # @param quiet_deps [Boolean] If this option is set to +true+, Sass won’t print warnings that are caused by
124
+ # dependencies. A “dependency” is defined as any file that’s loaded through +load_paths+ or +importer+.
125
+ # Stylesheets that are imported relative to the entrypoint are not considered dependencies.
126
+ # @param verbose [Boolean] By default, Dart Sass will print only five instances of the same deprecation warning per
127
+ # compilation to avoid deluging users in console noise. If you set verbose to +true+, it will instead print every
128
+ # deprecation warning it encounters.
129
+ # @return [CompileResult]
130
+ # @raise [ArgumentError, CompileError]
131
+ # @see https://sass-lang.com/documentation/js-api/functions/compilestring/
132
+ def compile_string(source,
133
+ importer: nil,
134
+ load_paths: [],
135
+ syntax: :scss,
136
+ url: nil,
137
+
138
+ charset: true,
139
+ source_map: false,
140
+ source_map_include_sources: false,
141
+ style: :expanded,
142
+
143
+ functions: {},
144
+ importers: [],
145
+
146
+ alert_ascii: false,
147
+ alert_color: nil,
148
+ logger: nil,
149
+ quiet_deps: false,
150
+ verbose: false)
151
+ raise ArgumentError, 'source must be set' if source.nil?
152
+
153
+ Host.new(@dispatcher).compile_request(
154
+ path: nil,
155
+ source:,
156
+ importer:,
157
+ load_paths:,
158
+ syntax:,
159
+ url:,
160
+ charset:,
161
+ source_map:,
162
+ source_map_include_sources:,
163
+ style:,
164
+ functions:,
165
+ importers:,
166
+ alert_color:,
167
+ alert_ascii:,
168
+ logger:,
169
+ quiet_deps:,
170
+ verbose:
171
+ )
172
+ end
173
+
174
+ # @return [String] Information about the Sass implementation.
175
+ # @see https://sass-lang.com/documentation/js-api/variables/info/
176
+ def info
177
+ @info ||= Host.new(@dispatcher).version_request
178
+ end
179
+
180
+ def close
181
+ @dispatcher.close
182
+ end
183
+
184
+ def closed?
185
+ @dispatcher.closed?
186
+ end
187
+ end
188
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sass
4
- class Embedded
5
- VERSION = '1.69.4'
4
+ module Embedded
5
+ VERSION = '1.69.6'
6
6
  end
7
7
  end
data/lib/sass/embedded.rb CHANGED
@@ -1,19 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'canonicalize_context'
4
- require_relative 'compile_error'
5
- require_relative 'compile_result'
6
- require_relative 'embedded/connection'
7
- require_relative 'embedded/dispatcher'
8
- require_relative 'embedded/host'
9
- require_relative 'embedded/resilient_dispatcher'
10
- require_relative 'embedded/varint'
3
+ require_relative 'compiler'
11
4
  require_relative 'embedded/version'
12
- require_relative 'embedded_protocol'
13
- require_relative 'logger/silent'
14
- require_relative 'logger/source_location'
15
- require_relative 'logger/source_span'
16
- require_relative 'value'
17
5
 
18
6
  # The Sass module.
19
7
  #
@@ -25,224 +13,96 @@ require_relative 'value'
25
13
  # @example
26
14
  # Sass.compile_string('h1 { font-size: 40px; }')
27
15
  module Sass
28
- @instance = nil
16
+ @compiler = nil
29
17
  @mutex = Mutex.new
30
18
 
31
19
  # rubocop:disable Layout/LineLength
32
20
  class << self
33
21
  # Compiles the Sass file at +path+ to CSS.
34
22
  # @overload compile(path, load_paths: [], charset: true, source_map: false, source_map_include_sources: false, style: :expanded, functions: {}, importers: [], alert_ascii: false, alert_color: nil, logger: nil, quiet_deps: false, verbose: false)
35
- # @param (see Embedded#compile)
36
- # @return (see Embedded#compile)
37
- # @raise (see Embedded#compile)
38
- # @see Embedded#compile
23
+ # @param (see Compiler#compile)
24
+ # @return (see Compiler#compile)
25
+ # @raise (see Compiler#compile)
26
+ # @see Compiler#compile
39
27
  def compile(...)
40
- instance.compile(...)
28
+ compiler.compile(...)
41
29
  end
42
30
 
43
31
  # Compiles a stylesheet whose contents is +source+ to CSS.
44
32
  # @overload compile_string(source, importer: nil, load_paths: [], syntax: :scss, url: nil, charset: true, source_map: false, source_map_include_sources: false, style: :expanded, functions: {}, importers: [], alert_ascii: false, alert_color: nil, logger: nil, quiet_deps: false, verbose: false)
45
- # @param (see Embedded#compile_string)
46
- # @return (see Embedded#compile_string)
47
- # @raise (see Embedded#compile_string)
48
- # @see Embedded#compile_string
33
+ # @param (see Compiler#compile_string)
34
+ # @return (see Compiler#compile_string)
35
+ # @raise (see Compiler#compile_string)
36
+ # @see Compiler#compile_string
49
37
  def compile_string(...)
50
- instance.compile_string(...)
38
+ compiler.compile_string(...)
51
39
  end
52
40
 
53
- # @param (see Embedded#info)
54
- # @return (see Embedded#info)
55
- # @raise (see Embedded#info)
56
- # @see Embedded#info
41
+ # @param (see Compiler#info)
42
+ # @return (see Compiler#info)
43
+ # @raise (see Compiler#info)
44
+ # @see Compiler#info
57
45
  def info
58
- instance.info
46
+ compiler.info
59
47
  end
60
48
 
61
49
  private
62
50
 
63
- def instance
64
- return @instance if @instance
51
+ def compiler
52
+ return @compiler if @compiler
65
53
 
66
54
  @mutex.synchronize do
67
- return @instance if @instance
55
+ return @compiler if @compiler
56
+
57
+ compiler = Class.new(Compiler) do
58
+ def initialize
59
+ @dispatcher = Compiler.const_get(:ResilientDispatcher).new(Class.new(Compiler.const_get(:Dispatcher)) do
60
+ def initialize
61
+ super
62
+
63
+ idle_timeout = 10
64
+ @last_accessed_time = current_time
65
+
66
+ Thread.new do
67
+ Thread.current.name = 'sass-embedded-process-reaper'
68
+ duration = idle_timeout
69
+ loop do
70
+ sleep(duration.negative? ? idle_timeout : duration)
71
+ break if @mutex.synchronize do
72
+ raise Errno::EBUSY if _closed?
73
+
74
+ duration = idle_timeout - (current_time - @last_accessed_time)
75
+ duration.negative? && _idle? && _close
76
+ end
77
+ end
78
+ close
79
+ rescue Errno::EBUSY
80
+ # do nothing
81
+ end
82
+ end
83
+
84
+ private
85
+
86
+ def _idle
87
+ super
88
+
89
+ @last_accessed_time = current_time
90
+ end
91
+
92
+ def current_time
93
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
94
+ end
95
+ end)
96
+ end
97
+ end.new
68
98
 
69
- @instance = Embedded.new
70
99
  at_exit do
71
- @instance.close
100
+ compiler.close
72
101
  end
73
- end
74
102
 
75
- @instance
103
+ @compiler = compiler
104
+ end
76
105
  end
77
106
  end
78
107
  # rubocop:enable Layout/LineLength
79
-
80
- # The {Embedded} host for using dart-sass. Each instance creates its own
81
- # communication {Dispatcher} with a dedicated compiler process.
82
- #
83
- # @example
84
- # embedded = Sass::Embedded.new
85
- # result = embedded.compile_string('h1 { font-size: 40px; }')
86
- # result = embedded.compile('style.scss')
87
- # embedded.close
88
- class Embedded
89
- def initialize
90
- @dispatcher = ResilientDispatcher.new
91
- end
92
-
93
- # Compiles the Sass file at +path+ to CSS.
94
- # @param path [String]
95
- # @param load_paths [Array<String>] Paths in which to look for stylesheets loaded by rules like
96
- # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
97
- # @param charset [Boolean] By default, if the CSS document contains non-ASCII characters, Sass adds a +@charset+
98
- # declaration (in expanded output mode) or a byte-order mark (in compressed mode) to indicate its encoding to
99
- # browsers or other consumers. If +charset+ is +false+, these annotations are omitted.
100
- # @param source_map [Boolean] Whether or not Sass should generate a source map.
101
- # @param source_map_include_sources [Boolean] Whether Sass should include the sources in the generated source map.
102
- # @param style [String, Symbol] The OutputStyle of the compiled CSS.
103
- # @param functions [Hash<String, Proc>] Additional built-in Sass functions that are available in all stylesheets.
104
- # @param importers [Array<Object>] Custom importers that control how Sass resolves loads from rules like
105
- # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
106
- # @param alert_ascii [Boolean] If this is +true+, the compiler will exclusively use ASCII characters in its error
107
- # and warning messages. Otherwise, it may use non-ASCII Unicode characters as well.
108
- # @param alert_color [Boolean] If this is +true+, the compiler will use ANSI color escape codes in its error and
109
- # warning messages. If it's +false+, it won't use these. If it's +nil+, the compiler will determine whether or
110
- # not to use colors depending on whether the user is using an interactive terminal.
111
- # @param logger [Object] An object to use to handle warnings and/or debug messages from Sass.
112
- # @param quiet_deps [Boolean] If this option is set to +true+, Sass won’t print warnings that are caused by
113
- # dependencies. A “dependency” is defined as any file that’s loaded through +load_paths+ or +importer+.
114
- # Stylesheets that are imported relative to the entrypoint are not considered dependencies.
115
- # @param verbose [Boolean] By default, Dart Sass will print only five instances of the same deprecation warning per
116
- # compilation to avoid deluging users in console noise. If you set verbose to +true+, it will instead print every
117
- # deprecation warning it encounters.
118
- # @return [CompileResult]
119
- # @raise [ArgumentError, CompileError]
120
- # @see https://sass-lang.com/documentation/js-api/functions/compile/
121
- def compile(path,
122
- load_paths: [],
123
-
124
- charset: true,
125
- source_map: false,
126
- source_map_include_sources: false,
127
- style: :expanded,
128
-
129
- functions: {},
130
- importers: [],
131
-
132
- alert_ascii: false,
133
- alert_color: nil,
134
- logger: nil,
135
- quiet_deps: false,
136
- verbose: false)
137
- raise ArgumentError, 'path must be set' if path.nil?
138
-
139
- Host.new(@dispatcher).compile_request(
140
- path: path,
141
- source: nil,
142
- importer: nil,
143
- load_paths: load_paths,
144
- syntax: nil,
145
- url: nil,
146
- charset: charset,
147
- source_map: source_map,
148
- source_map_include_sources: source_map_include_sources,
149
- style: style,
150
- functions: functions,
151
- importers: importers,
152
- alert_color: alert_color,
153
- alert_ascii: alert_ascii,
154
- logger: logger,
155
- quiet_deps: quiet_deps,
156
- verbose: verbose
157
- )
158
- end
159
-
160
- # Compiles a stylesheet whose contents is +source+ to CSS.
161
- # @param source [String]
162
- # @param importer [Object] The importer to use to handle loads that are relative to the entrypoint stylesheet.
163
- # @param load_paths [Array<String>] Paths in which to look for stylesheets loaded by rules like
164
- # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
165
- # @param syntax [String, Symbol] The Syntax to use to parse the entrypoint stylesheet.
166
- # @param url [String] The canonical URL of the entrypoint stylesheet. If this is passed along with +importer+, it's
167
- # used to resolve relative loads in the entrypoint stylesheet.
168
- # @param charset [Boolean] By default, if the CSS document contains non-ASCII characters, Sass adds a +@charset+
169
- # declaration (in expanded output mode) or a byte-order mark (in compressed mode) to indicate its encoding to
170
- # browsers or other consumers. If +charset+ is +false+, these annotations are omitted.
171
- # @param source_map [Boolean] Whether or not Sass should generate a source map.
172
- # @param source_map_include_sources [Boolean] Whether Sass should include the sources in the generated source map.
173
- # @param style [String, Symbol] The OutputStyle of the compiled CSS.
174
- # @param functions [Hash<String, Proc>] Additional built-in Sass functions that are available in all stylesheets.
175
- # @param importers [Array<Object>] Custom importers that control how Sass resolves loads from rules like
176
- # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
177
- # @param alert_ascii [Boolean] If this is +true+, the compiler will exclusively use ASCII characters in its error
178
- # and warning messages. Otherwise, it may use non-ASCII Unicode characters as well.
179
- # @param alert_color [Boolean] If this is +true+, the compiler will use ANSI color escape codes in its error and
180
- # warning messages. If it's +false+, it won't use these. If it's +nil+, the compiler will determine whether or
181
- # not to use colors depending on whether the user is using an interactive terminal.
182
- # @param logger [Object] An object to use to handle warnings and/or debug messages from Sass.
183
- # @param quiet_deps [Boolean] If this option is set to +true+, Sass won’t print warnings that are caused by
184
- # dependencies. A “dependency” is defined as any file that’s loaded through +load_paths+ or +importer+.
185
- # Stylesheets that are imported relative to the entrypoint are not considered dependencies.
186
- # @param verbose [Boolean] By default, Dart Sass will print only five instances of the same deprecation warning per
187
- # compilation to avoid deluging users in console noise. If you set verbose to +true+, it will instead print every
188
- # deprecation warning it encounters.
189
- # @return [CompileResult]
190
- # @raise [ArgumentError, CompileError]
191
- # @see https://sass-lang.com/documentation/js-api/functions/compilestring/
192
- def compile_string(source,
193
- importer: nil,
194
- load_paths: [],
195
- syntax: :scss,
196
- url: nil,
197
-
198
- charset: true,
199
- source_map: false,
200
- source_map_include_sources: false,
201
- style: :expanded,
202
-
203
- functions: {},
204
- importers: [],
205
-
206
- alert_ascii: false,
207
- alert_color: nil,
208
- logger: nil,
209
- quiet_deps: false,
210
- verbose: false)
211
- raise ArgumentError, 'source must be set' if source.nil?
212
-
213
- Host.new(@dispatcher).compile_request(
214
- path: nil,
215
- source: source,
216
- importer: importer,
217
- load_paths: load_paths,
218
- syntax: syntax,
219
- url: url,
220
- charset: charset,
221
- source_map: source_map,
222
- source_map_include_sources: source_map_include_sources,
223
- style: style,
224
- functions: functions,
225
- importers: importers,
226
- alert_color: alert_color,
227
- alert_ascii: alert_ascii,
228
- logger: logger,
229
- quiet_deps: quiet_deps,
230
- verbose: verbose
231
- )
232
- end
233
-
234
- # @return [String] Information about the Sass implementation.
235
- # @see https://sass-lang.com/documentation/js-api/variables/info/
236
- def info
237
- @info ||= Host.new(@dispatcher).version_request
238
- end
239
-
240
- def close
241
- @dispatcher.close
242
- end
243
-
244
- def closed?
245
- @dispatcher.closed?
246
- end
247
- end
248
108
  end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ # An exception thrown because a Sass compilation failed.
5
+ class CompileError < StandardError
6
+ # @return [String, nil]
7
+ attr_reader :sass_stack
8
+
9
+ # @return [Logger::SourceSpan, nil]
10
+ attr_reader :span
11
+
12
+ # @return [Array<String>]
13
+ attr_reader :loaded_urls
14
+
15
+ # @!visibility private
16
+ def initialize(message, full_message, sass_stack, span, loaded_urls)
17
+ super(message)
18
+
19
+ @full_message = full_message
20
+ @sass_stack = sass_stack
21
+ @span = span
22
+ @loaded_urls = loaded_urls
23
+ end
24
+
25
+ # @return [String]
26
+ def full_message(highlight: nil, order: nil, **)
27
+ return super if @full_message.nil?
28
+
29
+ highlight = Exception.respond_to?(:to_tty?) && Exception.to_tty? if highlight.nil?
30
+ if highlight
31
+ +@full_message
32
+ else
33
+ @full_message.gsub(/\e\[[0-9;]*m/, '')
34
+ end
35
+ end
36
+
37
+ # @return [String]
38
+ def to_css
39
+ content = full_message(highlight: false, order: :top)
40
+
41
+ <<~CSS
42
+ /* #{content.gsub('*/', "*\u2060/").gsub("\r\n", "\n").split("\n").join("\n * ")} */
43
+
44
+ body::before {
45
+ position: static;
46
+ display: block;
47
+ padding: 1em;
48
+ margin: 0 0 1em;
49
+ border-width: 0 0 2px;
50
+ border-bottom-style: solid;
51
+ font-family: monospace, monospace;
52
+ white-space: pre;
53
+ content: #{Serializer.dump_quoted_string(content)};
54
+ }
55
+ CSS
56
+ end
57
+ end
58
+
59
+ # An exception thrown by Sass Script.
60
+ class ScriptError < StandardError
61
+ def initialize(message, name = nil)
62
+ super(name.nil? ? message : "$#{name}: #{message}")
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ # The {ForkTracker} module.
5
+ #
6
+ # It tracks objects that need to be closed after `Process.fork`.
7
+ module ForkTracker
8
+ HASH = {}.compare_by_identity
9
+
10
+ MUTEX = Mutex.new
11
+
12
+ private_constant :HASH, :MUTEX
13
+
14
+ module_function
15
+
16
+ def add(obj)
17
+ MUTEX.synchronize do
18
+ HASH[obj] = true
19
+ end
20
+ end
21
+
22
+ def delete(obj)
23
+ MUTEX.synchronize do
24
+ HASH.delete(obj)
25
+ end
26
+ end
27
+
28
+ def each(...)
29
+ MUTEX.synchronize do
30
+ HASH.keys
31
+ end.each(...)
32
+ end
33
+
34
+ # The {CoreExt} module.
35
+ #
36
+ # It closes objects after `Process.fork`.
37
+ module CoreExt
38
+ def _fork
39
+ pid = super
40
+ ForkTracker.each(&:close) if pid.zero?
41
+ pid
42
+ end
43
+ end
44
+
45
+ private_constant :CoreExt
46
+
47
+ Process.singleton_class.prepend(CoreExt)
48
+ end
49
+
50
+ private_constant :ForkTracker
51
+ end