-
Notifications
You must be signed in to change notification settings - Fork 1
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 case where lockfiles are added into a repo #350
Merged
yamadapc
merged 5 commits into
main
from
spr/yamadapc/fix-case-where-lockfiles-are-added-into-a-repo
Feb 20, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@atlaspack/rust': patch | ||
--- | ||
|
||
Fix VCS watcher handling of new yarn.lock files between revisions |
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 |
---|---|---|
|
@@ -39,6 +39,10 @@ impl YarnResolution { | |
#[derive(Debug, Serialize, Deserialize)] | ||
#[serde(transparent)] | ||
pub struct YarnLock { | ||
/// Map of 'requirement' to 'resolution' | ||
/// | ||
/// * requirement -> `@atlaspack/core@^1.0.0` | ||
/// * resolution -> `@atlaspack/core@^1.0.0: @atlaspack/[email protected]` | ||
inner: HashMap<String, YarnLockEntry>, | ||
} | ||
|
||
|
@@ -132,13 +136,16 @@ pub fn parse_yarn_state_file(node_modules_directory: &Path) -> anyhow::Result<Ya | |
|
||
pub fn generate_events( | ||
node_modules_parent_path: &Path, | ||
old_yarn_lock: &YarnLock, | ||
old_yarn_lock: &Option<YarnLock>, | ||
new_yarn_lock: &YarnLock, | ||
state: &YarnStateFile, | ||
) -> Vec<PathBuf> { | ||
let changed_resolutions = new_yarn_lock | ||
.iter() | ||
.filter_map(|(package_name, new_resolution)| { | ||
let Some(old_yarn_lock) = old_yarn_lock.as_ref() else { | ||
return Some(new_resolution); | ||
}; | ||
let Some(old_resolution) = old_yarn_lock.get(package_name) else { | ||
return Some(new_resolution); | ||
}; | ||
|
@@ -156,6 +163,10 @@ pub fn generate_events( | |
|
||
if let Some(dependency_state) = state.get(&resolution.resolution) { | ||
for location in &dependency_state.locations { | ||
if location.is_empty() { | ||
// the workspace is listed as a location, which we can skip | ||
continue; | ||
} | ||
changed_paths.push(node_modules_parent_path.join(location)); | ||
} | ||
} | ||
|
@@ -187,7 +198,36 @@ mod test { | |
|
||
let events = generate_events( | ||
&node_modules_parent_path, | ||
&old_yarn_lock, | ||
&Some(old_yarn_lock), | ||
&new_yarn_lock, | ||
&yarn_state, | ||
); | ||
let events = events | ||
.iter() | ||
.map(|path| path.to_str().unwrap()) | ||
.collect::<Vec<_>>(); | ||
|
||
assert_eq!(events, vec!["node_modules/lodash"]); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_generate_events_when_old_file_is_missing() -> anyhow::Result<()> { | ||
let node_modules_parent_path = PathBuf::from(""); | ||
let cargo_path = Path::new(env!("CARGO_MANIFEST_DIR")); | ||
let samples_path = cargo_path.join("samples"); | ||
let new_yarn_lock_path = samples_path.join("new/yarn-lock"); | ||
let yarn_state_path = samples_path.join("new/yarn-state.yml"); | ||
|
||
let new_yarn_lock = parse_yarn_lock(&std::fs::read_to_string(new_yarn_lock_path)?)?; | ||
let yarn_state: YarnStateFile = | ||
serde_yaml::from_str(&std::fs::read_to_string(yarn_state_path)?)?; | ||
yarn_state.validate()?; | ||
|
||
let events = generate_events( | ||
&node_modules_parent_path, | ||
&None, | ||
&new_yarn_lock, | ||
&yarn_state, | ||
); | ||
|
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
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.
Should we remove this? I can do it in a follow up PR
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.
It can serve as documentation but we can remove it too or write a clearer description