sassc-embedded 1.74.1 → 1.75.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 411e788cd6cc17fd4f63773757f4f5b57aca396fd20218a6b2f3b3f15d1a1c9a
4
- data.tar.gz: df11ec77342a51c7283da1cd8f3d20f1a4b779752e09ec56baadd321e3baa974
3
+ metadata.gz: cf373b6b88c4dcdc3c784f85965562aa6e86ffffafd8ecb2b30513f2f52d51ae
4
+ data.tar.gz: d29bad09cafd09e2a5953c46ec546fe9674fc022bbae0b9092d399d4902b621c
5
5
  SHA512:
6
- metadata.gz: fd6134bfefa373e58bc505ab03e55764a10c970d052a66d9138dc61bd46d1bf143093e3d5ca4d8279936f110d6b3d5485f679d5893035d5da630f15c87acb304
7
- data.tar.gz: 7e072a1950cf8a5de7ee5e980f42fa590bc05140259315e87a0389f45b73827add28a0b9f5314c4ce7357b233b9911690d41a1e33a7cf21ac1bba2f912a48eec
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.74.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
- importers = import_handler.setup(nil)
17
-
18
16
  result = ::Sass.compile_string(
19
17
  @template,
20
- importer: importers.first,
18
+ importer: (NoopImporter unless @options[:importer].nil?),
21
19
  load_paths:,
22
20
  syntax:,
23
21
  url: file_url,
@@ -28,7 +26,7 @@ module SassC
28
26
  style: output_style,
29
27
 
30
28
  functions: functions_handler.setup(nil, functions: @functions),
31
- importers: importers.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),
@@ -137,11 +135,7 @@ module SassC
137
135
  end
138
136
 
139
137
  def load_paths
140
- @load_paths ||= if @options[:importer].nil?
141
- (@options[:load_paths] || []) + SassC.load_paths
142
- else
143
- []
144
- end
138
+ @load_paths ||= (@options[:load_paths] || []) + SassC.load_paths
145
139
  end
146
140
  end
147
141
 
@@ -185,6 +179,16 @@ module SassC
185
179
  end
186
180
  end
187
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
+
188
192
  class ImportHandler
189
193
  def setup(_native_options)
190
194
  if @importer
@@ -235,15 +239,6 @@ module SassC
235
239
  return exactly_one(try_path(path))
236
240
  end
237
241
 
238
- unless ext.empty?
239
- if from_import
240
- result = exactly_one(try_path("#{without_ext(path)}.import#{ext}"))
241
- return warn_deprecation_ext(result) unless result.nil?
242
- end
243
- result = exactly_one(try_path(path))
244
- return warn_deprecation_ext(result) unless result.nil?
245
- end
246
-
247
242
  if from_import
248
243
  result = exactly_one(try_path_with_ext("#{path}.import"))
249
244
  return result unless result.nil?
@@ -300,21 +295,6 @@ module SassC
300
295
  ext = File.extname(path)
301
296
  path.delete_suffix(ext)
302
297
  end
303
-
304
- def warn_deprecation_ext(path)
305
- basename = File.basename(path)
306
- warn <<~WARNING
307
- Deprecation Warning: Importing files with extensions other than `.scss`, `.sass`, `.css` from relative path or load paths without custom SassC::Importer is deprecated.
308
-
309
- Recommandation: Rename #{basename} to #{basename}.scss
310
-
311
- More info: https://github.com/sass-contrib/sassc-embedded-shim-ruby/pull/86
312
-
313
- #{path}
314
- #{' ' * (path.length - basename.length)}#{'^' * basename.length}
315
- WARNING
316
- path
317
- end
318
298
  end
319
299
  end
320
300
 
@@ -323,87 +303,64 @@ module SassC
323
303
  class ImportCache
324
304
  def initialize(importer)
325
305
  @importer = importer
326
- @canonical_urls = {}
327
- @id = 0
328
306
  @importer_results = {}
329
- @load_paths = (@importer.options[:load_paths] || []) + SassC.load_paths
330
- @parent_urls = [URL.path_to_file_url(File.absolute_path(@importer.options[:filename] || 'stdin'))]
307
+ @file_url = nil
331
308
  end
332
309
 
333
310
  def canonicalize(url, context)
334
- if url.start_with?(Protocol::IMPORT)
335
- canonical_url = @canonical_urls.delete(url)
336
- unless @importer_results.key?(canonical_url)
337
- path = URL.unescape(canonical_url)
338
- parent_path = URL.file_url_to_path(@parent_urls.last)
339
- canonical_url = resolve_file_url(path, parent_path, context.from_import)
340
- return unless canonical_url
341
-
342
- # Temporarily disable FileImporter optimization
343
- # https://github.com/sass/dart-sass/issues/2208
344
- #
345
- # if ['.sass', '.scss', '.css'].include?(File.extname(URL.file_url_to_path(canonical_url)))
346
- # @canonical_urls[url] = canonical_url
347
- # return nil
348
- # end
349
- end
350
- @parent_urls.push(canonical_url)
351
- canonical_url
352
- elsif url.start_with?(Protocol::LOADED)
353
- @parent_urls.pop
354
- Protocol::LOADED
355
- else
356
- parent_url = @parent_urls.last
357
- url = URL.join(parent_url, url)
358
- return unless url.start_with?(Protocol::FILE)
311
+ return if context.containing_url.nil?
359
312
 
360
- path = URL.file_urls_to_relative_path(url, parent_url)
361
- parent_path = URL.file_url_to_path(parent_url)
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
362
318
 
319
+ return unless containing_url.start_with?(Protocol::FILE)
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
363
326
  imports = @importer.imports(path, parent_path)
364
327
  imports = [SassC::Importer::Import.new(path)] if imports.nil?
365
328
  imports = [imports] unless imports.is_a?(Array)
366
-
367
- canonical_url = "#{Protocol::IMPORT}#{url}"
368
- @importer_results[canonical_url] = imports_to_native(imports, File.dirname(parent_path), context.from_import)
369
- canonical_url
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
343
+ end
370
344
  end
371
345
  end
372
346
 
373
347
  def load(canonical_url)
374
- if @importer_results.key?(canonical_url)
375
- @importer_results.delete(canonical_url)
376
- elsif canonical_url.start_with?(Protocol::FILE)
377
- path = URL.file_url_to_path(canonical_url)
378
- {
379
- contents: File.read(path),
380
- syntax: syntax(path),
381
- source_map_url: canonical_url
382
- }
383
- elsif canonical_url.start_with?(Protocol::LOADED)
384
- {
385
- contents: '',
386
- syntax: :scss
387
- }
388
- end
348
+ @importer_results.delete(canonical_url)
389
349
  end
390
350
 
391
- def find_file_url(url, _context)
392
- canonical_url = @canonical_urls.delete(url)
393
- return unless canonical_url
351
+ def find_file_url(_url, context)
352
+ return if context.containing_url.nil? || @file_url.nil?
394
353
 
395
- @parent_urls.push(canonical_url)
354
+ canonical_url = @file_url
355
+ @file_url = nil
396
356
  canonical_url
397
357
  end
398
358
 
399
359
  private
400
360
 
401
- def resolve_file_url(path, parent_path, from_import)
402
- [File.dirname(parent_path)].concat(@load_paths).each do |load_path|
403
- resolved = FileSystemImporter.resolve_path(File.absolute_path(path, load_path), from_import)
404
- return URL.path_to_file_url(resolved) unless resolved.nil?
405
- end
406
- nil
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?
407
364
  end
408
365
 
409
366
  def syntax(path)
@@ -417,44 +374,44 @@ module SassC
417
374
  end
418
375
  end
419
376
 
420
- def imports_to_native(imports, parent_dir, from_import)
421
- {
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] = {
422
406
  contents: imports.flat_map do |import|
423
- if import.source
424
- canonical_url = URL.path_to_file_url(File.absolute_path(import.path, parent_dir))
425
- @importer_results[canonical_url] = if import.source.is_a?(Hash)
426
- {
427
- contents: import.source[:contents],
428
- syntax: import.source[:syntax],
429
- source_map_url: canonical_url
430
- }
431
- else
432
- {
433
- contents: import.source,
434
- syntax: syntax(import.path),
435
- source_map_url: canonical_url
436
- }
437
- end
438
- else
439
- canonical_url = URL.escape(import.path)
440
- end
441
- import_url = "#{Protocol::IMPORT}#{next_id}"
442
- loaded_url = "#{Protocol::LOADED}#{next_id}"
443
- @canonical_urls[import_url] = canonical_url
444
407
  at_rule = from_import ? '@import' : '@forward'
445
- <<~SCSS
446
- #{at_rule} #{Script::Value::String.quote(import_url)};
447
- #{at_rule} #{Script::Value::String.quote(loaded_url)};
448
- SCSS
408
+ url = import_to_native(import, parent_dir, from_import, false)
409
+ "#{at_rule} #{Script::Value::String.quote(url)};"
449
410
  end.join("\n"),
450
411
  syntax: :scss
451
412
  }
452
- end
453
413
 
454
- def next_id
455
- id = @id
456
- @id = id.next
457
- id
414
+ canonical_url
458
415
  end
459
416
  end
460
417
 
@@ -610,8 +567,7 @@ module SassC
610
567
 
611
568
  module Protocol
612
569
  FILE = 'file:'
613
- IMPORT = 'sassc-embedded-import:'
614
- LOADED = 'sassc-embedded-loaded:'
570
+ GLOB = 'sassc-embedded-glob:'
615
571
  end
616
572
 
617
573
  private_constant :Protocol
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.74.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-04-04 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.74'
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.74'
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.74.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: