-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix case where lockfiles are added into a repo
If a lock-file is added into the repository then we will consider all dependency paths changed. Test Plan: cargo build Reviewers: pancaspe87 Reviewed By: pancaspe87 Pull Request: #350
- Loading branch information
Showing
4 changed files
with
74 additions
and
19 deletions.
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