-
Notifications
You must be signed in to change notification settings - Fork 17
Gentype support #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gentype support #138
Changes from 3 commits
c03dc12
097a7ca
1869102
57b7b90
2a8b2a2
c209a87
35e9a13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,10 @@ pub struct JsxSpecs { | |
pub v3_dependencies: Option<Vec<String>>, | ||
} | ||
|
||
/// Empty struct - the gentype config is loaded by bsc | ||
#[derive(Deserialize, Debug, Clone)] | ||
pub struct GenTypeConfig {} | ||
|
||
/// # bsconfig.json representation | ||
/// This is tricky, there is a lot of ambiguity. This is probably incomplete. | ||
#[derive(Deserialize, Debug, Clone)] | ||
|
@@ -157,6 +161,8 @@ pub struct Config { | |
pub namespace: Option<NamespaceConfig>, | ||
pub jsx: Option<JsxSpecs>, | ||
pub uncurried: Option<bool>, | ||
#[serde(rename = "gentypeconfig")] | ||
pub gentype_config: Option<GenTypeConfig>, | ||
// this is a new feature of rewatch, and it's not part of the bsconfig.json spec | ||
#[serde(rename = "namespace-entry")] | ||
pub namespace_entry: Option<String>, | ||
|
@@ -239,7 +245,17 @@ pub fn read(path: String) -> Config { | |
} | ||
|
||
fn check_if_rescript11_or_higher(version: &str) -> bool { | ||
version.split('.').next().unwrap().parse::<usize>().unwrap() >= 11 | ||
// Non stable rescript versions might contain non-numeric characters | ||
let filter_non_number_chars = |s: &str| s.chars().filter(|c| c.is_numeric()).collect::<String>(); | ||
|
||
version | ||
.split('.') | ||
.next() | ||
.map(filter_non_number_chars) | ||
.unwrap() | ||
.parse::<usize>() | ||
.unwrap() | ||
>= 11 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this cuts it - I think you can do wildcards like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see we also hacked this in at some point. But perhaps, while we're touching it, maybe we just fix it up nicely 👌 - If I have some time today, I'll try and conjure up a version as a suggestion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will go with the |
||
} | ||
|
||
fn namespace_from_package_name(package_name: &str) -> String { | ||
|
@@ -366,6 +382,13 @@ impl Config { | |
.or(self.suffix.to_owned()) | ||
.unwrap_or(".js".to_string()) | ||
} | ||
|
||
pub fn get_gentype_arg(&self) -> Vec<String> { | ||
match &self.gentype_config { | ||
Some(_) => vec!["-bs-gentype".to_string()], | ||
None => vec![], | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
|
@@ -389,4 +412,26 @@ mod tests { | |
assert_eq!(config.get_suffix(), ".mjs"); | ||
assert_eq!(config.get_module(), "es6"); | ||
} | ||
|
||
#[test] | ||
fn test_detect_gentypeconfig() { | ||
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" ], | ||
"gentypeconfig": { | ||
"module": "esmodule", | ||
"generatedFileExtension": ".gen.tsx" | ||
} | ||
} | ||
"#; | ||
|
||
let config = serde_json::from_str::<Config>(json).unwrap(); | ||
assert_eq!(config.gentype_config.is_some(), true); | ||
assert_eq!(config.get_gentype_arg(), vec!["-bs-gentype".to_string()]); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably not have this as an empty struct, but rather just
serde::Value
- such that it represents some random piece of JSON which we don't care about. Right now it implies it's empty, rather than something we don't care about.