File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change 3030
3131#### :nail_care : Polish
3232
33+ - Read package name from rescript.json if package.json is absent. https://github.com/rescript-lang/rescript/pull/7746
34+
3335#### :house : Internal
3436
3537- Add token viewer to ` res_parser ` . https://github.com/rescript-lang/rescript/pull/7751
Original file line number Diff line number Diff line change @@ -397,13 +397,27 @@ fn flatten_dependencies(dependencies: Vec<Dependency>) -> Vec<Dependency> {
397397}
398398
399399pub fn read_package_name ( package_dir : & Path ) -> Result < String > {
400- let package_json_path = package_dir. join ( "package.json" ) ;
400+ let mut file_name = "package.json" ;
401+ let package_json_path = package_dir. join ( file_name) ;
401402
402- let package_json_contents =
403- fs:: read_to_string ( & package_json_path) . map_err ( |e| anyhow ! ( "Could not read package.json: {}" , e) ) ?;
403+ let package_json_contents = if Path :: exists ( & package_json_path) {
404+ fs:: read_to_string ( & package_json_path) . map_err ( |e| anyhow ! ( "Could not read package.json: {}" , e) ) ?
405+ } else {
406+ let rescript_json_path = package_dir. join ( "rescript.json" ) ;
407+ if Path :: exists ( & rescript_json_path) {
408+ file_name = "rescript.json" ;
409+ fs:: read_to_string ( & rescript_json_path)
410+ . map_err ( |e| anyhow ! ( "Could not read rescript.json: {}" , e) ) ?
411+ } else {
412+ return Err ( anyhow ! (
413+ "There is no package.json or rescript.json file in {}" ,
414+ package_dir. to_string_lossy( )
415+ ) ) ;
416+ }
417+ } ;
404418
405419 let package_json: serde_json:: Value = serde_json:: from_str ( & package_json_contents)
406- . map_err ( |e| anyhow ! ( "Could not parse package.json : {}" , e) ) ?;
420+ . map_err ( |e| anyhow ! ( "Could not parse {} : {}" , file_name , e) ) ?;
407421
408422 package_json[ "name" ]
409423 . as_str ( )
You can’t perform that action at this time.
0 commit comments