Skip to content

Commit

Permalink
chore(turbo): rename workspace -> package in PackageGraph module (#7372)
Browse files Browse the repository at this point in the history
This PR renames `workspace` -> `package` in the `package_graph` module
of the `turborepo-repository` crate. There are many other references to
update, but since this is the canonical representation of packages in a
workspace, this is an important one to define the lexicon.
  • Loading branch information
mehulkar authored Feb 13, 2024
1 parent 2e9eed4 commit 46cb4d2
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 91 deletions.
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/commands/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub async fn run(
impl<'a> RepositoryDetails<'a> {
fn new(package_graph: &'a PackageGraph, config: &'a ConfigurationOptions) -> Self {
let mut workspaces: Vec<_> = package_graph
.workspaces()
.packages()
.map(|(workspace_name, workspace_info)| {
let workspace_details = RepositoryWorkspaceDetails {
path: workspace_info.package_path(),
Expand Down
4 changes: 2 additions & 2 deletions crates/turborepo-lib/src/commands/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub async fn prune(
for workspace in workspaces {
let entry = prune
.package_graph
.workspace_info(&workspace)
.package_info(&workspace)
.ok_or_else(|| Error::MissingWorkspace(workspace.clone()))?;

// We don't want to do any copying for the root workspace
Expand Down Expand Up @@ -282,7 +282,7 @@ impl<'a> Prune<'a> {

for target in scope {
let workspace = PackageName::Other(target.clone());
let Some(info) = package_graph.workspace_info(&workspace) else {
let Some(info) = package_graph.package_info(&workspace) else {
return Err(Error::MissingWorkspace(workspace));
};
trace!(
Expand Down
11 changes: 6 additions & 5 deletions crates/turborepo-lib/src/engine/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,12 @@ impl<'a> EngineBuilder<'a> {
workspace: workspace.clone(),
}
})?;
let workspace_dir = self.package_graph.workspace_dir(workspace).ok_or_else(|| {
Error::MissingPackageJson {
workspace: workspace.clone(),
}
})?;
let workspace_dir =
self.package_graph
.package_dir(workspace)
.ok_or_else(|| Error::MissingPackageJson {
workspace: workspace.clone(),
})?;
Ok(TurboJson::load(
self.repo_root,
workspace_dir,
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl Engine<Built> {

// check if the package for the task has that task in its package.json
let info = package_graph
.workspace_info(&PackageName::from(task_id.package().to_string()))
.package_info(&PackageName::from(task_id.package().to_string()))
.expect("package graph should contain workspace info for task package");

let package_has_task = info
Expand Down
6 changes: 3 additions & 3 deletions crates/turborepo-lib/src/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl Run {
}

let root_workspace = pkg_dep_graph
.workspace_info(&PackageName::Root)
.package_info(&PackageName::Root)
.expect("must have root workspace");

let is_monorepo = !self.opts.run_opts.single_package;
Expand Down Expand Up @@ -429,7 +429,7 @@ impl Run {
global_env_mode = EnvMode::Strict;
}

let workspaces = pkg_dep_graph.workspaces().collect();
let workspaces = pkg_dep_graph.packages().collect();
let package_inputs_hashes = PackageInputsHashes::calculate_file_hashes(
&scm,
engine.tasks().par_bridge(),
Expand All @@ -440,7 +440,7 @@ impl Run {
)?;

if self.opts.run_opts.parallel {
pkg_dep_graph.remove_workspace_dependencies();
pkg_dep_graph.remove_package_dependencies();
engine = self.build_engine(&pkg_dep_graph, &root_turbo_json, &filtered_pkgs)?;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/run/scope/change_detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<'a> GitChangeDetector for ScopeChangeDetector<'a> {
{
PackageChanges::All => Ok(self
.pkg_graph
.workspaces()
.packages()
.map(|(name, _)| name.to_owned())
.collect()),
PackageChanges::Some(packages) => Ok(packages
Expand Down
20 changes: 10 additions & 10 deletions crates/turborepo-lib/src/run/scope/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl PackageInference {
pkg_inference_path
);
let full_inference_path = turbo_root.resolve(pkg_inference_path);
for (workspace_name, workspace_entry) in pkg_graph.workspaces() {
for (workspace_name, workspace_entry) in pkg_graph.packages() {
let pkg_path = turbo_root.resolve(workspace_entry.package_path());
let inferred_path_is_below = pkg_path.contains(&full_inference_path);
// We skip over the root package as the inferred path will always be below it
Expand Down Expand Up @@ -158,7 +158,7 @@ impl<'a, T: GitChangeDetector> FilterResolver<'a, T> {
let filter_patterns = if is_all_packages {
// return all packages in the workspace
self.pkg_graph
.workspaces()
.packages()
.filter(|(name, _)| matches!(name, PackageName::Other(_)))
.map(|(name, _)| name.to_owned())
.collect()
Expand Down Expand Up @@ -228,7 +228,7 @@ impl<'a, T: GitChangeDetector> FilterResolver<'a, T> {
self.filter_graph_with_selectors(include_selectors)?
} else {
self.pkg_graph
.workspaces()
.packages()
// todo: a type-level way of dealing with non-root packages
.filter(|(name, _)| !PackageName::Root.eq(name)) // the root package has to be explicitly included
.map(|(name, _)| name.to_owned())
Expand Down Expand Up @@ -268,7 +268,7 @@ impl<'a, T: GitChangeDetector> FilterResolver<'a, T> {
let dependencies = dependencies
.iter()
.flatten()
.map(|i| i.as_workspace().to_owned())
.map(|i| i.as_package_name().to_owned())
.collect::<Vec<_>>();

// flatmap through the option, the set, and then the optional package name
Expand All @@ -277,7 +277,7 @@ impl<'a, T: GitChangeDetector> FilterResolver<'a, T> {

if selector.include_dependents {
let dependents = self.pkg_graph.ancestors(&node);
for dependent in dependents.iter().map(|i| i.as_workspace()) {
for dependent in dependents.iter().map(|i| i.as_package_name()) {
walked_dependents.insert(dependent.clone());

// get the dependent's dependencies
Expand All @@ -291,7 +291,7 @@ impl<'a, T: GitChangeDetector> FilterResolver<'a, T> {
let dependent_dependencies = dependent_dependencies
.iter()
.flatten()
.map(|i| i.as_workspace().to_owned())
.map(|i| i.as_package_name().to_owned())
.collect::<HashSet<_>>();

walked_dependent_dependencies.extend(dependent_dependencies);
Expand Down Expand Up @@ -348,7 +348,7 @@ impl<'a, T: GitChangeDetector> FilterResolver<'a, T> {
) -> Result<HashSet<PackageName>, ResolutionError> {
let mut entry_packages = HashSet::new();

for (name, info) in self.pkg_graph.workspaces() {
for (name, info) in self.pkg_graph.packages() {
if selector.parent_dir == AnchoredSystemPathBuf::default() {
entry_packages.insert(name.to_owned());
} else {
Expand Down Expand Up @@ -427,7 +427,7 @@ impl<'a, T: GitChangeDetector> FilterResolver<'a, T> {
self.packages_changed_in_range(&selector.from_ref, selector.to_ref())?;
let package_path_lookup = self
.pkg_graph
.workspaces()
.packages()
.map(|(name, entry)| (name, entry.package_path()))
.collect::<HashMap<_, _>>();

Expand Down Expand Up @@ -459,7 +459,7 @@ impl<'a, T: GitChangeDetector> FilterResolver<'a, T> {
{
entry_packages.insert(PackageName::Root);
} else {
let packages = self.pkg_graph.workspaces();
let packages = self.pkg_graph.packages();
for (name, _) in packages.filter(|(_name, info)| {
let path = info.package_path().as_path();
parent_dir_globber.is_match(path)
Expand All @@ -474,7 +474,7 @@ impl<'a, T: GitChangeDetector> FilterResolver<'a, T> {
entry_packages = self.match_package_names_to_vertices(
&selector.name_pattern,
self.pkg_graph
.workspaces()
.packages()
.map(|(name, _)| name.to_owned())
.collect(),
)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/run/summary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ impl<'a> RunSummary<'a> {
continue;
}
let dir = pkg_dep_graph
.workspace_info(pkg)
.package_info(pkg)
.ok_or_else(|| Error::MissingWorkspace(pkg.clone()))?
.package_path();

Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/run/summary/task_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl<'a> TaskSummaryFactory<'a> {
fn workspace_info(&self, task_id: &TaskId) -> Result<&PackageInfo, Error> {
let workspace_name = PackageName::from(task_id.package());
self.package_graph
.workspace_info(&workspace_name)
.package_info(&workspace_name)
.ok_or_else(|| Error::MissingWorkspace(workspace_name.to_string()))
}

Expand Down
14 changes: 7 additions & 7 deletions crates/turborepo-lib/src/task_graph/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ impl<'a> Visitor<'a> {
let crate::engine::Message { info, callback } = message;
let package_name = PackageName::from(info.package());

let workspace_info = self
.package_graph
.workspace_info(&package_name)
.ok_or_else(|| Error::MissingPackage {
package_name: package_name.clone(),
task_id: info.clone(),
})?;
let workspace_info =
self.package_graph
.package_info(&package_name)
.ok_or_else(|| Error::MissingPackage {
package_name: package_name.clone(),
task_id: info.clone(),
})?;

let package_task_event =
PackageTaskEventBuilder::new(info.package(), info.task()).with_parent(telemetry);
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-repository/src/change_mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<'a> ChangeMapper<'a> {
let mut changed_packages = HashSet::new();
for file in files {
let mut found = false;
for (name, entry) in graph.workspaces() {
for (name, entry) in graph.packages() {
if name == &PackageName::Root {
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions crates/turborepo-repository/src/package_graph/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ impl<'a, T: PackageDiscovery> BuildState<'a, ResolvedPackageManager, T> {

debug_assert!(single, "expected single package graph");
Ok(PackageGraph {
workspace_graph,
graph: workspace_graph,
node_lookup,
workspaces,
packages: workspaces,
lockfile,
package_manager,
})
Expand Down Expand Up @@ -514,9 +514,9 @@ impl<'a, T: PackageDiscovery> BuildState<'a, ResolvedLockfile, T> {
..
} = self;
Ok(PackageGraph {
workspace_graph,
graph: workspace_graph,
node_lookup,
workspaces,
packages: workspaces,
package_manager,
lockfile,
})
Expand Down
Loading

0 comments on commit 46cb4d2

Please sign in to comment.