Skip to content

Commit

Permalink
internal: Use new Id struct everywhere. (#861)
Browse files Browse the repository at this point in the history
* Update project/task.

* Update config.

* Update project graph.

* Update actions/deps.

* Update cli.

* Update tests.

* Fix deser.

* Update target.

* Polish.
  • Loading branch information
milesj committed May 30, 2023
1 parent f7f54fd commit 107718d
Show file tree
Hide file tree
Showing 82 changed files with 589 additions and 479 deletions.
18 changes: 17 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ crate-type = ["rlib"]
moon = { path = "../core/moon" }
moon_action_context = { path = "../core/action-context" }
moon_action_pipeline = { path = "../core/action-pipeline" }
moon_common = { path = "../../nextgen/common" }
moon_config = { path = "../core/config" }
moon_constants = { path = "../core/constants" }
moon_dep_graph = { path = "../core/dep-graph" }
Expand Down
20 changes: 11 additions & 9 deletions crates/cli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use crate::enums::{CacheMode, LogLevel, TouchedStatus};
use clap::{Parser, Subcommand};
use clap_complete::Shell;
use moon_action_context::ProfileType;
use moon_config::{FileGlob, ProjectID, TargetID};
use moon_common::Id;
use moon_config::FileGlob;
use moon_target::Target;
use std::path::PathBuf;

pub const BIN_NAME: &str = if cfg!(windows) { "moon.exe" } else { "moon" };
Expand All @@ -29,7 +31,7 @@ pub enum DockerCommands {
)]
Scaffold {
#[arg(required = true, help = "List of project IDs to copy sources for")]
ids: Vec<ProjectID>,
ids: Vec<Id>,

#[arg(long, help = "Additional file globs to include in sources")]
include: Vec<FileGlob>,
Expand All @@ -50,7 +52,7 @@ pub enum MigrateCommands {
)]
FromPackageJson {
#[arg(help = "ID of project to migrate")]
id: ProjectID,
id: Id,
},

#[command(
Expand All @@ -71,7 +73,7 @@ pub enum NodeCommands {
name: String,

#[arg(long, help = "ID of project to run in")]
project: Option<ProjectID>,
project: Option<Id>,
},
}

Expand Down Expand Up @@ -309,7 +311,7 @@ pub enum Commands {
)]
Project {
#[arg(help = "ID of project to display")]
id: ProjectID,
id: Id,

#[arg(long, help = "Print in JSON format")]
json: bool,
Expand All @@ -323,7 +325,7 @@ pub enum Commands {
)]
ProjectGraph {
#[arg(help = "ID of project to *only* graph")]
id: Option<ProjectID>,
id: Option<Id>,

#[arg(long, help = "Print the graph in DOT format")]
dot: bool,
Expand All @@ -338,15 +340,15 @@ pub enum Commands {
)]
Sync,

// moon task <id>
// moon task <target>
#[command(
name = "task",
about = "Display information about a single task.",
alias = "t"
)]
Task {
#[arg(help = "Target of task to display")]
id: TargetID,
target: Target,

#[arg(long, help = "Print in JSON format")]
json: bool,
Expand Down Expand Up @@ -400,7 +402,7 @@ pub enum Commands {
Check {
#[arg(help = "List of project IDs to explicitly check")]
#[clap(group = "projects")]
ids: Vec<ProjectID>,
ids: Vec<Id>,

#[arg(long, help = "Run check for all projects in the workspace")]
#[clap(group = "projects")]
Expand Down
9 changes: 7 additions & 2 deletions crates/cli/src/commands/check.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::commands::run::{run_target, RunOptions};
use crate::helpers::AnyError;
use moon::{generate_project_graph, load_workspace};
use moon_common::Id;
use moon_logger::trace;
use moon_project::Project;
use std::env;
Expand All @@ -13,7 +14,7 @@ pub struct CheckOptions {

const LOG_TARGET: &str = "moon:check";

pub async fn check(project_ids: &[String], options: CheckOptions) -> Result<(), AnyError> {
pub async fn check(project_ids: &[Id], options: CheckOptions) -> Result<(), AnyError> {
let mut workspace = load_workspace().await?;
let project_graph = generate_project_graph(&mut workspace).await?;
let mut projects: Vec<&Project> = vec![];
Expand All @@ -31,7 +32,11 @@ pub async fn check(project_ids: &[String], options: CheckOptions) -> Result<(),
trace!(
target: LOG_TARGET,
"Running for specific projects: {}",
project_ids.join(", ")
project_ids
.iter()
.map(|p| p.to_string())
.collect::<Vec<_>>()
.join(", ")
);

for id in project_ids {
Expand Down
13 changes: 7 additions & 6 deletions crates/cli/src/commands/docker/scaffold.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::MANIFEST_NAME;
use crate::helpers::AnyError;
use moon::{generate_project_graph, load_workspace};
use moon_config::{ProjectID, ProjectLanguage};
use moon_common::Id;
use moon_config::ProjectLanguage;
use moon_constants::CONFIG_DIRNAME;
use moon_error::MoonError;
use moon_platform_detector::detect_language_files;
Expand All @@ -18,8 +19,8 @@ use strum::IntoEnumIterator;
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct DockerManifest {
pub focused_projects: FxHashSet<ProjectID>,
pub unfocused_projects: FxHashSet<ProjectID>,
pub focused_projects: FxHashSet<Id>,
pub unfocused_projects: FxHashSet<Id>,
}

fn copy_files<T: AsRef<str>>(list: &[T], source: &Path, dest: &Path) -> Result<(), MoonError> {
Expand Down Expand Up @@ -116,7 +117,7 @@ fn scaffold_sources_project(
workspace: &Workspace,
project_graph: &ProjectGraph,
docker_sources_root: &Path,
project_id: &str,
project_id: &Id,
manifest: &mut DockerManifest,
) -> Result<(), ProjectGraphError> {
let project = project_graph.get(project_id)?;
Expand All @@ -142,7 +143,7 @@ fn scaffold_sources(
workspace: &Workspace,
project_graph: &ProjectGraph,
docker_root: &Path,
project_ids: &[String],
project_ids: &[Id],
include: &[String],
) -> Result<(), AnyError> {
let docker_sources_root = docker_root.join("sources");
Expand Down Expand Up @@ -192,7 +193,7 @@ fn scaffold_sources(
Ok(())
}

pub async fn scaffold(project_ids: &[String], include: &[String]) -> Result<(), AnyError> {
pub async fn scaffold(project_ids: &[Id], include: &[String]) -> Result<(), AnyError> {
let mut workspace = load_workspace().await?;
let docker_root = workspace.root.join(CONFIG_DIRNAME).join("docker");

Expand Down
3 changes: 1 addition & 2 deletions crates/cli/src/commands/graph/dto.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use moon_config::ProjectID;
use serde::{Deserialize, Serialize};

#[derive(Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
Expand All @@ -9,7 +8,7 @@ pub struct GraphNodeDto {

#[derive(Debug, Serialize, Deserialize)]
pub struct GraphEdgeDto {
pub id: ProjectID,
pub id: String,
pub source: usize,
pub target: usize,
}
Expand Down
7 changes: 2 additions & 5 deletions crates/cli/src/commands/graph/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ use crate::{
helpers::AnyError,
};
use moon::{build_project_graph, load_workspace};
use moon_common::Id;

pub async fn project_graph(
project_id: Option<String>,
dot: bool,
json: bool,
) -> Result<(), AnyError> {
pub async fn project_graph(project_id: Option<Id>, dot: bool, json: bool) -> Result<(), AnyError> {
let mut workspace = load_workspace().await?;
let mut project_build = build_project_graph(&mut workspace).await?;

Expand Down
5 changes: 3 additions & 2 deletions crates/cli/src/commands/migrate/from_package_json.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::check_dirty_repo;
use crate::helpers::AnyError;
use moon::{generate_project_graph, load_workspace};
use moon_common::Id;
use moon_config::{DependencyConfig, DependencyScope, ProjectDependsOn};
use moon_constants::CONFIG_PROJECT_FILENAME;
use moon_error::MoonError;
Expand All @@ -13,7 +14,7 @@ use starbase_utils::yaml;
const LOG_TARGET: &str = "moon:migrate:from-package-json";

pub async fn from_package_json(
project_id: String,
project_id: Id,
skip_touched_files_check: bool,
) -> Result<(), AnyError> {
let mut workspace = load_workspace().await?;
Expand All @@ -26,7 +27,7 @@ pub async fn from_package_json(

// Create a mapping of `package.json` names to project IDs
let project_graph = generate_project_graph(&mut workspace).await?;
let mut package_map: FxHashMap<String, String> = FxHashMap::default();
let mut package_map: FxHashMap<String, Id> = FxHashMap::default();

for project in project_graph.get_all()? {
if let Some(package_json) = PackageJson::read(&project.root)? {
Expand Down
11 changes: 6 additions & 5 deletions crates/cli/src/commands/migrate/from_turborepo.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::check_dirty_repo;
use crate::helpers::AnyError;
use moon::{generate_project_graph, load_workspace};
use moon_common::Id;
use moon_config::{InheritedTasksConfig, PlatformType, ProjectConfig, TaskCommandArgs, TaskConfig};
use moon_constants as constants;
use moon_logger::{info, warn};
Expand Down Expand Up @@ -32,17 +33,17 @@ pub struct TurboJson {
pub pipeline: FxHashMap<String, TurboTask>,
}

pub fn extract_project_task_ids(key: &str) -> (Option<String>, String) {
pub fn extract_project_task_ids(key: &str) -> (Option<Id>, Id) {
if key.contains('#') {
let mut parts = key.split('#');

return (
Some(parts.next().unwrap().to_string()),
parts.next().unwrap().to_string(),
Some(Id::raw(parts.next().unwrap())),
Id::raw(parts.next().unwrap()),
);
}

(None, key.to_owned())
(None, Id::raw(key))
}

pub fn convert_globals(turbo: &TurboJson, tasks_config: &mut InheritedTasksConfig) -> bool {
Expand All @@ -64,7 +65,7 @@ pub fn convert_globals(turbo: &TurboJson, tasks_config: &mut InheritedTasksConfi
modified
}

pub fn convert_task(name: String, task: TurboTask) -> TaskConfig {
pub fn convert_task(name: Id, task: TurboTask) -> TaskConfig {
let mut config = TaskConfig::default();
let mut inputs = vec![];

Expand Down
Loading

0 comments on commit 107718d

Please sign in to comment.