klenod-plugin-css 0.0.13 → 0.0.15
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 +4 -4
- data/ext/native/Cargo.lock +61 -5
- data/ext/native/Cargo.toml +1 -1
- data/lib/klenod/build/plugins/css_plugin.rb +40 -0
- data/lib/klenod/plugin/css/errors.rb +42 -0
- data/lib/klenod/plugin/css/transformer.rb +2 -1
- data/lib/klenod/plugin/css/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ed46edbabbf73e9d8f5d30187c19a946ea8593d22c055cc42d299389579c9a64
|
|
4
|
+
data.tar.gz: 4d42b67e82c23c8acba8e54a9762f9e54dc942fde38bc8d69cd8c01038dec9f3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '08d2e6445114ff8a75831216aff6a3bde58c34deb1a62ae9051bd8a47c864238f63a138b4a77a2a31369ea55d8287d7907812abde044c1840d52da49c7405fad'
|
|
7
|
+
data.tar.gz: 80c88fcaf3402f8a0a7522103a4b418dfa1d866dacb31ed5f82dd5fdcf6bf7313d88b4610249f058336a209076781be995507c053c0c3496b2b86c7bf482841d
|
data/ext/native/Cargo.lock
CHANGED
|
@@ -236,13 +236,26 @@ dependencies = [
|
|
|
236
236
|
"smallvec",
|
|
237
237
|
]
|
|
238
238
|
|
|
239
|
+
[[package]]
|
|
240
|
+
name = "cssparser"
|
|
241
|
+
version = "0.38.0"
|
|
242
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
243
|
+
checksum = "11119743ad110e8c1bdccd930d7f5c30c99e5fc76a7b63ec9807e84eef0c5f59"
|
|
244
|
+
dependencies = [
|
|
245
|
+
"cssparser-macros",
|
|
246
|
+
"dtoa-short",
|
|
247
|
+
"itoa",
|
|
248
|
+
"phf 0.14.0",
|
|
249
|
+
"smallvec",
|
|
250
|
+
]
|
|
251
|
+
|
|
239
252
|
[[package]]
|
|
240
253
|
name = "cssparser-color"
|
|
241
254
|
version = "0.5.0"
|
|
242
255
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
243
256
|
checksum = "bbaa233e1dcd9c13a5d3e3a8a2c0f5a727bac380398345dbcb31db4597edc86b"
|
|
244
257
|
dependencies = [
|
|
245
|
-
"cssparser",
|
|
258
|
+
"cssparser 0.37.0",
|
|
246
259
|
]
|
|
247
260
|
|
|
248
261
|
[[package]]
|
|
@@ -494,7 +507,7 @@ dependencies = [
|
|
|
494
507
|
"ahash 0.8.12",
|
|
495
508
|
"bitflags",
|
|
496
509
|
"const-str",
|
|
497
|
-
"cssparser",
|
|
510
|
+
"cssparser 0.37.0",
|
|
498
511
|
"cssparser-color",
|
|
499
512
|
"dashmap",
|
|
500
513
|
"data-encoding",
|
|
@@ -587,7 +600,7 @@ name = "native"
|
|
|
587
600
|
version = "0.0.1"
|
|
588
601
|
dependencies = [
|
|
589
602
|
"base64",
|
|
590
|
-
"cssparser",
|
|
603
|
+
"cssparser 0.38.0",
|
|
591
604
|
"lightningcss",
|
|
592
605
|
"magnus",
|
|
593
606
|
"parcel_sourcemap",
|
|
@@ -624,7 +637,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
|
624
637
|
checksum = "d05f71e01edca03d245ab0a9f7ce13a974ceb79baaae8faf2ba0b11de6b90913"
|
|
625
638
|
dependencies = [
|
|
626
639
|
"bitflags",
|
|
627
|
-
"cssparser",
|
|
640
|
+
"cssparser 0.37.0",
|
|
628
641
|
"log",
|
|
629
642
|
"phf 0.11.3",
|
|
630
643
|
"phf_codegen",
|
|
@@ -689,11 +702,22 @@ version = "0.13.1"
|
|
|
689
702
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
690
703
|
checksum = "c1562dc717473dbaa4c1f85a36410e03c047b2e7df7f45ee938fbef64ae7fadf"
|
|
691
704
|
dependencies = [
|
|
692
|
-
"phf_macros",
|
|
705
|
+
"phf_macros 0.13.1",
|
|
693
706
|
"phf_shared 0.13.1",
|
|
694
707
|
"serde",
|
|
695
708
|
]
|
|
696
709
|
|
|
710
|
+
[[package]]
|
|
711
|
+
name = "phf"
|
|
712
|
+
version = "0.14.0"
|
|
713
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
714
|
+
checksum = "010378780309880b08997fae13be7834dba947d36393bd372f2b1556deb2a2f6"
|
|
715
|
+
dependencies = [
|
|
716
|
+
"phf_macros 0.14.0",
|
|
717
|
+
"phf_shared 0.14.0",
|
|
718
|
+
"serde",
|
|
719
|
+
]
|
|
720
|
+
|
|
697
721
|
[[package]]
|
|
698
722
|
name = "phf_codegen"
|
|
699
723
|
version = "0.11.3"
|
|
@@ -724,6 +748,16 @@ dependencies = [
|
|
|
724
748
|
"phf_shared 0.13.1",
|
|
725
749
|
]
|
|
726
750
|
|
|
751
|
+
[[package]]
|
|
752
|
+
name = "phf_generator"
|
|
753
|
+
version = "0.14.0"
|
|
754
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
755
|
+
checksum = "aeb62e0959d5a1bebc965f4d15d9e2b7cea002b6b0f5ba8cde6cc26738467100"
|
|
756
|
+
dependencies = [
|
|
757
|
+
"fastrand",
|
|
758
|
+
"phf_shared 0.14.0",
|
|
759
|
+
]
|
|
760
|
+
|
|
727
761
|
[[package]]
|
|
728
762
|
name = "phf_macros"
|
|
729
763
|
version = "0.13.1"
|
|
@@ -737,6 +771,19 @@ dependencies = [
|
|
|
737
771
|
"syn 2.0.119",
|
|
738
772
|
]
|
|
739
773
|
|
|
774
|
+
[[package]]
|
|
775
|
+
name = "phf_macros"
|
|
776
|
+
version = "0.14.0"
|
|
777
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
778
|
+
checksum = "5fa8d0ca26d424d27630da600c6624696e7dec8bf7b3b492b383c5dc49e5e085"
|
|
779
|
+
dependencies = [
|
|
780
|
+
"phf_generator 0.14.0",
|
|
781
|
+
"phf_shared 0.14.0",
|
|
782
|
+
"proc-macro2",
|
|
783
|
+
"quote",
|
|
784
|
+
"syn 2.0.119",
|
|
785
|
+
]
|
|
786
|
+
|
|
740
787
|
[[package]]
|
|
741
788
|
name = "phf_shared"
|
|
742
789
|
version = "0.11.3"
|
|
@@ -755,6 +802,15 @@ dependencies = [
|
|
|
755
802
|
"siphasher",
|
|
756
803
|
]
|
|
757
804
|
|
|
805
|
+
[[package]]
|
|
806
|
+
name = "phf_shared"
|
|
807
|
+
version = "0.14.0"
|
|
808
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
809
|
+
checksum = "c6fd9027e2d9319be6349febd1db4e8d02aa544921200c9b777720ac34a3aa89"
|
|
810
|
+
dependencies = [
|
|
811
|
+
"siphasher",
|
|
812
|
+
]
|
|
813
|
+
|
|
758
814
|
[[package]]
|
|
759
815
|
name = "pin-project-lite"
|
|
760
816
|
version = "0.2.17"
|
data/ext/native/Cargo.toml
CHANGED
|
@@ -9,7 +9,7 @@ crate-type = ["cdylib"]
|
|
|
9
9
|
|
|
10
10
|
[dependencies]
|
|
11
11
|
base64 = "0.23.1"
|
|
12
|
-
cssparser = "0.
|
|
12
|
+
cssparser = "0.38.0"
|
|
13
13
|
lightningcss = { version = "1.0.0-alpha.70", features = ["serde", "visitor", "sourcemap"] }
|
|
14
14
|
magnus = "0.8.2"
|
|
15
15
|
parcel_sourcemap = { version = "2.1.1", features = ["json"] }
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "klenod/plugin/css/errors"
|
|
3
4
|
require "klenod/plugin/css/transformer"
|
|
4
5
|
require "uri"
|
|
5
6
|
|
|
@@ -107,6 +108,7 @@ module Klenod
|
|
|
107
108
|
css_result = result.metadata[:css_result]
|
|
108
109
|
javascript_only = result.metadata[:css_javascript_only]
|
|
109
110
|
return result unless css_result || javascript_only
|
|
111
|
+
return analysis_finalize(module_id, result, resolved_dependencies, dependency_records, context) if context.analysis?
|
|
110
112
|
|
|
111
113
|
if javascript_only
|
|
112
114
|
javascript_css_edit = finalized_css_edit(
|
|
@@ -202,6 +204,8 @@ module Klenod
|
|
|
202
204
|
end
|
|
203
205
|
|
|
204
206
|
def transform_css(module_id, code, transform_names:, context:)
|
|
207
|
+
# The filename also names the source in the emitted source map, so
|
|
208
|
+
# it stays the plain path. The error report uses module_id instead.
|
|
205
209
|
Transformer.transform(
|
|
206
210
|
module_id.path,
|
|
207
211
|
code,
|
|
@@ -212,6 +216,10 @@ module Klenod
|
|
|
212
216
|
local_css_variables: @local_css_variables && transform_names,
|
|
213
217
|
variable_pattern: @variable_pattern
|
|
214
218
|
)
|
|
219
|
+
rescue ParseError => error
|
|
220
|
+
# The native extension raises with only a message. Re-raise with the
|
|
221
|
+
# source so the report carries an excerpt like every other format.
|
|
222
|
+
raise ParseError.new(error, source: code, module_id: module_id)
|
|
215
223
|
end
|
|
216
224
|
|
|
217
225
|
def minify_enabled?(context)
|
|
@@ -404,6 +412,38 @@ module Klenod
|
|
|
404
412
|
CssEdit.new(edited.code, edited.source_map)
|
|
405
413
|
end
|
|
406
414
|
|
|
415
|
+
# Analysis keeps the resolved class map and an asset reference for
|
|
416
|
+
# importers, but skips import rewriting and source maps.
|
|
417
|
+
def analysis_finalize(module_id, result, resolved_dependencies, dependency_records, context)
|
|
418
|
+
if result.metadata[:css_javascript_only]
|
|
419
|
+
asset = analysis_css_asset(module_id, result.metadata.fetch(:css_javascript_result).code, :css_javascript_stylesheet, {})
|
|
420
|
+
asset.url = context.asset_url(asset.output_path)
|
|
421
|
+
|
|
422
|
+
return result.with(
|
|
423
|
+
code: "Default = #{asset.url.inspect}\n",
|
|
424
|
+
assets: [asset, *result.assets],
|
|
425
|
+
metadata: result.metadata.merge(css_javascript_stylesheet_path: asset.url)
|
|
426
|
+
)
|
|
427
|
+
end
|
|
428
|
+
|
|
429
|
+
css_result = result.metadata.fetch(:css_result)
|
|
430
|
+
classes = finalized_css_selectors(css_result, resolved_dependencies, dependency_records)
|
|
431
|
+
asset = analysis_css_asset(module_id, css_result.code, :css, {classes: classes, variables: css_result.variables})
|
|
432
|
+
asset.url = context.asset_url(asset.output_path)
|
|
433
|
+
|
|
434
|
+
result.with(
|
|
435
|
+
code: ruby_module_source(classes, asset.url, styles_dependency: result.dependencies.fetch(0)),
|
|
436
|
+
assets: [asset, *result.assets],
|
|
437
|
+
metadata: result.metadata.merge(css_asset_path: asset.url, css_classes: classes)
|
|
438
|
+
)
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
def analysis_css_asset(module_id, css, type, metadata)
|
|
442
|
+
hash = Hashing.short(css)
|
|
443
|
+
suffix = (type == :css) ? "" : ".javascript"
|
|
444
|
+
Asset.new(module_id.path, hash, "/#{asset_name(module_id)}#{suffix}.#{hash}.css", nil, css, "text/css", metadata.merge(type: type))
|
|
445
|
+
end
|
|
446
|
+
|
|
407
447
|
def css_asset_pair(module_id, css_edit, type, metadata, context)
|
|
408
448
|
source_map_asset = nil
|
|
409
449
|
css = css_edit.code
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "klenod/build/source_error"
|
|
4
|
+
|
|
5
|
+
module Klenod
|
|
6
|
+
module Build
|
|
7
|
+
module Plugins
|
|
8
|
+
module CSSPlugin
|
|
9
|
+
# The native extension looks this class up by name and raises it with
|
|
10
|
+
# only a message, so it has to tolerate being constructed that way. The
|
|
11
|
+
# plugin catches that bare error and re-raises it with the source and
|
|
12
|
+
# module attached, which is what fills in the excerpt.
|
|
13
|
+
class ParseError < Klenod::Build::SourceError
|
|
14
|
+
# "Unexpected token Colon at app:/styles.css:11:5"
|
|
15
|
+
LOCATION = /\A(?<message>.*)\s+at\s+(?<file>.+):(?<line>\d+):(?<column>\d+)\s*\z/m
|
|
16
|
+
|
|
17
|
+
def initialize(error, source: nil, module_id: nil)
|
|
18
|
+
super
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def kind
|
|
22
|
+
"CSS parse error"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def location(error)
|
|
28
|
+
found = LOCATION.match(message_for(error))
|
|
29
|
+
return nil unless found
|
|
30
|
+
|
|
31
|
+
Location.new(
|
|
32
|
+
# lightningcss reports a zero-based line and a one-based column.
|
|
33
|
+
line: found[:line].to_i + 1,
|
|
34
|
+
column: found[:column].to_i,
|
|
35
|
+
detail: found[:message]
|
|
36
|
+
)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
require "json"
|
|
4
4
|
|
|
5
|
+
require "klenod/plugin/css/errors"
|
|
6
|
+
|
|
5
7
|
begin
|
|
6
8
|
require "klenod/plugin/css/native"
|
|
7
9
|
rescue LoadError
|
|
@@ -13,7 +15,6 @@ module Klenod
|
|
|
13
15
|
module Plugins
|
|
14
16
|
module CSSPlugin
|
|
15
17
|
class Error < StandardError; end
|
|
16
|
-
class ParseError < Error; end
|
|
17
18
|
|
|
18
19
|
ImportDependency = Data.define(:url, :placeholder, :supports, :media, :loc)
|
|
19
20
|
UrlDependency = Data.define(:url, :placeholder, :loc)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: klenod-plugin-css
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.15
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrés Alin
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - '='
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.0.
|
|
18
|
+
version: 0.0.15
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - '='
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.0.
|
|
25
|
+
version: 0.0.15
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: rb_sys
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -66,6 +66,7 @@ files:
|
|
|
66
66
|
- ext/native/src/lib.rs
|
|
67
67
|
- lib/klenod/build/plugins/css_plugin.rb
|
|
68
68
|
- lib/klenod/plugin/css.rb
|
|
69
|
+
- lib/klenod/plugin/css/errors.rb
|
|
69
70
|
- lib/klenod/plugin/css/transformer.rb
|
|
70
71
|
- lib/klenod/plugin/css/version.rb
|
|
71
72
|
homepage: https://github.com/aalin/klenod
|