-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
do not automatically remove files not generated by Relay #3700
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -40,6 +40,7 @@ use log::{debug, info, warn}; | |||||||||
use rayon::{iter::IntoParallelRefIterator, slice::ParallelSlice}; | ||||||||||
use relay_codegen::Printer; | ||||||||||
use relay_transforms::{apply_transforms, find_resolver_dependencies, DependencyMap, Programs}; | ||||||||||
use relay_typegen::TypegenLanguage; | ||||||||||
use schema::SDLSchema; | ||||||||||
pub use source_control::add_to_mercurial; | ||||||||||
use std::iter::FromIterator; | ||||||||||
|
@@ -205,6 +206,14 @@ pub fn build_programs( | |||||||||
Ok((programs, Arc::new(source_hashes))) | ||||||||||
} | ||||||||||
|
||||||||||
fn is_relay_file_path(language: &TypegenLanguage, path: &PathBuf) -> bool { | ||||||||||
match (path.to_str(), &language) { | ||||||||||
(None, _) => false, | ||||||||||
(Some(path), TypegenLanguage::Flow) => path.ends_with(".graphql.js"), | ||||||||||
(Some(path), TypegenLanguage::TypeScript) => path.ends_with(".graphql.ts"), | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
pub fn build_project( | ||||||||||
config: &Config, | ||||||||||
project_config: &ProjectConfig, | ||||||||||
|
@@ -373,7 +382,9 @@ pub async fn commit_project( | |||||||||
break; | ||||||||||
} | ||||||||||
let path = config.root_dir.join(remaining_artifact); | ||||||||||
config.artifact_writer.remove(path)?; | ||||||||||
if is_relay_file_path(&project_config.typegen_config.language, &path) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is mostly nits (and not sure if it makes it better). But can we move this function to the artifact_writer? We already have
I think we can also add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd need to make sure that the typegen config is added to the artifact_writer if so, but maybe it's ok to add that? Or I could do a typegen unaware check and just check for .graphql.js or .graphql.ts always. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's fine to do a check without typegen config. What do you think about alternative approach, where we would filter these non-relay artifacts in the Somewhere here: relay/compiler/crates/relay-compiler/src/file_source/file_categorizer.rs Lines 237 to 239 in a07750f
|
||||||||||
config.artifact_writer.remove(path)?; | ||||||||||
} | ||||||||||
} | ||||||||||
log_event.stop(delete_artifacts_time); | ||||||||||
ArtifactMap::from(artifacts) | ||||||||||
|
@@ -443,7 +454,9 @@ pub async fn commit_project( | |||||||||
if should_stop_updating_artifacts() { | ||||||||||
break; | ||||||||||
} | ||||||||||
config.artifact_writer.remove(config.root_dir.join(path))?; | ||||||||||
if is_relay_file_path(&project_config.typegen_config.language, &path) { | ||||||||||
config.artifact_writer.remove(config.root_dir.join(path))?; | ||||||||||
} | ||||||||||
} | ||||||||||
log_event.stop(delete_artifacts_incremental_time); | ||||||||||
|
||||||||||
|
@@ -513,3 +526,42 @@ fn write_artifacts<F: Fn() -> bool + Sync + Send>( | |||||||||
)?; | ||||||||||
Ok(()) | ||||||||||
} | ||||||||||
|
||||||||||
#[cfg(test)] | ||||||||||
mod tests { | ||||||||||
use super::*; | ||||||||||
#[test] | ||||||||||
fn matches_relay_file_paths_properly() { | ||||||||||
assert_eq!( | ||||||||||
is_relay_file_path( | ||||||||||
&TypegenLanguage::Flow, | ||||||||||
&PathBuf::from("/some/folder/here/SomeModule.graphql.js") | ||||||||||
), | ||||||||||
true | ||||||||||
); | ||||||||||
|
||||||||||
assert_eq!( | ||||||||||
is_relay_file_path( | ||||||||||
&TypegenLanguage::TypeScript, | ||||||||||
&PathBuf::from("/some/folder/here/SomeModule.graphql.ts") | ||||||||||
), | ||||||||||
true | ||||||||||
); | ||||||||||
|
||||||||||
assert_eq!( | ||||||||||
is_relay_file_path( | ||||||||||
&TypegenLanguage::Flow, | ||||||||||
&PathBuf::from("/some/folder/here/SomeRandomFile.js") | ||||||||||
), | ||||||||||
false | ||||||||||
); | ||||||||||
|
||||||||||
assert_eq!( | ||||||||||
is_relay_file_path( | ||||||||||
&TypegenLanguage::TypeScript, | ||||||||||
&PathBuf::from("/some/folder/here/SomeRandomFile.ts") | ||||||||||
), | ||||||||||
false | ||||||||||
); | ||||||||||
} | ||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to convert this
to_str()
?can you use this: https://doc.rust-lang.org/std/path/struct.Path.html#method.ends_with?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think so, because it seems ends_with there only checks for entire chunks of the path. So that ends_with would mean the entire last chunk (the full file name in this case), which isn't what we're after. I tried using that function first. But maybe there's a better alternative still.