proscenium 0.24.0 → 0.24.1
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/lib/proscenium/css_module/transformer.rb +44 -20
- data/lib/proscenium/ext/proscenium +0 -0
- data/lib/proscenium/importer.rb +12 -12
- data/lib/proscenium/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 668df327ee285da0fb15524bf35d4dcd777d206c6745843cbf42c848fdc4f868
|
|
4
|
+
data.tar.gz: 88b129da486755fc965873347fef0e89ef4ce8b81b776b1595453772a7e08ec6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2f4302c5caa08bcb73d79de27caca6feef9709f0103e848abece9508d9902a6d627dae32fa340c349dc59b98d3002a0d9b5804ae4d687b3cc8bbe6aa98b4e6c6
|
|
7
|
+
data.tar.gz: 510c35503a64b92d62f9225907888ecb325a2f9e37e72ae4f3e61e00d525595ace3922e4f7b3958e28e41a4521cc60bab1b5a808a9a1e308a7ce069439fa5424
|
|
@@ -33,31 +33,22 @@ module Proscenium
|
|
|
33
33
|
# class_names "mypackage/button@large"
|
|
34
34
|
# class_names "@scoped/package/button@small"
|
|
35
35
|
#
|
|
36
|
+
# When a block is given, it is yielded once per input name with
|
|
37
|
+
# `(transformed_name, side_load_path)`. `side_load_path` is the exact string passed to
|
|
38
|
+
# `Importer.import` for that name, or `nil` for names that did not trigger a side-load (plain
|
|
39
|
+
# class names with `require_prefix: true`). The return value is unchanged — callers that don't
|
|
40
|
+
# need the path can keep ignoring the block.
|
|
41
|
+
#
|
|
36
42
|
# @param names [String,Symbol,Array<String,Symbol>]
|
|
37
43
|
# @param require_prefix: [Boolean] whether or not to require the `@` prefix.
|
|
44
|
+
# @yieldparam transformed_name [String]
|
|
45
|
+
# @yieldparam side_load_path [String, nil]
|
|
38
46
|
# @return [Array<String>] the transformed CSS module names.
|
|
39
47
|
def class_names(*names, require_prefix: true)
|
|
40
48
|
names.map do |name|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if name.include?('/')
|
|
45
|
-
if name.start_with?('@')
|
|
46
|
-
# Scoped bare specifier (eg. "@scoped/package/lib/button@default").
|
|
47
|
-
_, path, name = name.split('@')
|
|
48
|
-
path = "@#{path}"
|
|
49
|
-
else
|
|
50
|
-
# Local path (eg. /some/path/to/button@default") or bare specifier (eg.
|
|
51
|
-
# "mypackage/lib/button@default").
|
|
52
|
-
path, name = name.split('@')
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
class_name! name, original_name, path: "#{path}#{FILE_EXT}"
|
|
56
|
-
elsif name.start_with?('@')
|
|
57
|
-
class_name! name[1..], original_name
|
|
58
|
-
else
|
|
59
|
-
require_prefix ? name : class_name!(name, original_name)
|
|
60
|
-
end
|
|
49
|
+
transformed, path = transform_class_name(name, require_prefix: require_prefix)
|
|
50
|
+
yield(transformed, path) if block_given?
|
|
51
|
+
transformed
|
|
61
52
|
end
|
|
62
53
|
end
|
|
63
54
|
|
|
@@ -75,5 +66,38 @@ module Proscenium
|
|
|
75
66
|
"#{transformed_name}_#{digest}"
|
|
76
67
|
end
|
|
77
68
|
end
|
|
69
|
+
|
|
70
|
+
private
|
|
71
|
+
|
|
72
|
+
# Returns `[transformed_name, side_load_path]` for a single class-name reference.
|
|
73
|
+
# `side_load_path` is the exact string that `class_name!` passed to `Importer.import`, or
|
|
74
|
+
# `nil` if the name did not trigger a side-load. Extracted so `#class_names` can yield paths
|
|
75
|
+
# to consumers (e.g. proscenium-phlex's `resolved_css_module_paths` replay registry) without
|
|
76
|
+
# re-parsing names.
|
|
77
|
+
def transform_class_name(name, require_prefix:)
|
|
78
|
+
original_name = name.dup
|
|
79
|
+
name = name.to_s if name.is_a?(Symbol)
|
|
80
|
+
|
|
81
|
+
if name.include?('/')
|
|
82
|
+
if name.start_with?('@')
|
|
83
|
+
# Scoped bare specifier (eg. "@scoped/package/lib/button@default").
|
|
84
|
+
_, path, name = name.split('@')
|
|
85
|
+
path = "@#{path}"
|
|
86
|
+
else
|
|
87
|
+
# Local path (eg. /some/path/to/button@default") or bare specifier (eg.
|
|
88
|
+
# "mypackage/lib/button@default").
|
|
89
|
+
path, name = name.split('@')
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
module_path = "#{path}#{FILE_EXT}"
|
|
93
|
+
[class_name!(name, original_name, path: module_path), module_path]
|
|
94
|
+
elsif name.start_with?('@')
|
|
95
|
+
[class_name!(name[1..], original_name), @source_path&.to_s]
|
|
96
|
+
elsif require_prefix
|
|
97
|
+
[name, nil]
|
|
98
|
+
else
|
|
99
|
+
[class_name!(name, original_name), @source_path&.to_s]
|
|
100
|
+
end
|
|
101
|
+
end
|
|
78
102
|
end
|
|
79
103
|
end
|
|
Binary file
|
data/lib/proscenium/importer.rb
CHANGED
|
@@ -30,9 +30,9 @@ module Proscenium
|
|
|
30
30
|
digest = nil
|
|
31
31
|
|
|
32
32
|
if filepath.end_with?('.module.css')
|
|
33
|
-
if
|
|
34
|
-
digest =
|
|
35
|
-
abs_path =
|
|
33
|
+
if imported.key?(filepath)
|
|
34
|
+
digest = imported[filepath][:digest]
|
|
35
|
+
abs_path = imported[filepath][:abs_path]
|
|
36
36
|
else
|
|
37
37
|
manifest_path, non_manifest_path, abs_path = Resolver.resolve(filepath, as_array: true)
|
|
38
38
|
digest = Utils.css_module_digest(abs_path)
|
|
@@ -41,14 +41,14 @@ module Proscenium
|
|
|
41
41
|
if sideloaded
|
|
42
42
|
ActiveSupport::Notifications.instrument 'sideload.proscenium', identifier: filepath,
|
|
43
43
|
sideloaded: do
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
imported[filepath] = { ** }
|
|
45
|
+
imported[filepath][:digest] = digest
|
|
46
|
+
imported[filepath][:abs_path] = abs_path
|
|
47
47
|
end
|
|
48
48
|
else
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
imported[filepath] = { ** }
|
|
50
|
+
imported[filepath][:digest] = digest
|
|
51
|
+
imported[filepath][:abs_path] = abs_path
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
|
|
@@ -60,16 +60,16 @@ module Proscenium
|
|
|
60
60
|
|
|
61
61
|
"#{digest}#{transformed_path}"
|
|
62
62
|
else
|
|
63
|
-
return if
|
|
63
|
+
return if imported.key?(filepath)
|
|
64
64
|
|
|
65
65
|
Array(Resolver.resolve(filepath)).each do |fp|
|
|
66
66
|
if sideloaded
|
|
67
67
|
ActiveSupport::Notifications.instrument 'sideload.proscenium', identifier: fp,
|
|
68
68
|
sideloaded: do
|
|
69
|
-
|
|
69
|
+
imported[fp] = { ** }
|
|
70
70
|
end
|
|
71
71
|
else
|
|
72
|
-
|
|
72
|
+
imported[fp] = { ** }
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
75
|
end
|
data/lib/proscenium/version.rb
CHANGED