Skip to content

Commit

Permalink
Refactor extra artifact project config fields into extra_artifacts_co…
Browse files Browse the repository at this point in the history
…nfig

Reviewed By: tyao1

Differential Revision: D51673560

fbshipit-source-id: ad95d5f0bf48658ba900697b3cdb1ecaff21fe99
  • Loading branch information
monicatang authored and facebook-github-bot committed Dec 1, 2023
1 parent cefb442 commit 1cc9d93
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 35 deletions.
10 changes: 6 additions & 4 deletions compiler/crates/relay-compiler/src/artifact_content/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ impl ArtifactContent {
source_file: SourceLocationKey,
fragment_locations: &FragmentLocations,
) -> Vec<u8> {
let skip_types = project_config
.skip_types_for_artifact
.as_ref()
.map_or(false, |skip_types_fn| skip_types_fn(source_file));
let skip_types =
if let Some(extra_artifacts_config) = &project_config.extra_artifacts_config {
(extra_artifacts_config.skip_types_for_artifact)(source_file)
} else {
false
};
match self {
ArtifactContent::Operation {
normalization_operation,
Expand Down
6 changes: 3 additions & 3 deletions compiler/crates/relay-compiler/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use rayon::prelude::*;
use regex::Regex;
use relay_config::CustomScalarType;
use relay_config::DiagnosticReportConfig;
pub use relay_config::ExtraArtifactsConfig;
use relay_config::FlowTypegenConfig;
use relay_config::JsModuleFormat;
pub use relay_config::LocalPersistConfig;
Expand Down Expand Up @@ -356,6 +357,8 @@ Example file:
base: config_file_project.base,
enabled: true,
schema_extensions: config_file_project.schema_extensions,
extra_artifacts_config: None,
extra: config_file_project.extra,
output: config_file_project.output,
extra_artifacts_output: config_file_project.extra_artifacts_output,
shard_output: config_file_project.shard_output,
Expand All @@ -365,15 +368,12 @@ Example file:
typegen_config: config_file_project.typegen_config,
persist: config_file_project.persist,
variable_names_comment: config_file_project.variable_names_comment,
extra: config_file_project.extra,
test_path_regex,
feature_flags: Arc::new(
config_file_project
.feature_flags
.unwrap_or_else(|| config_file_feature_flags.clone()),
),
filename_for_artifact: None,
skip_types_for_artifact: None,
rollout: config_file_project.rollout,
js_module_format: config_file_project.js_module_format,
module_import_config: config_file_project.module_import_config,
Expand Down
1 change: 1 addition & 0 deletions compiler/crates/relay-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub use js_module_format::JsModuleFormat;
pub use module_import_config::DynamicModuleProvider;
pub use module_import_config::ModuleImportConfig;
pub use non_node_id_fields_config::NonNodeIdFieldsConfig;
pub use project_config::ExtraArtifactsConfig;
pub use project_config::LocalPersistAlgorithm;
pub use project_config::LocalPersistConfig;
pub use project_config::PersistConfig;
Expand Down
51 changes: 23 additions & 28 deletions compiler/crates/relay-config/src/project_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ pub enum SchemaLocation {
Directory(PathBuf),
}

pub struct ExtraArtifactsConfig {
pub filename_for_artifact: Box<dyn (Fn(SourceLocationKey, StringKey) -> String) + Send + Sync>,
pub skip_types_for_artifact: Box<dyn (Fn(SourceLocationKey) -> bool) + Send + Sync>,
}

impl Debug for ExtraArtifactsConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ExtraArtifactsConfig")
.field("filename_for_artifact", &"Fn")
.field("skip_types_for_artifact", &"Fn")
.finish()
}
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SchemaConfig {
Expand Down Expand Up @@ -214,8 +228,9 @@ impl Default for SchemaConfig {
pub struct ProjectConfig {
pub name: ProjectName,
pub base: Option<ProjectName>,
pub output: Option<PathBuf>,
pub extra_artifacts_output: Option<PathBuf>,
pub extra_artifacts_config: Option<ExtraArtifactsConfig>,
pub output: Option<PathBuf>,
pub shard_output: bool,
pub shard_strip_regex: Option<Regex>,
pub schema_extensions: Vec<PathBuf>,
Expand All @@ -228,9 +243,6 @@ pub struct ProjectConfig {
pub extra: serde_json::Value,
pub feature_flags: Arc<FeatureFlags>,
pub test_path_regex: Option<Regex>,
pub filename_for_artifact:
Option<Box<dyn (Fn(SourceLocationKey, StringKey) -> String) + Send + Sync>>,
pub skip_types_for_artifact: Option<Box<dyn (Fn(SourceLocationKey) -> bool) + Send + Sync>>,
pub rollout: Rollout,
pub js_module_format: JsModuleFormat,
pub module_import_config: ModuleImportConfig,
Expand All @@ -244,8 +256,9 @@ impl Default for ProjectConfig {
name: ProjectName::default(),
feature_flags: Default::default(),
base: None,
output: None,
extra_artifacts_output: None,
extra_artifacts_config: None,
output: None,
shard_output: false,
shard_strip_regex: None,
schema_extensions: vec![],
Expand All @@ -257,8 +270,6 @@ impl Default for ProjectConfig {
variable_names_comment: false,
extra: Default::default(),
test_path_regex: None,
filename_for_artifact: None,
skip_types_for_artifact: None,
rollout: Default::default(),
js_module_format: Default::default(),
module_import_config: Default::default(),
Expand All @@ -273,8 +284,9 @@ impl Debug for ProjectConfig {
let ProjectConfig {
name,
base,
output,
extra_artifacts_output,
extra_artifacts_config,
output,
shard_output,
shard_strip_regex,
schema_extensions,
Expand All @@ -287,8 +299,6 @@ impl Debug for ProjectConfig {
extra,
feature_flags,
test_path_regex,
filename_for_artifact,
skip_types_for_artifact,
rollout,
js_module_format,
module_import_config,
Expand All @@ -299,6 +309,7 @@ impl Debug for ProjectConfig {
.field("name", name)
.field("base", base)
.field("output", output)
.field("extra_artifacts_config", extra_artifacts_config)
.field("extra_artifacts_output", extra_artifacts_output)
.field("shard_output", shard_output)
.field("shard_strip_regex", shard_strip_regex)
Expand All @@ -312,22 +323,6 @@ impl Debug for ProjectConfig {
.field("extra", extra)
.field("feature_flags", feature_flags)
.field("test_path_regex", test_path_regex)
.field(
"filename_for_artifact",
&if filename_for_artifact.is_some() {
"Some<Fn>"
} else {
"None"
},
)
.field(
"skip_types_for_artifact",
&if skip_types_for_artifact.is_some() {
"Some<Fn>"
} else {
"None"
},
)
.field("rollout", rollout)
.field("js_module_format", js_module_format)
.field("module_import_config", module_import_config)
Expand Down Expand Up @@ -374,8 +369,8 @@ impl ProjectConfig {
) -> PathBuf {
let source_location = definition_name.location.source_location();
let artifact_name = definition_name.item.into();
let filename = if let Some(filename_for_artifact) = &self.filename_for_artifact {
filename_for_artifact(source_location, artifact_name)
let filename = if let Some(extra_artifacts_config) = &self.extra_artifacts_config {
(extra_artifacts_config.filename_for_artifact)(source_location, artifact_name)
} else {
match &self.typegen_config.language {
TypegenLanguage::Flow | TypegenLanguage::JavaScript => {
Expand Down

0 comments on commit 1cc9d93

Please sign in to comment.