Make sure every segment of `pointer` exists as a `Value::Object`. Walks one segment at a time, creating empty objects en route. The empty-string parent (`""`) resolves to the document root per RFC 6901.
(file: &mut File<JsonValue>, pointer: &str)
| 665 | /// one segment at a time, creating empty objects en route. The empty-string |
| 666 | /// parent (`""`) resolves to the document root per RFC 6901. |
| 667 | pub fn ensure_object_path(file: &mut File<JsonValue>, pointer: &str) { |
| 668 | let segments: Vec<&str> = pointer.split('/').filter(|s| !s.is_empty()).collect(); |
| 669 | let mut current = String::new(); |
| 670 | for segment in segments { |
| 671 | let parent = current.clone(); |
| 672 | current.push('/'); |
| 673 | current.push_str(segment); |
| 674 | if !matches!(file.contents.pointer(¤t), Some(JsonValue::Object(_))) { |
| 675 | set_nested_prop(file, &parent, segment, JsonValue::Object(Default::default())); |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | /// Apply an instance's `expected_specifier` to the package.json. Dispatches |
| 681 | /// over the dependency type's `Strategy`. Marks the file dirty only when the |
searching dependent graphs…