Skip to content

Commit

Permalink
chore(visitor): break up visitor to multiple modules (#9306)
Browse files Browse the repository at this point in the history
### Description

This is a prefactor to break up `visitor.rs` into multiple files. This
is primarily just moving code around, but there are a few more in depth
changes:
-
2873556
changes `TaskWarning` to only be constructed if there are missing envs,
removing the need to check later on
-
88e98c5
changes so we no longer call `which` for every task to find the package
manager binary. We instead call this on construction, but will only
handle the error case on actual command creation.

I highly recommend reviewing each commit on it's own. All commits that
move code do only that so hopefully that makes it easier to review.

### Testing Instructions

Integration tests and some basic manual testing.
  • Loading branch information
chris-olszewski authored Oct 23, 2024
1 parent 7d9ccae commit cff7529
Show file tree
Hide file tree
Showing 9 changed files with 1,404 additions and 1,246 deletions.
21 changes: 19 additions & 2 deletions crates/turborepo-lib/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,32 @@ pub struct RunOpts {
pub ui_mode: UIMode,
}

/// Projection of `RunOpts` that only includes information necessary to compute
/// pass through args.
#[derive(Debug)]
pub struct TaskArgs<'a> {
pass_through_args: &'a [String],
tasks: &'a [String],
}

impl RunOpts {
pub fn args_for_task(&self, task_id: &TaskId) -> Option<Vec<String>> {
pub fn task_args(&self) -> TaskArgs {
TaskArgs {
pass_through_args: &self.pass_through_args,
tasks: &self.tasks,
}
}
}

impl<'a> TaskArgs<'a> {
pub fn args_for_task(&self, task_id: &TaskId) -> Option<&'a [String]> {
if !self.pass_through_args.is_empty()
&& self
.tasks
.iter()
.any(|task| task.as_str() == task_id.task())
{
Some(self.pass_through_args.clone())
Some(self.pass_through_args)
} else {
None
}
Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-lib/src/process/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use turbopath::AbsoluteSystemPathBuf;

/// A command builder that can be used to build both regular
/// child processes and ones spawned hooked up to a PTY
#[derive(Debug, Clone)]
pub struct Command {
program: OsString,
args: Vec<OsString>,
Expand Down
1 change: 0 additions & 1 deletion crates/turborepo-lib/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ impl Run {
package_inputs_hashes,
&self.env_at_execution_start,
&global_hash,
self.opts.run_opts.env_mode,
self.color_config,
self.processes.clone(),
&self.repo_root,
Expand Down
Loading

0 comments on commit cff7529

Please sign in to comment.