Support .jsonc extension for all JSON files (#1159)

This commit is contained in:
Micah
2025-11-18 18:47:43 -08:00
committed by GitHub
parent 03410ced6d
commit ea70d89291
46 changed files with 759 additions and 153 deletions

View File

@@ -1,6 +1,6 @@
use std::path::Path;
use memofs::{IoResultExt, Vfs};
use memofs::Vfs;
use rbx_dom_weak::ustr;
use crate::{
@@ -25,8 +25,6 @@ pub fn snapshot_json(
let as_lua = json_to_lua(value).to_string();
let meta_path = path.with_file_name(format!("{}.meta.json", name));
let mut snapshot = InstanceSnapshot::new()
.name(name)
.class_name("ModuleScript")
@@ -34,14 +32,11 @@ pub fn snapshot_json(
.metadata(
InstanceMetadata::new()
.instigating_source(path)
.relevant_paths(vec![path.to_path_buf(), meta_path.clone()])
.relevant_paths(vec![path.to_path_buf()])
.context(context),
);
if let Some(meta_contents) = vfs.read(&meta_path).with_not_found()? {
let mut metadata = AdjacentMetadata::from_slice(&meta_contents, meta_path)?;
metadata.apply_all(&mut snapshot)?;
}
AdjacentMetadata::read_and_apply_all(vfs, path, name, &mut snapshot)?;
Ok(Some(snapshot))
}
@@ -111,4 +106,42 @@ mod test {
insta::assert_yaml_snapshot!(instance_snapshot);
}
#[test]
fn with_metadata() {
let mut imfs = InMemoryFs::new();
imfs.load_snapshot(
"/foo.json",
VfsSnapshot::file(
r#"{
"array": [1, 2, 3],
"int": 1234,
"float": 1234.5452,
}"#,
),
)
.unwrap();
imfs.load_snapshot(
"/foo.meta.json",
VfsSnapshot::file(
r#"{
"id": "manually specified"
}"#,
),
)
.unwrap();
let vfs = Vfs::new(imfs.clone());
let instance_snapshot = snapshot_json(
&InstanceContext::default(),
&vfs,
Path::new("/foo.json"),
"foo",
)
.unwrap()
.unwrap();
insta::assert_yaml_snapshot!(instance_snapshot);
}
}