Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(watch): package inference in watch mode #9404

Merged
merged 1 commit into from
Nov 13, 2024
Merged
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
65 changes: 34 additions & 31 deletions crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1106,41 +1106,44 @@ pub async fn run(
};

// Set some run flags if we have the data and are executing a Run
if let Command::Run {
run_args: _,
execution_args,
} = &mut command
{
// Don't overwrite the flag if it's already been set for whatever reason
execution_args.single_package = execution_args.single_package
|| repo_state
.as_ref()
.map(|repo_state| matches!(repo_state.mode, RepoMode::SinglePackage))
.unwrap_or(false);
// If this is a run command, and we know the actual invocation path, set the
// inference root, as long as the user hasn't overridden the cwd
if cli_args.cwd.is_none() {
if let Ok(invocation_dir) = env::var(INVOCATION_DIR_ENV_VAR) {
// TODO: this calculation can probably be wrapped into the path library
// and made a little more robust or clear
let invocation_path = Utf8Path::new(&invocation_dir);

// If repo state doesn't exist, we're either local turbo running at the root
// (cwd), or inference failed.
// If repo state does exist, we're global turbo, and want to calculate
// package inference based on the repo root
let this_dir = AbsoluteSystemPathBuf::cwd()?;
let repo_root = repo_state.as_ref().map_or(&this_dir, |r| &r.root);
if let Ok(relative_path) = invocation_path.strip_prefix(repo_root) {
if !relative_path.as_str().is_empty() {
debug!("pkg_inference_root set to \"{}\"", relative_path);
execution_args.pkg_inference_root = Some(relative_path.to_string());
match &mut command {
Command::Run {
run_args: _,
execution_args,
}
| Command::Watch(execution_args) => {
// Don't overwrite the flag if it's already been set for whatever reason
execution_args.single_package = execution_args.single_package
|| repo_state
.as_ref()
.map(|repo_state| matches!(repo_state.mode, RepoMode::SinglePackage))
.unwrap_or(false);
// If this is a run command, and we know the actual invocation path, set the
// inference root, as long as the user hasn't overridden the cwd
if cli_args.cwd.is_none() {
if let Ok(invocation_dir) = env::var(INVOCATION_DIR_ENV_VAR) {
// TODO: this calculation can probably be wrapped into the path library
// and made a little more robust or clear
let invocation_path = Utf8Path::new(&invocation_dir);

// If repo state doesn't exist, we're either local turbo running at the root
// (cwd), or inference failed.
// If repo state does exist, we're global turbo, and want to calculate
// package inference based on the repo root
let this_dir = AbsoluteSystemPathBuf::cwd()?;
let repo_root = repo_state.as_ref().map_or(&this_dir, |r| &r.root);
if let Ok(relative_path) = invocation_path.strip_prefix(repo_root) {
if !relative_path.as_str().is_empty() {
debug!("pkg_inference_root set to \"{}\"", relative_path);
execution_args.pkg_inference_root = Some(relative_path.to_string());
}
}
} else {
debug!("{} not set", INVOCATION_DIR_ENV_VAR);
}
} else {
debug!("{} not set", INVOCATION_DIR_ENV_VAR);
}
}
_ => {}
}

// TODO: make better use of RepoState, here and below. We've already inferred
Expand Down
Loading