Skip to content

Commit b3cfb8b

Browse files
fix(prune): support copying turbo.jsonc (#10107)
### Description Realized we weren't considering `jsonc` as a possible source when copying files for `prune`. Some future work is to make `prune` work with the now exposed `root_turbo_json()` method off of the configuration object, but didn't have time for that refactor at the moment. ### Testing Instructions Added `turbo.jsonc` test to the prune e2e tests
1 parent f611d80 commit b3cfb8b

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

crates/turborepo-lib/src/commands/prune.rs

+28-15
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use turborepo_telemetry::events::command::CommandEventBuilder;
1616
use turborepo_ui::BOLD;
1717

1818
use super::CommandBase;
19-
use crate::turbo_json::RawTurboJson;
19+
use crate::turbo_json::{RawTurboJson, CONFIG_FILE, CONFIG_FILE_JSONC};
2020

2121
pub const DEFAULT_OUTPUT_DIR: &str = "out";
2222

@@ -85,7 +85,12 @@ fn package_json() -> &'static AnchoredSystemPath {
8585

8686
fn turbo_json() -> &'static AnchoredSystemPath {
8787
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())
8994
}
9095

9196
pub async fn prune(
@@ -440,24 +445,32 @@ impl<'a> Prune<'a> {
440445
}
441446

442447
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(());
454455
};
455456

456-
let turbo_json = RawTurboJson::parse(&turbo_json_contents, anchored_turbo_path.as_str())?;
457-
458457
let pruned_turbo_json = turbo_json.prune_tasks(workspaces);
458+
let new_turbo_path = self.full_directory.resolve(turbo_json_name);
459459
new_turbo_path.create_with_contents(serde_json::to_string_pretty(&pruned_turbo_json)?)?;
460460

461461
Ok(())
462462
}
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+
}
463476
}

turborepo-tests/integration/tests/prune/includes-root-deps.t

+17
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,20 @@ Make sure that the internal util package is part of the prune output
77
- Added shared
88
- Added util
99
- Added web
10+
11+
Make sure turbo.jsonc is copied over
12+
$ mv turbo.json turbo.jsonc
13+
$ rm -r out
14+
$ ${TURBO} prune web
15+
Generating pruned monorepo for web in .*(\/|\\)out (re)
16+
- Added shared
17+
- Added util
18+
- Added web
19+
$ ls out
20+
apps
21+
package.json
22+
packages
23+
patches
24+
pnpm-lock.yaml
25+
pnpm-workspace.yaml
26+
turbo.jsonc

0 commit comments

Comments
 (0)