sassc-embedded 1.70.1 → 1.75.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a1d6d7f744b77407d5d03ab046589505f9b33251eb8440e61a8230725ea3160
4
- data.tar.gz: fb40b19e534709b43f83a26d3358efe8c7a6e0f493da6d1c2e358efc51a9c1a2
3
+ metadata.gz: cf373b6b88c4dcdc3c784f85965562aa6e86ffffafd8ecb2b30513f2f52d51ae
4
+ data.tar.gz: d29bad09cafd09e2a5953c46ec546fe9674fc022bbae0b9092d399d4902b621c
5
5
  SHA512:
6
- metadata.gz: 6f300bc7794f77fb090e4264bb62f79f1836a69be5a21a4b8e2889315bfa30dc18f46b372476ff9e8c5ac39d36e867bbb63c5d994eeb45ab64f8f12ac86d5660
7
- data.tar.gz: 74441eae5009812fa2058cdbe992da2ca24dd3ddb5cfb4518b7bde3544a4bfde6fc1ebbe628b671726d7da528d81e48a9d48cb663664f21e324f2824c816db4c
6
+ metadata.gz: c0ecd4e0d91d6890d2b9312a7f39889d46f58095299fa3160a7f133e2dc5efd51734ea0577c80271fedb0601357e9231d6beadd24dbff0e7e54a5b1a048ea74c
7
+ data.tar.gz: b58e4c56f4e3e41796f497885107f63765b91ec2fe81171cdc27b4d6d5d0a82909776a7453f723eee666f4e1cfedf1bedab35a75632517959e4e0cbe3b2ba909
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SassC
4
4
  module Embedded
5
- VERSION = '1.70.1'
5
+ VERSION = '1.75.2'
6
6
  end
7
7
  end
@@ -13,11 +13,9 @@ module SassC
13
13
  def render
14
14
  return @template.dup if @template.empty?
15
15
 
16
- base_importer = import_handler.setup(nil)
17
-
18
16
  result = ::Sass.compile_string(
19
17
  @template,
20
- importer: base_importer,
18
+ importer: (NoopImporter unless @options[:importer].nil?),
21
19
  load_paths:,
22
20
  syntax:,
23
21
  url: file_url,
@@ -28,12 +26,15 @@ module SassC
28
26
  style: output_style,
29
27
 
30
28
  functions: functions_handler.setup(nil, functions: @functions),
31
- importers: (base_importer.nil? ? [] : [base_importer]).concat(@options.fetch(:importers, [])),
29
+ importers: import_handler.setup(nil).concat(@options.fetch(:importers, [])),
32
30
 
33
31
  alert_ascii: @options.fetch(:alert_ascii, false),
34
32
  alert_color: @options.fetch(:alert_color, nil),
33
+ fatal_deprecations: @options.fetch(:fatal_deprecations, []),
34
+ future_deprecations: @options.fetch(:future_deprecations, []),
35
35
  logger: @options.fetch(:logger, nil),
36
36
  quiet_deps: @options.fetch(:quiet_deps, false),
37
+ silence_deprecations: @options.fetch(:silence_deprecations, []),
37
38
  verbose: @options.fetch(:verbose, false)
38
39
  )
39
40
 
@@ -134,11 +135,7 @@ module SassC
134
135
  end
135
136
 
136
137
  def load_paths
137
- @load_paths ||= if @options[:importer].nil?
138
- (@options[:load_paths] || []) + SassC.load_paths
139
- else
140
- []
141
- end
138
+ @load_paths ||= (@options[:load_paths] || []) + SassC.load_paths
142
139
  end
143
140
  end
144
141
 
@@ -182,12 +179,55 @@ module SassC
182
179
  end
183
180
  end
184
181
 
182
+ module NoopImporter
183
+ module_function
184
+
185
+ def canonicalize(...); end
186
+
187
+ def load(...); end
188
+ end
189
+
190
+ private_constant :NoopImporter
191
+
185
192
  class ImportHandler
186
193
  def setup(_native_options)
187
- Importer.new(@importer) if @importer
194
+ if @importer
195
+ import_cache = ImportCache.new(@importer)
196
+ [Importer.new(import_cache), FileImporter.new(import_cache)]
197
+ else
198
+ []
199
+ end
200
+ end
201
+
202
+ class Importer
203
+ def initialize(import_cache)
204
+ @import_cache = import_cache
205
+ end
206
+
207
+ def canonicalize(...)
208
+ @import_cache.canonicalize(...)
209
+ end
210
+
211
+ def load(...)
212
+ @import_cache.load(...)
213
+ end
188
214
  end
189
215
 
216
+ private_constant :Importer
217
+
190
218
  class FileImporter
219
+ def initialize(import_cache)
220
+ @import_cache = import_cache
221
+ end
222
+
223
+ def find_file_url(...)
224
+ @import_cache.find_file_url(...)
225
+ end
226
+ end
227
+
228
+ private_constant :FileImporter
229
+
230
+ class FileSystemImporter
191
231
  class << self
192
232
  def resolve_path(path, from_import)
193
233
  ext = File.extname(path)
@@ -199,15 +239,6 @@ module SassC
199
239
  return exactly_one(try_path(path))
200
240
  end
201
241
 
202
- unless ext.empty?
203
- if from_import
204
- result = exactly_one(try_path("#{without_ext(path)}.import#{ext}"))
205
- return result unless result.nil?
206
- end
207
- result = exactly_one(try_path(path))
208
- return result unless result.nil?
209
- end
210
-
211
242
  if from_import
212
243
  result = exactly_one(try_path_with_ext("#{path}.import"))
213
244
  return result unless result.nil?
@@ -235,7 +266,7 @@ module SassC
235
266
  end
236
267
 
237
268
  def try_path_as_dir(path, from_import)
238
- return unless dir_exist? path
269
+ return unless dir_exist?(path)
239
270
 
240
271
  if from_import
241
272
  result = exactly_one(try_path_with_ext(File.join(path, 'index.import')))
@@ -247,7 +278,7 @@ module SassC
247
278
 
248
279
  def exactly_one(paths)
249
280
  return if paths.empty?
250
- return paths.first if paths.length == 1
281
+ return paths.first if paths.one?
251
282
 
252
283
  raise "It's not clear which file to import. Found:\n#{paths.map { |path| " #{path}" }.join("\n")}"
253
284
  end
@@ -267,79 +298,69 @@ module SassC
267
298
  end
268
299
  end
269
300
 
270
- private_constant :FileImporter
301
+ private_constant :FileSystemImporter
271
302
 
272
- class Importer
303
+ class ImportCache
273
304
  def initialize(importer)
274
305
  @importer = importer
275
-
276
- @canonical_urls = {}
277
- @id = 0
278
306
  @importer_results = {}
279
- @parent_urls = [URL.path_to_file_url(File.absolute_path(@importer.options[:filename] || 'stdin'))]
307
+ @file_url = nil
280
308
  end
281
309
 
282
310
  def canonicalize(url, context)
283
- if url.start_with?(Protocol::IMPORT)
284
- canonical_url = @canonical_urls.delete(url.delete_prefix(Protocol::IMPORT))
285
- unless @importer_results.key?(canonical_url)
286
- canonical_url = resolve_file_url(canonical_url, @parent_urls.last, context.from_import)
287
- end
288
- @parent_urls.push(canonical_url)
289
- canonical_url
290
- elsif url.start_with?(Protocol::FILE)
291
- path = URL.file_urls_to_relative_path(url, @parent_urls.last)
292
- parent_path = URL.file_url_to_path(@parent_urls.last)
311
+ return if context.containing_url.nil?
312
+
313
+ containing_url = if context.containing_url.start_with?(Protocol::GLOB)
314
+ URL.unescape(URL.parse(context.containing_url).fragment)
315
+ else
316
+ context.containing_url
317
+ end
318
+
319
+ return unless containing_url.start_with?(Protocol::FILE)
293
320
 
321
+ path = URL.unescape(url)
322
+ parent_path = URL.file_url_to_path(containing_url)
323
+ parent_dir = File.dirname(parent_path)
324
+
325
+ if containing_url == context.containing_url
294
326
  imports = @importer.imports(path, parent_path)
295
327
  imports = [SassC::Importer::Import.new(path)] if imports.nil?
296
328
  imports = [imports] unless imports.is_a?(Array)
297
- imports.each do |import|
298
- import.path = File.absolute_path(import.path, File.dirname(parent_path))
329
+ canonical_url = imports_to_native(imports, parent_dir, context.from_import, url, context.containing_url)
330
+ if @importer_results.key?(canonical_url)
331
+ canonical_url
332
+ else
333
+ @file_url = canonical_url
334
+ nil
335
+ end
336
+ else
337
+ canonical_url = URL.path_to_file_url(File.absolute_path(path, parent_dir))
338
+ if @importer_results.key?(canonical_url)
339
+ canonical_url
340
+ else
341
+ @file_url = resolve_file_url(path, parent_dir, context.from_import)
342
+ nil
299
343
  end
300
-
301
- canonical_url = "#{Protocol::IMPORT}#{next_id}"
302
- @importer_results[canonical_url] = imports_to_native(imports, context.from_import)
303
- canonical_url
304
- elsif url.start_with?(Protocol::LOADED)
305
- canonical_url = Protocol::LOADED
306
- @parent_urls.pop
307
- canonical_url
308
344
  end
309
345
  end
310
346
 
311
347
  def load(canonical_url)
312
- if @importer_results.key?(canonical_url)
313
- @importer_results.delete(canonical_url)
314
- elsif canonical_url.start_with?(Protocol::FILE)
315
- path = URL.file_url_to_path(canonical_url)
316
- {
317
- contents: File.read(path),
318
- syntax: syntax(path),
319
- source_map_url: canonical_url
320
- }
321
- elsif canonical_url.start_with?(Protocol::LOADED)
322
- {
323
- contents: '',
324
- syntax: :scss
325
- }
326
- end
348
+ @importer_results.delete(canonical_url)
327
349
  end
328
350
 
329
- private
351
+ def find_file_url(_url, context)
352
+ return if context.containing_url.nil? || @file_url.nil?
330
353
 
331
- def load_paths
332
- @load_paths ||= (@importer.options[:load_paths] || []) + SassC.load_paths
354
+ canonical_url = @file_url
355
+ @file_url = nil
356
+ canonical_url
333
357
  end
334
358
 
335
- def resolve_file_url(url, parent_url, from_import)
336
- path = URL.file_urls_to_relative_path(url, parent_url)
337
- parent_path = URL.file_url_to_path(parent_url)
338
- [File.dirname(parent_path)].concat(load_paths).each do |load_path|
339
- resolved = FileImporter.resolve_path(File.absolute_path(path, load_path), from_import)
340
- return URL.path_to_file_url(resolved) unless resolved.nil?
341
- end
342
- nil
359
+ private
360
+
361
+ def resolve_file_url(path, parent_dir, from_import)
362
+ resolved = FileSystemImporter.resolve_path(File.absolute_path(path, parent_dir), from_import)
363
+ URL.path_to_file_url(resolved) unless resolved.nil?
343
364
  end
344
365
 
345
366
  def syntax(path)
@@ -353,45 +374,48 @@ module SassC
353
374
  end
354
375
  end
355
376
 
356
- def imports_to_native(imports, from_import)
357
- {
377
+ def import_to_native(import, parent_dir, from_import, canonicalize)
378
+ if import.source
379
+ canonical_url = URL.path_to_file_url(File.absolute_path(import.path, parent_dir))
380
+ @importer_results[canonical_url] = if import.source.is_a?(Hash)
381
+ {
382
+ contents: import.source[:contents],
383
+ syntax: import.source[:syntax],
384
+ source_map_url: canonical_url
385
+ }
386
+ else
387
+ {
388
+ contents: import.source,
389
+ syntax: syntax(import.path),
390
+ source_map_url: canonical_url
391
+ }
392
+ end
393
+ return canonical_url if canonicalize
394
+ elsif canonicalize
395
+ return resolve_file_url(import.path, parent_dir, from_import)
396
+ end
397
+
398
+ URL.escape(import.path)
399
+ end
400
+
401
+ def imports_to_native(imports, parent_dir, from_import, url, containing_url)
402
+ return import_to_native(imports.first, parent_dir, from_import, true) if imports.one?
403
+
404
+ canonical_url = "#{Protocol::GLOB}?#{URL.escape(url)}##{URL.escape(containing_url)}"
405
+ @importer_results[canonical_url] = {
358
406
  contents: imports.flat_map do |import|
359
- id = next_id
360
- canonical_url = URL.path_to_file_url(import.path)
361
- @canonical_urls[id] = canonical_url
362
- if import.source
363
- @importer_results[canonical_url] = if import.source.is_a?(Hash)
364
- {
365
- contents: import.source[:contents],
366
- syntax: import.source[:syntax],
367
- source_map_url: canonical_url
368
- }
369
- else
370
- {
371
- contents: import.source,
372
- syntax: syntax(import.path),
373
- source_map_url: canonical_url
374
- }
375
- end
376
- end
377
407
  at_rule = from_import ? '@import' : '@forward'
378
- [
379
- "#{at_rule} \"#{Protocol::IMPORT}#{id}\";",
380
- "#{at_rule} \"#{Protocol::LOADED}#{id}\";"
381
- ]
408
+ url = import_to_native(import, parent_dir, from_import, false)
409
+ "#{at_rule} #{Script::Value::String.quote(url)};"
382
410
  end.join("\n"),
383
411
  syntax: :scss
384
412
  }
385
- end
386
413
 
387
- def next_id
388
- id = @id
389
- @id = id.next
390
- id.to_s
414
+ canonical_url
391
415
  end
392
416
  end
393
417
 
394
- private_constant :Importer
418
+ private_constant :ImportCache
395
419
  end
396
420
 
397
421
  class Sass2Scss
@@ -543,8 +567,7 @@ module SassC
543
567
 
544
568
  module Protocol
545
569
  FILE = 'file:'
546
- IMPORT = 'sassc-embedded-import:'
547
- LOADED = 'sassc-embedded-loaded:'
570
+ GLOB = 'sassc-embedded-glob:'
548
571
  end
549
572
 
550
573
  private_constant :Protocol
@@ -556,6 +579,10 @@ module SassC
556
579
 
557
580
  module_function
558
581
 
582
+ def join(...)
583
+ URI.join(...).to_s
584
+ end
585
+
559
586
  def parse(str)
560
587
  PARSER.parse(str)
561
588
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sassc-embedded
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.70.1
4
+ version: 1.75.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - なつき
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-14 00:00:00.000000000 Z
11
+ date: 2024-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sass-embedded
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.70'
19
+ version: '1.75'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.70'
26
+ version: '1.75'
27
27
  description: An embedded sass shim for SassC.
28
28
  email:
29
29
  - i@ntk.me
@@ -79,7 +79,7 @@ licenses:
79
79
  metadata:
80
80
  bug_tracker_uri: https://github.com/sass-contrib/sassc-embedded-shim-ruby/issues
81
81
  documentation_uri: https://rubydoc.info/gems/sassc
82
- source_code_uri: https://github.com/sass-contrib/sassc-embedded-shim-ruby/tree/v1.70.1
82
+ source_code_uri: https://github.com/sass-contrib/sassc-embedded-shim-ruby/tree/v1.75.2
83
83
  funding_uri: https://github.com/sponsors/ntkme
84
84
  rubygems_mfa_required: 'true'
85
85
  post_install_message: