sassc-embedded 1.70.0 → 1.74.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: c255de6b5398fbe5a3297b2e0102089a3a4feb4536abf882a14ccb2c422b0743
4
- data.tar.gz: 956dd771d4345eaf8c6f71f594e3e8e03ff929648c5796e1243cd5a2b18e9b0e
3
+ metadata.gz: f2035f16da9c3d02bf4fce8ac06465db89afbee4b1ece61dfd3213b4fec4a150
4
+ data.tar.gz: 1ec55533d5a8949ed2ab53266b52abf963a2be427d228605e0c7147974490856
5
5
  SHA512:
6
- metadata.gz: d279064506b4c9a19efa377d4ec14534d6dc04d6110d6a05616b969b4d2e8de17eaffce8b0ceb2f6abf4189929cff1ce35388a7c9dae9ac189963ed0fb661237
7
- data.tar.gz: a482c18cc65d5d440d86be9b8d1df5a82f4a11bb428b1f3fb141aa22b72c04895206a33cb16a2e600fb80a21a22069734ab3e2a9c6b8537cd3810567e72e57d6
6
+ metadata.gz: 4f0d03db8a9d0848c96c21bcc340ee8fc15993f7b56697649fee823bb4e6a398a992b6245c4b6d274a12cf846c6aa8ee59bf56cc19c1b11081d251ae4509e05e
7
+ data.tar.gz: 40760cf8ab3aa85a459b83f2b41e5513b96fea52fc000fa435dd4f4115526914e3665388305962fdd91da1c454a326f64acb27bd47fd6ddd566a6e428bfb1b9f
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SassC
4
4
  module Embedded
5
- VERSION = '1.70.0'
5
+ VERSION = '1.74.0'
6
6
  end
7
7
  end
@@ -13,11 +13,11 @@ module SassC
13
13
  def render
14
14
  return @template.dup if @template.empty?
15
15
 
16
- base_importer = import_handler.setup(nil)
16
+ importers = import_handler.setup(nil)
17
17
 
18
18
  result = ::Sass.compile_string(
19
19
  @template,
20
- importer: base_importer,
20
+ importer: importers.first,
21
21
  load_paths:,
22
22
  syntax:,
23
23
  url: file_url,
@@ -28,12 +28,15 @@ module SassC
28
28
  style: output_style,
29
29
 
30
30
  functions: functions_handler.setup(nil, functions: @functions),
31
- importers: (base_importer.nil? ? [] : [base_importer]).concat(@options.fetch(:importers, [])),
31
+ importers: importers.concat(@options.fetch(:importers, [])),
32
32
 
33
33
  alert_ascii: @options.fetch(:alert_ascii, false),
34
34
  alert_color: @options.fetch(:alert_color, nil),
35
+ fatal_deprecations: @options.fetch(:fatal_deprecations, []),
36
+ future_deprecations: @options.fetch(:future_deprecations, []),
35
37
  logger: @options.fetch(:logger, nil),
36
38
  quiet_deps: @options.fetch(:quiet_deps, false),
39
+ silence_deprecations: @options.fetch(:silence_deprecations, []),
37
40
  verbose: @options.fetch(:verbose, false)
38
41
  )
39
42
 
@@ -180,35 +183,47 @@ module SassC
180
183
  Script::ValueConversion.from_native(native_value, @options)
181
184
  end
182
185
  end
183
-
184
- begin
185
- begin
186
- raise RuntimeError
187
- rescue StandardError
188
- raise ::Sass::ScriptError
189
- end
190
- rescue StandardError => e
191
- unless e.full_message.include?(e.cause.full_message)
192
- ::Sass::ScriptError.class_eval do
193
- def full_message(...)
194
- full_message = super(...)
195
- if cause
196
- "#{full_message}\n#{cause.full_message(...)}"
197
- else
198
- full_message
199
- end
200
- end
201
- end
202
- end
203
- end
204
186
  end
205
187
 
206
188
  class ImportHandler
207
189
  def setup(_native_options)
208
- Importer.new(@importer) if @importer
190
+ if @importer
191
+ import_cache = ImportCache.new(@importer)
192
+ [Importer.new(import_cache), FileImporter.new(import_cache)]
193
+ else
194
+ []
195
+ end
209
196
  end
210
197
 
198
+ class Importer
199
+ def initialize(import_cache)
200
+ @import_cache = import_cache
201
+ end
202
+
203
+ def canonicalize(...)
204
+ @import_cache.canonicalize(...)
205
+ end
206
+
207
+ def load(...)
208
+ @import_cache.load(...)
209
+ end
210
+ end
211
+
212
+ private_constant :Importer
213
+
211
214
  class FileImporter
215
+ def initialize(import_cache)
216
+ @import_cache = import_cache
217
+ end
218
+
219
+ def find_file_url(...)
220
+ @import_cache.find_file_url(...)
221
+ end
222
+ end
223
+
224
+ private_constant :FileImporter
225
+
226
+ class FileSystemImporter
212
227
  class << self
213
228
  def resolve_path(path, from_import)
214
229
  ext = File.extname(path)
@@ -223,10 +238,10 @@ module SassC
223
238
  unless ext.empty?
224
239
  if from_import
225
240
  result = exactly_one(try_path("#{without_ext(path)}.import#{ext}"))
226
- return result unless result.nil?
241
+ return warn_deprecation_ext(result) unless result.nil?
227
242
  end
228
243
  result = exactly_one(try_path(path))
229
- return result unless result.nil?
244
+ return warn_deprecation_ext(result) unless result.nil?
230
245
  end
231
246
 
232
247
  if from_import
@@ -256,7 +271,7 @@ module SassC
256
271
  end
257
272
 
258
273
  def try_path_as_dir(path, from_import)
259
- return unless dir_exist? path
274
+ return unless dir_exist?(path)
260
275
 
261
276
  if from_import
262
277
  result = exactly_one(try_path_with_ext(File.join(path, 'index.import')))
@@ -268,7 +283,7 @@ module SassC
268
283
 
269
284
  def exactly_one(paths)
270
285
  return if paths.empty?
271
- return paths.first if paths.length == 1
286
+ return paths.first if paths.one?
272
287
 
273
288
  raise "It's not clear which file to import. Found:\n#{paths.map { |path| " #{path}" }.join("\n")}"
274
289
  end
@@ -285,46 +300,71 @@ module SassC
285
300
  ext = File.extname(path)
286
301
  path.delete_suffix(ext)
287
302
  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
288
318
  end
289
319
  end
290
320
 
291
- private_constant :FileImporter
321
+ private_constant :FileSystemImporter
292
322
 
293
- class Importer
323
+ class ImportCache
294
324
  def initialize(importer)
295
325
  @importer = importer
296
-
297
326
  @canonical_urls = {}
298
- @id = 0
299
327
  @importer_results = {}
328
+ @load_paths = (@importer.options[:load_paths] || []) + SassC.load_paths
300
329
  @parent_urls = [URL.path_to_file_url(File.absolute_path(@importer.options[:filename] || 'stdin'))]
301
330
  end
302
331
 
303
332
  def canonicalize(url, context)
304
333
  if url.start_with?(Protocol::IMPORT)
305
- canonical_url = @canonical_urls.delete(url.delete_prefix(Protocol::IMPORT))
334
+ canonical_url = @canonical_urls.delete(url)
306
335
  unless @importer_results.key?(canonical_url)
307
- canonical_url = resolve_file_url(canonical_url, @parent_urls.last, context.from_import)
336
+ path = URL.unescape(canonical_url)
337
+ parent_path = URL.file_url_to_path(@parent_urls.last)
338
+ canonical_url = resolve_file_url(path, parent_path, context.from_import)
339
+ return unless canonical_url
340
+
341
+ # Temporarily disable FileImporter optimization
342
+ # https://github.com/sass/dart-sass/issues/2208
343
+ #
344
+ # if ['.sass', '.scss', '.css'].include?(File.extname(URL.file_url_to_path(canonical_url)))
345
+ # @canonical_urls[url] = canonical_url
346
+ # return nil
347
+ # end
308
348
  end
309
349
  @parent_urls.push(canonical_url)
310
350
  canonical_url
311
- elsif url.start_with?(Protocol::FILE)
312
- path = URL.file_urls_to_relative_path(url, @parent_urls.last)
313
- parent_path = URL.file_url_to_path(@parent_urls.last)
351
+ elsif url.start_with?(Protocol::LOADED)
352
+ @parent_urls.pop
353
+ Protocol::LOADED
354
+ else
355
+ parent_url = @parent_urls.last
356
+ url = URL.join(parent_url, url)
357
+ return unless url.start_with?(Protocol::FILE)
358
+
359
+ path = URL.file_urls_to_relative_path(url, parent_url)
360
+ parent_path = URL.file_url_to_path(parent_url)
314
361
 
315
362
  imports = @importer.imports(path, parent_path)
316
363
  imports = [SassC::Importer::Import.new(path)] if imports.nil?
317
364
  imports = [imports] unless imports.is_a?(Array)
318
- imports.each do |import|
319
- import.path = File.absolute_path(import.path, File.dirname(parent_path))
320
- end
321
365
 
322
- canonical_url = "#{Protocol::IMPORT}#{next_id}"
323
- @importer_results[canonical_url] = imports_to_native(imports, context.from_import)
324
- canonical_url
325
- elsif url.start_with?(Protocol::LOADED)
326
- canonical_url = Protocol::LOADED
327
- @parent_urls.pop
366
+ canonical_url = "#{Protocol::IMPORT}#{url}"
367
+ @importer_results[canonical_url] = imports_to_native(imports, File.dirname(parent_path), context.from_import)
328
368
  canonical_url
329
369
  end
330
370
  end
@@ -347,17 +387,19 @@ module SassC
347
387
  end
348
388
  end
349
389
 
350
- private
390
+ def find_file_url(url, _context)
391
+ canonical_url = @canonical_urls.delete(url)
392
+ return unless canonical_url
351
393
 
352
- def load_paths
353
- @load_paths ||= (@importer.options[:load_paths] || []) + SassC.load_paths
394
+ @parent_urls.push(canonical_url)
395
+ canonical_url
354
396
  end
355
397
 
356
- def resolve_file_url(url, parent_url, from_import)
357
- path = URL.file_urls_to_relative_path(url, parent_url)
358
- parent_path = URL.file_url_to_path(parent_url)
359
- [File.dirname(parent_path)].concat(load_paths).each do |load_path|
360
- resolved = FileImporter.resolve_path(File.absolute_path(path, load_path), from_import)
398
+ private
399
+
400
+ def resolve_file_url(path, parent_path, from_import)
401
+ [File.dirname(parent_path)].concat(@load_paths).each do |load_path|
402
+ resolved = FileSystemImporter.resolve_path(File.absolute_path(path, load_path), from_import)
361
403
  return URL.path_to_file_url(resolved) unless resolved.nil?
362
404
  end
363
405
  nil
@@ -374,13 +416,11 @@ module SassC
374
416
  end
375
417
  end
376
418
 
377
- def imports_to_native(imports, from_import)
419
+ def imports_to_native(imports, parent_dir, from_import)
378
420
  {
379
421
  contents: imports.flat_map do |import|
380
- id = next_id
381
- canonical_url = URL.path_to_file_url(import.path)
382
- @canonical_urls[id] = canonical_url
383
422
  if import.source
423
+ canonical_url = URL.path_to_file_url(File.absolute_path(import.path, parent_dir))
384
424
  @importer_results[canonical_url] = if import.source.is_a?(Hash)
385
425
  {
386
426
  contents: import.source[:contents],
@@ -394,25 +434,24 @@ module SassC
394
434
  source_map_url: canonical_url
395
435
  }
396
436
  end
437
+ else
438
+ canonical_url = URL.escape(import.path)
397
439
  end
440
+ import_url = "#{Protocol::IMPORT}#{canonical_url}"
441
+ loaded_url = "#{Protocol::LOADED}#{canonical_url}"
442
+ @canonical_urls[import_url] = canonical_url
398
443
  at_rule = from_import ? '@import' : '@forward'
399
- [
400
- "#{at_rule} \"#{Protocol::IMPORT}#{id}\";",
401
- "#{at_rule} \"#{Protocol::LOADED}#{id}\";"
402
- ]
444
+ <<~SCSS
445
+ #{at_rule} #{Script::Value::String.quote(import_url)};
446
+ #{at_rule} #{Script::Value::String.quote(loaded_url)};
447
+ SCSS
403
448
  end.join("\n"),
404
449
  syntax: :scss
405
450
  }
406
451
  end
407
-
408
- def next_id
409
- id = @id
410
- @id = id.next
411
- id.to_s
412
- end
413
452
  end
414
453
 
415
- private_constant :Importer
454
+ private_constant :ImportCache
416
455
  end
417
456
 
418
457
  class Sass2Scss
@@ -577,6 +616,10 @@ module SassC
577
616
 
578
617
  module_function
579
618
 
619
+ def join(...)
620
+ URI.join(...).to_s
621
+ end
622
+
580
623
  def parse(str)
581
624
  PARSER.parse(str)
582
625
  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.0
4
+ version: 1.74.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - なつき
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-18 00:00:00.000000000 Z
11
+ date: 2024-04-04 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.74'
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.74'
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.0
82
+ source_code_uri: https://github.com/sass-contrib/sassc-embedded-shim-ruby/tree/v1.74.0
83
83
  funding_uri: https://github.com/sponsors/ntkme
84
84
  rubygems_mfa_required: 'true'
85
85
  post_install_message: