diff --git a/src/bsconfig.rs b/src/bsconfig.rs index f5bf905..17cff89 100644 --- a/src/bsconfig.rs +++ b/src/bsconfig.rs @@ -39,7 +39,7 @@ pub fn to_qualified_without_children(s: &Source, sub_path: Option) -> P .to_string_lossy() .to_string(), subdirs: None, - type_: None, + type_: s.get_type(), }, Source::Qualified(PackageSource { dir, @@ -74,6 +74,31 @@ pub enum Source { Shorthand(String), Qualified(PackageSource), } + +impl Source { + /// When reading, we should propagate the sources all the way through the tree + pub fn get_type(&self) -> Option { + match self { + Source::Shorthand(_) => None, + Source::Qualified(PackageSource { type_, .. }) => type_.clone(), + } + } + pub fn set_type(&self, type_: Option) -> Source { + match (self, type_) { + (Source::Shorthand(dir), Some(type_)) => Source::Qualified(PackageSource { + dir: dir.to_string(), + subdirs: None, + type_: Some(type_), + }), + (Source::Qualified(package_source), type_) => Source::Qualified(PackageSource { + type_, + ..package_source.clone() + }), + (source, _) => source.clone(), + } + } +} + impl Eq for Source {} #[derive(Deserialize, Debug, Clone)] @@ -412,6 +437,39 @@ mod tests { assert_eq!(config.get_module(), "es6"); } + #[test] + fn test_sources() { + let json = r#" + { + "name": "@rescript/core", + "version": "0.5.0", + "sources": { + "dir": "test", + "subdirs": ["intl"], + "type": "dev" + }, + "suffix": ".mjs", + "package-specs": { + "module": "esmodule", + "in-source": true + }, + "bs-dev-dependencies": ["@rescript/tools"], + "warnings": { + "error": "+101" + } + } + "#; + + let config = serde_json::from_str::(json).unwrap(); + if let OneOrMore::Single(source) = config.sources { + let source = to_qualified_without_children(&source, None); + assert_eq!(source.type_, Some(String::from("dev"))); + } else { + dbg!(config.sources); + unreachable!() + } + } + #[test] fn test_detect_gentypeconfig() { let json = r#" @@ -430,7 +488,7 @@ mod tests { "#; let config = serde_json::from_str::(json).unwrap(); - assert_eq!(config.gentype_config.is_some(), true); + assert!(config.gentype_config.is_some()); assert_eq!(config.get_gentype_arg(), vec!["-bs-gentype".to_string()]); } diff --git a/src/build/packages.rs b/src/build/packages.rs index 7ecee3e..b50c0c6 100644 --- a/src/build/packages.rs +++ b/src/build/packages.rs @@ -184,6 +184,9 @@ pub fn read_folders( fn get_source_dirs(source: bsconfig::Source, sub_path: Option) -> AHashSet { let mut source_folders: AHashSet = AHashSet::new(); + let source_folder = bsconfig::to_qualified_without_children(&source, sub_path.to_owned()); + source_folders.insert(source_folder.to_owned()); + let (subdirs, full_recursive) = match source.to_owned() { bsconfig::Source::Shorthand(_) | bsconfig::Source::Qualified(bsconfig::PackageSource { subdirs: None, .. }) => (None, false), @@ -197,15 +200,12 @@ fn get_source_dirs(source: bsconfig::Source, sub_path: Option) -> AHash }) => (Some(subdirs), false), }; - let source_folder = bsconfig::to_qualified_without_children(&source, sub_path.to_owned()); - source_folders.insert(source_folder.to_owned()); - if !full_recursive { let sub_path = Path::new(&source_folder.dir).to_path_buf(); subdirs .unwrap_or(vec![]) .par_iter() - .map(|subdir| get_source_dirs(subdir.to_owned(), Some(sub_path.to_owned()))) + .map(|subsource| get_source_dirs(subsource.set_type(source.get_type()), Some(sub_path.to_owned()))) .collect::>>() .into_iter() .for_each(|subdir| source_folders.extend(subdir)) @@ -453,12 +453,12 @@ pub fn get_source_files( if type_ != &Some("dev".to_string()) { match read_folders(filter, package_dir, path_dir, recurse) { Ok(files) => map.extend(files), - Err(_e) if type_ == &Some("dev".to_string()) => { - log::warn!( - "Could not read folder: {}... Probably ok as type is dev", - path_dir.to_string_lossy() - ) - } + // Err(_e) if type_ == &Some("dev".to_string()) => { + // log::warn!( + // "Could not read folder: {}... Probably ok as type is dev", + // path_dir.to_string_lossy() + // ) + // } Err(_e) => log::error!( "Could not read folder: {:?}. Specified in dependency: {}, located {:?}...", path_dir.to_path_buf().into_os_string(),