Skip to content

Commit

Permalink
🐛 - Allow arbitrary modules in JSX
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandpeelen committed Nov 20, 2024
1 parent 95ca414 commit ae6c713
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/build/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,9 @@ mod test {
name: name.clone(),
config: crate::config::Config {
name: name.clone(),
sources: crate::config::OneOrMore::Single(Source::Shorthand(String::from("Source"))),
sources: Some(crate::config::OneOrMore::Single(Source::Shorthand(String::from(
"Source",
)))),
package_specs: None,
warnings: None,
suffix: None,
Expand Down
47 changes: 40 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,22 @@ pub enum NamespaceConfig {
String(String),
}

#[derive(Deserialize, Debug, Clone)]
#[derive(Deserialize, Debug, Clone, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
pub enum JsxMode {
#[serde(rename = "classic")]
Classic,
#[serde(rename = "automatic")]
Automatic,
}

#[derive(Deserialize, Debug, Clone)]
#[derive(Deserialize, Debug, Clone, Eq, PartialEq)]
#[serde(rename_all = "camelCase")]
#[serde(untagged)]
pub enum JsxModule {
#[serde(rename = "react")]
React,
Other(String),
}

#[derive(Deserialize, Debug, Clone)]
#[derive(Deserialize, Debug, Clone, Eq, PartialEq)]
pub struct JsxSpecs {
pub version: Option<i32>,
pub module: Option<JsxModule>,
Expand Down Expand Up @@ -376,6 +377,9 @@ impl Config {
Some(JsxModule::React) => {
vec!["-bs-jsx-module".to_string(), "react".to_string()]
}
Some(JsxModule::Other(module)) => {
vec!["-bs-jsx-module".to_string(), module]
}
None => vec![],
},
_ => vec![],
Expand Down Expand Up @@ -476,7 +480,7 @@ mod tests {
"#;

let config = serde_json::from_str::<Config>(json).unwrap();
if let OneOrMore::Single(source) = config.sources {
if let Some(OneOrMore::Single(source)) = config.sources {
let source = source.to_qualified_without_children(None);
assert_eq!(source.type_, Some(String::from("dev")));
} else {
Expand Down Expand Up @@ -507,6 +511,35 @@ mod tests {
assert_eq!(config.get_gentype_arg(), vec!["-bs-gentype".to_string()]);
}

#[test]
fn test_other_jsx_module() {
let json = r#"
{
"name": "my-monorepo",
"sources": [ { "dir": "src/", "subdirs": true } ],
"package-specs": [ { "module": "es6", "in-source": true } ],
"suffix": ".mjs",
"pinned-dependencies": [ "@teamwalnut/app" ],
"bs-dependencies": [ "@teamwalnut/app" ],
"jsx": {
"module": "Voby.JSX"
}
}
"#;

let config = serde_json::from_str::<Config>(json).unwrap();
assert!(config.jsx.is_some());
assert_eq!(
config.jsx.unwrap(),
JsxSpecs {
version: None,
module: Some(JsxModule::Other(String::from("Voby.JSX"))),
mode: None,
v3_dependencies: None,
},
);
}

#[test]
fn test_check_if_rescript11_or_higher() {
assert_eq!(check_if_rescript11_or_higher("11.0.0"), Ok(true));
Expand Down

0 comments on commit ae6c713

Please sign in to comment.