@@ -16,7 +16,7 @@ use turborepo_telemetry::events::command::CommandEventBuilder;
16
16
use turborepo_ui:: BOLD ;
17
17
18
18
use super :: CommandBase ;
19
- use crate :: turbo_json:: RawTurboJson ;
19
+ use crate :: turbo_json:: { RawTurboJson , CONFIG_FILE , CONFIG_FILE_JSONC } ;
20
20
21
21
pub const DEFAULT_OUTPUT_DIR : & str = "out" ;
22
22
@@ -85,7 +85,12 @@ fn package_json() -> &'static AnchoredSystemPath {
85
85
86
86
fn turbo_json ( ) -> & ' static AnchoredSystemPath {
87
87
static PATH : OnceLock < & ' static AnchoredSystemPath > = OnceLock :: new ( ) ;
88
- PATH . get_or_init ( || AnchoredSystemPath :: new ( "turbo.json" ) . unwrap ( ) )
88
+ PATH . get_or_init ( || AnchoredSystemPath :: new ( CONFIG_FILE ) . unwrap ( ) )
89
+ }
90
+
91
+ fn turbo_jsonc ( ) -> & ' static AnchoredSystemPath {
92
+ static PATH : OnceLock < & ' static AnchoredSystemPath > = OnceLock :: new ( ) ;
93
+ PATH . get_or_init ( || AnchoredSystemPath :: new ( CONFIG_FILE_JSONC ) . unwrap ( ) )
89
94
}
90
95
91
96
pub async fn prune (
@@ -440,24 +445,32 @@ impl<'a> Prune<'a> {
440
445
}
441
446
442
447
fn copy_turbo_json ( & self , workspaces : & [ String ] ) -> Result < ( ) , Error > {
443
- let anchored_turbo_path = turbo_json ( ) ;
444
- let original_turbo_path = self . root . resolve ( anchored_turbo_path) ;
445
- let new_turbo_path = self . full_directory . resolve ( anchored_turbo_path) ;
446
-
447
- let turbo_json_contents = match original_turbo_path. read_to_string ( ) {
448
- Ok ( contents) => contents,
449
- Err ( e) if e. kind ( ) == std:: io:: ErrorKind :: NotFound => {
450
- // If turbo.json doesn't exist skip copying
451
- return Ok ( ( ) ) ;
452
- }
453
- Err ( e) => return Err ( e. into ( ) ) ,
448
+ let Some ( ( turbo_json, turbo_json_name) ) = self
449
+ . get_turbo_json ( turbo_json ( ) )
450
+ . transpose ( )
451
+ . or_else ( || self . get_turbo_json ( turbo_jsonc ( ) ) . transpose ( ) )
452
+ . transpose ( ) ?
453
+ else {
454
+ return Ok ( ( ) ) ;
454
455
} ;
455
456
456
- let turbo_json = RawTurboJson :: parse ( & turbo_json_contents, anchored_turbo_path. as_str ( ) ) ?;
457
-
458
457
let pruned_turbo_json = turbo_json. prune_tasks ( workspaces) ;
458
+ let new_turbo_path = self . full_directory . resolve ( turbo_json_name) ;
459
459
new_turbo_path. create_with_contents ( serde_json:: to_string_pretty ( & pruned_turbo_json) ?) ?;
460
460
461
461
Ok ( ( ) )
462
462
}
463
+
464
+ fn get_turbo_json < ' b > (
465
+ & self ,
466
+ turbo_json_name : & ' b AnchoredSystemPath ,
467
+ ) -> Result < Option < ( RawTurboJson , & ' b AnchoredSystemPath ) > , Error > {
468
+ let original_turbo_path = self . root . resolve ( turbo_json_name) ;
469
+ let Some ( turbo_json_contents) = original_turbo_path. read_existing_to_string ( ) ? else {
470
+ return Ok ( None ) ;
471
+ } ;
472
+
473
+ let turbo_json = RawTurboJson :: parse ( & turbo_json_contents, turbo_json_name. as_str ( ) ) ?;
474
+ Ok ( Some ( ( turbo_json, turbo_json_name) ) )
475
+ }
463
476
}
0 commit comments