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 30
30
31
31
#### :nail_care : Polish
32
32
33
+ - Read package name from rescript.json if package.json is absent. https://github.com/rescript-lang/rescript/pull/7746
34
+
33
35
#### :house : Internal
34
36
35
37
- 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> {
397
397
}
398
398
399
399
pub 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) ;
401
402
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
+ } ;
404
418
405
419
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) ) ?;
407
421
408
422
package_json[ "name" ]
409
423
. as_str ( )
You can’t perform that action at this time.
0 commit comments