@@ -180,6 +180,34 @@ pub struct JsxSpecs {
180180/// We do not care about the internal structure because the gentype config is loaded by bsc.
181181pub type GenTypeConfig = serde_json:: Value ;
182182
183+ /// Wrapper around dependencies to emit a warning when the bs- prefix is used
184+ #[ derive( Deserialize , Debug , Clone ) ]
185+ pub struct Dependencies {
186+ pub deprecation_warning : bool ,
187+ pub value : Option < Vec < String > > ,
188+ }
189+
190+ impl Default for Dependencies {
191+ fn default ( ) -> Self {
192+ Self {
193+ deprecation_warning : false ,
194+ value : None ,
195+ }
196+ }
197+ }
198+
199+ impl From < Dependencies > for Option < Vec < String > > {
200+ fn from ( dependencies : Dependencies ) -> Self {
201+ dependencies. value
202+ }
203+ }
204+
205+ #[ derive( Deserialize , Debug , Clone ) ]
206+ pub struct DependencyInfo {
207+ pub dependencies : Dependencies ,
208+ pub dev_dependencies : Dependencies ,
209+ }
210+
183211/// # bsconfig.json representation
184212/// This is tricky, there is a lot of ambiguity. This is probably incomplete.
185213#[ derive( Deserialize , Debug , Clone ) ]
@@ -195,19 +223,8 @@ pub struct Config {
195223 #[ serde( rename = "pinned-dependencies" ) ]
196224 pub pinned_dependencies : Option < Vec < String > > ,
197225
198- #[ serde(
199- default ,
200- alias = "bs-dependencies" ,
201- deserialize_with = "deserialize_dependencies"
202- ) ]
203- pub dependencies : Option < Vec < String > > ,
204- #[ serde(
205- default ,
206- rename = "dev-dependencies" ,
207- alias = "bs-dev-dependencies" ,
208- deserialize_with = "deserialize_dev_dependencies"
209- ) ]
210- pub dev_dependencies : Option < Vec < String > > ,
226+ #[ serde( flatten, deserialize_with = "deserialize_dependencies" ) ]
227+ pub dependency_info : DependencyInfo ,
211228
212229 #[ serde( rename = "ppx-flags" ) ]
213230 pub ppx_flags : Option < Vec < OneOrMore < String > > > ,
@@ -243,8 +260,8 @@ pub fn flatten_flags(flags: &Option<Vec<OneOrMore<String>>>) -> Vec<String> {
243260 }
244261}
245262
246- /// Since ppx-flags could be one or more, and could be nested potentiall , this function takes the
247- /// flags and flattens them outright .
263+ /// Since ppx-flags could be one or more, and could potentially be nested, this function takes the
264+ /// flags and flattens them.
248265pub fn flatten_ppx_flags (
249266 node_modules_dir : & Path ,
250267 flags : & Option < Vec < OneOrMore < String > > > ,
@@ -299,14 +316,6 @@ pub fn flatten_ppx_flags(
299316 }
300317}
301318
302- /// Try to convert a bsconfig from a certain path to a bsconfig struct
303- pub fn read ( path : & Path ) -> Result < Config > {
304- let read = fs:: read_to_string ( path) ?;
305- let parse = serde_json:: from_str :: < Config > ( & read) ?;
306-
307- Ok ( parse)
308- }
309-
310319fn namespace_from_package_name ( package_name : & str ) -> String {
311320 let len = package_name. len ( ) ;
312321 let mut buf = String :: with_capacity ( len) ;
@@ -337,6 +346,14 @@ fn namespace_from_package_name(package_name: &str) -> String {
337346}
338347
339348impl Config {
349+ /// Try to convert a bsconfig from a certain path to a bsconfig struct
350+ pub fn new ( path : & Path ) -> Result < Self > {
351+ let read = fs:: read_to_string ( path) ?;
352+ let parse = serde_json:: from_str :: < Config > ( & read) ?;
353+
354+ Ok ( parse)
355+ }
356+
340357 pub fn get_namespace ( & self ) -> packages:: Namespace {
341358 let namespace_from_package = namespace_from_package_name ( & self . name ) ;
342359 match ( self . namespace . as_ref ( ) , self . namespace_entry . as_ref ( ) ) {
@@ -682,7 +699,7 @@ mod tests {
682699 }
683700
684701 #[ test]
685- fn test_dependencies ( ) {
702+ fn test_dependencies_deprecation ( ) {
686703 let json = r#"
687704 {
688705 "name": "testrepo",
@@ -702,11 +719,15 @@ mod tests {
702719 "# ;
703720
704721 let config = serde_json:: from_str :: < Config > ( json) . unwrap ( ) ;
705- assert_eq ! ( config. dependencies, Some ( vec![ "@testrepo/main" . to_string( ) ] ) ) ;
722+ assert_eq ! (
723+ config. dependency_info. dependencies. value,
724+ Some ( vec![ "@testrepo/main" . to_string( ) ] )
725+ ) ;
726+ assert_eq ! ( config. dependency_info. dependencies. deprecation_warning, true )
706727 }
707728
708729 #[ test]
709- fn test_dependencies_alias ( ) {
730+ fn test_dependencies ( ) {
710731 let json = r#"
711732 {
712733 "name": "testrepo",
@@ -726,11 +747,15 @@ mod tests {
726747 "# ;
727748
728749 let config = serde_json:: from_str :: < Config > ( json) . unwrap ( ) ;
729- assert_eq ! ( config. dependencies, Some ( vec![ "@testrepo/main" . to_string( ) ] ) ) ;
750+ assert_eq ! (
751+ config. dependency_info. dependencies. value,
752+ Some ( vec![ "@testrepo/main" . to_string( ) ] )
753+ ) ;
754+ assert_eq ! ( config. dependency_info. dependencies. deprecation_warning, false ) ;
730755 }
731756
732757 #[ test]
733- fn test_dev_dependencies ( ) {
758+ fn test_dev_dependencies_deprecation ( ) {
734759 let json = r#"
735760 {
736761 "name": "testrepo",
@@ -750,11 +775,15 @@ mod tests {
750775 "# ;
751776
752777 let config = serde_json:: from_str :: < Config > ( json) . unwrap ( ) ;
753- assert_eq ! ( config. dev_dependencies, Some ( vec![ "@testrepo/main" . to_string( ) ] ) ) ;
778+ assert_eq ! (
779+ config. dependency_info. dev_dependencies. value,
780+ Some ( vec![ "@testrepo/main" . to_string( ) ] )
781+ ) ;
782+ assert_eq ! ( config. dependency_info. dev_dependencies. deprecation_warning, true ) ;
754783 }
755784
756785 #[ test]
757- fn test_dev_dependencies_alias ( ) {
786+ fn test_dev_dependencies ( ) {
758787 let json = r#"
759788 {
760789 "name": "testrepo",
@@ -774,6 +803,10 @@ mod tests {
774803 "# ;
775804
776805 let config = serde_json:: from_str :: < Config > ( json) . unwrap ( ) ;
777- assert_eq ! ( config. dev_dependencies, Some ( vec![ "@testrepo/main" . to_string( ) ] ) ) ;
806+ assert_eq ! (
807+ config. dependency_info. dev_dependencies. value,
808+ Some ( vec![ "@testrepo/main" . to_string( ) ] )
809+ ) ;
810+ assert_eq ! ( config. dependency_info. dev_dependencies. deprecation_warning, false ) ;
778811 }
779812}
0 commit comments