Skip to content

Commit

Permalink
Add ability to filter out files excluded by excludes_extensions option
Browse files Browse the repository at this point in the history
Reviewed By: tyao1

Differential Revision: D61721120

fbshipit-source-id: 21963a58f1cf12c3b458cf97ab3f61d4a28049e4
  • Loading branch information
monicatang authored and facebook-github-bot committed Sep 9, 2024
1 parent a1c09cf commit 87d1ef6
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 65 deletions.
1 change: 1 addition & 0 deletions compiler/crates/relay-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extract-graphql = { path = "../extract-graphql" }
fnv = "1.0"
futures = { version = "0.3.30", features = ["async-await", "compat"] }
glob = "0.3"
globset = { version = "0.4.13", features = ["serde1"] }
graphql-cli = { path = "../graphql-cli" }
graphql-ir = { path = "../graphql-ir" }
graphql-syntax = { path = "../graphql-syntax" }
Expand Down
10 changes: 10 additions & 0 deletions compiler/crates/relay-compiler/relay-compiler-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3017,6 +3017,16 @@
"null"
]
},
"excludesExtensions": {
"description": "Some projects may need to exclude files with certain extensions.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"extra": {
"description": "A placeholder for allowing extra information in the config file",
"default": null
Expand Down
17 changes: 17 additions & 0 deletions compiler/crates/relay-compiler/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use common::ScalarName;
use dunce::canonicalize;
use fnv::FnvBuildHasher;
use fnv::FnvHashSet;
use globset::Glob;
use globset::GlobSetBuilder;
use graphql_ir::OperationDefinition;
use graphql_ir::Program;
use indexmap::IndexMap;
Expand Down Expand Up @@ -385,13 +387,25 @@ impl Config {
}],
})?;

let excludes_extensions_set =
config_file_project
.excludes_extensions
.map(move |extensions| {
let mut builder = GlobSetBuilder::new();
for ext in extensions {
builder.add(Glob::new(&ext).unwrap());
}
builder.build().unwrap()
});

let project_config = ProjectConfig {
name: project_name,
base: config_file_project.base,
enabled: true,
schema_extensions: config_file_project.schema_extensions,
extra_artifacts_config: None,
extra: config_file_project.extra,
excludes_extensions: excludes_extensions_set,
output: config_file_project.output,
extra_artifacts_output: config_file_project.extra_artifacts_output,
shard_output: config_file_project.shard_output,
Expand Down Expand Up @@ -994,6 +1008,9 @@ pub struct ConfigFileProject {
/// By default the will use `output` *if available
extra_artifacts_output: Option<PathBuf>,

/// Some projects may need to exclude files with certain extensions.
excludes_extensions: Option<Vec<String>>,

/// If `output` is provided and `shard_output` is `true`, shard the files
/// by putting them under `{output_dir}/{source_relative_path}`
#[serde(default)]
Expand Down
Loading

0 comments on commit 87d1ef6

Please sign in to comment.