|
1 | 1 | use crate::build::packages; |
| 2 | +use crate::helpers::deserialize::*; |
2 | 3 | use convert_case::{Case, Casing}; |
3 | 4 | use serde::Deserialize; |
4 | 5 | use std::fs; |
@@ -27,45 +28,6 @@ pub struct PackageSource { |
27 | 28 | pub type_: Option<String>, |
28 | 29 | } |
29 | 30 |
|
30 | | -/// `to_qualified_without_children` takes a tree like structure of dependencies, coming in from |
31 | | -/// `bsconfig`, and turns it into a flat list. The main thing we extract here are the source |
32 | | -/// folders, and optional subdirs, where potentially, the subdirs recurse or not. |
33 | | -pub fn to_qualified_without_children(s: &Source, sub_path: Option<PathBuf>) -> PackageSource { |
34 | | - match s { |
35 | | - Source::Shorthand(dir) => PackageSource { |
36 | | - dir: sub_path |
37 | | - .map(|p| p.join(Path::new(dir))) |
38 | | - .unwrap_or(Path::new(dir).to_path_buf()) |
39 | | - .to_string_lossy() |
40 | | - .to_string(), |
41 | | - subdirs: None, |
42 | | - type_: s.get_type(), |
43 | | - }, |
44 | | - Source::Qualified(PackageSource { |
45 | | - dir, |
46 | | - type_, |
47 | | - subdirs: Some(Subdirs::Recurse(should_recurse)), |
48 | | - }) => PackageSource { |
49 | | - dir: sub_path |
50 | | - .map(|p| p.join(Path::new(dir))) |
51 | | - .unwrap_or(Path::new(dir).to_path_buf()) |
52 | | - .to_string_lossy() |
53 | | - .to_string(), |
54 | | - subdirs: Some(Subdirs::Recurse(*should_recurse)), |
55 | | - type_: type_.to_owned(), |
56 | | - }, |
57 | | - Source::Qualified(PackageSource { dir, type_, .. }) => PackageSource { |
58 | | - dir: sub_path |
59 | | - .map(|p| p.join(Path::new(dir))) |
60 | | - .unwrap_or(Path::new(dir).to_path_buf()) |
61 | | - .to_string_lossy() |
62 | | - .to_string(), |
63 | | - subdirs: None, |
64 | | - type_: type_.to_owned(), |
65 | | - }, |
66 | | - } |
67 | | -} |
68 | | - |
69 | 31 | impl Eq for PackageSource {} |
70 | 32 |
|
71 | 33 | #[derive(Deserialize, Debug, Clone, PartialEq, Hash)] |
@@ -97,14 +59,53 @@ impl Source { |
97 | 59 | (source, _) => source.clone(), |
98 | 60 | } |
99 | 61 | } |
| 62 | + |
| 63 | + /// `to_qualified_without_children` takes a tree like structure of dependencies, coming in from |
| 64 | + /// `bsconfig`, and turns it into a flat list. The main thing we extract here are the source |
| 65 | + /// folders, and optional subdirs, where potentially, the subdirs recurse or not. |
| 66 | + pub fn to_qualified_without_children(&self, sub_path: Option<PathBuf>) -> PackageSource { |
| 67 | + match self { |
| 68 | + Source::Shorthand(dir) => PackageSource { |
| 69 | + dir: sub_path |
| 70 | + .map(|p| p.join(Path::new(dir))) |
| 71 | + .unwrap_or(Path::new(dir).to_path_buf()) |
| 72 | + .to_string_lossy() |
| 73 | + .to_string(), |
| 74 | + subdirs: None, |
| 75 | + type_: self.get_type(), |
| 76 | + }, |
| 77 | + Source::Qualified(PackageSource { |
| 78 | + dir, |
| 79 | + type_, |
| 80 | + subdirs: Some(Subdirs::Recurse(should_recurse)), |
| 81 | + }) => PackageSource { |
| 82 | + dir: sub_path |
| 83 | + .map(|p| p.join(Path::new(dir))) |
| 84 | + .unwrap_or(Path::new(dir).to_path_buf()) |
| 85 | + .to_string_lossy() |
| 86 | + .to_string(), |
| 87 | + subdirs: Some(Subdirs::Recurse(*should_recurse)), |
| 88 | + type_: type_.to_owned(), |
| 89 | + }, |
| 90 | + Source::Qualified(PackageSource { dir, type_, .. }) => PackageSource { |
| 91 | + dir: sub_path |
| 92 | + .map(|p| p.join(Path::new(dir))) |
| 93 | + .unwrap_or(Path::new(dir).to_path_buf()) |
| 94 | + .to_string_lossy() |
| 95 | + .to_string(), |
| 96 | + subdirs: None, |
| 97 | + type_: type_.to_owned(), |
| 98 | + }, |
| 99 | + } |
| 100 | + } |
100 | 101 | } |
101 | 102 |
|
102 | 103 | impl Eq for Source {} |
103 | 104 |
|
104 | 105 | #[derive(Deserialize, Debug, Clone)] |
105 | 106 | pub struct PackageSpec { |
106 | 107 | pub module: String, |
107 | | - #[serde(rename = "in-source")] |
| 108 | + #[serde(rename = "in-source", default = "default_true")] |
108 | 109 | pub in_source: bool, |
109 | 110 | pub suffix: Option<String>, |
110 | 111 | } |
@@ -262,6 +263,10 @@ pub fn flatten_ppx_flags( |
262 | 263 | pub fn read(path: String) -> Config { |
263 | 264 | fs::read_to_string(path.clone()) |
264 | 265 | .map_err(|e| format!("Could not read bsconfig. {path} - {e}")) |
| 266 | + // .and_then(|x| { |
| 267 | + // dbg!(&x); |
| 268 | + // repair(x).map_err(|e| format!("Json was invalid and could not be repaired. {path} - {e}")) |
| 269 | + // }) |
265 | 270 | .and_then(|x| { |
266 | 271 | serde_json::from_str::<Config>(&x).map_err(|e| format!("Could not parse bsconfig. {path} - {e}")) |
267 | 272 | }) |
@@ -462,7 +467,7 @@ mod tests { |
462 | 467 |
|
463 | 468 | let config = serde_json::from_str::<Config>(json).unwrap(); |
464 | 469 | if let OneOrMore::Single(source) = config.sources { |
465 | | - let source = to_qualified_without_children(&source, None); |
| 470 | + let source = source.to_qualified_without_children(None); |
466 | 471 | assert_eq!(source.type_, Some(String::from("dev"))); |
467 | 472 | } else { |
468 | 473 | dbg!(config.sources); |
|
0 commit comments