Apply an instance's `expected_specifier` to the package.json. Dispatches over the dependency type's `Strategy`. Marks the file dirty only when the stored value actually changed.
(file: &mut File<JsonValue>, instance: &Instance)
| 681 | /// over the dependency type's `Strategy`. Marks the file dirty only when the |
| 682 | /// stored value actually changed. |
| 683 | pub fn copy_expected_specifier_json(file: &mut File<JsonValue>, instance: &Instance) { |
| 684 | let path_to_prop_str = &instance.descriptor.dependency_type.path.as_str(); |
| 685 | let raw_specifier = instance.expected_specifier.borrow().as_ref().unwrap().get_raw().to_string(); |
| 686 | match instance.descriptor.dependency_type.strategy { |
| 687 | Strategy::NameAndVersionProps => { |
| 688 | set_prop(file, path_to_prop_str, JsonValue::String(raw_specifier)); |
| 689 | } |
| 690 | Strategy::NamedVersionString => { |
| 691 | let full_value = format!("{}@{}", instance.descriptor.name, raw_specifier); |
| 692 | set_prop(file, path_to_prop_str, JsonValue::String(full_value)); |
| 693 | } |
| 694 | Strategy::UnnamedVersionString => { |
| 695 | set_prop(file, path_to_prop_str, JsonValue::String(raw_specifier)); |
| 696 | } |
| 697 | Strategy::VersionsByName => { |
| 698 | set_nested_prop(file, path_to_prop_str, &instance.descriptor.name, JsonValue::String(raw_specifier)); |
| 699 | } |
| 700 | Strategy::InvalidConfig => { |
| 701 | unreachable!("unrecognised strategy"); |
| 702 | } |
| 703 | }; |
| 704 | } |
| 705 | |
| 706 | /// Eagerly convert the parsed yaml into an owned `serde_json::Value`. No |
| 707 | /// caching — every call allocates a fresh Value. Caller is expected to |
searching dependent graphs…