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

Add new option to support compiling a single project #3868

Closed
wants to merge 4 commits into from
Closed
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
40 changes: 28 additions & 12 deletions compiler/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 compiler/crates/relay-bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ schema-documentation = { path = "../schema-documentation" }
simplelog = "0.10.0"
thiserror = "1.0.30"
tokio = { version = "1.15", features = ["full", "test-util", "tracing"] }
intern = { path = "../intern" }
3 changes: 3 additions & 0 deletions compiler/crates/relay-bin/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use thiserror::Error;

#[derive(Debug, Error)]
pub enum Error {
#[error("Unable to filter projects. Error details: \n{details}")]
ProjectFilterError { details: String },

#[error("Unable to run the relay language server. Error details: \n{details}")]
LSPError { details: String },

Expand Down
41 changes: 41 additions & 0 deletions compiler/crates/relay-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use clap::{ArgEnum, Parser};
use common::ConsoleLogger;
use intern::string_key::Intern;
use log::{error, info};
use relay_compiler::{
build_project::artifact_writer::ArtifactValidationWriter, compiler::Compiler, config::Config,
Expand Down Expand Up @@ -56,6 +57,11 @@ struct CompileCommand {
#[clap(long, short)]
watch: bool,

/// Compile only this project. You can pass this argument multiple times.
/// to compile multiple projects. If excluded, all projects will be compiled.
#[clap(name = "project", long, short)]
projects: Vec<String>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect this to just be project and that you would specify it multiple times to specify multiple projects. Can you confirm what it actually looks like to pass multiple projects? I think it would be not great to have to pass multiple projects using one flag (how are you supposed to delineate them? commas? spaces?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I think it doesn't do any space / command delimiting by default. I updated the language a bit to better explain.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Can just make this --project?

Suggested change
projects: Vec<String>,
project: Vec<String>,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@captbaritone Incase it isn't clear from the code. I kept the rust name as projects since it truly is a list of projects to compile. The clap name is project since the user can pass projects like so --project projectA --project projectB


/// Compile using this config file. If not provided, searches for a config in
/// package.json under the `relay` key or `relay.config.json` files among other up
/// from the current working directory.
Expand Down Expand Up @@ -191,6 +197,39 @@ fn configure_logger(output: OutputKind, terminal_mode: TerminalMode) {
TermLogger::init(log_level, log_config, terminal_mode, ColorChoice::Auto).unwrap();
}

/// Update Config if the `project` flag is set
fn set_project_flag(config: &mut Config, project: Vec<String>) -> Result<(), Error> {
if project.is_empty() {
return Ok(());
}

for project_config in config.projects.values_mut() {
project_config.enabled = false;
}
for selected_project in project {
let selected_project = selected_project.intern();

if let Some(project_config) = config.projects.get_mut(&selected_project) {
project_config.enabled = true;
} else {
return Err(Error::ProjectFilterError {
details: format!(
"Project `{}` not found, available projects: {}.",
selected_project,
config
.projects
.keys()
.map(|name| name.lookup())
.collect::<Vec<_>>()
.join(", ")
),
});
}
}

return Ok(());
}

async fn handle_compiler_command(command: CompileCommand) -> Result<(), Error> {
configure_logger(command.output, TerminalMode::Mixed);

Expand All @@ -205,6 +244,8 @@ async fn handle_compiler_command(command: CompileCommand) -> Result<(), Error> {

let mut config = get_config(command.config)?;

set_project_flag(&mut config, command.projects)?;

tbezman marked this conversation as resolved.
Show resolved Hide resolved
if command.validate {
config.artifact_writer = Box::new(ArtifactValidationWriter::default());
}
Expand Down