这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions crates/turborepo-lib/src/commands/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use turborepo_telemetry::events::command::CommandEventBuilder;
use turborepo_ui::BOLD;

use super::CommandBase;
use crate::turbo_json::RawTurboJson;
use crate::turbo_json::{RawTurboJson, CONFIG_FILE, CONFIG_FILE_JSONC};

pub const DEFAULT_OUTPUT_DIR: &str = "out";

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

fn turbo_json() -> &'static AnchoredSystemPath {
static PATH: OnceLock<&'static AnchoredSystemPath> = OnceLock::new();
PATH.get_or_init(|| AnchoredSystemPath::new("turbo.json").unwrap())
PATH.get_or_init(|| AnchoredSystemPath::new(CONFIG_FILE).unwrap())
}

fn turbo_jsonc() -> &'static AnchoredSystemPath {
static PATH: OnceLock<&'static AnchoredSystemPath> = OnceLock::new();
PATH.get_or_init(|| AnchoredSystemPath::new(CONFIG_FILE_JSONC).unwrap())
}

pub async fn prune(
Expand Down Expand Up @@ -440,24 +445,32 @@ impl<'a> Prune<'a> {
}

fn copy_turbo_json(&self, workspaces: &[String]) -> Result<(), Error> {
let anchored_turbo_path = turbo_json();
let original_turbo_path = self.root.resolve(anchored_turbo_path);
let new_turbo_path = self.full_directory.resolve(anchored_turbo_path);

let turbo_json_contents = match original_turbo_path.read_to_string() {
Ok(contents) => contents,
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
// If turbo.json doesn't exist skip copying
return Ok(());
}
Err(e) => return Err(e.into()),
let Some((turbo_json, turbo_json_name)) = self
.get_turbo_json(turbo_json())
.transpose()
.or_else(|| self.get_turbo_json(turbo_jsonc()).transpose())
.transpose()?
else {
return Ok(());
};

let turbo_json = RawTurboJson::parse(&turbo_json_contents, anchored_turbo_path.as_str())?;

let pruned_turbo_json = turbo_json.prune_tasks(workspaces);
let new_turbo_path = self.full_directory.resolve(turbo_json_name);
new_turbo_path.create_with_contents(serde_json::to_string_pretty(&pruned_turbo_json)?)?;

Ok(())
}

fn get_turbo_json<'b>(
&self,
turbo_json_name: &'b AnchoredSystemPath,
) -> Result<Option<(RawTurboJson, &'b AnchoredSystemPath)>, Error> {
let original_turbo_path = self.root.resolve(turbo_json_name);
let Some(turbo_json_contents) = original_turbo_path.read_existing_to_string()? else {
return Ok(None);
};

let turbo_json = RawTurboJson::parse(&turbo_json_contents, turbo_json_name.as_str())?;
Ok(Some((turbo_json, turbo_json_name)))
}
}
17 changes: 17 additions & 0 deletions turborepo-tests/integration/tests/prune/includes-root-deps.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,20 @@ Make sure that the internal util package is part of the prune output
- Added shared
- Added util
- Added web

Make sure turbo.jsonc is copied over
$ mv turbo.json turbo.jsonc
$ rm -r out
$ ${TURBO} prune web
Generating pruned monorepo for web in .*(\/|\\)out (re)
- Added shared
- Added util
- Added web
$ ls out
apps
package.json
packages
patches
pnpm-lock.yaml
pnpm-workspace.yaml
turbo.jsonc
Loading