omena_resolver/
module_id.rs1use serde::Serialize;
2
3#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
4#[serde(rename_all = "camelCase")]
5pub struct ModuleCanonicalIdV0 {
6 pub schema_version: &'static str,
7 pub product: &'static str,
8 pub feature_gate: &'static str,
9 pub canonical_id: String,
10 pub source_uri: String,
11 pub package_name: Option<String>,
12 pub export_name: Option<String>,
13 pub layer_marker: &'static str,
14}
15
16pub fn canonicalize_module_id_v0(source_uri: impl Into<String>) -> ModuleCanonicalIdV0 {
17 let source_uri = source_uri.into();
18 ModuleCanonicalIdV0 {
19 schema_version: "0",
20 product: "omena-resolver.module-canonical-id",
21 feature_gate: "frame-rule",
22 canonical_id: source_uri.clone(),
23 source_uri,
24 package_name: None,
25 export_name: None,
26 layer_marker: "frame-rule",
27 }
28}
29
30#[cfg(test)]
31mod tests {
32 use super::*;
33
34 #[test]
35 fn module_canonical_id_uses_frame_rule_layer_marker() {
36 let module = canonicalize_module_id_v0("file:///workspace/a.module.css");
37
38 assert_eq!(module.schema_version, "0");
39 assert_eq!(module.product, "omena-resolver.module-canonical-id");
40 assert_eq!(module.feature_gate, "frame-rule");
41 assert_eq!(module.layer_marker, "frame-rule");
42 assert_eq!(module.canonical_id, module.source_uri);
43 }
44}