sass-embedded 1.69.5-x64-mingw-ucrt → 1.69.7-x64-mingw-ucrt

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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/exe/sass +2 -2
  4. data/ext/sass/cli.rb +2 -2
  5. data/ext/sass/dart-sass/src/LICENSE +32 -0
  6. data/ext/sass/dart-sass/src/dart.exe +0 -0
  7. data/ext/sass/dart-sass/src/sass.snapshot +0 -0
  8. data/ext/sass/embedded_sass_pb.rb +1 -1
  9. data/lib/sass/calculation_value/calculation_operation.rb +2 -5
  10. data/lib/sass/calculation_value.rb +10 -4
  11. data/lib/sass/compiler/connection.rb +92 -0
  12. data/lib/sass/{embedded → compiler}/dispatcher.rb +32 -11
  13. data/lib/sass/compiler/dispatcher_manager.rb +44 -0
  14. data/lib/sass/{embedded → compiler}/host/function_registry.rb +3 -3
  15. data/lib/sass/{embedded → compiler}/host/importer_registry.rb +4 -4
  16. data/lib/sass/{embedded → compiler}/host/logger_registry.rb +1 -1
  17. data/lib/sass/{embedded → compiler}/host/protofier.rb +1 -1
  18. data/lib/sass/{embedded → compiler}/host/structifier.rb +1 -1
  19. data/lib/sass/{embedded → compiler}/host/value_protofier.rb +3 -3
  20. data/lib/sass/{embedded → compiler}/host.rb +23 -14
  21. data/lib/sass/{embedded → compiler}/varint.rb +1 -1
  22. data/lib/sass/compiler.rb +191 -0
  23. data/lib/sass/elf.rb +2 -2
  24. data/lib/sass/embedded/version.rb +2 -2
  25. data/lib/sass/embedded.rb +65 -204
  26. data/lib/sass/exception.rb +65 -0
  27. data/lib/sass/fork_tracker.rb +51 -0
  28. data/lib/sass/serializer.rb +41 -0
  29. data/lib/sass/value/argument_list.rb +2 -2
  30. data/lib/sass/value/calculation.rb +3 -1
  31. data/lib/sass/value/function.rb +5 -3
  32. data/lib/sass/value/number.rb +8 -8
  33. data/lib/sass/value/string.rb +5 -8
  34. data/lib/sass/value.rb +1 -9
  35. metadata +25 -22
  36. data/lib/sass/compile_error.rb +0 -31
  37. data/lib/sass/embedded/connection.rb +0 -71
  38. data/lib/sass/embedded/resilient_dispatcher.rb +0 -40
  39. data/lib/sass/script_error.rb +0 -10
@@ -0,0 +1,191 @@
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/dispatcher_manager'
8
+ require_relative 'compiler/host'
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 = DispatcherManager.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 ||= <<~INFO.freeze
178
+ sass-embedded\t#{Embedded::VERSION}\t(Embedded Host)\t[Ruby]
179
+ #{Host.new(@dispatcher).version_request}
180
+ INFO
181
+ end
182
+
183
+ def close
184
+ @dispatcher.close
185
+ end
186
+
187
+ def closed?
188
+ @dispatcher.closed?
189
+ end
190
+ end
191
+ end
data/lib/sass/elf.rb CHANGED
@@ -150,7 +150,7 @@ module Sass
150
150
  def initialize(buffer)
151
151
  @buffer = buffer
152
152
  @ehdr = read_ehdr
153
- @buffer.seek(@ehdr[:e_phoff], :SET)
153
+ @buffer.seek(@ehdr[:e_phoff], IO::SEEK_SET)
154
154
  @proghdrs = Array.new(@ehdr[:e_phnum]) do
155
155
  read_phdr
156
156
  end
@@ -176,7 +176,7 @@ module Sass
176
176
  phdr = @proghdrs.find { |p| p[:p_type] == PT_INTERP }
177
177
  return if phdr.nil?
178
178
 
179
- @buffer.seek(phdr[:p_offset], :SET)
179
+ @buffer.seek(phdr[:p_offset], IO::SEEK_SET)
180
180
  interpreter = @buffer.read(phdr[:p_filesz])
181
181
  raise ArgumentError unless interpreter.end_with?("\0")
182
182
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sass
4
- class Embedded
5
- VERSION = '1.69.5'
4
+ module Embedded
5
+ VERSION = '1.69.7'
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,223 +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(:DispatcherManager).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
- @instance
102
+
103
+ @compiler = compiler
74
104
  end
75
105
  end
76
106
  end
77
107
  # rubocop:enable Layout/LineLength
78
-
79
- # The {Embedded} host for using dart-sass. Each instance creates its own
80
- # communication {Dispatcher} with a dedicated compiler process.
81
- #
82
- # @example
83
- # embedded = Sass::Embedded.new
84
- # result = embedded.compile_string('h1 { font-size: 40px; }')
85
- # result = embedded.compile('style.scss')
86
- # embedded.close
87
- class Embedded
88
- def initialize
89
- @dispatcher = ResilientDispatcher.new
90
- end
91
-
92
- # Compiles the Sass file at +path+ to CSS.
93
- # @param path [String]
94
- # @param load_paths [Array<String>] Paths in which to look for stylesheets loaded by rules like
95
- # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
96
- # @param charset [Boolean] By default, if the CSS document contains non-ASCII characters, Sass adds a +@charset+
97
- # declaration (in expanded output mode) or a byte-order mark (in compressed mode) to indicate its encoding to
98
- # browsers or other consumers. If +charset+ is +false+, these annotations are omitted.
99
- # @param source_map [Boolean] Whether or not Sass should generate a source map.
100
- # @param source_map_include_sources [Boolean] Whether Sass should include the sources in the generated source map.
101
- # @param style [String, Symbol] The OutputStyle of the compiled CSS.
102
- # @param functions [Hash<String, Proc>] Additional built-in Sass functions that are available in all stylesheets.
103
- # @param importers [Array<Object>] Custom importers that control how Sass resolves loads from rules like
104
- # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
105
- # @param alert_ascii [Boolean] If this is +true+, the compiler will exclusively use ASCII characters in its error
106
- # and warning messages. Otherwise, it may use non-ASCII Unicode characters as well.
107
- # @param alert_color [Boolean] If this is +true+, the compiler will use ANSI color escape codes in its error and
108
- # warning messages. If it's +false+, it won't use these. If it's +nil+, the compiler will determine whether or
109
- # not to use colors depending on whether the user is using an interactive terminal.
110
- # @param logger [Object] An object to use to handle warnings and/or debug messages from Sass.
111
- # @param quiet_deps [Boolean] If this option is set to +true+, Sass won’t print warnings that are caused by
112
- # dependencies. A “dependency” is defined as any file that’s loaded through +load_paths+ or +importer+.
113
- # Stylesheets that are imported relative to the entrypoint are not considered dependencies.
114
- # @param verbose [Boolean] By default, Dart Sass will print only five instances of the same deprecation warning per
115
- # compilation to avoid deluging users in console noise. If you set verbose to +true+, it will instead print every
116
- # deprecation warning it encounters.
117
- # @return [CompileResult]
118
- # @raise [ArgumentError, CompileError]
119
- # @see https://sass-lang.com/documentation/js-api/functions/compile/
120
- def compile(path,
121
- load_paths: [],
122
-
123
- charset: true,
124
- source_map: false,
125
- source_map_include_sources: false,
126
- style: :expanded,
127
-
128
- functions: {},
129
- importers: [],
130
-
131
- alert_ascii: false,
132
- alert_color: nil,
133
- logger: nil,
134
- quiet_deps: false,
135
- verbose: false)
136
- raise ArgumentError, 'path must be set' if path.nil?
137
-
138
- Host.new(@dispatcher).compile_request(
139
- path: path,
140
- source: nil,
141
- importer: nil,
142
- load_paths: load_paths,
143
- syntax: nil,
144
- url: nil,
145
- charset: charset,
146
- source_map: source_map,
147
- source_map_include_sources: source_map_include_sources,
148
- style: style,
149
- functions: functions,
150
- importers: importers,
151
- alert_color: alert_color,
152
- alert_ascii: alert_ascii,
153
- logger: logger,
154
- quiet_deps: quiet_deps,
155
- verbose: verbose
156
- )
157
- end
158
-
159
- # Compiles a stylesheet whose contents is +source+ to CSS.
160
- # @param source [String]
161
- # @param importer [Object] The importer to use to handle loads that are relative to the entrypoint stylesheet.
162
- # @param load_paths [Array<String>] Paths in which to look for stylesheets loaded by rules like
163
- # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
164
- # @param syntax [String, Symbol] The Syntax to use to parse the entrypoint stylesheet.
165
- # @param url [String] The canonical URL of the entrypoint stylesheet. If this is passed along with +importer+, it's
166
- # used to resolve relative loads in the entrypoint stylesheet.
167
- # @param charset [Boolean] By default, if the CSS document contains non-ASCII characters, Sass adds a +@charset+
168
- # declaration (in expanded output mode) or a byte-order mark (in compressed mode) to indicate its encoding to
169
- # browsers or other consumers. If +charset+ is +false+, these annotations are omitted.
170
- # @param source_map [Boolean] Whether or not Sass should generate a source map.
171
- # @param source_map_include_sources [Boolean] Whether Sass should include the sources in the generated source map.
172
- # @param style [String, Symbol] The OutputStyle of the compiled CSS.
173
- # @param functions [Hash<String, Proc>] Additional built-in Sass functions that are available in all stylesheets.
174
- # @param importers [Array<Object>] Custom importers that control how Sass resolves loads from rules like
175
- # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
176
- # @param alert_ascii [Boolean] If this is +true+, the compiler will exclusively use ASCII characters in its error
177
- # and warning messages. Otherwise, it may use non-ASCII Unicode characters as well.
178
- # @param alert_color [Boolean] If this is +true+, the compiler will use ANSI color escape codes in its error and
179
- # warning messages. If it's +false+, it won't use these. If it's +nil+, the compiler will determine whether or
180
- # not to use colors depending on whether the user is using an interactive terminal.
181
- # @param logger [Object] An object to use to handle warnings and/or debug messages from Sass.
182
- # @param quiet_deps [Boolean] If this option is set to +true+, Sass won’t print warnings that are caused by
183
- # dependencies. A “dependency” is defined as any file that’s loaded through +load_paths+ or +importer+.
184
- # Stylesheets that are imported relative to the entrypoint are not considered dependencies.
185
- # @param verbose [Boolean] By default, Dart Sass will print only five instances of the same deprecation warning per
186
- # compilation to avoid deluging users in console noise. If you set verbose to +true+, it will instead print every
187
- # deprecation warning it encounters.
188
- # @return [CompileResult]
189
- # @raise [ArgumentError, CompileError]
190
- # @see https://sass-lang.com/documentation/js-api/functions/compilestring/
191
- def compile_string(source,
192
- importer: nil,
193
- load_paths: [],
194
- syntax: :scss,
195
- url: nil,
196
-
197
- charset: true,
198
- source_map: false,
199
- source_map_include_sources: false,
200
- style: :expanded,
201
-
202
- functions: {},
203
- importers: [],
204
-
205
- alert_ascii: false,
206
- alert_color: nil,
207
- logger: nil,
208
- quiet_deps: false,
209
- verbose: false)
210
- raise ArgumentError, 'source must be set' if source.nil?
211
-
212
- Host.new(@dispatcher).compile_request(
213
- path: nil,
214
- source: source,
215
- importer: importer,
216
- load_paths: load_paths,
217
- syntax: syntax,
218
- url: url,
219
- charset: charset,
220
- source_map: source_map,
221
- source_map_include_sources: source_map_include_sources,
222
- style: style,
223
- functions: functions,
224
- importers: importers,
225
- alert_color: alert_color,
226
- alert_ascii: alert_ascii,
227
- logger: logger,
228
- quiet_deps: quiet_deps,
229
- verbose: verbose
230
- )
231
- end
232
-
233
- # @return [String] Information about the Sass implementation.
234
- # @see https://sass-lang.com/documentation/js-api/variables/info/
235
- def info
236
- @info ||= Host.new(@dispatcher).version_request
237
- end
238
-
239
- def close
240
- @dispatcher.close
241
- end
242
-
243
- def closed?
244
- @dispatcher.closed?
245
- end
246
- end
247
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.serialize_quoted_string(content, ascii_only: true)};
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) if Process.respond_to?(:_fork)
48
+ end
49
+
50
+ private_constant :ForkTracker
51
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sass
4
+ # The {Serializer} module.
5
+ module Serializer
6
+ module_function
7
+
8
+ def serialize_quoted_string(string, ascii_only: false)
9
+ buffer = [0x22]
10
+ string.each_codepoint do |codepoint|
11
+ if codepoint.zero?
12
+ # If the character is NULL (U+0000), then the REPLACEMENT CHARACTER (U+FFFD).
13
+ buffer << 0xFFFD
14
+ elsif codepoint == 0x22
15
+ # If the character is '"' (U+0022) or "\" (U+005C), then the escaped character.
16
+ buffer << 0x5C << 0x22
17
+ elsif codepoint == 0x5C
18
+ # If the character is '"' (U+0022) or "\" (U+005C), then the escaped character.
19
+ buffer << 0x5C << 0x5C
20
+ elsif codepoint < 0x20 || (ascii_only ? codepoint >= 0x7F : codepoint == 0x7F)
21
+ # If the character is in the range [\1-\1f] (U+0001 to U+001F) or is U+007F,
22
+ # then the character escaped as code point.
23
+ buffer << 0x5C
24
+ buffer.concat(codepoint.to_s(16).codepoints)
25
+ buffer << 0x20
26
+ else
27
+ # Otherwise, the character itself.
28
+ buffer << codepoint
29
+ end
30
+ end
31
+ buffer << 0x22
32
+ buffer.pack('U*')
33
+ end
34
+
35
+ def serialize_unquoted_string(string)
36
+ string.tr("\0", "\uFFFD").gsub(/\n */, ' ')
37
+ end
38
+ end
39
+
40
+ private_constant :Serializer
41
+ end