sassc-embedded 1.74.1 → 1.75.0

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: 411e788cd6cc17fd4f63773757f4f5b57aca396fd20218a6b2f3b3f15d1a1c9a
4
- data.tar.gz: df11ec77342a51c7283da1cd8f3d20f1a4b779752e09ec56baadd321e3baa974
3
+ metadata.gz: 0de8391b1121b4101cf613ea4f7d7f854e4e96211cc0d5463ae0b419523aa85f
4
+ data.tar.gz: '06514688a9cd96979626c33a1ff7314ec6a0846d917f83b3e22404f5f1b67ec2'
5
5
  SHA512:
6
- metadata.gz: fd6134bfefa373e58bc505ab03e55764a10c970d052a66d9138dc61bd46d1bf143093e3d5ca4d8279936f110d6b3d5485f679d5893035d5da630f15c87acb304
7
- data.tar.gz: 7e072a1950cf8a5de7ee5e980f42fa590bc05140259315e87a0389f45b73827add28a0b9f5314c4ce7357b233b9911690d41a1e33a7cf21ac1bba2f912a48eec
6
+ metadata.gz: 6f3474d7c63a4fd2d1f9f9b1c1c8fc808620fa6080801c0d50a7e9448ea33083f1c1aaf341eeb919af9ffc5d20fa21d7c5f3ba1b2100b9316c7abb796eec4775
7
+ data.tar.gz: 7a7cdb33102bc838a17ef302d814abb60dfe59d5f855c50f800b1f91ad6bc3b49937194d26d62fa0fcb5cc6964b4b5d72e22bc25bd73c37e381fe7851017a6ba
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SassC
4
4
  module Embedded
5
- VERSION = '1.74.1'
5
+ VERSION = '1.75.0'
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),
@@ -185,6 +183,16 @@ module SassC
185
183
  end
186
184
  end
187
185
 
186
+ module NoopImporter
187
+ module_function
188
+
189
+ def canonicalize(...); end
190
+
191
+ def load(...); end
192
+ end
193
+
194
+ private_constant :NoopImporter
195
+
188
196
  class ImportHandler
189
197
  def setup(_native_options)
190
198
  if @importer
@@ -235,15 +243,6 @@ module SassC
235
243
  return exactly_one(try_path(path))
236
244
  end
237
245
 
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
246
  if from_import
248
247
  result = exactly_one(try_path_with_ext("#{path}.import"))
249
248
  return result unless result.nil?
@@ -300,21 +299,6 @@ module SassC
300
299
  ext = File.extname(path)
301
300
  path.delete_suffix(ext)
302
301
  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
302
  end
319
303
  end
320
304
 
@@ -323,83 +307,64 @@ module SassC
323
307
  class ImportCache
324
308
  def initialize(importer)
325
309
  @importer = importer
326
- @canonical_urls = {}
327
- @id = 0
328
310
  @importer_results = {}
311
+ @file_url = nil
329
312
  @load_paths = (@importer.options[:load_paths] || []) + SassC.load_paths
330
- @parent_urls = [URL.path_to_file_url(File.absolute_path(@importer.options[:filename] || 'stdin'))]
331
313
  end
332
314
 
333
315
  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)
316
+ return if context.containing_url.nil?
317
+
318
+ containing_url = if context.containing_url.start_with?(Protocol::GLOB)
319
+ URL.unescape(URL.parse(context.containing_url).fragment)
320
+ else
321
+ context.containing_url
322
+ end
323
+
324
+ return unless containing_url.start_with?(Protocol::FILE)
359
325
 
360
- path = URL.file_urls_to_relative_path(url, parent_url)
361
- parent_path = URL.file_url_to_path(parent_url)
326
+ path = URL.unescape(url)
327
+ parent_path = URL.file_url_to_path(containing_url)
328
+ parent_dir = File.dirname(parent_path)
362
329
 
330
+ if containing_url == context.containing_url
363
331
  imports = @importer.imports(path, parent_path)
364
332
  imports = [SassC::Importer::Import.new(path)] if imports.nil?
365
333
  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
334
+ canonical_url = imports_to_native(imports, parent_dir, context.from_import, url, context.containing_url)
335
+ if @importer_results.key?(canonical_url)
336
+ canonical_url
337
+ else
338
+ @file_url = canonical_url
339
+ nil
340
+ end
341
+ else
342
+ canonical_url = URL.path_to_file_url(File.absolute_path(path, parent_dir))
343
+ if @importer_results.key?(canonical_url)
344
+ canonical_url
345
+ else
346
+ @file_url = resolve_file_url(path, parent_dir, context.from_import)
347
+ nil
348
+ end
370
349
  end
371
350
  end
372
351
 
373
352
  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
353
+ @importer_results.delete(canonical_url)
389
354
  end
390
355
 
391
- def find_file_url(url, _context)
392
- canonical_url = @canonical_urls.delete(url)
393
- return unless canonical_url
356
+ def find_file_url(_url, _context)
357
+ return if @file_url.nil?
394
358
 
395
- @parent_urls.push(canonical_url)
359
+ canonical_url = @file_url
360
+ @file_url = nil
396
361
  canonical_url
397
362
  end
398
363
 
399
364
  private
400
365
 
401
- def resolve_file_url(path, parent_path, from_import)
402
- [File.dirname(parent_path)].concat(@load_paths).each do |load_path|
366
+ def resolve_file_url(path, parent_dir, from_import)
367
+ [parent_dir].concat(@load_paths).each do |load_path|
403
368
  resolved = FileSystemImporter.resolve_path(File.absolute_path(path, load_path), from_import)
404
369
  return URL.path_to_file_url(resolved) unless resolved.nil?
405
370
  end
@@ -417,44 +382,44 @@ module SassC
417
382
  end
418
383
  end
419
384
 
420
- def imports_to_native(imports, parent_dir, from_import)
421
- {
385
+ def import_to_native(import, parent_dir, from_import, canonicalize)
386
+ if import.source
387
+ canonical_url = URL.path_to_file_url(File.absolute_path(import.path, parent_dir))
388
+ @importer_results[canonical_url] = if import.source.is_a?(Hash)
389
+ {
390
+ contents: import.source[:contents],
391
+ syntax: import.source[:syntax],
392
+ source_map_url: canonical_url
393
+ }
394
+ else
395
+ {
396
+ contents: import.source,
397
+ syntax: syntax(import.path),
398
+ source_map_url: canonical_url
399
+ }
400
+ end
401
+ return canonical_url if canonicalize
402
+ elsif canonicalize
403
+ return resolve_file_url(import.path, parent_dir, from_import)
404
+ end
405
+
406
+ URL.escape(import.path)
407
+ end
408
+
409
+ def imports_to_native(imports, parent_dir, from_import, url, containing_url)
410
+ return import_to_native(imports.first, parent_dir, from_import, true) if imports.one?
411
+
412
+ canonical_url = "#{Protocol::GLOB}?#{URL.escape(url)}##{URL.escape(containing_url)}"
413
+ @importer_results[canonical_url] = {
422
414
  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
415
  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
416
+ url = import_to_native(import, parent_dir, from_import, false)
417
+ "#{at_rule} #{Script::Value::String.quote(url)};"
449
418
  end.join("\n"),
450
419
  syntax: :scss
451
420
  }
452
- end
453
421
 
454
- def next_id
455
- id = @id
456
- @id = id.next
457
- id
422
+ canonical_url
458
423
  end
459
424
  end
460
425
 
@@ -610,8 +575,7 @@ module SassC
610
575
 
611
576
  module Protocol
612
577
  FILE = 'file:'
613
- IMPORT = 'sassc-embedded-import:'
614
- LOADED = 'sassc-embedded-loaded:'
578
+ GLOB = 'sassc-embedded-glob:'
615
579
  end
616
580
 
617
581
  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.0
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-12 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.0
83
83
  funding_uri: https://github.com/sponsors/ntkme
84
84
  rubygems_mfa_required: 'true'
85
85
  post_install_message: