Skip to content

Commit 1cc9d93

Browse files
monicatangfacebook-github-bot
authored andcommitted
Refactor extra artifact project config fields into extra_artifacts_config
Reviewed By: tyao1 Differential Revision: D51673560 fbshipit-source-id: ad95d5f0bf48658ba900697b3cdb1ecaff21fe99
1 parent cefb442 commit 1cc9d93

File tree

4 files changed

+33
-35
lines changed

4 files changed

+33
-35
lines changed

compiler/crates/relay-compiler/src/artifact_content/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ impl ArtifactContent {
6666
source_file: SourceLocationKey,
6767
fragment_locations: &FragmentLocations,
6868
) -> Vec<u8> {
69-
let skip_types = project_config
70-
.skip_types_for_artifact
71-
.as_ref()
72-
.map_or(false, |skip_types_fn| skip_types_fn(source_file));
69+
let skip_types =
70+
if let Some(extra_artifacts_config) = &project_config.extra_artifacts_config {
71+
(extra_artifacts_config.skip_types_for_artifact)(source_file)
72+
} else {
73+
false
74+
};
7375
match self {
7476
ArtifactContent::Operation {
7577
normalization_operation,

compiler/crates/relay-compiler/src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use rayon::prelude::*;
3131
use regex::Regex;
3232
use relay_config::CustomScalarType;
3333
use relay_config::DiagnosticReportConfig;
34+
pub use relay_config::ExtraArtifactsConfig;
3435
use relay_config::FlowTypegenConfig;
3536
use relay_config::JsModuleFormat;
3637
pub use relay_config::LocalPersistConfig;
@@ -356,6 +357,8 @@ Example file:
356357
base: config_file_project.base,
357358
enabled: true,
358359
schema_extensions: config_file_project.schema_extensions,
360+
extra_artifacts_config: None,
361+
extra: config_file_project.extra,
359362
output: config_file_project.output,
360363
extra_artifacts_output: config_file_project.extra_artifacts_output,
361364
shard_output: config_file_project.shard_output,
@@ -365,15 +368,12 @@ Example file:
365368
typegen_config: config_file_project.typegen_config,
366369
persist: config_file_project.persist,
367370
variable_names_comment: config_file_project.variable_names_comment,
368-
extra: config_file_project.extra,
369371
test_path_regex,
370372
feature_flags: Arc::new(
371373
config_file_project
372374
.feature_flags
373375
.unwrap_or_else(|| config_file_feature_flags.clone()),
374376
),
375-
filename_for_artifact: None,
376-
skip_types_for_artifact: None,
377377
rollout: config_file_project.rollout,
378378
js_module_format: config_file_project.js_module_format,
379379
module_import_config: config_file_project.module_import_config,

compiler/crates/relay-config/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub use js_module_format::JsModuleFormat;
2828
pub use module_import_config::DynamicModuleProvider;
2929
pub use module_import_config::ModuleImportConfig;
3030
pub use non_node_id_fields_config::NonNodeIdFieldsConfig;
31+
pub use project_config::ExtraArtifactsConfig;
3132
pub use project_config::LocalPersistAlgorithm;
3233
pub use project_config::LocalPersistConfig;
3334
pub use project_config::PersistConfig;

compiler/crates/relay-config/src/project_config.rs

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,20 @@ pub enum SchemaLocation {
161161
Directory(PathBuf),
162162
}
163163

164+
pub struct ExtraArtifactsConfig {
165+
pub filename_for_artifact: Box<dyn (Fn(SourceLocationKey, StringKey) -> String) + Send + Sync>,
166+
pub skip_types_for_artifact: Box<dyn (Fn(SourceLocationKey) -> bool) + Send + Sync>,
167+
}
168+
169+
impl Debug for ExtraArtifactsConfig {
170+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
171+
f.debug_struct("ExtraArtifactsConfig")
172+
.field("filename_for_artifact", &"Fn")
173+
.field("skip_types_for_artifact", &"Fn")
174+
.finish()
175+
}
176+
}
177+
164178
#[derive(Debug, Serialize, Deserialize)]
165179
#[serde(rename_all = "camelCase")]
166180
pub struct SchemaConfig {
@@ -214,8 +228,9 @@ impl Default for SchemaConfig {
214228
pub struct ProjectConfig {
215229
pub name: ProjectName,
216230
pub base: Option<ProjectName>,
217-
pub output: Option<PathBuf>,
218231
pub extra_artifacts_output: Option<PathBuf>,
232+
pub extra_artifacts_config: Option<ExtraArtifactsConfig>,
233+
pub output: Option<PathBuf>,
219234
pub shard_output: bool,
220235
pub shard_strip_regex: Option<Regex>,
221236
pub schema_extensions: Vec<PathBuf>,
@@ -228,9 +243,6 @@ pub struct ProjectConfig {
228243
pub extra: serde_json::Value,
229244
pub feature_flags: Arc<FeatureFlags>,
230245
pub test_path_regex: Option<Regex>,
231-
pub filename_for_artifact:
232-
Option<Box<dyn (Fn(SourceLocationKey, StringKey) -> String) + Send + Sync>>,
233-
pub skip_types_for_artifact: Option<Box<dyn (Fn(SourceLocationKey) -> bool) + Send + Sync>>,
234246
pub rollout: Rollout,
235247
pub js_module_format: JsModuleFormat,
236248
pub module_import_config: ModuleImportConfig,
@@ -244,8 +256,9 @@ impl Default for ProjectConfig {
244256
name: ProjectName::default(),
245257
feature_flags: Default::default(),
246258
base: None,
247-
output: None,
248259
extra_artifacts_output: None,
260+
extra_artifacts_config: None,
261+
output: None,
249262
shard_output: false,
250263
shard_strip_regex: None,
251264
schema_extensions: vec![],
@@ -257,8 +270,6 @@ impl Default for ProjectConfig {
257270
variable_names_comment: false,
258271
extra: Default::default(),
259272
test_path_regex: None,
260-
filename_for_artifact: None,
261-
skip_types_for_artifact: None,
262273
rollout: Default::default(),
263274
js_module_format: Default::default(),
264275
module_import_config: Default::default(),
@@ -273,8 +284,9 @@ impl Debug for ProjectConfig {
273284
let ProjectConfig {
274285
name,
275286
base,
276-
output,
277287
extra_artifacts_output,
288+
extra_artifacts_config,
289+
output,
278290
shard_output,
279291
shard_strip_regex,
280292
schema_extensions,
@@ -287,8 +299,6 @@ impl Debug for ProjectConfig {
287299
extra,
288300
feature_flags,
289301
test_path_regex,
290-
filename_for_artifact,
291-
skip_types_for_artifact,
292302
rollout,
293303
js_module_format,
294304
module_import_config,
@@ -299,6 +309,7 @@ impl Debug for ProjectConfig {
299309
.field("name", name)
300310
.field("base", base)
301311
.field("output", output)
312+
.field("extra_artifacts_config", extra_artifacts_config)
302313
.field("extra_artifacts_output", extra_artifacts_output)
303314
.field("shard_output", shard_output)
304315
.field("shard_strip_regex", shard_strip_regex)
@@ -312,22 +323,6 @@ impl Debug for ProjectConfig {
312323
.field("extra", extra)
313324
.field("feature_flags", feature_flags)
314325
.field("test_path_regex", test_path_regex)
315-
.field(
316-
"filename_for_artifact",
317-
&if filename_for_artifact.is_some() {
318-
"Some<Fn>"
319-
} else {
320-
"None"
321-
},
322-
)
323-
.field(
324-
"skip_types_for_artifact",
325-
&if skip_types_for_artifact.is_some() {
326-
"Some<Fn>"
327-
} else {
328-
"None"
329-
},
330-
)
331326
.field("rollout", rollout)
332327
.field("js_module_format", js_module_format)
333328
.field("module_import_config", module_import_config)
@@ -374,8 +369,8 @@ impl ProjectConfig {
374369
) -> PathBuf {
375370
let source_location = definition_name.location.source_location();
376371
let artifact_name = definition_name.item.into();
377-
let filename = if let Some(filename_for_artifact) = &self.filename_for_artifact {
378-
filename_for_artifact(source_location, artifact_name)
372+
let filename = if let Some(extra_artifacts_config) = &self.extra_artifacts_config {
373+
(extra_artifacts_config.filename_for_artifact)(source_location, artifact_name)
379374
} else {
380375
match &self.typegen_config.language {
381376
TypegenLanguage::Flow | TypegenLanguage::JavaScript => {

0 commit comments

Comments
 (0)