mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
Refactor metadata file name generation in syncback_lua and AdjacentMetadata to strip known script type suffixes (.server, .client, .plugin) for improved compatibility. This change ensures accurate base name extraction for meta files while maintaining handling of Windows-invalid characters.
This commit is contained in:
parent
73684a97bb
commit
033dec4e18
2 changed files with 28 additions and 13 deletions
|
|
@ -159,20 +159,28 @@ pub fn syncback_lua<'sync>(
|
||||||
|
|
||||||
if !meta.is_empty() {
|
if !meta.is_empty() {
|
||||||
let parent_location = snapshot.path.parent_err()?;
|
let parent_location = snapshot.path.parent_err()?;
|
||||||
// Use the file stem from the script path (e.g., "Foo.server" from "Foo.server.luau")
|
// Use the base name from the script path, stripping the script type suffix
|
||||||
// to match how AdjacentMetadata::read_and_apply_all looks for meta files.
|
// (e.g., "Foo" from "Foo.server.luau") to match how AdjacentMetadata::read_and_apply_all
|
||||||
let meta_name = snapshot
|
// looks for meta files.
|
||||||
|
let file_stem = snapshot
|
||||||
.path
|
.path
|
||||||
.file_stem()
|
.file_stem()
|
||||||
.and_then(|s| s.to_str())
|
.and_then(|s| s.to_str())
|
||||||
.map(|s| s.to_string())
|
.unwrap_or("");
|
||||||
.unwrap_or_else(|| {
|
let meta_name = file_stem
|
||||||
if snapshot.encode_windows_invalid_chars() {
|
.strip_suffix(".server")
|
||||||
encode_path_name(&new_inst.name)
|
.or_else(|| file_stem.strip_suffix(".client"))
|
||||||
} else {
|
.or_else(|| file_stem.strip_suffix(".plugin"))
|
||||||
new_inst.name.clone()
|
.unwrap_or(file_stem);
|
||||||
}
|
let meta_name = if meta_name.is_empty() {
|
||||||
});
|
if snapshot.encode_windows_invalid_chars() {
|
||||||
|
encode_path_name(&new_inst.name)
|
||||||
|
} else {
|
||||||
|
new_inst.name.clone()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
meta_name.to_string()
|
||||||
|
};
|
||||||
fs_snapshot.add_file(
|
fs_snapshot.add_file(
|
||||||
parent_location.join(format!("{}.meta.json", meta_name)),
|
parent_location.join(format!("{}.meta.json", meta_name)),
|
||||||
crate::json::to_vec_pretty_sorted(&meta).context("cannot serialize metadata")?,
|
crate::json::to_vec_pretty_sorted(&meta).context("cannot serialize metadata")?,
|
||||||
|
|
|
||||||
|
|
@ -55,12 +55,19 @@ impl AdjacentMetadata {
|
||||||
// Use the file stem from the actual path (which has encoded chars)
|
// Use the file stem from the actual path (which has encoded chars)
|
||||||
// rather than the decoded name, so meta files are found correctly
|
// rather than the decoded name, so meta files are found correctly
|
||||||
// when encodeWindowsInvalidChars is enabled.
|
// when encodeWindowsInvalidChars is enabled.
|
||||||
|
// Strip known script type suffixes (.server, .client, .plugin) to get
|
||||||
|
// the base name for the meta file.
|
||||||
let file_stem = path
|
let file_stem = path
|
||||||
.file_stem()
|
.file_stem()
|
||||||
.and_then(|s| s.to_str())
|
.and_then(|s| s.to_str())
|
||||||
.unwrap_or("");
|
.unwrap_or("");
|
||||||
let meta_path_json = path.with_file_name(format!("{file_stem}.meta.json"));
|
let base_name = file_stem
|
||||||
let meta_path_jsonc = path.with_file_name(format!("{file_stem}.meta.jsonc"));
|
.strip_suffix(".server")
|
||||||
|
.or_else(|| file_stem.strip_suffix(".client"))
|
||||||
|
.or_else(|| file_stem.strip_suffix(".plugin"))
|
||||||
|
.unwrap_or(file_stem);
|
||||||
|
let meta_path_json = path.with_file_name(format!("{base_name}.meta.json"));
|
||||||
|
let meta_path_jsonc = path.with_file_name(format!("{base_name}.meta.jsonc"));
|
||||||
|
|
||||||
if let Some(meta_contents) = vfs.read(&meta_path_json).with_not_found()? {
|
if let Some(meta_contents) = vfs.read(&meta_path_json).with_not_found()? {
|
||||||
let mut metadata = Self::from_slice(&meta_contents, meta_path_json.clone())?;
|
let mut metadata = Self::from_slice(&meta_contents, meta_path_json.clone())?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue