-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
fix(core): optimize daemon output glob matching #27775
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
15f848d
chore(repo): wip
FrozenPandaz d931e75
fix(misc): fix
FrozenPandaz 818fbd5
fix(core): optimize glob output resolution time
AgentEnder 1c3b07d
chore(core): code review
AgentEnder f601907
fix(storybook): use correct outputs
AgentEnder c453042
chore(core): fixes
FrozenPandaz e70bbbd
chore(storybook): update snapshots
AgentEnder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod cache; | ||
pub mod expand_outputs; | ||
pub mod file_ops; | ||
pub mod cache; | ||
pub mod validate_outputs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use itertools::Itertools; | ||
use regex::Regex; | ||
|
||
use crate::native::glob::{contains_glob_pattern, glob_transform::partition_glob}; | ||
|
||
const ALLOWED_WORKSPACE_ROOT_OUTPUT_PREFIXES: [&str; 2] = ["!{workspaceRoot}", "{workspaceRoot}"]; | ||
|
||
fn is_missing_prefix(output: &str) -> bool { | ||
let re = Regex::new(r"^!?\{[\s\S]+\}").expect("Output pattern regex should compile"); | ||
|
||
!re.is_match(output) | ||
} | ||
|
||
#[napi] | ||
pub fn validate_outputs(outputs: Vec<String>) -> anyhow::Result<()> { | ||
let outputs_len = outputs.len(); | ||
let mut missing_prefix = Vec::with_capacity(outputs_len); | ||
let mut workspace_globs = Vec::with_capacity(outputs_len); | ||
|
||
for output in outputs.iter() { | ||
if is_missing_prefix(output) { | ||
missing_prefix.push(output); | ||
} else { | ||
for prefix in ALLOWED_WORKSPACE_ROOT_OUTPUT_PREFIXES.iter() { | ||
if let Some(trimmed) = output.strip_prefix(prefix) { | ||
if contains_glob_pattern(&trimmed) { | ||
let (root, _) = partition_glob(&trimmed)?; | ||
if root.is_empty() { | ||
workspace_globs.push(output); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if workspace_globs.is_empty() && missing_prefix.is_empty() { | ||
return Ok(()); | ||
} | ||
|
||
let mut error_message = String::new(); | ||
if !missing_prefix.is_empty() { | ||
error_message.push_str(&format!( | ||
"The following outputs are invalid: \n - {}\n\nRun `nx repair` to fix this.", | ||
missing_prefix.iter().join("\n - ") | ||
)); | ||
} | ||
if !workspace_globs.is_empty() { | ||
error_message.push_str(&format!( | ||
"The following outputs are defined by a glob pattern from the workspace root: \n - {}\n\nThese can be slow, replace them with a more specific pattern.", | ||
workspace_globs.iter().join("\n - ") | ||
)); | ||
} | ||
|
||
Err(anyhow::anyhow!(error_message)) | ||
} | ||
|
||
#[napi] | ||
pub fn get_transformable_outputs(outputs: Vec<String>) -> Vec<String> { | ||
outputs | ||
.into_iter() | ||
.filter(|output| is_missing_prefix(output)) | ||
.collect() | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::is_missing_prefix; | ||
|
||
#[test] | ||
fn test_is_missing_prefix() { | ||
assert!(is_missing_prefix("dist")); | ||
assert!(is_missing_prefix("!dist")); | ||
assert!(!is_missing_prefix("{workspaceRoot}/dist")); | ||
assert!(!is_missing_prefix("!{workspaceRoot}/dist")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we use the multi-threaded walker below?
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.
We can do this some other time.